setuid, setgid
Purpose
Sets a process's user and group IDs.
Syntax
int setuid (uid) int setgid (gid)
int uid; int gid;
Description
The setuid system call sets the real and effective user
IDs of the calling process. If the effective user ID of
the calling process is superuser, then the real and
effective user IDs are set to the value of the uid param-
eter. If the effective user ID of the calling process is
not superuser, but the real user ID is equal to the value
of the uid parameter, or the process's original effective
user ID as set by the exec system call is equal to uid,
then the effective user ID is set to the value of the uid
parameter.
The setgid system call sets the real and effective group
IDs of the calling process. If the effective user ID of
the calling process is superuser, then the real and
effective group IDs are set to the value of the gid
parameter. If the effective user ID of the calling
process is not superuser, but the real group ID is equal
to the value of the gid parameter, or the process's ori-
ginal effective group ID as set by the exec system call
is equal to gid, then the effective group ID is set to
the value of the gid parameter.
Return Value
Upon successful completion, a value of 0 is returned. If
the setuid or setgid system call fails, then a value of
-1 is returned and errno is set to indicate the error.
Diagnostics
The setuid and setgid system calls fail if the following
is true:
EPERM The uid (gid) parameter is not equal to the
real user (group) ID of the process or to the
original effective user (group) ID as set by
the exec system call, and the effective user
ID is not superuser.
EINVAL The uid parameter is not a valid user ID.
Related Information
In this book: "exec: execl, execv, execle, execve,
execlp, execvp," "getpid, getpgrp, getppid," and "getuid,
geteuid, getgid, getegid."