Ticket #5455: add-server-behavior-and-misc-03.patch
| File add-server-behavior-and-misc-03.patch, 6.2 KB (added by BobNovas, 16 months ago) |
|---|
-
names/authority.py
82 82 additional = [] 83 83 default_ttl = max(self.soa[1].minimum, self.soa[1].expire) 84 84 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() + '.')) 86 89 87 90 if domain_records: 88 91 for record in domain_records: … … 208 211 209 212 def stripComments(self, lines): 210 213 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 214 216 ] 215 217 216 218 … … 233 235 lines = L 234 236 L = [] 235 237 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()) 237 245 return filter(None, L) 238 246 239 247 … … 242 250 ORIGIN = self.origin 243 251 244 252 self.records = {} 253 self.previousDomain = None 245 254 246 255 for (line, index) in zip(lines, range(len(lines))): 247 256 if line[0] == '$TTL': … … 275 284 r.ttl = ttl 276 285 self.records.setdefault(domain.lower(), []).append(r) 277 286 278 print 'Adding IN Record', domain, ttl, r287 #print 'Adding IN Record', domain, ttl, r 279 288 if type == 'SOA': 280 289 self.soa = (domain, r) 281 290 else: … … 283 292 284 293 285 294 # 286 # This file ends here. Read no further.295 # parse a bind format line. 287 296 # 288 297 def parseRecordLine(self, origin, ttl, line): 289 MARKERS = dns.QUERY_CLASSES.values() + dns.QUERY_TYPES.values()290 298 cls = 'IN' 291 owner = origin 292 299 293 300 if line[0] == '@': 294 line = line[1:]295 301 owner = origin 296 # print 'default owner' 297 elif not line[0].isdigit() and line[0] not in MARKERS: 302 elif line[0]: 298 303 owner = line[0] 299 line = line[1:]300 # print 'owner is ', owner 304 else: 305 owner = self.previousDomain 301 306 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]: 303 309 domain = owner 304 310 owner = origin 305 # print 'woops, owner is ', owner, ' domain is ', domain 311 line = line[1:] 306 312 else: 307 313 domain = line[0] 308 314 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 311 320 if line[0] in dns.QUERY_CLASSES.values(): 312 321 cls = line[0] 313 322 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] 321 326 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 333 340 self.addRecord(owner, ttl, type, domain, cls, rdata) 341 342 self.previousDomain = domain -
names/client.py
246 246 for (d, q, t) in self.pending: 247 247 self.queryTCP(q, t).chainDeferred(d) 248 248 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 249 258 250 251 259 def messageReceived(self, message, protocol, address = None): 252 260 log.msg("Unexpected message (%d) received from %r" % (message.id, address)) 253 261 -
names/secondary.py
59 59 if self.transferring: 60 60 return 61 61 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 64 74 ).addCallback(self._cbZone 65 75 ).addErrback(self._ebZone 66 76 )
