CHOWN(2)

NAME
chown, fchown - change owner and group of a file

SYNOPSIS
int chown(name, owner, group)
char *name;

int fchown(fd, owner, group)

DESCRIPTION
Chown changes the owner and group of the file specified by the null-terminated string name. Fchown changes the owner and group of an open file specified by file descriptor. Only the super-user may change the userid of a file. The owner of a file may change its groupid to match the current effective groupid; any other changes are restricted to the super-user. If the file has either set-userid or set-groupid permission (see stat(2)) neither the userid or groupid may be changed.

EXAMPLES
The following sequence, executed by a superuser process with T_NOCHK and T_SETPRIV capabilities, will change the owner of any file, regardless of privileges and set-id modes (less Herculean methods usually suffice). The sequence is illustrative only: it ignores the possiblility of the file being altered by a hostile superuser while the file is unprivileged. Sound security procedures might require the various steps to be done by different persons, with interspersed vetting similar to that described in setpriv(8).

        getflab(file, &savlab);
        setflab(file, &nopriv);
        stat(file, &savmod);
        chmod(file, 0);
        chown(file, uid, gid);
        chmod(file, savmod.s_mode);
        setflab(file, &savlab);

SEE ALSO
chown(8), chmod(2), passwd(5)

DIAGNOSTICS
EACCES, EBADF, EFAULT, EIO, ELAB, ELOOP, ENOENT, ENOTDIR, EPERM