]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/chown.2
Maintenance scripts
[thirdparty/man-pages.git] / man2 / chown.2
CommitLineData
fea681da
MK
1.\" Hey Emacs! This file is -*- nroff -*- source.
2.\"
3.\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
4.\" Copyright (c) 1998 Andries Brouwer (aeb@cwi.nl)
5.\"
6.\" Permission is granted to make and distribute verbatim copies of this
7.\" manual provided the copyright notice and this permission notice are
8.\" preserved on all copies.
9.\"
10.\" Permission is granted to copy and distribute modified versions of this
11.\" manual under the conditions for verbatim copying, provided that the
12.\" entire resulting derived work is distributed under the terms of a
13.\" permission notice identical to this one.
14.\"
15.\" Since the Linux kernel and libraries are constantly changing, this
16.\" manual page may be incorrect or out-of-date. The author(s) assume no
17.\" responsibility for errors or omissions, or for damages resulting from
18.\" the use of the information contained herein. The author(s) may not
19.\" have taken the same level of care in the production of this manual,
20.\" which is licensed free of charge, as they might when working
21.\" professionally.
22.\"
23.\" Formatted or processed versions of this manual, if unaccompanied by
24.\" the source, must acknowledge the copyright and authors of this work.
25.\"
26.\" Modified by Michael Haardt <michael@moria.de>
27.\" Modified 1993-07-21 by Rik Faith <faith@cs.unc.edu>
28.\" Modified 1996-07-09 by Andries Brouwer <aeb@cwi.nl>
29.\" Modified 1996-11-06 by Eric S. Raymond <esr@thyrsus.com>
30.\" Modified 1997-05-18 by Michael Haardt <michael@cantor.informatik.rwth-aachen.de>
305a0578 31.\" Modified 2004-06-23 by Michael Kerrisk <mtk-manpages@gmx.net>
fea681da
MK
32.\"
33.TH CHOWN 2 2004-06-23 "Linux 2.6.7" "Linux Programmer's Manual"
34.SH NAME
35chown, fchown, lchown \- change ownership of a file
36.SH SYNOPSIS
37.B #include <sys/types.h>
38.br
39.B #include <unistd.h>
40.sp
41.BI "int chown(const char *" path ", uid_t " owner ", gid_t " group );
42.br
43.BI "int fchown(int " fd ", uid_t " owner ", gid_t " group );
44.br
45.BI "int lchown(const char *" path ", uid_t " owner ", gid_t " group );
46.SH DESCRIPTION
47These system calls change the owner and group of the file specified by
48.I path
49or by
50.IR fd .
51Only a privileged process (Linux: one with the
52.B CAP_CHOWN
53capability) may change the owner of a file.
54The owner of a file may change the group of the file
55to any group of which that owner is a member.
56A privileged process (Linux: with
57.BR CAP_CHOWN )
58may change the group arbitrarily.
59
60If the
61.I owner
62or
63.I group
64is specified as \-1, then that ID is not changed.
65
2c8d1c7d 66When the owner or group of an executable file are changed by a non-superuser,
fea681da
MK
67the S_ISUID and S_ISGID mode bits are cleared. POSIX does not specify whether
68this also should happen when root does the
69.IR chown ;
70the Linux behaviour depends on the kernel version.
71.\" In Linux 2.0 kernels, superuser was like everyone else
72.\" In 2.2, up to 2.2.12, these bits were not cleared for superuser.
73.\" Since 2.2.13, superuser is once more like everyone else.
74In case of a non-group-executable file (with clear S_IXGRP bit)
75the S_ISGID bit indicates mandatory locking, and is not cleared
76by a
77.IR chown .
78
79.SH "RETURN VALUE"
80On success, zero is returned. On error, \-1 is returned, and
81.I errno
82is set appropriately.
83.SH ERRORS
84Depending on the file system, other errors can be returned. The more
85general errors for
e511ffb6 86.BR chown ()
fea681da
MK
87are listed below.
88.TP
89.B EACCES
90Search permission is denied on a component of the path prefix.
91(See also
92.BR path_resolution (2).)
93.TP
94.B EFAULT
95.I path
96points outside your accessible address space.
97.TP
98.B ELOOP
99Too many symbolic links were encountered in resolving
100.IR path .
101.TP
102.B ENAMETOOLONG
103.I path
104is too long.
105.TP
106.B ENOENT
107The file does not exist.
108.TP
109.B ENOMEM
110Insufficient kernel memory was available.
111.TP
112.B ENOTDIR
113A component of the path prefix is not a directory.
114.TP
115.B EPERM
116The calling process did not have the required permissions
117(see above) to change owner and/or group.
118.TP
119.B EROFS
120The named file resides on a read-only file system.
121.PP
122The general errors for
e511ffb6 123.BR fchown ()
fea681da
MK
124are listed below:
125.TP
126.B EBADF
127The descriptor is not valid.
128.TP
129.B EIO
130A low-level I/O error occurred while modifying the inode.
131.TP
132.B ENOENT
133See above.
134.TP
135.B EPERM
136See above.
137.TP
138.B EROFS
139See above.
140.SH NOTES
141In versions of Linux prior to 2.1.81 (and distinct from 2.1.46),
e511ffb6 142.BR chown ()
fea681da
MK
143did not follow symbolic links.
144Since Linux 2.1.81,
e511ffb6 145.BR chown ()
fea681da 146does follow symbolic links, and there is a new system call
e511ffb6 147.BR lchown ()
fea681da
MK
148that does not follow symbolic links.
149Since Linux 2.1.86, this new call (that has the same semantics
150as the old
e511ffb6 151.BR chown ())
fea681da 152has got the same syscall number, and
e511ffb6 153.BR chown ()
fea681da
MK
154got the newly introduced number.
155.LP
156The prototype for
e511ffb6 157.BR fchown ()
fea681da
MK
158is only available if
159.B _BSD_SOURCE
160is defined (either explicitly, or implicitly, by not defining
e9496f74 161_POSIX_SOURCE or compiling with the \-ansi flag).
fea681da
MK
162.SH "CONFORMING TO"
163The
e511ffb6 164.BR chown ()
fea681da
MK
165call conforms to SVr4, SVID, POSIX, X/OPEN. The 4.4BSD version can only be
166used by the superuser (that is, ordinary users cannot give away files).
167SVr4 documents EINVAL, EINTR, ENOLINK and EMULTIHOP returns, but no
168ENOMEM. POSIX.1 does not document ENOMEM or ELOOP error conditions.
169.PP
170The
e511ffb6 171.BR fchown ()
fea681da
MK
172call conforms to 4.4BSD and SVr4.
173SVr4 documents additional EINVAL, EIO, EINTR, and ENOLINK error conditions.
174.SH RESTRICTIONS
175The \fBchown\fP() semantics are deliberately violated on NFS file systems
176which have UID mapping enabled. Additionally, the semantics of all system
177calls which access the file contents are violated, because \fBchown\fP()
178may cause immediate access revocation on already open files. Client side
179caching may lead to a delay between the time where ownership have
180been changed to allow access for a user and the time where the file can
181actually be accessed by the user on other clients.
182.SH "SEE ALSO"
183.BR chmod (2),
184.BR flock (2),
185.BR path_resolution (2)