Start of man-pages-5.14: updating Changes and Changes.old
[man-pages.git] / man2 / seteuid.2
blobafab7ae8880394a01ec70c84c7f5d339728625f7
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 2021-03-22 "Linux" "Linux Programmer's Manual"
30 .SH NAME
31 seteuid, setegid \- set effective user or group ID
32 .SH SYNOPSIS
33 .nf
34 .B #include <unistd.h>
35 .PP
36 .BI "int seteuid(uid_t " euid );
37 .BI "int setegid(gid_t " egid );
38 .fi
39 .PP
40 .RS -4
41 Feature Test Macro Requirements for glibc (see
42 .BR feature_test_macros (7)):
43 .RE
44 .PP
45 .BR seteuid (),
46 .BR setegid ():
47 .nf
48     _POSIX_C_SOURCE >= 200112L
49         || /* Glibc <= 2.19: */ _BSD_SOURCE
50 .fi
51 .SH DESCRIPTION
52 .BR seteuid ()
53 sets the effective user ID of the calling process.
54 Unprivileged processes may only set the effective user ID to the
55 real user ID, the effective user ID or the saved set-user-ID.
56 .PP
57 Precisely the same holds for
58 .BR setegid ()
59 with "group" instead of "user".
60 .\" When
61 .\" .I euid
62 .\" equals \-1, nothing is changed.
63 .\" (This is an artifact of the implementation in glibc of seteuid()
64 .\" using setresuid(2).)
65 .SH RETURN VALUE
66 On success, zero is returned.
67 On error, \-1 is returned, and
68 .I errno
69 is set to indicate the error.
70 .PP
71 .IR Note :
72 there are cases where
73 .BR seteuid ()
74 can fail even when the caller is UID 0;
75 it is a grave security error to omit checking for a failure return from
76 .BR seteuid ().
77 .SH ERRORS
78 .TP
79 .B EINVAL
80 The target user or group ID is not valid in this user namespace.
81 .TP
82 .B EPERM
83 In the case of
84 .BR seteuid ():
85 the calling process is not privileged (does not have the
86 .BR CAP_SETUID
87 capability in its user namespace) and
88 .I euid
89 does not match the current real user ID, current effective user ID,
90 or current saved set-user-ID.
91 .IP
92 In the case of
93 .BR setegid ():
94 the calling process is not privileged (does not have the
95 .BR CAP_SETGID
96 capability in its user namespace) and
97 .I egid
98 does not match the current real group ID, current effective group ID,
99 or current saved set-group-ID.
100 .SH CONFORMING TO
101 POSIX.1-2001, POSIX.1-2008, 4.3BSD.
102 .SH NOTES
103 Setting the effective user (group) ID to the
104 saved set-user-ID (saved set-group-ID) is
105 possible since Linux 1.1.37 (1.1.38).
106 On an arbitrary system one should check
107 .BR _POSIX_SAVED_IDS .
109 Under glibc 2.0,
110 .BI seteuid( euid )
111 is equivalent to
112 .BI setreuid(\-1, " euid" )
113 and hence may change the saved set-user-ID.
114 Under glibc 2.1 and later, it is equivalent to
115 .BI setresuid(\-1, " euid" ", \-1)"
116 and hence does not change the saved set-user-ID.
117 Analogous remarks hold for
118 .BR setegid (),
119 with the difference that the change in implementation from
120 .BI setregid(\-1, " egid" )
122 .BI setresgid(\-1, " egid" ", \-1)"
123 occurred in glibc 2.2 or 2.3 (depending on the hardware architecture).
125 According to POSIX.1,
126 .BR seteuid ()
127 .RB ( setegid ())
128 need not permit
129 .I euid
130 .RI ( egid )
131 to be the same value as the current effective user (group) ID,
132 and some implementations do not permit this.
133 .SS C library/kernel differences
134 On Linux,
135 .BR seteuid ()
137 .BR setegid ()
138 are implemented as library functions that call, respectively,
139 .BR setreuid (2)
141 .BR setregid (2).
142 .SH SEE ALSO
143 .BR geteuid (2),
144 .BR setresuid (2),
145 .BR setreuid (2),
146 .BR setuid (2),
147 .BR capabilities (7),
148 .BR credentials (7),
149 .BR user_namespaces (7)