Handle getgroups() returning 0. Also add missing check for HAVE_GETGROUPS.
This commit is contained in:
14
set_perms.c
14
set_perms.c
@@ -490,7 +490,9 @@ static void
|
|||||||
runas_setgroups()
|
runas_setgroups()
|
||||||
{
|
{
|
||||||
static int ngroups = -1;
|
static int ngroups = -1;
|
||||||
|
#ifdef HAVE_GETGROUPS
|
||||||
static GETGROUPS_T *groups;
|
static GETGROUPS_T *groups;
|
||||||
|
#endif
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
|
|
||||||
if (def_preserve_groups)
|
if (def_preserve_groups)
|
||||||
@@ -503,14 +505,16 @@ runas_setgroups()
|
|||||||
pw = runas_pw ? runas_pw : sudo_user.pw;
|
pw = runas_pw ? runas_pw : sudo_user.pw;
|
||||||
if (initgroups(pw->pw_name, pw->pw_gid) < 0)
|
if (initgroups(pw->pw_name, pw->pw_gid) < 0)
|
||||||
log_error(USE_ERRNO|MSG_ONLY, "can't set runas group vector");
|
log_error(USE_ERRNO|MSG_ONLY, "can't set runas group vector");
|
||||||
if ((ngroups = getgroups(0, NULL)) < 0)
|
#ifdef HAVE_GETGROUPS
|
||||||
log_error(USE_ERRNO|MSG_ONLY, "can't get runas ngroups");
|
if ((ngroups = getgroups(0, NULL)) > 0) {
|
||||||
groups = emalloc2(ngroups, sizeof(GETGROUPS_T));
|
groups = emalloc2(ngroups, sizeof(GETGROUPS_T));
|
||||||
if (getgroups(ngroups, groups) < 0)
|
if (getgroups(ngroups, groups) < 0)
|
||||||
log_error(USE_ERRNO|MSG_ONLY, "can't get runas group vector");
|
log_error(USE_ERRNO|MSG_ONLY, "can't get runas group vector");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (setgroups(ngroups, groups) < 0)
|
if (setgroups(ngroups, groups) < 0)
|
||||||
log_error(USE_ERRNO|MSG_ONLY, "can't set runas group vector");
|
log_error(USE_ERRNO|MSG_ONLY, "can't set runas group vector");
|
||||||
|
#endif /* HAVE_GETGROUPS */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user