5 $etcfile= "/etc/named/zones-rgc";
10 while ($ARGV[0] =~ m/^\-/) {
14 if (s/^\-f/-/) { $usage=0; $check=0; $install++; }
15 elsif (s/^\-y/-/) { $usage=0; $check=1; $install++; }
16 elsif (s/^\-n/-/) { $usage=0; $check=1; $install=0; }
17 elsif (s/^\-h/-/) { $hostdelg=1; $hostzone=0; }
18 elsif (s/^\-z/-/) { $hostdelg=1; $hostzone=1; }
19 elsif (s/^\-q/-/) { $progress=0; }
20 else { $usage=1; break; }
25 "usage: named-conf-regen -f|-y|-n [-h|-z]\n".
27 " -f install without checking -ff and then ndc reload\n".
28 " -y check and install -yy and then ndc reload\n".
30 "additional options:\n".
31 " -h check output from host -C\n".
32 " -z check output from host -C and host -val\n".
35 beginfile('secondary.zones');
36 open E, "< $etcfile" or die "$0: open $etcfile: $!\n";
38 $!=0; defined $_=<E> or die "$0: read $etcfile $!\n";
39 s/^\s+//; chomp; s/\s+$//;
42 if (m/^myname\s+(\S.*\S)/) {
43 @mynames= split /\s+/, $1;
44 } elsif (m/^(secondary|backup|unoff)\s+(\S+)\s+([0-9. \t]+)$/) {
47 @servers= split /\s+/, $3;
52 die "$0: $etcfile:$.: syntax error in \`$_'\n";
57 my ($type,$domain) = @_;
59 defined($c=open ADH, "-|") or die "$0: fork adnshost: $!\n";
61 exec 'adnshost','+Do','+Dt','+Dc','-Cf',"-t$type",
63 die "$0: exec adnshost: $!\n";
68 die "$0: lookup -t$type $domain failed $? $!\n" if $? or $!;
73 my ($type,$domain) = @_;
74 my (@result)= lookup($type,$domain);
75 @result==1 or die "$0: lookup -t$type $domain gave more than one RR\n";
82 $soa= lookup1('soa',$zone);
83 $soa_origin=$soa; $soa_origin =~ s/ .*//;
84 $soa_origin_addr= lookup1('a',$soa_origin);
86 @zone_ns= lookup('ns-',$zone);
88 @ok_sources= ($soa_origin_addr);
89 $ok_sources_descr= "SOA ORIGIN $soa_origin [$soa_origin_addr]";
91 if ($style eq 'unoff' || $style eq 'backup') {
92 for $zone_ns (@zone_ns) {
93 @zone_ns_addrs= lookup('a',$zone_ns);
94 push @ok_sources, @zone_ns_addrs;
95 $ok_sources_descr.= ", NS $zone_ns [@zone_ns_addrs]";
99 for $server (@servers) {
100 grep { $server eq $_ } @ok_sources
101 or warn "secondarying from $server which is not ".
102 "$ok_sources_desc\n";
105 if ($style eq 'secondary') {
106 grep { $zone_ns=$_, grep { $myname eq $_ } @mynames } @zone_n
107 or warn "supposedly published secondary but we ".
108 "(@mynames) are not published ($@zone_ns)\n";
115 # $superzone= $zone; $superzone =~ s/^[^\.]+\.//;
116 # @super_ns= lookup('ns-',$zone);
121 for $super_ns (@super_ns) {
123 open DIG, "dig @$super_ns. -t ns +norecurse $zone."
124 or die "$0: fork for dig: $!\n";
134 warning "$myname unlisted NS $nsnames"
140 warning "$myname advertised NS $nsnames"
148 set -e; a="`host -t a \"$ns\".`"; set +e
149 taddrs="`echo \" $a\" | expand | sed -n '
151 s/^[^ ][^ ]* *A *\([0-9][.0-9]*\)/\1/p
153 equlines "A $ns" "$a" "$taddrs"
154 addrs="$addrs $taddrs"
164 for server in $servers
172 if [ "x$addr" = "x$server" ]
179 warning "server $server? but $rectype $names" $addrs
194 checkhostout -val localhost
200 chdir "$base/primary" or die "$0: chdir $base/primary: $!";
201 beginfile('primary.zones');
204 $zone= $f; $zone =~ s/_db$//;
209 zone="`echo $f | sed -e 's/_db$//'`"
223 $currentfile_opened= $install ? "$conf/$currentfile.new" : "/dev/null";
224 open CFF, "> $toopen" or die "$0: begin $currentfile_opened: $!\n";
228 close CFF or die "$0: close $currentfile_opened: $!\n";
229 push @files, $currentfile;
232 sub installfiles () {
233 return unless $install;
234 chdir $conf or die "$0: chdir $conf: $!\n";
236 rename "$f.new", $f or die "$0: install new $f: $!\n";
241 echo >&2 "$zone $style: $*"
242 warnings=$[$warnings+1]
246 if [ "x`echo \" $2\" | wc -l`" != "x`echo \" $3\" | wc -l`" ]
254 hostout="`host $1 \"$zone\" 2>&1 >/dev/null $2 | egrep -v \
255 '^ \!\!\! .* SOA primary .* is not advertised via NS$'`"
257 if [ "x$hostout" = x ]; then return; fi
260 warning "warnings from host:"
269 echo -n "$zone $style " >&2
276 if [ $warnings != 0 ]
278 echo >&2 "$warnings warnings "