Changeset 832


Ignore:
Timestamp:
03/30/22 14:48:23 (3 years ago)
Author:
Kris Deugau
Message:

/trunk

Replace the hack in r829 with a proper solution:

  • Have getRecList() and getRecCount() accept most of the Postgres CIDR operators in the filter argument
  • Have dns-rpc.cgi prefix the CIDR to remove with the <<= operator when calling getRecList()

This commit only applies the second part to the "delete everything"
branch of the RPC delByCIDR() sub with known failure cases.

See #77.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r831 r832  
    44614461  # Filtering on host/val (mainly normal record list)
    44624462  if ($args{filter}) {
    4463     $sql .= " AND (r.host ~* ? OR r.val ~* ? OR r.host ~* ? OR r.val ~* ?)";
    4464     my $tmp = join('.',reverse(split(/\./,$args{filter})));
    4465     push @bindvars, ($args{filter},$args{filter});
    4466     push @bindvars, ($tmp, $tmp);
     4463    # not much use to end users, but internal callers may want more fine-grained restriction on CIDR ranges
     4464    # we'll only support the value-comparison operators;  bitwise/add/subtract don't make much sense in this context
     4465    my $ipfilt = 0;
     4466    if ($args{filter} =~ /^\s*(<|<=|=|>=|>|<>|<<|<<=|>>|>>=)\s*([\da-fA-F].+)\s*$/) {
     4467      my $filt_op = $1;
     4468      my $filt_val = $2;
     4469      # do we have an IP-ish value?
     4470      if ($filt_val =~ m,^(?:[\d.]+|[0-9a-f]+)(?:/\d+)?$,) {
     4471        # now make sure
     4472        my $tmp = new NetAddr::IP $filt_val;
     4473        if ($tmp) {
     4474          $sql .= " AND inetlazy(r.val) $filt_op ?";
     4475          push @bindvars, $filt_val;
     4476          $ipfilt = 1;
     4477        } # really looks like a valid IP/CIDR
     4478      } # looks IPish
     4479    } # has CIDR operator
     4480    if (!$ipfilt) {
     4481      # simple text matching, with a bit of mix-n-match to account for .arpa names
     4482      $sql .= " AND (r.host ~* ? OR r.val ~* ? OR r.host ~* ? OR r.val ~* ?)";
     4483      my $tmp = join('.',reverse(split(/\./,$args{filter})));
     4484      push @bindvars, ($args{filter},$args{filter});
     4485      push @bindvars, ($tmp, $tmp);
     4486    }
    44674487  }
    44684488
     
    45384558  # Filtering on host/val (mainly normal record list)
    45394559  if ($args{filter}) {
    4540     $sql .= " AND (r.host ~* ? OR r.val ~* ? OR r.host ~* ? OR r.val ~* ?)";
    4541     my $tmp = join('.',reverse(split(/\./,$args{filter})));
    4542     push @bindvars, ($args{filter},$args{filter});
    4543     push @bindvars, ($tmp, $tmp);
     4560    # not much use to end users, but internal callers may want more fine-grained restriction on CIDR ranges
     4561    # we'll only support the value-comparison operators;  bitwise/add/subtract don't make much sense in this context
     4562    my $ipfilt = 0;
     4563    if ($args{filter} =~ /^\s*(<|<=|=|>=|>|<>|<<|<<=|>>|>>=)\s*([\da-fA-F].+)\s*$/) {
     4564      my $filt_op = $1;
     4565      my $filt_val = $2;
     4566      # do we have an IP-ish value?
     4567      if ($filt_val =~ m,^(?:[\d.]+|[0-9a-f]+)(?:/\d+)?$,) {
     4568        # now make sure
     4569        my $tmp = new NetAddr::IP $filt_val;
     4570        if ($tmp) {
     4571          $sql .= " AND inetlazy(r.val) $filt_op ?";
     4572          push @bindvars, $filt_val;
     4573          $ipfilt = 1;
     4574        } # really looks like a valid IP/CIDR
     4575      } # looks IPish
     4576    } # has CIDR operator
     4577    if (!$ipfilt) {
     4578      # simple text matching, with a bit of mix-n-match to account for .arpa names
     4579      $sql .= " AND (r.host ~* ? OR r.val ~* ? OR r.host ~* ? OR r.val ~* ?)";
     4580      my $tmp = join('.',reverse(split(/\./,$args{filter})));
     4581      push @bindvars, ($args{filter},$args{filter});
     4582      push @bindvars, ($tmp, $tmp);
     4583    }
    45444584  }
    45454585
  • trunk/dns-rpc.cgi

    r829 r832  
    16311631        # Delete ALL EVARYTHING!!one11!! in $args{cidr}
    16321632
    1633         # Use offset => 'all' to make sure we actually find all the records we need to remove,
    1634         # otherwise the record(s) that need to be deleted may be more than 75 records down the
    1635         # list and won't get caught.  We also do a crude filter based on the /24 of $args{cidr}
    1636         # to reduce the remote's cost for the operation - if the revzone is large, it'll iterate
    1637         # over a Very Large Number(TM) of records, just to delete a small handful.  Bad juju.
    1638         my $filt = $args{cidr};
    1639         $filt =~ s,\.\d+(?:/\d+)?$,,;
     1633        # Deleting a small $args{cidr} from a large reverse zone will sometimes
     1634        # silently fail by not finding the appropriate record(s).  Prepend a
     1635        # Postgres CIDR operator to assist in filtering
     1636        my $filt = "<<= $args{cidr}";
     1637
    16401638        my $reclist = $dnsdb->getRecList(rpc => 1, defrec => 'n', revrec => 'y', id => $zonelist->[0]->{rdns_id},
    16411639            filter => $filt, offset => 'all');
Note: See TracChangeset for help on using the changeset viewer.