1GETGROUPS(2) Linux Programmer's Manual GETGROUPS(2)
2
3
4
6 getgroups, setgroups - get/set list of supplementary group IDs
7
9 #include <unistd.h>
10
11 int getgroups(int size, gid_t list[]);
12
13 #include <grp.h>
14
15 int setgroups(size_t size, const gid_t *list);
16
17 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
18
19 setgroups():
20 Since glibc 2.19:
21 _DEFAULT_SOURCE
22 Glibc 2.19 and earlier:
23 _BSD_SOURCE
24
26 getgroups() returns the supplementary group IDs of the calling process
27 in list. The argument size should be set to the maximum number of
28 items that can be stored in the buffer pointed to by list. If the
29 calling process is a member of more than size supplementary groups,
30 then an error results.
31
32 It is unspecified whether the effective group ID of the calling process
33 is included in the returned list. (Thus, an application should also
34 call getegid(2) and add or remove the resulting 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. A process can drop all of
45 its supplementary groups with the call:
46
47 setgroups(0, NULL);
48
50 On success, getgroups() returns the number of supplementary group IDs.
51 On error, -1 is returned, and errno is set to indicate the error.
52
53 On success, setgroups() returns 0. On error, -1 is returned, and errno
54 is set to indicate the error.
55
57 EFAULT list has an invalid address.
58
59 getgroups() can additionally fail with the following error:
60
61 EINVAL size is less than the number of supplementary group IDs, but is
62 not zero.
63
64 setgroups() can additionally fail with the following errors:
65
66 EINVAL size is greater than NGROUPS_MAX (32 before Linux 2.6.4; 65536
67 since Linux 2.6.4).
68
69 ENOMEM Out of memory.
70
71 EPERM The calling process has insufficient privilege (the caller does
72 not have the CAP_SETGID capability in the user namespace in
73 which it resides).
74
75 EPERM (since Linux 3.19)
76 The use of setgroups() is denied in this user namespace. See
77 the description of /proc/[pid]/setgroups in user_namespaces(7).
78
80 getgroups(): SVr4, 4.3BSD, POSIX.1-2001, POSIX.1-2008.
81
82 setgroups(): SVr4, 4.3BSD. Since setgroups() requires privilege, it is