in reply to An odd failure of setuid(0)
#!/usr/bin/perl print "effective: $>, real: $<\n"; $> = 111; open(O,">foo") or die "Can't write foo: $!\n"; close O or die "Can't close O: $!\n"; $> = 0; open(O,">bar") or die "Can't write bar: $!\n"; close O or die "Can't close O: $!\n"; $> = 111 ; # this must fail. open(O,">bar") or warn "Can't write bar: $!\n"; # change real uid $< = 111; # oops, forgot to set $> to 0 print "effective: $>, real: $<\n"; $< = 0; # no effect print "effective: $>, real: $<\n";
This outputs:
effective: 0, real: 0 Can't write bar: Permission denied effective: 111, real: 111 effective: 111, real: 111
As you see, the second change of the real uid had no effect. Let's see what's in here:
quux [gm] /tmp/foo # ls -l total 4 -rw-r--r-- 1 root root 0 2006-06-26 02:31 bar -rw-r--r-- 1 111 root 0 2006-06-26 02:31 foo -rw-r--r-- 1 root root 338 2006-06-26 02:29 setuid.pl
Where do you get the function setuid from? can't find that in my perlfunc...
update: ah, POSIX.
setuid Sets the real user identifier and the effective user identi +- fier for this process. Similar to assigning a value to the Perl's builtin $< variable, see "$UID" in perlvar, except that the latter will change only the real user identifier.
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: An odd failure of setuid(0)
by Llew_Llaw_Gyffes (Scribe) on Jun 26, 2006 at 00:59 UTC | |
by shmem (Chancellor) on Jun 26, 2006 at 01:02 UTC |