setuid (euid) after setuid (uid) on System 5

Leslie Mikesell les at chinet.chi.il.us
Sat Mar 18 15:35:24 AEST 1989


In article <123 at cat.Fulcrum.BT.CO.UK> igb at 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



More information about the Comp.bugs.sys5 mailing list