setuid VS seteuid
seteuid:
when the calling process is not root :
Set the euid to real id or saved id, but not root(it doesn't have root capability)
when the calling process is root:
Change the euid, can be changed to root.(it has root capability)
No mater the calling process is root or not, it can only change the euid.
setuid:
when the calling process is not root :
Change the euid to real id or saved uid, but not root.(it doesn't have root capability). For example: it can change user1 to user2. only change the euid.
When the calling process is root:
Change the real id and euid as arbitrary id.
Differences of setuid and seteuid: setuid will change all ids such as real id and euid, and saved user-id when the calling process is root. Once the real id is changed, when OS checks the real id and euid, they are found to be the same, so OS will not change to euid back to the real id, in other words, the euid was permanently changed.
Seteuid can only change euid to any id when the calling process is root. Since the real id has not changed, OS will find the inconsistency when checking the real id and the euid and change euid back after jumping out of process.
Similarity of setuid and seteuid: euid can only be changed when the caling process is not root.
Ps : saved set-user-ID is the real id change before.
The saved user ID (suid) is used when a program running with elevated privileges needs to temporarily do some unprivileged work.