xref: /csrg-svn/lib/libc/gen/initgroups.c (revision 61111)
121346Sdist /*
2*61111Sbostic  * Copyright (c) 1983, 1993
3*61111Sbostic  *	The Regents of the University of California.  All rights reserved.
435091Sbostic  *
542625Sbostic  * %sccs.include.redist.c%
621346Sdist  */
79110Ssam 
826567Sdonn #if defined(LIBC_SCCS) && !defined(lint)
9*61111Sbostic static char sccsid[] = "@(#)initgroups.c	8.1 (Berkeley) 06/04/93";
1035091Sbostic #endif /* LIBC_SCCS and not lint */
1121346Sdist 
1246597Sdonn #include <sys/param.h>
1359446Sbostic 
149110Ssam #include <stdio.h>
159110Ssam 
1646597Sdonn int
initgroups(uname,agroup)179110Ssam initgroups(uname, agroup)
1846597Sdonn 	const char *uname;
199110Ssam 	int agroup;
209110Ssam {
2151660Smckusick 	int groups[NGROUPS], ngroups;
229110Ssam 
2351660Smckusick 	ngroups = NGROUPS;
2451660Smckusick 	if (getgrouplist(uname, agroup, groups, &ngroups) < 0)
2559446Sbostic 		warnx("%s is in too many groups, using first %d",
2651660Smckusick 		    uname, ngroups);
279110Ssam 	if (setgroups(ngroups, groups) < 0) {
2859446Sbostic 		warn("setgroups");
2927457Sdonn 		return (-1);
309110Ssam 	}
319110Ssam 	return (0);
329110Ssam }
33