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

Skip to content

Commit 84bbf5e

Browse files
tiranencukou
authored andcommitted
Fix SASL get/set options on big endian platforms
The options OPT_X_SASL_SSF_MIN, OPT_X_SASL_SSF_MAX, and OPT_X_SASL_SSF take *ber_len_t as input and output arguments. ber_len_t is defined as unsigned long: ``` /* LBER lengths (32 bits or larger) */ #define LBER_LEN_T long typedef unsigned LBER_LEN_T ber_len_t; ``` Wrong type handling is causing issues on big endian platforms. Signed-off-by: Christian Heimes <[email protected]>
1 parent 2fc51b2 commit 84bbf5e

File tree

3 files changed

+53
-12
lines changed

3 files changed

+53
-12
lines changed

LICENCE.MIT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ to all contributions by the following authors:
66
* Aymeric Augustin
77
* Bernhard M. Wiedemann
88
* Bradley Baetz
9+
* Christian Heimes
910
* Éloi Rivard
1011
* Eyal Cherevatzki
1112
* Fred Thomsen

Modules/options.c

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ LDAP_set_option(LDAPObject *self, int option, PyObject *value)
4343
double doubleval;
4444
char *strval;
4545
struct timeval tv;
46+
#if HAVE_SASL
47+
/* unsigned long */
48+
ber_len_t blen;
49+
#endif
4650
void *ptr;
4751
LDAP *ld;
4852
LDAPControl **controls = NULL;
@@ -92,10 +96,6 @@ LDAP_set_option(LDAPObject *self, int option, PyObject *value)
9296
case LDAP_OPT_X_TLS_REQUIRE_SAN:
9397
#endif
9498
#endif
95-
#ifdef HAVE_SASL
96-
case LDAP_OPT_X_SASL_SSF_MIN:
97-
case LDAP_OPT_X_SASL_SSF_MAX:
98-
#endif
9999
#ifdef LDAP_OPT_X_KEEPALIVE_IDLE
100100
case LDAP_OPT_X_KEEPALIVE_IDLE:
101101
#endif
@@ -111,6 +111,16 @@ LDAP_set_option(LDAPObject *self, int option, PyObject *value)
111111
return 0;
112112
ptr = &intval;
113113
break;
114+
115+
#ifdef HAVE_SASL
116+
case LDAP_OPT_X_SASL_SSF_MIN:
117+
case LDAP_OPT_X_SASL_SSF_MAX:
118+
if (!PyArg_Parse(value, "k:set_option", &blen))
119+
return 0;
120+
ptr = &blen;
121+
break;
122+
#endif
123+
114124
case LDAP_OPT_HOST_NAME:
115125
case LDAP_OPT_URI:
116126
#ifdef LDAP_OPT_DEFBASE
@@ -138,6 +148,7 @@ LDAP_set_option(LDAPObject *self, int option, PyObject *value)
138148
return 0;
139149
ptr = strval;
140150
break;
151+
141152
case LDAP_OPT_TIMEOUT:
142153
case LDAP_OPT_NETWORK_TIMEOUT:
143154
/* Float valued timeval options */
@@ -242,6 +253,10 @@ LDAP_get_option(LDAPObject *self, int option)
242253
LDAPAPIInfo apiinfo;
243254
LDAPControl **lcs;
244255
char *strval;
256+
#if HAVE_SASL
257+
/* unsigned long */
258+
ber_len_t blen;
259+
#endif
245260
PyObject *extensions, *v;
246261
Py_ssize_t i, num_extensions;
247262

@@ -280,9 +295,6 @@ LDAP_get_option(LDAPObject *self, int option)
280295

281296
return v;
282297

283-
#ifdef HAVE_SASL
284-
case LDAP_OPT_X_SASL_SSF:
285-
#endif
286298
case LDAP_OPT_REFERRALS:
287299
case LDAP_OPT_RESTART:
288300
case LDAP_OPT_DEREF:
@@ -305,10 +317,6 @@ LDAP_get_option(LDAPObject *self, int option)
305317
case LDAP_OPT_X_TLS_REQUIRE_SAN:
306318
#endif
307319
#endif
308-
#ifdef HAVE_SASL
309-
case LDAP_OPT_X_SASL_SSF_MIN:
310-
case LDAP_OPT_X_SASL_SSF_MAX:
311-
#endif
312320
#ifdef LDAP_OPT_X_SASL_NOCANON
313321
case LDAP_OPT_X_SASL_NOCANON:
314322
#endif
@@ -330,6 +338,17 @@ LDAP_get_option(LDAPObject *self, int option)
330338
return option_error(res, "ldap_get_option");
331339
return PyInt_FromLong(intval);
332340

341+
#ifdef HAVE_SASL
342+
case LDAP_OPT_X_SASL_SSF:
343+
case LDAP_OPT_X_SASL_SSF_MIN:
344+
case LDAP_OPT_X_SASL_SSF_MAX:
345+
/* ber_len_t options (unsigned long)*/
346+
res = LDAP_int_get_option(self, option, &blen);
347+
if (res != LDAP_OPT_SUCCESS)
348+
return option_error(res, "ldap_get_option");
349+
return PyLong_FromUnsignedLong(blen);
350+
#endif
351+
333352
case LDAP_OPT_HOST_NAME:
334353
case LDAP_OPT_URI:
335354
#ifdef LDAP_OPT_DEFBASE

Tests/t_ldapobject.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def test005_invalid_credentials(self):
334334

335335
@requires_sasl()
336336
@requires_ldapi()
337-
def test006_sasl_extenal_bind_s(self):
337+
def test006_sasl_external_bind_s(self):
338338
l = self.ldap_object_class(self.server.ldapi_uri)
339339
l.sasl_external_bind_s()
340340
self.assertEqual(l.whoami_s(), 'dn:'+self.server.root_dn.lower())
@@ -343,6 +343,27 @@ def test006_sasl_extenal_bind_s(self):
343343
l.sasl_external_bind_s(authz_id=authz_id)
344344
self.assertEqual(l.whoami_s(), authz_id.lower())
345345

346+
@requires_sasl()
347+
@requires_ldapi()
348+
def test006_sasl_options(self):
349+
l = self.ldap_object_class(self.server.ldapi_uri)
350+
351+
minssf = l.get_option(ldap.OPT_X_SASL_SSF_MIN)
352+
self.assertGreaterEqual(minssf, 0)
353+
self.assertLessEqual(minssf, 256)
354+
maxssf = l.get_option(ldap.OPT_X_SASL_SSF_MAX)
355+
self.assertGreaterEqual(maxssf, 0)
356+
# libldap sets SSF_MAX to INT_MAX
357+
self.assertLessEqual(maxssf, 2**31 - 1)
358+
359+
l.set_option(ldap.OPT_X_SASL_SSF_MIN, 56)
360+
l.set_option(ldap.OPT_X_SASL_SSF_MAX, 256)
361+
self.assertEqual(l.get_option(ldap.OPT_X_SASL_SSF_MIN), 56)
362+
self.assertEqual(l.get_option(ldap.OPT_X_SASL_SSF_MAX), 256)
363+
364+
l.sasl_external_bind_s()
365+
self.assertEqual(l.whoami_s(), 'dn:' + self.server.root_dn.lower())
366+
346367
def test007_timeout(self):
347368
l = self.ldap_object_class(self.server.ldap_uri)
348369
m = l.search_ext(self.server.suffix, ldap.SCOPE_SUBTREE, '(objectClass=*)')

0 commit comments

Comments
 (0)