summaryrefslogtreecommitdiff
path: root/usr/src/man/man2/chown.2
blob: 72c42a6a5f1728905254fa740193595df9e35260 (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
'\" te
.\" Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved.
.\" Copyright 1989 AT&T
.\" 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]
.TH CHOWN 2 "Mar 2, 2021"
.SH NAME
chown, lchown, fchown, fchownat \- change owner and group of a file
.SH SYNOPSIS
.nf
#include <unistd.h>
#include <sys/types.h>

\fBint\fR \fBchown\fR(\fBconst char *\fR\fIpath\fR, \fBuid_t\fR \fIowner\fR, \fBgid_t\fR \fIgroup\fR);
.fi

.LP
.nf
\fBint\fR \fBlchown\fR(\fBconst char *\fR\fIpath\fR, \fBuid_t\fR \fIowner\fR, \fBgid_t\fR \fIgroup\fR);
.fi

.LP
.nf
\fBint\fR \fBfchown\fR(\fBint\fR \fIfildes\fR, \fBuid_t\fR \fIowner\fR, \fBgid_t\fR \fIgroup\fR);
.fi

.LP
.nf
\fBint\fR \fBfchownat\fR(\fBint\fR \fIfildes\fR, \fBconst char *\fR\fIpath\fR, \fBuid_t\fR \fIowner\fR,
     \fBgid_t\fR \fIgroup\fR, \fBint\fR \fIflag\fR);
.fi

.SH DESCRIPTION
The \fBchown()\fR function sets the owner \fBID\fR and group \fBID\fR of the
file specified by \fIpath\fR or referenced by the open file descriptor
\fIfildes\fR to \fIowner\fR and \fIgroup\fR respectively. If \fIowner\fR or
\fIgroup\fR is specified as \(mi1, \fBchown()\fR does not change the
corresponding \fBID\fR of the file.
.sp
.LP
The  \fBlchown()\fR function sets the owner \fBID\fR and group \fBID\fR of the
named file in the same manner as \fBchown()\fR, unless the named file is a
symbolic link. In this case, \fBlchown()\fR changes the ownership of the
symbolic link file itself, while \fBchown()\fR changes the ownership of the
file or directory to which the symbolic link refers.
.sp
.LP
The \fBfchownat()\fR function sets the owner ID and group ID of the named  file
in the same manner as \fBchown()\fR. If, however, the \fIpath\fR argument is
relative, the path is resolved relative to the \fIfildes\fR argument rather
than the current working directory.  If the \fIfildes\fR argument has the
special value \fBAT_FDCWD\fR, the path resolution reverts back to current
working directory relative.  If the \fIflag\fR argument is set to \fBAT_SYMLINK_NOFOLLOW\fR,
the function behaves like \fBlchown()\fR with respect to symbolic links. If the
\fIpath\fR argument is absolute, the \fIfildes\fR argument is ignored.  If the
\fIpath\fR argument is a null pointer, the function behaves like
\fBfchown()\fR.
.sp
.LP
If  \fBchown()\fR, \fBlchown()\fR, \fBfchown()\fR, or \fBfchownat()\fR is
invoked by a process that does not have {\fBPRIV_FILE_SETID\fR} asserted in its
effective set, the set-user-ID and set-group-ID bits of the file mode,
\fBS_ISUID\fR and  \fBS_ISGID\fR respectively, are cleared (see
\fBchmod\fR(2)). Additional restrictions apply when changing the ownership to
uid 0.
.sp
.LP
The operating system defines several privileges to override restrictions on the
\fBchown()\fR family of functions. When the {\fBPRIV_FILE_CHOWN\fR} 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 {\fBPRIV_FILE_CHOWN_SELF\fR} 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.
.sp
.LP
The operating system provides a configuration option,
{\fB_POSIX_CHOWN_RESTRICTED\fR}, to control the default behavior of processes
and the behavior of the NFS server.  If {\fB_POSIX_CHOWN_RESTRICTED\fR} is not
in effect, the privilege {\fBPRIV_FILE_CHOWN_SELF\fR} is asserted in the
inheritable set of all processes unless overridden by \fBpolicy.conf\fR(4) or
\fBuser_attr\fR(4). To set this configuration option, include the following
line in \fB/etc/system\fR:
.sp
.LP
set rstchown = 1
.sp
.LP
To disable this option, include the following line in  \fB/etc/system\fR:
.sp
.LP
set rstchown = 0
.sp
.LP
See \fBsystem\fR(4) and  \fBfpathconf\fR(2).
.sp
.LP
Upon successful completion, \fBchown()\fR, \fBfchown()\fR and \fBlchown()\fR
mark for update the \fBst_ctime\fR field of the file.
.SH RETURN VALUES
Upon successful completion, \fB0\fR is returned. Otherwise, \fB\(mi1\fR is
returned, the owner and group of the named file remain unchanged, and
\fBerrno\fR is set to indicate the error.
.SH ERRORS
All of these functions will fail if:
.sp
.ne 2
.na
\fB\fBEPERM\fR\fR
.ad
.RS 9n
The effective user ID does not match the owner of the file and the
{\fBPRIV_FILE_CHOWN\fR} privilege is not asserted in the effective set of the
calling process, or the {\fBPRIV_FILE_CHOWN_SELF\fR} privilege is not asserted
in the effective set of the calling process.
.RE

.sp
.LP
The \fBchown()\fR, \fBlchown()\fR, and \fBfchownat()\fR functions will fail if:
.sp
.ne 2
.na
\fB\fBEACCES\fR\fR
.ad
.RS 16n
Search permission is denied on a component of the path prefix of \fIpath\fR.
.RE

.sp
.ne 2
.na
\fB\fBEFAULT\fR\fR
.ad
.RS 16n
The \fIpath\fR argument points to an illegal address and for \fBfchownat()\fR,
the file descriptor has the value \fBAT_FDCWD\fR.
.RE

.sp
.ne 2
.na
\fB\fBEINTR\fR\fR
.ad
.RS 16n
A signal was caught during the execution of the \fBchown()\fR or \fBlchown()\fR
function.
.RE

.sp
.ne 2
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 16n
The \fIgroup\fR or \fIowner\fR argument is out of range.
.RE

.sp
.ne 2
.na
\fB\fBEIO\fR\fR
.ad
.RS 16n
An I/O error occurred while reading from or writing to the file system.
.RE

.sp
.ne 2
.na
\fB\fBELOOP\fR\fR
.ad
.RS 16n
Too many symbolic links were encountered in translating \fIpath\fR.
.RE

.sp
.ne 2
.na
\fB\fBENAMETOOLONG\fR\fR
.ad
.RS 16n
The length of the \fIpath\fR argument exceeds {\fIPATH_MAX\fR}, or the length
of a \fIpath\fR component exceeds {\fINAME_MAX\fR} while
{\fB_POSIX_NO_TRUNC\fR} is in effect.
.RE

.sp
.ne 2
.na
\fB\fBENOLINK\fR\fR
.ad
.RS 16n
The \fIpath\fR argument points to a remote machine and the link to that machine
is no longer active.
.RE

.sp
.ne 2
.na
\fB\fBENOENT\fR\fR
.ad
.RS 16n
Either a component of the path prefix or the file referred to by \fIpath\fR
does not exist or is a null pathname.
.RE

.sp
.ne 2
.na
\fB\fBENOTDIR\fR\fR
.ad
.RS 16n
A component of the path prefix of \fIpath\fR is not a directory, or the path
supplied to \fBfchownat()\fR is relative and the file descriptor provided does
not refer to a valid directory.
.RE

.sp
.ne 2
.na
\fB\fBEROFS\fR\fR
.ad
.RS 16n
The named file  resides on a read-only file system.
.RE

.sp
.LP
The \fBfchown()\fR and \fBfchownat()\fR functions will fail if:
.sp
.ne 2
.na
\fB\fBEBADF\fR\fR
.ad
.RS 11n
For \fBfchown()\fR the \fIfildes\fR argument is not an open file descriptor
and.
.sp
For \fBfchownat()\fR, the \fIpath\fR argument is not absolute and the
\fIfildes\fR argument is not \fBAT_FDCWD\fR or an open file descriptor.
.RE

.sp
.ne 2
.na
\fB\fBEIO\fR\fR
.ad
.RS 11n
An I/O error occurred while reading from or writing to the file system.
.RE

.sp
.ne 2
.na
\fB\fBEINTR\fR\fR
.ad
.RS 11n
A signal was caught during execution of the function.
.RE

.sp
.ne 2
.na
\fB\fBENOLINK\fR\fR
.ad
.RS 11n
The \fIfildes\fR argument points to a remote machine and the link to that
machine is no longer active.
.RE

.sp
.ne 2
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 11n
The \fIgroup\fR or \fIowner\fR argument is out of range.
.RE

.sp
.ne 2
.na
\fB\fBEROFS\fR\fR
.ad
.RS 11n
The named file referred to by \fIfildes\fR resides on a read-only file system.
.RE

.SH ATTRIBUTES
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Interface Stability	See below.
_
MT-Level	See below.
.TE

.sp
.LP
The \fBchown()\fR, \fBfchown()\fR, and \fBlchown()\fR functions are Standard.
The \fBfchownat()\fR function is Evolving.
.sp
.LP
The \fBchown()\fR and \fBfchownat()\fR functions are Async-Signal-Safe.
.SH SEE ALSO
\fBchgrp\fR(1), \fBchown\fR(1), \fBchmod\fR(2), \fBfpathconf\fR(2),
\fBsystem\fR(4), \fBattributes\fR(5), \fBstandards\fR(5)