From c49bc80494938a41d2c34c7ac1cde1fe3a14ddd5 Mon Sep 17 00:00:00 2001 From: Martin Kosek Date: Tue, 25 Sep 2012 10:36:01 +0200 Subject: Use custom zonemgr for reverse zones When DNS is being installed during ipa-{server,dns,replica}-install, forward and reverse zone is created. However, reverse zone was always created with default zonemgr even when a custom zonemgr was passed to the installer as this functionality was missing in function creating reverse zone. Consolidate functions creating forward and reverse zones to avoid code duplication and errors like this one. Reverse zones are now created with custom zonemgr (when entered by user). https://fedorahosted.org/freeipa/ticket/2790 --- ipalib/plugins/dns.py | 25 ++++++------------------- ipalib/util.py | 13 +++++++++++++ 2 files changed, 19 insertions(+), 19 deletions(-) (limited to 'ipalib') diff --git a/ipalib/plugins/dns.py b/ipalib/plugins/dns.py index 8c269c0a0..febd4d17c 100644 --- a/ipalib/plugins/dns.py +++ b/ipalib/plugins/dns.py @@ -34,7 +34,7 @@ from ipalib import _, ngettext from ipalib.util import (validate_zonemgr, normalize_zonemgr, validate_hostname, validate_dns_label, validate_domain_name, get_dns_forward_zone_update_policy, get_dns_reverse_zone_update_policy, - get_reverse_zone_default) + get_reverse_zone_default, zone_is_reverse, REVERSE_DNS_ZONES) from ipapython.ipautil import valid_ip, CheckedIPAddress, is_host_resolvable __doc__ = _(""" @@ -1499,19 +1499,6 @@ _dns_record_options = tuple(__dns_record_options_iter()) _dns_supported_record_types = tuple(record.rrtype for record in _dns_records \ if record.supported) -# dictionary of valid reverse zone -> number of address components -_valid_reverse_zones = { - '.in-addr.arpa.' : 4, - '.ip6.arpa.' : 32, -} - -def zone_is_reverse(zone_name): - for rev_zone_name in _valid_reverse_zones.keys(): - if zone_name.endswith(rev_zone_name): - return True - - return False - def check_ns_rec_resolvable(zone, name): if not name.endswith('.'): # this is a DNS name relative to the zone @@ -1842,7 +1829,7 @@ class dnszone_find(LDAPSearch): assert isinstance(base_dn, DN) if options.get('forward_only', False): search_kw = {} - search_kw['idnsname'] = _valid_reverse_zones.keys() + search_kw['idnsname'] = REVERSE_DNS_ZONES.keys() rev_zone_filter = ldap.make_filter(search_kw, rules=ldap.MATCH_NONE, exact=False, trailing_wildcard=False) filter = ldap.combine_filters((rev_zone_filter, filter), rules=ldap.MATCH_ALL) @@ -2027,14 +2014,14 @@ class dnsrecord(LDAPObject): else: addr = keys[-1] zone_len = 0 - for valid_zone in _valid_reverse_zones: - if zone.find(valid_zone) != -1: + for valid_zone in REVERSE_DNS_ZONES: + if zone.endswith(valid_zone): zone = zone.replace(valid_zone,'') zone_name = valid_zone - zone_len = _valid_reverse_zones[valid_zone] + zone_len = REVERSE_DNS_ZONES[valid_zone] if not zone_len: - allowed_zones = ', '.join(_valid_reverse_zones) + allowed_zones = ', '.join(REVERSE_DNS_ZONES) raise errors.ValidationError(name='ptrrecord', error=unicode(_('Reverse zone for PTR record should be a sub-zone of one the following fully qualified domains: %s') % allowed_zones)) diff --git a/ipalib/util.py b/ipalib/util.py index df8791ba0..53b6c80c5 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -494,6 +494,19 @@ def get_dns_reverse_zone_update_policy(realm, reverse_zone, rrtypes=('PTR',)): return policy +# dictionary of valid reverse zone -> number of address components +REVERSE_DNS_ZONES = { + '.in-addr.arpa.' : 4, + '.ip6.arpa.' : 32, +} + +def zone_is_reverse(zone_name): + zone_name = normalize_zone(zone_name) + if any(zone_name.endswith(name) for name in REVERSE_DNS_ZONES): + return True + + return False + def get_reverse_zone_default(ip_address): ip = netaddr.IPAddress(ip_address) items = ip.reverse_dns.split('.') -- cgit