ptg10805159258 Process Control Chapter 8seteuidandsetegidFunctionsPOSIX.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 errorAn 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 IDeffective
user IDsaved
set-user-IDsuperuser
setreuid(ruid,euid)superuser
setuid(uid)superuser
seteuid(uid)
euid
euid uid uid uid
ruiduidunprivileged
setreuidunprivileged
setreuidunprivileged
setuidorseteuidunprivileged
setuidorseteuidexecof
set-user-IDFigure 8.19Summary of all the functions that set the various user IDsGroup 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.