1SETUID(2) Linux Programmer's Manual SETUID(2)
2
3
4
6 setuid - set user identity
7
9 #include <sys/types.h>
10 #include <unistd.h>
11
12 int setuid(uid_t uid);
13
15 setuid() sets the effective user ID of the calling process. If the
16 effective UID of the caller is root, the real UID and saved set-user-ID
17 are also set.
18
19 Under Linux, setuid() is implemented like the POSIX version with the
20 _POSIX_SAVED_IDS feature. This allows a set-user-ID (other than root)
21 program to drop all of its user privileges, do some un-privileged work,
22 and then reengage the original effective user ID in a secure manner.
23
24 If the user is root or the program is set-user-ID-root, special care
25 must be taken. The setuid() function checks the effective user ID of
26 the caller and if it is the superuser, all process-related user ID's
27 are set to uid. After this has occurred, it is impossible for the pro‐
28 gram to regain root privileges.
29
30 Thus, a set-user-ID-root program wishing to temporarily drop root priv‐
31 ileges, assume the identity of an unprivileged user, and then regain
32 root privileges afterward cannot use setuid(). You can accomplish this
33 with seteuid(2).
34
36 On success, zero is returned. On error, -1 is returned, and errno is
37 set appropriately.
38
40 EAGAIN The uid does not match the current uid and uid brings process
41 over its RLIMIT_NPROC resource limit.
42
43 EPERM The user is not privileged (Linux: does not have the CAP_SETUID
44 capability) and uid does not match the real UID or saved set-
45 user-ID of the calling process.
46
48 SVr4, POSIX.1-2001. Not quite compatible with the 4.4BSD call, which
49 sets all of the real, saved, and effective user IDs.
50
52 Linux has the concept of the file system user ID, normally equal to the
53 effective user ID. The setuid() call also sets the file system user ID
54 of the calling process. See setfsuid(2).
55
56 If uid is different from the old effective UID, the process will be
57 forbidden from leaving core dumps.
58
59 The original Linux setuid() system call supported only 16-bit user IDs.
60 Subsequently, Linux 2.4 added setuid32() supporting 32-bit IDs. The
61 glibc setuid() wrapper function transparently deals with the variation
62 across kernel versions.
63
65 getuid(2), seteuid(2), setfsuid(2), setreuid(2), capabilities(7), cre‐
66 dentials(7)
67
69 This page is part of release 3.53 of the Linux man-pages project. A
70 description of the project, and information about reporting bugs, can
71 be found at http://www.kernel.org/doc/man-pages/.
72
73
74
75Linux 2010-11-22 SETUID(2)