xref: /openbsd/lib/libc/sys/setreuid.2 (revision 898184e3)
1.\"	$OpenBSD: setreuid.2,v 1.8 2012/06/26 21:27:44 tedu 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: June 26 2012 $
33.Dt SETREUID 2
34.Os
35.Sh NAME
36.Nm setreuid
37.Nd set real and effective user IDs
38.Sh SYNOPSIS
39.Fd #include <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 effective user ID is changed to a value other than 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
72Upon successful completion, a value of 0 is returned.
73Otherwise, a value of -1 is returned and
74.Va errno
75is set to indicate the error.
76.Sh ERRORS
77.Bl -tag -width Er
78.It Bq Er EPERM
79The current process is not the superuser and a change
80other than changing the effective user ID to the real user ID
81was specified.
82.El
83.Sh SEE ALSO
84.Xr getuid 2 ,
85.Xr seteuid 2 ,
86.Xr setregid 2 ,
87.Xr setresuid 2 ,
88.Xr setuid 2
89.Sh STANDARDS
90The
91.Fn setreuid
92function conforms to the
93.St -p1003.1-2001
94and
95.St -xpg4.3
96specifications.
97.Sh HISTORY
98The
99.Fn setreuid
100function call appeared in
101.Bx 4.2 .
102A semantically different version appeared in
103.Bx 4.4 .
104The current version, with the original semantics restored, appeared in
105.Ox 3.3 .
106.Sh CAVEATS
107The
108.Fn setreuid
109function predates
110.Tn POSIX
111saved user IDs.
112This implementation changes the saved user ID to the new value of
113the real user ID only if the real user ID is specified and either
114changed
115or the effective user ID is changed to a value other than the current
116saved user ID.
117Other implementations may behave differently.
118