xref: /netbsd/lib/libc/sys/setreuid.2 (revision c4a72b64)
1.\"	$NetBSD: setreuid.2,v 1.18 2002/10/01 18:10:45 wiz Exp $
2.\"
3.\" Copyright (c) 1998, 2000, 2001 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Charles M. Hannum.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"        This product includes software developed by the NetBSD
20.\"        Foundation, Inc. and its contributors.
21.\" 4. Neither the name of The NetBSD Foundation nor the names of its
22.\"    contributors may be used to endorse or promote products derived
23.\"    from this software without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35.\" POSSIBILITY OF SUCH DAMAGE.
36.\"
37.\"
38.\" Copyright (c) 1980, 1991 The Regents of the University of California.
39.\" All rights reserved.
40.\"
41.\" Redistribution and use in source and binary forms, with or without
42.\" modification, are permitted provided that the following conditions
43.\" are met:
44.\" 1. Redistributions of source code must retain the above copyright
45.\"    notice, this list of conditions and the following disclaimer.
46.\" 2. Redistributions in binary form must reproduce the above copyright
47.\"    notice, this list of conditions and the following disclaimer in the
48.\"    documentation and/or other materials provided with the distribution.
49.\" 3. All advertising materials mentioning features or use of this software
50.\"    must display the following acknowledgement:
51.\"	This product includes software developed by the University of
52.\"	California, Berkeley and its contributors.
53.\" 4. Neither the name of the University nor the names of its contributors
54.\"    may be used to endorse or promote products derived from this software
55.\"    without specific prior written permission.
56.\"
57.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
58.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
59.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
60.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
61.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
62.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
63.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
64.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
65.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
66.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
67.\" SUCH DAMAGE.
68.\"
69.\"     from: @(#)setreuid.2	6.4 (Berkeley) 3/10/91
70.\"
71.Dd January 5, 2001
72.Dt SETREUID 2
73.Os
74.Sh NAME
75.Nm setreuid
76.Nd set real and effective user ID's
77.Sh LIBRARY
78.Lb libc
79.Sh SYNOPSIS
80.Fd #include \*[Lt]unistd.h\*[Gt]
81.Ft int
82.Fn setreuid "uid_t ruid" "uid_t euid"
83.Sh DESCRIPTION
84.Bf -symbolic
85This interface is made obsolete by the saved ID functionality in
86.Xr setuid 2
87and
88.Xr seteuid 2 .
89.Ef
90.Pp
91The real and effective user ID's of the
92current process are set according to the arguments.
93If the real user ID is changed, the saved user ID is changed to the new
94value of the effective user ID.
95.Pp
96If
97.Fa ruid
98or
99.Fa euid
100is -1, the current uid is filled in by the system.
101Unprivileged users may change the real user
102ID to the effective user ID, and may change the effective user ID to the
103real user ID or the saved user ID; only the super-user may
104make other changes.
105.Pp
106The
107.Fn setreuid
108function has been used to swap the real and effective user
109IDs in set-user-ID programs to temporarily relinquish the set-user-ID
110value.
111This purpose is now better served by the use of the
112.Fn seteuid
113function (see
114.Xr setuid 2 ) .
115.Pp
116When setting the real and effective user IDs to the same value, this
117function is equivalent to the
118.Fn setuid
119function.
120When setting only the effective user ID, this function is equivalent to
121the
122.Fn seteuid
123function.
124.Sh RETURN VALUES
125Upon successful completion, a value of 0 is returned.
126Otherwise, a value of -1 is returned and
127.Va errno
128is set to indicate the error.
129.Sh ERRORS
130.Bl -tag -width Er
131.It Bq Er EPERM
132The current process is not the super-user and a change
133other than changing the effective user-id to the real user-id
134was specified.
135.El
136.Sh SEE ALSO
137.Xr getuid 2 ,
138.Xr seteuid 2 ,
139.Xr setgid 2 ,
140.Xr setuid 2
141.Sh HISTORY
142The
143.Fn setreuid
144function call appeared in
145.Bx 4.2 .
146An incompatible version was implemented in
147.Bx 4.4 .
148It was reimplemented in
149.Nx 1.2
150in a way compatible with
151.Bx 4.3 ,
152SunOS and Linux, but should not be used in new code.
153