1 .\" $NetBSD: chown.2,v 1.31 2010/05/31 12:16:20 njoly Exp $
3 .\" Copyright (c) 1980, 1991, 1993, 1994
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)chown.2 8.4 (Berkeley) 4/19/94
39 .Nd change owner and group of a file
45 .Fn chown "const char *path" "uid_t owner" "gid_t group"
47 .Fn lchown "const char *path" "uid_t owner" "gid_t group"
49 .Fn fchown "int fd" "uid_t owner" "gid_t group"
51 The owner ID and group ID of the file
56 is changed as specified by the arguments
60 The owner of a file may change the
63 he or she is a member,
66 capability is restricted to the super-user.
68 When called to change the owner of a file,
76 When a called to change the group of a file,
81 clear the set-group-id
84 These actions are taken to prevent accidental or mischievous creation of
85 set-user-id and set-group-id programs.
90 except in the case where the named file is a symbolic link,
93 changes the owner and group of the link,
96 changes the owner and group of the file the link references.
99 is particularly useful when used in conjunction
100 with the file locking primitives (see
103 One of the owner or group id's
104 may be left unchanged by specifying it as (uid_t)\-1 or (gid_t)\-1 respectively.
106 Zero is returned if the operation was successful;
107 \-1 is returned if an error occurs, with a more specific
108 error code being placed in the global variable
114 will fail and the file will be unchanged if:
117 A component of the path prefix is not a directory.
118 .It Bq Er ENAMETOOLONG
119 A component of a pathname exceeded
121 characters, or an entire path name exceeded
125 The named file does not exist.
127 Search permission is denied for a component of the path prefix.
129 Too many symbolic links were encountered in translating the pathname.
131 The effective user ID is not the super-user.
133 The named file resides on a read-only file system.
136 points outside the process's allocated address space.
138 An I/O error occurred while reading from or writing to the file system.
146 does not refer to a valid descriptor.
149 refers to a socket, not a file.
151 The effective user ID is not the super-user.
153 The named file resides on a read-only file system.
155 An I/O error occurred while reading from or writing to the file system.
166 function deviates from the semantics defined in
168 which specifies that, unless the caller is the super-user, both the
169 set-user-id and set-group-id bits on a file shall be cleared, regardless
170 of the file attribute changed.
175 functions, as defined by
177 provide the same semantics.
179 To retain conformance to these standards, compatibility interfaces
202 function call appeared in
209 functions were changed to follow symbolic links in
213 function call appeared in