From 2c329da1fad94da9f30134c7874eb782e2fd2cec Mon Sep 17 00:00:00 2001 From: Nigel Kukard <nkukard@lbsd.net> Date: Fri, 27 Feb 2009 07:55:39 +0000 Subject: [PATCH] * Added mod_userdb_sql ability to enable SQL support in smradiusd --- smradius/config.pm | 8 ++++-- smradius/modules/userdb/mod_userdb_sql.pm | 13 ++++++++-- smradiusd | 30 +++++++++++++---------- smradiusd.conf | 1 + 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/smradius/config.pm b/smradius/config.pm index 3deec22c..9f3a30ba 100644 --- a/smradius/config.pm +++ b/smradius/config.pm @@ -29,6 +29,10 @@ our (@ISA,@EXPORT); @EXPORT = qw( ); + +use smradius::logging; + + # Our vars my $config; @@ -49,11 +53,11 @@ sub Init $db->{'DSN'} = $config->{'database'}{'dsn'}; $db->{'Username'} = $config->{'database'}{'username'}; $db->{'Password'} = $config->{'database'}{'password'}; + $db->{'enabled'} = 0; # Check we have all the config we need if (!defined($db->{'DSN'})) { - $server->log(1,"smradius/config.pm: No 'DSN' defined in config file for 'database'"); - exit 1; + $server->log(LOG_NOTICE,"smradius/config.pm: No 'DSN' defined in config file for 'database'"); } $server->{'smradius'}{'database'} = $db; diff --git a/smradius/modules/userdb/mod_userdb_sql.pm b/smradius/modules/userdb/mod_userdb_sql.pm index 2c05929e..a5cfa3bd 100644 --- a/smradius/modules/userdb/mod_userdb_sql.pm +++ b/smradius/modules/userdb/mod_userdb_sql.pm @@ -16,13 +16,14 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -package mod_sql_test; +package mod_userdb_sql; use strict; use warnings; # Modules we need use smradius::constants; +use smradius::logging; # Exporter stuff @@ -53,6 +54,14 @@ our $pluginInfo = { sub init { my $server = shift; + my $config = $server->{'config'}; + + + # Enable support for database + if (!$server->{'smradius'}->{'database'}->{'enable'}) { + $server->log(LOG_NOTICE,"[MOD_USERDB_SQL] Enabling database support."); + $server->{'smradius'}->{'database'}->{'enable'} = 1; + } } @@ -88,7 +97,7 @@ sub get { my ($server,$user,$packet) = @_; - + my $userDetails; # TODO: Query user and get attributes, return in $userDetails hash return $userDetails; diff --git a/smradiusd b/smradiusd index 062dfb4b..20f95900 100755 --- a/smradiusd +++ b/smradiusd @@ -306,6 +306,7 @@ sub plugin_register { sub child_init_hook { my $self = shift; + my $config = $self->{'config'}; $self->SUPER::child_init_hook(); @@ -313,22 +314,25 @@ sub child_init_hook $self->log(LOG_DEBUG,"[SMRADIUS] Starting up caching engine"); smradius::cache::connect($self); - # This is the database connection timestamp, if we connect, it resets to 0 - # if not its used to check if we must kill the child and try a reconnect - $self->{'client'}->{'dbh_status'} = time(); - - # Init system stuff - $self->{'client'}->{'dbh'} = smradius::dbilayer::Init($self); - if (defined($self->{'client'}->{'dbh'})) { - # Check if we succeeded - if (!($self->{'client'}->{'dbh'}->connect())) { + # Do we need database support? + if ($self->{'smradius'}->{'database'}->{'enable'}) { + # This is the database connection timestamp, if we connect, it resets to 0 + # if not its used to check if we must kill the child and try a reconnect + $self->{'client'}->{'dbh_status'} = time(); + + # Init core database support + $self->{'client'}->{'dbh'} = smradius::dbilayer::Init($self); + if (defined($self->{'client'}->{'dbh'})) { + # Check if we succeeded + if (!($self->{'client'}->{'dbh'}->connect())) { # If we succeeded, record OK - $self->{'client'}->{'dbh_status'} = 0; + $self->{'client'}->{'dbh_status'} = 0; + } else { + $self->log(LOG_WARN,"[SMRADIUS] Failed to connect to database: ".$self->{'client'}->{'dbh'}->Error()." ($$)"); + } } else { - $self->log(LOG_WARN,"[SMRADIUS] Failed to connect to database: ".$self->{'client'}->{'dbh'}->Error()." ($$)"); + $self->log(LOG_WARN,"[SMRADIUS] Failed to Initialize: ".smradius::dbilayer::internalErr()." ($$)"); } - } else { - $self->log(LOG_WARN,"[SMRADIUS] Failed to Initialize: ".smradius::dbilayer::internalErr()." ($$)"); } } diff --git a/smradiusd.conf b/smradiusd.conf index 707089e2..ba35dcc4 100644 --- a/smradiusd.conf +++ b/smradiusd.conf @@ -104,6 +104,7 @@ EOT users=<<EOT mod_userdb_test +mod_userdb_sql EOT # ======================================================================================== -- GitLab