]>
Commit | Line | Data |
---|---|---|
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 | |
35 | chown, 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 | |
47 | These system calls change the owner and group of the file specified by | |
48 | .I path | |
49 | or by | |
50 | .IR fd . | |
51 | Only a privileged process (Linux: one with the | |
52 | .B CAP_CHOWN | |
53 | capability) may change the owner of a file. | |
54 | The owner of a file may change the group of the file | |
55 | to any group of which that owner is a member. | |
56 | A privileged process (Linux: with | |
57 | .BR CAP_CHOWN ) | |
58 | may change the group arbitrarily. | |
59 | ||
60 | If the | |
61 | .I owner | |
62 | or | |
63 | .I group | |
64 | is specified as \-1, then that ID is not changed. | |
65 | ||
66 | When the owner or group of an executable file are changed by a non-super-user, | |
67 | the S_ISUID and S_ISGID mode bits are cleared. POSIX does not specify whether | |
68 | this also should happen when root does the | |
69 | .IR chown ; | |
70 | the 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. | |
74 | In case of a non-group-executable file (with clear S_IXGRP bit) | |
75 | the S_ISGID bit indicates mandatory locking, and is not cleared | |
76 | by a | |
77 | .IR chown . | |
78 | ||
79 | .SH "RETURN VALUE" | |
80 | On success, zero is returned. On error, \-1 is returned, and | |
81 | .I errno | |
82 | is set appropriately. | |
83 | .SH ERRORS | |
84 | Depending on the file system, other errors can be returned. The more | |
85 | general errors for | |
86 | .B chown | |
87 | are listed below. | |
88 | .TP | |
89 | .B EACCES | |
90 | Search 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 | |
96 | points outside your accessible address space. | |
97 | .TP | |
98 | .B ELOOP | |
99 | Too many symbolic links were encountered in resolving | |
100 | .IR path . | |
101 | .TP | |
102 | .B ENAMETOOLONG | |
103 | .I path | |
104 | is too long. | |
105 | .TP | |
106 | .B ENOENT | |
107 | The file does not exist. | |
108 | .TP | |
109 | .B ENOMEM | |
110 | Insufficient kernel memory was available. | |
111 | .TP | |
112 | .B ENOTDIR | |
113 | A component of the path prefix is not a directory. | |
114 | .TP | |
115 | .B EPERM | |
116 | The calling process did not have the required permissions | |
117 | (see above) to change owner and/or group. | |
118 | .TP | |
119 | .B EROFS | |
120 | The named file resides on a read-only file system. | |
121 | .PP | |
122 | The general errors for | |
123 | .B fchown | |
124 | are listed below: | |
125 | .TP | |
126 | .B EBADF | |
127 | The descriptor is not valid. | |
128 | .TP | |
129 | .B EIO | |
130 | A low-level I/O error occurred while modifying the inode. | |
131 | .TP | |
132 | .B ENOENT | |
133 | See above. | |
134 | .TP | |
135 | .B EPERM | |
136 | See above. | |
137 | .TP | |
138 | .B EROFS | |
139 | See above. | |
140 | .SH NOTES | |
141 | In versions of Linux prior to 2.1.81 (and distinct from 2.1.46), | |
142 | .B chown | |
143 | did not follow symbolic links. | |
144 | Since Linux 2.1.81, | |
145 | .B chown | |
146 | does follow symbolic links, and there is a new system call | |
147 | .B lchown | |
148 | that does not follow symbolic links. | |
149 | Since Linux 2.1.86, this new call (that has the same semantics | |
150 | as the old | |
151 | .BR chown ) | |
152 | has got the same syscall number, and | |
153 | .B chown | |
154 | got the newly introduced number. | |
155 | .LP | |
156 | The prototype for | |
157 | .B fchown | |
158 | is only available if | |
159 | .B _BSD_SOURCE | |
160 | is defined (either explicitly, or implicitly, by not defining | |
161 | _POSIX_SOURCE or compiling with the -ansi flag). | |
162 | .SH "CONFORMING TO" | |
163 | The | |
164 | .B chown | |
165 | call conforms to SVr4, SVID, POSIX, X/OPEN. The 4.4BSD version can only be | |
166 | used by the superuser (that is, ordinary users cannot give away files). | |
167 | SVr4 documents EINVAL, EINTR, ENOLINK and EMULTIHOP returns, but no | |
168 | ENOMEM. POSIX.1 does not document ENOMEM or ELOOP error conditions. | |
169 | .PP | |
170 | The | |
171 | .B fchown | |
172 | call conforms to 4.4BSD and SVr4. | |
173 | SVr4 documents additional EINVAL, EIO, EINTR, and ENOLINK error conditions. | |
174 | .SH RESTRICTIONS | |
175 | The \fBchown\fP() semantics are deliberately violated on NFS file systems | |
176 | which have UID mapping enabled. Additionally, the semantics of all system | |
177 | calls which access the file contents are violated, because \fBchown\fP() | |
178 | may cause immediate access revocation on already open files. Client side | |
179 | caching may lead to a delay between the time where ownership have | |
180 | been changed to allow access for a user and the time where the file can | |
181 | actually 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) |