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():