#!/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";
####
effective: 0, real: 0
Can't write bar: Permission denied
effective: 111, real: 111
effective: 111, real: 111
####
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
####
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.