2020-07-30 21:38:15 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-07-30 21:38:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Kernel/Process.h>
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-11-07 23:51:39 +00:00
|
|
|
ErrorOr<FlatPtr> Process::sys$getuid()
|
2020-07-30 21:38:15 +00:00
|
|
|
{
|
2022-08-17 20:03:04 +00:00
|
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
2021-12-29 09:11:45 +00:00
|
|
|
TRY(require_promise(Pledge::stdio));
|
2021-08-28 20:11:16 +00:00
|
|
|
return uid().value();
|
2020-07-30 21:38:15 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:51:39 +00:00
|
|
|
ErrorOr<FlatPtr> Process::sys$getgid()
|
2020-07-30 21:38:15 +00:00
|
|
|
{
|
2022-08-17 20:03:04 +00:00
|
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
2021-12-29 09:11:45 +00:00
|
|
|
TRY(require_promise(Pledge::stdio));
|
2021-08-28 20:11:16 +00:00
|
|
|
return gid().value();
|
2020-07-30 21:38:15 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:51:39 +00:00
|
|
|
ErrorOr<FlatPtr> Process::sys$geteuid()
|
2020-07-30 21:38:15 +00:00
|
|
|
{
|
2022-08-17 20:03:04 +00:00
|
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
2021-12-29 09:11:45 +00:00
|
|
|
TRY(require_promise(Pledge::stdio));
|
2021-08-28 20:11:16 +00:00
|
|
|
return euid().value();
|
2020-07-30 21:38:15 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:51:39 +00:00
|
|
|
ErrorOr<FlatPtr> Process::sys$getegid()
|
2020-07-30 21:38:15 +00:00
|
|
|
{
|
2022-08-17 20:03:04 +00:00
|
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
2021-12-29 09:11:45 +00:00
|
|
|
TRY(require_promise(Pledge::stdio));
|
2021-08-28 20:11:16 +00:00
|
|
|
return egid().value();
|
2020-07-30 21:38:15 +00:00
|
|
|
}
|
|
|
|
|
2022-08-20 16:25:54 +00:00
|
|
|
ErrorOr<FlatPtr> Process::sys$getresuid(Userspace<UserID*> user_ruid, Userspace<UserID*> user_euid, Userspace<UserID*> user_suid)
|
2020-07-30 21:38:15 +00:00
|
|
|
{
|
2022-08-17 20:03:04 +00:00
|
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
2021-12-29 09:11:45 +00:00
|
|
|
TRY(require_promise(Pledge::stdio));
|
2022-08-20 16:25:54 +00:00
|
|
|
|
|
|
|
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));
|
2021-11-07 23:51:39 +00:00
|
|
|
return 0;
|
2020-07-30 21:38:15 +00:00
|
|
|
}
|
|
|
|
|
2022-08-20 16:25:54 +00:00
|
|
|
ErrorOr<FlatPtr> Process::sys$getresgid(Userspace<GroupID*> user_rgid, Userspace<GroupID*> user_egid, Userspace<GroupID*> user_sgid)
|
2020-07-30 21:38:15 +00:00
|
|
|
{
|
2022-08-17 20:03:04 +00:00
|
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
2021-12-29 09:11:45 +00:00
|
|
|
TRY(require_promise(Pledge::stdio));
|
2022-08-20 16:25:54 +00:00
|
|
|
|
|
|
|
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));
|
2021-11-07 23:51:39 +00:00
|
|
|
return 0;
|
2020-07-30 21:38:15 +00:00
|
|
|
}
|
|
|
|
|
2022-08-20 16:25:54 +00:00
|
|
|
ErrorOr<FlatPtr> Process::sys$getgroups(size_t count, Userspace<GroupID*> user_gids)
|
2020-07-30 21:38:15 +00:00
|
|
|
{
|
2022-08-17 20:03:04 +00:00
|
|
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
2021-12-29 09:11:45 +00:00
|
|
|
TRY(require_promise(Pledge::stdio));
|
2022-08-20 16:25:54 +00:00
|
|
|
|
|
|
|
auto credentials = this->credentials();
|
|
|
|
|
2020-07-30 21:38:15 +00:00
|
|
|
if (!count)
|
2022-08-20 16:25:54 +00:00
|
|
|
return credentials->extra_gids().size();
|
|
|
|
if (count != credentials->extra_gids().size())
|
2021-03-01 12:49:16 +00:00
|
|
|
return EINVAL;
|
2022-08-20 16:25:54 +00:00
|
|
|
TRY(copy_to_user(user_gids, credentials->extra_gids().data(), sizeof(GroupID) * count));
|
2021-11-07 23:51:39 +00:00
|
|
|
return 0;
|
2020-07-30 21:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|