xref: /netbsd-src/lib/libc/gen/getgrouplist.3 (revision aaf4ece63a859a04e37cf3a7229b5fab0157cc06)
1.\"	$NetBSD: getgrouplist.3,v 1.13 2005/01/06 15:29:35 lukem Exp $
2.\"
3.\" Copyright (c) 2005 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Luke Mewburn.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"        This product includes software developed by the NetBSD
20.\"        Foundation, Inc. and its contributors.
21.\" 4. Neither the name of The NetBSD Foundation nor the names of its
22.\"    contributors may be used to endorse or promote products derived
23.\"    from this software without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35.\" POSSIBILITY OF SUCH DAMAGE.
36.\"
37.\" Copyright (c) 1991, 1993
38.\"	The Regents of the University of California.  All rights reserved.
39.\"
40.\" Redistribution and use in source and binary forms, with or without
41.\" modification, are permitted provided that the following conditions
42.\" are met:
43.\" 1. Redistributions of source code must retain the above copyright
44.\"    notice, this list of conditions and the following disclaimer.
45.\" 2. Redistributions in binary form must reproduce the above copyright
46.\"    notice, this list of conditions and the following disclaimer in the
47.\"    documentation and/or other materials provided with the distribution.
48.\" 3. Neither the name of the University nor the names of its contributors
49.\"    may be used to endorse or promote products derived from this software
50.\"    without specific prior written permission.
51.\"
52.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62.\" SUCH DAMAGE.
63.\"
64.\"     @(#)getgrouplist.3	8.1 (Berkeley) 6/9/93
65.\"
66.Dd January 6, 2005
67.Dt GETGROUPLIST 3
68.Os
69.Sh NAME
70.Nm getgrouplist ,
71.Nm getgroupmembership ,
72.Nd calculate group access list
73.Sh LIBRARY
74.Lb libc
75.Sh SYNOPSIS
76.In unistd.h
77.Ft int
78.Fn getgrouplist "const char *name" "gid_t basegid" "gid_t *groups" "int *ngroups"
79.Ft int
80.Fn getgroupmembership "const char *name" "gid_t basegid" "gid_t *groups" "int maxgrp" "int *ngroups"
81.Sh DESCRIPTION
82The
83.Fn getgrouplist
84and
85.Fn getgroupmembership
86functions read through the group database and calculate
87the group access list for the user specified in
88.Fa name .
89The
90.Fa basegid
91is automatically included in the groups list.
92Typically this value is given as
93the group number from the password database.
94.Pp
95The resulting group list is returned in the integer array pointed to by
96.Fa groups .
97.Pp
98For
99.Fn getgrouplist ,
100the caller specifies the size of the
101.Fa groups
102array in the integer pointed to by
103.Fa ngroups .
104.Pp
105For
106.Fn getgroupmembership ,
107the caller specifies the size of the
108.Fa groups
109array in
110.Fa maxgrp .
111.Pp
112The actual number of groups found is returned in
113.Fa ngroups .
114.Pp
115Duplicate group ids will be suppressed from the result.
116.Sh RETURN VALUES
117The
118.Fn getgrouplist
119and
120.Fn getgroupmembership
121functions
122return 0 if successful, and
123return \-1 if the size of the group list is too small to
124hold all the user's groups.
125In the latter case, the
126.Fa groups
127array will be filled with as many groups as will fit and
128.Fa ngroups
129will contain the total number of groups found.
130.Sh FILES
131.Bl -tag -width /etc/group -compact
132.It Pa /etc/group
133group membership list
134.El
135.Sh SEE ALSO
136.Xr setgroups 2 ,
137.Xr initgroups 3 ,
138.Xr group 5
139.Sh HISTORY
140The
141.Fn getgrouplist
142function first appeared in
143.Bx 4.4 .
144The
145.Fn getgroupmembership
146function first appeared in
147.Nx 3.0
148to address an API deficiency in
149.Fn getgrouplist .
150.Sh BUGS
151The
152.Fn getgrouplist
153function
154uses the routines based on
155.Xr getgrent 3 .
156If the invoking program uses any of these routines,
157the group structure will
158be overwritten in the call to
159.Fn getgrouplist .
160