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

DESCRIPTION

23       getgroups()  returns the supplementary group IDs of the calling process
24       in list.  The argument size should be set  to  the  maximum  number  of
25       items  that  can  be  stored  in the buffer pointed to by list.  If the
26       calling process is a member of more  than  size  supplementary  groups,
27       then  an  error results.  It is unspecified whether the effective group
28       ID of the calling process is included in the returned list.  (Thus,  an
29       application should also call getegid(2) and add or remove the resulting
30       value.)
31
32       If size is zero, list is not modified, but the total number of  supple‐
33       mentary  group IDs for the process is returned.  This allows the caller
34       to determine the size of a dynamically allocated list to be used  in  a
35       further call to getgroups().
36
37       setgroups()  sets  the supplementary group IDs for the calling process.
38       Appropriate privileges (Linux: the CAP_SETGID capability) are required.
39       The  size  argument  specifies the number of supplementary group IDs in
40       the buffer pointed to by list.
41

RETURN VALUE

43       On success, getgroups() returns the number of supplementary group  IDs.
44       On error, -1 is returned, and errno is set appropriately.
45
46       On success, setgroups() returns 0.  On error, -1 is returned, and errno
47       is set appropriately.
48

ERRORS

50       EFAULT list has an invalid address.
51
52       getgroups() can additionally fail with the following error:
53
54       EINVAL size is less than the number of supplementary group IDs, but  is
55              not zero.
56
57       setgroups() can additionally fail with the following errors:
58
59       EINVAL size  is  greater than NGROUPS_MAX (32 before Linux 2.6.4; 65536
60              since Linux 2.6.4).
61
62       ENOMEM Out of memory.
63
64       EPERM  The calling process has insufficient privilege.
65

CONFORMING TO

67       SVr4, 4.3BSD.  The getgroups() function is in POSIX.1-2001.  Since set‐
68       groups() requires privilege, it is not covered by POSIX.1-2001.
69

NOTES

71       A  process  can have up to NGROUPS_MAX supplementary group IDs in addi‐
72       tion to the effective group ID.  The set of supplementary group IDs  is
73       inherited from the parent process, and preserved across an execve(2).
74
75       The  maximum  number  of  supplementary  group  IDs  can be found using
76       sysconf(3):
77
78           long ngroups_max;
79           ngroups_max = sysconf(_SC_NGROUPS_MAX);
80
81       The maximum return value of getgroups() cannot be larger than one  more
82       than this value.
83

SEE ALSO

85       getgid(2),  setgid(2), getgrouplist(3), initgroups(3), capabilities(7),
86       credentials(7)
87

COLOPHON

89       This page is part of release 3.25 of the Linux  man-pages  project.   A
90       description  of  the project, and information about reporting bugs, can
91       be found at http://www.kernel.org/doc/man-pages/.
92
93
94
95Linux                             2008-06-03                      GETGROUPS(2)
Impressum