X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/blobdiff_plain/de7b8ea980507045f9d50c5449ef717011d77970..ed5d57202ebab0e923eb8e9d967a9f97792a6e8f:/lib/libc/gen/getgrouplist.c diff --git a/lib/libc/gen/getgrouplist.c b/lib/libc/gen/getgrouplist.c index 54e2ce2775..695cee8899 100644 --- a/lib/libc/gen/getgrouplist.c +++ b/lib/libc/gen/getgrouplist.c @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,10 +10,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -31,57 +27,23 @@ * SUCH DAMAGE. * * @(#)getgrouplist.c 8.2 (Berkeley) 12/8/94 + * $FreeBSD: src/lib/libc/gen/getgrouplist.c,v 1.16 2007/12/12 10:08:02 bushman Exp $ * $DragonFly: src/lib/libc/gen/getgrouplist.c,v 1.6 2005/04/27 12:37:43 joerg Exp $ */ /* * get credential */ +#include + #include #include #include +extern int __getgroupmembership(const char *, gid_t, gid_t *, int, int *); + int getgrouplist(const char *uname, gid_t agroup, gid_t *groups, int *grpcnt) { - struct group *grp; - int i, ngroups; - int ret, maxgroups; - - 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); }