[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 2

setuid, setruid, seteuid, setreuid or setuidx Subroutine

Purpose

Sets the process user IDs.

Library

Standard C Library (libc.a)

Syntax

#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;

Description

The setuid, setruid, seteuid, and setreuid subroutines reset the process user IDs. The following semantics are supported:

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:
RUID != EUID
If the EUID parameter specifies either the process's real or saved user IDs, the process effective user ID is set to the EUID parameter. Otherwise, the EPERM error code is returned.
RUID== EUID
If the process effective user ID is the root user, the process's real and effective user IDs are set to the EUID parameter. Otherwise, the EPERM error code is returned.
setuidx The which parameter can have one of the following values:
ID_EFFECTIVE
UID must be either the real or saved UID. The effective user ID for the current process will be set to UID.
ID_EFFECTIVE|ID_REAL
Invoker must have appropriate privilege. The real and effective user ID for the current process will be set to UID.
ID_EFFECTIVE|ID_REAL|ID_SAVED
Invoker must have appropriate privilege. The real, effective and saved user ID for the current process will be set to UID.
ID_LOGIN
Invoker must have appropriate privilege. The login UID for the current process will be set to UID.

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.

Parameters

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.

Return Values

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.

Error Codes

The setuid, seteuid, setreuid, and setuidx subroutines are unsuccessful if either of the following is true:

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.

Related Information

The getuid or geteuid subroutine, setgid (setgid, setrgid, setegid, setregid, or setgidx Subroutine) subroutine.

List of Security and Auditing Subroutines and Subroutines Overview in AIX 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]