OSDN Git Service

(split) LDP man-pages の original/ を v3.29 に更新。
[linuxjm/LDP_man-pages.git] / original / man2 / setuid.2
1 .\" Copyright (C), 1994, Graeme W. Wilford (Wilf).
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" Fri Jul 29th 12:56:44 BST 1994  Wilf. <G.Wilford@ee.surrey.ac.uk>
24 .\" Changes inspired by patch from Richard Kettlewell
25 .\"   <richard@greenend.org.uk>, aeb 970616.
26 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
27 .\"     Added notes on capability requirements
28 .TH SETUID 2 2010-02-21 "Linux" "Linux Programmer's Manual"
29 .SH NAME
30 setuid \- set user identity
31 .SH SYNOPSIS
32 .B #include <sys/types.h>
33 .br
34 .B #include <unistd.h>
35 .sp
36 .BI "int setuid(uid_t " uid );
37 .SH DESCRIPTION
38 .BR setuid ()
39 sets the effective user ID of the calling process.
40 If the effective UID of the caller is root,
41 the real UID and saved set-user-ID are also set.
42 .PP
43 Under Linux,
44 .BR setuid ()
45 is implemented like the POSIX version with the
46 .B _POSIX_SAVED_IDS
47 feature.
48 This allows a set-user-ID (other than root) program to drop all of its user
49 privileges, do some un-privileged work, and then reengage the original
50 effective user ID in a secure manner.
51 .PP
52 If the user is root or the program is set-user-ID-root, special care must be
53 taken.
54 The
55 .BR setuid ()
56 function checks the effective user ID of the caller and if it is
57 the superuser, all process-related user ID's are set to
58 .IR uid .
59 After this has occurred, it is impossible for the program to regain root
60 privileges.
61 .PP
62 Thus, a set-user-ID-root program wishing to temporarily drop root
63 privileges, assume the identity of an unprivileged user, and then regain
64 root privileges afterward cannot use
65 .BR setuid ().
66 You can accomplish this with
67 .BR seteuid (2).
68 .SH "RETURN VALUE"
69 On success, zero is returned.
70 On error, \-1 is returned, and
71 .I errno
72 is set appropriately.
73 .SH ERRORS
74 .TP
75 .B EAGAIN
76 The
77 .I uid
78 does not match the current uid and
79 .I uid
80 brings process over its
81 .B RLIMIT_NPROC
82 resource limit.
83 .TP
84 .B EPERM
85 The user is not privileged (Linux: does not have the
86 .B CAP_SETUID
87 capability) and
88 .I uid
89 does not match the real UID or saved set-user-ID of the calling process.
90 .SH "CONFORMING TO"
91 SVr4, POSIX.1-2001.
92 Not quite compatible with the 4.4BSD call, which
93 sets all of the real, saved, and effective user IDs.
94 .\" SVr4 documents an additional EINVAL error condition.
95 .SH NOTES
96 .SS Linux Notes
97 Linux has the concept of file system user ID, normally equal to the
98 effective user ID.
99 The
100 .BR setuid ()
101 call also sets the file system user ID of the calling process.
102 See
103 .BR setfsuid (2).
104 .PP
105 If
106 .I uid
107 is different from the old effective uid, the process will
108 be forbidden from leaving core dumps.
109 .SH "SEE ALSO"
110 .BR getuid (2),
111 .BR seteuid (2),
112 .BR setfsuid (2),
113 .BR setreuid (2),
114 .BR capabilities (7),
115 .BR credentials (7)