setuid(3)
NAME
setuid, seteuid, setruid, setgid, setegid, setrgid − set user and group ID
SYNTAX
setuid(uid)
seteuid(euid)
setruid(ruid)
setgid(gid)
setegid(egid)
setrgid(rgid)
DESCRIPTION
The setuid subroutine sets both the real and effective user ID of the current process to the ID specified. Likewise, the setgid subroutine sets the real and effective group ID of the current process to the ID specified.
The seteuid subroutine sets the effective user ID of the current process, while the setegid subroutine sets the effective group ID of the current process.
The setruid subroutine sets the real user ID of the current process, while the setrgid subroutine sets the real group ID of the current process.
These calls are only permitted to the super-user or if the argument is the real or effective ID.
ENVIRONMENT
SYSTEM_FIVE
Differs from the System V definition in that it returns EPERM instead of EINVAL if the argument is out of range.
POSIX
SYSTEM_FIVE
When your program is compiled in POSIX or System V mode the following semantics apply when using the setuid or setgid functions:
If the process is the super-user the real, effective, and saved set (as described in execve())) user/group ID are set to uid.
If the process is not the super-user, but uid is equal to the real or the saved set user/group ID, the effective user/group ID is set to uid. The real and saved set user/group ID remain unchanged.
POSIX
In POSIX mode, the setuid function returns a value of type uid_t. The setgid function returns a value of type gid_t.
DIAGNOSTICS
Zero is returned if the user ID or group ID is set; −1 is returned otherwise.
SEE ALSO
setreuid(2), setregid(2), getuid(2), getgid(2)
Subroutines