chiark / gitweb /
Fix problems with primary-dir
[chiark-utils.git] / scripts / named-conf
index 0cad8021db6dba31e66c89ca3bede0c8777177ca..f6c518b4f7d3161f632a67cef5996783ccb63419 100755 (executable)
@@ -114,7 +114,8 @@ sub cfg_fail ($) { die "$quis: $where:\n $_[0]\n"; }
 
 sub read_config ($) {
     my ($if) = @_;
-    my ($fh,$z,@self,$before, $mod,$dir,$prefix,$suffix,$lprefix,$lsuffix);
+    my ($fh,$z,@self,$before,
+       $mod,$dir,$prefix,$suffix,$subfile,$lprefix,$lsuffix,$zf);
     local ($_);
 
     $fh= new IO::File $if,'r' or cfg_fail("open $if:\n $!");
@@ -139,10 +140,18 @@ sub read_config ($) {
            @self_soa= @self if $1 ne '-ns';
        } elsif (m/^self\-addr\s+([0-9. \t]+)/) {
            @self_addr= split /\s+/, $1;
-       } elsif (m/^primary\-dir([*?]?)\s+(\S+)((?:\s+(\S+))?:\s+(\S+))?$/) {
-           ($mod, $dir, $prefix, $suffix) = ($1,qualify($2),$3,$4);
-           $suffix= '_db' if !defined $suffix;
-           $prefix= '' if !defined $prefix;
+       } elsif (m,^
+                primary\-dir ([*?]?)
+                \s+ (\S+)/([^/ \t]*)
+                (?: \s+ ([^/ \t]*) (?: (/.+) )?
+                 )?
+                $,x) {
+           ($mod, $dir, $prefix, $suffix, $subfile) =
+               ($1,qualify($2),$3,$4,$5);
+           $suffix= '' if !defined $suffix;
+           $subfile= '' if !defined $subfile;
+           $suffix= '_db' if !length $suffix && !length $subfile;
+           if (-d "$dir/$prefix") { $dir.='/'; $dir.=$prefix; $prefix=''; }
            opendir D, $dir or cfg_fail("open primary-dir $dir:\n $!");
            $lprefix= length $prefix; $lsuffix= length $suffix;
            while (defined($_= readdir D)) {
@@ -151,7 +160,13 @@ sub read_config ($) {
                next unless substr($_,0,$lprefix) eq $prefix;
                next unless substr($_,length($_)-$lsuffix) eq $suffix;
                $z= substr($_,$lprefix,length($_)-($lprefix+$lsuffix));
-               zone_conf($z,'primary','p',$mod,"$dir/$_");
+               $zf= $dir.'/'.$prefix.$z.$suffix.$subfile;
+               if (!stat $zf) {
+                   next if length $subfile && $! == &ENOENT;
+                   cfg_fail("cannot stat zonefile $zf:\n $!");
+               }
+               -f _ or cfg_fail("zonefile $zf is not a plain file");
+               zone_conf($z,'primary','p',$mod,$zf);
            }
            closedir D or cfg_fail("close primary-dir $dir:\n $!");
        } elsif (m/^primary([*?]?)\s+(\S+)\s+(\S+)$/) {
@@ -160,7 +175,7 @@ sub read_config ($) {
            zone_conf($2,'published','s',$1,'',$3);
        } elsif (m/^stealth([*?]?)\s+(\S+)\s+([0-9. \t]+)$/) {
            zone_conf($2,'stealth','u',$1,'',split /\s+/, $3);
-       } elsif (m/^slave\-dir\s+(\S+)((?:\s+(\S+))?:\s+(\S+))?$/) {
+       } elsif (m/^slave\-dir\s+(\S+)(?:(?:\s+(\S+))\s+(\S+))?$/) {
            ($slave_dir, $slave_prefix, $slave_suffix) = (qualify($1),$2,$3);
        } elsif (m/^output\s+bind8\+(\S+)$/) {
            cfg_fail("default output may not apply to only some zones")
@@ -192,7 +207,10 @@ sub zone_conf ($$$$$@) {
            unless length $default_output;
        set_output($default_output);
     }
-    cfg_fail("redefined zone $zone") if exists $zone_cfg{$zone};
+    cfg_fail("redefined zone $zone\n".
+            " earlier definition $zone_cfg{$zone}{'where'}")
+       if exists $zone_cfg{$zone};
+    $zone_cfg{$zone}{'where'}= $where;
     $zone_cfg{$zone}{'file'}= $file;
     $zone_cfg{$zone}{'style_p'}= $style.$mod;
     $zone_cfg{$zone}{'s'}= $sabbr.$mod; # p)rimary s)econdary u)npub f)oreign
@@ -459,8 +477,8 @@ sub zone_servers_ok () {
        }
     }
     if ($cfg->{'s'} =~ m/s/ && !$delg_to_us) {
-       zone_warnmore("we are supposedly published secondary,".
-                     " but not listed as a nameserver");
+       zone_warning("we are supposedly published secondary,".
+                    " but not listed as a nameserver");
     }
 }