Changeset 800


Ignore:
Timestamp:
11/05/20 17:07:56 (3 years ago)
Author:
Kris Deugau
Message:

/trunk

Commit 2nd archived iteration of bind2hosts in development

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bind2hosts

    r799 r800  
    6868  next if /^\s*$/;
    6969  next if /^\s*;/;
     70  next if /^\s*\)/;     # SOA closing (possibly other records too?)
     71                        # arguably should do some more targeted voodoo when parsing the SOA details
     72
    7073  if (my ($macro,$mdetail) = (/^\s*\$(TTL|ORIGIN|INCLUDE)\s+(.+)/) ) {
    7174    # macro sort of thing;  $TTL and $ORIGIN most common.  $INCLUDE is a thing, expect it to be rare in live use tho
    7275    if ($macro eq 'TTL') {
    73       if ($mdetail =~ /^\d+$/) {
    74         $defttl = $mdetail;
     76      # irrelevant for a hosts file
     77    } elsif ($macro eq 'ORIGIN') {
     78      # $ORIGIN supports cascading/nesting, by watching for fully-qualified names vs partial names.
     79      if ($mdetail =~ /\.$/) {
     80        $origin = $mdetail;
    7581      } else {
    76         warn "invalid \$TTL: $_\n";
    77       }
    78     } elsif ($macro eq 'ORIGIN') {
    79 ##fixme:  going to skip the stupid case of "$ORIGIN com." and the like that lie
    80 # between . and the root domain we were told we're importing;  anyone using such
    81 # a mess outside the root servers is clearly insane
    82 # handled cases:
    83 #   $ORIGIN .
    84 #   $ORIGIN [zonedomain].
    85 #   $ORIGIN [subdomain.zonedomain].
    86       if ($mdetail eq '.' || $mdetail =~ /$zname\.$/ || $zname =~ /$mdetail\.$/) {
    87         $recbase = $mdetail;
    88       } else {
    89         # if we continue, we either use an $ORIGIN that's out of zone, or ignore it and potentially publish incorrect records.
    90         die "bad \$ORIGIN: $_\n";
     82        # append current origin to unqualified origin
     83        $origin = "$mdetail.$origin";
    9184      }
    9285    }
     86##fixme: should arguably handle $INCLUDE
     87# probably NOT going to handle $GENERATE, since that type of record set is best handled in DNS
    9388    next;
    9489  }
    95   # skip stale records that have no value
    96 #  next if /^ip-\d+-\d+-\d+/;
    97 #  next if /^ip.pre.fix.\d+.static.colo/;
     90
     91  my $origrec = $_;
     92
     93##fixme:  convert to optional skipfile?
     94# skip stale records that have no value
     95#next if /^ip-\d+-\d+-\d+/;
     96#next if /^ip.pre.fix.\d+.static.colo/;
     97
     98  # leading whitespace indicates "same label as last record"
     99  if (/^\s/) {
     100    $curlabel = $prevlabel;
     101  } else {
     102    ($curlabel) = /^([\w\@_.-]+)\s/;
     103  }
     104
     105  # magic name!
     106  $curlabel = "$zname." if $curlabel eq '@';
     107
     108  # append $ORIGIN if name is not fully qualified.
     109  if ($curlabel !~ /\.$/) {
     110    $curlabel .= $origin;
     111  }
     112
     113  # check for zone scope.  skip bad records.
     114  if ($curlabel !~ /$zname.$/) {
     115    warn "bad record $origrec, maybe bad \$ORIGIN?\n";
     116    next;
     117  }
     118
    98119  my ($name) = /([\w_.-]+)\s/;
    99120  # append zone name to record name if missing AND not dot-terminated;
     
    152173#;imap   IN      900     CNAME   deepnet.cx.
    153174##fixme:  not sure how to handle the case where someone leaves off the class.
    154   if ($doimport) {
    155     my ($code, $msg);
    156     if ($rev eq 'n') {
    157       ($code,$msg) = $dnsdb->addRec('n', $rev, $zid, \$name, \$itype, \$rdata, $ttl);
    158     } else {
    159       ($code,$msg) = $dnsdb->addRec('n', $rev, $zid, \$rdata, \$itype, \$name, $ttl);
    160     }
    161     print "$code: $msg\n";
    162   }
     175#  if ($doimport) {
     176#    my ($code, $msg);
     177#    if ($rev eq 'n') {
     178#      ($code,$msg) = $dnsdb->addRec('n', $rev, $zid, \$name, \$itype, \$rdata, $ttl);
     179#    } else {
     180#      ($code,$msg) = $dnsdb->addRec('n', $rev, $zid, \$rdata, \$itype, \$name, $ttl);
     181#    }
     182#    print "$code: $msg\n";
     183#  }
     184
    163185}
    164186
Note: See TracChangeset for help on using the changeset viewer.