1setreuid(2)                   System Calls Manual                  setreuid(2)
2
3
4

NAME

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

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

VERSIONS

77       POS