User::AccountChecker - Tools for user account checking in an Unix environment
Version 0.02
Provides an interface to check current user account. Useful for shell scripting.
A little code snippet :
use User::AccountChecker; my $uuac = User::AccountChecker->new(); # need to identify current user die("You are not allowed to continue.\n") unless($uuac->isuser('root')); # check if root user if ($uuac->isroot) { print("You are root.\n"); } else { print("You are not root.\n"); } # need root permissions for a shell command my $shellcommand = $uuac->shellrootcmd("cat /etc/shadow"); # if current user is root, $shellcommand == "cat /etc/shadow" # otherwise, $shellcommand == "sudo cat /etc/shadow", and # $ENV{'SUDO_ASKPASS'} if ssh-askpass is installed # force a script to be runned as root $uuac->runasroot(@ARGV); # $uuac->isroot() should be true # need root permissions to continue $uuac->musttoberoot(); print("if you see this message then you get root permissions.\n");
User::AccountChecker->new()
Constructor
return new instance of User::AccountChecker
$object->isuser($name)
Checks if the current user is $name.
$name
param string $name the name of the user account to check
return true if the current user is $name, false otherwise
$object->isroot()
Checks if the current user is root.
return true if the current user is root, false otherwise
$object->musttoberoot()
Requires the current user to be logged as root. Dies if the current user is not root.
$object->shellrootcmd($command)
Checks for ssh-askpass linux command and initialize $ENV{'SUDO_ASKPASS'} if it is founded. Adds sudo at the beginning of a command, or at the beginning of each piped commands.
$ENV{'SUDO_ASKPASS'}
param string $command the command to wich add sudo
$command
return $command with sudo prefix if the current user isn't root, else return $command
$object->runasroot($commandargs)
Forces a script to be runned as root
param array $commandargs the command arguments (eg. @ARGV)
$commandargs
Eric Villard, <evi at cpan.org>
<evi at cpan.org>
Please report any bugs or feature requests to bug-User at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=User. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-User at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc User::AccountChecker
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=User
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/User
CPAN Ratings
http://cpanratings.perl.org/d/User
Search CPAN
http://search.cpan.org/dist/User/
Copyright 2010 Eric Villard.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install User::AccountChecker, copy and paste the appropriate command in to your terminal.
cpanm
cpanm User::AccountChecker
CPAN shell
perl -MCPAN -e shell install User::AccountChecker
For more information on module installation, please visit the detailed CPAN module installation guide.