From 9280012969a290c0e31d1d8a109e68c09e3019f3 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 9 Nov 2011 10:35:03 +0100 Subject: [PATCH] Anlegen der Auth-DB fixen MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Auth.pms Session-Management kam nicht damit zurecht, wenn die Auth-DB bzw. das "auth"-Schema darin noch nicht existiert haben. Das passiert z.B., wenn die Auth-DB gerade über den Admin-Bereich angelegt werden soll. --- SL/Auth.pm | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/SL/Auth.pm b/SL/Auth.pm index 37586b8ff..7e46c125e 100644 --- a/SL/Auth.pm +++ b/SL/Auth.pm @@ -525,10 +525,24 @@ sub restore_session { $form = $main::form; - $dbh = $self->dbconnect(); + # Don't fail if the auth DB doesn't yet. + if (!( $dbh = $self->dbconnect(1) )) { + $::lxdebug->leave_sub; + return SESSION_NONE; + } + + # Don't fail if the "auth" schema doesn't exist yet, e.g. if the + # admin is creating the session tables at the moment. $query = qq|SELECT *, (mtime < (now() - '$self->{session_timeout}m'::interval)) AS is_expired FROM auth.session WHERE id = ?|; - $cookie = selectfirst_hashref_query($form, $dbh, $query, $session_id); + if (!($sth = $dbh->prepare($query)) || !$sth->execute($session_id)) { + $sth->finish if $sth; + $::lxdebug->leave_sub; + return SESSION_NONE; + } + + $cookie = $sth->fetchrow_hashref; + $sth->finish; if (!$cookie || $cookie->{is_expired} || ($cookie->{ip_address} ne $ENV{REMOTE_ADDR})) { $self->destroy_session(); @@ -703,7 +717,13 @@ sub save_session { $dbh->begin_work unless $provided_dbh; - do_query($::form, $dbh, qq|LOCK auth.session_content|); + # If this fails then the "auth" schema might not exist yet, e.g. if + # the admin is just trying to create the auth database. + if (!$dbh->do(qq|LOCK auth.session_content|)) { + $dbh->rollback unless $provided_dbh; + $::lxdebug->leave_sub; + return; + } my @unfetched_keys = map { $_->{key} } grep { ! $_->{fetched} } -- 2.20.1