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

DESCRIPTION

19       getgroups()
20              Up  to size supplementary group IDs (of the calling process) are
21              returned in list.  It is unspecified whether the effective group
22              ID  of  the  calling  process  is included in the returned list.
23              (Thus, an application should also call  getegid(2)  and  add  or
24              remove the resulting value.)  If size is zero, list is not modi‐
25              fied, but the total number of supplementary group  IDs  for  the
26              process is returned.
27
28       setgroups()
29              Sets  the  supplementary group IDs for the process.  Appropriate
30              privileges (Linux: the CAP_SETGID capability) are required.
31

RETURN VALUE

33       getgroups()
34              On success, the number of supplementary group IDs  is  returned.
35              On error, -1 is returned, and errno is set appropriately.
36
37       setgroups()
38              On  success,  zero  is  returned.  On error, -1 is returned, and
39              errno is set appropriately.
40

ERRORS

42       EFAULT list has an invalid address.
43
44       EINVAL For setgroups(), size is greater  than  NGROUPS  (32  for  Linux
45              2.0.32).   For getgroups(), size is less than the number of sup‐
46              plementary group IDs, but is not zero.
47
48       EPERM  The calling process has  insufficient  privilege  to  call  set‐
49              groups().
50

NOTES

52       A  process  can have up to at least NGROUPS_MAX supplementary group IDs
53       in addition to the effective group ID. The set of  supplementary  group
54       IDs  is inherited from the parent process and may be changed using set‐
55       groups().  The maximum number of supplementary group IDs can  be  found
56       using sysconf(3):
57           long ngroups_max;
58           ngroups_max = sysconf(_SC_NGROUPS_MAX);
59       The  maximal return value of getgroups() cannot be larger than one more
60       than the value obtained this way.
61
62       The prototype for setgroups()  is  only  available  if  _BSD_SOURCE  is
63       defined.
64

CONFORMING TO

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

SEE ALSO

70       getgid(2), setgid(2), initgroups(3), capabilities(7)
71
72
73
74Linux 2.6.6                       2004-05-27                      GETGROUPS(2)
Impressum