Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / lib / libc / sys / chown.2
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 .\" $FreeBSD: src/lib/libc/sys/chown.2,v 1.12.2.6 2001/12/14 18:34:00 ru Exp $
34 .\" $DragonFly: src/lib/libc/sys/chown.2,v 1.2 2003/06/17 04:26:47 dillon Exp $
35 .\"
36 .Dd April 19, 1994
37 .Dt CHOWN 2
38 .Os
39 .Sh NAME
40 .Nm chown ,
41 .Nm fchown ,
42 .Nm lchown
43 .Nd change owner and group of a file
44 .Sh LIBRARY
45 .Lb libc
46 .Sh SYNOPSIS
47 .In unistd.h
48 .Ft int
49 .Fn chown "const char *path" "uid_t owner" "gid_t group"
50 .Ft int
51 .Fn fchown "int fd" "uid_t owner" "gid_t group"
52 .Ft int
53 .Fn lchown "const char *path" "uid_t owner" "gid_t group"
54 .Sh DESCRIPTION
55 The owner ID and group ID of the file
56 named by
57 .Fa path
58 or referenced by
59 .Fa fd
60 is changed as specified by the arguments
61 .Fa owner
62 and
63 .Fa group .
64 The owner of a file may change the
65 .Fa group
66 to a group of which
67 he or she is a member,
68 but the change
69 .Fa owner
70 capability is restricted to the super-user.
71 .Pp
72 .Fn Chown
73 clears the set-user-id and set-group-id bits
74 on the file
75 to prevent accidental or mischievous creation of
76 set-user-id and set-group-id programs if not executed
77 by the super-user.
78 .Fn chown
79 follows symbolic links to operate on the target of the link
80 rather than the link itself.
81 .Pp
82 .Fn Fchown
83 is particularly useful when used in conjunction
84 with the file locking primitives (see
85 .Xr flock 2 ) .
86 .Pp
87 .Fn Lchown
88 is similar to
89 .Fn chown
90 but does not follow symbolic links.
91 .Pp
92 One of the owner or group id's
93 may be left unchanged by specifying it as -1.
94 .Sh RETURN VALUES
95 .Rv -std
96 .Sh ERRORS
97 .Fn Chown
98 and
99 .Fn lchown
100 will fail and the file will be unchanged if:
101 .Bl -tag -width Er
102 .It Bq Er ENOTDIR
103 A component of the path prefix is not a directory.
104 .It Bq Er ENAMETOOLONG
105 A component of a pathname exceeded 255 characters,
106 or an entire path name exceeded 1023 characters.
107 .It Bq Er ENOENT
108 The named file does not exist.
109 .It Bq Er EACCES
110 Search permission is denied for a component of the path prefix.
111 .It Bq Er ELOOP
112 Too many symbolic links were encountered in translating the pathname.
113 .It Bq Er EPERM
114 The effective user ID is not the super-user.
115 .It Bq Er EROFS
116 The named file resides on a read-only file system.
117 .It Bq Er EFAULT
118 .Fa Path
119 points outside the process's allocated address space.
120 .It Bq Er EIO
121 An I/O error occurred while reading from or writing to the file system.
122 .El
123 .Pp
124 .Fn Fchown
125 will fail if:
126 .Bl -tag -width Er
127 .It Bq Er EBADF
128 .Fa fd
129 does not refer to a valid descriptor.
130 .It Bq Er EINVAL
131 .Fa fd
132 refers to a socket, not a file.
133 .It Bq Er EPERM
134 The effective user ID is not the super-user.
135 .It Bq Er EROFS
136 The named file resides on a read-only file system.
137 .It Bq Er EIO
138 An I/O error occurred while reading from or writing to the file system.
139 .El
140 .Sh SEE ALSO
141 .Xr chgrp 1 ,
142 .Xr chmod 2 ,
143 .Xr flock 2 ,
144 .Xr chown 8
145 .Sh STANDARDS
146 The
147 .Fn chown
148 function call is expected to conform to
149 .St -p1003.1-90 .
150 .Sh HISTORY
151 A
152 .Fn chown
153 function call appeared in
154 .At v7 .
155 The
156 .Fn fchown
157 function call
158 appeared in
159 .Bx 4.2 .
160 .Pp
161 The
162 .Fn chown
163 function was changed to follow symbolic links in
164 .Bx 4.4 .
165 The
166 .Fn lchown
167 function was added in
168 .Fx 3.0
169 to compensate for the loss of functionality.