Use getgrouplist_2() on macOS if available.

This commit is contained in:
Todd C. Miller
2016-12-13 10:39:32 -07:00
parent 56cc9aa02d
commit ae76e1a229
5 changed files with 30 additions and 0 deletions

View File

@@ -256,6 +256,14 @@ sudo_make_gidlist_item(const struct passwd *pw, char * const *unused1)
}
(void)getgrouplist(pw->pw_name, pw->pw_gid, gids, &ngids);
} else {
#ifdef HAVE_GETGROUPLIST_2
ngids = getgrouplist_2(pw->pw_name, pw->pw_gid, &gids);
if (ngids == -1) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"unable to allocate memory");
debug_return_ptr(NULL);
}
#else
ngids = (int)sysconf(_SC_NGROUPS_MAX) * 2;
if (ngids < 0)
ngids = NGROUPS_MAX * 2;
@@ -276,6 +284,7 @@ sudo_make_gidlist_item(const struct passwd *pw, char * const *unused1)
if (getgrouplist(pw->pw_name, pw->pw_gid, gids, &ngids) == -1)
ngids = -1;
}
#endif /* HAVE_GETGROUPLIST_2 */
}
}
if (ngids <= 0) {