From c7ee765c4de086ac92922519d7065fc6b6796f10 Mon Sep 17 00:00:00 2001 From: Petr Spacek Date: Mon, 7 Mar 2016 14:10:54 +0100 Subject: Add function ipapython.dnsutil.inside_auto_empty_zone() It allows to test if given DNS name belongs to an automatic empty zone. https://fedorahosted.org/freeipa/ticket/5710 Reviewed-By: Martin Basti --- ipapython/dnsutil.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'ipapython') diff --git a/ipapython/dnsutil.py b/ipapython/dnsutil.py index e8d2f6ff6..240b7c9cd 100644 --- a/ipapython/dnsutil.py +++ b/ipapython/dnsutil.py @@ -203,3 +203,28 @@ def is_auto_empty_zone(zone): """ assert_absolute_dnsname(zone) return zone in EMPTY_ZONES + + +def inside_auto_empty_zone(name): + """True if specified absolute name is a subdomain of an automatic empty + zone. + + DNS domain is a subdomain of itself so this function + returns True for zone apexes, too. + + >>> inside_auto_empty_zone(DNSName('in-addr.arpa.')) + False + >>> inside_auto_empty_zone(DNSName('10.in-addr.arpa.')) + True + >>> inside_auto_empty_zone(DNSName('1.10.in-addr.arpa.')) + True + >>> inside_auto_empty_zone(DNSName('1.10.in-addr.arpa')) + Traceback (most recent call last): + ... + AssertionError: ... + """ + assert_absolute_dnsname(name) + for aez in EMPTY_ZONES: + if name.is_subdomain(aez): + return True + return False -- cgit