]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/setgid.2
_exit.2, access.2, brk.2, chmod.2, clone.2, epoll_wait.2, eventfd.2, fork.2, getgroup...
[thirdparty/man-pages.git] / man2 / setgid.2
1 .\" Copyright (C), 1994, Graeme W. Wilford. (Wilf.)
2 .\" and Copyright (C) 2010, 2015, Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
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 .\" %%%LICENSE_END
25 .\"
26 .\" Fri Jul 29th 12:56:44 BST 1994 Wilf. <G.Wilford@ee.surrey.ac.uk>
27 .\" Modified 1997-01-31 by Eric S. Raymond <esr@thyrsus.com>
28 .\" Modified 2002-03-09 by aeb
29 .\"
30 .TH SETGID 2 2015-03-29 "Linux" "Linux Programmer's Manual"
31 .SH NAME
32 setgid \- set group identity
33 .SH SYNOPSIS
34 .B #include <sys/types.h>
35 .br
36 .B #include <unistd.h>
37 .sp
38 .BI "int setgid(gid_t " gid );
39 .SH DESCRIPTION
40 .BR setgid ()
41 sets the effective group ID of the calling process.
42 If the caller is privileged (has the
43 CAP_SETGID
44 capability), the real GID and saved set-group-ID are also set.
45
46 Under Linux,
47 .BR setgid ()
48 is implemented like the POSIX version with the
49 .B _POSIX_SAVED_IDS
50 feature.
51 This allows a set-group-ID program that is not set-user-ID-root
52 to drop all of its group
53 privileges, do some un-privileged work, and then reengage the original
54 effective group ID in a secure manner.
55 .SH RETURN VALUE
56 On success, zero is returned.
57 On error, \-1 is returned, and
58 .I errno
59 is set appropriately.
60 .SH ERRORS
61 .TP
62 .B EINVAL
63 The group ID specified in
64 .I gid
65 is not valid in this user namespace.
66 .TP
67 .B EPERM
68 The calling process is not privileged (does not have the
69 \fBCAP_SETGID\fP capability), and
70 .I gid
71 does not match the real group ID or saved set-group-ID of
72 the calling process.
73 .SH CONFORMING TO
74 SVr4, POSIX.1-2001.
75 .SH NOTES
76 The original Linux
77 .BR setgid ()
78 system call supported only 16-bit group IDs.
79 Subsequently, Linux 2.4 added
80 .BR setgid32 ()
81 supporting 32-bit IDs.
82 The glibc
83 .BR setgid ()
84 wrapper function transparently deals with the variation across kernel versions.
85 .\"
86 .SS C library/kernel differences
87 At the kernel level, user IDs and group IDs are a per-thread attribute.
88 However, POSIX requires that all threads in a process
89 share the same credentials.
90 The NPTL threading implementation handles the POSIX requirements by
91 providing wrapper functions for
92 the various system calls that change process UIDs and GIDs.
93 These wrapper functions (including the one for
94 .BR setgid ())
95 employ a signal-based technique to ensure
96 that when one thread changes credentials,
97 all of the other threads in the process also change their credentials.
98 For details, see
99 .BR nptl (7).
100 .SH SEE ALSO
101 .BR getgid (2),
102 .BR setegid (2),
103 .BR setregid (2),
104 .BR capabilities (7),
105 .BR credentials (7),
106 .BR user_namespaces (7)