aglassman
aglassman

Reputation: 2653

What does < do in Perl in this instance?

I am confused as to what the second line does in this snippet of code. $runas should be evaluated to the user's uid i think. What does the $< do? This is contained in a CGI script.

my $runAS = (getpwnam("username"))[2];
$runAS = $< if ($runAS == 0);

Upvotes: 4

Views: 147

Answers (3)

thb
thb

Reputation: 14454

From the perlvar man page:

$< The real uid of this process.

So, the $< returns the user's real, numerical ID. This is not the user's username, but a sysadmin-assigned number. For example, if your username were a aglassman and mine, thb, on the same system, then your UID might be 1005 and mine, 1006, depending on which of our accounts the sysadmin had created first. On a Linux platform, see the file /etc/passwd for your system's UIDs.

Upvotes: 1

pulven
pulven

Reputation: 156

from http://perldoc.perl.org/perlvar.html

$<

The real uid of this process. You can change both the real uid and the effective uid at the same time by using POSIX::setuid() . Since changes to $< require a system call, check $! after a change attempt to detect any possible errors.

Mnemonic: it's the uid you came from, if you're running setuid.

Upvotes: 6

vstm
vstm

Reputation: 12537

$< is a special variable in perl:

The real uid of this process. You can change both the real uid and the effective uid at the same time by using POSIX::setuid() . Since changes to $< require a system call, check $! after a change attempt to detect any possible errors.

Upvotes: 12

Related Questions