'\" 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 "Oct 9, 2008" .SH NAME chown, lchown, fchown, fchownat \- change owner and group of a file .SH SYNOPSIS .LP .nf #include #include \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 .sp .LP 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 \fBSYMLNK\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 .sp .LP 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 .sp .LP 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 .sp .LP 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 .sp .LP \fBchgrp\fR(1), \fBchown\fR(1), \fBchmod\fR(2), \fBfpathconf\fR(2), \fBsystem\fR(4), \fBattributes\fR(5), \fBstandards\fR(5)