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