Hi fellows,

as we have an auth check for vpopmail already, it would make sense to have a check for allowed recipients there as well IMHO.

Attaching one, if someone feels like using it, feedback appreciated :)

Best Regards
Markus Ullmann
# this plugin checks if a user exists in the vpopmail database
#
use Qpsmtpd::DSN;
use DBI;
use Qpsmtpd::Constants;

use Digest::HMAC_MD5 qw(hmac_md5_hex);

sub hook_rcpt {
  my ($self) = @_;
  # skip if SMTP-AUTHed already                            
  return (DECLINED) if $self->qp->connection->relay_client;
                     
  my $connect  = "dbi:mysql:dbname=vpopmail";
  my $dbuser   = "vpopmailuser";
  my $dbpasswd = "vpoppassword";
  my ($self, $transaction, $recipient, %param) = @_;

  my $dbh = DBI->connect( $connect, $dbuser, $dbpasswd );
  $dbh->{ShowErrorStatement} = 1;

  my $local_part = lc $recipient->user;
  my $domain_part = lc $recipient->host;

  my $bad = $local_part . '@' . $domain_part;

  my $sth_1 = $dbh->prepare(<<SQL);
select *
from vpopmail
where pw_name = ? and pw_domain = ?
SQL

  $sth_1->execute( $local_part, $domain_part );
  if( $sth_1 -> fetchrow_array() ) {
      return( OK );
  }

  my $sth_2 = $dbh->prepare(<<SQL);
select *
from valias
where alias = ? and domain = ?
SQL

  $sth_2->execute( $local_part, $domain_part );
  if( $sth_2 -> fetchrow_array() ) {
      return ( OK );
  }

  return (DENY,Qpsmtpd::DSN->no_such_user("mail to $bad not accepted here"));
}

Reply via email to