Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!cs.utexas.edu!uunet!auspex!guy From: guy@auspex.auspex.com (Guy Harris) Newsgroups: comp.unix.questions Subject: Re: doing setreuid with setuid in modern sysv Message-ID: <2818@auspex.auspex.com> Date: 15 Jan 90 19:49:59 GMT References: <90Jan14.130354est.2125@neat.cs.toronto.edu> Organization: Auspex Systems, Santa Clara Lines: 22 >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 ? By changing your kernel, or perhaps running S5R4.0 if it has "seteuid()". The problem with the saved set-user ID is that it works only if you're *NOT* running as "root". There are (at least) two separate "set UID" functions you want for UNIX programs: one that sets *only* the effective UID, and that lets you toggle it an indefinite number of times between the real and saved set-user ID, and one that sets *all* the UIDs. The former would be used by most set-UID programs, and the latter would be used by, say, "login" or "su". Unfortunately, both of those functions are called "setuid()" in System V; the way the S5 kernel distinguishes between them is that "setuid()" is the first function if the effective UID isn't 0, and the second function if it is. S5R4 may have picked up "seteuid()" from 4BSD; if so, with any luck it sets only the effective UID, even if the current effective UID is 0.