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
Notes: sideshowbarker 2024-07-18 18:52:53 +09:00
5 changed files with 34 additions and 0 deletions

View File

@ -79,6 +79,7 @@ namespace Kernel {
S(setegid) \
S(setuid) \
S(setgid) \
S(setreuid) \
S(setresuid) \
S(setresgid) \
S(alarm) \

View File

@ -324,6 +324,7 @@ public:
KResultOr<int> sys$setegid(gid_t);
KResultOr<int> sys$setuid(uid_t);
KResultOr<int> sys$setgid(gid_t);
KResultOr<int> sys$setreuid(uid_t, uid_t);
KResultOr<int> sys$setresuid(uid_t, uid_t, uid_t);
KResultOr<int> sys$setresgid(gid_t, gid_t, gid_t);
KResultOr<unsigned> sys$alarm(unsigned seconds);

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);

View File

@ -555,6 +555,12 @@ int setgid(gid_t gid)
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int setreuid(uid_t ruid, uid_t euid)
{
int rc = syscall(SC_setreuid, ruid, euid);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int setresuid(uid_t ruid, uid_t euid, uid_t suid)
{
int rc = syscall(SC_setresuid, ruid, euid, suid);

View File

@ -74,6 +74,7 @@ int seteuid(uid_t);
int setegid(gid_t);
int setuid(uid_t);
int setgid(gid_t);
int setreuid(uid_t, uid_t);
int setresuid(uid_t, uid_t, uid_t);
int setresgid(gid_t, gid_t, gid_t);
pid_t tcgetpgrp(int fd);