in reply to An odd failure of setuid(0)

The answer is simple: Once you have dropped your privileges with setuid($u), you run as a normal user, and no normal user may setuid(0).

You may change to root if your effective or saved uid is zero. However, setuid($u) sets both of them to $u. I believe you could use the seteuid system call instead of setuid to set only the effective uid. Unfortunately I cannot find a seteuid function in the POSIX module..

Compare to the setuid(2) man page and the like.

Replies are listed 'Best First'.
Re^2: An odd failure of setuid(0)
by Llew_Llaw_Gyffes (Scribe) on Jun 26, 2006 at 01:03 UTC

    I believe you've nailed it.  I was overthinking the problem (see previous comment), then failing to consider that my first setuid($u) was negating my setuid/sgid bits that were allowing me to setuid(0) in the first place.