From 998e880b61b4c201a9483a0beafc6d139a29f0db Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 10 Oct 2016 20:11:57 +0100 Subject: [PATCH] unbound: Skip invalid hostnames 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 --- config/unbound/unbound-dhcp-leases-bridge | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/config/unbound/unbound-dhcp-leases-bridge b/config/unbound/unbound-dhcp-leases-bridge index c62d23390..862b5814f 100644 --- a/config/unbound/unbound-dhcp-leases-bridge +++ b/config/unbound/unbound-dhcp-leases-bridge @@ -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), -- 2.39.2