I am exploring the suid area, and found myself unable to answer this question. For the sake of the question, lets assume the program binary is suid, owned by user 1001 and ran by user 1000 (both non-root) - therefor RUID=1000, EUID=1001.
When _POSIX_SAVED_IDS
is set, I can use setuid()
and seteuid()
in order to change the RUID and EUID (respectively) between 1000 and 1001.
However, when _POSIX_SAVED_IDS
is not set, seteuid(1000)
will render doing seteuid(1001)
impossible later, and setuid(1001)
will do the same to setuid(1000)
later on.
In order to change the EUID to the RUID and keep the possibility of going back later on, the solution I found here GNU Setuid Program Example is to use setreuid(1001,1000)
(swapping them). What are the effects of this on the program, since it changes the RUID? From what I understand, it changes the owner of the process, and therefor has implications on permissions of killing or interacting with the process.
What systems do not use _POSIX_SAVED_IDS?
Since POSIX requires
_POSIX_SAVED_IDS
to be defined with positive value, no systems should lack_POSIX_SAVED_IDS
.Source: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/unistd.h.html