xref: /illumos-gate/usr/src/man/man2/chown.2 (revision bbf215553c7233fbab8a0afdf1fac74c44781867)
1c10c16deSRichard Lowe'\" te
2c10c16deSRichard Lowe.\" Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved.
3c10c16deSRichard Lowe.\" Copyright 1989 AT&T
4fc1e9305SRobert Mustacchi.\" Copyright 2021 Oxide Computer Company
5c10c16deSRichard Lowe.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
6c10c16deSRichard Lowe.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
7c10c16deSRichard Lowe.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
8fc1e9305SRobert Mustacchi.Dd March 13, 2021
9fc1e9305SRobert Mustacchi.Dt CHOWN 2
10fc1e9305SRobert Mustacchi.Os
11fc1e9305SRobert Mustacchi.Sh NAME
12fc1e9305SRobert Mustacchi.Nm chown ,
13fc1e9305SRobert Mustacchi.Nm lchown ,
14fc1e9305SRobert Mustacchi.Nm fchown ,
15fc1e9305SRobert Mustacchi.Nm fchownat
16fc1e9305SRobert Mustacchi.Nd change owner and group of a file
17fc1e9305SRobert Mustacchi.Sh SYNOPSIS
18fc1e9305SRobert Mustacchi.In unistd.h
19fc1e9305SRobert Mustacchi.In sys/types.h
20fc1e9305SRobert Mustacchi.Ft int
21fc1e9305SRobert Mustacchi.Fo chown
22fc1e9305SRobert Mustacchi.Fa "const char *path"
23fc1e9305SRobert Mustacchi.Fa "uid_t owner"
24fc1e9305SRobert Mustacchi.Fa "gid_t group"
25fc1e9305SRobert Mustacchi.Fc
26fc1e9305SRobert Mustacchi.Ft int
27fc1e9305SRobert Mustacchi.Fo lchown
28fc1e9305SRobert Mustacchi.Fa "const char *path"
29fc1e9305SRobert Mustacchi.Fa "uid_t owner"
30fc1e9305SRobert Mustacchi.Fa "gid_t group"
31fc1e9305SRobert Mustacchi.Fc
32fc1e9305SRobert Mustacchi.Ft int
33fc1e9305SRobert Mustacchi.Fo fchown
34fc1e9305SRobert Mustacchi.Fa "int fildes"
35fc1e9305SRobert Mustacchi.Fa "uid_t owner"
36fc1e9305SRobert Mustacchi.Fa "gid_t group"
37fc1e9305SRobert Mustacchi.Fc
38fc1e9305SRobert Mustacchi.Ft int
39fc1e9305SRobert Mustacchi.Fo fchownat
40fc1e9305SRobert Mustacchi.Fa "int fildes"
41fc1e9305SRobert Mustacchi.Fa "const char *path"
42fc1e9305SRobert Mustacchi.Fa "uid_t owner"
43fc1e9305SRobert Mustacchi.Fa "gid_t group"
44fc1e9305SRobert Mustacchi.Fa "int flag"
45fc1e9305SRobert Mustacchi.Fc
46fc1e9305SRobert Mustacchi.Sh DESCRIPTION
47fc1e9305SRobert MustacchiThe
48fc1e9305SRobert Mustacchi.Fn chown
49fc1e9305SRobert Mustacchiand
50fc1e9305SRobert Mustacchi.Fn fchown
51fc1e9305SRobert Mustacchifunctions set the owner
52fc1e9305SRobert Mustacchi.Sy ID
53fc1e9305SRobert Mustacchiand group
54fc1e9305SRobert Mustacchi.Sy ID
55fc1e9305SRobert Mustacchiof the file specified by
56fc1e9305SRobert Mustacchi.Fa path
57fc1e9305SRobert Mustacchior referenced by the open file descriptor
58fc1e9305SRobert Mustacchi.Fa fildes
59fc1e9305SRobert Mustacchito
60fc1e9305SRobert Mustacchi.Fa owner
61fc1e9305SRobert Mustacchiand
62fc1e9305SRobert Mustacchi.Fa group
63fc1e9305SRobert Mustacchirespectively.
64fc1e9305SRobert MustacchiIf
65fc1e9305SRobert Mustacchi.Fa owner
66fc1e9305SRobert Mustacchior
67fc1e9305SRobert Mustacchi.Fa group
68fc1e9305SRobert Mustacchiis specified as -1,
69fc1e9305SRobert Mustacchi.Fn chown
70fc1e9305SRobert Mustacchiand
71fc1e9305SRobert Mustacchi.Fn fchown
72fc1e9305SRobert Mustacchido not change the corresponding
73fc1e9305SRobert Mustacchi.Sy ID
74fc1e9305SRobert Mustacchiof the file.
75fc1e9305SRobert Mustacchi.Pp
76fc1e9305SRobert MustacchiThe
77fc1e9305SRobert Mustacchi.Fn lchown
78fc1e9305SRobert Mustacchifunction sets the owner
79fc1e9305SRobert Mustacchi.Sy ID
80fc1e9305SRobert Mustacchiand group
81fc1e9305SRobert Mustacchi.Sy ID
82fc1e9305SRobert Mustacchiof the named file in the same manner as
83fc1e9305SRobert Mustacchi.Fn chown ,
84fc1e9305SRobert Mustacchiunless the named file is a symbolic link.
85fc1e9305SRobert MustacchiIn this case,
86fc1e9305SRobert Mustacchi.Fn lchown
87fc1e9305SRobert Mustacchichanges the ownership of the symbolic link file itself, while
88fc1e9305SRobert Mustacchi.Fn chown
89fc1e9305SRobert Mustacchichanges the ownership of the file or directory to which the symbolic link
90fc1e9305SRobert Mustacchirefers.
91fc1e9305SRobert Mustacchi.Pp
92fc1e9305SRobert MustacchiThe
93fc1e9305SRobert Mustacchi.Fn fchownat
94fc1e9305SRobert Mustacchifunction sets the owner ID and group ID of the named  file
95fc1e9305SRobert Mustacchiin the same manner as
96fc1e9305SRobert Mustacchi.Fn chown .
97fc1e9305SRobert MustacchiIf, however, the
98fc1e9305SRobert Mustacchi.Fa path
99fc1e9305SRobert Mustacchiargument is relative
100fc1e9305SRobert Mustacchi.Po
101fc1e9305SRobert Mustacchidoes not start with a
102fc1e9305SRobert Mustacchi.Qq /
103fc1e9305SRobert Mustacchi.Pc ,
104fc1e9305SRobert Mustacchithe path is resolved relative to the
105fc1e9305SRobert Mustacchi.Fa fildes
106fc1e9305SRobert Mustacchiargument rather than the current working directory.
107fc1e9305SRobert MustacchiIf the
108fc1e9305SRobert Mustacchi.Fa fildes
109fc1e9305SRobert Mustacchiargument has the special value
110fc1e9305SRobert Mustacchi.Dv AT_FDCWD ,
111fc1e9305SRobert Mustacchithe path resolution reverts back to current working directory relative.
112fc1e9305SRobert MustacchiIf the
113fc1e9305SRobert Mustacchi.Fa flag
114fc1e9305SRobert Mustacchiargument is set to
115fc1e9305SRobert Mustacchi.Dv AT_SYMLINK_NOFOLLOW ,
116fc1e9305SRobert Mustacchithe function behaves like
117fc1e9305SRobert Mustacchi.Fn lchown
118fc1e9305SRobert Mustacchiwith respect to symbolic links.
119fc1e9305SRobert MustacchiIf the
120fc1e9305SRobert Mustacchi.Fa path
121fc1e9305SRobert Mustacchiargument is absolute, the
122fc1e9305SRobert Mustacchi.Fa fildes
123fc1e9305SRobert Mustacchiargument is ignored.
124fc1e9305SRobert MustacchiIf the
125fc1e9305SRobert Mustacchi.Fa path
126fc1e9305SRobert Mustacchiargument is a null pointer, the function behaves like
127fc1e9305SRobert Mustacchi.Fn fchown .
128fc1e9305SRobert Mustacchi.Pp
129fc1e9305SRobert MustacchiIf
130fc1e9305SRobert Mustacchi.Fn chown ,
131fc1e9305SRobert Mustacchi.Fn lchown ,
132fc1e9305SRobert Mustacchi.Fn fchown ,
133fc1e9305SRobert Mustacchior
134fc1e9305SRobert Mustacchi.Fn fchownat
135fc1e9305SRobert Mustacchiis invoked by a process that does not have
136fc1e9305SRobert Mustacchi.Brq Dv PRIV_FILE_SETID
137fc1e9305SRobert Mustacchiasserted in its effective set, the set-user-ID and set-group-ID bits of the
138fc1e9305SRobert Mustacchifile mode,
139fc1e9305SRobert Mustacchi.Dv S_ISUID
140fc1e9305SRobert Mustacchiand
141fc1e9305SRobert Mustacchi.Dv S_ISGID
142fc1e9305SRobert Mustacchirespectively, are cleared
143fc1e9305SRobert Mustacchi.Po
144fc1e9305SRobert Mustacchisee
145fc1e9305SRobert Mustacchi.Xr chmod 2
146fc1e9305SRobert Mustacchi.Pc .
147fc1e9305SRobert MustacchiAdditional restrictions apply when changing the ownership to uid 0.
148fc1e9305SRobert Mustacchi.Pp
149c10c16deSRichard LoweThe operating system defines several privileges to override restrictions on the
150fc1e9305SRobert Mustacchi.Fn chown
151fc1e9305SRobert Mustacchifamily of functions.
152fc1e9305SRobert MustacchiWhen the
153fc1e9305SRobert Mustacchi.Brq Dv PRIV_FILE_CHOWN
154fc1e9305SRobert Mustacchiprivilege is asserted in the effective set of the current process, there are no
155c10c16deSRichard Lowerestrictions except in the special circumstances of changing ownership to or
156fc1e9305SRobert Mustacchifrom uid 0.
157fc1e9305SRobert MustacchiWhen the
158fc1e9305SRobert Mustacchi.Brq Dv PRIV_FILE_CHOWN_SELF
159fc1e9305SRobert Mustacchiprivilege is asserted, ownership changes are restricted to the files of which
160fc1e9305SRobert Mustacchithe ownership matches the effective user ID of the current process.
161fc1e9305SRobert MustacchiIf neither privilege is asserted in the effective set of the calling process,
162fc1e9305SRobert Mustacchiownership changes are limited to changes of the group of the file to the list of
163fc1e9305SRobert Mustacchisupplementary group IDs and the effective group ID.
164fc1e9305SRobert Mustacchi.Pp
165c10c16deSRichard LoweThe operating system provides a configuration option,
166fc1e9305SRobert Mustacchi.Brq Dv _POSIX_CHOWN_RESTRICTED ,
167fc1e9305SRobert Mustacchito control the default behavior of processes and the behavior of the NFS server.
168fc1e9305SRobert MustacchiIf
169fc1e9305SRobert Mustacchi.Brq Dv B_POSIX_CHOWN_RESTRICTED
170fc1e9305SRobert Mustacchiis not in effect, the privilege
171fc1e9305SRobert Mustacchi.Brq PRIV_FILE_CHOWN_SELF
172fc1e9305SRobert Mustacchiis asserted in the inheritable set of all processes unless overridden by
173*bbf21555SRichard Lowe.Xr policy.conf 5
174fc1e9305SRobert Mustacchior
175*bbf21555SRichard Lowe.Xr user_attr 5 .
176fc1e9305SRobert MustacchiTo set this configuration option, include the following
177fc1e9305SRobert Mustacchiline in
178fc1e9305SRobert Mustacchi.Pa /etc/system :
179fc1e9305SRobert Mustacchi.Bd -literal -offset indent
180c10c16deSRichard Loweset rstchown = 1
181fc1e9305SRobert Mustacchi.Ed
182fc1e9305SRobert Mustacchi.Pp
183fc1e9305SRobert MustacchiTo disable this option, include the following line in
184fc1e9305SRobert Mustacchi.Pa /etc/system :
185fc1e9305SRobert Mustacchi.Bd -literal -offset indent
186c10c16deSRichard Loweset rstchown = 0
187fc1e9305SRobert Mustacchi.Ed
188fc1e9305SRobert Mustacchi.Pp
189fc1e9305SRobert MustacchiSee
190*bbf21555SRichard Lowe.Xr system 5
191fc1e9305SRobert Mustacchiand
192fc1e9305SRobert Mustacchi.Xr fpathconf 2 .
193fc1e9305SRobert Mustacchi.Pp
194fc1e9305SRobert MustacchiUpon successful completion,
195fc1e9305SRobert Mustacchi.Fn chown ,
196fc1e9305SRobert Mustacchi.Fn fchown ,
197fc1e9305SRobert Mustacchi.Fn lchown ,
198fc1e9305SRobert Mustacchiand
199fc1e9305SRobert Mustacchi.Fn fchownat
200fc1e9305SRobert Mustacchimark for update the
201fc1e9305SRobert Mustacchi.Fa st_ctime
202fc1e9305SRobert Mustacchifield of the file.
203fc1e9305SRobert Mustacchi.Sh RETURN VALUES
204fc1e9305SRobert MustacchiUpon successful completion,
205fc1e9305SRobert Mustacchi.Sy 0
206fc1e9305SRobert Mustacchiis returned.
207fc1e9305SRobert MustacchiOtherwise,
208fc1e9305SRobert Mustacchi.Sy -1
209fc1e9305SRobert Mustacchiis returned, the owner and group of the named file remain unchanged, and
210fc1e9305SRobert Mustacchi.Va errno
211fc1e9305SRobert Mustacchiis set to indicate the error.
212fc1e9305SRobert Mustacchi.Sh ERRORS
213c10c16deSRichard LoweAll of these functions will fail if:
214fc1e9305SRobert Mustacchi.Bl -tag -width Er
215fc1e9305SRobert Mustacchi.It Er EPERM
216c10c16deSRichard LoweThe effective user ID does not match the owner of the file and the
217fc1e9305SRobert Mustacchi.Brq Dv PRIV_FILE_CHOWN
218fc1e9305SRobert Mustacchiprivilege is not asserted in the effective set of the calling process, or the
219fc1e9305SRobert Mustacchi.Brq Dv PRIV_FILE_CHOWN_SELF
220fc1e9305SRobert Mustacchiprivilege is not asserted in the effective set of the calling process.
221fc1e9305SRobert Mustacchi.El
222fc1e9305SRobert Mustacchi.Pp
223fc1e9305SRobert MustacchiThe
224fc1e9305SRobert Mustacchi.Fn chown ,
225fc1e9305SRobert Mustacchi.Fn lchown ,
226fc1e9305SRobert Mustacchiand
227fc1e9305SRobert Mustacchi.Fn fchownat
228fc1e9305SRobert Mustacchifunctions will fail if:
229fc1e9305SRobert Mustacchi.Bl -tag -width Er
230fc1e9305SRobert Mustacchi.It Er EACCES
231fc1e9305SRobert MustacchiSearch permission is denied on a component of the path prefix of
232fc1e9305SRobert Mustacchi.Fa path .
233fc1e9305SRobert Mustacchi.It Er EFAULT
234fc1e9305SRobert MustacchiThe
235fc1e9305SRobert Mustacchi.Fa path
236fc1e9305SRobert Mustacchiargument points to an illegal address and for
237fc1e9305SRobert Mustacchi.Fn fchownat ,
238fc1e9305SRobert Mustacchithe file descriptor has the value
239fc1e9305SRobert Mustacchi.Dv AT_FDCWD .
240fc1e9305SRobert Mustacchi.It Er EINTR
241fc1e9305SRobert MustacchiA signal was caught during the execution of the
242fc1e9305SRobert Mustacchi.Fn chown
243fc1e9305SRobert Mustacchior
244fc1e9305SRobert Mustacchi.Fn lchown
245c10c16deSRichard Lowefunction.
246fc1e9305SRobert Mustacchi.It Er EINVAL
247fc1e9305SRobert MustacchiThe
248fc1e9305SRobert Mustacchi.Fa group
249fc1e9305SRobert Mustacchior
250fc1e9305SRobert Mustacchi.Fa owner
251fc1e9305SRobert Mustacchiargument is out of range.
252fc1e9305SRobert Mustacchi.It Er EIO
253c10c16deSRichard LoweAn I/O error occurred while reading from or writing to the file system.
254fc1e9305SRobert Mustacchi.It Er ELOOP
255fc1e9305SRobert MustacchiToo many symbolic links were encountered in translating
256fc1e9305SRobert Mustacchi.Fa path .
257fc1e9305SRobert Mustacchi.It Er ENAMETOOLONG
258fc1e9305SRobert MustacchiThe length of the
259fc1e9305SRobert Mustacchi.Fa path
260fc1e9305SRobert Mustacchiargument exceeds
261fc1e9305SRobert Mustacchi.Brq Dv PATH_MAX ,
262fc1e9305SRobert Mustacchior the length of a
263fc1e9305SRobert Mustacchi.Fa path
264fc1e9305SRobert Mustacchicomponent exceeds
265fc1e9305SRobert Mustacchi.Brq Dv NAME_MAX
266fc1e9305SRobert Mustacchiwhile
267fc1e9305SRobert Mustacchi.Brq Dv _POSIX_NO_TRUNC
268fc1e9305SRobert Mustacchiis in effect.
269fc1e9305SRobert Mustacchi.It Er ENOLINK
270fc1e9305SRobert MustacchiThe
271fc1e9305SRobert Mustacchi.Fa path
272fc1e9305SRobert Mustacchiargument points to a remote machine and the link to that machine is no longer
273fc1e9305SRobert Mustacchiactive.
274fc1e9305SRobert Mustacchi.It Er ENOENT
275fc1e9305SRobert MustacchiEither a component of the path prefix or the file referred to by
276fc1e9305SRobert Mustacchi.Fa path
277c10c16deSRichard Lowedoes not exist or is a null pathname.
278fc1e9305SRobert Mustacchi.It Er ENOTDIR
279fc1e9305SRobert MustacchiA component of the path prefix of
280fc1e9305SRobert Mustacchi.Fa path
281fc1e9305SRobert Mustacchiis not a directory, or the path supplied to
282fc1e9305SRobert Mustacchi.Fn fchownat
283fc1e9305SRobert Mustacchiis relative and the file descriptor provided does not refer to a valid
284fc1e9305SRobert Mustacchidirectory.
285fc1e9305SRobert Mustacchi.It Er EROFS
286c10c16deSRichard LoweThe named file resides on a read-only file system.
287fc1e9305SRobert Mustacchi.El
288fc1e9305SRobert Mustacchi.Pp
289fc1e9305SRobert MustacchiThe
290fc1e9305SRobert Mustacchi.Fn chown
291fc1e9305SRobert Mustacchiand
292fc1e9305SRobert Mustacchi.Fn fchownat
293fc1e9305SRobert Mustacchifunctions will fail if:
294fc1e9305SRobert Mustacchi.Bl -tag -width Er
295fc1e9305SRobert Mustacchi.It Er EBADF
296fc1e9305SRobert MustacchiFor
297fc1e9305SRobert Mustacchi.Fn fchown ,
298fc1e9305SRobert Mustacchithe
299fc1e9305SRobert Mustacchi.Fa fildes
300fc1e9305SRobert Mustacchiargument is not an open file descriptor.
301fc1e9305SRobert Mustacchi.Pp
302fc1e9305SRobert MustacchiFor
303fc1e9305SRobert Mustacchi.Fn fchownat ,
304fc1e9305SRobert Mustacchithe
305fc1e9305SRobert Mustacchi.Fa path
306fc1e9305SRobert Mustacchiargument is not absolute and the fildes argument is neither
307fc1e9305SRobert Mustacchi.Dv AT_FDCWD ,
308fc1e9305SRobert Mustacchinor an open file descriptor.
309fc1e9305SRobert Mustacchi.It Er EIO
310c10c16deSRichard LoweAn I/O error occurred while reading from or writing to the file system.
311fc1e9305SRobert Mustacchi.It Er EINTR
312c10c16deSRichard LoweA signal was caught during execution of the function.
313fc1e9305SRobert Mustacchi.It Er ENOLINK
314fc1e9305SRobert MustacchiThe
315fc1e9305SRobert Mustacchi.Fa fildes
316fc1e9305SRobert Mustacchiargument points to a remote machine and the link to that machine is no longer
317fc1e9305SRobert Mustacchiactive.
318fc1e9305SRobert Mustacchi.It Er EINVAL
319fc1e9305SRobert MustacchiThe
320fc1e9305SRobert Mustacchi.Fa group
321fc1e9305SRobert Mustacchior
322fc1e9305SRobert Mustacchi.Fa owner
323fc1e9305SRobert Mustacchiargument is out of range.
324fc1e9305SRobert Mustacchi.It Er EROFS
325fc1e9305SRobert MustacchiThe named file referred to by
326fc1e9305SRobert Mustacchi.Fa fildes
327fc1e9305SRobert Mustacchiresides on a read-only file system.
328fc1e9305SRobert Mustacchi.El
329fc1e9305SRobert Mustacchi.Sh INTERFACE STABILITY
330fc1e9305SRobert Mustacchi.Sy Committed
331fc1e9305SRobert Mustacchi.Sh MT-LEVEL
332fc1e9305SRobert Mustacchi.Sy Async-Signal-Safe
333fc1e9305SRobert Mustacchi.Sh SEE ALSO
334fc1e9305SRobert Mustacchi.Xr chgrp 1 ,
335fc1e9305SRobert Mustacchi.Xr chown 1 ,
336fc1e9305SRobert Mustacchi.Xr chmod 2 ,
337fc1e9305SRobert Mustacchi.Xr fpathconf 2 ,
338*bbf21555SRichard Lowe.Xr system 5 ,
339*bbf21555SRichard Lowe.Xr attributes 7 ,
340*bbf21555SRichard Lowe.Xr standards 7
341