Debian Codegraph @

upstream/debian-trixie/man2/seteuid.2

raw
1 .\" Copyright (C) 2001 Andries Brouwer ([email protected])
2 .\"
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
4 .\"
5 .\" [should really be seteuid.3]
6 .\" Modified, 27 May 2004, Michael Kerrisk <[email protected]>
7 .\" Added notes on capability requirements
8 .\"
9 .TH seteuid 2 2024-05-02 "Linux man-pages 6.9.1"
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 .P
19 .BI "int seteuid(uid_t " euid );
20 .BI "int setegid(gid_t " egid );
21 .fi
22 .P
23 .RS -4
24 Feature Test Macro Requirements for glibc (see
25 .BR feature_test_macros (7)):
26 .RE
27 .P
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 .P
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 .P
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 VERSIONS
84 Setting the effective user (group) ID to the
85 saved set-user-ID (saved set-group-ID) is
86 possible since Linux 1.1.37 (1.1.38).
87 On an arbitrary system one should check
88 .BR _POSIX_SAVED_IDS .
89 .P
90 Under glibc 2.0,
91 .BI seteuid( euid )
92 is equivalent to
93 .BI setreuid(\-1, " euid" )
94 and hence may change the saved set-user-ID.
95 Under glibc 2.1 and later, it is equivalent to
96 .BI setresuid(\-1, " euid" ", \-1)"
97 and hence does not change the saved set-user-ID.
98 Analogous remarks hold for
99 .BR setegid (),
100 with the difference that the change in implementation from
101 .BI setregid(\-1, " egid" )
102 to
103 .BI setresgid(\-1, " egid" ", \-1)"
104 occurred in glibc 2.2 or 2.3 (depending on the hardware architecture).
105 .P
106 According to POSIX.1,
107 .BR seteuid ()
108 .RB ( setegid ())
109 need not permit
110 .I euid
111 .RI ( egid )
112 to be the same value as the current effective user (group) ID,
113 and some implementations do not permit this.
114 .SS C library/kernel differences
115 On Linux,
116 .BR seteuid ()
117 and
118 .BR setegid ()
119 are implemented as library functions that call, respectively,
120 .BR setresuid (2)
121 and
122 .BR setresgid (2).
123 .SH STANDARDS
124 POSIX.1-2008.
125 .SH HISTORY
126 POSIX.1-2001, 4.3BSD.
127 .SH SEE ALSO
128 .BR geteuid (2),
129 .BR setresuid (2),
130 .BR setreuid (2),
131 .BR setuid (2),
132 .BR capabilities (7),
133 .BR credentials (7),
134 .BR user_namespaces (7)