mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:17:44 +00:00
Kernel+LibC: Implement setregid(2)
This copies and adapts the setresgid syscall, following in the footsteps of setreuid and setresuid.
This commit is contained in:
parent
2a502fe232
commit
70337f3a4b
5 changed files with 43 additions and 0 deletions
|
@ -206,6 +206,40 @@ ErrorOr<FlatPtr> Process::sys$setresuid(UserID new_ruid, UserID new_euid, UserID
|
|||
});
|
||||
}
|
||||
|
||||
ErrorOr<FlatPtr> Process::sys$setregid(GroupID new_rgid, GroupID new_egid)
|
||||
{
|
||||
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
||||
TRY(require_promise(Pledge::id));
|
||||
|
||||
return with_mutable_protected_data([&](auto& protected_data) -> ErrorOr<FlatPtr> {
|
||||
auto credentials = this->credentials();
|
||||
|
||||
if (new_rgid == (gid_t)-1)
|
||||
new_rgid = credentials->gid();
|
||||
if (new_egid == (gid_t)-1)
|
||||
new_egid = credentials->egid();
|
||||
|
||||
auto ok = [&credentials](GroupID id) { return id == credentials->gid() || id == credentials->egid() || id == credentials->sgid(); };
|
||||
if (!ok(new_rgid) || !ok(new_egid))
|
||||
return EPERM;
|
||||
|
||||
auto new_credentials = TRY(Credentials::create(
|
||||
credentials->uid(),
|
||||
new_rgid,
|
||||
credentials->euid(),
|
||||
new_egid,
|
||||
credentials->suid(),
|
||||
credentials->sgid(),
|
||||
credentials->extra_gids()));
|
||||
|
||||
if (credentials->egid() != new_egid)
|
||||
protected_data.dumpable = false;
|
||||
|
||||
protected_data.credentials = move(new_credentials);
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
ErrorOr<FlatPtr> Process::sys$setresgid(GroupID new_rgid, GroupID new_egid, GroupID new_sgid)
|
||||
{
|
||||
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue