copyediting for Usenix manuals
[unix-history] / usr / src / lib / libc / sys / setuid.2
CommitLineData
15715acc
KB
1.\" Copyright (c) 1983, 1991, 1993
2.\" The Regents of the University of California. All rights reserved.
1d70186a 3.\"
ae59e04c 4.\" %sccs.include.redist.man%
1d70186a 5.\"
15715acc 6.\" @(#)setuid.2 8.1 (Berkeley) %G%
ae59e04c
CL
7.\"
8.Dd
d715e838 9.Dt SETUID 2
ae59e04c
CL
10.Os BSD 4.2
11.Sh NAME
12.Nm setuid ,
13.Nm seteuid ,
ae59e04c
CL
14.Nm setgid ,
15.Nm setegid ,
ae59e04c
CL
16.Nd set user and group ID
17.Sh SYNOPSIS
18.Fd #include <sys/types.h>
ec343852 19.Fd #include <unistd.h>
ae59e04c
CL
20.Ft int
21.Fn setuid "uid_t uid"
22.Ft int
23.Fn seteuid "uid_t euid"
24.Ft int
ae59e04c
CL
25.Fn setgid "gid_t gid"
26.Ft int
27.Fn setegid "gid_t egid"
ae59e04c
CL
28.Sh DESCRIPTION
29The
30.Fn setuid
31function
1435cb8b
KM
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.
ae59e04c
CL
50.Pp
51The
52.Fn seteuid
53function
54.Pq Fn setegid
1d70186a
KM
55sets the effective user ID (group ID) of the
56current process.
1435cb8b
KM
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.
ae59e04c 67.Pp
ae59e04c
CL
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
d715e838
KM
73specified is not the real, effective ID, or saved ID,
74these functions return \-1.
ae59e04c 75.Sh SEE ALSO
ae59e04c
CL
76.Xr getuid 2 ,
77.Xr getgid 2
1435cb8b
KM
78.Sh STANDARDS
79The
ae59e04c
CL
80.Fn setuid
81and
82.Fn setgid
1435cb8b
KM
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.