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
|
|
|
}
|
|
|
|
|
2021-11-07 23:51:39 +00:00
|
|
|
ErrorOr<FlatPtr> Process::sys$getresuid(Userspace<UserID*> ruid, Userspace<UserID*> euid, Userspace<UserID*> 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));
|
2021-09-05 15:38:37 +00:00
|
|
|
TRY(copy_to_user(ruid, &m_protected_values.uid));
|
|
|
|
TRY(copy_to_user(euid, &m_protected_values.euid));
|
|
|
|
TRY(copy_to_user(suid, &m_protected_values.suid));
|
2021-11-07 23:51:39 +00:00
|
|
|
return 0;
|
2020-07-30 21:38:15 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:51:39 +00:00
|
|
|
ErrorOr<FlatPtr> Process::sys$getresgid(Userspace<GroupID*> rgid, Userspace<GroupID*> egid, Userspace<GroupID*> 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));
|
2021-09-05 15:38:37 +00:00
|
|
|
TRY(copy_to_user(rgid, &m_protected_values.gid));
|
|
|
|
TRY(copy_to_user(egid, &m_protected_values.egid));
|
|
|
|
TRY(copy_to_user(sgid, &m_protected_values.sgid));
|
2021-11-07 23:51:39 +00:00
|
|
|
return 0;
|
2020-07-30 21:38:15 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:51:39 +00:00
|
|
|
ErrorOr<FlatPtr> Process::sys$getgroups(size_t count, Userspace<gid_t*> 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));
|
2020-07-30 21:38:15 +00:00
|
|
|
if (!count)
|
2021-03-10 19:07:08 +00:00
|
|
|
return extra_gids().size();
|
2021-06-16 14:44:15 +00:00
|
|
|
if (count != extra_gids().size())
|
2021-03-01 12:49:16 +00:00
|
|
|
return EINVAL;
|
2021-11-07 23:51:39 +00:00
|
|
|
TRY(copy_to_user(user_gids, extra_gids().data(), sizeof(gid_t) * count));
|
|
|
|
return 0;
|
2020-07-30 21:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|