]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
unbound: Skip invalid hostnames
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 10 Oct 2016 19:11:57 +0000 (20:11 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 10 Oct 2016 19:11:57 +0000 (20:11 +0100)
If there are any invalid hostnames in the DHCP leases
table, we just skip them and do not create and RRs for
them.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
config/unbound/unbound-dhcp-leases-bridge

index c62d23390e78d48e63dbe8786d9a0b3dd44aca48..862b5814f03f073c83178fb25f73192507a22477 100644 (file)
@@ -227,11 +227,16 @@ class Lease(object):
        def hostname(self):
                hostname = self._properties.get("client-hostname")
 
+               if hostname is None:
+                       return
+
                # Remove any ""
-               if hostname:
-                       hostname = hostname.replace("\"", "")
+               hostname = hostname.replace("\"", "")
 
-               return hostname
+               # Only return valid hostnames
+               m = re.match(r"^[A-Z0-9\-]{1,63}$", hostname, re.I)
+               if m:
+                       return hostname
 
        @property
        def domain(self):
@@ -279,7 +284,8 @@ class Lease(object):
 
        @property
        def fqdn(self):
-               return "%s.%s" % (self.hostname, self.domain)
+               if self.hostname:
+                       return "%s.%s" % (self.hostname, self.domain)
 
        @staticmethod
        def _parse_time(s):
@@ -310,6 +316,10 @@ class Lease(object):
 
        @property
        def rrset(self):
+               # If the lease does not have a valid FQDN, we cannot create any RRs
+               if self.fqdn is None:
+                       return []
+
                return [
                        # Forward record
                        (self.fqdn, "%s" % LOCAL_TTL, "IN A", self.ipaddr),