xref: /original-bsd/lib/libc/gen/initgroups.c (revision c3e32dec)
1 /*
2  * Copyright (c) 1983, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #if defined(LIBC_SCCS) && !defined(lint)
9 static char sccsid[] = "@(#)initgroups.c	8.1 (Berkeley) 06/04/93";
10 #endif /* LIBC_SCCS and not lint */
11 
12 #include <sys/param.h>
13 
14 #include <stdio.h>
15 
16 int
17 initgroups(uname, agroup)
18 	const char *uname;
19 	int agroup;
20 {
21 	int groups[NGROUPS], ngroups;
22 
23 	ngroups = NGROUPS;
24 	if (getgrouplist(uname, agroup, groups, &ngroups) < 0)
25 		warnx("%s is in too many groups, using first %d",
26 		    uname, ngroups);
27 	if (setgroups(ngroups, groups) < 0) {
28 		warn("setgroups");
29 		return (-1);
30 	}
31 	return (0);
32 }
33