From: Michael Tremer Date: Mon, 10 Oct 2016 19:11:57 +0000 (+0100) Subject: unbound: Skip invalid hostnames X-Git-Tag: v2.19-core106~19 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=998e880b61b4c201a9483a0beafc6d139a29f0db;p=people%2Fstevee%2Fipfire-2.x.git 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 --- diff --git a/config/unbound/unbound-dhcp-leases-bridge b/config/unbound/unbound-dhcp-leases-bridge index c62d23390e..862b5814f0 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),