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