The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

User::AccountChecker - Tools for user account checking in an Unix environment

VERSION

Version 0.02

SYNOPSIS

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");

SUBROUTINES/METHODS

new

User::AccountChecker->new()

Constructor

  • return new instance of User::AccountChecker

isuser

$object->isuser($name)

Checks if the current user is $name.

  • param string $name the name of the user account to check

  • return true if the current user is $name, false otherwise

isroot

$object->isroot()

Checks if the current user is root.

  • return true if the current user is root, false otherwise

musttoberoot

$object->musttoberoot()

Requires the current user to be logged as root. Dies if the current user is not root.

shellrootcmd

$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.

  • param string $command the command to wich add sudo

  • return $command with sudo prefix if the current user isn't root, else return $command

runasroot

$object->runasroot($commandargs)

Forces a script to be runned as root

  • param array $commandargs the command arguments (eg. @ARGV)

AUTHOR

Eric Villard, <evi at cpan.org>

BUGS

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.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc User::AccountChecker

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

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.