Commit a9007817 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Cleanup handling of names that equals domain

parent 63c3bc6b
......@@ -6,6 +6,13 @@ import re
import sys
import os
class NoNameserverException(Exception):
pass
class InvalidHostnameException(Exception):
pass
def generate(tree, options):
#
# A. Check if host is a nameserver
......@@ -100,7 +107,7 @@ def header(tree, domain, origin=None):
if not filter(lambda ns: ns.domain[0] == domain and ns.primary[0] == 'yes',
tree._host_._interface_._nameserver_):
raise Exception("No nameserver defined for %s" % domain)
raise NoNameserverException("No nameserver defined for %s" % domain)
result = util.StringArray()
if origin:
result += "$ORIGIN %s." % origin
......@@ -153,8 +160,8 @@ class DomainDict:
pass
def add_host(self, name, ttl, kind, value):
if not re.match('^[*0-9a-zA-Z][-.0-9a-zA-Z]*$', name):
raise Exception('Invalid host name "%s"' % name)
if not re.match('^([*0-9a-zA-Z][-.0-9a-zA-Z]*|@)$', name):
raise InvalidHostnameException('Invalid host name "%s"' % name)
if not name in self.host:
self.host[name] = set()
pass
......@@ -197,18 +204,6 @@ class DomainDict:
def generate_forward(tree, hosts):
def callback(domain):
result = header(tree, domain, domain)
for name,address,ttl in hosts:
if name == '%s.' % (domain):
# Host with same name as domain goes into header
if address.version == 4:
result += ('@ %-8s IN A %s' %
(ttl, str(address.exploded)))
elif address.version == 6:
result += ('@ %-8s IN AAAA %s' %
(ttl, str(address.exploded)))
pass
pass
pass
for mx in [ m for m in tree._host_._interface_._mailhost_
if m.domain[0] == domain]:
pri = int(mx.priority[0] or 0)
......@@ -276,15 +271,15 @@ def generate_forward(tree, hosts):
for s in tree._subnet_
if s.domain[0] and util.network(s)]:
for name,address,ttl in hosts:
try:
if name.endswith('.'):
d = '.'.join(name.split('.')[1:-1])
n = name.split('.')[0]
add_host(d, n, ttl, address)
continue
except Exception,e:
if name.endswith('.'):
if name[0:-1] == domain:
add_host(domain, '@', ttl, address)
pass
elif '.'.join(name.split('.')[1:-1]) == domain:
add_host(domain, name.split('.')[0], ttl, address)
pass
pass
if address in net:
elif address in net:
add_host(domain, name, ttl, address)
pass
pass
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment