landlock_restrict_self.2: tfix
[man-pages.git] / man2 / seteuid.2
blobc78f8060943f9f30f36ca381db170498e4da38dc
1 .\" Copyright (C) 2001 Andries Brouwer (aeb@cwi.nl)
2 .\"
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
4 .\"
5 .\" [should really be seteuid.3]
6 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
7 .\"     Added notes on capability requirements
8 .\"
9 .TH SETEUID 2 2021-03-22 "Linux" "Linux Programmer's Manual"
10 .SH NAME
11 seteuid, setegid \- set effective user or group ID
12 .SH LIBRARY
13 Standard C library
14 .RI ( libc ", " \-lc )
15 .SH SYNOPSIS
16 .nf
17 .B #include <unistd.h>
18 .PP
19 .BI "int seteuid(uid_t " euid );
20 .BI "int setegid(gid_t " egid );
21 .fi
22 .PP
23 .RS -4
24 Feature Test Macro Requirements for glibc (see
25 .BR feature_test_macros (7)):
26 .RE
27 .PP
28 .BR seteuid (),
29 .BR setegid ():
30 .nf
31     _POSIX_C_SOURCE >= 200112L
32         || /* Glibc <= 2.19: */ _BSD_SOURCE
33 .fi
34 .SH DESCRIPTION
35 .BR seteuid ()
36 sets the effective user ID of the calling process.
37 Unprivileged processes may only set the effective user ID to the
38 real user ID, the effective user ID or the saved set-user-ID.
39 .PP
40 Precisely the same holds for
41 .BR setegid ()
42 with "group" instead of "user".
43 .\" When
44 .\" .I euid
45 .\" equals \-1, nothing is changed.
46 .\" (This is an artifact of the implementation in glibc of seteuid()
47 .\" using setresuid(2).)
48 .SH RETURN VALUE
49 On success, zero is returned.
50 On error, \-1 is returned, and
51 .I errno
52 is set to indicate the error.
53 .PP
54 .IR Note :
55 there are cases where
56 .BR seteuid ()
57 can fail even when the caller is UID 0;
58 it is a grave security error to omit checking for a failure return from
59 .BR seteuid ().
60 .SH ERRORS
61 .TP
62 .B EINVAL
63 The target user or group ID is not valid in this user namespace.
64 .TP
65 .B EPERM
66 In the case of
67 .BR seteuid ():
68 the calling process is not privileged (does not have the
69 .B CAP_SETUID
70 capability in its user namespace) and
71 .I euid
72 does not match the current real user ID, current effective user ID,
73 or current saved set-user-ID.
74 .IP
75 In the case of
76 .BR setegid ():
77 the calling process is not privileged (does not have the
78 .B CAP_SETGID
79 capability in its user namespace) and
80 .I egid
81 does not match the current real group ID, current effective group ID,
82 or current saved set-group-ID.
83 .SH STANDARDS
84 POSIX.1-2001, POSIX.1-2008, 4.3BSD.
85 .SH NOTES
86 Setting the effective user (group) ID to the
87 saved set-user-ID (saved set-group-ID) is
88 possible since Linux 1.1.37 (1.1.38).
89 On an arbitrary system one should check
90 .BR _POSIX_SAVED_IDS .
91 .PP
92 Under glibc 2.0,
93 .BI seteuid( euid )
94 is equivalent to
95 .BI setreuid(\-1, " euid" )
96 and hence may change the saved set-user-ID.
97 Under glibc 2.1 and later, it is equivalent to
98 .BI setresuid(\-1, " euid" ", \-1)"
99 and hence does not change the saved set-user-ID.
100 Analogous remarks hold for
101 .BR setegid (),
102 with the difference that the change in implementation from
103 .BI setregid(\-1, " egid" )
105 .BI setresgid(\-1, " egid" ", \-1)"
106 occurred in glibc 2.2 or 2.3 (depending on the hardware architecture).
108 According to POSIX.1,
109 .BR seteuid ()
110 .RB ( setegid ())
111 need not permit
112 .I euid
113 .RI ( egid )
114 to be the same value as the current effective user (group) ID,
115 and some implementations do not permit this.
116 .SS C library/kernel differences
117 On Linux,
118 .BR seteuid ()
120 .BR setegid ()
121 are implemented as library functions that call, respectively,
122 .BR setreuid (2)
124 .BR setregid (2).
125 .SH SEE ALSO
126 .BR geteuid (2),
127 .BR setresuid (2),
128 .BR setreuid (2),
129 .BR setuid (2),
130 .BR capabilities (7),
131 .BR credentials (7),
132 .BR user_namespaces (7)