Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | .\" Copyright (c) 1980, 1991 Regents of the University of California. |
2 | .\" 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 6.6 (Berkeley) 3/10/91 | |
33 | .\" | |
34 | .Dd March 10, 1991 | |
35 | .Dt CHMOD 2 | |
36 | .Os BSD 4 | |
37 | .Sh NAME | |
38 | .Nm chmod , | |
39 | .Nm fchmod | |
40 | .Nd change mode of file | |
41 | .Sh SYNOPSIS | |
42 | .Fd #include <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 | .Sh DESCRIPTION | |
48 | The function | |
49 | .Fn chmod | |
50 | sets the file permission bits | |
51 | of the file | |
52 | specified by the pathname | |
53 | .Fa path | |
54 | to | |
55 | .Fa mode . | |
56 | .Fn Fchmod | |
57 | sets the permission bits of the specified | |
58 | file descriptor | |
59 | .Fa fd . | |
60 | .Fn Chmod | |
61 | verifies that the process owner (user) either owns | |
62 | the file specified by | |
63 | .Fa path | |
64 | (or | |
65 | .Fa fd ) , | |
66 | or | |
67 | is the super-user. | |
68 | A mode is created from | |
69 | .Em or Ap d | |
70 | permission bit masks | |
71 | defined in | |
72 | .Aq Pa sys/stat.h : | |
73 | .Bd -literal -offset indent -compact | |
74 | #define S_IRWXU 0000700 /* RWX mask for owner */ | |
75 | #define S_IRUSR 0000400 /* R for owner */ | |
76 | #define S_IWUSR 0000200 /* W for owner */ | |
77 | #define S_IXUSR 0000100 /* X for owner */ | |
78 | ||
79 | #define S_IRWXG 0000070 /* RWX mask for group */ | |
80 | #define S_IRGRP 0000040 /* R for group */ | |
81 | #define S_IWGRP 0000020 /* W for group */ | |
82 | #define S_IXGRP 0000010 /* X for group */ | |
83 | ||
84 | #define S_IRWXO 0000007 /* RWX mask for other */ | |
85 | #define S_IROTH 0000004 /* R for other */ | |
86 | #define S_IWOTH 0000002 /* W for other */ | |
87 | #define S_IXOTH 0000001 /* X for other */ | |
88 | ||
89 | #define S_ISUID 0004000 /* set user id on execution */ | |
90 | #define S_ISGID 0002000 /* set group id on execution */ | |
91 | #define S_ISVTX 0001000 /* save swapped text even after use */ | |
92 | .Ed | |
93 | .Pp | |
94 | The | |
95 | .Dv ISVTX | |
96 | (the | |
97 | .Em sticky bit ) | |
98 | indicates to the system which executable files are shareable (the | |
99 | default) and the system maintains the program text of the files | |
100 | in the swap area. The sticky bit may only be set by the super user | |
101 | on shareable executable files. | |
102 | .Pp | |
103 | If mode | |
104 | .Dv ISVTX | |
105 | (the `sticky bit') is set on a directory, | |
106 | an unprivileged user may not delete or rename | |
107 | files of other users in that directory. The sticky bit may be | |
108 | set by any user on a directory which the user owns or has appropriate | |
109 | permissions. | |
110 | For more details of the properties of the sticky bit, see | |
111 | .Xr sticky 8 . | |
112 | .Pp | |
113 | Writing or changing the owner of a file | |
114 | turns off the set-user-id and set-group-id bits | |
115 | unless the user is the super-user. | |
116 | This makes the system somewhat more secure | |
117 | by protecting set-user-id (set-group-id) files | |
118 | from remaining set-user-id (set-group-id) if they are modified, | |
119 | at the expense of a degree of compatibility. | |
120 | .Sh RETURN VALUES | |
121 | Upon successful completion, a value of 0 is returned. | |
122 | Otherwise, a value of -1 is returned and | |
123 | .Va errno | |
124 | is set to indicate the error. | |
125 | .Sh ERRORS | |
126 | .Fn Chmod | |
127 | will fail and the file mode will be unchanged if: | |
128 | .Bl -tag -width Er | |
129 | .It Bq Er ENOTDIR | |
130 | A component of the path prefix is not a directory. | |
131 | .It Bq Er EINVAL | |
132 | The pathname contains a character with the high-order bit set. | |
133 | .It Bq Er ENAMETOOLONG | |
134 | A component of a pathname exceeded 255 characters, | |
135 | or an entire path name exceeded 1023 characters. | |
136 | .It Bq Er ENOENT | |
137 | The named file does not exist. | |
138 | .It Bq Er EACCES | |
139 | Search permission is denied for a component of the path prefix. | |
140 | .It Bq Er ELOOP | |
141 | Too many symbolic links were encountered in translating the pathname. | |
142 | .It Bq Er EPERM | |
143 | The effective user ID does not match the owner of the file and | |
144 | the effective user ID is not the super-user. | |
145 | .It Bq Er EROFS | |
146 | The named file resides on a read-only file system. | |
147 | .It Bq Er EFAULT | |
148 | .Fa Path | |
149 | points outside the process's allocated address space. | |
150 | .It Bq Er EIO | |
151 | An I/O error occurred while reading from or writing to the file system. | |
152 | .El | |
153 | .Pp | |
154 | .Fn Fchmod | |
155 | will fail if: | |
156 | .Bl -tag -width Er | |
157 | .It Bq Er EBADF | |
158 | The descriptor is not valid. | |
159 | .It Bq Er EINVAL | |
160 | .Fa Fd | |
161 | refers to a socket, not to a file. | |
162 | .It Bq Er EROFS | |
163 | The file resides on a read-only file system. | |
164 | .It Bq Er EIO | |
165 | An I/O error occurred while reading from or writing to the file system. | |
166 | .El | |
167 | .Sh SEE ALSO | |
168 | .Xr chmod 1 , | |
169 | .Xr open 2 , | |
170 | .Xr chown 2 , | |
171 | .Xr stat 2 , | |
172 | .Xr sticky 8 | |
173 | .Sh STANDARDS | |
174 | .Fn Chmod | |
175 | is expected to conform to IEEE Std 1003.1-1988 | |
176 | .Pq Dq Tn POSIX . | |
177 | .Sh HISTORY | |
178 | The | |
179 | .Fn fchmod | |
180 | function call | |
181 | appeared in | |
182 | .Bx 4.2 . |