From 212329ebf6fd952bf94beb8e275d5d12a6c6db8f Mon Sep 17 00:00:00 2001 From: Dominik Meyer Date: Wed, 27 Dec 2023 11:29:48 +0100 Subject: [PATCH] FIX: verify dsn --- plugins/rcpt_mysql | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/plugins/rcpt_mysql b/plugins/rcpt_mysql index dd2c3dd..a489898 100644 --- a/plugins/rcpt_mysql +++ b/plugins/rcpt_mysql @@ -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));