]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/getgroups.2
ffix
[thirdparty/man-pages.git] / man2 / getgroups.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu)
4 .\"
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\"
25 .\" Modified Thu Oct 31 12:04:29 1996 by Eric S. Raymond <esr@thyrsus.com>
26 .\" Modified, 27 May 2004, Michael Kerrisk <mtk-manpages@gmx.net>
27 .\" Added notes on capability requirements
28 .\"
29 .TH GETGROUPS 2 2004-05-27 "Linux 2.6.6" "Linux Programmer's Manual"
30 .SH NAME
31 getgroups, setgroups \- get/set list of supplementary group IDs
32 .SH SYNOPSIS
33 .B #include <sys/types.h>
34 .br
35 .B #include <unistd.h>
36 .sp
37 .BI "int getgroups(int " size ", gid_t " list []);
38 .sp
39 .B #include <grp.h>
40 .sp
41 .BI "int setgroups(size_t " size ", const gid_t *" list );
42 .SH DESCRIPTION
43 .TP
44 .BR getgroups ()
45 Up to
46 .I size
47 supplementary group IDs (of the calling process) are returned in
48 .IR list .
49 It is unspecified whether the effective group ID of the calling process
50 is included in the returned list.
51 (Thus, an application should also call
52 .BR getegid (2)
53 and add or remove the resulting value.)
54 If
55 .I size
56 is zero,
57 .I list
58 is not modified, but the total number of supplementary group IDs for the
59 process is returned.
60 .TP
61 .BR setgroups ()
62 Sets the supplementary group IDs for the process.
63 Appropriate privileges (Linux: the
64 .B CAP_SETGID
65 capability) are required.
66 .SH "RETURN VALUE"
67 .TP
68 .BR getgroups ()
69 On success, the number of supplementary group IDs is returned.
70 On error, \-1 is returned, and
71 .I errno
72 is set appropriately.
73 .TP
74 .BR setgroups ()
75 On success, zero is returned.
76 On error, \-1 is returned, and
77 .I errno
78 is set appropriately.
79 .SH ERRORS
80 .TP
81 .B EFAULT
82 .I list
83 has an invalid address.
84 .TP
85 .B EINVAL
86 For
87 .BR setgroups (),
88 .I size
89 is greater than
90 .B NGROUPS
91 (32 for Linux 2.0.32).
92 For
93 .BR getgroups (),
94 .I size
95 is less than the number of supplementary group IDs, but is not zero.
96 .TP
97 .B EPERM
98 The calling process has insufficient privilege to call
99 .BR setgroups ().
100 .SH NOTES
101 A process can have up to at least NGROUPS_MAX supplementary group IDs
102 in addition to the effective group ID.
103 The set of supplementary group IDs
104 is inherited from the parent process and may be changed using
105 .BR setgroups ().
106 The maximum number of supplementary group IDs can be found using
107 .BR sysconf (3):
108 .nf
109
110 long ngroups_max;
111 ngroups_max = sysconf(_SC_NGROUPS_MAX);
112
113 .fi
114 The maximal return value of
115 .BR getgroups ()
116 cannot be larger than one more than the value obtained this way.
117 .LP
118 The prototype for
119 .BR setgroups ()
120 is only available if
121 .B _BSD_SOURCE
122 is defined.
123 .SH "CONFORMING TO"
124 SVr4, 4.3BSD.
125 The
126 .BR getgroups ()
127 function is in POSIX.1-2001.
128 Since
129 .BR setgroups ()
130 requires privilege, it is not covered by POSIX.1-2001.
131 .SH "SEE ALSO"
132 .BR getgid (2),
133 .BR setgid (2),
134 .BR initgroups (3),
135 .BR capabilities (7)