Changeset 812


Ignore:
Timestamp:
11/24/20 17:22:33 (4 years ago)
Author:
Kris Deugau
Message:

/trunk

Fifth sampled iteration of bind-import

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bind-import

    r811 r812  
    6262
    6363# 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
     65my $prevlabel = '';
     66my $curlabel = '';
     67
    6468while (<>) {
    6569  chomp;
    6670  next if /^\s*$/;
    6771  next if /^\s*;/;
    68   if (my ($macro,$mdetail) = (/^\s*\$(TTL|ORIGIN|INCLUDE)\s+(.+)/) ) {
     72  if (my ($macro,$mdetail) = (/^\s*\$(TTL|ORIGIN|INCLUDE|GENERATE)\s+(.+)/) ) {
    6973    # macro sort of thing;  $TTL and $ORIGIN most common.  $INCLUDE is a thing, expect it to be rare in live use tho
    7074    if ($macro eq 'TTL') {
     
    8993      }
    9094    }
     95    # not handling $INCLUDE or $GENERATE (altho the latter seems to be mostly a less-flexible version of the template types)
    9196    next;
    9297  }
     
    9499  next if /^ip-192-168-1(12|20)-\d+/;
    95100  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/;
    97103  # append zone name to record name if missing AND not dot-terminated;
    98104  # this happens automagically for forward zones, but not reverse because Reasons.  (fixme?)
     
    102108$name = $zname if /^\s*IN/;
    103109$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/;
    116113  if (defined $ttl) {
    117114    # TTL may be zero
     
    121118    $ttl = $zonettl;
    122119  }
     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  }
    123133  my ($type) = /([A-Z-]+)\s/;
    124134  if (!$reverse_typemap{$type}) {
     
    130140  chomp;
    131141  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  }
    132166
    133167  # 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.