chiark / gitweb /
support assocdb_dbh
authorIan Jackson <ian.jackson@eu.citrix.com>
Fri, 18 Jan 2013 18:45:16 +0000 (18:45 +0000)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Fri, 18 Jan 2013 18:45:16 +0000 (18:45 +0000)
cgi-auth-flexible.pm

index c7ded66..e8b493d 100644 (file)
@@ -180,6 +180,7 @@ sub new_verifier {
     my $verifier = {
        S => {
             dir => undef,
+           assocdb_dbh => undef, # must have AutoCommit=0, RaiseError=1
            assocdb_path => 'caf-assocs.db',
            keys_path => 'caf-keys',
            assocdb_dsn => undef,
@@ -254,17 +255,23 @@ sub _dbopen ($) {
     my $dbh = $v->{Dbh};
     return $dbh if $dbh; 
 
-    $v->{S}{assocdb_dsn} ||= "dbi:SQLite:dbname=".$v->_get_path('assocdb');
-    my $dsn = $v->{S}{assocdb_dsn};
-
-    my $u = umask 077;
-    $dbh = DBI->connect($dsn, $v->{S}{assocdb_user}, 
-                        $v->{S}{assocdb_password}, { 
-                            AutoCommit => 0,
-                            RaiseError => 1,
-                            ShowErrorStatement => 1,
-                        });
-    die "$dsn $! ?" unless $dbh;
+    $dbh = $v->{S}{assocdb_dbh};
+    if ($dbh) {
+        die if $dbh->{AutoCommit};
+        die unless $dbh->{RaiseError};
+    } else {
+        $v->{S}{assocdb_dsn} ||= "dbi:SQLite:dbname=".$v->_get_path('assocdb');
+        my $dsn = $v->{S}{assocdb_dsn};
+
+        my $u = umask 077;
+        $dbh = DBI->connect($dsn, $v->{S}{assocdb_user},
+                            $v->{S}{assocdb_password}, {
+                                AutoCommit => 0,
+                                RaiseError => 1,
+                                ShowErrorStatement => 1,
+                            });
+        die "$dsn $! ?" unless $dbh;
+    }
     $v->{Dbh} = $dbh;
 
     $v->_db_setup_do("CREATE TABLE $v->{S}{assocdb_table} (".