- Timestamp:
- 11/24/20 17:22:33 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bind-import
r811 r812 62 62 63 63 # need to spin up a full state machine-ish thing, because BIND zone files are all about context 64 # see ch4, p56-72 in the grasshopper book 65 my $prevlabel = ''; 66 my $curlabel = ''; 67 64 68 while (<>) { 65 69 chomp; 66 70 next if /^\s*$/; 67 71 next if /^\s*;/; 68 if (my ($macro,$mdetail) = (/^\s*\$(TTL|ORIGIN|INCLUDE )\s+(.+)/) ) {72 if (my ($macro,$mdetail) = (/^\s*\$(TTL|ORIGIN|INCLUDE|GENERATE)\s+(.+)/) ) { 69 73 # macro sort of thing; $TTL and $ORIGIN most common. $INCLUDE is a thing, expect it to be rare in live use tho 70 74 if ($macro eq 'TTL') { … … 89 93 } 90 94 } 95 # not handling $INCLUDE or $GENERATE (altho the latter seems to be mostly a less-flexible version of the template types) 91 96 next; 92 97 } … … 94 99 next if /^ip-192-168-1(12|20)-\d+/; 95 100 next if /ip.add.re.\d+\s*$/; 96 my ($name) = /([\w_.-]+)\s/; 101 # records must begin in the first column, no leading whitespace 102 my ($name) = /^([\w\@_.-]+)\s/; 97 103 # append zone name to record name if missing AND not dot-terminated; 98 104 # this happens automagically for forward zones, but not reverse because Reasons. (fixme?) … … 102 108 $name = $zname if /^\s*IN/; 103 109 $name = $zname if /^\@/; 104 s/([\w\@_.-]+)\s+//; 105 my ($class) = /(IN|CS|CH|HS)\s/; 106 if ($class) { 107 if ($class ne 'IN') { 108 print "Non-Internet class records not supported, you weirdo\n"; 109 next; 110 } 111 s/(IN|CS|CH|HS)\s+//; 112 } else { 113 $class = 'IN' if !$class; 114 } 115 my ($ttl) = /(\d+)?\s/; 110 s/^([\w\@_.-]+)\s+//; 111 # by convention the optional TTL leads the optional class, but they're apparently swappable. 112 my ($ttl) = /^(\d+)?\s/; 116 113 if (defined $ttl) { 117 114 # TTL may be zero … … 121 118 $ttl = $zonettl; 122 119 } 120 my ($class) = /^(IN|CS|CH|HS|\d+)\s/; 121 if (defined $class) { 122 if ($class =~ /\d+/) { 123 124 } 125 if ($class ne 'IN') { 126 print "Non-Internet class records not supported, you weirdo\n"; 127 next; 128 } 129 s/(IN|CS|CH|HS)\s+//; 130 } else { 131 $class = 'IN'; 132 } 123 133 my ($type) = /([A-Z-]+)\s/; 124 134 if (!$reverse_typemap{$type}) { … … 130 140 chomp; 131 141 my $rdata = $_; 142 143 # SOA is the only type that may span multiple lines. Probably. Note even AXFRed zones write multiline SOA records: 144 #@ IN SOA test.example.invalid. test.example.invalid. (2020082500 7200 900 604800 3600) 145 # IN NS olddns.example.com. 146 # IN MX 1 fred.foo.bar.invalid. 147 #foo IN A 192.168.16.45 148 # AXFR'ed zone file gets written as 149 #$ORIGIN . 150 #$TTL 3600 ; 1 hour 151 #example.invalid IN SOA test.example.invalid. test.example.invalid. ( 152 # 2020082500 ; serial 153 # 7200 ; refresh (2 hours) 154 # 900 ; retry (15 minutes) 155 # 604800 ; expire (1 week) 156 # 3600 ; minimum (1 hour) 157 # ) 158 # NS olddns.example.com. 159 # MX 1 fred.foo.bar.invalid. 160 #$ORIGIN example.invalid. 161 #foo A 192.168.16.45 162 163 if ($type eq 'SOA') { 164 165 } 132 166 133 167 # Quotes may arguably be syntactically required, but they're not actually part of the record data
Note:
See TracChangeset
for help on using the changeset viewer.