]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/seteuid.2
Ready for 5.00
[thirdparty/man-pages.git] / man2 / seteuid.2
1 .\" Copyright (C) 2001 Andries Brouwer (aeb@cwi.nl)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" [should really be seteuid.3]
26 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
27 .\" Added notes on capability requirements
28 .\"
29 .TH SETEUID 2 2017-09-15 "Linux" "Linux Programmer's Manual"
30 .SH NAME
31 seteuid, setegid \- set effective user or group ID
32 .SH SYNOPSIS
33 .B #include <sys/types.h>
34 .br
35 .B #include <unistd.h>
36 .PP
37 .BI "int seteuid(uid_t " euid );
38 .br
39 .BI "int setegid(gid_t " egid );
40 .PP
41 .in -4n
42 Feature Test Macro Requirements for glibc (see
43 .BR feature_test_macros (7)):
44 .in
45 .PP
46 .ad l
47 .BR seteuid (),
48 .BR setegid ():
49 .RS 4
50 _POSIX_C_SOURCE\ >=\ 200112L
51 || /* Glibc versions <= 2.19: */ _BSD_SOURCE
52 .RE
53 .ad
54 .SH DESCRIPTION
55 .BR seteuid ()
56 sets the effective user ID of the calling process.
57 Unprivileged processes may only set the effective user ID to the
58 real user ID, the effective user ID or the saved set-user-ID.
59 .PP
60 Precisely the same holds for
61 .BR setegid ()
62 with "group" instead of "user".
63 .\" When
64 .\" .I euid
65 .\" equals \-1, nothing is changed.
66 .\" (This is an artifact of the implementation in glibc of seteuid()
67 .\" using setresuid(2).)
68 .SH RETURN VALUE
69 On success, zero is returned.
70 On error, \-1 is returned, and
71 .I errno
72 is set appropriately.
73 .PP
74 .IR Note :
75 there are cases where
76 .BR seteuid ()
77 can fail even when the caller is UID 0;
78 it is a grave security error to omit checking for a failure return from
79 .BR seteuid ().
80 .SH ERRORS
81 .TP
82 .B EINVAL
83 The target user or group ID is not valid in this user namespace.
84 .TP
85 .B EPERM
86 In the case of
87 .BR seteuid ():
88 the calling process is not privileged (does not have the
89 .BR CAP_SETUID
90 capability in its user namespace) and
91 .I euid
92 does not match the current real user ID, current effective user ID,
93 or current saved set-user-ID.
94 .IP
95 In the case of
96 .BR setegid ():
97 the calling process is not privileged (does not have the
98 .BR CAP_SETGID
99 capability in its user namespace) and
100 .I egid
101 does not match the current real group ID, current effective group ID,
102 or current saved set-group-ID.
103 .SH CONFORMING TO
104 POSIX.1-2001, POSIX.1-2008, 4.3BSD.
105 .SH NOTES
106 Setting the effective user (group) ID to the
107 saved set-user-ID (saved set-group-ID) is
108 possible since Linux 1.1.37 (1.1.38).
109 On an arbitrary system one should check
110 .BR _POSIX_SAVED_IDS .
111 .PP
112 Under glibc 2.0,
113 .BI seteuid( euid )
114 is equivalent to
115 .BI setreuid(\-1, " euid" )
116 and hence may change the saved set-user-ID.
117 Under glibc 2.1 and later, it is equivalent to
118 .BI setresuid(\-1, " euid" ", \-1)"
119 and hence does not change the saved set-user-ID.
120 Analogous remarks hold for
121 .BR setegid (),
122 with the difference that the change in implementation from
123 .BI setregid(\-1, " egid" )
124 to
125 .BI setresgid(\-1, " egid" ", \-1)"
126 occurred in glibc 2.2 or 2.3 (depending on the hardware architecture).
127 .PP
128 According to POSIX.1,
129 .BR seteuid ()
130 .RB ( setegid ())
131 need not permit
132 .I euid
133 .RI ( egid )
134 to be the same value as the current effective user (group) ID,
135 and some implementations do not permit this.
136 .SS C library/kernel differences
137 On Linux,
138 .BR seteuid ()
139 and
140 .BR setegid ()
141 are implemented as library functions that call, respectively,
142 .BR setreuid (2)
143 and
144 .BR setregid (2).
145 .SH SEE ALSO
146 .BR geteuid (2),
147 .BR setresuid (2),
148 .BR setreuid (2),
149 .BR setuid (2),
150 .BR capabilities (7),
151 .BR credentials (7),
152 .BR user_namespaces (7)