1.\" Copyright (c) 1983, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" %sccs.include.redist.man% 5.\" 6.\" @(#)setuid.2 8.1 (Berkeley) 06/04/93 7.\" 8.Dd 9.Dt SETUID 2 10.Os BSD 4.2 11.Sh NAME 12.Nm setuid , 13.Nm seteuid , 14.Nm setgid , 15.Nm setegid , 16.Nd set user and group ID 17.Sh SYNOPSIS 18.Fd #include <sys/types.h> 19.Fd #include <unistd.h> 20.Ft int 21.Fn setuid "uid_t uid" 22.Ft int 23.Fn seteuid "uid_t euid" 24.Ft int 25.Fn setgid "gid_t gid" 26.Ft int 27.Fn setegid "gid_t egid" 28.Sh DESCRIPTION 29The 30.Fn setuid 31function 32sets the real and effective 33user IDs and the saved set-user-ID of the current process 34to the specified value. 35The 36.Fn setuid 37function is permitted if the specified ID is equal to the real user ID 38of the process, or if the effective user ID is that of the super user. 39.Pp 40The 41.Fn setgid 42function 43sets the real and effective 44group IDs and the saved set-group-ID of the current process 45to the specified value. 46The 47.Fn setgid 48function is permitted if the specified ID is equal to the real group ID 49of the process, or if the effective user ID is that of the super user. 50.Pp 51The 52.Fn seteuid 53function 54.Pq Fn setegid 55sets the effective user ID (group ID) of the 56current process. 57The effective user ID may be set to the value 58of the real user ID or the saved set-user-ID (see 59.Xr intro 2 60and 61.Xr execve 2 ) ; 62in this way, the effective user ID of a set-user-ID executable 63may be toggled by switching to the real user ID, then re-enabled 64by reverting to the set-user-ID value. 65Similarly, the effective group ID may be set to the value 66of the real group ID or the saved set-user-ID. 67.Pp 68.Sh RETURN VALUES 69Upon success, these functions return 0; 70otherwise \-1 is returned. 71.Pp 72If the user is not the super user, or the uid 73specified is not the real, effective ID, or saved ID, 74these functions return \-1. 75.Sh SEE ALSO 76.Xr getuid 2 , 77.Xr getgid 2 78.Sh STANDARDS 79The 80.Fn setuid 81and 82.Fn setgid 83functions are compliant with the 84.St -p1003.1-88 85specification with 86.Li _POSIX_SAVED_IDS 87not defined. 88The 89.Fn seteuid 90and 91.Fn setegid 92functions are extensions based on the 93.Tn POSIX 94concept of 95.Li _POSIX_SAVED_IDS , 96and have been proposed for a future revision of the standard. 97