From 9b01d87626de2c5a0cb9b5e0d10959b13f03fbba Mon Sep 17 00:00:00 2001
From: Martin Basti <mbasti@redhat.com>
Date: Thu, 15 Jan 2015 13:13:55 +0100
Subject: [PATCH] Always return absolute idnsname in dnszone commands
Ticket: https://fedorahosted.org/freeipa/ticket/4722
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
---
ipalib/plugins/dns.py | 36 ++++++++++++++++++++++++++++++++++--
1 file changed, 34 insertions(+), 2 deletions(-)
diff --git a/ipalib/plugins/dns.py b/ipalib/plugins/dns.py
index 34afc189866993481229bb68a5edd77e0a4eaff3..ea4c212b42631e8513a13d2a7f5a859b2176376b 100644
--- a/ipalib/plugins/dns.py
+++ b/ipalib/plugins/dns.py
@@ -1848,6 +1848,18 @@ class DNSZoneBase(LDAPObject):
except errors.NotFound:
raise e # re-raise original exception
+ def _make_zonename_absolute(self, entry_attrs, **options):
+ """
+ Zone names can be relative in IPA < 4.0, make sure we always return
+ absolute zone name from ldap
+ """
+ if options.get('raw'):
+ return
+
+ if "idnsname" in entry_attrs:
+ entry_attrs.single_value['idnsname'] = (
+ entry_attrs.single_value['idnsname'].make_absolute())
+
class DNSZoneBase_add(LDAPCreate):
@@ -1895,6 +1907,11 @@ class DNSZoneBase_del(LDAPDelete):
class DNSZoneBase_mod(LDAPUpdate):
has_output_params = LDAPUpdate.has_output_params + dnszone_output_params
+ def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
+ assert isinstance(dn, DN)
+ self.obj._make_zonename_absolute(entry_attrs, **options)
+ return dn
+
class DNSZoneBase_find(LDAPSearch):
__doc__ = _('Search for DNS zones (SOA records).')
@@ -1929,6 +1946,11 @@ class DNSZoneBase_find(LDAPSearch):
filter = _create_idn_filter(self, ldap, *args, **options)
return (filter, base_dn, scope)
+ def post_callback(self, ldap, entries, truncated, *args, **options):
+ for entry_attrs in entries:
+ self.obj._make_zonename_absolute(entry_attrs, **options)
+ return truncated
+
class DNSZoneBase_show(LDAPRetrieve):
has_output_params = LDAPRetrieve.has_output_params + dnszone_output_params
@@ -1939,6 +1961,11 @@ class DNSZoneBase_show(LDAPRetrieve):
self.obj.handle_not_found(*keys)
return dn
+ def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
+ assert isinstance(dn, DN)
+ self.obj._make_zonename_absolute(entry_attrs, **options)
+ return dn
+
class DNSZoneBase_disable(LDAPQuery):
has_output = output.standard_value
@@ -2539,7 +2566,8 @@ class dnszone_mod(DNSZoneBase_mod):
return result
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
- assert isinstance(dn, DN)
+ dn = super(dnszone_mod, self).post_callback(ldap, dn, entry_attrs,
+ *keys, **options)
self.obj._rr_zone_postprocess(entry_attrs, **options)
return dn
@@ -2576,6 +2604,9 @@ class dnszone_find(DNSZoneBase_find):
return (filter, base_dn, scope)
def post_callback(self, ldap, entries, truncated, *args, **options):
+ truncated = super(dnszone_find, self).post_callback(ldap, entries,
+ truncated, *args,
+ **options)
for entry_attrs in entries:
self.obj._rr_zone_postprocess(entry_attrs, **options)
return truncated
@@ -2592,7 +2623,8 @@ class dnszone_show(DNSZoneBase_show):
return result
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
- assert isinstance(dn, DN)
+ dn = super(dnszone_show, self).post_callback(ldap, dn, entry_attrs,
+ *keys, **options)
self.obj._rr_zone_postprocess(entry_attrs, **options)
return dn
--
2.1.0