chown(2) 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(fd, owner, group) int fd, owner, group; DESCRIPTION The file that is named by path or referenced by fd has its owner and group changed as specified. Only the superuser or the owner of the file may execute this call. chown clears the set-user-ID and set-group-ID bits on the file to prevent accidental creation of set-user-ID and set- group-ID programs owned by the superuser. If chown is invoked successfully by users other than the su- peruser, the set-user-ID and set-group-ID bits of the file mode, 04000 and 02000 respectively, will be cleared. This prevents ordinary users from effectively making themselves other users or members of a group to which they don't be- long. Only one of the owner and group IDs may be set by specifying the other as -1. If the compatibility flag COMPAT_BSDCHOWN is set, chown is restricted to processes with superuser privileges. This compatibility flag also limits a process that has an effec- tive user ID equal to the user ID of the file, but otherwise without appropriate privileges, from changing the file's group ID to the effective group ID of the process only, or to its supplementary group IDs. For the POSIX environment, the COMPAT_BSDCHOWN flag is set to support these added restrictions. RETURN VALUE A value of 0 is returned if the operation was successful; A value of -1 is returned if an error occurs, and a more specific error code is placed in the global variable errno. ERRORS chown will fail and the file will be unchanged if one or more of the following are true: April, 1990 1
chown(2) chown(2)[EINVAL] The argument path does not refer to a file. [ENOTDIR] A component of the path prefix is not a direc- tory. [ENOENT] The argument pathname is too long. [ENOENT] The named file does not exist. [EACCES] Search permission is denied on a component of the path prefix. [EPERM] A pathname contains a character with the high-order bit set. [ENAMETOOLONG] A component of a pathname exceeded NAME_MAX characters, or an entire pathname exceeded PATH_MAX. [ELOOP] Too many symbolic links were encountered in translating a pathname. [EPERM] The effective user ID does not match the owner of the file and the effective user ID is not the superuser. [EROFS] The named file resides on a read-only file system. [EFAULT] The argument path points outside the allocated address space of the process. [ELOOP] Too many symbolic links were encountered in translating the pathname. fchown will fail if one or both of the following are true: [EBADF] The fd does not refer to a valid descriptor. [EINVAL] The fd refers to a socket, not a file. SEE ALSO chown(1), chgrp(2), chmod(2). 2 April, 1990