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
|
|
|
*/
|
|
|
|
|
2023-02-24 17:45:37 +00:00
|
|
|
#include <Kernel/Tasks/Process.h>
|
2020-07-30 21:38:15 +00:00
|
|
|
|
|
|
|
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-20 16:36:47 +00:00
|
|
|
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
2021-12-29 09:11:45 +00:00
|
|
|
TRY(require_promise(Pledge::stdio));
|
2022-08-20 22:21:01 +00:00
|
|
|
auto credentials = this->credentials();
|
|
|
|
return credentials->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-20 16:36:47 +00:00
|
|
|
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
2021-12-29 09:11:45 +00:00
|
|
|
TRY(require_promise(Pledge::stdio));
|
2022-08-20 22:21:01 +00:00
|
|
|
auto credentials = this->credentials();
|
|
|
|
return credentials->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-20 16:36:47 +00:00
|
|
|
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
2021-12-29 09:11:45 +00:00
|
|
|
TRY(require_promise(Pledge::stdio));
|
2022-08-20 22:21:01 +00:00
|
|
|
auto credentials = this->credentials();
|
|
|
|
return credentials->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-20 16:36:47 +00:00
|
|
|
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
2021-12-29 09:11:45 +00:00
|
|
|
TRY(require_promise(Pledge::stdio));
|
2022-08-20 22:21:01 +00:00
|
|
|
auto credentials = this->credentials();
|
|
|
|
return credentials->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-20 16:36:47 +00:00
|
|
|
VERIFY_NO_PROCESS_BIG_LOCK(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-20 16:36:47 +00:00
|
|
|
VERIFY_NO_PROCESS_BIG_LOCK(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-20 16:36:47 +00:00
|
|
|
VERIFY_NO_PROCESS_BIG_LOCK(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;
|
2023-03-24 08:59:28 +00:00
|
|
|
TRY(copy_n_to_user(user_gids, credentials->extra_gids().data(), count));
|
2021-11-07 23:51:39 +00:00
|
|
|
return 0;
|
2020-07-30 21:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|