1SETRESUID(2)               Linux Programmer's Manual              SETRESUID(2)
2
3
4

NAME

6       setresuid, setresgid - set real, effective and saved user or group ID
7

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

VERSIONS

69       These calls are available under Linux since Linux 2.1.44.
70

CONFORMING TO

72       These  calls are nonstandard; they also appear on HP-UX and some of the
73       BSDs.
74

NOTES