Home | History | Annotate | Line # | Download | only in gen
getgrouplist.c revision 1.21
      1  1.21     lukem /*	$NetBSD: getgrouplist.c,v 1.21 2005/01/06 15:10:45 lukem Exp $	*/
      2  1.19     lukem 
      3  1.19     lukem /*-
      4  1.21     lukem  * Copyright (c) 2004-2005 The NetBSD Foundation, Inc.
      5  1.19     lukem  * All rights reserved.
      6  1.19     lukem  *
      7  1.19     lukem  * This code is derived from software contributed to The NetBSD Foundation
      8  1.19     lukem  * by Luke Mewburn.
      9  1.19     lukem  *
     10  1.19     lukem  * Redistribution and use in source and binary forms, with or without
     11  1.19     lukem  * modification, are permitted provided that the following conditions
     12  1.19     lukem  * are met:
     13  1.19     lukem  * 1. Redistributions of source code must retain the above copyright
     14  1.19     lukem  *    notice, this list of conditions and the following disclaimer.
     15  1.19     lukem  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.19     lukem  *    notice, this list of conditions and the following disclaimer in the
     17  1.19     lukem  *    documentation and/or other materials provided with the distribution.
     18  1.19     lukem  * 3. All advertising materials mentioning features or use of this software
     19  1.19     lukem  *    must display the following acknowledgement:
     20  1.19     lukem  *	This product includes software developed by the NetBSD
     21  1.19     lukem  *	Foundation, Inc. and its contributors.
     22  1.19     lukem  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.19     lukem  *    contributors may be used to endorse or promote products derived
     24  1.19     lukem  *    from this software without specific prior written permission.
     25  1.19     lukem  *
     26  1.19     lukem  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.19     lukem  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.19     lukem  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.19     lukem  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.19     lukem  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.19     lukem  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.19     lukem  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.19     lukem  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.19     lukem  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.19     lukem  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.19     lukem  * POSSIBILITY OF SUCH DAMAGE.
     37  1.19     lukem  */
     38   1.4       cgd 
     39   1.6  christos #include <sys/cdefs.h>
     40   1.1       cgd #if defined(LIBC_SCCS) && !defined(lint)
     41   1.4       cgd #if 0
     42   1.8     perry static char sccsid[] = "@(#)getgrouplist.c	8.2 (Berkeley) 12/8/94";
     43   1.4       cgd #else
     44  1.21     lukem __RCSID("$NetBSD: getgrouplist.c,v 1.21 2005/01/06 15:10:45 lukem Exp $");
     45   1.4       cgd #endif
     46   1.1       cgd #endif /* LIBC_SCCS and not lint */
     47   1.1       cgd 
     48   1.1       cgd /*
     49  1.19     lukem  * calculate group access list
     50   1.1       cgd  */
     51  1.19     lukem 
     52   1.7       jtc #include "namespace.h"
     53  1.12     lukem #include <sys/param.h>
     54  1.12     lukem 
     55  1.13     lukem #include <assert.h>
     56  1.19     lukem #include <nsswitch.h>
     57  1.19     lukem #include <stdarg.h>
     58   1.6  christos #include <unistd.h>
     59   1.7       jtc 
     60   1.7       jtc #ifdef __weak_alias
     61  1.15   mycroft __weak_alias(getgrouplist,_getgrouplist)
     62   1.7       jtc #endif
     63   1.1       cgd 
     64   1.1       cgd int
     65  1.18     lukem getgrouplist(const char *uname, gid_t agroup, gid_t *groups, int *grpcnt)
     66   1.1       cgd {
     67  1.21     lukem 	int	rv, groupc;
     68  1.13     lukem 
     69  1.13     lukem 	_DIAGASSERT(uname != NULL);
     70  1.20     lukem 	/* groups may be NULL if just sizing when invoked with *grpcnt = 0 */
     71  1.13     lukem 	_DIAGASSERT(grpcnt != NULL);
     72   1.1       cgd 
     73  1.21     lukem 	groupc = 0;
     74  1.21     lukem 	rv = getgroupmembership(uname, agroup, groups, *grpcnt, &groupc);
     75  1.21     lukem 	*grpcnt = groupc;	/* set groupc to the actual # of groups */
     76  1.21     lukem 	return rv;
     77   1.1       cgd }
     78