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