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