Skip to content

Commit fc77d6c

Browse files
committed
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 <cheimes@redhat.com>
1 parent 69867f5 commit fc77d6c

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;
@@ -89,10 +93,6 @@ LDAP_set_option(LDAPObject *self, int option, PyObject *value)
8993
case LDAP_OPT_X_TLS_PROTOCOL_MIN:
9094
#endif
9195
#endif
92-
#ifdef HAVE_SASL
93-
case LDAP_OPT_X_SASL_SSF_MIN:
94-
case LDAP_OPT_X_SASL_SSF_MAX:
95-
#endif
9696
#ifdef LDAP_OPT_X_KEEPALIVE_IDLE
9797
case LDAP_OPT_X_KEEPALIVE_IDLE:
9898
#endif
@@ -108,6 +108,16 @@ LDAP_set_option(LDAPObject *self, int option, PyObject *value)
108108
return 0;
109109
ptr = &intval;
110110
break;
111+
112+
#ifdef HAVE_SASL
113+
case LDAP_OPT_X_SASL_SSF_MIN:
114+
case LDAP_OPT_X_SASL_SSF_MAX:
115+
if (!PyArg_Parse(value, "k:set_option", &blen))
116+
return 0;
117+
ptr = &blen;
118+
break;
119+
#endif
120+
111121
case LDAP_OPT_HOST_NAME:
112122
case LDAP_OPT_URI:
113123
#ifdef LDAP_OPT_DEFBASE
@@ -135,6 +145,7 @@ LDAP_set_option(LDAPObject *self, int option, PyObject *value)
135145
return 0;
136146
ptr = strval;
137147
break;
148+
138149
case LDAP_OPT_TIMEOUT:
139150
case LDAP_OPT_NETWORK_TIMEOUT:
140151
/* Float valued timeval options */
@@ -239,6 +250,10 @@ LDAP_get_option(LDAPObject *self, int option)
239250
LDAPAPIInfo apiinfo;
240251
LDAPControl **lcs;
241252
char *strval;
253+
#if HAVE_SASL
254+
/* unsigned long */
255+
ber_len_t blen;
256+
#endif
242257
PyObject *extensions, *v;
243258
Py_ssize_t i, num_extensions;
244259

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

278293
return v;
279294

280-
#ifdef HAVE_SASL
281-
case LDAP_OPT_X_SASL_SSF:
282-
#endif
283295
case LDAP_OPT_REFERRALS:
284296
case LDAP_OPT_RESTART:
285297
case LDAP_OPT_DEREF:
@@ -299,10 +311,6 @@ LDAP_get_option(LDAPObject *self, int option)
299311
case LDAP_OPT_X_TLS_PROTOCOL_MIN:
300312
#endif
301313
#endif
302-
#ifdef HAVE_SASL
303-
case LDAP_OPT_X_SASL_SSF_MIN:
304-
case LDAP_OPT_X_SASL_SSF_MAX:
305-
#endif
306314
#ifdef LDAP_OPT_X_SASL_NOCANON
307315
case LDAP_OPT_X_SASL_NOCANON:
308316
#endif
@@ -324,6 +332,17 @@ LDAP_get_option(LDAPObject *self, int option)
324332
return option_error(res, "ldap_get_option");
325333
return PyInt_FromLong(intval);
326334

335+
#ifdef HAVE_SASL
336+
case LDAP_OPT_X_SASL_SSF:
337+
case LDAP_OPT_X_SASL_SSF_MIN:
338+
case LDAP_OPT_X_SASL_SSF_MAX:
339+
/* ber_len_t options (unsigned long)*/
340+
res = LDAP_int_get_option(self, option, &blen);
341+
if (res != LDAP_OPT_SUCCESS)
342+
return option_error(res, "ldap_get_option");
343+
return PyLong_FromUnsignedLong(blen);
344+
#endif
345+
327346
case LDAP_OPT_HOST_NAME:
328347
case LDAP_OPT_URI:
329348
#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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy