util: add function for dropping root privileges

Share the code for dropping supplementary groups and setting effective,
saved, and real user UID/GID between system drivers.
This commit is contained in:
Miroslav Lichvar
2015-12-08 17:16:45 +01:00
parent 334ac06102
commit 3cf6acdf24
6 changed files with 28 additions and 34 deletions

View File

@@ -419,16 +419,7 @@ void SYS_MacOSX_DropRoot(uid_t uid, gid_t gid)
{
PRV_StartHelper();
if (setgroups(0, NULL))
LOG_FATAL(LOGF_SysMacOSX, "setgroups() failed : %s", strerror(errno));
if (setgid(gid))
LOG_FATAL(LOGF_SysMacOSX, "setgid(%d) failed : %s", gid, strerror(errno));
if (setuid(uid))
LOG_FATAL(LOGF_SysMacOSX, "setuid(%d) failed : %s", uid, strerror(errno));
DEBUG_LOG(LOGF_SysMacOSX, "Root dropped to uid %d gid %d", uid, gid);
UTI_DropRoot(uid, gid);
}
#endif