Apache2-AuthenSecurID

 view release on metacpan or  search on metacpan

ace_initd  view on Meta::CPAN

#!/opt/ActivePerl-5.8/bin/perl

# $Id: ace_initd,v 1.5 2007/12/08 03:27:01 atobey Exp $

use Authen::ACE;
use IO::Socket::INET;
use Sys::Syslog;
use Crypt::CBC;
use Getopt::Long;

our( $port, $facility, $secret, $listen, $var_ace, $daemon, $pidfile );

GetOptions(
    "port=i"     => \$port,     "p=i" => \$port,
    "facility=s" => \$facility, "f=s" => \$facility,
    "secret=s"   => \$secret,   "s=s" => \$secret,
    "listen=s"   => \$listen,   "l=s" => \$listen,
    "var_ace=s"  => \$var_ace,  "a=s" => \$var_ace,
    "daemon"     => \$daemon,   "d"   => \$daemon,
    "pidfile=s"  => \$pidfile,  "p=s" => \$pidfile
);

# make the secret not visible in 'ps' output
if ( $secret ) {
    my $newname = $0;
    $newname =~ s/$secret/###########/g;
    $0 = $newname;
}

# background the program if --daemon/-d is specified
if ( $daemon ) {
    my $pid = fork();
    if ( $pid ) {
        exit 0;
    }
    else {
        eval {
            require POSIX;
            POSIX::setsid();
        };
    }
}

$var_ace        ||= $ENV{VAR_ACE};
$ENV{'VAR_ACE'} ||= $var_ace;
$facility       ||= 'local2';
$port           ||= 1969;
$secret         ||= 'secret';
$listen         ||= '127.0.0.1';
write_pidfile( $pidfile );

my $crypt = new Crypt::CBC ( $secret, "Blowfish" );

# maybe make UNIX socket an option?
my $server = IO::Socket::INET->new(
    LocalPort    =>    $port,
    Proto        =>    'udp',
    LocalAddr    =>    $listen
) or die "Couldn't be a tcp server on port $port: $!\n";

openlog ( 'ace_initd', 'nowait', $facility );

my %ACE;
my $mesg;
my $result;
my $request;
my $info;
my $rand;

while ( $server->recv($mesg, 1024) ) {
   $mesg = $crypt->decrypt_hex ( $mesg );
   my ( $rand, $request, $type, $username, $passcode ) = split /\:/, $mesg;
      eval {
       if ( ! $ACE{$request} ) {
       $ACE{$request} = new Authen::ACE;
       }
       if ( $type eq "check" ) {
       ($result,$info) = $ACE{$request}->Check($passcode,$username);
       }
       if ( $type eq "next" ) {
       ($result,$info) = $ACE{$request}->Next($passcode);
        }
       if ( $type eq "pin" ) {
       ($result,$info) = $ACE{$request}->PIN($passcode);
       }
       if ( $result != 5 && $result != 2 ) {
       delete $ACE{$request};
    } 
      };
   if ( $@ ) {



( run in 1.542 second using v1.01-cache-2.11-cpan-f56aa216473 )