xref: /dragonfly/lib/libc/sys/chown.2 (revision b40e316c)
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
55The owner ID and group ID of the file
56named by
57.Fa path
58or referenced by
59.Fa fd
60is changed as specified by the arguments
61.Fa owner
62and
63.Fa group .
64The owner of a file may change the
65.Fa group
66to a group of which
67he or she is a member,
68but the change
69.Fa owner
70capability is restricted to the super-user.
71.Pp
72.Fn Chown
73clears the set-user-id and set-group-id bits
74on the file
75to prevent accidental or mischievous creation of
76set-user-id and set-group-id programs if not executed
77by the super-user.
78.Fn chown
79follows symbolic links to operate on the target of the link
80rather than the link itself.
81.Pp
82.Fn Fchown
83is particularly useful when used in conjunction
84with the file locking primitives (see
85.Xr flock 2 ) .
86.Pp
87.Fn Lchown
88is similar to
89.Fn chown
90but does not follow symbolic links.
91.Pp
92One of the owner or group id's
93may be left unchanged by specifying it as -1.
94.Sh RETURN VALUES
95.Rv -std
96.Sh ERRORS
97.Fn Chown
98and
99.Fn lchown
100will fail and the file will be unchanged if:
101.Bl -tag -width Er
102.It Bq Er ENOTDIR
103A component of the path prefix is not a directory.
104.It Bq Er ENAMETOOLONG
105A component of a pathname exceeded 255 characters,
106or an entire path name exceeded 1023 characters.
107.It Bq Er ENOENT
108The named file does not exist.
109.It Bq Er EACCES
110Search permission is denied for a component of the path prefix.
111.It Bq Er ELOOP
112Too many symbolic links were encountered in translating the pathname.
113.It Bq Er EPERM
114The effective user ID is not the super-user.
115.It Bq Er EROFS
116The named file resides on a read-only file system.
117.It Bq Er EFAULT
118.Fa Path
119points outside the process's allocated address space.
120.It Bq Er EIO
121An I/O error occurred while reading from or writing to the file system.
122.El
123.Pp
124.Fn Fchown
125will fail if:
126.Bl -tag -width Er
127.It Bq Er EBADF
128.Fa fd
129does not refer to a valid descriptor.
130.It Bq Er EINVAL
131.Fa fd
132refers to a socket, not a file.
133.It Bq Er EPERM
134The effective user ID is not the super-user.
135.It Bq Er EROFS
136The named file resides on a read-only file system.
137.It Bq Er EIO
138An 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
146The
147.Fn chown
148function call is expected to conform to
149.St -p1003.1-90 .
150.Sh HISTORY
151A
152.Fn chown
153function call appeared in
154.At v7 .
155The
156.Fn fchown
157function call
158appeared in
159.Bx 4.2 .
160.Pp
161The
162.Fn chown
163function was changed to follow symbolic links in
164.Bx 4.4 .
165The
166.Fn lchown
167function was added in
168.Fx 3.0
169to compensate for the loss of functionality.
170