chown(2) chown(2)
NAME
chown, fchown, lchown - change owner and group of a file
SYNOPSIS
#include <sys/types.h>
int chown (path, owner, group)
char *path;
uid_t owner;
gid_t group;
SYNOPSIS (4.2BSD)
#include <sys/types.h>
int lchown (path, owner, group)
char *path;
uid_t owner;
gid_t group;
#include <sys/types.h>
int fchown (fildes, owner, group)
int fildes;
uid_t owner;
gid_t group;
DESCRIPTION
The owner ID and group ID of the file specified by path or
referenced by the descriptor fildes are set to owner and
group respectively. If owner or group is specified as -1,
the corresponding ID of the file is not changed.
If the user is super-user, the privilege ID of the specified
file is set to the numeric value contained in group; other-
wise, the privilege ID of the specified file is set to the
security label of the file's current privilege ID and the
group of the privilege referred to by group. (B1 only)
The function lchown sets the owner ID and group ID of the
named file just as chown does, except in the case where 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.
The operating system has a configuration option
{_POSIX_CHOWN_RESTRICTED}, to restrict ownership changes.
When this option is in effect, a process with effective user
ID these functions. equal to the file owner is prevented
from changing the owner ID of the file, and may change the
group of the file only to a group to which the effective
user ID belongs. Only a process with the effective user ID
Page 1 CX/UX Programmer's Reference Manual
chown(2) chown(2)
of the super-user can arbitrarily change owner IDs whether
this option is in effect or not.
Only super-user can change the file's privilege ID to or
from a privilege ID not defined on the system.
A file's security label cannot be changed if the file is
being held open by another process and the user's real user
ID is not root (character devices are exempted). All file
reclassifications by chown are audited.
If chown, lchown, or fchown is invoked by other than the
super-user, the set-user-ID and set-group-ID bits of the
file mode, S_ISUID and S_ISGID respectively, will be cleared
[see chmod(2)].
Upon successful completion, chown, lchown, and fchown mark
for update the st_ctime field of the file.
chown and lchown will fail and the owner and group of the
named file will remain unchanged if one or more of the fol-
lowing are true:
[EACCES] Search permission is denied on a component of
the path prefix.
[EFAULT] Path points outside the allocated address
space of the process.
[EINVAL] The path argument does not refer to a file.
[ENAMETOOLONG] The path argument exceeds {PATH_MAX} in
length, or a pathname component is longer
than {NAME_MAX} (see pathconf(2)).
[ENOTDIR] A component of the path prefix is not a
directory.
[ENOENT] The named file does not exist, or the path
argument points to an empty string.
[EPERM] The effective user ID is not super-user, the
POSIX_CHOWN_RESTRICTED option is enabled, and
an attempt to change ownership was attempted,
or, the effective user ID is not a member of
group. If the POSIX_CHOWN_RESTRICTED option
is disabled, EPERM will be returned if the
effective user ID is not super-user and the
does not match the owner of the file.
[EPERM] The user's current security label is not
identical to the file's security label and
Page 2 CX/UX Programmer's Reference Manual
chown(2) chown(2)
the effective user ID is not super-user.
[EPERM] The named file is being held open by another
process.
[EPERM] The file's privilege ID cannot be changed
because the new group is not defined at the
file's current security level and the user is
not super-user. (B1 only)
[EROFS] The named file resides on a read-only file
system.
fchown will fail if:
[EBADF] fildes does not refer to a valid descriptor.
[EINVAL] fildes refers to a socket, not a file.
[EPERM] The effective user ID does not match the
owner of the file and the effective user ID
is not super-user, or the user's current
security label is not identical to the file's
security label and the user's effective user
ID is not super-user.
[EROFS] The named file resides on a read-only file
system.
RETURN VALUE
Upon successful completion, a value of 0 is returned. Oth-
erwise, a value of -1 is returned and errno is set to indi-
cate the error.
NOTE
The chown function is defined in the 88open Binary and
Object Compatibility Standards (BCS/OCS) for use in BCS/OCS
compliant applications. The fchown function is defined in
the 88open BCS/OCS Networking Supplements (BCSNS/OCSNS) for
use in BCS/OCS compliant networking applications.
OCS/OCSNS-defined functions may be accessed by passing OCS
options to cc(1) and ld(1).
SEE ALSO
chmod(2), chmod(1SX).
chown(1) in the CX/UX User's Reference Manual.
Consult the system administrator for the configuration of
the POSIX_CHOWN_RESTRICTED option.
Page 3 CX/UX Programmer's Reference Manual