doing setreuid with setuid in modern sysv
Rayan Zachariassen
rayan at cs.toronto.edu
Mon Jan 15 05:05:01 AEST 1990
A year ago or more I asked about how to simulate setreuid() functionality
(i.e. as root set uid to non-root, then back to root) on a System V machine,
and was told by a reliable source that this cannot be done in any AT&T Unix
prior to System V.2.2.1. Well, it seems it cannot be done (with setuid()
anyway) in newer systems either. My understanding was that a 'saved uid'
(the uid of the process on instantiation) would always be kept around for
permissions checking for future setuid() calls. It seems (tested on
ISC 386/ix (SVR3.2) and IRIX3.2 (SVR3.1)) that setuid() behaves the same
way as on BSD systems and resets both real and effective uid (good) but
that there is no saved uid used for permissions checking later on.
Could someone set me straight on this please? How does one flip back and
forth between uid 0 and uid != 0 in a process started by uid 0 on a modern
System V ?
For example, if you compile and run the following program as root, it
should print
uid=0
uid=1
uid=0
according to the new setuid() semantics I was told of.
Thanks,
rayan
--
main()
{
printf("uid=%d\n", getuid());
if (setuid(1) < 0)
perror("setuid(1)");
printf("uid=%d\n", getuid());
if (setuid(0) < 0)
perror("setuid(0)");
printf("uid=%d\n", getuid());
exit(0);
}
More information about the Comp.unix.questions
mailing list