Sets the process user IDs.
Standard C Library (libc.a)
#include <unistd.h>
int setuid (UID)
uid_t UID;
int setruid (RUID)
uid_t RUID;
int seteuid (EUID)
uid_t EUID;
int setreuid (RUID, EUID)
uid_t RUID;
uid_t EUID;
#include <unistd.h>
#include <sys/id.h>
int setuidx (which, UID)
int which;
uid_t UID;
The setuid, setruid, seteuid, and setreuid subroutines reset the process user IDs. The following semantics are supported:
Item | Description |
---|---|
setuid | If the effective user ID of the process is the root user, the process's real, effective, and saved user IDs are set to the value of the UID parameter. Otherwise, the process effective user ID is reset if the UID parameter specifies either the current real or saved user IDs. |
seteuid | The process effective user ID is reset if the UID parameter is equal to either the current real or saved user IDs or if the effective user ID of the process is the root user. |
setruid | The EPERM error code is always returned. Processes cannot reset only their real user IDs. |
setreuid | The RUID and EUID parameters can have the following
two possibilities:
|
setuidx | The setuidx subroutine does not modify the privileges
of the process after the user ID of the process has been modified.
To modify the privileges and the user ID of a process, use the setpriv subroutine
and the setuidx subroutine together. The which parameter
can have one of the following values:
|
The real and effective user ID parameters can have a value of -1. If the value is -1, the actual value for the UID parameter is set to the corresponding current the UID parameter of the process.
The operating system does not support setuid or setgid (setgid, setrgid, setegid, setregid, or setgidx Subroutine) shell scripts.
These subroutines are part of Base Operating System (BOS) Runtime.
Item | Description |
---|---|
UID | Specifies the user ID to set. |
EUID | Specifies the effective user ID to set. |
RUID | Specifies the real user ID to set. |
which | Specifies which user ID values to set. |
Upon successful completion, the setuid, seteuid, setreuid, and setuidx subroutines return a value of 0. Otherwise, a value of -1 is returned and the errno global variable is set to indicate the error.
The setuid, seteuid, setreuid, and setuidx subroutines are unsuccessful if either of the following is true:
Item | Description |
---|---|
EINVAL | The value of the UID or EUID parameter is not valid. |
EPERM | The process does not have the appropriate privileges and the UID and EUID parameters are not equal to either the real or saved user IDs of the process. |
#include <sys/id.h>
#include <sys/priv.h>
int main(void) {
int uid=206;
priv_t priv;
bzero(priv.pv_priv, sizeof(priv.pv_priv));
if (setuidx(ID_EFFECTIVE|ID_REAL|ID_SAVED|ID_LOGIN,uid) < 0) {
perror("setuidx error");
exit(errno);
}
if(setpriv(PRIV_SET|PRIV_INHERITED|PRIV_EFFECTIVE|PRIV_BEQUEATH,&priv,sizeof(priv_t))<0) {
perror("setpriv error");
exit(errno);
}
exit (0);
}