diff --git a/smradius/config.pm b/smradius/config.pm index 3deec22c3f7702556a59da7e5677f3b982e7b504..9f3a30ba4b40615e4d829f2adea3c486363cb555 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 2c05929e76c1c781774f319facb0faf5dc92103d..a5cfa3bd70ab51e612736b6890a34143fd0228eb 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 062dfb4bce23615798852646a888e3d598c25bdb..20f95900562dd96aa6f4946dc32766b05bdffc9d 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 707089e2a14e8a440a632f98b42ffe8e42088a88..ba35dcc49f3577766ddebef2b14a38bfbca3dfbf 100644 --- a/smradiusd.conf +++ b/smradiusd.conf @@ -104,6 +104,7 @@ EOT users=<<EOT mod_userdb_test +mod_userdb_sql EOT # ========================================================================================