Changeset 2209 for trunk/packages/invirt-dns/invirt-dns
- Timestamp:
- Feb 27, 2009, 4:38:33 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/invirt-dns/invirt-dns
r2208 r2209 82 82 3600, self.ns, auth=True)) 83 83 84 if cls == dns.IN: 85 if name.endswith(".in-addr.arpa"): 86 if type in (dns.PTR, dns.ALL_RECORDS): 87 ip = '.'.join(reversed(name.split('.')[:-2])) 88 value = invirt.database.NIC.query.filter_by(ip=ip).first() 89 if value and value.hostname: 90 hostname = value.hostname 91 if '.' not in hostname: 92 hostname = hostname + "." + config.dns.domains[0] 93 record = dns.Record_PTR(hostname, ttl) 94 results.append(dns.RRHeader(name, dns.PTR, dns.IN, 95 ttl, record, auth=True)) 96 else: # IP address doesn't point to an active host 97 return defer.fail(failure.Failure(dns.AuthoritativeDomainError(name))) 98 elif type == dns.SOA: 99 results.append(dns.RRHeader(domain, dns.SOA, dns.IN, 100 ttl, self.soa, auth=True)) 101 # FIXME: Should only return success with no records if the name actually exists 102 elif name == domain or name == '.'+domain: 103 if type in (dns.A, dns.ALL_RECORDS): 104 record = dns.Record_A(config.dns.nameservers[0].ip, ttl) 105 results.append(dns.RRHeader(name, dns.A, dns.IN, 84 # The order of logic: 85 # - What class? 86 # - What domain: in-addr.arpa, domain root, or subdomain? 87 # - What query type: A, PTR, NS, ...? 88 89 if cls != dns.IN: 90 # Hahaha. No. 91 return defer.fail(failure.Failure(dns.AuthoritativeDomainError(name))) 92 93 if name.endswith(".in-addr.arpa"): 94 if type in (dns.PTR, dns.ALL_RECORDS): 95 ip = '.'.join(reversed(name.split('.')[:-2])) 96 value = invirt.database.NIC.query.filter_by(ip=ip).first() 97 if value and value.hostname: 98 hostname = value.hostname 99 if '.' not in hostname: 100 hostname = hostname + "." + config.dns.domains[0] 101 record = dns.Record_PTR(hostname, ttl) 102 results.append(dns.RRHeader(name, dns.PTR, dns.IN, 106 103 ttl, record, auth=True)) 107 elif type == dns.NS: 108 results.append(dns.RRHeader(domain, dns.NS, dns.IN, 109 ttl, self.ns, auth=True)) 110 authority = [] 111 elif type == dns.SOA: 112 results.append(dns.RRHeader(domain, dns.SOA, dns.IN, 113 ttl, self.soa, auth=True)) 104 else: # IP address doesn't point to an active host 105 return defer.fail(failure.Failure(dns.AuthoritativeDomainError(name))) 106 elif type == dns.SOA: 107 results.append(dns.RRHeader(domain, dns.SOA, dns.IN, 108 ttl, self.soa, auth=True)) 109 # FIXME: Should only return success with no records if the name actually exists 110 111 elif name == domain or name == '.'+domain: 112 if type in (dns.A, dns.ALL_RECORDS): 113 record = dns.Record_A(config.dns.nameservers[0].ip, ttl) 114 results.append(dns.RRHeader(name, dns.A, dns.IN, 115 ttl, record, auth=True)) 116 elif type == dns.NS: 117 results.append(dns.RRHeader(domain, dns.NS, dns.IN, 118 ttl, self.ns, auth=True)) 119 authority = [] 120 elif type == dns.SOA: 121 results.append(dns.RRHeader(domain, dns.SOA, dns.IN, 122 ttl, self.soa, auth=True)) 123 124 else: 125 host = name[:-len(domain)-1] 126 value = invirt.database.NIC.query.filter_by(hostname=host).first() 127 if value: 128 ip = value.ip 114 129 else: 115 host = name[:-len(domain)-1] 116 value = invirt.database.NIC.query.filter_by(hostname=host).first() 130 value = invirt.database.Machine.query().filter_by(name=host).first() 117 131 if value: 118 ip = value.ip 119 else: 120 value = invirt.database.Machine.query().filter_by(name=host).first() 121 if value: 122 ip = value.nics[0].ip 123 else: 124 return defer.fail(failure.Failure(dns.AuthoritativeDomainError(name))) 125 126 if ip is None: 132 ip = value.nics[0].ip 133 else: 127 134 return defer.fail(failure.Failure(dns.AuthoritativeDomainError(name))) 128 129 if type in (dns.A, dns.ALL_RECORDS): 130 record = dns.Record_A(ip, ttl) 131 results.append(dns.RRHeader(name, dns.A, dns.IN, 132 ttl, record, auth=True)) 133 elif type == dns.SOA: 134 results.append(dns.RRHeader(domain, dns.SOA, dns.IN, 135 ttl, self.soa, auth=True)) 136 if len(results) == 0: 137 authority = [] 138 additional = [] 139 return defer.succeed((results, authority, additional)) 140 else: 141 #Doesn't exist 142 return defer.fail(failure.Failure(dns.AuthoritativeDomainError(name))) 135 if ip is None: 136 return defer.fail(failure.Failure(dns.AuthoritativeDomainError(name))) 137 if type in (dns.A, dns.ALL_RECORDS): 138 record = dns.Record_A(ip, ttl) 139 results.append(dns.RRHeader(name, dns.A, dns.IN, 140 ttl, record, auth=True)) 141 elif type == dns.SOA: 142 results.append(dns.RRHeader(domain, dns.SOA, dns.IN, 143 ttl, self.soa, auth=True)) 144 145 if len(results) == 0: 146 authority = [] 147 additional = [] 148 return defer.succeed((results, authority, additional)) 143 149 144 150 class QuotingBindAuthority(authority.BindAuthority):
Note: See TracChangeset
for help on using the changeset viewer.