1 .\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu)
2 .\" and Copyright (C) 2008, 2010, 2015, Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" Modified Thu Oct 31 12:04:29 1996 by Eric S. Raymond <esr@thyrsus.com>
27 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
28 .\" Added notes on capability requirements
29 .\" 2008-05-03, mtk, expanded and rewrote parts of DESCRIPTION and RETURN
30 .\" VALUE, made style of page more consistent with man-pages style.
32 .TH GETGROUPS 2 2019-03-06 "Linux" "Linux Programmer's Manual"
34 getgroups, setgroups \- get/set list of supplementary group IDs
36 .B #include <sys/types.h>
38 .B #include <unistd.h>
40 .BI "int getgroups(int " size ", gid_t " list []);
44 .BI "int setgroups(size_t " size ", const gid_t *" list );
47 Feature Test Macro Requirements for glibc (see
48 .BR feature_test_macros (7)):
54 Glibc 2.19 and earlier:
59 returns the supplementary group IDs of the calling process in
63 should be set to the maximum number of items that can be stored in the
66 If the calling process is a member of more than
68 supplementary groups, then an error results.
69 It is unspecified whether the effective group ID of the calling process
70 is included in the returned list.
71 (Thus, an application should also call
73 and add or remove the resulting value.)
79 is not modified, but the total number of supplementary group IDs for the
81 This allows the caller to determine the size of a dynamically allocated
83 to be used in a further call to
87 sets the supplementary group IDs for the calling process.
88 Appropriate privileges are required (see the description of the
93 argument specifies the number of supplementary group IDs
94 in the buffer pointed to by
96 A process can drop all of its supplementary groups with the call:
106 returns the number of supplementary group IDs.
107 On error, \-1 is returned, and
109 is set appropriately.
114 On error, \-1 is returned, and
116 is set appropriately.
121 has an invalid address.
124 can additionally fail with the following error:
128 is less than the number of supplementary group IDs, but is not zero.
131 can additionally fail with the following errors:
137 (32 before Linux 2.6.4; 65536 since Linux 2.6.4).
143 The calling process has insufficient privilege
144 (the caller does not have the
146 capability in the user namespace in which it resides).
148 .BR EPERM " (since Linux 3.19)"
151 is denied in this user namespace.
152 See the description of
153 .IR /proc/[pid]/setgroups
155 .BR user_namespaces (7).
158 SVr4, 4.3BSD, POSIX.1-2001, POSIX.1-2008.
164 requires privilege, it is not covered by POSIX.1.
166 A process can have up to
168 supplementary group IDs
169 in addition to the effective group ID.
174 The set of supplementary group IDs
175 is inherited from the parent process, and preserved across an
178 The maximum number of supplementary group IDs can be found at run time using
184 ngroups_max = sysconf(_SC_NGROUPS_MAX);
188 The maximum return value of
190 cannot be larger than one more than this value.
191 Since Linux 2.6.4, the maximum number of supplementary group IDs is also
192 exposed via the Linux-specific read-only file,
193 .IR /proc/sys/kernel/ngroups_max .
197 system call supported only 16-bit group IDs.
198 Subsequently, Linux 2.4 added
200 supporting 32-bit IDs.
203 wrapper function transparently deals with the variation across kernel versions.
205 .SS C library/kernel differences
206 At the kernel level, user IDs and group IDs are a per-thread attribute.
207 However, POSIX requires that all threads in a process
208 share the same credentials.
209 The NPTL threading implementation handles the POSIX requirements by
210 providing wrapper functions for
211 the various system calls that change process UIDs and GIDs.
212 These wrapper functions (including the one for
214 employ a signal-based technique to ensure
215 that when one thread changes credentials,
216 all of the other threads in the process also change their credentials.
222 .BR getgrouplist (3),
223 .BR group_member (3),
225 .BR capabilities (7),