CHOWN(2) CHOWN(2) NAME chown, fchown, lchown - change owner and group of a file C SYNOPSIS #include <sys/types.h> #include <unistd.h> 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 fd, uid_t owner, gid_t group); DESCRIPTION Path points to a path name naming a file, and fd refers to the file descriptor associated with a file. The owner ID and group ID of the named file are set to the numeric values contained in owner and group respectively. Note that lchown differs from chown in that it does not follow symbolic links. Only processes with effective user ID equal to the file owner or super- user may change the ownership of a file. However, if the variable restricted_chown is enabled [see intro(2) and lboot(1M)] then only the super-user can change the owner of the file, because if users were able to give files away, they could defeat the file space accounting procedures. The owner of the file may change the group ownership only to those groups of which he is a member. 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, 04000 and 02000 respectively, will be cleared. Note that this has the side-effect of disabling mandatory file/record locking. Either the owner or group ID may be left unchanged by specifying it as -1. Upon successful completion, chown, lchown, and fchown mark for update the st_ctime field [see stat(2)] 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 following are true: [ENOTDIR] A component of the path prefix is not a directory. [ENOENT] The named file does not exist. [EACCES] Search permission is denied on a component of the path prefix. [EPERM] The effective user ID does not match the owner of the file and the effective user ID is not super-user. [EPERM] restricted_chown is enabled and the effective user ID is not the super-user. [EINVAL] The owner or group value is out of the valid range of -1, MAXUID. [EROFS] The named file resides on a read-only file system. [EFAULT] Path points outside the allocated address space of the process. [ELOOP] A path name lookup involved too many symbolic links. [ENAMETOOLONG] The length of path exceeds {PATH_MAX}, or a pathname component is longer than {NAME_MAX}. fchown will fail if: [EBADF] Fd does not refer to a valid descriptor. [EINVAL] Fd refers to a socket, not a file. The owner or group value is out of the valid range of -1, MAXUID. SEE ALSO DIAGNOSTICS Upon successful completion, a value of 0 is returned. Otherwise, a value of -1 is returned and errno is set to indicate the error. Page 2