badrcptto: log tweaks, better regex detection

This commit is contained in:
Matt Simerson 2012-06-22 23:56:25 -04:00
parent 6020949551
commit 560ce218e3
2 changed files with 16 additions and 6 deletions

View File

@ -55,7 +55,7 @@ sub hook_rcpt {
or return (DECLINED); or return (DECLINED);
my @badrcptto = $self->qp->config("badrcptto") or do { my @badrcptto = $self->qp->config("badrcptto") or do {
$self->log(LOGINFO, "skip: empty config"); $self->log(LOGINFO, "skip, empty config");
return (DECLINED); return (DECLINED);
}; };
@ -79,7 +79,7 @@ sub hook_rcpt {
sub is_match { sub is_match {
my ( $self, $to, $bad, $host ) = @_; my ( $self, $to, $bad, $host ) = @_;
if ( $bad =~ /[\/\^\$\*\+\!\%]/ ) { # it's a regexp if ( $bad =~ /[\/\^\$\*\+\!\%\?\\]/ ) { # it's a regexp
$self->log(LOGDEBUG, "badmailfrom pattern ($bad) match for $to"); $self->log(LOGDEBUG, "badmailfrom pattern ($bad) match for $to");
if ( $to =~ /$bad/i ) { if ( $to =~ /$bad/i ) {
$self->log(LOGINFO, 'fail: pattern match'); $self->log(LOGINFO, 'fail: pattern match');

View File

@ -13,6 +13,14 @@ sub register_tests {
$self->register_test("test_get_host_and_to", 8); $self->register_test("test_get_host_and_to", 8);
} }
sub _reset_connection_flags {
my $self = shift;
$self->qp->connection->relay_client(0);
$self->qp->connection->notes('whitelisthost', 0);
$self->connection->notes('naughty',0);
$self->connection->notes('rejected', 0);
};
sub test_is_match { sub test_is_match {
my $self = shift; my $self = shift;
@ -52,19 +60,21 @@ sub test_is_match {
sub test_hook_rcpt { sub test_hook_rcpt {
my $self = shift; my $self = shift;
$self->_reset_connection_flags();
my $transaction = $self->qp->transaction; my $transaction = $self->qp->transaction;
my $recipient = Qpsmtpd::Address->new( '<user@example.com>' ); my $recipient = Qpsmtpd::Address->new( '<user@example.com>' );
my ($r, $mess) = $self->hook_rcpt( $transaction, $recipient ); my ($r, $mess) = $self->hook_rcpt( $transaction, $recipient );
cmp_ok( DECLINED, '==', $r, "valid +"); cmp_ok( $r, '==', DECLINED, "valid +");
$recipient = Qpsmtpd::Address->new( '<bad@example.com>' ); $recipient = Qpsmtpd::Address->new( '<bad@example.com>' );
($r, $mess) = $self->hook_rcpt( $transaction, $recipient ); ($r, $mess) = $self->hook_rcpt( $transaction, $recipient );
cmp_ok( DENY, '==', $r, "bad match, +"); cmp_ok( $r, '==', DENY, "bad match, +, $mess");
$recipient = Qpsmtpd::Address->new( '<any@bad.example.com>' ); $recipient = Qpsmtpd::Address->new( '<any@bad.example.com>' );
($r, $mess) = $self->hook_rcpt( $transaction, $recipient ); ($r, $mess) = $self->hook_rcpt( $transaction, $recipient );
cmp_ok( DENY, '==', $r, "bad host match, +"); cmp_ok( $r, '==', DENY, "bad host match, +, $mess");
}; };
sub test_get_host_and_to { sub test_get_host_and_to {