xref: /freebsd/lib/libc/gen/getgrouplist.3 (revision d9cc3d558d00ee7f62dbef2032f099033c91d2a1)
1.\"-
2.\" SPDX-License-Identifier: BSD-3-Clause
3.\"
4.\" Copyright (c) 1991, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\" Copyright (c) 2025 The FreeBSD Foundation
7.\"
8.\" Portions of this documentation were written by Olivier Certner
9.\" <olce@FreeBSD.org> at Kumacom SARL under sponsorship from the FreeBSD
10.\" Foundation.
11.\"
12.\" Redistribution and use in source and binary forms, with or without
13.\" modification, are permitted provided that the following conditions
14.\" are met:
15.\" 1. Redistributions of source code must retain the above copyright
16.\"    notice, this list of conditions and the following disclaimer.
17.\" 2. Redistributions in binary form must reproduce the above copyright
18.\"    notice, this list of conditions and the following disclaimer in the
19.\"    documentation and/or other materials provided with the distribution.
20.\" 3. Neither the name of the University nor the names of its contributors
21.\"    may be used to endorse or promote products derived from this software
22.\"    without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.Dd August 29, 2025
37.Dt GETGROUPLIST 3
38.Os
39.Sh NAME
40.Nm getgrouplist
41.Nd produce a user's effective group list
42.Sh LIBRARY
43.Lb libc
44.Sh SYNOPSIS
45.In unistd.h
46.Ft int
47.Fn getgrouplist "const char *name" "gid_t basegid" "gid_t *groups" "int *ngroups"
48.Sh DESCRIPTION
49The
50.Fn getgrouplist
51function reads through the group database to retrieve the supplementary groups
52for the user specified in
53.Fa name ,
54and returns the effective group list, whose first group is the value of
55.Fa basegid
56and the others are the retrieved supplementary groups.
57.Fa basegid
58typically is the user's group number from the password database.
59.Pp
60The effective group list is returned in the array pointed to by
61.Fa groups .
62The caller specifies the size of the
63.Fa groups
64array in the integer pointed to by
65.Fa ngroups ;
66the actual number of groups found is returned in
67.Fa ngroups .
68.Sh RETURN VALUES
69The
70.Fn getgrouplist
71function
72returns 0 on success and \-1 if the size of the group list is too small to
73hold all the user's groups.
74Here, the group array will be filled with as many groups as will fit.
75.Sh FILES
76.Bl -tag -width /etc/group -compact
77.It Pa /etc/group
78group membership list
79.El
80.Sh SEE ALSO
81.Xr setcred 2 ,
82.Xr setgroups 2 ,
83.Xr initgroups 3
84.Sh HISTORY
85The
86.Fn getgrouplist
87function first appeared in
88.Bx 4.4 .
89