setuid - further details
setuid() sets the real-user-ID (ruid),effective-user-ID (euid), and/or
saved-user-ID (suid) of the calling process. The super-user's euid is
zero. The following conditions govern setuid's behavior:
- If the euid is zero, setuid() sets the ruid, euid, and suid to
uid.
- If the euid is not zero, but the argument uid is equal to the
ruid or the suid, setuid() sets the euid to uid; the ruid and
suid remain unchanged. (If a set-user-ID program is not
running as super-user, it can change its euid to match its
ruid and reset itself to the previous euid value.)
- If euid is not zero, but the argument uid is equal to the
euid, and the calling process is a member of a group that has
the PRIV_SETRUGID privilege (see privgrp(4)), setuid() sets
the ruid to uid; the euid and suid remain unchanged.