Initial import from FreeBSD RELENG_4:
[dragonfly.git] / lib / libcr / sys / setuid.2
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 .\" $FreeBSD: src/lib/libc/sys/setuid.2,v 1.13.2.7 2003/02/14 00:49:42 keramida Exp $
34 .\"
35 .Dd June 4, 1993
36 .Dt SETUID 2
37 .Os
38 .Sh NAME
39 .Nm setuid ,
40 .Nm seteuid ,
41 .Nm setgid ,
42 .Nm setegid ,
43 .Nd set user and group ID
44 .Sh LIBRARY
45 .Lb libc
46 .Sh SYNOPSIS
47 .In sys/types.h
48 .In unistd.h
49 .Ft int
50 .Fn setuid "uid_t uid"
51 .Ft int
52 .Fn seteuid "uid_t euid"
53 .Ft int
54 .Fn setgid "gid_t gid"
55 .Ft int
56 .Fn setegid "gid_t egid"
57 .Sh DESCRIPTION
58 The
59 .Fn setuid
60 function
61 sets the real and effective
62 user IDs and the saved set-user-ID of the current process
63 to the specified value.
64 .\" Comment out next block for !_POSIX_SAVED_IDS
65 .\" The real user ID and the saved set-user-ID are changed only if the
66 .\" effective user ID is that of the super user.
67 .\" I.e.
68 .\" .Fn setuid
69 .\" function is equal to
70 .\" .Fn seteuid
71 .\" function if the effective user ID is not that of the super user.
72 .\" End of block
73 The
74 .Fn setuid
75 function is permitted if the specified ID is equal to the real user ID
76 .\" Comment out next line for !_POSIX_SAVED_IDS
77 .\" or the saved set-user-ID
78 .\" Next line is for Appendix B.4.2.2 case.
79 or the effective user ID
80 of the process, or if the effective user ID is that of the super user.
81 .Pp
82 The
83 .Fn setgid
84 function
85 sets the real and effective
86 group IDs and the saved set-group-ID of the current process
87 to the specified value.
88 .\" Comment out next block for !_POSIX_SAVED_IDS
89 .\" The real group ID and the saved set-group-ID are changed only if the
90 .\" effective user ID is that of the super user.
91 .\" I.e.
92 .\" .Fn setgid
93 .\" function is equal to
94 .\" .Fn setegid
95 .\" function if the effective user ID is not that of the super user.
96 .\" End of block
97 The
98 .Fn setgid
99 function is permitted if the specified ID is equal to the real group ID
100 .\" Comment out next line for !_POSIX_SAVED_IDS
101 .\" or the saved set-group-ID
102 .\" Next line is for Appendix B.4.2.2 case.
103 or the effective group ID
104 of the process, or if the effective user ID is that of the super user.
105 .Pp
106 The
107 .Fn seteuid
108 function
109 .Pq Fn setegid
110 sets the effective user ID (group ID) of the
111 current process.
112 The effective user ID may be set to the value
113 of the real user ID or the saved set-user-ID (see
114 .Xr intro 2
115 and
116 .Xr execve 2 ) ;
117 in this way, the effective user ID of a set-user-ID executable
118 may be toggled by switching to the real user ID, then re-enabled
119 by reverting to the set-user-ID value.
120 Similarly, the effective group ID may be set to the value
121 of the real group ID or the saved set-group-ID.
122 .Sh RETURN VALUES
123 .Rv -std
124 .Sh ERRORS
125 The functions will fail if:
126 .Bl -tag -width Er
127 .It Bq Er EPERM
128 The user is not the super user and the ID
129 specified is not the real, effective ID, or saved ID.
130 .El
131 .Sh SEE ALSO
132 .Xr getgid 2 ,
133 .Xr getuid 2 ,
134 .Xr issetugid 2 ,
135 .Xr setregid 2 ,
136 .Xr setreuid 2
137 .Sh STANDARDS
138 The
139 .Fn setuid
140 and
141 .Fn setgid
142 functions are compliant with the
143 .St -p1003.1-90
144 specification with
145 .Li _POSIX_SAVED_IDS
146 .\" Uncomment next line for !_POSIX_SAVED_IDS
147 not
148 defined with the permitted extensions from Appendix B.4.2.2.
149 The
150 .Fn seteuid
151 and
152 .Fn setegid
153 functions are extensions based on the
154 .Tn POSIX
155 concept of
156 .Li _POSIX_SAVED_IDS ,
157 and have been proposed for a future revision of the standard.
158 .Sh HISTORY
159 A
160 .Fn setuid
161 and a
162 .Fn setgid
163 function calls appeared in
164 .At v7 .