X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=cgi-auth-flexible.git;a=blobdiff_plain;f=cgi-auth-flexible.pm;h=1d23ae7f7d3844fb17720e9a4e948dda5a8114c9;hp=4b4823a7362df6dd3bc4733e7796eb1fb4c15aca;hb=22718a11458ca91fa40bcd11270ed1e3606ea12f;hpb=0cc7c93091dc8700032bf5eef81120d46633d65f diff --git a/cgi-auth-flexible.pm b/cgi-auth-flexible.pm index 4b4823a..1d23ae7 100644 --- a/cgi-auth-flexible.pm +++ b/cgi-auth-flexible.pm @@ -32,7 +32,7 @@ BEGIN { @EXPORT = qw(); %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ], - @EXPORT_OK = qw(); + @EXPORT_OK = qw(@default_db_setup_stmts); } our @EXPORT_OK; @@ -202,6 +202,18 @@ sub gen_plain_footer_html ($$) { ''); } +our @default_db_setup_stmts = + ("CREATE TABLE $v->{S}{db_prefix}_assocs (". + " assochash VARCHAR PRIMARY KEY,". + " username VARCHAR NOT NULL,". + " last INTEGER NOT NULL". + ")" + , + "CREATE INDEX $v->{S}{db_prefix}_assocs_timeout_index". + " ON $v->{S}{db_prefix}_assocs". + " (last)" + ); + #---------- licence and source code ---------- sub srcdump_dump ($$$) { @@ -420,13 +432,14 @@ sub new_verifier { S => { dir => undef, assocdb_dbh => undef, # must have AutoCommit=0, RaiseError=1 - assocdb_path => 'caf-assocs.db', + assocdb_path => 'caf.db', keys_path => 'caf-keys', srcdump_path => 'caf-srcdump', assocdb_dsn => undef, assocdb_user => '', assocdb_password => '', - assocdb_table => 'caf_assocs', + db_prefix => 'caf', + assocdb_setup_stmts => [@_default_db_setup_statements], random_source => '/dev/urandom', secretbits => 128, # bits hash_algorithm => "SHA-256", @@ -543,14 +556,9 @@ sub _dbopen ($) { } $v->{Dbh} = $dbh; - $v->_db_setup_do("CREATE TABLE $v->{S}{assocdb_table} (". - " assochash VARCHAR PRIMARY KEY,". - " username VARCHAR NOT NULL,". - " last INTEGER NOT NULL". - ")"); - $v->_db_setup_do("CREATE INDEX $v->{S}{assocdb_table}_timeout_index". - " ON $v->{S}{assocdb_table}". - " (last)"); + foreach my $stmt (@default_db_setup_stmts) { + $v->_db_setup_do($stmt); + } return $dbh; } @@ -832,7 +840,7 @@ sub _check_divert_core ($) { " enabled. You must enable cookies". " as we use them for login."), CookieSecret => $r->_fresh_secret(), - Params => $r->chain_params() }) + Params => $r->_chain_params() }) } if (!$cookt || $cookt eq 'n' || $cookh ne $parmh) { $r->_db_revoke($cookh); @@ -850,13 +858,13 @@ sub _check_divert_core ($) { return ({ Kind => 'LOGIN-BAD', Message => $login_errormessage, CookieSecret => $cooks, - Params => $r->chain_params() }) + Params => $r->_chain_params() }) } $r->_db_record_login_ok($parmh,$username); return ({ Kind => 'REDIRECT-LOGGEDIN', Message => $r->_gt("Logging in..."), CookieSecret => $cooks, - Params => $r->chain_params() }); + Params => $r->_chain_params() }); } if ($cookt eq 't') { $cookt = ''; @@ -876,7 +884,7 @@ sub _check_divert_core ($) { return ({ Kind => 'LOGIN-INCOMINGLINK', Message => $r->_gt("You need to log in."), CookieSecret => $news, - Params => $r->chain_params() }); + Params => $r->_chain_params() }); } else { $r->_db_revoke($parmh); return ({ Kind => 'LOGIN-FRESH', @@ -910,7 +918,14 @@ sub _check_divert_core ($) { return undef; } -sub chain_params ($) { +sub _chain_params ($) { +# =item C<< $authreq->_chain_params() >> +# +# Returns a hash of the "relevant" parameters to this request, in a form +# used by C. This is all of the query parameters +# which are not related to CGI::Auth::Flexible. The PATH_INFO from the +# request is returned as the parameter C<< '' >>. + my ($r) = @_; my %p = %{ $r->_ch('get_params') }; foreach my $pncn (keys %{ $r->{S} }) { @@ -949,12 +964,12 @@ sub _identify ($$) { my $dbh = $r->{Dbh}; - $dbh->do("DELETE FROM $r->{S}{assocdb_table}". + $dbh->do("DELETE FROM $r->{S}{db_prefix}_assocs". " WHERE last < ?", {}, time - $r->{S}{login_timeout}); my $row = $dbh->selectrow_arrayref("SELECT username, last". - " FROM $r->{S}{assocdb_table}". + " FROM $r->{S}{db_prefix}_assocs". " WHERE assochash = ?", {}, $h); if (defined $row) { #print STDERR "_identify h=$h s=$s YES @$row\n"; @@ -995,7 +1010,7 @@ sub _db_revoke ($$) { my $dbh = $r->{Dbh}; - $dbh->do("DELETE FROM $r->{S}{assocdb_table}". + $dbh->do("DELETE FROM $r->{S}{db_prefix}_assocs". " WHERE assochash = ?", {}, $h); } @@ -1003,7 +1018,7 @@ sub _db_record_login_ok ($$$) { my ($r,$h,$user) = @_; $r->_db_revoke($h); my $dbh = $r->{Dbh}; - $dbh->do("INSERT INTO $r->{S}{assocdb_table}". + $dbh->do("INSERT INTO $r->{S}{db_prefix}_assocs". " (assochash, username, last) VALUES (?,?,?)", {}, $h, $user, time); }