Index: trunk/dns-rpc.cgi
===================================================================
--- trunk/dns-rpc.cgi	(revision 717)
+++ trunk/dns-rpc.cgi	(revision 721)
@@ -246,7 +246,8 @@
     ($code,$msg) = $dnsdb->delZone($args{zone}, $args{revrec});
   } else {
+    die "Need zone location\n" if !defined($args{location});
     my $zoneid;
-    $zoneid = $dnsdb->domainID($args{zone}) if $args{revrec} eq 'n';
-    $zoneid = $dnsdb->revID($args{zone}) if $args{revrec} eq 'y';
+    $zoneid = $dnsdb->domainID($args{zone}, $args{location}) if $args{revrec} eq 'n';
+    $zoneid = $dnsdb->revID($args{zone}, $args{location}) if $args{revrec} eq 'y';
     die "Can't find zone: ".$dnsdb->errstr."\n" if !$zoneid;
     ($code,$msg) = $dnsdb->delZone($zoneid, $args{revrec});
@@ -264,5 +265,5 @@
   _commoncheck(\%args, 'y');
 
-  my $domid = $dnsdb->domainID($args{domain});
+  my $domid = $dnsdb->domainID($args{domain}, $args{location});
   die $dnsdb->errstr."\n" if !$domid;
   return $domid;
@@ -450,4 +451,9 @@
   die "Missing zone ID\n" if !$args{id};
 
+  # caller may not know about zone IDs.  accept the zone name, but require a location if so
+  if ($args{id} !~ /^\d+$/) {
+    die "Location required to use the zone name\n" if !defined($args{location});
+  }
+
   # set some optional args
   $args{offset} = 0 if !$args{offset};
@@ -461,7 +467,7 @@
   if ($args{defrec} eq 'n') {
     if ($args{revrec} eq 'n') {
-      $args{id} = $dnsdb->domainID($args{id}) if $args{id} !~ /^\d+$/;
+      $args{id} = $dnsdb->domainID($args{id}, $args{location}) if $args{id} !~ /^\d+$/;
     } else {
-      $args{id} = $dnsdb->revID($args{id}) if $args{id} !~ /^\d+$/
+      $args{id} = $dnsdb->revID($args{id}, $args{location}) if $args{id} !~ /^\d+$/
     }
   }
@@ -485,4 +491,9 @@
 
   _reccheck(\%args);
+
+  # caller may not know about zone IDs.  accept the zone name, but require a location if so
+  if ($args{id} !~ /^\d+$/) {
+    die "Location required to use the zone name\n" if !defined($args{location});
+  }
 
   # set some optional args
@@ -493,4 +504,16 @@
   $args{direction} = 'ASC' if !$args{direction};
 
+  # convert zone name to zone ID, if needed
+  if ($args{defrec} eq 'n') {
+    if ($args{revrec} eq 'n') {
+      $args{id} = $dnsdb->domainID($args{id}, $args{location}) if $args{id} !~ /^\d+$/;
+    } else {
+      $args{id} = $dnsdb->revID($args{id}, $args{location}) if $args{id} !~ /^\d+$/
+    }
+  }
+
+  # fail if we *still* don't have a valid zone ID
+  die $dnsdb->errstr."\n" if !$args{id};
+
   my $ret = $dnsdb->getRecCount(defrec => $args{defrec}, revrec => $args{revrec},
 	id => $args{id}, filter => $args{filter});
@@ -499,5 +522,5 @@
 
   return $ret;
-}
+} # getRecCount()
 
 # The core sub uses references for some arguments to allow limited modification for
@@ -572,4 +595,8 @@
   _commoncheck(\%args, 'y');
   my $cidr = new NetAddr::IP $args{cidr};
+
+  # Location required so we don't turn up unrelated zones in getZonesByCIDR().
+  # Caller should generally have some knowledge of this.
+  die "Need location\n" if !defined($args{location});
 
   my $zonelist = $dnsdb->getZonesByCIDR(%args);
@@ -696,4 +723,8 @@
   my $cidr = new NetAddr::IP $args{cidr};
 
+  # Location required so we don't turn up unrelated zones in getZonesByCIDR().
+  # Caller should generally have some knowledge of this.
+  die "Need location\n" if !defined($args{location});
+
   my $zonelist = $dnsdb->getZonesByCIDR(%args);
 
@@ -764,4 +795,8 @@
 
   my $up_res;
+
+  # Location required so we don't turn up unrelated zones in getZonesByCIDR().
+  # Caller should generally have some knowledge of this.
+  die "Need location\n" if !defined($args{location});
 
   my $zonelist = $dnsdb->getZonesByCIDR(%args);
@@ -827,5 +862,8 @@
   my @retlist;
 
-  my $zsth = $dnsdb->{dbh}->prepare("SELECT rdns_id,group_id FROM revzones WHERE revnet >>= ?");
+  # Location required so we don't turn up unrelated zones
+  die "Need location\n" if !defined($args{location});
+
+  my $zsth = $dnsdb->{dbh}->prepare("SELECT rdns_id,group_id FROM revzones WHERE revnet >>= ? AND location = ?");
   # Going to assume template records with no expiry
   # Also note IPv6 template records don't expand sanely the way v4 records do
@@ -850,5 +888,5 @@
   eval {
     foreach my $template (@{$args{templates}}) {
-      $zsth->execute($template);
+      $zsth->execute($template, $args{location});
       my ($zid,$zgrp) = $zsth->fetchrow_array;
       if (!$zid) {
@@ -909,11 +947,11 @@
   # Caller may pass 'n' in delsubs.  Assume it should be false/undefined
   # unless the caller explicitly requested 'yes'
-  $args{delsubs} = 0 if $args{delsubs} ne 'y';
+  $args{delsubs} = 0 if !$args{delsubs} || $args{delsubs} ne 'y';
 
   # Don't delete the A component of an A+PTR by default
   $args{delforward} = 0 if !$args{delforward};
 
-  # make sure this is set if not passed
-  $args{location} = '' if !$args{location};
+  # Location required so we don't turn up unrelated zones in getZonesByCIDR().
+  die "Need location\n" if !defined($args{location});
 
   # much like addOrUpdateRevRec()
