]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/setgid.2
fuse.4: ffix
[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 2017-09-15 "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 .PP
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 calling process is privileged (more precisely: has the
43 .B CAP_SETGID
44 capability in its user namespace),
45 the real GID and saved set-group-ID are also set.
46 .PP
47 Under Linux,
48 .BR setgid ()
49 is implemented like the POSIX version with the
50 .B _POSIX_SAVED_IDS
51 feature.
52 This allows a set-group-ID program that is not set-user-ID-root
53 to drop all of its group
54 privileges, do some un-privileged work, and then reengage the original
55 effective group ID in a secure manner.
56 .SH RETURN VALUE
57 On success, zero is returned.
58 On error, \-1 is returned, and
59 .I errno
60 is set appropriately.
61 .SH ERRORS
62 .TP
63 .B EINVAL
64 The group ID specified in
65 .I gid
66 is not valid in this user namespace.
67 .TP
68 .B EPERM
69 The calling process is not privileged (does not have the
70 \fBCAP_SETGID\fP capability in its user namespace), and
71 .I gid
72 does not match the real group ID or saved set-group-ID of
73 the calling process.
74 .SH CONFORMING TO
75 POSIX.1-2001, POSIX.1-2008, SVr4.
76 .SH NOTES
77 The original Linux
78 .BR setgid ()
79 system call supported only 16-bit group IDs.
80 Subsequently, Linux 2.4 added
81 .BR setgid32 ()
82 supporting 32-bit IDs.
83 The glibc
84 .BR setgid ()
85 wrapper function transparently deals with the variation across kernel versions.
86 .\"
87 .SS C library/kernel differences
88 At the kernel level, user IDs and group IDs are a per-thread attribute.
89 However, POSIX requires that all threads in a process
90 share the same credentials.
91 The NPTL threading implementation handles the POSIX requirements by
92 providing wrapper functions for
93 the various system calls that change process UIDs and GIDs.
94 These wrapper functions (including the one for
95 .BR setgid ())
96 employ a signal-based technique to ensure
97 that when one thread changes credentials,
98 all of the other threads in the process also change their credentials.
99 For details, see
100 .BR nptl (7).
101 .SH SEE ALSO
102 .BR getgid (2),
103 .BR setegid (2),
104 .BR setregid (2),
105 .BR capabilities (7),
106 .BR credentials (7),
107 .BR user_namespaces (7)