SPUG: Understanding RUID EUID and modules (fwd)
John Costello
cos at indeterminate.net
Wed May 16 12:16:28 PDT 2007
Sending this again, as the original didn't come through and I wouldn't be
surprised if $< and $> in the Subject caused problems.
---------- Forwarded message ----------
Date: Wed, 16 May 2007 11:51:09 -0700 (PDT)
From: John Costello <cos at indeterminate.net>
To: spug-list at pm.org
Subject: Understanding $<, $> and modules
I'm puzzling over how Perl handles changes to $< and $> when run as root.
What I'm trying to do: Drop privileges to a non-root user, do some
things, return to root privileges. There may be better ways to do all
this, but I'm more interested in why Perl behaves the way it does.
If I run this from a perl script
print "RUID $< and EUID $>\n";
$< = $> = 8000;
print "RUID now $< and EUID now $>\n";
$< = $> = 0;
print "RUID set to $< and EUID set to $>\n";
I get
RUID 0 and EUID 0
RUID now 8000 and EUID now 8000
RUID set to 8000 and EUID set to 8000
which is what I expect.
If I dump
$< = $> = 8000;
into a module that I call from the main script, so that I now have this
script
print "RUID $< and EUID $>\n";
$results = local::SetPerms->changed_ruid_euid();
print "RUID now $< and EUID now $>\n";
$< = $> = 0;
print "RUID set to $< and EUID set to $>\n";
I get
RUID 0 and EUID 0
RUID now 8000 and EUID now 8000
RUID set to 0 and EUID set to 0
which I didn't expect, because I don't know what is going on under the
hood.
So, do modules have their own $< and $>, copied from the main script? Are
modules run as separate processes? Where would be a good spot to start
reading (Programming Perl?)?
John
More information about the spug-list
mailing list