FIX: verify dsn
This commit is contained in:
parent
1197d6524e
commit
05ff0ad608
@ -39,6 +39,16 @@ sub createDSN
|
||||
$self->{dsn} = $dsn;
|
||||
|
||||
$self->log(LOGDEBUG, "created DSN " . $self->{dsn});
|
||||
|
||||
# try to parse the dsn to ensure it is valid
|
||||
my @data = DBI->parse_dsn($self->{dsn});
|
||||
|
||||
if (@data == 0)
|
||||
{
|
||||
$self->log(LOGERROR, "DSN " . $self->{dsn} . " not valid");
|
||||
$self->{dsn}="";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sub createQuery
|
||||
@ -180,20 +190,25 @@ sub askDatabase
|
||||
my $self = shift;
|
||||
my $recipient = shift;
|
||||
|
||||
$self->log(LOGDEBUG, "use DSN " . $self->{dsn});
|
||||
if (length($self->{dsn}) == 0)
|
||||
{
|
||||
$self->log(LOGERROR, "DSN not valid not checking recipient in database");
|
||||
return DECLINED;
|
||||
}
|
||||
|
||||
my $dbh = DBI::connect($self->{dsn}, $self->{user}, $self->{pass});
|
||||
|
||||
if ($dbh->err())
|
||||
{
|
||||
warn("error connecting to DB: " . $dbh->errstr());
|
||||
return DENYSOFT;
|
||||
$self->log(LOGERROR, "error connecting to DB: " . $dbh->errstr());
|
||||
return DECLINED;
|
||||
}
|
||||
|
||||
my $sth = $dbh->prepare($self->{sqlquery});
|
||||
if ($sth->err())
|
||||
{
|
||||
warn("error preparing query: " . $sth->errstr());
|
||||
return DENYSOFT;
|
||||
$self->log(LOGERROR, "error preparing query: " . $sth->errstr());
|
||||
return DECLINED;
|
||||
}
|
||||
|
||||
$sth->execute($self->prepareParams($recipient));
|
||||
|
Loading…
Reference in New Issue
Block a user