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

NAME

6       setreuid, setregid - set real and/or effective user or group ID
7

SYNOPSIS

9       #include <unistd.h>
10
11       int setreuid(uid_t ruid, uid_t euid);
12       int setregid(gid_t rgid, gid_t egid);
13
14   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
15
16       setreuid(), setregid():
17           _XOPEN_SOURCE >= 500
18               || /* Since glibc 2.19: */ _DEFAULT_SOURCE
19               || /* Glibc <= 2.19: */ _BSD_SOURCE
20

DESCRIPTION

22       setreuid() sets real and effective user IDs of the calling process.
23
24       Supplying a value of -1 for either the real or effective user ID forces
25       the system to leave that ID unchanged.
26
27       Unprivileged processes may only set the effective user ID to  the  real
28       user ID, the effective user ID, or the saved set-user-ID.
29
30       Unprivileged users may only set the real user ID to the real user ID or
31       the effective user ID.
32
33       If the real user ID is set (i.e., ruid is not -1) or the effective user
34       ID  is set to a value not equal to the previous real user ID, the saved
35       set-user-ID will be set to the new effective user ID.
36
37       Completely analogously, setregid() sets real and effective  group  ID's
38       of the calling process, and all of the above holds with "group" instead
39       of "user".
40

RETURN VALUE

42       On success, zero is returned.  On error, -1 is returned, and  errno  is
43       set to indicate the error.
44
45       Note: there are cases where setreuid() can fail even when the caller is
46       UID 0; it is a grave security error to omit checking for a failure  re‐
47       turn from setreuid().
48

ERRORS

50       EAGAIN The call would change the caller's real UID (i.e., ruid does not
51              match the caller's real UID), but there was a temporary  failure
52              allocating the necessary kernel data structures.
53
54       EAGAIN ruid  does  not  match the caller's real UID and this call would
55              bring the number of processes belonging to the real user ID ruid
56              over the caller's RLIMIT_NPROC resource limit.  Since Linux 3.1,
57              this error case no longer occurs (but robust applications should
58              check  for  this  error);  see  the description of EAGAIN in ex‐
59              ecve(2).
60
61       EINVAL One or more of the target user or group IDs is not valid in this
62              user namespace.
63
64       EPERM  The  calling  process is not privileged (on Linux, does not have
65              the necessary capability in its user  namespace:  CAP_SETUID  in
66              the case of setreuid(), or CAP_SETGID in the case of setregid())
67              and a change other than (i) swapping the effective user  (group)
68              ID  with  the  real  user (group) ID, or (ii) setting one to the
69              value of the other or (iii) setting the effective  user  (group)
70              ID  to  the  value of the saved set-user-ID (saved set-group-ID)
71              was specified.
72

CONFORMING TO

74       POSIX.1-2001, POSIX.1-2008, 4.3BSD (setreuid() and setregid() first ap‐
75       peared in