pgreco / rpms / ipa

Forked from forks/areguera/rpms/ipa 4 years ago
Clone

Blame SOURCES/0026-Host-del-fix-behavior-of-updatedns-and-PTR-records.patch

403b09
From 57b757807a53400b8addb19d323f5691122c3ebb Mon Sep 17 00:00:00 2001
403b09
From: Martin Basti <mbasti@redhat.com>
403b09
Date: Thu, 21 Jul 2016 13:18:34 +0200
403b09
Subject: [PATCH] Host-del: fix behavior of --updatedns and PTR records
403b09
403b09
* target for ptr record must be absolute domain name
403b09
* zone is detected using DNS system instead of random splitting of
403b09
hostname
403b09
403b09
https://fedorahosted.org/freeipa/ticket/6060
403b09
403b09
Reviewed-By: Petr Spacek <pspacek@redhat.com>
403b09
---
403b09
 ipaserver/plugins/host.py | 26 +++++++++++++++-----------
403b09
 1 file changed, 15 insertions(+), 11 deletions(-)
403b09
403b09
diff --git a/ipaserver/plugins/host.py b/ipaserver/plugins/host.py
403b09
index f342b05c87b936ab7b99009cfb0f6d3acde4ef93..413dcf15e0423170d8334902b9dcf8fb5aa14de6 100644
403b09
--- a/ipaserver/plugins/host.py
403b09
+++ b/ipaserver/plugins/host.py
403b09
@@ -18,6 +18,9 @@
403b09
 # You should have received a copy of the GNU General Public License
403b09
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
403b09
 
403b09
+from __future__ import absolute_import
403b09
+
403b09
+import dns.resolver
403b09
 import string
403b09
 
403b09
 import six
403b09
@@ -134,7 +137,7 @@ register = Registry()
403b09
 host_pwd_chars = string.digits + string.ascii_letters + '_,.@+-='
403b09
 
403b09
 
403b09
-def remove_ptr_rec(ipaddr, host, domain):
403b09
+def remove_ptr_rec(ipaddr, fqdn):
403b09
     """
403b09
     Remove PTR record of IP address (ipaddr)
403b09
     :return: True if PTR record was removed, False if record was not found
403b09
@@ -143,13 +146,12 @@ def remove_ptr_rec(ipaddr, host, domain):
403b09
     try:
403b09
         revzone, revname = get_reverse_zone(ipaddr)
403b09
 
403b09
-        # in case domain is in FQDN form with a trailing dot, we needn't add
403b09
-        # another one, in case it has no trailing dot, dnsrecord-del will
403b09
-        # normalize the entry
403b09
-        delkw = {'ptrrecord': "%s.%s" % (host, domain)}
403b09
+        # assume that target in PTR record is absolute name (otherwise it is
403b09
+        # non-standard configuration)
403b09
+        delkw = {'ptrrecord': u"%s" % fqdn.make_absolute()}
403b09
 
403b09
         api.Command['dnsrecord_del'](revzone, revname, **delkw)
403b09
-    except errors.NotFound:
403b09
+    except (errors.NotFound, errors.AttrValueNotFound):
403b09
         api.log.debug('PTR record of ipaddr %s not found', ipaddr)
403b09
         return False
403b09
 
403b09
@@ -794,13 +796,15 @@ class host_del(LDAPDelete):
403b09
 
403b09
         if updatedns:
403b09
             # Remove A, AAAA, SSHFP and PTR records of the host
403b09
-            parts = fqdn.split('.')
403b09
-            domain = unicode('.'.join(parts[1:]))
403b09
+            fqdn_dnsname = DNSName(fqdn).make_absolute()
403b09
+            zone = DNSName(dns.resolver.zone_for_name(fqdn_dnsname))
403b09
+            relative_hostname = fqdn_dnsname.relativize(zone)
403b09
+
403b09
             # Get all resources for this host
403b09
             rec_removed = False
403b09
             try:
403b09
                 record = api.Command['dnsrecord_show'](
403b09
-                    domain, parts[0])['result']
403b09
+                    zone, relative_hostname)['result']
403b09
             except errors.NotFound:
403b09
                 pass
403b09
             else:
403b09
@@ -808,13 +812,13 @@ class host_del(LDAPDelete):
403b09
                 for attr in ('arecord', 'aaaarecord'):
403b09
                     for val in record.get(attr, []):
403b09
                         rec_removed = (
403b09
-                            remove_ptr_rec(val, parts[0], domain) or
403b09
+                            remove_ptr_rec(val, fqdn_dnsname) or
403b09
                             rec_removed
403b09
                         )
403b09
                 try:
403b09
                     # remove all A, AAAA, SSHFP records of the host
403b09
                     api.Command['dnsrecord_mod'](
403b09
-                        domain,
403b09
+                        zone,
403b09
                         record['idnsname'][0],
403b09
                         arecord=[],
403b09
                         aaaarecord=[],
403b09
-- 
403b09
2.7.4
403b09