CHOWN(2)
NAME
chown, fchown − 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;
int fchown (fildes, owner, group)
int fildes;
uid_t owner;
gid_t group;
DESCRIPTION
Chown changes the user and group ownership of a file. The path argument points to a path name naming a file. The fildes argument is a file descriptor. The chown and fchown functions set the owner ID and group ID of the file to the numeric values contained in owner and group respectively. A value of UID_NO_CHANGE or GID_NO_CHANGE can be specified in owner or group to leave unchanged the file’s owner ID or group ID respectively. Note that owner and group should be less than or equal to UID_MAX (see limits(5)).
Only processes with effective user ID equal to the file owner or superuser can change the ownership of a file. If privilege groups are supported, the owner of a file can change the ownership only if he is a member of a privilege group allowing CHOWN, as set up by setprivgrp(1M). All users get CHOWN privileges by default.
The group ownership of a file can be changed to any group in the current process’s access list or to the real or effective group ID of the current process. If privilege groups are supported and the user is permitted the CHOWN privilege, the file can be given to any group.
If chown is invoked on a regular file by other than the superuser, the set-user-ID and set-group-ID bits of the file mode are cleared. Whether chown preserves or clears these bits on files of other types is implementation dependent.
Access Control Lists (ACLs)
A user can allow or deny specific individuals and groups access to a file by using the file’s access control list (see acl(5)). When using chown(2) in conjunction with ACLs, if the new owner and/or group does not have an optional ACL entry corresponding to u.% and/or %.g in the file’s access control list, the file’s access permission bits remain unchanged. However, if the new owner and/or group is already designated by an optional ACL entry of u.% and/or %.g, chown sets the file’s permission bits (and the three basic ACL entries) to the permissions contained in that entry.
ERRORS
Chown fails and the owner and group of the file remain unchanged if one or more of the following is true:
[EBADF] Fildes is not a valid file descriptor.
[ENOTDIR] A component of the path prefix is not a directory.
[ENOENT] The file named by path does not exist.
[EACCES] Search permission is denied on a component of the path prefix.
[EPERM] The effective user ID is not superuser and one or more of the following conditions exist:
The effective user ID does not match the owner of the file.
When changing the owner of the file, if the owner of the file is not a member of a privilege group allowing the CHOWN privilege.
When changing the group of the file, if the owner of the file is not a member of a privilege group allowing the CHOWN privilege and the group number is not in the current process’s access list.
[EROFS] The named file resides on a read-only file system.
[EFAULT] Path points outside the allocated address space of the process. The reliable detection of this error will be implementation dependent.
[ENAMETOOLONG]
A component of path exceeds NAME_MAX bytes while _POSIX_NO_TRUNC is in effect, or path exceeds PATH_MAX bytes.
[ELOOP] Too many symbolic links were encountered in translating path.
DEPENDENCIES
HP Clustered Environment:
Chown does not clear the set-user-ID bit of a directory, because that bit indicates that the directory is hidden (see cdf(4)).
When chown is called from a diskless node, the privilege groups checked are the ones set up on the cluster server.
RETURN VALUE
Upon successful completion, a value of 0 is returned. Otherwise, a value of −1 is returned and errno is set to indicate the error.
AUTHOR
Fchown was developed by the University of California, Berkeley.
SEE ALSO
chown(1), setprivgrp(1M), chmod(2), setacl(2), acl(5), limits(5).
STANDARDS CONFORMANCE
chown: SVID2, XPG2, XPG3, POSIX.1, FIPS 151-1
Hewlett-Packard Company — HP-UX Release 7.0: Sept 1989