mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:37:46 +00:00
Add some basic setgroups(), getgroups() and initgroups().
Also teach /bin/id to print the user's supplemental groups.
This commit is contained in:
parent
d3bd3791cb
commit
a7f1d892a9
12 changed files with 167 additions and 19 deletions
22
LibC/grp.cpp
22
LibC/grp.cpp
|
@ -118,4 +118,26 @@ next_entry:
|
|||
return __grdb_entry;
|
||||
}
|
||||
|
||||
int initgroups(const char* user, gid_t extra_gid)
|
||||
{
|
||||
size_t count = 0;
|
||||
gid_t gids[32];
|
||||
bool extra_gid_added = false;
|
||||
setgrent();
|
||||
while (auto* gr = getgrent()) {
|
||||
for (auto* mem = gr->gr_mem; *mem; ++mem) {
|
||||
if (!strcmp(*mem, user)) {
|
||||
gids[count++] = gr->gr_gid;
|
||||
if (gr->gr_gid == extra_gid)
|
||||
extra_gid_added = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
endgrent();
|
||||
if (!extra_gid_added)
|
||||
gids[count++] = extra_gid;
|
||||
return setgroups(count, gids);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue