NAME | SYNOPSIS | DESCRIPTION | RETURN VALUES | ERRORS | ATTRIBUTES | SUMMARY OF TRUSTED SOLARIS CHANGES | SEE ALSO
#include <unistd.h> #include <sys/types.h>int chown(const char * path, uid_t owner, gid_t group);
The chown() function sets the owner ID and group ID of the file specified by path or referenced by the open file descriptor fildes to owner and group respectively. If owner or group is specified as -1, chown() does not change the corresponding ID of the file.
The lchown() function sets the owner ID and group ID of the named file in the same manner as chown() , unless the named file is a symbolic link. In this case, lchown() changes the ownership of the symbolic link file itself, while chown() changes the ownership of the file or directory to which the symbolic link refers.
If
chown()
,
lchown()
, or
fchown()
is invoked, the set-user-
ID
and set-group-
ID
bits of the file mode,
chmod(2)
. respectively, are cleared. See
chmod(2)
. To bypass this restriction, the process may assert the
PRIV_FILE_SETID
privilege.
The operating system has a configuration option,
_POSIX_CHOWN_RESTRICTED
, to restrict ownership changes for the
chown()
,
lchown()
, and
fchown()
functions. When
_POSIX_CHOWN_RESTRICTED
is not in effect, the effective user
ID
of the process must match the owner of the file. To override this restriction, the calling process must assert the
PRIV_FILE_CHOWN
privilege. When
_POSIX_CHOWN_RESTRICTED
is not in effect, the effective user
ID
of the process must match the owner of the file or the process must be the super-user to change the ownership of a file. When
_POSIX_CHOWN_RESTRICTED
is in effect, the
chown()
,
lchown()
, and
fchown()
functions require that the calling process assert the
PRIV_FILE_CHOWN
privilege to change the user
ID
of a file. To change the group
ID
of a file, the process must be the
owner of the file and the new group
ID
must be the group of the process
ID
or must be in the supplementary group list of the process. To override this restriction, the calling process may assert the
PRIV_FILE_CHOWN
privilege.
set rstchown = 1
To disable this option, include the following line in /etc/system :
set rstchown = 0
See system(4) and fpathconf(2) .
Upon successful completion, chown() , fchown() and lchown() mark for update the st_ctime field of the file.
The chown() and lchown() functions will fail if:
Search permission is denied on a component of the path prefix of
path
. To override this restriction, the calling process may assert one or both of these privileges:
PRIV_FILE_DAC_SEARCH
and
PRIV_FILE_MAC_SEARCH
.
Write permission is denied on
path
or
fildes
. To override this restriction, the calling process may assert
the
PRIV_FILE_MAC_WRITE
privilege.
The path argument points to an illegal address.
A signal was caught during the execution of the chown() or lchown() function.
The group or owner argument is out of range.
An I/O error occurred while reading from or writing to the file system.
Too many symbolic links were encountered in translating path .
The length of the path argument exceeds PATH_MAX , or the length of a path component exceeds NAME_MAX while _POSIX_NO_TRUNC is in effect.
The path argument points to a remote machine and the link to that machine is no longer active.
Either a component of the path prefix or the file referred to by path does not exist or is a null pathname.
A component of the path prefix of path is not a directory.
The effective user
ID
does not match the owner of the file. If
_POSIX_CHOWN_RESTRICTED
is set, the calling process must assert the
PRIV_FILE_CHOWN
privilege. If
_POSIX_CHOWN_RESTRICTED
is not set, the calling process may assert the
PRIV_FILE_CHOWN
privilege.
The named file resides on a read-only file system.
The fchown() function will fail if:
The fildes argument is not an open file descriptor.
An I/O error occurred while reading from or writing to the file system.
A signal was caught during execution of the function.
The fildes argument points to a remote machine and the link to that machine is no longer active.
The group or owner argument is out of range.
The effective user ID does not match the owner of the file, or the process is not the super-user and _POSIX_CHOWN_RESTRICTED indicates that such privilege is required.
The named file referred to by fildes resides on a read-only file system.
See attributes(5) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
---|---|
MT-Level | chown() is Async-Signal-Safe |
Appropriate privilege is required to override access checks.
When the ownership of
path
and
fildes
is changed, the set-user-
ID
and set-group-
ID
bits are cleared. The calling process may assert the
PRIV_FILE_SETID
privilege
to bypass this restriction.
To change the user
ID
of the file when the calling process does not own the file and
_POSIX_CHOWN_RESTRICTED
is not in effect, the calling process may assert the
PRIV_FILE_CHOWN
privilege.
To change the group
ID
of the file when the calling process does not own the file, and the new group
ID
is not in the group
ID
of the process or in the supplementary group list of the process, and
_POSIX_CHOWN_RESTRICTED
is not in effect, the calling process may assert the
PRIV_FILE_CHOWN
privilege.
NAME | SYNOPSIS | DESCRIPTION | RETURN VALUES | ERRORS | ATTRIBUTES | SUMMARY OF TRUSTED SOLARIS CHANGES | SEE ALSO