xref: /freebsd/lib/libc/gen/getgrouplist.3 (revision df21a004be237a1dccd03c7b47254625eea62fa9)
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 October 9, 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 retrieves from the group database the supplementary groups for the user
52specified 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 supplementary groups.
57.Fa basegid
58typically is the user's initial numerical group ID 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 length of the
63.Fa groups
64array in the integer pointed to by
65.Fa ngroups .
66The number of groups of the effective group list, which may be greater than the
67.Fa groups
68array's length, is returned through
69.Fa ngroups .
70.Sh RETURN VALUES
71The
72.Fn getgrouplist
73function returns 0 on success and \-1 if the length of the group list is too
74small to hold all the user's groups.
75In the latter case, the
76.Fa groups
77array is filled with as many groups as possible from the start of the effective
78group list, and the length pointed to by
79.Fa ngroups
80is set to the full length of the latter, thus to a value strictly greater than
81before the call.
82.Sh FILES
83.Bl -tag -width /etc/group -compact
84.It Pa /etc/group
85group membership list
86.El
87.Sh SEE ALSO
88.Xr setcred 2 ,
89.Xr setgroups 2 ,
90.Xr initgroups 3
91.Sh HISTORY
92The
93.Fn getgrouplist
94function first appeared in
95.Bx 4.4 .
96