Nuke AppleTalk support.
[dragonfly.git] / lib / libc / sys / chmod.2
1 .\" Copyright (c) 1980, 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 .\"     @(#)chmod.2     8.1 (Berkeley) 6/4/93
33 .\" $FreeBSD: src/lib/libc/sys/chmod.2,v 1.16.2.7 2001/12/14 18:34:00 ru Exp $
34 .\"
35 .Dd August 9, 2009
36 .Dt CHMOD 2
37 .Os
38 .Sh NAME
39 .Nm chmod ,
40 .Nm fchmod ,
41 .Nm lchmod ,
42 .Nm fchmodat
43 .Nd change mode of file
44 .Sh LIBRARY
45 .Lb libc
46 .Sh SYNOPSIS
47 .In sys/stat.h
48 .Ft int
49 .Fn chmod "const char *path" "mode_t mode"
50 .Ft int
51 .Fn fchmod "int fd" "mode_t mode"
52 .Ft int
53 .Fn lchmod "const char *path" "mode_t mode"
54 .Ft int
55 .Fn fchmodat "int dirfd" "const char *path" "mode_t mode" "int flags"
56 .Sh DESCRIPTION
57 The file permission bits of the file named specified by
58 .Fa path
59 or referenced by the file descriptor
60 .Fa fd
61 are changed to
62 .Fa mode .
63 The
64 .Fn chmod
65 function verifies that the process owner (user) either owns
66 the file specified by
67 .Fa path
68 (or
69 .Fa fd ) ,
70 or
71 is the super-user.
72 The
73 .Fn chmod
74 function follows symbolic links to operate on the target of the link
75 rather than the link itself.
76 .Pp
77 The
78 .Fa lchmod
79 function is similar to
80 .Fn chmod
81 but does not follow symbolic links.
82 .Pp
83 The
84 .Fn fchmodat
85 function is equivalent to the
86 .Fn chmod
87 or
88 .Fn lchmod
89 functions except in the case where the
90 .Fa path
91 specifies a relative path.
92 In this case the file to be opened is determined relative to the directory
93 associated with the file descriptor
94 .Fa dirfd
95 instead of the current working directory.
96 If
97 .Fn fchmodat
98 is passed the special value
99 .Dv AT_FDCWD
100 in the
101 .Fa dirfd
102 parameter, the current working directory is used
103 and the behavior is identical to a call to
104 .Fn chmod
105 or
106 .Fn lchmod .
107 .Pp
108 A mode is created from
109 .Em or'd
110 permission bit masks
111 defined in
112 .In sys/stat.h :
113 .Pp
114 .Bd -literal -offset indent -compact
115 #define S_IRWXU 0000700    /* RWX mask for owner */
116 #define S_IRUSR 0000400    /* R for owner */
117 #define S_IWUSR 0000200    /* W for owner */
118 #define S_IXUSR 0000100    /* X for owner */
119
120 #define S_IRWXG 0000070    /* RWX mask for group */
121 #define S_IRGRP 0000040    /* R for group */
122 #define S_IWGRP 0000020    /* W for group */
123 #define S_IXGRP 0000010    /* X for group */
124
125 #define S_IRWXO 0000007    /* RWX mask for other */
126 #define S_IROTH 0000004    /* R for other */
127 #define S_IWOTH 0000002    /* W for other */
128 #define S_IXOTH 0000001    /* X for other */
129
130 #define S_ISUID 0004000    /* set user id on execution */
131 #define S_ISGID 0002000    /* set group id on execution */
132 #define S_ISVTX 0001000    /* sticky bit */
133 #ifndef _POSIX_SOURCE
134 #define S_ISTXT 0001000
135 #endif
136 .Ed
137 .Pp
138 The
139 .Dx
140 VM system totally ignores the sticky bit
141 .Pq Dv ISVTX
142 for executables.
143 On UFS-based filesystems (FFS, MFS, LFS) the sticky
144 bit may only be set upon directories.
145 .Pp
146 If mode
147 .Dv ISVTX
148 (the `sticky bit') is set on a directory,
149 an unprivileged user may not delete or rename
150 files of other users in that directory.
151 The sticky bit may be
152 set by any user on a directory which the user owns or has appropriate
153 permissions.
154 For more details of the properties of the sticky bit, see
155 .Xr sticky 8 .
156 .Pp
157 If mode ISUID (set UID) is set on a directory,
158 and the MNT_SUIDDIR option was used in the mount of the filesystem,
159 then the owner of any new files and sub-directories
160 created within this directory are set
161 to be the same as the owner of that directory.
162 If this function is enabled, new directories will inherit
163 the bit from their parents.  Execute bits are removed from
164 the file, and it will not be given to root.
165 This behavior does not change the
166 requirements for the user to be allowed to write the file, but only the eventual
167 owner after it has been created.
168 Group inheritance is not affected.
169 .Pp
170 This feature is designed for use on fileservers serving PC users via
171 ftp or SAMBA.
172 It provides security holes for shell users and as
173 such should not be used on shell machines, especially on home directories.
174 This option requires the SUIDDIR
175 option in the kernel to work.
176 Only UFS filesystems support this option.
177 For more details of the suiddir mount option, see
178 .Xr mount 8 .
179 .Pp
180 Writing or changing the owner of a file
181 turns off the set-user-id and set-group-id bits
182 unless the user is the super-user.
183 This makes the system somewhat more secure
184 by protecting set-user-id (set-group-id) files
185 from remaining set-user-id (set-group-id) if they are modified,
186 at the expense of a degree of compatibility.
187 .Pp
188 The values for the
189 .Fa flags
190 are constructed by a bitwise-inclusive OR of flags from the following list,
191 defined in
192 .In fcntl.h :
193 .Bl -tag -width indent
194 .It Dv AT_SYMLINK_NOFOLLOW
195 If
196 .Fa path
197 names a symbolic link, the mode of the symbolic link is changed.
198 .El
199 .Sh RETURN VALUES
200 .Rv -std
201 .Sh ERRORS
202 .Fn Chmod ,
203 .Fn lchmod
204 and
205 .Fn fchmodat
206 will fail and the file mode will be unchanged if:
207 .Bl -tag -width Er
208 .It Bq Er ENOTDIR
209 A component of the path prefix or
210 .Fa dirfd
211 is not a directory.
212 .It Bq Er ENAMETOOLONG
213 A component of a pathname exceeded 255 characters,
214 or an entire path name exceeded 1023 characters.
215 .It Bq Er ENOENT
216 The named file does not exist.
217 .It Bq Er EACCES
218 Search permission is denied for a component of the path prefix.
219 .It Bq Er ELOOP
220 Too many symbolic links were encountered in translating the pathname.
221 .It Bq Er EPERM
222 The effective user ID does not match the owner of the file and
223 the effective user ID is not the super-user.
224 .It Bq Er EROFS
225 The named file resides on a read-only file system.
226 .It Bq Er EFAULT
227 .Fa Path
228 points outside the process's allocated address space.
229 .It Bq Er EIO
230 An I/O error occurred while reading from or writing to the file system.
231 .It Bq Er EFTYPE
232 An attempt was made to set the sticky bit upon an executable.
233 .El
234 .Pp
235 .Fn Fchmod
236 will fail if:
237 .Bl -tag -width Er
238 .It Bq Er EBADF
239 The descriptor is not valid.
240 .It Bq Er EINVAL
241 .Fa fd
242 refers to a socket, not to a file.
243 .It Bq Er EROFS
244 The file resides on a read-only file system.
245 .It Bq Er EIO
246 An I/O error occurred while reading from or writing to the file system.
247 .El
248 .Sh SEE ALSO
249 .Xr chmod 1 ,
250 .Xr chown 2 ,
251 .Xr open 2 ,
252 .Xr stat 2 ,
253 .Xr sticky 8
254 .Sh STANDARDS
255 The
256 .Fn chmod
257 function call is expected to conform to
258 .St -p1003.1-90 ,
259 except for the return of
260 .Er EFTYPE
261 and the use of
262 .Dv S_ISTXT .
263 .Sh HISTORY
264 A
265 .Fn chmod
266 function call appeared in
267 .At v7 .
268 The
269 .Fn fchmod
270 function call
271 appeared in
272 .Bx 4.2 .
273 The
274 .Fn lchmod
275 function call appeared in
276 .Fx 3.0 .
277 .Pp
278 The
279 .Fn fchmodat
280 system call appeared in
281 .Dx 2.3 .