Fix SASL get/set options on big endian platforms · python-ldap/python-ldap@84bbf5e · GitHub
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 <cheimes@redhat.com>
1 parent 2fc51b2 commit 84bbf5e

3 files changed

Lines changed: 53 additions & 12 deletions

File tree

LICENCE.MIT

Lines changed: 1 addition & 0 deletions

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

0 commit comments

Comments
 (0)