From: Todd C. Miller Date: Fri, 22 May 2009 10:37:29 +0000 (+0000) Subject: Handle getgroups() returning 0. Also add missing check for HAVE_GETGROUPS. X-Git-Tag: SUDO_1_7_2~24 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=896508077cdf7ceae24566b68dbe12f74a7cdede;p=sudo Handle getgroups() returning 0. Also add missing check for HAVE_GETGROUPS. --- diff --git a/set_perms.c b/set_perms.c index 686eeb171..6ffebcf4c 100644 --- a/set_perms.c +++ b/set_perms.c @@ -490,7 +490,9 @@ static void runas_setgroups() { static int ngroups = -1; +#ifdef HAVE_GETGROUPS static GETGROUPS_T *groups; +#endif struct passwd *pw; if (def_preserve_groups) @@ -503,14 +505,16 @@ runas_setgroups() pw = runas_pw ? runas_pw : sudo_user.pw; if (initgroups(pw->pw_name, pw->pw_gid) < 0) log_error(USE_ERRNO|MSG_ONLY, "can't set runas group vector"); - if ((ngroups = getgroups(0, NULL)) < 0) - log_error(USE_ERRNO|MSG_ONLY, "can't get runas ngroups"); - groups = emalloc2(ngroups, sizeof(GETGROUPS_T)); - if (getgroups(ngroups, groups) < 0) - log_error(USE_ERRNO|MSG_ONLY, "can't get runas group vector"); +#ifdef HAVE_GETGROUPS + if ((ngroups = getgroups(0, NULL)) > 0) { + groups = emalloc2(ngroups, sizeof(GETGROUPS_T)); + if (getgroups(ngroups, groups) < 0) + log_error(USE_ERRNO|MSG_ONLY, "can't get runas group vector"); + } } else { if (setgroups(ngroups, groups) < 0) log_error(USE_ERRNO|MSG_ONLY, "can't set runas group vector"); +#endif /* HAVE_GETGROUPS */ } }