1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:27:46 +00:00

Kernel/LibC: Implement setreuid

This commit is contained in:
Jesse Buhagiar 2021-04-09 21:13:15 +10:00 committed by Andreas Kling
parent 81eab1a9d1
commit 60cdbc9397
5 changed files with 34 additions and 0 deletions

View file

@ -73,6 +73,31 @@ KResultOr<int> Process::sys$setgid(gid_t new_gid)
return 0;
}
KResultOr<int> Process::sys$setreuid(uid_t new_ruid, uid_t new_euid)
{
REQUIRE_PROMISE(id);
if (new_ruid == (uid_t)-1)
new_ruid = uid();
if (new_euid == (uid_t)-1)
new_euid = euid();
auto ok = [this](uid_t id) { return id == uid() || id == euid() || id == suid(); };
if (!ok(new_ruid) || !ok(new_euid))
return EPERM;
if (new_ruid < (uid_t)-1 || new_euid < (uid_t)-1)
return EINVAL;
if (euid() != new_euid)
set_dumpable(false);
ProtectedDataMutationScope scope { *this };
m_uid = new_ruid;
m_euid = new_euid;
return 0;
}
KResultOr<int> Process::sys$setresuid(uid_t new_ruid, uid_t new_euid, uid_t new_suid)
{
REQUIRE_PROMISE(id);