xref: /csrg-svn/lib/libc/sys/setuid.2 (revision 61185)
1*61185Sbostic.\" Copyright (c) 1983, 1991, 1993
2*61185Sbostic.\"	The Regents of the University of California.  All rights reserved.
320588Smckusick.\"
448352Scael.\" %sccs.include.redist.man%
520588Smckusick.\"
6*61185Sbostic.\"     @(#)setuid.2	8.1 (Berkeley) 06/04/93
748352Scael.\"
848352Scael.Dd
957817Smckusick.Dt SETUID 2
1048352Scael.Os BSD 4.2
1148352Scael.Sh NAME
1248352Scael.Nm setuid ,
1348352Scael.Nm seteuid ,
1448352Scael.Nm setgid ,
1548352Scael.Nm setegid ,
1648352Scael.Nd set user and group ID
1748352Scael.Sh SYNOPSIS
1848352Scael.Fd #include <sys/types.h>
1953868Sbostic.Fd #include <unistd.h>
2048352Scael.Ft int
2148352Scael.Fn setuid "uid_t uid"
2248352Scael.Ft int
2348352Scael.Fn seteuid "uid_t euid"
2448352Scael.Ft int
2548352Scael.Fn setgid "gid_t gid"
2648352Scael.Ft int
2748352Scael.Fn setegid "gid_t egid"
2848352Scael.Sh DESCRIPTION
2948352ScaelThe
3048352Scael.Fn setuid
3148352Scaelfunction
3258266Smckusicksets the real and effective
3358266Smckusickuser IDs and the saved set-user-ID of the current process
3458266Smckusickto the specified value.
3558266SmckusickThe
3658266Smckusick.Fn setuid
3758266Smckusickfunction is permitted if the specified ID is equal to the real user ID
3858266Smckusickof the process, or if the effective user ID is that of the super user.
3948352Scael.Pp
4048352ScaelThe
4158266Smckusick.Fn setgid
4258266Smckusickfunction
4358266Smckusicksets the real and effective
4458266Smckusickgroup IDs and the saved set-group-ID of the current process
4558266Smckusickto the specified value.
4658266SmckusickThe
4758266Smckusick.Fn setgid
4858266Smckusickfunction is permitted if the specified ID is equal to the real group ID
4958266Smckusickof the process, or if the effective user ID is that of the super user.
5058266Smckusick.Pp
5158266SmckusickThe
5248352Scael.Fn seteuid
5348352Scaelfunction
5448352Scael.Pq Fn setegid
5520588Smckusicksets the effective user ID (group ID) of the
5620588Smckusickcurrent process.
5758266SmckusickThe effective user ID may be set to the value
5858266Smckusickof the real user ID or the saved set-user-ID (see
5958266Smckusick.Xr intro 2
6058266Smckusickand
6158266Smckusick.Xr execve 2 ) ;
6258266Smckusickin this way, the effective user ID of a set-user-ID executable
6358266Smckusickmay be toggled by switching to the real user ID, then re-enabled
6458266Smckusickby reverting to the set-user-ID value.
6558266SmckusickSimilarly, the effective group ID may be set to the value
6658266Smckusickof the real group ID or the saved set-user-ID.
6748352Scael.Pp
6848352Scael.Sh RETURN VALUES
6948352ScaelUpon success, these functions return 0;
7048352Scaelotherwise \-1 is returned.
7148352Scael.Pp
7248352ScaelIf the user is not the super user, or the uid
7357817Smckusickspecified is not the real, effective ID, or saved ID,
7457817Smckusickthese functions return \-1.
7548352Scael.Sh SEE ALSO
7648352Scael.Xr getuid 2 ,
7748352Scael.Xr getgid 2
7858266Smckusick.Sh STANDARDS
7958266SmckusickThe
8048352Scael.Fn setuid
8148352Scaeland
8248352Scael.Fn setgid
8358266Smckusickfunctions are compliant with the
8458266Smckusick.St -p1003.1-88
8558266Smckusickspecification with
8658266Smckusick.Li _POSIX_SAVED_IDS
8758266Smckusicknot defined.
8858266SmckusickThe
8958266Smckusick.Fn seteuid
9058266Smckusickand
9158266Smckusick.Fn setegid
9258266Smckusickfunctions are extensions based on the
9358266Smckusick.Tn POSIX
9458266Smckusickconcept of
9558266Smckusick.Li _POSIX_SAVED_IDS ,
9658266Smckusickand have been proposed for a future revision of the standard.
97