1.\" Copyright (c) 1983, 1991 Regents of the University of California. 2.\" 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.\" from: @(#)setuid.3 6.4 (Berkeley) 4/19/91 33.\" $Id: setuid.2,v 1.2 1994/04/10 00:16:58 cgd Exp $ 34.\" 35.Dd April 19, 1991 36.Dt SETUID 2 37.Os BSD 4.2 38.Sh NAME 39.Nm setuid , 40.Nm seteuid , 41.Nm setgid , 42.Nm setegid 43.Nd set user and group ID 44.Sh SYNOPSIS 45.Fd #include <sys/types.h> 46.Fd #include <unistd.h> 47.Ft int 48.Fn setuid "uid_t uid" 49.Ft int 50.Fn seteuid "uid_t euid" 51.Ft int 52.Fn setgid "gid_t gid" 53.Ft int 54.Fn setegid "gid_t egid" 55.Sh DESCRIPTION 56The 57.Fn setuid 58function sets the real and effective user IDs and the saved 59set-user-ID of the current process to the specified value. The 60.Fn setuid 61function is permitted if the specified ID is equal to the real user ID of 62the process, or if the effective user ID is that of the super user. 63.Pp 64The 65.Fn setgid 66function sets the real and effective group IDs and the saved 67set-group-ID of the current process to the specified value. The 68.Fn setgid 69function is permitted if the specified ID is equal to the real group ID 70of the process, or if the effective user ID is that of the super user. 71.Pp 72The 73.Fn seteuid 74function sets the effective user ID 75of the current process. The effective user ID may be set to the value of 76the real user ID or the saved set-user-ID (see 77.Xr intro 2 78and 79.Xr execve 2 ); 80in this way, the effective user ID of a set-user-ID executable may be 81toggled by switching to the real user ID, then re-enabled by reverting to 82the set-user-ID value. 83Similarly, with 84.Fn setegid 85the effective group ID may be set to 86the value of the real group ID or the saved set-user-ID. 87.Sh RETURN VALUES 88Upon success, these functions return 0; 89otherwise \-1 is returned. 90.Pp 91If the user is not the super user, or the uid (gid) specified is not 92the real ID, effective ID, or saved ID of the process, 93these functions return \-1. 94.Sh SEE ALSO 95.Xr getuid 2 , 96.Xr getgid 2 97.Sh HISTORY 98The 99.Fn setuid 100and 101.Fn setgid 102functions are compliant with the 103.St -p1003.1-88 104specification with 105.Li _POSIX_SAVED_IDS 106not defined. 107The 108.Fn seteuid 109and 110.Fn setegid 111functions are extensions based on the 112.Tn POSIX 113concept of 114.Li _POSIX_SAVED_IDS , 115and have been proposed for a future revision of the standard. 116