Skip to content
Snippets Groups Projects
Commit a9007817 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Cleanup handling of names that equals domain

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