I’m dropping root privileges with setregid(real_gid, effective_gid). Both are set to 1000, but when I’m running id command there’s root in group list! How do I remove that?
I’m dropping root privileges with setregid(real_gid, effective_gid) . Both are set to 1000, but
Share
If
rootis one of the auxilliary groups, you’ll need to usegetgroups()andsetgroups()to adjust the auxilliary groups list – removingroot(0) from that list. Note that POSIX specifiesgetgroups()but does not specifysetgroups().You could probably use code similar to this:
Note that the
rootgroup is 0 on Linux, but the name of group 0 is not alwaysroot(e.g. it issystemon AIX andwheelon MacOS X) and not all systems have a grouproot(neither AIX nor MacOS X, again). Note too that the kernel does not grant any special privileges to group 0 by virtue of it being group 0 (whereas it does grant special privileges to user 0).You can generalize the code by looking up the group(s) you want to omit. POSIX provides an NGROUPS_MAX too; you could use that in place of MAX_AUX_GROUPS. The standard page also suggests: