summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen/getgrouplist.c
diff options
context:
space:
mode:
authorbushman <bushman@FreeBSD.org>2007-12-12 10:08:03 +0000
committerbushman <bushman@FreeBSD.org>2007-12-12 10:08:03 +0000
commitb02556dae5c4b2e396b5bee2c663fe38f28d369b (patch)
treec40928e3eb8bab77c816a763945d3d4a10c59962 /lib/libc/gen/getgrouplist.c
parentb52b3d4702084768bfb2db0f76743d7a3b993690 (diff)
downloadFreeBSD-src-b02556dae5c4b2e396b5bee2c663fe38f28d369b.zip
FreeBSD-src-b02556dae5c4b2e396b5bee2c663fe38f28d369b.tar.gz
Implementing 'fallback' nsswitch source. 'fallback' source is used
when particular function can't be found in nsswitch-module. For example, getgrouplist(3) will use module-supplied 'getgroupmembership' function (which can work in an optimal way for such source as LDAP) and will fall back to the stanard iterate-through-all-groups implementation otherwise. PR: ports/114655 Submitted by: Michael Hanselmann <freebsd AT hansmi DOT ch> Reviewed by: brooks (mentor)
Diffstat (limited to 'lib/libc/gen/getgrouplist.c')
-rw-r--r--lib/libc/gen/getgrouplist.c43
1 files changed, 4 insertions, 39 deletions
diff --git a/lib/libc/gen/getgrouplist.c b/lib/libc/gen/getgrouplist.c
index 3510a31..9eb55f9 100644
--- a/lib/libc/gen/getgrouplist.c
+++ b/lib/libc/gen/getgrouplist.c
@@ -42,46 +42,11 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include <unistd.h>
+extern int __getgroupmembership(const char *, gid_t, gid_t *, int, int *);
+
int
getgrouplist(const char *uname, gid_t agroup, gid_t *groups, int *grpcnt)
{
- const struct group *grp;
- int i, maxgroups, ngroups, ret;
-
- ret = 0;
- ngroups = 0;
- maxgroups = *grpcnt;
- /*
- * When installing primary group, duplicate it;
- * the first element of groups is the effective gid
- * and will be overwritten when a setgid file is executed.
- */
- groups[ngroups++] = agroup;
- if (maxgroups > 1)
- groups[ngroups++] = agroup;
- /*
- * Scan the group file to find additional groups.
- */
- setgrent();
- while ((grp = getgrent()) != NULL) {
- for (i = 0; i < ngroups; i++) {
- if (grp->gr_gid == groups[i])
- goto skip;
- }
- for (i = 0; grp->gr_mem[i]; i++) {
- if (!strcmp(grp->gr_mem[i], uname)) {
- if (ngroups >= maxgroups) {
- ret = -1;
- break;
- }
- groups[ngroups++] = grp->gr_gid;
- break;
- }
- }
-skip:
- ;
- }
- endgrent();
- *grpcnt = ngroups;
- return (ret);
+ return __getgroupmembership(uname, agroup, groups, *grpcnt, grpcnt);
}
+
OpenPOWER on IntegriCloud