Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

258 Process Control Chapter 8

seteuidandsetegidFunctions

POSIX.1 includes the two functionsseteuid and setegid.These functions are
similar tosetuidandsetgid,but only the effective user ID or effective group ID is
changed.

#include <unistd.h>
int seteuid(uid_tuid);
int setegid(gid_tgid);
Both return: 0 if OK,−1 on error

An unprivileged user can set its effective user ID to either its real user ID or its saved
set-user-ID. Foraprivileged user,only the effective user ID is set touid.(This behavior
differs from that of thesetuidfunction, which changes all three user IDs.)
Figure8.19 summarizes all the functions that we’ve described herethat modify the
three user IDs.

real
user ID

effective
user ID

saved
set-user-ID

superuser
setreuid(ruid,euid)

superuser
setuid(uid)

superuser
seteuid(uid)
euid
euid uid uid uid
ruid

uid

unprivileged
setreuid

unprivileged
setreuid

unprivileged
setuidorseteuid

unprivileged
setuidorseteuid

execof
set-user-ID

Figure 8.19Summary of all the functions that set the various user IDs

Group IDs


Everything that we’ve said so far in this section also applies in a similar fashion to
group IDs. The supplementary group IDs arenot affected bysetgid,setregid,or
setegid.
Free download pdf