1.\" $OpenBSD: setreuid.2,v 1.4 2004/01/25 14:48:32 jmc 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 January 29, 2003 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. 45If the real user ID is changed, or the effective user ID is changed 46to a value other than the real user ID, then the saved user ID will 47be set to the effective user ID. 48.Pp 49Unprivileged users may change either user ID to the current value 50of the real, effective, or saved user ID. 51Only the superuser may make other changes. 52.Pp 53Supplying a value of -1 for either the real or effective 54user ID forces the system to substitute the current 55ID in place of the -1 parameter. 56.Pp 57The 58.Fn setreuid 59function was intended to allow swapping the real and 60effective user IDs in set-user-ID programs to temporarily relinquish 61the set-user-ID value. 62This purpose is now better served by the use of the 63.Fn seteuid 64function (see 65.Xr setuid 2 ) . 66.Pp 67When setting the real and effective user IDs to the same value, the 68.Fn setuid 69function is preferred. 70.Sh RETURN VALUES 71Upon successful completion, a value of 0 is returned. 72Otherwise, a value of -1 is returned and 73.Va errno 74is set to indicate the error. 75.Sh ERRORS 76.Bl -tag -width Er 77.It Bq Er EPERM 78The current process is not the superuser and a change 79other than changing the effective user ID to the real user ID 80was specified. 81.El 82.Sh SEE ALSO 83.Xr getuid 2 , 84.Xr seteuid 2 , 85.Xr setresuid 2 , 86.Xr setuid 2 87.Sh STANDARDS 88The 89.Fn setreuid 90function conforms to the 91.St -p1003.1-2001 92and 93.St -xpg4.3 . 94specifications. 95.Pp 96Note, however, that prior to 97.St -p1003.1-2001 , 98the 99.Fn setreuid 100function was not a part of the 101.St -p1003.1 102specification. 103As a result, it may not be implemented on all systems. 104.Sh HISTORY 105The 106.Fn setreuid 107function call appeared in 108.Bx 4.2 . 109A semantically different version appeared in 110.Bx 4.4 . 111The current version, with the original semantics restored, appeared in 112.Ox 3.3 . 113.Sh CAVEATS 114The 115.Fn setreuid 116function predates 117.Tn POSIX 118saved user IDs. 119This implementation changes the saved user ID to the new value of 120the effective user ID if the real user ID is changed. 121Other implementations may behave differently. 122