View | Details | Raw Unified | Return to bug 7231
Collapse All | Expand All

(-)lib/Mail/SpamAssassin/Dns.pm (-9 / +18 lines)
Lines 171-177 Link Here
171
  if (substr($rule, 0, 2) eq "__") {
171
  if (substr($rule, 0, 2) eq "__") {
172
    # don't bother with meta rules
172
    # don't bother with meta rules
173
  } elsif ($answer->type eq 'TXT') {
173
  } elsif ($answer->type eq 'TXT') {
174
    # txtdata returns a non- zone-file-format encoded result, unlike rdatastr;
174
    # txtdata returns a non- zone-file-format encoded result, unlike rdstring;
175
    # avoid space-separated RDATA <character-string> fields if possible,
175
    # avoid space-separated RDATA <character-string> fields if possible,
176
    # txtdata provides a list of strings in a list context since Net::DNS 0.69
176
    # txtdata provides a list of strings in a list context since Net::DNS 0.69
177
    $log = join('',$answer->txtdata);
177
    $log = join('',$answer->txtdata);
Lines 215-226 Link Here
215
215
216
  my $qname = $question->qname;
216
  my $qname = $question->qname;
217
217
218
  # txtdata returns a non- zone-file-format encoded result, unlike rdatastr;
218
  # txtdata returns a non- zone-file-format encoded result, unlike rdstring;
219
  # avoid space-separated RDATA <character-string> fields if possible,
219
  # avoid space-separated RDATA <character-string> fields if possible,
220
  # txtdata provides a list of strings in a list context since Net::DNS 0.69
220
  # txtdata provides a list of strings in a list context since Net::DNS 0.69
221
  #
221
  #
222
  my $rdatastr = $answer->UNIVERSAL::can('txtdata') ? join('',$answer->txtdata)
222
  # rdatastr() is historical/undocumented, use rdstring() since Net::DNS 0.69
223
                                                    : $answer->rdatastr;
223
  my $rdatastr = $answer->UNIVERSAL::can('txtdata')  ? join('',$answer->txtdata)
224
               : $answer->UNIVERSAL::can('rdstring') ? $answer->rdstring
225
                                                     : $answer->rdatastr;
224
  if (defined $qname && defined $rdatastr) {
226
  if (defined $qname && defined $rdatastr) {
225
    my $qclass = $question->qclass;
227
    my $qclass = $question->qclass;
226
    my $qtype = $question->qtype;
228
    my $qtype = $question->qtype;
Lines 267-274 Link Here
267
    my $answ_type = $answer->type;
269
    my $answ_type = $answer->type;
268
    # TODO: there are some CNAME returns that might be useful
270
    # TODO: there are some CNAME returns that might be useful
269
    next if ($answ_type ne 'A' && $answ_type ne 'TXT');
271
    next if ($answ_type ne 'A' && $answ_type ne 'TXT');
270
    # skip any A record that isn't on 127/8
272
    if ($answ_type eq 'A') {
271
    next if ($answ_type eq 'A' && $answer->rdatastr !~ /^127\./);
273
      # Net::DNS::RR::A::address() is available since Net::DNS 0.69
274
      my $ip_address = $answer->UNIVERSAL::can('address') ? $answer->address
275
                                                          : $answer->rdatastr;
276
      # skip any A record that isn't on 127.0.0.0/8
277
      next if $ip_address !~ /^127\./;
278
    }
272
    for my $rule (@{$rules}) {
279
    for my $rule (@{$rules}) {
273
      $self->dnsbl_hit($rule, $question, $answer);
280
      $self->dnsbl_hit($rule, $question, $answer);
274
    }
281
    }
Lines 284-295 Link Here
284
sub process_dnsbl_set {
291
sub process_dnsbl_set {
285
  my ($self, $set, $question, $answer) = @_;
292
  my ($self, $set, $question, $answer) = @_;
286
293
287
  # txtdata returns a non- zone-file-format encoded result, unlike rdatastr;
294
  # txtdata returns a non- zone-file-format encoded result, unlike rdstring;
288
  # avoid space-separated RDATA <character-string> fields if possible,
295
  # avoid space-separated RDATA <character-string> fields if possible,
289
  # txtdata provides a list of strings in a list context since Net::DNS 0.69
296
  # txtdata provides a list of strings in a list context since Net::DNS 0.69
290
  #
297
  #
291
  my $rdatastr = $answer->UNIVERSAL::can('txtdata') ? join('',$answer->txtdata)
298
  # rdatastr() is historical/undocumented, use rdstring() since Net::DNS 0.69
292
                                                    : $answer->rdatastr;
299
  my $rdatastr = $answer->UNIVERSAL::can('txtdata')  ? join('',$answer->txtdata)
300
               : $answer->UNIVERSAL::can('rdstring') ? $answer->rdstring
301
                                                     : $answer->rdatastr;
293
302
294
  while (my ($subtest, $rule) = each %{ $self->{dnspost}->{$set} }) {
303
  while (my ($subtest, $rule) = each %{ $self->{dnspost}->{$set} }) {
295
    next if $self->{tests_already_hit}->{$rule};
304
    next if $self->{tests_already_hit}->{$rule};
(-)lib/Mail/SpamAssassin/Plugin/AskDNS.pm (-8 / +13 lines)
Lines 539-545 Link Here
539
    @answer = ( undef );
539
    @answer = ( undef );
540
  }
540
  }
541
541
542
  # NOTE:  $rr->rdatastr returns the result encoded in a DNS zone file
542
  # NOTE:  $rr->rdstring returns the result encoded in a DNS zone file
543
  # format, i.e. enclosed in double quotes if a result contains whitespace
543
  # format, i.e. enclosed in double quotes if a result contains whitespace
544
  # (or other funny characters), and may use \DDD encoding or \X quoting as
544
  # (or other funny characters), and may use \DDD encoding or \X quoting as
545
  # per RFC 1035.  Using $rr->txtdata instead avoids this unnecessary encoding
545
  # per RFC 1035.  Using $rr->txtdata instead avoids this unnecessary encoding
Lines 566-573 Link Here
566
      # special case, no answer records, only rcode can be tested
566
      # special case, no answer records, only rcode can be tested
567
    } else {
567
    } else {
568
      $rr_type = uc $rr->type;
568
      $rr_type = uc $rr->type;
569
      if ($rr->UNIVERSAL::can('txtdata')) {  # TXT, SPF
569
      if ($rr_type eq 'A') {
570
        # join with no intervening spaces, as per RFC 5518
570
        # Net::DNS::RR::A::address() is available since Net::DNS 0.69
571
        $rr_rdatastr = $rr->UNIVERSAL::can('address') ? $rr->address
572
                                                      : $rr->rdatastr;
573
        if ($rr_rdatastr =~ m/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/) {
574
          $rdatanum = Mail::SpamAssassin::Util::my_inet_aton($rr_rdatastr);
575
        }
576
      } elsif ($rr->UNIVERSAL::can('txtdata')) {
577
        # TXT, SPF: join with no intervening spaces, as per RFC 5518
571
        if ($txtdata_can_provide_a_list || $rr_type ne 'TXT') {
578
        if ($txtdata_can_provide_a_list || $rr_type ne 'TXT') {
572
          $rr_rdatastr = join('', $rr->txtdata);  # txtdata() in list context!
579
          $rr_rdatastr = join('', $rr->txtdata);  # txtdata() in list context!
573
        } else {  # char_str_list() is only available for TXT records
580
        } else {  # char_str_list() is only available for TXT records
Lines 574-584 Link Here
574
          $rr_rdatastr = join('', $rr->char_str_list);  # historical
581
          $rr_rdatastr = join('', $rr->char_str_list);  # historical
575
        }
582
        }
576
      } else {
583
      } else {
577
        $rr_rdatastr = $rr->rdatastr;
584
        # rdatastr() is historical, use rdstring() since Net::DNS 0.69
578
        if ($rr_type eq 'A' &&
585
        $rr_rdatastr = $rr->UNIVERSAL::can('rdstring') ? $rr->rdstring
579
            $rr_rdatastr =~ m/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/) {
586
                                                       : $rr->rdatastr;
580
          $rdatanum = Mail::SpamAssassin::Util::my_inet_aton($rr_rdatastr);
581
        }
582
      }
587
      }
583
    # dbg("askdns: received rr type %s, data: %s", $rr_type, $rr_rdatastr);
588
    # dbg("askdns: received rr type %s, data: %s", $rr_type, $rr_rdatastr);
584
    }
589
    }
(-)lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm (-9 / +13 lines)
Lines 942-950 Link Here
942
    next unless (defined($str) && defined($dom));
942
    next unless (defined($str) && defined($dom));
943
    dbg("uridnsbl: got($j) NS for $dom: $str");
943
    dbg("uridnsbl: got($j) NS for $dom: $str");
944
944
945
    if ($str =~ /IN\s+NS\s+(\S+)/) {
945
    if ($rr->type eq 'NS') {
946
      my $nsmatch = lc $1;
946
      my $nsmatch = lc $rr->nsdname;  # available since at least Net::DNS 0.14
947
      $nsmatch =~ s/\.$//;
948
      my $nsrhblstr = $nsmatch;
947
      my $nsrhblstr = $nsmatch;
949
      my $fullnsrhblstr = $nsmatch;
948
      my $fullnsrhblstr = $nsmatch;
950
949
Lines 1025-1033 Link Here
1025
    }
1024
    }
1026
    dbg("uridnsbl: complete_a_lookup got(%d) A for %s: %s", $j,$hname,$str);
1025
    dbg("uridnsbl: complete_a_lookup got(%d) A for %s: %s", $j,$hname,$str);
1027
1026
1028
    local $1;
1027
    if ($rr->type eq 'A') {
1029
    if ($str =~ /IN\s+A\s+(\S+)/) {
1028
      # Net::DNS::RR::A::address() is available since Net::DNS 0.69
1030
      $self->lookup_dnsbl_for_ip($pms, $ent->{obj}, $1);
1029
      my $ip_address = $rr->UNIVERSAL::can('address') ? $rr->address
1030
                                                      : $rr->rdatastr;
1031
      $self->lookup_dnsbl_for_ip($pms, $ent->{obj}, $ip_address);
1031
    }
1032
    }
1032
  }
1033
  }
1033
}
1034
}
Lines 1038-1044 Link Here
1038
  my ($self, $pms, $obj, $ip) = @_;
