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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

CONFORMING TO

75       POSIX.1-2001, POSIX.1-2008, 4.3BSD  (setreuid()  and  setregid()  firs