use strict;
use CDB_File;
use vars qw(%RAD_REQUEST %RAD_REPLY %RAD_CHECK);
# for standaline testing
#my %RAD_REQUEST;
#my %RAD_REPLY;
#my %RAD_CHECK;
# This the remapping of return values
use constant RLM_MODULE_REJECT=> 0;# /* immediately reject the request */
use constant RLM_MODULE_FAIL=> 1;# /* module failed, don't reply */
use constant RLM_MODULE_OK=> 2;# /* the module is OK, continue */
use constant RLM_MODULE_HANDLED=> 3;# /* the module handled the request, so stop. */
use constant RLM_MODULE_INVALID=> 4;# /* the module considers the request invalid. */
use constant RLM_MODULE_USERLOCK=> 5;# /* reject the request (user is locked out) */
use constant RLM_MODULE_NOTFOUND=> 6;# /* user not found */
use constant RLM_MODULE_NOOP=> 7;# /* module succeeded without doing anything */
use constant RLM_MODULE_UPDATED=> 8;# /* OK (pairs modified) */
use constant RLM_MODULE_NUMCODES=> 9;# /* How many return codes there are */
sub authorize {
return RLM_MODULE_OK
}
sub authenticate {
my %isplookup;
my $isp;
my $tie;
my $username;
my %ispconfig;
my @ispconfarray;
&log_request_attributes;
##$RAD_REQUEST{'User-Name'} = "nasport:192.168.1.41:2/0/0/400";
if ($RAD_REQUEST{'User-Name'}=~ /^nasport:/) {
$tie = tie %isplookup, 'CDB_File', 'ispuser.cdb' or return RLM_MODULE_FAIL;
$username = $RAD_REQUEST{'User-Name'};
$username =~ s/^nasport://;
##print "Username:$username\n";
$isp = $isplookup{$username};
##print "ISP:$isp\n";
if($isp) {
# Lookup ISP config and return reply AVPs
$tie = tie %ispconfig, 'CDB_File', 'ispconfig.cdb' or return RLM_MODULE_FAIL;
@ispconfarray = split(/\t/,$ispconfig{$isp}); # fields are tab delimited
my $lns_ipaddr = $ispconfarray[0];
my $lns_passwd = $ispconfarray[1];
my $vrf = $ispconfarray[2];
##print "IPADDR:$lns_ipaddr, PASSWD:$lns_passwd, VRF:$vrf\n";
$RAD_REPLY{'Cisco-AVpair'} = "vpdn:tunnel-type=l2tp\n";
$RAD_REPLY{'Cisco-AVpair'} .= "vpdn:vpn-vrf=$vrf\n";
$RAD_REPLY{'Cisco-AVpair'} .= "vpdn:ip-addresses=$lns_ipaddr";
$RAD_REPLY{'Cisco-AVpair'} .= "vpdn:l2tp-tunnel-password=$lns_passwd";
return RLM_MODULE_OK;
} else {
# No ISP found
return RLM_MODULE_INVALID;
}
undef $tie;
untie %isplookup;
} else {
return RLM_MODULE_INVALID;
}
undef $tie;
untie %isplookup;
}
sub log_request_attributes {
# This shouldn't be done in production environments!
# This is only meant for debugging!
for (keys %RAD_REQUEST) {
&radiusd::radlog(1, "RAD_REQUEST: $_ = $RAD_REQUEST{$_}");
}
}
# standalone
#authenticate();