FIX: verify dsn

This commit is contained in:
Dominik Meyer 2023-12-27 11:29:48 +01:00
parent 1197d6524e
commit 05ff0ad608
Signed by: byterazor
GPG Key ID: EABDA0FD5981BC97

View File

@ -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));