man-pages/man2/getgroups.2

144 lines
3.9 KiB
Groff
Raw Normal View History

2004-11-03 13:51:07 +00:00
.\" Hey Emacs! This file is -*- nroff -*- source.
.\"
.\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu)
.\"
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one.
.\"
2004-11-03 13:51:07 +00:00
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date. The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein. The author(s) may not
.\" have taken the same level of care in the production of this manual,
.\" which is licensed free of charge, as they might when working
.\" professionally.
.\"
2004-11-03 13:51:07 +00:00
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\"
.\" Modified Thu Oct 31 12:04:29 1996 by Eric S. Raymond <esr@thyrsus.com>
2007-09-20 06:52:22 +00:00
.\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
2004-11-03 13:51:07 +00:00
.\" Added notes on capability requirements
.\"
.TH GETGROUPS 2 2008-06-02 "Linux" "Linux Programmer's Manual"
2004-11-03 13:51:07 +00:00
.SH NAME
getgroups, setgroups \- get/set list of supplementary group IDs
.SH SYNOPSIS
.B #include <sys/types.h>
.br
.B #include <unistd.h>
.sp
.BI "int getgroups(int " size ", gid_t " list []);
.sp
.B #include <grp.h>
.sp
.BI "int setgroups(size_t " size ", const gid_t *" list );
.sp
.in -4n
Feature Test Macro Requirements for glibc (see
.BR feature_test_macros (7)):
.in
.sp
.BR setgroups ():
_BSD_SOURCE
2004-11-03 13:51:07 +00:00
.SH DESCRIPTION
2008-04-23 15:36:48 +00:00
.\" FIXME. The layout of the DESCRIPTION and RETURN VALUE sections
.\" of this page are somewhat inconsistent.
2004-11-03 13:51:07 +00:00
.TP
.BR getgroups ()
2004-11-03 13:51:07 +00:00
Up to
.I size
supplementary group IDs (of the calling process) are returned in
.IR list .
It is unspecified whether the effective group ID of the calling process
is included in the returned list.
(Thus, an application should also call
2004-11-03 13:51:07 +00:00
.BR getegid (2)
and add or remove the resulting value.)
If
.I size
is zero,
.I list
is not modified, but the total number of supplementary group IDs for the
process is returned.
.TP
.BR setgroups ()
2004-11-03 13:51:07 +00:00
Sets the supplementary group IDs for the process.
Appropriate privileges (Linux: the
.B CAP_SETGID
capability) are required.
.SH "RETURN VALUE"
.TP
.BR getgroups ()
2004-11-03 13:51:07 +00:00
On success, the number of supplementary group IDs is returned.
On error, \-1 is returned, and
.I errno
is set appropriately.
.TP
.BR setgroups ()
On success, zero is returned.
On error, \-1 is returned, and
2004-11-03 13:51:07 +00:00
.I errno
is set appropriately.
.SH ERRORS
.TP
.B EFAULT
.I list
has an invalid address.
.TP
.B EINVAL
For
.BR setgroups (),
2004-11-03 13:51:07 +00:00
.I size
is greater than
.B NGROUPS_MAX
(32 before Linux 2.6.4; 65536 since Linux 2.6.4).
2004-11-03 13:51:07 +00:00
For
.BR getgroups (),
2004-11-03 13:51:07 +00:00
.I size
is less than the number of supplementary group IDs, but is not zero.
.TP
.B EPERM
The calling process has insufficient privilege to call
.BR setgroups ().
.SH "CONFORMING TO"
SVr4, 4.3BSD.
The
.BR getgroups ()
function is in POSIX.1-2001.
Since
.BR setgroups ()
requires privilege, it is not covered by POSIX.1-2001.
2004-11-03 13:51:07 +00:00
.SH NOTES
2007-06-22 17:16:20 +00:00
A process can have up to at least
.B NGROUPS_MAX
supplementary group IDs
in addition to the effective group ID.
The set of supplementary group IDs
2004-11-03 13:51:07 +00:00
is inherited from the parent process and may be changed using
.BR setgroups ().
2004-11-03 13:51:07 +00:00
The maximum number of supplementary group IDs can be found using
.BR sysconf (3):
.nf
2007-05-14 19:20:34 +00:00
2004-11-03 13:51:07 +00:00
long ngroups_max;
ngroups_max = sysconf(_SC_NGROUPS_MAX);
2007-05-14 19:20:34 +00:00
2004-11-03 13:51:07 +00:00
.fi
The maximal return value of
.BR getgroups ()
2004-11-03 13:51:07 +00:00
cannot be larger than one more than the value obtained this way.
.SH "SEE ALSO"
.BR getgid (2),
.BR setgid (2),
2008-05-04 18:31:25 +00:00
.BR getgrouplist (3),
2004-11-03 13:51:07 +00:00
.BR initgroups (3),
.BR capabilities (7),
.BR credentials (7)