On 15/01/15 15:07, Jan Cholasta wrote:
Dne 15.1.2015 v 14:58 Martin Basti napsal(a):
On 15/01/15 14:25, Jan Cholasta wrote:
Hi,

Dne 15.1.2015 v 13:27 Martin Basti napsal(a):
On 15/01/15 13:17, Martin Basti wrote:
https://fedorahosted.org/freeipa/ticket/4722

Patch attached.

Fast fix.

Updated patch attached.

1) Forward zone commands are not fixed.
FWzones are new and always normalized to absolute name in ldap

Would you bet your money on that? Better be safe than sorry, especially when it's just a matter of moving the code around (right?)


2) It seems that the primary key returned by -mod, -del and -show
(.result.value) is made absolute somewhere else in the code. Would it
be possible to do it in one place?
IMO it is not possible.

Value is generated from key, and key is normalized to absolute zone
before calling execute.

LDAPUpdate:
...
         if self.obj.primary_key:
             pkey = keys[-1]
         else:
             pkey = None

         return dict(result=entry_attrs, value=pkey_to_value(pkey,
options))

The idnsname attribute is just taken from LDAP without any normalization

Right.




3) Attribute values returned from LDAP are never None, so the if
should be "if 'idnsname' in entry_attrs:".
Ok I will revert the change I made.

4) If idnsname always has only single value, use
"entry_attrs.single_value['idnsname'] =
entry_attrs.single_value['idnsname'].make_absolute()"
Thanks

Honza


Updated patch attached.



Updated patch attached.

--
Martin Basti

From 5ea17ecf1b6811df05042beb6a9024cefee415df Mon Sep 17 00:00:00 2001
From: Martin Basti <mba...@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
---
 ipalib/plugins/dns.py | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/ipalib/plugins/dns.py b/ipalib/plugins/dns.py
index 7a80036c94432a01ea8781101712ea1135134948..4b95684747ac1d470665016e614b68095bc8690f 100644
--- a/ipalib/plugins/dns.py
+++ b/ipalib/plugins/dns.py
@@ -2081,6 +2081,15 @@ class DNSZoneBase(LDAPObject):
             except errors.NotFound:
                 raise e  # re-raise original exception
 
+    def _make_zonename_absolute(self, entry_attrs):
+        """
+        Zone names can be relative in IPA < 4.0, make sure we always return
+        absolute zone name from ldap
+        """
+        if "idnsname" in entry_attrs:
+            entry_attrs.single_value['idnsname'] = \
+                entry_attrs.single_value['idnsname'].make_absolute()
+
 
 class DNSZoneBase_add(LDAPCreate):
 
@@ -2798,6 +2807,7 @@ class dnszone_mod(DNSZoneBase_mod):
     def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
         assert isinstance(dn, DN)
         self.obj._rr_zone_postprocess(entry_attrs, **options)
+        self.obj._make_zonename_absolute(entry_attrs)
         return dn
 
 
@@ -2835,6 +2845,7 @@ class dnszone_find(DNSZoneBase_find):
     def post_callback(self, ldap, entries, truncated, *args, **options):
         for entry_attrs in entries:
             self.obj._rr_zone_postprocess(entry_attrs, **options)
+            self.obj._make_zonename_absolute(entry_attrs)
         return truncated
 
 
@@ -2851,6 +2862,7 @@ class dnszone_show(DNSZoneBase_show):
     def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
         assert isinstance(dn, DN)
         self.obj._rr_zone_postprocess(entry_attrs, **options)
+        self.obj._make_zonename_absolute(entry_attrs)
         return dn
 
 
@@ -4370,11 +4382,21 @@ class dnsforwardzone_mod(DNSZoneBase_mod):
 
         return dn
 
+    def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
+        assert isinstance(dn, DN)
+        self.obj._make_zonename_absolute(entry_attrs)
+        return dn
+
 
 @register()
 class dnsforwardzone_find(DNSZoneBase_find):
     __doc__ = _('Search for DNS forward zones.')
 
+    def post_callback(self, ldap, entries, truncated, *args, **options):
+        for entry_attrs in entries:
+            self.obj._make_zonename_absolute(entry_attrs)
+        return truncated
+
 
 @register()
 class dnsforwardzone_show(DNSZoneBase_show):
@@ -4382,6 +4404,11 @@ class dnsforwardzone_show(DNSZoneBase_show):
 
     has_output_params = LDAPRetrieve.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)
+        return dn
+
 
 @register()
 class dnsforwardzone_disable(DNSZoneBase_disable):
-- 
2.1.0

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to