From bc4f0d2cae9bb9c25df4507a2c73d50160803402 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 28 Apr 2015 06:26:40 +0000 Subject: [PATCH] made etc/perl/Codepot/AuthenHandler.pm pgsql friendly --- codepot/etc/perl/Codepot/AccessHandler.pm | 32 ++++++++++++++++++----- codepot/etc/perl/Codepot/AuthenHandler.pm | 2 +- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/codepot/etc/perl/Codepot/AccessHandler.pm b/codepot/etc/perl/Codepot/AccessHandler.pm index 04cd2cf2..e00b450b 100644 --- a/codepot/etc/perl/Codepot/AccessHandler.pm +++ b/codepot/etc/perl/Codepot/AccessHandler.pm @@ -67,6 +67,7 @@ sub get_config ldap_userid_search_filter => $cfg->param ('ldap_userid_search_filter'), database_hostname => $cfg->param ('database_hostname'), + database_port => $cfg->param ("database_port"), database_username => $cfg->param ('database_username'), database_password => $cfg->param ('database_password'), database_name => $cfg->param ('database_name'), @@ -161,14 +162,20 @@ sub authenticate_ldap sub authenticate_database { - my ($dbh, $prefix, $userid, $password) = @_; + my ($dbh, $prefix, $userid, $password, $driver) = @_; - my $query = $dbh->prepare ("SELECT userid,passwd FROM ${prefix}user WHERE userid=? and enabled='Y'"); + my $user_table_name = "${prefix}user"; + if ($driver eq 'postgre' && length($prefix) <= 0) + { + $user_table_name = '"user"'; + } + + my $query = $dbh->prepare ("SELECT userid,passwd FROM ${user_table_name} WHERE userid=? and enabled='Y'"); if (!$query || !$query->execute ($userid)) { return (-1, $dbh->errstr()); } - + my @row = $query->fetchrow_array; $query->finish (); @@ -191,9 +198,16 @@ sub open_database my $dbtype = $cfg->{database_driver}; my $dbname = $cfg->{database_name}; my $dbhost = $cfg->{database_hostname}; + my $dbport = $cfg->{database_port}; + + if ($dbtype eq 'postgre') { $dbtype = 'Pg'; } + + my $dbstr = "DBI:$dbtype:database=$dbname;"; + if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } + if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } my $dbh = DBI->connect( - "DBI:$dbtype:$dbname:$dbhost", + $dbstr, $cfg->{database_username}, $cfg->{database_password}, { RaiseError => 0, PrintError => 0, AutoCommit => 0 } @@ -312,7 +326,11 @@ sub __handler elsif ($cfg->{login_model} eq 'DbLoginModel') { ($auth, $errmsg) = authenticate_database ( - $dbh, $cfg->{database_prefix}, $userid, $password); + $dbh, $cfg->{database_prefix}, $userid, $password, $cfg->{database_driver}); + if ($auth <= -1) + { + $r->log_error ("Database error - $errmsg"); + } } if ($auth <= -1) { @@ -361,14 +379,14 @@ sub handler: method $cfg = get_config (); if (!defined($cfg)) { - $r->log_error ("Cannot load configuration"); + $r->log_error ('Cannot load configuration'); return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR; } my $dbh = open_database ($cfg); if (!defined($dbh)) { - $r->log_error ("Cannot open database"); + $r->log_error ('Cannot open database - ' . $DBI::errstr); return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR; } diff --git a/codepot/etc/perl/Codepot/AuthenHandler.pm b/codepot/etc/perl/Codepot/AuthenHandler.pm index 00bc7f55..e02c9ab7 100644 --- a/codepot/etc/perl/Codepot/AuthenHandler.pm +++ b/codepot/etc/perl/Codepot/AuthenHandler.pm @@ -7,6 +7,6 @@ use Apache2::Const -compile => qw(OK DECLINED FORBIDDEN HTTP_UNAUTHORIZED HTTP_ sub handler: method { - return Apache2::Const::OK; + return Apache2::Const::OK; } 1;