Xref: utzoo comp.unix.wizards:15100 comp.bugs.sys5:810 Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!mailrus!ukma!rutgers!att!chinet!les From: les@chinet.chi.il.us (Leslie Mikesell) Newsgroups: comp.unix.wizards,comp.bugs.sys5 Subject: Re: setuid (euid) after setuid (uid) on System 5 Message-ID: <7962@chinet.chi.il.us> Date: 18 Mar 89 05:35:24 GMT References: <123@cat.Fulcrum.BT.CO.UK> Reply-To: les@chinet.chi.il.us (Leslie Mikesell) Followup-To: comp.unix.wizards Organization: Chinet - Public Access Unix Lines: 30 In article <123@cat.Fulcrum.BT.CO.UK> igb@Fulcrum.BT.CO.UK (Ian G Batten) writes: >Should the following program work or not, on System Five? This is a >common idiom in the source code of HoneyDanber uucp, and two local System >Five machines refuse to honour the second setuid. The manual page implies >they should. Please, no flames --- just mail me an answer. I've been >sweating blood over the code all day and I hope I can lodge this as a >kernel problem. >main () >{ > int uid, euid; > > printf ("uid = %d; euid = %d\n", uid = getuid (), euid = geteuid ()); > if (setuid (uid) != 0) > perror ("setuid (uid)"); > printf ("uid = %d; euid = %d\n", getuid (), geteuid ()); > if (setuid (euid) != 0) > perror ("setuid (euid)"); > printf ("uid = %d; euid = %d\n", getuid (), geteuid ()); >} If your current effective uid is 0 and you execute setuid(anything_but_0) then there is no way back. Other combinations of different uid and euid can flip back and forth as desired. You have to fork off a child process if you are root and want to do something as another id and go back to being root (or just assume that root's permissions are sufficient anyway and chown() any files that you create..) Les Mikesell