diff options
author | Petr Spacek <pspacek@redhat.com> | 2014-10-23 14:13:38 +0200 |
---|---|---|
committer | Petr Viktorin <pviktori@redhat.com> | 2014-10-29 15:02:08 +0100 |
commit | 4e42d171300114bffc62ac12bbe1c00f7c8f4518 (patch) | |
tree | bf326790caebbb6afa03a247a3648d543610c160 | |
parent | 75cdc50ba91a94682eac11f99995746be283f668 (diff) | |
download | freeipa-4e42d171300114bffc62ac12bbe1c00f7c8f4518.tar.gz freeipa-4e42d171300114bffc62ac12bbe1c00f7c8f4518.tar.xz freeipa-4e42d171300114bffc62ac12bbe1c00f7c8f4518.zip |
Fix zone name to directory name conversion in BINDMgr.
https://fedorahosted.org/freeipa/ticket/4657
Reviewed-By: Martin Basti <mbasti@redhat.com>
-rw-r--r-- | ipapython/dnssec/bindmgr.py | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/ipapython/dnssec/bindmgr.py b/ipapython/dnssec/bindmgr.py index 55765e16b..9c831c241 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: |