hosts_allow: better logging

This commit is contained in:
Matt Simerson 2012-06-23 00:45:18 -04:00
parent efc3d1b914
commit 5dbc47ed1a

View File

@ -82,24 +82,34 @@ sub hook_pre_connection {
} }
} }
foreach ($self->qp->config("hosts_allow")) { my @r = $self->in_hosts_allow( $remote );
s/^\s*//; return @r if scalar @r;
$self->log( LOGDEBUG, "pass" );
return (DECLINED);
}
sub in_hosts_allow {
my $self = shift;
my $remote = shift;
foreach ( $self->qp->config('hosts_allow') ) {
s/^\s*//; # trim leading whitespace
my ($ipmask, $const, $message) = split /\s+/, $_, 3; my ($ipmask, $const, $message) = split /\s+/, $_, 3;
next unless defined $const; next unless defined $const;
my ($net,$mask) = split '/', $ipmask, 2; my ($net,$mask) = split '/', $ipmask, 2;
$mask = 32 if ! defined $mask; $mask = 32 if ! defined $mask;
$mask = pack "B32", "1"x($mask)."0"x(32-$mask); $mask = pack "B32", "1"x($mask)."0"x(32-$mask);
if (join(".", unpack("C4", inet_aton($remote) & $mask)) eq $net) { if (join('.', unpack('C4', inet_aton($remote) & $mask)) eq $net) {
$const = Qpsmtpd::Constants::return_code($const) || DECLINED; $const = Qpsmtpd::Constants::return_code($const) || DECLINED;
if ( $const =~ /deny/i ) { if ( $const =~ /deny/i ) {
$self->log( LOGINFO, "fail: $message" ); $self->log( LOGINFO, "fail, $message" );
}; };
$self->log( LOGDEBUG, "pass: $const, $message" ); $self->log( LOGDEBUG, "pass, $const, $message" );
return($const, $message); return($const, $message);
} }
} }
$self->log( LOGDEBUG, "pass" ); return;
return (DECLINED); };
}