getgrouplist.c revision 1.21.24.1 1 1.21.24.1 yamt /* $NetBSD: getgrouplist.c,v 1.21.24.1 2008/05/18 12:30:15 yamt 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 *
19 1.19 lukem * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.19 lukem * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.19 lukem * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.19 lukem * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.19 lukem * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.19 lukem * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.19 lukem * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.19 lukem * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.19 lukem * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.19 lukem * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.19 lukem * POSSIBILITY OF SUCH DAMAGE.
30 1.19 lukem */
31 1.4 cgd
32 1.6 christos #include <sys/cdefs.h>
33 1.1 cgd #if defined(LIBC_SCCS) && !defined(lint)
34 1.4 cgd #if 0
35 1.8 perry static char sccsid[] = "@(#)getgrouplist.c 8.2 (Berkeley) 12/8/94";
36 1.4 cgd #else
37 1.21.24.1 yamt __RCSID("$NetBSD: getgrouplist.c,v 1.21.24.1 2008/05/18 12:30:15 yamt Exp $");
38 1.4 cgd #endif
39 1.1 cgd #endif /* LIBC_SCCS and not lint */
40 1.1 cgd
41 1.1 cgd /*
42 1.19 lukem * calculate group access list
43 1.1 cgd */
44 1.19 lukem
45 1.7 jtc #include "namespace.h"
46 1.12 lukem #include <sys/param.h>
47 1.12 lukem
48 1.13 lukem #include <assert.h>
49 1.19 lukem #include <nsswitch.h>
50 1.19 lukem #include <stdarg.h>
51 1.6 christos #include <unistd.h>
52 1.7 jtc
53 1.7 jtc #ifdef __weak_alias
54 1.15 mycroft __weak_alias(getgrouplist,_getgrouplist)
55 1.7 jtc #endif
56 1.1 cgd
57 1.1 cgd int
58 1.18 lukem getgrouplist(const char *uname, gid_t agroup, gid_t *groups, int *grpcnt)
59 1.1 cgd {
60 1.21 lukem int rv, groupc;
61 1.13 lukem
62 1.13 lukem _DIAGASSERT(uname != NULL);
63 1.20 lukem /* groups may be NULL if just sizing when invoked with *grpcnt = 0 */
64 1.13 lukem _DIAGASSERT(grpcnt != NULL);
65 1.1 cgd
66 1.21 lukem groupc = 0;
67 1.21 lukem rv = getgroupmembership(uname, agroup, groups, *grpcnt, &groupc);
68 1.21 lukem *grpcnt = groupc; /* set groupc to the actual # of groups */
69 1.21 lukem return rv;
70 1.1 cgd }
71