Description | Error: rlm_perl: perl_embed:: module = /etc/raddb/rlm_perl_packetfence.pl , func = post_auth exit status= Modification of a read-only value attempted at /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/DBI.pm line 563.
Launching db connection in FreeRADIUS' CLONE {...} then re-connecting only if necessary should mitigate the issue. Here's a patch for those interested:
--- pf/addons/802.1X/rlm_perl_packetfence.pl c967f44b9c3e832b4c2189e5792b47c1006872cd
+++ pf/addons/802.1X/rlm_perl_packetfence.pl 4c5b8f74db3f0770ba542f020d98a1e74ffa1371
@@ -37,6 +37,7 @@ use vars qw(%RAD_REQUEST %RAD_REPLY %RAD
use vars qw(%RAD_REQUEST %RAD_REPLY %RAD_CHECK);
#use Data::Dumper;
+our $mysql_connection;
# This is hash wich hold original request from radius
#my %RAD_REQUEST;
# In this hash you add values that will be returned to NAS.
@@ -221,6 +222,22 @@ sub log_request_attributes {
}
}
+sub CLONE {
+ db_connect();
+}
+
+sub db_connect {
+
+ $mysql_connection = DBI->connect("dbi:mysql:dbname=".DB_NAME.";host=".DB_HOSTNAME,
+ DB_USER, DB_PASS, {PrintError => 0});
+
+ if (!defined($mysql_connection)) {
+ openlog("rlm_perl_packetfence", "perror,pid","user");
+ syslog("info", "Can't connect to the database.");
+ closelog();
+ }
+}
+
# Here is the decision process:
#
# registered, guest, secure => disconnect (-1)
@@ -250,14 +267,16 @@ sub getVlan {
openlog("rlm_perl_packetfence", "perror,pid","user");
syslog("info", "getVlan called with switch_ip $switch_ip, mac $mac, is_eap_request
$is_eap_request");
-
- # create database connection
- my $mysql_connection = DBI->connect("dbi:mysql:dbname=".DB_NAME.";host=".DB_HOSTNAME,
- DB_USER, DB_PASS, {PrintError => 0});
+
+ if (!defined($mysql_connection) || !$mysql_connection->ping() ) {
+ syslog("info", "Database connection seems down.. Reconnecting...");
+ db_connect();
- if (!defined($mysql_connection)) {
- syslog("info", "Can't connect to the database.");
- return undef;
+ if (!defined($mysql_connection) || !$mysql_connection->ping() ) {
+ syslog("info", "Database still down... Bailing out for this request.");
+ closelog();
+ return;
+ }
}
# check if mac exists already in database
@@ -402,7 +421,6 @@ sub getVlan {
# return the correct VLAN, close resources
syslog("info", "returning VLAN $correctVlan for $mac");
closelog();
- $mysql_connection->disconnect();
return $correctVlan;
}
|