1.\" $OpenBSD: setuid.2,v 1.10 2000/10/18 05:12:11 aaron Exp $ 2.\" $NetBSD: setuid.2,v 1.3 1995/02/27 12:37:06 cgd Exp $ 3.\" 4.\" Copyright (c) 1983, 1991, 1993 5.\" The Regents of the University of California. All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. All advertising materials mentioning features or use of this software 16.\" must display the following acknowledgement: 17.\" This product includes software developed by the University of 18.\" California, Berkeley and its contributors. 19.\" 4. Neither the name of the University nor the names of its contributors 20.\" may be used to endorse or promote products derived from this software 21.\" without specific prior written permission. 22.\" 23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33.\" SUCH DAMAGE. 34.\" 35.\" @(#)setuid.2 8.1 (Berkeley) 6/4/93 36.\" 37.Dd June 4, 1993 38.Dt SETUID 2 39.Os 40.Sh NAME 41.Nm setuid , 42.Nm seteuid , 43.Nm setgid , 44.Nm setegid 45.Nd set user and group ID 46.Sh SYNOPSIS 47.Fd #include <sys/types.h> 48.Fd #include <unistd.h> 49.Ft int 50.Fn setuid "uid_t uid" 51.Ft int 52.Fn seteuid "uid_t euid" 53.Ft int 54.Fn setgid "gid_t gid" 55.Ft int 56.Fn setegid "gid_t egid" 57.Sh DESCRIPTION 58The 59.Fn setuid 60function sets the real and effective user IDs and the saved set-user-ID 61of the current process to the specified value. 62The 63.Fn setuid 64function is permitted if the effective user ID is that of the superuser, 65or if the specified user ID is the same as the effective user ID. 66If not, but the specified user ID is the same as the real user ID, 67.Fn setuid 68will set the effective user ID to the real user ID. 69.Pp 70The 71.Fn setgid 72function sets the real and effective groups IDs and the saved set-group-ID 73of the current process to the specified value. 74The 75.Fn setgid 76function is permitted if the effective user ID is that of the superuser, 77or if the specified group ID is the same as the effective group ID. 78If not, but the specified group ID is the same as the real group ID, 79.Fn setgid 80will set the effective group ID to the real group ID. 81.Pp 82The 83.Fn seteuid 84function 85.Pq Fn setegid 86sets the effective user ID (group ID) of the current process. 87The effective user ID may be set to the value 88of the real user ID or the saved set-user-ID (see 89.Xr intro 2 90and 91.Xr execve 2 ) ; 92in this way, the effective user ID of a set-user-ID executable 93may be toggled by switching to the real user ID, then re-enabled 94by reverting to the set-user-ID value. 95Similarly, the effective group ID may be set to the value 96of the real group ID or the saved set-group-ID. 97.Sh RETURN VALUES 98Upon success, these functions return 0; 99otherwise \-1 is returned. 100.Pp 101If the user is not the superuser, or the UID 102specified is not the real, effective ID, or saved ID, 103these functions return \-1. 104.Sh SEE ALSO 105.Xr getgid 2 , 106.Xr getuid 2 , 107.Xr issetugid 2 108.Sh STANDARDS 109The 110.Fn setuid 111and 112.Fn setgid 113functions are compliant with the 114.St -p1003.1-90 115specification with 116.Li _POSIX_SAVED_IDS 117defined, with the extensions allowed in section B.4.2.2. 118The 119.Fn seteuid 120and 121.Fn setegid 122functions are extensions based on the 123.Tn POSIX 124concept of 125.Li _POSIX_SAVED_IDS , 126and have been proposed for a future revision of the standard. 127