1GETGROUPS(2) Linux Programmer's Manual GETGROUPS(2)
2
3
4
6 getgroups, setgroups - get/set list of supplementary group IDs
7
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
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
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
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
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
83 A