]>
Commit | Line | Data |
---|---|---|
fea681da MK |
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. | |
305a0578 | 26 | .\" Modified, 27 May 2004, Michael Kerrisk <mtk-manpages@gmx.net> |
fea681da MK |
27 | .\" Added notes on capability requirements |
28 | .TH SETUID 2 2004-05-27 "Linux 2.6.6" "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 | |
e511ffb6 | 38 | .BR setuid () |
fea681da | 39 | sets the effective user ID of the current process. |
d9df8ff8 MK |
40 | If the effective UID of the caller is root, |
41 | the real UID and saved set-user-ID are also set. | |
fea681da MK |
42 | .PP |
43 | Under Linux, | |
e511ffb6 | 44 | .BR setuid () |
fea681da | 45 | is implemented like the POSIX version with the _POSIX_SAVED_IDS feature. |
880f5b4b | 46 | This allows a set-user-ID (other than root) program to drop all of its user |
fea681da MK |
47 | privileges, do some un-privileged work, and then re-engage the original |
48 | effective user ID in a secure manner. | |
49 | .PP | |
880f5b4b | 50 | If the user is root or the program is set-user-ID-root, special care must be |
fea681da | 51 | taken. The |
e511ffb6 | 52 | .BR setuid () |
d3c8b3e9 MK |
53 | function checks the effective user ID of the caller and if it is |
54 | the superuser, all process related user ID's are set to | |
fea681da MK |
55 | .IR uid . |
56 | After this has occurred, it is impossible for the program to regain root | |
57 | privileges. | |
58 | .PP | |
880f5b4b | 59 | Thus, a set-user-ID-root program wishing to temporarily drop root |
fea681da MK |
60 | privileges, assume the identity of a non-root user, and then regain |
61 | root privileges afterwards cannot use | |
e511ffb6 | 62 | .BR setuid (). |
fea681da | 63 | You can accomplish this with the (non-POSIX, BSD) call |
e1d6264d | 64 | .BR seteuid (). |
fea681da MK |
65 | .SH "RETURN VALUE" |
66 | On success, zero is returned. On error, \-1 is returned, and | |
67 | .I errno | |
68 | is set appropriately. | |
69 | .SH ERRORS | |
70 | .TP | |
71 | .B EAGAIN | |
72 | The | |
73 | .I uid | |
74 | does not match the current uid and | |
75 | .I uid | |
76 | brings process over it's NPROC rlimit. | |
77 | .TP | |
78 | .B EPERM | |
79 | The user is not privileged (Linux: does not have the | |
80 | .B CAP_SETUID | |
81 | capability) and | |
82 | .I uid | |
d9df8ff8 | 83 | does not match the real UID or saved set-user-ID of the calling process. |
fea681da | 84 | .SH "CONFORMING TO" |
97c1eac8 MK |
85 | SVr4, POSIX.1-2001. |
86 | Not quite compatible with the 4.4BSD call, which | |
87 | sets all of the real, saved, and effective user IDs. | |
88 | .\" SVr4 documents an additional EINVAL error condition. | |
fea681da MK |
89 | .SH "LINUX-SPECIFIC REMARKS" |
90 | Linux has the concept of filesystem user ID, normally equal to the | |
91 | effective user ID. The | |
e511ffb6 | 92 | .BR setuid () |
fea681da MK |
93 | call also sets the filesystem user ID of the current process. |
94 | See | |
95 | .BR setfsuid (2). | |
96 | .PP | |
97 | If | |
98 | .I uid | |
99 | is different from the old effective uid, the process will | |
100 | be forbidden from leaving core dumps. | |
101 | .SH "SEE ALSO" | |
102 | .BR getuid (2), | |
103 | .BR seteuid (2), | |
104 | .BR setfsuid (2), | |
105 | .BR setreuid (2), | |
106 | .BR capabilities (7) |