When setting up the execution environment, set groups before gid/egid

like sudo 1.7 did.
This commit is contained in:
Todd C. Miller
2012-01-19 12:55:23 -05:00
parent 8e3691c38e
commit 66a66729af

View File

@@ -988,6 +988,14 @@ exec_setup(struct command_details *details, const char *ptyname, int ptyfd)
/*
* Set groups, including supplementary group vector.
*/
if (!ISSET(details->flags, CD_PRESERVE_GROUPS)) {
if (details->ngroups >= 0) {
if (sudo_setgroups(details->ngroups, details->groups) < 0) {
warning(_("unable to set supplementary group IDs"));
goto done;
}
}
}
#ifdef HAVE_SETEUID
if (ISSET(details->flags, CD_SET_EGID) && setegid(details->egid)) {
warning(_("unable to set effective gid to runas gid %u"),
@@ -1001,15 +1009,6 @@ exec_setup(struct command_details *details, const char *ptyname, int ptyfd)
goto done;
}
if (!ISSET(details->flags, CD_PRESERVE_GROUPS)) {
if (details->ngroups >= 0) {
if (sudo_setgroups(details->ngroups, details->groups) < 0) {
warning(_("unable to set supplementary group IDs"));
goto done;
}
}
}
if (ISSET(details->flags, CD_SET_PRIORITY)) {
if (setpriority(PRIO_PROCESS, 0, details->priority) != 0) {
warning(_("unable to set process priority"));