helo: improved invalid_localhost detection
This commit is contained in:
parent
91f8133f5c
commit
04a984bbab
@ -339,11 +339,14 @@ sub is_regex_match {
|
|||||||
|
|
||||||
sub invalid_localhost {
|
sub invalid_localhost {
|
||||||
my ($self, $host) = @_;
|
my ($self, $host) = @_;
|
||||||
return if lc $host ne 'localhost';
|
|
||||||
if (Qpsmtpd::Utils->is_localhost($self->qp->connection->remote_ip)) {
|
if (Qpsmtpd::Utils->is_localhost($self->qp->connection->remote_ip)) {
|
||||||
$self->log(LOGDEBUG, "pass, is localhost");
|
$self->log(LOGDEBUG, "pass, is localhost");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if ($host && lc $host eq 'localhost') {
|
||||||
|
$self->log(LOGDEBUG, "pass, host is localhost");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
#$self->log( LOGINFO, "fail, not localhost" );
|
#$self->log( LOGINFO, "fail, not localhost" );
|
||||||
return ("You are not localhost", "invalid localhost");
|
return ("You are not localhost", "invalid localhost");
|
||||||
|
@ -11,7 +11,7 @@ sub register_tests {
|
|||||||
$self->register_test('test_init_resolver', 2);
|
$self->register_test('test_init_resolver', 2);
|
||||||
$self->register_test('test_is_in_badhelo', 2);
|
$self->register_test('test_is_in_badhelo', 2);
|
||||||
$self->register_test('test_is_regex_match', 3);
|
$self->register_test('test_is_regex_match', 3);
|
||||||
$self->register_test('test_invalid_localhost', 5);
|
$self->register_test('test_invalid_localhost', 8);
|
||||||
$self->register_test('test_is_plain_ip', 3);
|
$self->register_test('test_is_plain_ip', 3);
|
||||||
$self->register_test('test_is_address_literal', 3);
|
$self->register_test('test_is_address_literal', 3);
|
||||||
$self->register_test('test_no_forward_dns', 2);
|
$self->register_test('test_no_forward_dns', 2);
|
||||||
@ -61,21 +61,20 @@ sub test_is_regex_match {
|
|||||||
sub test_invalid_localhost {
|
sub test_invalid_localhost {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
|
my ($err, $why);
|
||||||
|
foreach my $ip ( undef, '', '192.0.99.5' ) {
|
||||||
$self->qp->connection->remote_ip(undef);
|
$self->qp->connection->remote_ip(undef);
|
||||||
my ($err, $why) = $self->invalid_localhost('localhost' );
|
|
||||||
ok( $err, "localhost, undefined remote IP: $why");
|
|
||||||
|
|
||||||
$self->qp->connection->remote_ip('');
|
|
||||||
($err, $why) = $self->invalid_localhost('localhost' );
|
($err, $why) = $self->invalid_localhost('localhost' );
|
||||||
ok( $err, "localhost, empty remote IP: $why");
|
ok(!$err, "host: localhost, remote ip: $ip");
|
||||||
|
|
||||||
$self->qp->connection->remote_ip('192.0.99.5');
|
$self->qp->connection->remote_ip(undef);
|
||||||
($err, $why) = $self->invalid_localhost('localhost');
|
($err, $why) = $self->invalid_localhost('not-localhost');
|
||||||
ok( $err, "localhost, invalid remote IP: $why");
|
ok($err, "host: not-localhost, remote ip: $ip");
|
||||||
|
};
|
||||||
|
|
||||||
foreach my $ip (qw/ ::1 127.0.0.1 / ) {
|
foreach my $ip (qw/ ::1 127.0.0.1 / ) {
|
||||||
$self->qp->connection->remote_ip($ip);
|
$self->qp->connection->remote_ip($ip);
|
||||||
($err, $why) = $self->invalid_localhost('localhost');
|
($err, $why) = $self->invalid_localhost('not-localhost');
|
||||||
ok( ! $err, "localhost, correct remote IP ($ip)");
|
ok( ! $err, "localhost, correct remote IP ($ip)");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user