xref: /csrg-svn/lib/libc/gen/initgroups.c (revision 51660)
121346Sdist /*
221346Sdist  * Copyright (c) 1983 Regents of the University of California.
335091Sbostic  * All rights reserved.
435091Sbostic  *
542625Sbostic  * %sccs.include.redist.c%
621346Sdist  */
79110Ssam 
826567Sdonn #if defined(LIBC_SCCS) && !defined(lint)
9*51660Smckusick static char sccsid[] = "@(#)initgroups.c	5.8 (Berkeley) 11/12/91";
1035091Sbostic #endif /* LIBC_SCCS and not lint */
1121346Sdist 
129110Ssam /*
139110Ssam  * initgroups
149110Ssam  */
1546597Sdonn #include <sys/param.h>
169110Ssam #include <stdio.h>
179110Ssam 
1846597Sdonn int
199110Ssam initgroups(uname, agroup)
2046597Sdonn 	const char *uname;
219110Ssam 	int agroup;
229110Ssam {
23*51660Smckusick 	int groups[NGROUPS], ngroups;
249110Ssam 
25*51660Smckusick 	ngroups = NGROUPS;
26*51660Smckusick 	if (getgrouplist(uname, agroup, groups, &ngroups) < 0)
27*51660Smckusick 		fprintf(stderr,
28*51660Smckusick 		    "initgroups: %s is in too many groups, using first %d\n",
29*51660Smckusick 		    uname, ngroups);
309110Ssam 	if (setgroups(ngroups, groups) < 0) {
3112168Ssam 		perror("setgroups");
3227457Sdonn 		return (-1);
339110Ssam 	}
349110Ssam 	return (0);
359110Ssam }
36