add timeout so we won't wait forever... (is that what's making it lock up
on onion?) git-svn-id: https://svn.perl.org/qpsmtpd/trunk@71 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
parent
a2f455320e
commit
9916cfc038
@ -20,14 +20,14 @@ sub connect_handler {
|
||||
# results in the first rcpt handler ... oh well.
|
||||
|
||||
my $res = new Net::DNS::Resolver;
|
||||
my $sockets = [];
|
||||
my $sel = IO::Select->new();
|
||||
|
||||
for my $dnsbl (keys %dnsbl_zones) {
|
||||
$self->log(5, "Checking $reversed_ip.$dnsbl");
|
||||
push @{$sockets}, [$dnsbl, $res->bgsend("$reversed_ip.$dnsbl", "TXT")];
|
||||
$self->log(5, "Checking $reversed_ip.$dnsbl in the background");
|
||||
$sel->add($res->bgsend("$reversed_ip.$dnsbl", "TXT"));
|
||||
}
|
||||
|
||||
$self->qp->connection->notes('dnsbl_sockets', $sockets);
|
||||
$self->qp->connection->notes('dnsbl_sockets', $sel);
|
||||
|
||||
return DECLINED;
|
||||
}
|
||||
@ -41,19 +41,31 @@ sub process_sockets {
|
||||
if $conn->notes('dnsbl');
|
||||
|
||||
my $res = new Net::DNS::Resolver;
|
||||
my $sockets = $conn->notes('dnsbl_sockets') or return "";
|
||||
my $sel = $conn->notes('dnsbl_sockets') or return "";
|
||||
|
||||
my $result;
|
||||
|
||||
for my $socket (@{$sockets}) {
|
||||
my $query = $res->bgread($socket->[1]);
|
||||
my $dnsbl = $socket->[0];
|
||||
$self->log(6, "waiting for dnsbl dns");
|
||||
|
||||
# don't wait more than 5 seconds here
|
||||
my @ready = $sel->can_read(5);
|
||||
|
||||
$self->log(6, "DONE waiting for dnsbl dns");
|
||||
|
||||
for my $socket (@ready) {
|
||||
my $query = $res->bgread($socket);
|
||||
undef $socket;
|
||||
|
||||
my $dnsbl;
|
||||
|
||||
if ($query) {
|
||||
my $a_record = 0;
|
||||
foreach my $rr ($query->answer) {
|
||||
$a_record = 1 if $rr->type eq "A";
|
||||
my $name = $rr->name;
|
||||
($dnsbl) = ($name =~ m/(?:\d+\.){4}(.*)/) unless $dnsbl;
|
||||
$dnsbl = $name unless $dnsbl;
|
||||
$self->log(9, "name ", $rr->name);
|
||||
next unless $rr->type eq "TXT";
|
||||
$self->log(10, "got txt record");
|
||||
$result = $rr->txtdata and last;
|
||||
@ -64,10 +76,13 @@ sub process_sockets {
|
||||
$self->log(4, "$dnsbl query failed: ", $res->errorstring)
|
||||
unless $res->errorstring eq "NXDOMAIN";
|
||||
}
|
||||
|
||||
last if $result;
|
||||
|
||||
}
|
||||
|
||||
# if there were more to read; then forget about them again ...
|
||||
undef $_ for (@{$sockets});
|
||||
# if there was more to read; then forget it
|
||||
$conn->notes('dnsbl_sockets', undef);
|
||||
|
||||
return $conn->notes('dnsbl', $result);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user