1getgroups(2)                  System Calls Manual                 getgroups(2)
2
3
4

NAME

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

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

VERSIONS

83   C library/ker