NAME
chown, lchown, fchown - Changes the owner and group IDs of
a file
SYNOPSIS
int chown(
const char *path,
uid_t owner,
gid_t group );
int lchown(
const char *path,
uid_t owner,
gid_t group );
int fchown(
int filedes,
uid_t owner,
gid_t group );
PARAMETERS
path Specifies the name of the file whose owner ID,
group ID, or both are to be changed. When the
path parameter refers to a symbolic link, the
behaviors of the chown() and the lchown() func-
tions differ. The chown() function changes the
ownership of the file pointed to by the symbolic
link. The lchown() function changes the ownership
of the symbolic link file itself.
filedes Specifies a valid open file descriptor.
owner Specifies a numeric value representing the owner
ID.
group Specifies a numeric value representing the group
ID.
DESCRIPTION
The chown(), lchown() and fchown() functions change the
owner and group of a file.
A process can change the value of the owner ID of a file
only if the process has superuser privilege. A process can
change the value of the file group ID if the effective user
ID of the process matches the owner ID of the file, or if
the process has superuser privilege. A process without
superuser privilege can change the group ID of a file only
to the value of its effective group ID or to a value in its
supplementary group list.
If the value of the owner ID is changed and the process does
not have superuser privilege, the set-user ID attribute (the
S_ISUID bit) of a regular file is cleared.
The set-user ID attribute (S_ISUID bit) of a file is cleared
upon successful return if:
o The file is a regular file.
o The process does not have superuser privilege.
The set-group ID attribute (S_ISGID bit) of a file is
cleared upon successful return if:
o The file is a regular file.
o The process does not have superuser privilege.
If the owner or group parameter is specified as (uid_t)-1 or
(gid_t)-t respectively, the corresponding ID of the file is
unchanged.
Upon successful completion, the chown(), lchown(), and
fchown() functions mark the st_ctime field of the file for
update.
AES Support Level:
Full use (chown())
Full use (lchown())
Trial use (fchown())
RETURN VALUES
Upon successful completion, the chown(), lchown(), and
fchown() functions return a value of 0 (zero). Otherwise, a
value of -1 is returned, the owner and group of the file
remain unchanged, and errno is set to indicate the error.
ERRORS
If the chown() and lchown() functions fail, errno may be set
to one of the following values:
[EACCES] Search permission is denied on a component of
path.
[EFAULT] The path parameter is an invalid address.
[ELOOP] Too many links were encountered in translating
path.
[ENAMETOOLONG]
The length of the path argument exceeds PATH_MAX
or a pathname component is longer than NAME_MAX.
[ENOTDIR] A component of path is not a directory.
[ENOENT] The path parameter does not exist or is an empty
string.
[EPERM] The effective user ID does not match the ID of the
owner of the file, and the calling process does
not have appropriate privilege and
[_POSIX_CHOWN_RESTRICTED} indicates that such
privilege is required.
[EROFS] The named file resides on a read-only file system.
If the fchown() function fails, errno may be set to one of
the following values:
[EBADF] The file descriptor filedes is not valid.
[EROFS] The file referred to by filedes resides on a
read-only file system.
[EPERM] The effective user ID does not match the ID of the
owner of the file, and the calling process does
not have appropriate privilege and
[_POSIX_CHOWN_RESTRICTED} indicates that such
privilege is required.
RELATED INFORMATION
Functions: chmod(2)
Commands: chown(1)
Acknowledgement and Disclaimer