1GETGROUPS(2)               Linux Programmer's Manual              GETGROUPS(2)
2
3
4

NAME

6       getgroups, setgroups - get/set list of supplementary group IDs
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <unistd.h>
11
12       int getgroups(int size, gid_t list[]);
13
14       #include <grp.h>
15
16       int setgroups(size_t size, const gid_t *list);
17
18   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
19
20       setgroups():
21           Since glibc 2.19:
22               _DEFAULT_SOURCE
23           Glibc 2.19 and earlier:
24               _BSD_SOURCE
25

DESCRIPTION

27       getgroups()  returns the supplementary group IDs of the calling process
28       in list.  The argument size should be set  to  the  maximum  number  of
29       items  that  can  be  stored  in the buffer pointed to by list.  If the
30       calling process is a member of more  than  size  supplementary  groups,
31       then an error results.
32
33       It is unspecified whether the effective group ID of the calling process
34       is included in the returned list.  (Thus, an  application  should  also
35       call getegid(2) and add or remove the resulting value.)
36
37       If  size is zero, list is not modified, but the total number of supple‐
38       mentary group IDs for the process is returned.  This allows the  caller
39       to  determine  the size of a dynamically allocated list to be used in a
40       further call to getgroups().
41
42       setgroups() sets the supplementary group IDs for the  calling  process.
43       Appropriate  privileges  are required (see the description of the EPERM
44       error, below).  The size argument specifies the number of supplementary
45       group  IDs in the buffer pointed to by list.  A process can drop all of
46       its supplementary groups with the call:
47
48           setgroups(0, NULL);
49

RETURN VALUE

51       On success, getgroups() returns the number of supplementary group  IDs.
52       On error, -1 is returned, and errno is set appropriately.
53
54       On success, setgroups() returns 0.  On error, -1 is returned, and errno
55       is set appropriately.
56

ERRORS

58       EFAULT list has an invalid address.
59
60       getgroups() can additionally fail with the following error:
61
62       EINVAL size is less than the number of supplementary group IDs, but  is
63              not zero.
64
65       setgroups() can additionally fail with the following errors:
66
67       EINVAL size  is  greater than NGROUPS_MAX (32 before Linux 2.6.4; 65536
68              since Linux 2.6.4).
69
70       ENOMEM Out of memory.
71
72       EPERM  The calling process has insufficient privilege (the caller  does
73              not  have  the  CAP_SETGID  capability  in the user namespace in
74              which it resides).
75
76       EPERM (since Linux 3.19)
77              The use of setgroups() is denied in this  user  namespace.   See
78              the description of /proc/[pid]/setgroups in user_namespaces(7).
79

CONFORMING TO

81       getgroups(): SVr4, 4.3BSD, POSIX.1-2001, POSIX.1-2008.
82
83       setgroups(): SVr4, 4.3BSD.  Since setgroups() requires privilege, it is
84       not covered by POSIX.1.
85

NOTES

87       A process can have up to NGROUPS_MAX supplementary group IDs  in  addi‐
88       tion to the effective group ID.  The constant NGROUPS_MAX is defined in
89       <limits.h>.  The set of supplementary group IDs is inherited  from  the
90       parent process, and preserved across an execve(2).
91
92       The  maximum number of supplementary group IDs can be found at run time
93       using sysconf(3):
94
95           long ngroups_max;
96           ngroups_max = sysconf(_SC_NGROUPS_MAX);
97
98       The maximum return value of getgroups() cannot be larger than one  more
99       than  this  value.  Since Linux 2.6.4, the maximum number of supplemen‐
100       tary group IDs is also exposed via the Linux-specific  read-only  file,
101       /proc/sys/kernel/ngroups_max.
102
103       The  original Linux getgroups() system call supported only 16-bit group
104       IDs.  Subsequently, Linux 2.4 added  getgroups32(),  supporting  32-bit
105       IDs.   The  glibc getgroups() wrapper function transparently deals with
106       the variation across kernel versions.
107
108   C library/kernel differences
109       At the kernel level, user IDs and group IDs are a per-thread attribute.
110       However,  POSIX  requires  that all threads in a process share the same
111       credentials.  The  NPTL  threading  implementation  handles  the  POSIX
112       requirements  by  providing  wrapper  functions  for the various system
113       calls that change process  UIDs  and  GIDs.   These  wrapper  functions
114       (including  the one for setgroups()) employ a signal-based technique to
115       ensure that when one thread  changes  credentials,  all  of  the  other
116       threads in the process also change their credentials.  For details, see
117       nptl(7).
118

SEE ALSO

120       getgid(2), setgid(2), getgrouplist(3), group_member(3),  initgroups(3),
121       capabilities(7), credentials(7)
122

COLOPHON

124       This  page  is  part of release 5.07 of the Linux man-pages project.  A
125       description of the project, information about reporting bugs,  and  the
126       latest     version     of     this    page,    can    be    found    at
127       https://www.kernel.org/doc/man-pages/.
128
129
130
131Linux                             2019-03-06                      GETGROUPS(2)
Impressum