mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 10:57:36 +00:00
Kernel/LibC: Implement setreuid
This commit is contained in:
parent
81eab1a9d1
commit
60cdbc9397
5 changed files with 34 additions and 0 deletions
|
@ -79,6 +79,7 @@ namespace Kernel {
|
|||
S(setegid) \
|
||||
S(setuid) \
|
||||
S(setgid) \
|
||||
S(setreuid) \
|
||||
S(setresuid) \
|
||||
S(setresgid) \
|
||||
S(alarm) \
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue