]>
Commit | Line | Data |
---|---|---|
9bccf70c A |
1 | .\" Copyright (c) 1980, 1991, 1993, 1994 |
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 | .\" @(#)chown.2 8.4 (Berkeley) 4/19/94 | |
33 | .\" | |
91447636 | 34 | .Dd April 19, 1994 |
9bccf70c A |
35 | .Dt CHOWN 2 |
36 | .Os | |
37 | .Sh NAME | |
38 | .Nm chown , | |
91447636 A |
39 | .Nm fchown , |
40 | .Nm lchown | |
41 | .Nd change owner and group of a file | |
9bccf70c | 42 | .Sh SYNOPSIS |
91447636 | 43 | .In unistd.h |
9bccf70c | 44 | .Ft int |
2d21ac55 A |
45 | .Fo chown |
46 | .Fa "const char *path" | |
47 | .Fa "uid_t owner" | |
48 | .Fa "gid_t group" | |
49 | .Fc | |
9bccf70c | 50 | .Ft int |
2d21ac55 A |
51 | .Fo fchown |
52 | .Fa "int fildes" | |
53 | .Fa "uid_t owner" | |
54 | .Fa "gid_t group" | |
55 | .Fc | |
91447636 | 56 | .Ft int |
2d21ac55 A |
57 | .Fo lchown |
58 | .Fa "const char *path" | |
59 | .Fa "uid_t owner" | |
60 | .Fa "gid_t group" | |
61 | .Fc | |
9bccf70c | 62 | .Sh DESCRIPTION |
91447636 | 63 | The owner ID and group ID of the file |
9bccf70c A |
64 | named by |
65 | .Fa path | |
66 | or referenced by | |
2d21ac55 | 67 | .Fa fildes |
9bccf70c A |
68 | is changed as specified by the arguments |
69 | .Fa owner | |
91447636 | 70 | and |
9bccf70c A |
71 | .Fa group . |
72 | The owner of a file may change the | |
73 | .Fa group | |
74 | to a group of which | |
75 | he or she is a member, | |
76 | but the change | |
77 | .Fa owner | |
78 | capability is restricted to the super-user. | |
79 | .Pp | |
91447636 A |
80 | The |
81 | .Fn chown | |
82 | system call | |
9bccf70c A |
83 | clears the set-user-id and set-group-id bits |
84 | on the file | |
85 | to prevent accidental or mischievous creation of | |
91447636 A |
86 | set-user-id and set-group-id programs if not executed |
87 | by the super-user. | |
88 | The | |
89 | .Fn chown | |
90 | system call | |
91 | follows symbolic links to operate on the target of the link | |
92 | rather than the link itself. | |
9bccf70c | 93 | .Pp |
91447636 A |
94 | The |
95 | .Fn fchown | |
96 | system call | |
9bccf70c A |
97 | is particularly useful when used in conjunction |
98 | with the file locking primitives (see | |
99 | .Xr flock 2 ) . | |
100 | .Pp | |
91447636 A |
101 | The |
102 | .Fn lchown | |
103 | system call is similar to | |
104 | .Fn chown | |
105 | but does not follow symbolic links. | |
106 | .Pp | |
9bccf70c A |
107 | One of the owner or group id's |
108 | may be left unchanged by specifying it as -1. | |
109 | .Sh RETURN VALUES | |
91447636 | 110 | .Rv -std |
9bccf70c | 111 | .Sh ERRORS |
2d21ac55 | 112 | .Pp |
91447636 A |
113 | The |
114 | .Fn chown | |
115 | and | |
116 | .Fn lchown | |
2d21ac55 | 117 | system calls will fail if: |
9bccf70c | 118 | .Bl -tag -width Er |
2d21ac55 | 119 | .\" ========== |
9bccf70c A |
120 | .It Bq Er EACCES |
121 | Search permission is denied for a component of the path prefix. | |
9bccf70c | 122 | .It Bq Er EFAULT |
91447636 A |
123 | The |
124 | .Fa path | |
125 | argument | |
9bccf70c | 126 | points outside the process's allocated address space. |
2d21ac55 A |
127 | .\" ========== |
128 | .It Bq Er ELOOP | |
129 | Too many symbolic links are encountered in translating the pathname. | |
130 | This is taken to be indicative of a looping symbolic link. | |
131 | .\" ========== | |
132 | .It Bq Er ENAMETOOLONG | |
133 | A component of a pathname exceeded 255 characters, | |
134 | or an entire path name exceeded 1023 characters. | |
135 | .\" ========== | |
136 | .It Bq Er ENOENT | |
137 | A component of | |
138 | .Fa path | |
139 | does not exist. | |
140 | .\" ========== | |
141 | .It Bq Er ENOTDIR | |
142 | A component of the path prefix is not a directory. | |
9bccf70c A |
143 | .El |
144 | .Pp | |
91447636 A |
145 | The |
146 | .Fn fchown | |
147 | system call will fail if: | |
9bccf70c | 148 | .Bl -tag -width Er |
2d21ac55 | 149 | .\" ========== |
9bccf70c | 150 | .It Bq Er EBADF |
91447636 | 151 | The |
2d21ac55 | 152 | .Fa fildes |
91447636 | 153 | argument |
9bccf70c | 154 | does not refer to a valid descriptor. |
2d21ac55 | 155 | .\" ========== |
9bccf70c | 156 | .It Bq Er EINVAL |
91447636 | 157 | The |
2d21ac55 | 158 | .Fa fildes |
91447636 | 159 | argument |
9bccf70c | 160 | refers to a socket, not a file. |
2d21ac55 A |
161 | .El |
162 | .Pp | |
163 | Any of these calls will fail if: | |
164 | .Bl -tag -width Er | |
165 | .\" ========== | |
166 | .It Bq Er EINTR | |
167 | Its execution is interrupted by a signal. | |
168 | .\" ========== | |
169 | .It Bq Er EIO | |
170 | An I/O error occurs while reading from or writing to the file system. | |
171 | .\" ========== | |
9bccf70c | 172 | .It Bq Er EPERM |
2d21ac55 A |
173 | The effective user ID does not match the owner of the file |
174 | and the calling process does not have appropriate (i.e., root) privileges. | |
175 | .\" ========== | |
9bccf70c A |
176 | .It Bq Er EROFS |
177 | The named file resides on a read-only file system. | |
9bccf70c A |
178 | .El |
179 | .Sh SEE ALSO | |
9bccf70c A |
180 | .Xr chgrp 1 , |
181 | .Xr chmod 2 , | |
91447636 A |
182 | .Xr flock 2 , |
183 | .Xr chown 8 | |
9bccf70c A |
184 | .Sh STANDARDS |
185 | The | |
186 | .Fn chown | |
91447636 A |
187 | system call is expected to conform to |
188 | .St -p1003.1-90 . | |
9bccf70c A |
189 | .Sh HISTORY |
190 | The | |
91447636 A |
191 | .Fn chown |
192 | function appeared in | |
193 | .At v7 . | |
194 | The | |
9bccf70c | 195 | .Fn fchown |
91447636 | 196 | system call appeared in |
9bccf70c A |
197 | .Bx 4.2 . |
198 | .Pp | |
199 | The | |
200 | .Fn chown | |
201 | and | |
202 | .Fn fchown | |
91447636 | 203 | system calls were changed to follow symbolic links in |
9bccf70c | 204 | .Bx 4.4 . |
91447636 A |
205 | The |
206 | .Fn lchown | |
207 | system call was added in | |
208 | .Fx 3.0 | |
209 | to compensate for the loss of functionality. |