]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/setfsgid.2
execve.2, setfsgid.2, setfsuid.2, splice.2, fopen.3, malloc_trim.3, posix_memalign...
[thirdparty/man-pages.git] / man2 / setfsgid.2
1 .\" Copyright (C) 1995, Thomas K. Dyas <tdyas@eden.rutgers.edu>
2 .\" and Copyright (C) 2019, 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 .\" Created 1995-08-06 Thomas K. Dyas <tdyas@eden.rutgers.edu>
27 .\" Modified 2000-07-01 aeb
28 .\" Modified 2002-07-23 aeb
29 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
30 .\" Added notes on capability requirements
31 .\"
32 .TH SETFSGID 2 2019-05-09 "Linux" "Linux Programmer's Manual"
33 .SH NAME
34 setfsgid \- set group identity used for filesystem checks
35 .SH SYNOPSIS
36 .B #include <sys/fsuid.h>
37 .PP
38 .BI "int setfsgid(uid_t " fsgid );
39 .SH DESCRIPTION
40 On Linux, a process has both a filesystem group ID and an effective group ID.
41 The (Linux-specific) filesystem group ID is used
42 for permissions checking when accessing filesystem objects,
43 while the effective group ID is used for some other kinds
44 of permissions checks (see
45 .BR credentials (7)).
46 .PP
47 Normally, the value of the process's filesystem group ID
48 is the same as the value of its effective group ID.
49 This is so, because whenever a process's effective group ID is changed,
50 the kernel also changes the filesystem group ID to be the same as
51 the new value of the effective group ID.
52 A process can cause the value of its filesystem group ID to diverge
53 from its effective group ID by using
54 .BR setfsgid ()
55 to change its filesystem group ID to the value given in
56 .IR fsgid .
57 .PP
58 .BR setfsgid ()
59 will succeed only if the caller is the superuser or if
60 .I fsgid
61 matches either the caller's real group ID, effective group ID,
62 saved set-group-ID, or current the filesystem user ID.
63 .SH RETURN VALUE
64 On both success and failure,
65 this call returns the previous filesystem group ID of the caller.
66 .SH VERSIONS
67 This system call is present in Linux since version 1.2.
68 .\" This system call is present since Linux 1.1.44
69 .\" and in libc since libc 4.7.6.
70 .SH CONFORMING TO
71 .BR setfsgid ()
72 is Linux-specific and should not be used in programs intended
73 to be portable.
74 .SH NOTES
75 The filesystem group ID concept and the
76 .BR setfsgid ()
77 system call were invented for historical reasons that are
78 no longer applicable on modern Linux kernels.
79 See
80 .BR setfsuid (2)
81 for a discussion of why the use of both
82 .BR setfsuid (2)
83 and
84 .BR setfsgid ()
85 is nowadays unneeded.
86 .PP
87 The original Linux
88 .BR setfsgid ()
89 system call supported only 16-bit group IDs.
90 Subsequently, Linux 2.4 added
91 .BR setfsgid32 ()
92 supporting 32-bit IDs.
93 The glibc
94 .BR setfsgid ()
95 wrapper function transparently deals with the variation across kernel versions.
96 .SS C library/kernel differences
97 In glibc 2.15 and earlier,
98 when the wrapper for this system call determines that the argument can't be
99 passed to the kernel without integer truncation (because the kernel
100 is old and does not support 32-bit group IDs),
101 it will return \-1 and set \fIerrno\fP to
102 .B EINVAL
103 without attempting
104 the system call.
105 .SH BUGS
106 No error indications of any kind are returned to the caller,
107 and the fact that both successful and unsuccessful calls return
108 the same value makes it impossible to directly determine
109 whether the call succeeded or failed.
110 Instead, the caller must resort to looking at the return value
111 from a further call such as
112 .IR setfsgid(\-1)
113 (which will always fail), in order to determine if a preceding call to
114 .BR setfsgid ()
115 changed the filesystem group ID.
116 At the very
117 least,
118 .B EPERM
119 should be returned when the call fails (because the caller lacks the
120 .B CAP_SETGID
121 capability).
122 .SH SEE ALSO
123 .BR kill (2),
124 .BR setfsuid (2),
125 .BR capabilities (7),
126 .BR credentials (7)