Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix SASL get/set options on big endian platforms #416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions LICENCE.MIT
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ to all contributions by the following authors:
* Aymeric Augustin
* Bernhard M. Wiedemann
* Bradley Baetz
* Christian Heimes
* Éloi Rivard
* Eyal Cherevatzki
* Fred Thomsen
Expand Down
41 changes: 30 additions & 11 deletions Modules/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ LDAP_set_option(LDAPObject *self, int option, PyObject *value)
double doubleval;
char *strval;
struct timeval tv;
#if HAVE_SASL
/* unsigned long */
ber_len_t blen;
#endif
void *ptr;
LDAP *ld;
LDAPControl **controls = NULL;
Expand Down Expand Up @@ -89,10 +93,6 @@ LDAP_set_option(LDAPObject *self, int option, PyObject *value)
case LDAP_OPT_X_TLS_PROTOCOL_MIN:
#endif
#endif
#ifdef HAVE_SASL
case LDAP_OPT_X_SASL_SSF_MIN:
case LDAP_OPT_X_SASL_SSF_MAX:
#endif
#ifdef LDAP_OPT_X_KEEPALIVE_IDLE
case LDAP_OPT_X_KEEPALIVE_IDLE:
#endif
Expand All @@ -108,6 +108,16 @@ LDAP_set_option(LDAPObject *self, int option, PyObject *value)
return 0;
ptr = &intval;
break;

#ifdef HAVE_SASL
case LDAP_OPT_X_SASL_SSF_MIN:
case LDAP_OPT_X_SASL_SSF_MAX:
if (!PyArg_Parse(value, "k:set_option", &blen))
return 0;
ptr = &blen;
break;
#endif

case LDAP_OPT_HOST_NAME:
case LDAP_OPT_URI:
#ifdef LDAP_OPT_DEFBASE
Expand Down Expand Up @@ -135,6 +145,7 @@ LDAP_set_option(LDAPObject *self, int option, PyObject *value)
return 0;
ptr = strval;
break;

case LDAP_OPT_TIMEOUT:
case LDAP_OPT_NETWORK_TIMEOUT:
/* Float valued timeval options */
Expand Down Expand Up @@ -239,6 +250,10 @@ LDAP_get_option(LDAPObject *self, int option)
LDAPAPIInfo apiinfo;
LDAPControl **lcs;
char *strval;
#if HAVE_SASL
/* unsigned long */
ber_len_t blen;
#endif
PyObject *extensions, *v;
Py_ssize_t i, num_extensions;

Expand Down Expand Up @@ -277,9 +292,6 @@ LDAP_get_option(LDAPObject *self, int option)

return v;

#ifdef HAVE_SASL
case LDAP_OPT_X_SASL_SSF:
#endif
case LDAP_OPT_REFERRALS:
case LDAP_OPT_RESTART:
case LDAP_OPT_DEREF:
Expand All @@ -299,10 +311,6 @@ LDAP_get_option(LDAPObject *self, int option)
case LDAP_OPT_X_TLS_PROTOCOL_MIN:
#endif
#endif
#ifdef HAVE_SASL
case LDAP_OPT_X_SASL_SSF_MIN:
case LDAP_OPT_X_SASL_SSF_MAX:
#endif
#ifdef LDAP_OPT_X_SASL_NOCANON
case LDAP_OPT_X_SASL_NOCANON:
#endif
Expand All @@ -324,6 +332,17 @@ LDAP_get_option(LDAPObject *self, int option)
return option_error(res, "ldap_get_option");
return PyInt_FromLong(intval);

#ifdef HAVE_SASL
case LDAP_OPT_X_SASL_SSF:
case LDAP_OPT_X_SASL_SSF_MIN:
case LDAP_OPT_X_SASL_SSF_MAX:
/* ber_len_t options (unsigned long)*/
res = LDAP_int_get_option(self, option, &blen);
if (res != LDAP_OPT_SUCCESS)
return option_error(res, "ldap_get_option");
return PyLong_FromUnsignedLong(blen);
#endif

case LDAP_OPT_HOST_NAME:
case LDAP_OPT_URI:
#ifdef LDAP_OPT_DEFBASE
Expand Down
23 changes: 22 additions & 1 deletion Tests/t_ldapobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def test005_invalid_credentials(self):

@requires_sasl()
@requires_ldapi()
def test006_sasl_extenal_bind_s(self):
def test006_sasl_external_bind_s(self):
l = self.ldap_object_class(self.server.ldapi_uri)
l.sasl_external_bind_s()
self.assertEqual(l.whoami_s(), 'dn:'+self.server.root_dn.lower())
Expand All @@ -343,6 +343,27 @@ def test006_sasl_extenal_bind_s(self):
l.sasl_external_bind_s(authz_id=authz_id)
self.assertEqual(l.whoami_s(), authz_id.lower())

@requires_sasl()
@requires_ldapi()
def test006_sasl_options(self):
l = self.ldap_object_class(self.server.ldapi_uri)

minssf = l.get_option(ldap.OPT_X_SASL_SSF_MIN)
self.assertGreaterEqual(minssf, 0)
self.assertLessEqual(minssf, 256)
maxssf = l.get_option(ldap.OPT_X_SASL_SSF_MAX)
self.assertGreaterEqual(maxssf, 0)
# libldap sets SSF_MAX to INT_MAX
self.assertLessEqual(maxssf, 2**31 - 1)

l.set_option(ldap.OPT_X_SASL_SSF_MIN, 56)
l.set_option(ldap.OPT_X_SASL_SSF_MAX, 256)
self.assertEqual(l.get_option(ldap.OPT_X_SASL_SSF_MIN), 56)
self.assertEqual(l.get_option(ldap.OPT_X_SASL_SSF_MAX), 256)

l.sasl_external_bind_s()
self.assertEqual(l.whoami_s(), 'dn:' + self.server.root_dn.lower())

def test007_timeout(self):
l = self.ldap_object_class(self.server.ldap_uri)
m = l.search_ext(self.server.suffix, ldap.SCOPE_SUBTREE, '(objectClass=*)')
Expand Down