Ticket #5455: add-server-behavior-and-misc-03.patch

File add-server-behavior-and-misc-03.patch, 6.2 KB (added by BobNovas, 4 years ago)
  • names/authority.py

     
    8282        additional = []
    8383        default_ttl = max(self.soa[1].minimum, self.soa[1].expire)
    8484
    85         domain_records = self.records.get(name.lower())
     85        #a record in self.records has a trailing dot if it was created with one, but is never
     86        #queried with a trailing dot. So, if the get fails with no trailing dot, try it with
     87        #a trailing dot.  (You could do a better job, and trim the trailing dot, but that's hard.)
     88        domain_records = self.records.get(name.lower(), self.records.get(name.lower() + '.'))
    8689
    8790        if domain_records:
    8891            for record in domain_records:
     
    208211
    209212    def stripComments(self, lines):
    210213        return [
    211             a.find(';') == -1 and a or a[:a.find(';')] for a in [
    212                 b.strip() for b in lines
    213             ]
     214            #leading whitespace is significant - don't strip it!
     215            a.find(';') == -1 and a or a[:a.find(';')] for a in lines
    214216        ]
    215217
    216218
     
    233235        lines = L
    234236        L = []
    235237        for line in lines:
    236             L.append(line.split())
     238            if not line:
     239                continue
     240           
     241            if line[0] in [' ', '\t']:
     242                L.append([''] + line.split())
     243            else:
     244                L.append(line.split())
    237245        return filter(None, L)
    238246
    239247
     
    242250        ORIGIN = self.origin
    243251
    244252        self.records = {}
     253        self.previousDomain = None
    245254
    246255        for (line, index) in zip(lines, range(len(lines))):
    247256            if line[0] == '$TTL':
     
    275284            r.ttl = ttl
    276285            self.records.setdefault(domain.lower(), []).append(r)
    277286
    278             print 'Adding IN Record', domain, ttl, r
     287            #print 'Adding IN Record', domain, ttl, r
    279288            if type == 'SOA':
    280289                self.soa = (domain, r)
    281290        else:
     
    283292
    284293
    285294    #
    286     # This file ends here.  Read no further.
     295    # parse a bind format line.
    287296    #
    288297    def parseRecordLine(self, origin, ttl, line):
    289         MARKERS = dns.QUERY_CLASSES.values() + dns.QUERY_TYPES.values()
    290298        cls = 'IN'
    291         owner = origin
    292 
     299       
    293300        if line[0] == '@':
    294             line = line[1:]
    295301            owner = origin
    296 #            print 'default owner'
    297         elif not line[0].isdigit() and line[0] not in MARKERS:
     302        elif line[0]:
    298303            owner = line[0]
    299             line = line[1:]
    300 #            print 'owner is ', owner
     304        else:
     305            owner = self.previousDomain
    301306
    302         if line[0].isdigit() or line[0] in MARKERS:
     307        #if the line starts with whitespace, it's not a name
     308        if not line[0]:
    303309            domain = owner
    304310            owner = origin
    305 #            print 'woops, owner is ', owner, ' domain is ', domain
     311            line = line[1:]
    306312        else:
    307313            domain = line[0]
    308314            line = line[1:]
    309 #            print 'domain is ', domain
    310 
     315       
     316        if line[0].isdigit():
     317            ttl = int(line[0])
     318            line = line[1:]
     319           
    311320        if line[0] in dns.QUERY_CLASSES.values():
    312321            cls = line[0]
    313322            line = line[1:]
    314 #            print 'cls is ', cls
    315             if line[0].isdigit():
    316                 ttl = int(line[0])
    317                 line = line[1:]
    318 #                print 'ttl is ', ttl
    319         elif line[0].isdigit():
    320             ttl = int(line[0])
     323           
     324        if line[0] in dns.QUERY_TYPES.values():
     325            type = line[0]
    321326            line = line[1:]
    322 #            print 'ttl is ', ttl
    323             if line[0] in dns.QUERY_CLASSES.values():
    324                 cls = line[0]
    325                 line = line[1:]
    326 #                print 'cls is ', cls
    327 
    328         type = line[0]
    329 #        print 'type is ', type
    330         rdata = line[1:]
    331 #        print 'rdata is ', rdata
    332 
     327       
     328        if type == dns.QUERY_TYPES[dns.RRSIG] and len(line) > 9:
     329            line[8] = ''.join(line[8:])
     330            line = line[0:9]
     331        elif type == dns.QUERY_TYPES[dns.DS] and len(line) > 4:
     332            line[3] = ''.join(line[3:])
     333            line = line[0:3]
     334        elif type == dns.QUERY_TYPES[dns.DNSKEY] and len(line) > 4:
     335            line[3] = ''.join(line[3:])
     336            line = line[0:3]
     337           
     338        rdata = line
     339       
    333340        self.addRecord(owner, ttl, type, domain, cls, rdata)
     341       
     342        self.previousDomain = domain
  • names/client.py

     
    246246        for (d, q, t) in self.pending:
    247247            self.queryTCP(q, t).chainDeferred(d)
    248248        del self.pending[:]
     249       
     250    def connectionLost(self, protocol):
     251        """
     252        Called on UDP protocol when a DNS UDP query times out and is retried
     253        on the TCP protocol. 30 seconds after the TCP query completes, this
     254        method is called on the UDP protocol.
     255        """
     256        self.connections.remove(protocol)
     257        del protocol
    249258
    250 
    251259    def messageReceived(self, message, protocol, address = None):
    252260        log.msg("Unexpected message (%d) received from %r" % (message.id, address))
    253261
  • names/secondary.py

     
    5959        if self.transferring:
    6060            return
    6161        self.transfering = True
    62         return client.Resolver(servers=[(self.primary, dns.PORT)]
    63             ).lookupZone(self.domain
     62       
     63        #allow for using a primary that is not serving DNS on port 53
     64        #pick up the port from the primary address in ip:port format
     65        primary = self.primary
     66        port = dns.PORT
     67        parts = self.primary.split(':')
     68        if len(parts) == 2:
     69            primary = parts[0]
     70            port = int(parts[1])
     71           
     72        return client.Resolver(servers=[(primary, port)]
     73            ).lookupZone(self.domain, timeout=600
    6474            ).addCallback(self._cbZone
    6575            ).addErrback(self._ebZone
    6676            )