setreuid(3B)
NAME
setreuid − set real and effective user IDs
SYNOPSIS
/usr/ucb/cc [ flag ... ] file ...
int setreuid( ruid, euid)
int ruid, euid;
DESCRIPTION
setreuid() emulates the BSD setreuid() system call. However, exact BSD semantics are not maintained. Also, this routine cannot implement all cases that are possible with the BSD system call, and returns an error in those cases.
If setreuid() is executed by root (the effective user ID is 0), and the application is either trying to change both the real user ID and effective user ID to the same value, or if the application is trying to change the real user ID to root, then setreuid() calls the setuid(2) system call with the ruid parameter, to change the real, effective, and saved user IDs to the new value.
setreuid() detects this case in the following manner:
If the special cases for root (described above) are not met, setreuid() maps an ruid and/or euid parameter equaling −1 to the current real user ID or current effective user ID, respectively.
If the ruid parameter equals the current effective user ID, and the euid parameter equals the current real user ID; or if the ruid parameter equals the current real user ID, then this case is detected.
setreuid() returns EPERM error in cases it cannot implement. These cases include: non-root user attempts to change the real user ID to the current effective user ID (that is, setreuid(y, −1) where y equals the current effective user ID).
It is recommended that applications use one of the base system calls in place of setreuid(). If the application is executed as root, and intends to change its real and effective user IDs to give up root privilege, the recommended interface is setuid(2).
RETURN VALUES
Upon successful completion, a value of 0 is returned. Otherwise, a value of −1 is returned and errno is set to indicate the error.
ERRORS
setreuid() will fail and neither of the user IDs will be changed if:
EPERM The calling process’s effective user ID is not the super-user and a change other than changing the real user ID to the effective user ID, or changing the effective user ID to the real user ID or the saved set-user ID, was specified.
EPERM setreuid() detected it cannot handle this case.
SEE ALSO
exec(2), getuid(2), setuid(2), setregid(3B)
NOTES
Use of these interfaces should be restricted to only applications written on BSD platforms. Use of these interfaces with any of the system libraries or in multi-thread applications is unsupported.
Sun Microsystems — Last change: 24 Mar 1993