Force deletion of corrupted sessions in DBI backends (#2404)

This commit is contained in:
Clément OUDOT 2021-01-03 18:17:46 +01:00
parent 726b327bda
commit f021df37e4

View File

@ -32,7 +32,7 @@ my $nb_error = 0;
#=============================================================================
my $lmconf = Lemonldap::NG::Common::Conf->new()
or die $Lemonldap::NG::Common::Conf::msg;
my $conf = $lmconf->getConf or die "Unable to get configuration ($!)";
my $conf = $lmconf->getConf or die "Unable to get configuration ($!)";
my $localconf = $lmconf->getLocalConf(PORTALSECTION)
or die "Unable to get local configuration ($!)";
@ -236,7 +236,7 @@ for my $options (@backends) {
# Remove lock files for File backend
if ( $options->{backend} =~ /^Apache::Session::(?:Browseable::)?File$/i ) {
require Apache::Session::Lock::File;
my $l = new Apache::Session::Lock::File;
my $l = new Apache::Session::Lock::File;
my $lock_directory = $options->{LockDirectory} || $options->{Directory};
$l->clean( $lock_directory, $conf->{timeout} );
}
@ -257,6 +257,28 @@ for my $options (@backends) {
}
}
}
# Force deletion of corrupted sessions for DBI backend
if ( $options->{backend} =~
/^Apache::Session::(?:Browseable::)?(MySQL|Postgres|DBI|Oracle|Informix|MySQLJSON|PgHstore|PgJSON|SQLLite|Sybase)$/i
and $force )
{
my $dbi = DBI->connect_cached( $options->{DataSource},
$options->{UserName}, $options->{Password} );
my $table = $options->{TableName} || "sessions";
my $req = $dbi->prepare("DELETE from $table WHERE id=?");
foreach (@errors) {
my $id = $_;
my $res = $req->execute($id);
unless ( $res == 1 ) {
print STDERR "Fail to delete session $id with force\n";
}
else {
print STDERR "Session $id removed with force\n";
$nb_error--;
}
}
}
}
#=============================================================================