mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-28 14:02:51 +00:00
This patch adds a new object to hold a Process's user credentials: - UID, EUID, SUID - GID, EGID, SGID, extra GIDs Credentials are immutable and child processes initially inherit the Credentials object from their parent. Whenever a process changes one or more of its user/group IDs, a new Credentials object is constructed. Any code that wants to inspect and act on a set of credentials can now do so without worrying about data races.
86 lines
2.2 KiB
C++
86 lines
2.2 KiB
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <Kernel/Process.h>
|
|
|
|
namespace Kernel {
|
|
|
|
ErrorOr<FlatPtr> Process::sys$getuid()
|
|
{
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
|
TRY(require_promise(Pledge::stdio));
|
|
return uid().value();
|
|
}
|
|
|
|
ErrorOr<FlatPtr> Process::sys$getgid()
|
|
{
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
|
TRY(require_promise(Pledge::stdio));
|
|
return gid().value();
|
|
}
|
|
|
|
ErrorOr<FlatPtr> Process::sys$geteuid()
|
|
{
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
|
TRY(require_promise(Pledge::stdio));
|
|
return euid().value();
|
|
}
|
|
|
|
ErrorOr<FlatPtr> Process::sys$getegid()
|
|
{
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
|
TRY(require_promise(Pledge::stdio));
|
|
return egid().value();
|
|
}
|
|
|
|
ErrorOr<FlatPtr> Process::sys$getresuid(Userspace<UserID*> user_ruid, Userspace<UserID*> user_euid, Userspace<UserID*> user_suid)
|
|
{
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
|
TRY(require_promise(Pledge::stdio));
|
|
|
|
auto credentials = this->credentials();
|
|
auto uid = credentials->uid();
|
|
auto euid = credentials->euid();
|
|
auto suid = credentials->suid();
|
|
|
|
TRY(copy_to_user(user_ruid, &uid));
|
|
TRY(copy_to_user(user_euid, &euid));
|
|
TRY(copy_to_user(user_suid, &suid));
|
|
return 0;
|
|
}
|
|
|
|
ErrorOr<FlatPtr> Process::sys$getresgid(Userspace<GroupID*> user_rgid, Userspace<GroupID*> user_egid, Userspace<GroupID*> user_sgid)
|
|
{
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
|
TRY(require_promise(Pledge::stdio));
|
|
|
|
auto credentials = this->credentials();
|
|
auto gid = credentials->gid();
|
|
auto egid = credentials->egid();
|
|
auto sgid = credentials->sgid();
|
|
|
|
TRY(copy_to_user(user_rgid, &gid));
|
|
TRY(copy_to_user(user_egid, &egid));
|
|
TRY(copy_to_user(user_sgid, &sgid));
|
|
return 0;
|
|
}
|
|
|
|
ErrorOr<FlatPtr> Process::sys$getgroups(size_t count, Userspace<GroupID*> user_gids)
|
|
{
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
|
TRY(require_promise(Pledge::stdio));
|
|
|
|
auto credentials = this->credentials();
|
|
|
|
if (!count)
|
|
return credentials->extra_gids().size();
|
|
if (count != credentials->extra_gids().size())
|
|
return EINVAL;
|
|
TRY(copy_to_user(user_gids, credentials->extra_gids().data(), sizeof(GroupID) * count));
|
|
return 0;
|
|
}
|
|
|
|
}
|