Skip to content
Snippets Groups Projects
Commit 2aade931 authored by Nigel Kukard's avatar Nigel Kukard
Browse files

* Preliminary work fixing up the modules

parent ad47f39b
No related branches found
No related tags found
No related merge requests found
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
package mod_auth_chap; package smradius::modules::authentication::mod_auth_chap;
use strict; use strict;
use warnings; use warnings;
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
package mod_auth_mschap; package smradius::modules::authentication::mod_auth_mschap;
use strict; use strict;
use warnings; use warnings;
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
# with this program; if not, write to the Free Software Foundation, Inc., # with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
package mod_auth_pap; package smradius::modules::authentication::mod_auth_pap;
use strict; use strict;
use warnings; use warnings;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
# with this program; if not, write to the Free Software Foundation, Inc., # with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
package mod_feature_capping; package smradius::modules::features::mod_feature_capping;
use strict; use strict;
use warnings; use warnings;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
# with this program; if not, write to the Free Software Foundation, Inc., # with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
package mod_feature_validity; package smradius::modules::features::mod_feature_validity;
use strict; use strict;
use warnings; use warnings;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
# with this program; if not, write to the Free Software Foundation, Inc., # with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
package mod_config_sql; package smradius::modules::system::mod_config_sql;
use strict; use strict;
use warnings; use warnings;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
# with this program; if not, write to the Free Software Foundation, Inc., # with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
package mod_config_sql_topups; package smradius::modules::system::mod_config_sql_topups;
use strict; use strict;
use warnings; use warnings;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
# with this program; if not, write to the Free Software Foundation, Inc., # with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
package mod_config_test; package smradius::smradius::modules::mod_config_test;
use strict; use strict;
use warnings; use warnings;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
# with this program; if not, write to the Free Software Foundation, Inc., # with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
package mod_userdb_sql; package smradius::modules::userdb::mod_userdb_sql;
use strict; use strict;
use warnings; use warnings;
......
...@@ -23,11 +23,7 @@ use warnings; ...@@ -23,11 +23,7 @@ use warnings;
# Set library directory # Set library directory
use lib qw( use lib qw(
../ ./ ../ ./
smradius/modules/authentication smradius
smradius/modules/userdb
smradius/modules/accounting
smradius/modules/features
smradius/modules/config
awitpt/db awitpt/db
); );
...@@ -121,7 +117,7 @@ sub configure { ...@@ -121,7 +117,7 @@ sub configure {
) or die "Failed to open config file '".$cfg->{'config_file'}."': $!"; ) or die "Failed to open config file '".$cfg->{'config_file'}."': $!";
# Copy config # Copy config
my %config = %inifile; my %config = %inifile;
untie(%inifile); #untie(%inifile);
# Pull in params for the server # Pull in params for the server
my @server_params = ( my @server_params = (
...@@ -176,86 +172,120 @@ sub configure { ...@@ -176,86 +172,120 @@ sub configure {
} }
# #
# System plugins # System modules
# #
my @system_params = ( if (ref($config{'system'}{'modules'}) eq "ARRAY") {
'plugins', foreach my $module (@{$config{'system'}{'modules'}}) {
); $module =~ s/\s+//g;
my $system; # Skip comments
foreach my $param (@system_params) { next if ($module =~ /^#/);
$system->{$param} = $config{'system'}{$param} if (defined($config{'system'}{$param})); $module = "system/$module";
} push(@{$cfg->{'module_list'}},$module);
}
if (!defined($system->{'plugins'})) { } else {
$self->log(LOG_ERR,"[SMRADIUS] System configuration error: System plugins not found"); my @moduleList = split(/\s+/,$config{'system'}{'modules'});
exit 1; foreach my $module (@moduleList) {
# Skip comments
next if ($module =~ /^#/);
$module = "system/$module";
push(@{$cfg->{'module_list'}},$module);
}
} }
# #
# Authentication plugins # Feature modules
# #
my @auth_params = ( if (ref($config{'features'}{'modules'}) eq "ARRAY") {
'mechanisms', foreach my $module (@{$config{'features'}{'modules'}}) {
'users', $module =~ s/\s+//g;
); # Skip comments
my $auth; next if ($module =~ /^#/);
foreach my $param (@auth_params) { $module = "features/$module";
$auth->{$param} = $config{'authentication'}{$param} if (defined($config{'authentication'}{$param})); push(@{$cfg->{'module_list'}},$module);
} }
} else {
if (!defined($auth->{'users'})) { my @moduleList = split(/\s+/,$config{'features'}{'modules'});
$self->log(LOG_ERR,"[SMRADIUS] Authentication configuration error: Userdb plugins not found"); foreach my $module (@moduleList) {
exit 1; # Skip comments
next if ($module =~ /^#/);
$module = "features/$module";
push(@{$cfg->{'module_list'}},$module);
}
} }
# #
# Accounting plugins # Authentication modules
# #
my @acct_params = ( if (ref($config{'authentication'}{'mechanisms'}) eq "ARRAY") {
'plugins', foreach my $module (@{$config{'authentication'}{'mechanisms'}}) {
); $module =~ s/\s+//g;
my $acct; # Skip comments
foreach my $param (@acct_params) { next if ($module =~ /^#/);
$acct->{$param} = $config{'accounting'}{$param} if (defined($config{'accounting'}{$param})); $module = "authentication/$module";
push(@{$cfg->{'module_list'}},$module);
}
} else {
my @moduleList = split(/\s+/,$config{'authentication'}{'mechanisms'});
foreach my $module (@moduleList) {
# Skip comments
next if ($module =~ /^#/);
$module = "authentication/$module";
push(@{$cfg->{'module_list'}},$module);
}
} }
if (!defined($acct->{'plugins'})) { if (ref($config{'authentication'}{'users'}) eq "ARRAY") {
$self->log(LOG_ERR,"[SMRADIUS] Accounting configuration error: Plugins not found"); foreach my $module (@{$config{'authentication'}{'users'}}) {
exit 1; $module =~ s/\s+//g;
# Skip comments
next if ($module =~ /^#/);
$module = "userdb/$module";
push(@{$cfg->{'module_list'}},$module);
}
} else {
my @moduleList = split(/\s+/,$config{'authentication'}{'users'});
foreach my $module (@moduleList) {
# Skip comments
next if ($module =~ /^#/);
$module = "userdb/$module";
push(@{$cfg->{'module_list'}},$module);
}
} }
# #
# Feature plugins # Accounting modules
# #
my $features; if (ref($config{'accounting'}{'module_list'}) eq "ARRAY") {
$features->{'plugins'} = [ ]; foreach my $module (@{$config{'accounting'}{'module_list'}}) {
$features->{'plugins'} = $config{'features'}{'plugins'} if (defined($config{'features'}{'plugins'})); $module =~ s/\s+//g;
# Skip comments
next if ($module =~ /^#/);
$module = "accounting/$module";
push(@{$cfg->{'module_list'}},$module);
}
} else {
my @moduleList = split(/\s+/,$config{'accounting'}{'module_list'});
foreach my $module (@moduleList) {
# Skip comments
next if ($module =~ /^#/);
$module = "accounting/$module";
push(@{$cfg->{'module_list'}},$module);
}
}
# #
# Dictionary configuration # Dictionary configuration
# #
my @dictionary_params = (
'load',
);
my $dictionary;
foreach my $param (@dictionary_params) {
$dictionary->{$param} = $config{'dictionary'}{$param} if (defined($config{'dictionary'}{$param}));
}
if (!defined($dictionary->{'load'})) {
$self->log(LOG_ERR,"[SMRADIUS] Dictionary configuration error: 'load' not found");
exit 1;
}
# Split off dictionaries to load # Split off dictionaries to load
if (ref($dictionary->{'load'}) eq "ARRAY") { if (ref($config{'dictionary'}->{'load'}) eq "ARRAY") {
foreach my $dict (@{$dictionary->{'load'}}) { foreach my $dict (@{$config{'dictionary'}->{'load'}}) {
$dict =~ s/\s+//g; $dict =~ s/\s+//g;
# Skip comments # Skip comments
next if ($dict =~ /^#/); next if ($dict =~ /^#/);
push(@{$cfg->{'dictionary_list'}},$dict); push(@{$cfg->{'dictionary_list'}},$dict);
} }
} else { } else {
my @dictList = split(/\s+/,$dictionary->{'load'}); my @dictList = split(/\s+/,$config{'dictionary'}->{'load'});
foreach my $dict (@dictList) { foreach my $dict (@dictList) {
# Skip comments # Skip comments
next if ($dict =~ /^#/); next if ($dict =~ /^#/);
...@@ -263,21 +293,6 @@ sub configure { ...@@ -263,21 +293,6 @@ sub configure {
} }
} }
$cfg->{'authentication'} = $auth;
$cfg->{'plugins'} = [
@{$auth->{'mechanisms'}},
@{$auth->{'users'}},
@{$acct->{'plugins'}},
@{$features->{'plugins'}},
@{$system->{'plugins'}}
];
# Clean up plugins
foreach my $plugin (@{$cfg->{'plugins'}}) {
$plugin =~ s/\s+//g;
}
# Save our config and stuff # Save our config and stuff
$self->{'config'} = $cfg; $self->{'config'} = $cfg;
$self->{'cmdline'} = $cmdline; $self->{'cmdline'} = $cmdline;
...@@ -305,31 +320,35 @@ sub post_configure_hook { ...@@ -305,31 +320,35 @@ sub post_configure_hook {
if (!$dict->readfile($df)) { if (!$dict->readfile($df)) {
$self->log(LOG_WARN,"[SMRADIUS] Failed to load dictionary '$df': $!"); $self->log(LOG_WARN,"[SMRADIUS] Failed to load dictionary '$df': $!");
} }
$self->log(LOG_DEBUG,"[SMRADIUS] Loaded plugin '$df'."); $self->log(LOG_DEBUG,"[SMRADIUS] Loaded module '$df'.");
} }
$self->log(LOG_NOTICE,"[SMRADIUS] Dictionaries initialized."); $self->log(LOG_NOTICE,"[SMRADIUS] Dictionaries initialized.");
# Store the dictionary # Store the dictionary
$self->{'radius'}->{'dictionary'} = $dict; $self->{'radius'}->{'dictionary'} = $dict;
$self->log(LOG_NOTICE,"[SMRADIUS] Initializing modules..."); $self->log(LOG_NOTICE,"[SMRADIUS] Initializing modules...");
# Load plugins # Load modules
foreach my $plugin (@{$config->{'plugins'}}) { foreach my $module (@{$config->{'module_list'}}) {
# Load plugin # Split off dir and mod name
$module =~ /^(\w+)\/(\w+)$/;
my ($mod_dir,$mod_name) = ($1,$2);
# Load module
my $res = eval(" my $res = eval("
use $plugin; use smradius::modules::${mod_dir}::${mod_name};
plugin_register(\$self,\"$plugin\",\$${plugin}::pluginInfo); plugin_register(\$self,\"${mod_name}\",\$smradius::modules::${mod_dir}::${mod_name}::pluginInfo);
"); ");
if ($@ || (defined($res) && $res != 0)) { if ($@ || (defined($res) && $res != 0)) {
$self->log(LOG_WARN,"[SMRADIUS] Error loading plugin $plugin ($@)"); $self->log(LOG_WARN,"[SMRADIUS] Error loading module $module ($@)");
} else { } else {
$self->log(LOG_DEBUG,"[SMRADIUS] Plugin '$plugin' loaded."); $self->log(LOG_DEBUG,"[SMRADIUS] Plugin '$module' loaded.");
} }
} }
$self->log(LOG_NOTICE,"[SMRADIUS] Plugins initialized."); $self->log(LOG_NOTICE,"[SMRADIUS] Plugins initialized.");
$self->log(LOG_NOTICE,"[SMRADIUS] Initializing system modules."); $self->log(LOG_NOTICE,"[SMRADIUS] Initializing system modules.");
# Init caching engine # Init caching engine
# smradius::cache::Init($self); # awitpt::cache::Init($self);
$self->log(LOG_NOTICE,"[SMRADIUS] System modules initialized."); $self->log(LOG_NOTICE,"[SMRADIUS] System modules initialized.");
} }
...@@ -349,7 +368,7 @@ sub plugin_register { ...@@ -349,7 +368,7 @@ sub plugin_register {
# Set real module name & save # Set real module name & save
$info->{'Module'} = $plugin; $info->{'Module'} = $plugin;
push(@{$self->{'plugins'}},$info); push(@{$self->{'module_list'}},$info);
# If we should, init the module # If we should, init the module
if (defined($info->{'Init'})) { if (defined($info->{'Init'})) {
...@@ -370,7 +389,7 @@ sub child_init_hook ...@@ -370,7 +389,7 @@ sub child_init_hook
$self->SUPER::child_init_hook(); $self->SUPER::child_init_hook();
$self->log(LOG_DEBUG,"[SMRADIUS] Starting up caching engine"); $self->log(LOG_DEBUG,"[SMRADIUS] Starting up caching engine");
smradius::cache::connect($self); awitpt::cache::connect($self);
# Do we need database support? # Do we need database support?
if ($self->{'smradius'}->{'database'}->{'enabled'}) { if ($self->{'smradius'}->{'database'}->{'enabled'}) {
...@@ -379,7 +398,7 @@ sub child_init_hook ...@@ -379,7 +398,7 @@ sub child_init_hook
$self->{'client'}->{'dbh_status'} = time(); $self->{'client'}->{'dbh_status'} = time();
# Init core database support # Init core database support
$self->{'client'}->{'dbh'} = smradius::dbilayer::Init($self); $self->{'client'}->{'dbh'} = awitpt::db::dbilayer::Init($self,'smradius');
if (defined($self->{'client'}->{'dbh'})) { if (defined($self->{'client'}->{'dbh'})) {
# Check if we succeeded # Check if we succeeded
if (!($self->{'client'}->{'dbh'}->connect())) { if (!($self->{'client'}->{'dbh'}->connect())) {
...@@ -390,7 +409,7 @@ sub child_init_hook ...@@ -390,7 +409,7 @@ sub child_init_hook
" ($$)"); " ($$)");
} }
} else { } else {
$self->log(LOG_WARN,"[SMRADIUS] Failed to Initialize: ".smradius::dbilayer::internalErr()." ($$)"); $self->log(LOG_WARN,"[SMRADIUS] Failed to Initialize: ".awitpt::db::dbilayer::internalError()." ($$)");
} }
} }
...@@ -406,7 +425,7 @@ sub child_finish_hook { ...@@ -406,7 +425,7 @@ sub child_finish_hook {
$self->SUPER::child_finish_hook(); $self->SUPER::child_finish_hook();
$self->log(LOG_DEBUG,"[SMRADIUS] Shutting down caching engine ($$)"); $self->log(LOG_DEBUG,"[SMRADIUS] Shutting down caching engine ($$)");
smradius::cache::disconnect($self); awitpt::cache::disconnect($self);
} }
...@@ -415,7 +434,7 @@ sub process_request { ...@@ -415,7 +434,7 @@ sub process_request {
my $self = shift; my $self = shift;
my $server = $self->{'server'}; my $server = $self->{'server'};
my $client = $self->{'client'}; my $client = $self->{'client'};
my $log = defined($server->{'config'}{'logging'}{'modules'}); my $log = defined($server->{'config'}{'logging'}{'module_list'});
# Grab packet # Grab packet
...@@ -490,7 +509,7 @@ sub process_request { ...@@ -490,7 +509,7 @@ sub process_request {
# GRAB & PROCESS CONFIG # GRAB & PROCESS CONFIG
# #
foreach my $module (@{$self->{'plugins'}}) { foreach my $module (@{$self->{'module_list'}}) {
# Try find config attribute # Try find config attribute
if ($module->{'Config_get'}) { if ($module->{'Config_get'}) {
...@@ -537,7 +556,7 @@ sub process_request { ...@@ -537,7 +556,7 @@ sub process_request {
# #
# Loop with modules to try find user # Loop with modules to try find user
foreach my $module (@{$self->{'plugins'}}) { foreach my $module (@{$self->{'module_list'}}) {
# Try find user # Try find user
if ($module->{'User_find'}) { if ($module->{'User_find'}) {
$self->log(LOG_INFO,"[SMRADIUS] FIND: Trying plugin '".$module->{'Name'}."' for username '". $self->log(LOG_INFO,"[SMRADIUS] FIND: Trying plugin '".$module->{'Name'}."' for username '".
...@@ -591,7 +610,7 @@ sub process_request { ...@@ -591,7 +610,7 @@ sub process_request {
} }
# Loop with modules to try something that handles accounting # Loop with modules to try something that handles accounting
foreach my $module (@{$self->{'plugins'}}) { foreach my $module (@{$self->{'module_list'}}) {
# Try find user # Try find user
if ($module->{'Accounting_log'}) { if ($module->{'Accounting_log'}) {
$self->log(LOG_INFO,"[SMRADIUS] ACCT: Trying plugin '".$module->{'Name'}."'"); $self->log(LOG_INFO,"[SMRADIUS] ACCT: Trying plugin '".$module->{'Name'}."'");
...@@ -626,8 +645,8 @@ sub process_request { ...@@ -626,8 +645,8 @@ sub process_request {
# Are we going to POD the user? # Are we going to POD the user?
my $PODUser = 0; my $PODUser = 0;
# Loop with features that have post-authentication hooks # Loop with modules that have post-authentication hooks
foreach my $module (@{$self->{'plugins'}}) { foreach my $module (@{$self->{'module_list'}}) {
# Try authenticate # Try authenticate
if ($module->{'Feature_Post-Accounting_hook'}) { if ($module->{'Feature_Post-Accounting_hook'}) {
$self->log(LOG_INFO,"[SMRADIUS] POST-ACCT: Trying plugin '".$module->{'Name'}."' for '". $self->log(LOG_INFO,"[SMRADIUS] POST-ACCT: Trying plugin '".$module->{'Name'}."' for '".
...@@ -747,7 +766,7 @@ sub process_request { ...@@ -747,7 +766,7 @@ sub process_request {
# #
# Loop with authentication modules # Loop with authentication modules
foreach my $module (@{$self->{'plugins'}}) { foreach my $module (@{$self->{'module_list'}}) {
# Try authenticate # Try authenticate
if ($module->{'Authentication_try'}) { if ($module->{'Authentication_try'}) {
$self->log(LOG_INFO,"[SMRADIUS] AUTH: Trying plugin '".$module->{'Name'}."' for '".$user->{'Username'}."'"); $self->log(LOG_INFO,"[SMRADIUS] AUTH: Trying plugin '".$module->{'Name'}."' for '".$user->{'Username'}."'");
...@@ -778,9 +797,9 @@ sub process_request { ...@@ -778,9 +797,9 @@ sub process_request {
} }
} }
# Loop with features that have post-authentication hooks # Loop with modules that have post-authentication hooks
if ($authenticated) { if ($authenticated) {
foreach my $module (@{$self->{'plugins'}}) { foreach my $module (@{$self->{'module_list'}}) {
# Try authenticate # Try authenticate
if ($module->{'Feature_Post-Authentication_hook'}) { if ($module->{'Feature_Post-Authentication_hook'}) {
$self->log(LOG_INFO,"[SMRADIUS] POST-AUTH: Trying plugin '".$module->{'Name'}. $self->log(LOG_INFO,"[SMRADIUS] POST-AUTH: Trying plugin '".$module->{'Name'}.
...@@ -804,7 +823,7 @@ sub process_request { ...@@ -804,7 +823,7 @@ sub process_request {
} elsif ($res == MOD_RES_NACK) { } elsif ($res == MOD_RES_NACK) {
$self->log(LOG_NOTICE,"[SMRADIUS] POST-AUTH: Failed authentication by '".$module->{'Name'}."'"); $self->log(LOG_NOTICE,"[SMRADIUS] POST-AUTH: Failed authentication by '".$module->{'Name'}."'");
$authenticated = 0; $authenticated = 0;
# Do we want to run the other features ?? # Do we want to run the other modules ??
last; last;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment