Hello,

Fix zone name to directory name conversion in BINDMgr.

https://fedorahosted.org/freeipa/ticket/4657

--
Petr^2 Spacek
From dd948e32277acca6dc218e02b8f5c22d6ebc81c3 Mon Sep 17 00:00:00 2001
From: Petr Spacek <pspa...@redhat.com>
Date: Thu, 23 Oct 2014 14:13:38 +0200
Subject: [PATCH] Fix zone name to directory name conversion in BINDMgr.

https://fedorahosted.org/freeipa/ticket/4657
---
 ipapython/dnssec/bindmgr.py | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/ipapython/dnssec/bindmgr.py b/ipapython/dnssec/bindmgr.py
index 55765e16b59259f24bcb25b2276835362adbadc9..9c831c241d53ec3dd996b8fd8c3106a92998deb8 100644
--- a/ipapython/dnssec/bindmgr.py
+++ b/ipapython/dnssec/bindmgr.py
@@ -120,10 +120,40 @@ class BINDMgr(object):
         with open("%s/%s.dn" % (workdir, basename), 'w') as dn_file:
             dn_file.write(attrs['dn'])
 
+    def get_zone_dir_name(self, zone):
+        """Escape zone name to form suitable for file-system.
+
+        This method has to be equivalent to zr_get_zone_path()
+        in bind-dyndb-ldap/zone_register.c."""
+
+        if zone == dns.name.root:
+            return "@"
+
+        # strip final (empty) label
+        zone = zone.relativize(dns.name.root)
+        escaped = ""
+        for label in zone:
+            for char in label:
+                c = ord(char)
+                if ((c >= 0x30 and c <= 0x39) or   # digit
+                   (c >= 0x41 and c <= 0x5A) or    # uppercase
+                   (c >= 0x61 and c <= 0x7A) or    # lowercase
+                   c == 0x2D or                    # hyphen
+                   c == 0x5F):                     # underscore
+                    if (c >= 0x41 and c <= 0x5A):  # downcase
+                        c += 0x20
+                    escaped += chr(c)
+                else:
+                    escaped += "%%%02X" % c
+            escaped += '.'
+
+        # strip trailing period
+        return escaped[:-1]
+
     def sync_zone(self, zone):
         self.log.info('Synchronizing zone %s' % zone)
         zone_path = os.path.join(paths.BIND_LDAP_DNS_ZONE_WORKDIR,
-                zone.to_text(omit_final_dot=True))
+                self.get_zone_dir_name(zone))
         try:
             os.makedirs(zone_path)
         except OSError as e:
-- 
1.9.3

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

Reply via email to