OSDN Git Service

ee11a2f97dc4da7bb7bc61abb075b30d15785b40
[linuxjm/LDP_man-pages.git] / original / 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 2014-09-21 "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 .sp
37 .BI "int seteuid(uid_t " euid );
38 .br
39 .BI "int setegid(gid_t " egid );
40 .sp
41 .in -4n
42 Feature Test Macro Requirements for glibc (see
43 .BR feature_test_macros (7)):
44 .in
45 .sp
46 .ad l
47 .BR seteuid (),
48 .BR setegid ():
49 .RS 4
50 _BSD_SOURCE || _POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600
51 .RE
52 .ad
53 .SH DESCRIPTION
54 .BR seteuid ()
55 sets the effective user ID of the calling process.
56 Unprivileged user processes may only set the effective user ID to the
57 real user ID, the effective user ID or the saved set-user-ID.
58
59 Precisely the same holds for
60 .BR setegid ()
61 with "group" instead of "user".
62 .\" When
63 .\" .I euid
64 .\" equals \-1, nothing is changed.
65 .\" (This is an artifact of the implementation in glibc of seteuid()
66 .\" using setresuid(2).)
67 .SH RETURN VALUE
68 On success, zero is returned.
69 On error, \-1 is returned, and
70 .I errno
71 is set appropriately.
72
73 .IR Note :
74 there are cases where
75 .BR seteuid ()
76 can fail even when the caller is UID 0;
77 it is a grave security error to omit checking for a failure return from
78 .BR seteuid ().
79 .SH ERRORS
80 .TP
81 .B EINVAL
82 The target user or group ID is not valid in this user namespace.
83 .TP
84 .B EPERM
85 The calling process is not privileged (Linux: does not have the
86 .B CAP_SETUID
87 capability in the case of
88 .BR seteuid (),
89 or the
90 .B CAP_SETGID
91 capability in the case of
92 .BR setegid ())
93 and
94 .I euid
95 (respectively,
96 .IR egid )
97 is not the real user (group) ID, the effective user (group) ID,
98 or the saved set-user-ID (saved set-group-ID).
99 .SH CONFORMING TO
100 4.3BSD, POSIX.1-2001.
101 .SH NOTES
102 Setting the effective user (group) ID to the
103 saved set-user-ID (saved set-group-ID) is
104 possible since Linux 1.1.37 (1.1.38).
105 On an arbitrary system one should check
106 .BR _POSIX_SAVED_IDS .
107 .LP
108 Under glibc 2.0
109 .BI seteuid( euid )
110 is equivalent to
111 .BI setreuid(\-1, " euid" )
112 and hence may change the saved set-user-ID.
113 Under glibc 2.1 and later it is equivalent to
114 .BI setresuid(\-1, " euid" ", \-1)"
115 and hence does not change the saved set-user-ID.
116 Analogous remarks hold for
117 .BR setegid (),
118 with the difference that the change in implementation from
119 .BI setregid(\-1, " egid" )
120 to
121 .BI setresgid(\-1, " egid" ", \-1)"
122 occurred in glibc 2.2 or 2.3 (depending on the hardware architecture).
123
124 According to POSIX.1,
125 .BR seteuid ()
126 .RB ( setegid ())
127 need not permit
128 .I euid
129 .RI ( egid )
130 to be the same value as the current effective user (group) ID,
131 and some implementations do not permit this.
132 .SS C library/kernel ABI differences
133 On Linux,
134 .BR seteuid ()
135 and
136 .BR setegid ()
137 are implemented as library functions that call, respectively,
138 .BR setreuid (2)
139 and
140 .BR setresgid (2).
141 .SH SEE ALSO
142 .BR geteuid (2),
143 .BR setresuid (2),
144 .BR setreuid (2),
145 .BR setuid (2),
146 .BR capabilities (7),
147 .BR credentials (7),
148 .BR user_namespaces (7)
149 .SH COLOPHON
150 This page is part of release 3.79 of the Linux
151 .I man-pages
152 project.
153 A description of the project,
154 information about reporting bugs,
155 and the latest version of this page,
156 can be found at
157 \%http://www.kernel.org/doc/man\-pages/.