From b5c049ae2e62f24c6dfce618b94f567671e238ea Mon Sep 17 00:00:00 2001 From: Martin Kosek Date: Wed, 9 Nov 2011 14:10:08 +0100 Subject: Allow custom server backend encoding Server framework does not support encoding of native Python type values stored in Param classes and sub-classes. When backend (LDAP) value encoding differs from Python type value representation user has to has to hard-code the encoders in his processing. This patch introduces a method Param.encode which is used in server context to encode native Python Param values. The new encode method is used for Bool parameter to convert native Python bool type value (True, False) to LDAP value ("TRUE", "FALSE"). https://fedorahosted.org/freeipa/ticket/2039 --- ipaserver/plugins/ldap2.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'ipaserver/plugins/ldap2.py') diff --git a/ipaserver/plugins/ldap2.py b/ipaserver/plugins/ldap2.py index 5c401829..32a1eccb 100644 --- a/ipaserver/plugins/ldap2.py +++ b/ipaserver/plugins/ldap2.py @@ -45,6 +45,7 @@ from ldap.controls import LDAPControl from ldap.functions import explode_dn from ipalib.dn import DN from ipalib import _ +from ipalib.parameters import Bool import krbV @@ -62,6 +63,22 @@ MEMBERS_INDIRECT = 2 # SASL authentication mechanism SASL_AUTH = _ldap_sasl.sasl({}, 'GSSAPI') +# OID 1.3.6.1.4.1.1466.115.121.1.7 (Boolean) syntax encoding +def _encode_bool(self, value): + def encode_bool_value(value): + if value: + return u'TRUE' + else: + return u'FALSE' + + if type(value) in (tuple, list): + return tuple(encode_bool_value(v) for v in value) + else: + return encode_bool_value(value) + +# set own Bool parameter encoder +Bool._encode = _encode_bool + # universal LDAPError handler def _handle_errors(e, **kw): """ -- cgit