OSDN Git Service

LDP: Update original to LDP v3.77
[linuxjm/LDP_man-pages.git] / original / man2 / setuid.2
1 .\" Copyright (C), 1994, Graeme W. Wilford (Wilf).
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 .\" Fri Jul 29th 12:56:44 BST 1994  Wilf. <G.Wilford@ee.surrey.ac.uk>
26 .\" Changes inspired by patch from Richard Kettlewell
27 .\"   <richard@greenend.org.uk>, aeb 970616.
28 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
29 .\"     Added notes on capability requirements
30 .TH SETUID 2 2014-09-21 "Linux" "Linux Programmer's Manual"
31 .SH NAME
32 setuid \- set user identity
33 .SH SYNOPSIS
34 .B #include <sys/types.h>
35 .br
36 .B #include <unistd.h>
37 .sp
38 .BI "int setuid(uid_t " uid );
39 .SH DESCRIPTION
40 .BR setuid ()
41 sets the effective user ID of the calling process.
42 If the effective UID of the caller is root,
43 the real UID and saved set-user-ID are also set.
44 .PP
45 Under Linux,
46 .BR setuid ()
47 is implemented like the POSIX version with the
48 .B _POSIX_SAVED_IDS
49 feature.
50 This allows a set-user-ID (other than root) program to drop all of its user
51 privileges, do some un-privileged work, and then reengage the original
52 effective user ID in a secure manner.
53 .PP
54 If the user is root or the program is set-user-ID-root, special care must be
55 taken.
56 The
57 .BR setuid ()
58 function checks the effective user ID of the caller and if it is
59 the superuser, all process-related user ID's are set to
60 .IR uid .
61 After this has occurred, it is impossible for the program to regain root
62 privileges.
63 .PP
64 Thus, a set-user-ID-root program wishing to temporarily drop root
65 privileges, assume the identity of an unprivileged user, and then regain
66 root privileges afterward cannot use
67 .BR setuid ().
68 You can accomplish this with
69 .BR seteuid (2).
70 .SH RETURN VALUE
71 On success, zero is returned.
72 On error, \-1 is returned, and
73 .I errno
74 is set appropriately.
75
76 .IR Note :
77 there are cases where
78 .BR setuid ()
79 can fail even when the caller is UID 0;
80 it is a grave security error to omit checking for a failure return from
81 .BR setuid ().
82 .SH ERRORS
83 .TP
84 .B EAGAIN
85 The call would change the caller's real UID (i.e.,
86 .I uid
87 does not match the caller's real UID),
88 but there was a temporary failure allocating the
89 necessary kernel data structures.
90 .TP
91 .B EAGAIN
92 .I uid
93 does not match the real user ID of the caller and this call would
94 bring the number of processes belonging to the real user ID
95 .I uid
96 over the caller's
97 .B RLIMIT_NPROC
98 resource limit.
99 Since Linux 3.1, this error case no longer occurs
100 (but robust applications should check for this error);
101 see the description of
102 .B EAGAIN
103 in
104 .BR execve (2).
105 .TP
106 .B EINVAL
107 The user ID specified in
108 .I uid
109 is not valid in this user namespace.
110 .TP
111 .B EPERM
112 The user is not privileged (Linux: does not have the
113 .B CAP_SETUID
114 capability) and
115 .I uid
116 does not match the real UID or saved set-user-ID of the calling process.
117 .SH CONFORMING TO
118 SVr4, POSIX.1-2001.
119 Not quite compatible with the 4.4BSD call, which
120 sets all of the real, saved, and effective user IDs.
121 .\" SVr4 documents an additional EINVAL error condition.
122 .SH NOTES
123 Linux has the concept of the filesystem user ID, normally equal to the
124 effective user ID.
125 The
126 .BR setuid ()
127 call also sets the filesystem user ID of the calling process.
128 See
129 .BR setfsuid (2).
130 .PP
131 If
132 .I uid
133 is different from the old effective UID, the process will
134 be forbidden from leaving core dumps.
135
136 The original Linux
137 .BR setuid ()
138 system call supported only 16-bit user IDs.
139 Subsequently, Linux 2.4 added
140 .BR setuid32 ()
141 supporting 32-bit IDs.
142 The glibc
143 .BR setuid ()
144 wrapper function transparently deals with the variation across kernel versions.
145 .SH SEE ALSO
146 .BR getuid (2),
147 .BR seteuid (2),
148 .BR setfsuid (2),
149 .BR setreuid (2),
150 .BR capabilities (7),
151 .BR credentials (7),
152 .BR user_namespaces (7)
153 .SH COLOPHON
154 This page is part of release 3.77 of the Linux
155 .I man-pages
156 project.
157 A description of the project,
158 information about reporting bugs,
159 and the latest version of this page,
160 can be found at
161 \%http://www.kernel.org/doc/man\-pages/.