summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomas Krizek <tkrizek@redhat.com>2017-08-23 14:28:49 +0200
committerChristian Heimes <cheimes@redhat.com>2018-02-07 17:27:11 +0100
commit005d85ff688ad97d0b785f3cc906c142eea4d7cd (patch)
treeb27215cd5a8f24129e7248279510cc7da13692bd
parent53f202bdcc0ec996d51d01bff450c1344e2c32d6 (diff)
downloadfreeipa-005d85ff688ad97d0b785f3cc906c142eea4d7cd.tar.gz
freeipa-005d85ff688ad97d0b785f3cc906c142eea4d7cd.tar.xz
freeipa-005d85ff688ad97d0b785f3cc906c142eea4d7cd.zip
py3: bindmgr: fix bytes issues
LDAP client returns values as bytes, thus bindmgr must work with bytes properly. https://pagure.io/freeipa/issue/4985 Signed-off-by: Tomas Krizek <tkrizek@redhat.com> Reviewed-By: Stanislav Laznicka <slaznick@redhat.com>
-rw-r--r--ipaserver/dnssec/bindmgr.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/ipaserver/dnssec/bindmgr.py b/ipaserver/dnssec/bindmgr.py
index 32975fc54..69dff3dee 100644
--- a/ipaserver/dnssec/bindmgr.py
+++ b/ipaserver/dnssec/bindmgr.py
@@ -56,8 +56,10 @@ class BINDMgr(object):
return dns.name.from_text(dn[idx - 1]['idnsname'])
def time_ldap2bindfmt(self, str_val):
+ if isinstance(str_val, bytes):
+ str_val = str_val.decode('utf-8')
dt = datetime.strptime(str_val, ipalib.constants.LDAP_GENERALIZED_TIME_FORMAT)
- return dt.strftime(time_bindfmt)
+ return dt.strftime(time_bindfmt).encode('utf-8')
def dates2params(self, ldap_attrs):
"""Convert LDAP timestamps to list of parameters suitable
@@ -106,15 +108,15 @@ class BINDMgr(object):
"""Run dnssec-keyfromlabel on given LDAP object.
:returns: base file name of output files, e.g. Kaaa.test.+008+19719"""
logger.info('attrs: %s', attrs)
- assert attrs.get('idnsseckeyzone', ['FALSE'])[0] == 'TRUE', \
- 'object %s is not a DNS zone key' % attrs['dn']
+ assert attrs.get('idnsseckeyzone', [b'FALSE'])[0] == b'TRUE', \
+ b'object %s is not a DNS zone key' % attrs['dn']
- uri = "%s;pin-source=%s" % (attrs['idnsSecKeyRef'][0], paths.DNSSEC_SOFTHSM_PIN)
+ uri = b"%s;pin-source=%s" % (attrs['idnsSecKeyRef'][0], paths.DNSSEC_SOFTHSM_PIN.encode('utf-8'))
cmd = [paths.DNSSEC_KEYFROMLABEL, '-K', workdir, '-a', attrs['idnsSecAlgorithm'][0], '-l', uri]
cmd += self.dates2params(attrs)
- if attrs.get('idnsSecKeySep', ['FALSE'])[0].upper() == 'TRUE':
+ if attrs.get('idnsSecKeySep', [b'FALSE'])[0].upper() == b'TRUE':
cmd += ['-f', 'KSK']
- if attrs.get('idnsSecKeyRevoke', ['FALSE'])[0].upper() == 'TRUE':
+ if attrs.get('idnsSecKeyRevoke', [b'FALSE'])[0].upper() == b'TRUE':
cmd += ['-R', datetime.now().strftime(time_bindfmt)]
cmd.append(zone.to_text())