]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - lib/libc/sys/chmod.2
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.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 .\" 4. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     @(#)chmod.2     8.1 (Berkeley) 6/4/93
29 .\" $FreeBSD$
30 .\"
31 .Dd January 16, 2006
32 .Dt CHMOD 2
33 .Os
34 .Sh NAME
35 .Nm chmod ,
36 .Nm fchmod ,
37 .Nm lchmod
38 .Nd change mode of file
39 .Sh LIBRARY
40 .Lb libc
41 .Sh SYNOPSIS
42 .In sys/stat.h
43 .Ft int
44 .Fn chmod "const char *path" "mode_t mode"
45 .Ft int
46 .Fn fchmod "int fd" "mode_t mode"
47 .Ft int
48 .Fn lchmod "const char *path" "mode_t mode"
49 .Sh DESCRIPTION
50 The file permission bits of the file named specified by
51 .Fa path
52 or referenced by the file descriptor
53 .Fa fd
54 are changed to
55 .Fa mode .
56 The
57 .Fn chmod
58 system call verifies that the process owner (user) either owns
59 the file specified by
60 .Fa path
61 (or
62 .Fa fd ) ,
63 or
64 is the super-user.
65 The
66 .Fn chmod
67 system call follows symbolic links to operate on the target of the link
68 rather than the link itself.
69 .Pp
70 The
71 .Fn lchmod
72 system call is similar to
73 .Fn chmod
74 but does not follow symbolic links.
75 .Pp
76 A mode is created from
77 .Em or'd
78 permission bit masks
79 defined in
80 .In sys/stat.h :
81 .Pp
82 .Bd -literal -offset indent -compact
83 #define S_IRWXU 0000700    /* RWX mask for owner */
84 #define S_IRUSR 0000400    /* R for owner */
85 #define S_IWUSR 0000200    /* W for owner */
86 #define S_IXUSR 0000100    /* X for owner */
87
88 #define S_IRWXG 0000070    /* RWX mask for group */
89 #define S_IRGRP 0000040    /* R for group */
90 #define S_IWGRP 0000020    /* W for group */
91 #define S_IXGRP 0000010    /* X for group */
92
93 #define S_IRWXO 0000007    /* RWX mask for other */
94 #define S_IROTH 0000004    /* R for other */
95 #define S_IWOTH 0000002    /* W for other */
96 #define S_IXOTH 0000001    /* X for other */
97
98 #define S_ISUID 0004000    /* set user id on execution */
99 #define S_ISGID 0002000    /* set group id on execution */
100 #ifndef __BSD_VISIBLE
101 #define S_ISTXT 0001000    /* sticky bit */
102 #endif
103 .Ed
104 .Pp
105 The
106 .Fx
107 VM system totally ignores the sticky bit
108 .Pq Dv ISTXT
109 for executables.
110 On UFS-based file systems (FFS, LFS) the sticky
111 bit may only be set upon directories.
112 .Pp
113 If mode
114 .Dv ISTXT
115 (the `sticky bit') is set on a directory,
116 an unprivileged user may not delete or rename
117 files of other users in that directory.
118 The sticky bit may be
119 set by any user on a directory which the user owns or has appropriate
120 permissions.
121 For more details of the properties of the sticky bit, see
122 .Xr sticky 8 .
123 .Pp
124 If mode ISUID (set UID) is set on a directory,
125 and the MNT_SUIDDIR option was used in the mount of the file system,
126 then the owner of any new files and sub-directories
127 created within this directory are set
128 to be the same as the owner of that directory.
129 If this function is enabled, new directories will inherit
130 the bit from their parents.
131 Execute bits are removed from
132 the file, and it will not be given to root.
133 This behavior does not change the
134 requirements for the user to be allowed to write the file, but only the eventual
135 owner after it has been created.
136 Group inheritance is not affected.
137 .Pp
138 This feature is designed for use on fileservers serving PC users via
139 ftp, SAMBA, or netatalk.
140 It provides security holes for shell users and as
141 such should not be used on shell machines, especially on home directories.
142 This option requires the SUIDDIR
143 option in the kernel to work.
144 Only UFS file systems support this option.
145 For more details of the suiddir mount option, see
146 .Xr mount 8 .
147 .Pp
148 Writing or changing the owner of a file
149 turns off the set-user-id and set-group-id bits
150 unless the user is the super-user.
151 This makes the system somewhat more secure
152 by protecting set-user-id (set-group-id) files
153 from remaining set-user-id (set-group-id) if they are modified,
154 at the expense of a degree of compatibility.
155 .Sh RETURN VALUES
156 .Rv -std
157 .Sh ERRORS
158 The
159 .Fn chmod
160 system call
161 will fail and the file mode will be unchanged if:
162 .Bl -tag -width Er
163 .It Bq Er ENOTDIR
164 A component of the path prefix is not a directory.
165 .It Bq Er ENAMETOOLONG
166 A component of a pathname exceeded 255 characters,
167 or an entire path name exceeded 1023 characters.
168 .It Bq Er ENOENT
169 The named file does not exist.
170 .It Bq Er EACCES
171 Search permission is denied for a component of the path prefix.
172 .It Bq Er ELOOP
173 Too many symbolic links were encountered in translating the pathname.
174 .It Bq Er EPERM
175 The effective user ID does not match the owner of the file and
176 the effective user ID is not the super-user.
177 .It Bq Er EPERM
178 The effective user ID is not the super-user, the effective user ID do match the
179 owner of the file, but the group ID of the file does not match the effective
180 group ID nor one of the supplementary group IDs.
181 .It Bq Er EPERM
182 The named file has its immutable or append-only flag set, see the
183 .Xr chflags 2
184 manual page for more information.
185 .It Bq Er EROFS
186 The named file resides on a read-only file system.
187 .It Bq Er EFAULT
188 The
189 .Fa path
190 argument
191 points outside the process's allocated address space.
192 .It Bq Er EIO
193 An I/O error occurred while reading from or writing to the file system.
194 .It Bq Er EFTYPE
195 The effective user ID is not the super-user, the mode includes the sticky bit
196 .Dv ( S_ISVTX ) ,
197 and path does not refer to a directory.
198 .El
199 .Pp
200 The
201 .Fn fchmod
202 system call will fail if:
203 .Bl -tag -width Er
204 .It Bq Er EBADF
205 The descriptor is not valid.
206 .It Bq Er EINVAL
207 The
208 .Fa fd
209 argument
210 refers to a socket, not to a file.
211 .It Bq Er EROFS
212 The file resides on a read-only file system.
213 .It Bq Er EIO
214 An I/O error occurred while reading from or writing to the file system.
215 .El
216 .Sh SEE ALSO
217 .Xr chmod 1 ,
218 .Xr chflags 2 ,
219 .Xr chown 2 ,
220 .Xr open 2 ,
221 .Xr stat 2 ,
222 .Xr sticky 8
223 .Sh STANDARDS
224 The
225 .Fn chmod
226 system call is expected to conform to
227 .St -p1003.1-90 ,
228 except for the return of
229 .Er EFTYPE
230 and the use of
231 .Dv S_ISTXT .
232 .Sh HISTORY
233 The
234 .Fn chmod
235 function appeared in
236 .At v7 .
237 The
238 .Fn fchmod
239 system call appeared in
240 .Bx 4.2 .
241 The
242 .Fn lchmod
243 system call appeared in
244 .Fx 3.0 .