* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
* %sccs.include.redist.c%
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid
[] = "@(#)getgrouplist.c 8.1 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
getgrouplist(uname
, agroup
, groups
, grpcnt
)
register struct group
*grp
;
register struct passwd
*pw
;
* 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
;
groups
[ngroups
++] = agroup
;
* Scan the group file to find additional groups.
while (grp
= getgrent()) {
if (grp
->gr_gid
== agroup
)
if (ngroups
>= maxgroups
) {
for (i
= 0; grp
->gr_mem
[i
]; i
++) {
if (!strcmp(grp
->gr_mem
[i
], uname
)) {
groups
[ngroups
++] = grp
->gr_gid
;