On 10/26/02 1:14 PM, Jeff Lowrey wrote:
At 1:09 PM -0400 10/26/02, Mark Knipfer wrote:

On 10/26/02 11:55 AM, Mark Knipfer wrote:

How do you check for root level access in Perl 5.6.0 in Mac OS X?

After browsing and reading through part of the O'Rielly - Programming Perl 2nd Edition book, I came up with this routine:

$login = (getpwuid($>));
if (!$login == "root")
{
die "\nYou cannot run this Perl script as user \"$login\", must be ROOT!\n\n";
}

Of course that only works if the 'root' user is named 'root', and not 'administrator' or etc. And it doesn't allow someone to run your script from sudo.

But you may find more assistance in perldoc -f getpwuid

-Jeff Lowrey
Correct. I wanted to use the UID, but I used the names instead. I am learning Perl after fooling with it with the past six years. I never really tried to learn until recently. When I used the above part in my Perl script, I thought about what-if someone used 'sudo' to run this script. That is something that I need to learn how to handle.

Thanks.

Reply via email to