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

NAME

6       seteuid, setegid - set effective user or group ID
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <unistd.h>
11
12       int seteuid(uid_t euid);
13       int setegid(gid_t egid);
14
15   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
16
17       seteuid(), setegid():
18           _POSIX_C_SOURCE >= 200112L
19               || /* Glibc versions <= 2.19: */ _BSD_SOURCE
20

DESCRIPTION

22       seteuid()  sets the effective user ID of the calling process.  Unprivi‐
23       leged processes may only set the effective user ID to the real user ID,
24       the effective user ID or the saved set-user-ID.
25
26       Precisely the same holds for setegid() with "group" instead of "user".
27

RETURN VALUE

29       On  success,  zero is returned.  On error, -1 is returned, and errno is
30       set appropriately.
31
32       Note: there are cases where seteuid() can fail even when the caller  is
33       UID  0;  it  is  a  grave security error to omit checking for a failure
34       return from seteuid().
35

ERRORS

37       EINVAL The target user or group ID is not valid in this user namespace.
38
39       EPERM  In the case of seteuid(): the calling process is not  privileged
40              (does  not have the CAP_SETUID capability in its user namespace)
41              and euid does not match the current real user ID, current effec‐
42              tive user ID, or current saved set-user-ID.
43
44              In  the case of setegid(): the calling process is not privileged
45              (does not have the CAP_SETGID capability in its user  namespace)
46              and  egid  does  not  match  the  current real group ID, current
47              effective group ID, or current saved set-group-ID.
48

CONFORMING TO

50       POSIX.1-2001, POSIX.1-2008, 4.3BSD.
51

NOTES

53       Setting the effective user (group) ID to the saved  set-user-ID  (saved
54       set-group-ID) is possible since Linux 1.1.37 (1.1.38).  On an arbitrary
55       system one should check _POSIX_SAVED_IDS.
56
57       Under glibc 2.0, seteuid(euid) is equivalent to setreuid(-1, euid)  and
58       hence  may change the saved set-user-ID.  Under glibc 2.1 and later, it
59       is equivalent to setresuid(-1, euid, -1) and hence does not change  the
60       saved set-user-ID.  Analogous remarks hold for setegid(), with the dif‐
61       ference that the change in implementation from  setregid(-1,  egid)  to
62       setresgid(-1,  egid, -1) occurred in glibc 2.2 or 2.3 (depending on the
63       hardware architecture).
64
65       According to POSIX.1, seteuid() (setegid()) need not permit euid (egid)
66       to be the same value as the current effective user (group) ID, and some
67       implementations do not permit this.
68
69   C library/kernel differences
70       On Linux, seteuid() and setegid() are implemented as library  functions
71       that call, respectively, setreuid(2) and setregid(2).
72

SEE ALSO

74       geteuid(2), setresuid(2), setreuid(2), setuid(2), capabilities(7), cre‐
75       dentials(7), user_namespaces(7)
76

COLOPHON

78       This page is part of release 5.04 of the Linux  man-pages  project.   A
79       description  of  the project, information about reporting bugs, and the
80       latest    version    of    this    page,    can     be     found     at
81       https://www.kernel.org/doc/man-pages/.
82
83
84
85Linux                             2017-09-15                        SETEUID(2)
Impressum