xref: /openbsd/lib/libc/sys/setreuid.2 (revision 5af055cd)
1.\"	$OpenBSD: setreuid.2,v 1.12 2015/02/05 02:33:09 schwarze Exp $
2.\"
3.\" Copyright (c) 1980, 1991, 1993, 1994
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\"      @(#)setreuid.2	8.2 (Berkeley) 4/16/94
31.\"
32.Dd $Mdocdate: February 5 2015 $
33.Dt SETREUID 2
34.Os
35.Sh NAME
36.Nm setreuid
37.Nd set real and effective user IDs
38.Sh SYNOPSIS
39.In unistd.h
40.Ft int
41.Fn setreuid "uid_t ruid" "uid_t euid"
42.Sh DESCRIPTION
43The real and effective user IDs of the
44current process are set according to the arguments.
45The saved user ID will be set to the new value of the real
46user ID if a real user ID is specified and either
47the new real user ID value is different from the current value
48or the new value of the effective user ID differs from the
49current saved user ID.
50.Pp
51Unprivileged users may change either user ID to the current value
52of the real, effective, or saved user ID.
53Only the superuser may make other changes.
54.Pp
55Supplying a value of -1 for either the real or effective
56user ID forces the system to substitute the current
57ID in place of the -1 parameter.
58.Pp
59The
60.Fn setreuid
61function was intended to allow swapping the real and
62effective user IDs in set-user-ID programs to temporarily relinquish
63the set-user-ID value.
64This purpose is now better served by the use of the
65.Xr seteuid 2
66function.
67.Pp
68When setting the real and effective user IDs to the same value, the
69.Xr setuid 2
70function is preferred.
71.Sh RETURN VALUES
72.Rv -std
73.Sh ERRORS
74.Bl -tag -width Er
75.It Bq Er EPERM
76The current process is not the superuser and a change
77other than changing the effective user ID to the real user ID
78was specified.
79.El
80.Sh SEE ALSO
81.Xr getuid 2 ,
82.Xr seteuid 2 ,
83.Xr setregid 2 ,
84.Xr setresuid 2 ,
85.Xr setuid 2
86.Sh STANDARDS
87The
88.Fn setreuid
89function conforms to the
90.St -p1003.1-2008
91specification, except that the conditions for changing the saved
92user ID differ and that, if it is changed, the saved user ID
93is set to the real user ID instead of the effective user ID.
94.Sh HISTORY
95The
96.Fn setreuid
97system call first appeared in
98.Bx 4.1c ,
99predating POSIX.
100A semantically different version appeared in
101.Bx 4.4 .
102The current version, with the original semantics restored, appeared in
103.Ox 3.3 .
104