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