summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Mustacchi <rm@fingolfin.org>2021-03-13 12:11:21 -0800
committerRobert Mustacchi <rm@fingolfin.org>2021-03-18 13:28:27 -0700
commitfc1e9305ae86a296023d90240041e860548ba1bd (patch)
treecec26dd81ee1bd4111898360915efdb34646d18e
parent173f6047c6877d03cbb55428e6ec95f07c9cbb83 (diff)
downloadillumos-joyent-fc1e9305ae86a296023d90240041e860548ba1bd.tar.gz
13627 chown(2) mixes up chown() and fchown()
Reviewed by: Andy Fiddaman <andy@omnios.org> Approved by: Gordon Ross <gordon.w.ross@gmail.com>
-rw-r--r--usr/src/man/man2/chown.2623
1 files changed, 322 insertions, 301 deletions
diff --git a/usr/src/man/man2/chown.2 b/usr/src/man/man2/chown.2
index 72c42a6a5f..cd0605dd23 100644
--- a/usr/src/man/man2/chown.2
+++ b/usr/src/man/man2/chown.2
@@ -1,319 +1,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]
-.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
+.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
-\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
+.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 {\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
+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,
-{\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
+.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 4
+or
+.Xr user_attr 4 .
+To set this configuration option, include the following
+line in
+.Pa /etc/system :
+.Bd -literal -offset indent
set rstchown = 1
-.sp
-.LP
-To disable this option, include the following line in \fB/etc/system\fR:
-.sp
-.LP
+.Ed
+.Pp
+To disable this option, include the following line in
+.Pa /etc/system :
+.Bd -literal -offset indent
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
+.Ed
+.Pp
+See
+.Xr system 4
+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:
-.sp
-.ne 2
-.na
-\fB\fBEPERM\fR\fR
-.ad
-.RS 9n
+.Bl -tag -width Er
+.It Er EPERM
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
+.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.
-.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
+.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.
-.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
+.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.
-.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
+.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.
-.RE
-
-.sp
-.ne 2
-.na
-\fB\fBEINTR\fR\fR
-.ad
-.RS 11n
+.It Er EINTR
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)
+.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 4 ,
+.Xr attributes 5 ,
+.Xr standards 5