1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
.\" Copyright (c) 1983, 1991 The Regents of the University of California.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)setregid.2 6.4 (Berkeley) 3/10/91
.\"
.\" Modified Sat Jul 24 09:08:49 1993 by Rik Faith <faith@cs.unc.edu>
.\" Portions extracted from linux/kernel/sys.c:
.\" Copyright (C) 1991, 1992 Linus Torvalds
.\" May be distributed under the GNU General Public License
.\" Changes: 1994-07-29 by Wilf <G.Wilford@ee.surrey.ac.uk>
.\" 1994-08-02 by Wilf due to change in kernel.
.\" 2004-07-04 by aeb
.\" 2004-05-27 by Michael Kerrisk
.\"
.TH SETREUID 2 2010-11-22 "Linux" "Linux Programmer's Manual"
.SH NAME
setreuid, setregid \- set real and/or effective user or group ID
.SH SYNOPSIS
.B #include <sys/types.h>
.br
.B #include <unistd.h>
.sp
.BI "int setreuid(uid_t " ruid ", uid_t " euid );
.br
.BI "int setregid(gid_t " rgid ", gid_t " egid );
.sp
.in -4n
Feature Test Macro Requirements for glibc (see
.BR feature_test_macros (7)):
.in
.sp
.BR setreuid (),
.BR setregid ():
.RS 4
.ad l
_BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
_XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
.ad
.RE
.SH DESCRIPTION
.BR setreuid ()
sets real and effective user IDs of the calling process.
Supplying a value of \-1 for either the real or effective user ID forces
the system to leave that ID unchanged.
Unprivileged processes may only set the effective user ID to the real user ID,
the effective user ID, or the saved set-user-ID.
Unprivileged users may only set the real user ID to
the real user ID or the effective user ID.
If the real user ID is set or the effective user ID is set to a value
not equal to the previous real user ID,
the saved set-user-ID will be set to the new effective user ID.
Completely analogously,
.BR setregid ()
sets real and effective group ID's of the calling process,
and all of the above holds with "group" instead of "user".
.SH "RETURN VALUE"
On success, zero is returned.
On error, \-1 is returned, and
.I errno
is set appropriately.
.SH ERRORS
.TP
.B EPERM
The calling process is not privileged
(Linux: does not have the
.B CAP_SETUID
capability in the case of
.BR setreuid (),
or the
.B CAP_SETGID
capability in the case of
.BR setregid ())
and a change other than (i)
swapping the effective user (group) ID with the real user (group) ID,
or (ii) setting one to the value of the other or (iii) setting the
effective user (group) ID to the value of the
saved set-user-ID (saved set-group-ID) was specified.
.SH "CONFORMING TO"
POSIX.1-2001, 4.3BSD (the
.BR setreuid ()
and
.BR setregid ()
function calls first appeared in 4.2BSD).
.SH NOTES
Setting the effective user (group) ID to the
saved set-user-ID (saved set-group-ID) is
possible since Linux 1.1.37 (1.1.38).
POSIX.1 does not specify all of possible ID changes that are permitted
on Linux for an unprivileged process.
For
.BR setreuid (),
the effective user ID can be made the same as the
real user ID or the save set-user-ID,
and it is unspecified whether unprivileged processes may set the
real user ID to the real user ID, the effective user ID, or the
saved set-user-ID.
For
.BR setregid (),
the real group ID can be changed to the value of the saved set-group-ID,
and the effective group ID can be changed to the value of
the real group ID or the saved set-group-ID.
The precise details of what ID changes are permitted vary
across implementations.
POSIX.1 makes no specification about the effect of these calls
on the saved set-user-ID and saved set-group-ID.
The original Linux
.BR setreuid ()
and
.BR setregid ()
system calls supported only 16-bit user and group IDs.
Subsequently, Linux 2.4 added
.BR setreuid32 ()
and
.BR setregid32 (),
supporting 32-bit IDs.
The glibc
.BR setreuid ()
and
.BR setregid ()
wrapper functions transparently deal with the variations across kernel versions.
.SH "SEE ALSO"
.BR getgid (2),
.BR getuid (2),
.BR seteuid (2),
.BR setgid (2),
.BR setresuid (2),
.BR setuid (2),
.BR capabilities (7)
|