Changeset 721 for trunk


Ignore:
Timestamp:
05/17/16 17:37:32 (8 years ago)
Author:
Kris Deugau
Message:

/trunk

Require a location (even an explicitly empty one) from the RPC caller

in delZone, getRecList, and getRecCount so we can support callers
providing the zone name instead of the zone ID.

Require a location (even an explicitly empty one) in all RPC subs that

expect CIDR arguments so we can find the correct record in the correct
zone.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dns-rpc.cgi

    r717 r721  
    246246    ($code,$msg) = $dnsdb->delZone($args{zone}, $args{revrec});
    247247  } else {
     248    die "Need zone location\n" if !defined($args{location});
    248249    my $zoneid;
    249     $zoneid = $dnsdb->domainID($args{zone}) if $args{revrec} eq 'n';
    250     $zoneid = $dnsdb->revID($args{zone}) if $args{revrec} eq 'y';
     250    $zoneid = $dnsdb->domainID($args{zone}, $args{location}) if $args{revrec} eq 'n';
     251    $zoneid = $dnsdb->revID($args{zone}, $args{location}) if $args{revrec} eq 'y';
    251252    die "Can't find zone: ".$dnsdb->errstr."\n" if !$zoneid;
    252253    ($code,$msg) = $dnsdb->delZone($zoneid, $args{revrec});
     
    264265  _commoncheck(\%args, 'y');
    265266
    266   my $domid = $dnsdb->domainID($args{domain});
     267  my $domid = $dnsdb->domainID($args{domain}, $args{location});
    267268  die $dnsdb->errstr."\n" if !$domid;
    268269  return $domid;
     
    450451  die "Missing zone ID\n" if !$args{id};
    451452
     453  # caller may not know about zone IDs.  accept the zone name, but require a location if so
     454  if ($args{id} !~ /^\d+$/) {
     455    die "Location required to use the zone name\n" if !defined($args{location});
     456  }
     457
    452458  # set some optional args
    453459  $args{offset} = 0 if !$args{offset};
     
    461467  if ($args{defrec} eq 'n') {
    462468    if ($args{revrec} eq 'n') {
    463       $args{id} = $dnsdb->domainID($args{id}) if $args{id} !~ /^\d+$/;
     469      $args{id} = $dnsdb->domainID($args{id}, $args{location}) if $args{id} !~ /^\d+$/;
    464470    } else {
    465       $args{id} = $dnsdb->revID($args{id}) if $args{id} !~ /^\d+$/
     471      $args{id} = $dnsdb->revID($args{id}, $args{location}) if $args{id} !~ /^\d+$/
    466472    }
    467473  }
     
    485491
    486492  _reccheck(\%args);
     493
     494  # caller may not know about zone IDs.  accept the zone name, but require a location if so
     495  if ($args{id} !~ /^\d+$/) {
     496    die "Location required to use the zone name\n" if !defined($args{location});
     497  }
    487498
    488499  # set some optional args
     
    493504  $args{direction} = 'ASC' if !$args{direction};
    494505
     506  # convert zone name to zone ID, if needed
     507  if ($args{defrec} eq 'n') {
     508    if ($args{revrec} eq 'n') {
     509      $args{id} = $dnsdb->domainID($args{id}, $args{location}) if $args{id} !~ /^\d+$/;
     510    } else {
     511      $args{id} = $dnsdb->revID($args{id}, $args{location}) if $args{id} !~ /^\d+$/
     512    }
     513  }
     514
     515  # fail if we *still* don't have a valid zone ID
     516  die $dnsdb->errstr."\n" if !$args{id};
     517
    495518  my $ret = $dnsdb->getRecCount(defrec => $args{defrec}, revrec => $args{revrec},
    496519        id => $args{id}, filter => $args{filter});
     
    499522
    500523  return $ret;
    501 }
     524} # getRecCount()
    502525
    503526# The core sub uses references for some arguments to allow limited modification for
     
    572595  _commoncheck(\%args, 'y');
    573596  my $cidr = new NetAddr::IP $args{cidr};
     597
     598  # Location required so we don't turn up unrelated zones in getZonesByCIDR().
     599  # Caller should generally have some knowledge of this.
     600  die "Need location\n" if !defined($args{location});
    574601
    575602  my $zonelist = $dnsdb->getZonesByCIDR(%args);
     
    696723  my $cidr = new NetAddr::IP $args{cidr};
    697724
     725  # Location required so we don't turn up unrelated zones in getZonesByCIDR().
     726  # Caller should generally have some knowledge of this.
     727  die "Need location\n" if !defined($args{location});
     728
    698729  my $zonelist = $dnsdb->getZonesByCIDR(%args);
    699730
     
    764795
    765796  my $up_res;
     797
     798  # Location required so we don't turn up unrelated zones in getZonesByCIDR().
     799  # Caller should generally have some knowledge of this.
     800  die "Need location\n" if !defined($args{location});
    766801
    767802  my $zonelist = $dnsdb->getZonesByCIDR(%args);
     
    827862  my @retlist;
    828863
    829   my $zsth = $dnsdb->{dbh}->prepare("SELECT rdns_id,group_id FROM revzones WHERE revnet >>= ?");
     864  # Location required so we don't turn up unrelated zones
     865  die "Need location\n" if !defined($args{location});
     866
     867  my $zsth = $dnsdb->{dbh}->prepare("SELECT rdns_id,group_id FROM revzones WHERE revnet >>= ? AND location = ?");
    830868  # Going to assume template records with no expiry
    831869  # Also note IPv6 template records don't expand sanely the way v4 records do
     
    850888  eval {
    851889    foreach my $template (@{$args{templates}}) {
    852       $zsth->execute($template);
     890      $zsth->execute($template, $args{location});
    853891      my ($zid,$zgrp) = $zsth->fetchrow_array;
    854892      if (!$zid) {
     
    909947  # Caller may pass 'n' in delsubs.  Assume it should be false/undefined
    910948  # unless the caller explicitly requested 'yes'
    911   $args{delsubs} = 0 if $args{delsubs} ne 'y';
     949  $args{delsubs} = 0 if !$args{delsubs} || $args{delsubs} ne 'y';
    912950
    913951  # Don't delete the A component of an A+PTR by default
    914952  $args{delforward} = 0 if !$args{delforward};
    915953
    916   # make sure this is set if not passed
    917   $args{location} = '' if !$args{location};
     954  # Location required so we don't turn up unrelated zones in getZonesByCIDR().
     955  die "Need location\n" if !defined($args{location});
    918956
    919957  # much like addOrUpdateRevRec()
Note: See TracChangeset for help on using the changeset viewer.