Debian Codegraph @

upstream/debian-trixie/man2/setresuid.2

raw
1 .\" Copyright (C) 1997 Andries Brouwer ([email protected])
2 .\" and Copyright (C) 2005, 2010, 2014, 2015, Michael Kerrisk <[email protected]>
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .\" Modified, 2003-05-26, Michael Kerrisk, <[email protected]>
7 .TH setresuid 2 2024-05-02 "Linux man-pages 6.9.1"
8 .SH NAME
9 setresuid, setresgid \- set real, effective, and saved user or group ID
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ", " \-lc )
13 .SH SYNOPSIS
14 .nf
15 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
16 .B #include <unistd.h>
17 .P
18 .BI "int setresuid(uid_t " ruid ", uid_t " euid ", uid_t " suid );
19 .BI "int setresgid(gid_t " rgid ", gid_t " egid ", gid_t " sgid );
20 .fi
21 .SH DESCRIPTION
22 .BR setresuid ()
23 sets the real user ID, the effective user ID, and the
24 saved set-user-ID of the calling process.
25 .P
26 An unprivileged process may change its real UID,
27 effective UID, and saved set-user-ID, each to one of:
28 the current real UID, the current effective UID, or the
29 current saved set-user-ID.
30 .P
31 A privileged process (on Linux, one having the \fBCAP_SETUID\fP capability)
32 may set its real UID, effective UID, and
33 saved set-user-ID to arbitrary values.
34 .P
35 If one of the arguments equals \-1, the corresponding value is not changed.
36 .P
37 Regardless of what changes are made to the real UID, effective UID,
38 and saved set-user-ID, the filesystem UID is always set to the same
39 value as the (possibly new) effective UID.
40 .P
41 Completely analogously,
42 .BR setresgid ()
43 sets the real GID, effective GID, and saved set-group-ID
44 of the calling process (and always modifies the filesystem GID
45 to be the same as the effective GID),
46 with the same restrictions for unprivileged processes.
47 .SH RETURN VALUE
48 On success, zero is returned.
49 On error, \-1 is returned, and
50 .I errno
51 is set to indicate the error.
52 .P
53 .IR Note :
54 there are cases where
55 .BR setresuid ()
56 can fail even when the caller is UID 0;
57 it is a grave security error to omit checking for a failure return from
58 .BR setresuid ().
59 .SH ERRORS
60 .TP
61 .B EAGAIN
62 The call would change the caller's real UID (i.e.,
63 .I ruid
64 does not match the caller's real UID),
65 but there was a temporary failure allocating the
66 necessary kernel data structures.
67 .TP
68 .B EAGAIN
69 .I ruid
70 does not match the caller's real UID and this call would
71 bring the number of processes belonging to the real user ID
72 .I ruid
73 over the caller's
74 .B RLIMIT_NPROC
75 resource limit.
76 Since Linux 3.1, this error case no longer occurs
77 (but robust applications should check for this error);
78 see the description of
79 .B EAGAIN
80 in
81 .BR execve (2).
82 .TP
83 .B EINVAL
84 One or more of the target user or group IDs
85 is not valid in this user namespace.
86 .TP
87 .B EPERM
88 The calling process is not privileged (did not have the necessary
89 capability in its user namespace)
90 and tried to change the IDs to values that are not permitted.
91 For
92 .BR setresuid (),
93 the necessary capability is
94 .BR CAP_SETUID ;
95 for
96 .BR setresgid (),
97 it is
98 .BR CAP_SETGID .
99 .SH VERSIONS
100 .SS C library/kernel differences
101 At the kernel level, user IDs and group IDs are a per-thread attribute.
102 However, POSIX requires that all threads in a process
103 share the same credentials.
104 The NPTL threading implementation handles the POSIX requirements by
105 providing wrapper functions for
106 the various system calls that change process UIDs and GIDs.
107 These wrapper functions (including those for
108 .BR setresuid ()
109 and
110 .BR setresgid ())
111 employ a signal-based technique to ensure
112 that when one thread changes credentials,
113 all of the other threads in the process also change their credentials.
114 For details, see
115 .BR nptl (7).
116 .SH STANDARDS
117 None.
118 .SH HISTORY
119 Linux 2.1.44,
120 glibc 2.3.2.
121 HP-UX, FreeBSD.
122 .P
123 The original Linux
124 .BR setresuid ()
125 and
126 .BR setresgid ()
127 system calls supported only 16-bit user and group IDs.
128 Subsequently, Linux 2.4 added
129 .BR setresuid32 ()
130 and
131 .BR setresgid32 (),
132 supporting 32-bit IDs.
133 The glibc
134 .BR setresuid ()
135 and
136 .BR setresgid ()
137 wrapper functions transparently deal with the variations across kernel versions.
138 .SH SEE ALSO
139 .BR getresuid (2),
140 .BR getuid (2),
141 .BR setfsgid (2),
142 .BR setfsuid (2),
143 .BR setreuid (2),
144 .BR setuid (2),
145 .BR capabilities (7),
146 .BR credentials (7),
147 .BR user_namespaces (7)