1039
  my ($self, $pms, $obj, $ip) = @_;
1039
1040
1040
  local($1,$2,$3,$4);
1041
  local($1,$2,$3,$4);
1041
  $ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
1042
  $ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/
1043
    or warn "lookup_dnsbl_for_ip: not an IPv4 address: $ip\n";
1042
  my $revip = "$4.$3.$2.$1";
1044
  my $revip = "$4.$3.$2.$1";
1043
1045
1044
  my $conf = $pms->{conf};
1046
  my $conf = $pms->{conf};
Lines 1100-1111 Link Here
1100
    my $rr_type = $rr->type;
1102
    my $rr_type = $rr->type;
1101
1103
1102
    if ($rr_type eq 'A') {
1104
    if ($rr_type eq 'A') {
1103
      $rdatastr = $rr->rdatastr;
1105
      # Net::DNS::RR::A::address() is available since Net::DNS 0.69
1106
      $rdatastr = $rr->UNIVERSAL::can('address') ? $rr->address
1107
                                                 : $rr->rdatastr;
1104
      if ($rdatastr =~ m/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
1108
      if ($rdatastr =~ m/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
1105
        $rdatanum = Mail::SpamAssassin::Util::my_inet_aton($rdatastr);
1109
        $rdatanum = Mail::SpamAssassin::Util::my_inet_aton($rdatastr);
1106
      }
1110
      }
1107
    } elsif ($rr_type eq 'TXT') {
1111
    } elsif ($rr_type eq 'TXT') {
1108
      # txtdata returns a non- zone-file-format encoded result, unlike rdatastr;
1112
      # txtdata returns a non- zone-file-format encoded result, unlike rdstring;
1109
      # avoid space-separated RDATA <character-string> fields if possible;
1113
      # avoid space-separated RDATA <character-string> fields if possible;
1110
      # txtdata provides a list of strings in list context since Net::DNS 0.69
1114
      # txtdata provides a list of strings in list context since Net::DNS 0.69
1111
      $rdatastr = join('',$rr->txtdata);
1115
      $rdatastr = join('',$rr->txtdata);

Return to bug 7231