1SETREUID(3P) POSIX Programmer's Manual SETREUID(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 setreuid — set real and effective user IDs
13
15 #include <unistd.h>
16
17 int setreuid(uid_t ruid, uid_t euid);
18
20 The setreuid() function shall set the real and effective user IDs of
21 the current process to the values specified by the ruid and euid argu‐
22 ments. If ruid or euid is -1, the corresponding effective or real user
23 ID of the current process shall be left unchanged.
24
25 A process with appropriate privileges can set either ID to any value.
26 An unprivileged process can only set the effective user ID if the euid
27 argument is equal to either the real, effective, or saved user ID of
28 the process.
29
30 If the real user ID is being set (ruid is not -1), or the effective
31 user ID is being set to a value not equal to the real user ID, then the
32 saved set-user-ID of the current process shall be set equal to the new
33 effective user ID.
34
35 It is unspecified whether a process without appropriate privileges is
36 permitted to change the real user ID to match the current effective
37 user ID or saved set-user-ID of the process.
38
40 Upon successful completion, 0 shall be returned. Otherwise, -1 shall be
41 returned and errno set to indicate the error.
42
44 The setreuid() function shall fail if:
45
46 EINVAL The value of the ruid or euid argument is invalid or out-of-
47 range.
48
49 EPERM The current process does not have appropriate privileges, and
50 either an attempt was made to change the effective user ID to a
51 value other than the real user ID or the saved set-user-ID or an
52 attempt was made to change the real user ID to a value not per‐
53 mitted by the implementation.
54
55 The following sections are informative.
56
58 Setting the Effective User ID to the Real User ID
59 The following example sets the effective user ID of the calling process
60 to the real user ID, so that files created later will be owned by the
61 current user. It also sets the saved set-user-ID to the real user ID,
62 so any future attempt to set the effective user ID back to its previous
63 value will fail.
64
65
66 #include <unistd.h>
67 #include <sys/types.h>
68 ...
69 setreuid(getuid(), getuid());
70 ...
71
73 None.
74
76 Earlier versions of this standard did not specify whether the saved
77 set-user-ID was affected by setreuid() calls. This version specifies
78 common existing practice that constitutes an important security fea‐
79 ture. The ability to set both the effective user ID and saved set-user-
80 ID to be the same as the real user ID means that any security weakness
81 in code that is executed after that point cannot result in malicious
82 code being executed with the previous effective user ID. Privileged
83 applications could already do this using just setuid(), but for non-
84 privileged applications the only standard method available is to use
85 this feature of setreuid().
86
88 None.
89
91 getegid(), geteuid(), getgid(), getuid(), setegid(), seteuid(), set‐
92 gid(), setregid(), setuid()
93
94 The Base Definitions volume of POSIX.1‐2017, <unistd.h>
95
97 Portions of this text are reprinted and reproduced in electronic form
98 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
99 table Operating System Interface (POSIX), The Open Group Base Specifi‐
100 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
101 Electrical and Electronics Engineers, Inc and The Open Group. In the
102 event of any discrepancy between this version and the original IEEE and
103 The Open Group Standard, the original IEEE and The Open Group Standard
104 is the referee document. The original Standard can be obtained online
105 at http://www.opengroup.org/unix/online.html .
106
107 Any typographical or formatting errors that appear in this page are
108 most likely to have been introduced during the conversion of the source
109 files to man page format. To report such errors, see https://www.ker‐
110 nel.org/doc/man-pages/reporting_bugs.html .
111
112
113
114IEEE/The Open Group 2017 SETREUID(3P)