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.  It is unspecified whether the effective group
32       ID of the calling process is included in the returned list.  (Thus,  an
33       application should also call getegid(2) and add or remove the resulting
34       value.)
35
36       If size is zero, list is not modified, but the total number of  supple‐
37       mentary  group IDs for the process is returned.  This allows the caller
38       to determine the size of a dynamically allocated list to be used  in  a
39       further call to getgroups().
40
41       setgroups()  sets  the supplementary group IDs for the calling process.
42       Appropriate privileges are required (see the description of  the  EPERM
43       error, below).  The size argument specifies the number of supplementary
44       group IDs in the buffer pointed to by list.
45

RETURN VALUE

47       On success, getgroups() returns the number of supplementary group  IDs.
48       On error, -1 is returned, and errno is set appropriately.
49
50       On success, setgroups() returns 0.  On error, -1 is returned, and errno
51       is set appropriately.
52

ERRORS

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

CONFORMING TO

77       getgroups(): SVr4, 4.3BSD, POSIX.1-2001, POSIX.1-2008.
78
79       setgroups(): SVr4, 4.3BSD.  Since setgroups() requires privilege, it is
80       not covered by POSIX.1.
81

NOTES

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

SEE ALSO

116       getgid(2), setgid(2), getgrouplist(3), group_member(3),  initgroups(3),
117       capabilities(7), credentials(7)
118

COLOPHON

120       This  page  is  part of release 4.16 of the Linux man-pages project.  A
121       description of the project, information about reporting bugs,  and  the
122       latest     version     of     this    page,    can    be    found    at
123       https://www.kernel.org/doc/man-pages/.
124
125
126
127Linux                             2017-09-15                      GETGROUPS(2)
Impressum