1.\" $NetBSD: setreuid.2,v 1.17 2002/02/08 01:28:22 ross 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. If the real user ID 93is changed, the saved user ID is changed to the new value of the effective 94user 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. This purpose is now better served by the use of the 111.Fn seteuid 112function (see 113.Xr setuid 2 ) . 114.Pp 115When setting the real and effective user IDs to the same value, this 116function is equivalent to the 117.Fn setuid 118function. 119When setting only the effective user ID, this function is equivalent to 120the 121.Fn seteuid 122function. 123.Sh RETURN VALUES 124Upon successful completion, a value of 0 is returned. Otherwise, 125a value of -1 is returned and 126.Va errno 127is set to indicate the error. 128.Sh ERRORS 129.Bl -tag -width Er 130.It Bq Er EPERM 131The current process is not the super-user and a change 132other than changing the effective user-id to the real user-id 133was specified. 134.El 135.Sh SEE ALSO 136.Xr getuid 2 , 137.Xr seteuid 2 , 138.Xr setgid 2 , 139.Xr setuid 2 140.Sh HISTORY 141The 142.Fn setreuid 143function call appeared in 144.Bx 4.2 . 145An incompatible version was implemented in 146.Bx 4.4 . 147It was reimplemented in 148.Nx 1.2 149in a way compatible with 150.Bx 4.3 , 151SunOS and Linux, but should not be used in new code. 152