int chown(path, owner, group) char *path; int owner; int group; int fchown(fd, owner, group) int fd; int owner; int group;
#include <sys/types.h> int chown(path, owner, group) char *path; uid_t owner; gid_t group;
The file that is named by path or referenced by fd has its owner and group changed as specified. Only the super-user may change the owner of the file, because if users were able to give files away, they could defeat the file-space accounting procedures (see NOTES). The owner of the file may change the group to a group of which he is a member. The super-user may change the group arbitrarily.
fchown() is particularly useful when used in conjunction with the file locking primitives (see flock.2
If owner or group is specified as -1, the corresponding ID of the file is not changed.
If a process whose effective user ID is not super-user successfully changes the group ID of a file, the set-user-ID and set-group-ID bits of the file mode, S_ISUID and S_ISGID respectively (see stat.2v will be cleared.
If the final component of path is a symbolic link, the ownership and group of the symbolic link is changed, not the ownership and group of the file or directory to which it points.
chown() will fail and the file will be unchanged if:
A pathname component is longer than {NAME_MAX} (see sysconf.2v while {_POSIX_NO_TRUNC} is in effect (see pathconf.2v
The group ID specified by group is not the current group ID of the file and is not in the process' supplementary group IDs, and the effective user ID is not the super-user.
fchown() will fail if:
The group ID specified by group is not the current group ID of the file and is not in the supplementary group IDs, and the effective user ID is not the super-user.
In addition to the above, the following may also occur:
For chown() to behave as described above, {_POSIX_CHOWN_RESTRICTED} must be in effect (see pathconf.2v {_POSIX_CHOWN_RESTRICTED} is always in effect on SunOS systems, but for portability, applications should call pathconf() to determine whether {_POSIX_CHOWN_RESTRICTED} is in effect for path.
If {_POSIX_CHOWN_RESTRICTED} is in effect for the file system on which the file referred to by path or fd resides, only the super-user may change the owner of the file. Otherwise, processes with effective user ID equal to the file owner or super-user may change the owner of the file.
Created by unroff & hp-tools. © somebody (See intro for details). All Rights Reserved. Last modified 11/5/97