resolvable_fromhost: added karma smites

This commit is contained in:
Matt Simerson 2013-03-26 17:52:41 -04:00
parent 7da69ef12d
commit 3bb85a66a1

View File

@ -109,21 +109,26 @@ sub hook_mail {
return DECLINED if $resolved; # success, no need to continue
#return DECLINED if $sender->host; # reject later
if ( ! $self->{_args}{reject} ) {;
$self->log(LOGINFO, 'skip, reject disabled' );
return DECLINED;
};
my $result = $transaction->notes('resolvable_fromhost') or do {
$self->log(LOGINFO, 'error, missing result' );
return Qpsmtpd::DSN->temp_resolver_failed( $self->get_reject_type(), '' );
if ( $self->{_args}{reject} ) {;
$self->log(LOGINFO, 'error, missing result' );
return Qpsmtpd::DSN->temp_resolver_failed( $self->get_reject_type(), '' );
};
$self->log(LOGINFO, 'error, missing result, reject disabled' );
return DECLINED;
};
return DECLINED if $result =~ /^(?:a|ip|mx)$/; # success
return DECLINED if $result =~ /^(?:whitelist|null|naughty)$/; # immunity
$self->log(LOGINFO, "fail, $result" ); # log error
$self->adjust_karma( -1 );
if ( ! $self->{_args}{reject} ) {;
$self->log(LOGINFO, "fail, reject disabled, $result" );
return DECLINED;
};
$self->log(LOGINFO, "fail, $result" ); # log error
return Qpsmtpd::DSN->addr_bad_from_system( $self->get_reject_type(),
"FQDN required in the envelope sender");
}
@ -134,6 +139,7 @@ sub check_dns {
# we can't even parse a hostname out of the address
if ( ! $host ) {
$transaction->notes('resolvable_fromhost', 'unparsable host');
$self->adjust_karma( -1 );
return;
};
@ -142,6 +148,7 @@ sub check_dns {
if ( $host =~ m/^\[(\d{1,3}\.){3}\d{1,3}\]$/ ) {
$self->log(LOGINFO, "skip, $host is an IP");
$transaction->notes('resolvable_fromhost', 'ip');
$self->adjust_karma( -1 );
return 1;
};
@ -150,8 +157,9 @@ sub check_dns {
$res->udp_timeout(30);
my $has_mx = $self->get_and_validate_mx( $res, $host, $transaction );
return 1 if $has_mx == 1; # success!
return 1 if $has_mx == 1; # success, has MX!
return if $has_mx == -1; # has invalid MX records
# at this point, no MX for fh is resolvable
my @host_answers = $self->get_host_records( $res, $host, $transaction );
foreach my $rr (@host_answers) {
@ -189,6 +197,7 @@ sub get_and_validate_mx {
my @mx = mx($res, $host);
if ( ! scalar @mx ) { # no mx records
$self->adjust_karma( -1 );
$self->log(LOGINFO, "$host has no MX");
return 0;
};
@ -203,8 +212,9 @@ sub get_and_validate_mx {
}
# if there are MX records, and we got here, none are valid
$self->log(LOGINFO, "fail, invalid MX for $host");
#$self->log(LOGINFO, "fail, invalid MX for $host");
$transaction->notes('resolvable_fromhost', "invalid MX for $host");
$self->adjust_karma( -1 );
return -1;
};