1SETRESUID(2) Linux Programmer's Manual SETRESUID(2)
2
3
4
6 setresuid, setresgid - set real, effective and saved user or group ID
7
9 #define _GNU_SOURCE /* See feature_test_macros(7) */
10 #include <unistd.h>
11
12 int setresuid(uid_t ruid, uid_t euid, uid_t suid);
13 int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
14
16 setresuid() sets the real user ID, the effective user ID, and the saved
17 set-user-ID of the calling process.
18
19 An unprivileged process may change its real UID, effective UID, and
20 saved set-user-ID, each to one of: the current real UID, the current
21 effective UID or the current saved set-user-ID.
22
23 A privileged process (on Linux, one having the CAP_SETUID capability)
24 may set its real UID, effective UID, and saved set-user-ID to arbitrary
25 values.
26
27 If one of the arguments equals -1, the corresponding value is not
28 changed.
29
30 Regardless of what changes are made to the real UID, effective UID, and
31 saved set-user-ID, the filesystem UID is always set to the same value
32 as the (possibly new) effective UID.
33
34 Completely analogously, setresgid() sets the real GID, effective GID,
35 and saved set-group-ID of the calling process (and always modifies the
36 filesystem GID to be the same as the effective GID), with the same
37 restrictions for unprivileged processes.
38
40 On success, zero is returned. On error, -1 is returned, and errno is
41 set appropriately.
42
43 Note: there are cases where setresuid() can fail even when the caller
44 is UID 0; it is a grave security error to omit checking for a failure
45 return from setresuid().
46
48 EAGAIN The call would change the caller's real UID (i.e., ruid does not
49 match the caller's real UID), but there was a temporary failure
50 allocating the necessary kernel data structures.
51
52 EAGAIN ruid does not match the caller's real UID and this call would
53 bring the number of processes belonging to the real user ID ruid
54 over the caller's RLIMIT_NPROC resource limit. Since Linux 3.1,
55 this error case no longer occurs (but robust applications should
56 check for this error); see the description of EAGAIN in
57 execve(2).
58
59 EINVAL One or more of the target user or group IDs is not valid in this
60 user namespace.
61
62 EPERM The calling process is not privileged (did not have the neces‐
63 sary capability in its user namespace) and tried to change the
64 IDs to values that are not permitted. For setresuid(), the nec‐
65 essary capability is CAP_SETUID; for setresgid(), it is CAP_SET‐
66 GID.
67
69 These calls are available under Linux since Linux 2.1.44.
70
72 These calls are nonstandard; they also appear on HP-UX and some of the
73 BSDs.
74
76 Under HP-UX and FreeBSD, the prototype is found in <unistd.h>. Under
77 Linux, the prototype is provided by glibc since version 2.3.2.
78
79 The original Linux setresuid() and setresgid() system calls supported
80 only 16-bit user and group IDs. Subsequently, Linux 2.4 added setre‐
81 suid32() and setresgid32(), supporting 32-bit IDs. The glibc setre‐
82 suid() and setresgid() wrapper functions transparently deal with the
83 variations across kernel versions.
84
85 C library/kernel differences
86 At the kernel level, user IDs and group IDs are a per-thread attribute.
87 However, POSIX requires that all threads in a process share the same
88 credentials. The NPTL threading implementation handles the POSIX
89 requirements by providing wrapper functions for the various system
90 calls that change process UIDs and GIDs. These wrapper functions
91 (including those for setresuid() and setresgid()) employ a signal-based
92 technique to ensure that when one thread changes credentials, all of
93 the other threads in the process also change their credentials. For
94 details, see nptl(7).
95
97 getresuid(2), getuid(2), setfsgid(2), setfsuid(2), setreuid(2),
98 setuid(2), capabilities(7), credentials(7), user_namespaces(7)
99
101 This page is part of release 5.07 of the Linux man-pages project. A
102 description of the project, information about reporting bugs, and the
103 latest version of this page, can be found at
104 https://www.kernel.org/doc/man-pages/.
105
106
107
108Linux 2017-09-15 SETRESUID(2)