From 2894a44b40e460fc4112988407818439f2e9672d Mon Sep 17 00:00:00 2001 From: Josiah Worcester Date: Sun, 15 Mar 2015 19:20:53 -0500 Subject: add alternate backend support for getgrouplist This completes the alternate backend support that was previously added to the getpw* and getgr* functions. Unlike those, though, it unconditionally queries nscd. Any groups from nscd that aren't in the /etc/groups file are added to the returned list, and any that are present in the file are ignored. The purpose of this behavior is to provide a view of the group database consistent with what is observed by the getgr* functions. If group memberships reported by nscd were honored when the corresponding group already has a definition in the /etc/groups file, the user's getgrouplist-based membership in the group would conflict with their non-membership in the reported gr_mem[] for the group. The changes made also make getgrouplist thread-safe and eliminate its clobbering of the global getgrent state. --- src/misc/getgrouplist.c | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 src/misc/getgrouplist.c (limited to 'src/misc') diff --git a/src/misc/getgrouplist.c b/src/misc/getgrouplist.c deleted file mode 100644 index c9a8f090..00000000 --- a/src/misc/getgrouplist.c +++ /dev/null @@ -1,24 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include - -int getgrouplist(const char *user, gid_t gid, gid_t *groups, int *ngroups) -{ - size_t n, i; - struct group *gr; - if (*ngroups<1) return -1; - n = *ngroups; - *groups++ = gid; - *ngroups = 1; - - setgrent(); - while ((gr = getgrent()) && *ngroups < INT_MAX) { - for (i=0; gr->gr_mem[i] && strcmp(user, gr->gr_mem[i]); i++); - if (!gr->gr_mem[i]) continue; - if (++*ngroups <= n) *groups++ = gr->gr_gid; - } - endgrent(); - - return *ngroups > n ? -1 : *ngroups; -} -- cgit v1.2.1