Blame SOURCES/0001-Fix-SASL-get-set-options-on-big-endian-platforms.patch

b415e9
From 30fb0a8bda8fbedc22de87b21b8b1b64de310a6b Mon Sep 17 00:00:00 2001
b415e9
From: Christian Heimes <cheimes@redhat.com>
b415e9
Date: Mon, 28 Jun 2021 11:03:02 +0200
b415e9
Subject: [PATCH] Fix SASL get/set options on big endian platforms
b415e9
b415e9
The options OPT_X_SASL_SSF_MIN, OPT_X_SASL_SSF_MAX, and OPT_X_SASL_SSF
b415e9
take *ber_len_t as input and output arguments. ber_len_t is defined as
b415e9
unsigned long:
b415e9
b415e9
```
b415e9
    /* LBER lengths (32 bits or larger) */
b415e9
    #define LBER_LEN_T long
b415e9
b415e9
    typedef unsigned LBER_LEN_T ber_len_t;
b415e9
```
b415e9
b415e9
Wrong type handling is causing issues on big endian platforms.
b415e9
b415e9
Signed-off-by: Christian Heimes <cheimes@redhat.com>
b415e9
---
b415e9
 Modules/options.c     | 41 ++++++++++++++++++++++++++++++-----------
b415e9
 Tests/t_ldapobject.py | 23 ++++++++++++++++++++++-
b415e9
 2 files changed, 52 insertions(+), 12 deletions(-)
b415e9
b415e9
diff --git a/Modules/options.c b/Modules/options.c
b415e9
index 549a672..67511e8 100644
b415e9
--- a/Modules/options.c
b415e9
+++ b/Modules/options.c
b415e9
@@ -43,6 +43,10 @@ LDAP_set_option(LDAPObject *self, int option, PyObject *value)
b415e9
     double doubleval;
b415e9
     char *strval;
b415e9
     struct timeval tv;
b415e9
+#if HAVE_SASL
b415e9
+    /* unsigned long */
b415e9
+    ber_len_t blen;
b415e9
+#endif
b415e9
     void *ptr;
b415e9
     LDAP *ld;
b415e9
     LDAPControl **controls = NULL;
b415e9
@@ -89,10 +93,6 @@ LDAP_set_option(LDAPObject *self, int option, PyObject *value)
b415e9
     case LDAP_OPT_X_TLS_PROTOCOL_MIN:
b415e9
 #endif
b415e9
 #endif
b415e9
-#ifdef HAVE_SASL
b415e9
-    case LDAP_OPT_X_SASL_SSF_MIN:
b415e9
-    case LDAP_OPT_X_SASL_SSF_MAX:
b415e9
-#endif
b415e9
 #ifdef LDAP_OPT_X_KEEPALIVE_IDLE
b415e9
     case LDAP_OPT_X_KEEPALIVE_IDLE:
b415e9
 #endif
b415e9
@@ -108,6 +108,16 @@ LDAP_set_option(LDAPObject *self, int option, PyObject *value)
b415e9
             return 0;
b415e9
         ptr = &intval;
b415e9
         break;
b415e9
+
b415e9
+#ifdef HAVE_SASL
b415e9
+    case LDAP_OPT_X_SASL_SSF_MIN:
b415e9
+    case LDAP_OPT_X_SASL_SSF_MAX:
b415e9
+        if (!PyArg_Parse(value, "k:set_option", &blen))
b415e9
+            return 0;
b415e9
+        ptr = &ble;;
b415e9
+        break;
b415e9
+#endif
b415e9
+
b415e9
     case LDAP_OPT_HOST_NAME:
b415e9
     case LDAP_OPT_URI:
b415e9
 #ifdef LDAP_OPT_DEFBASE
b415e9
@@ -135,6 +145,7 @@ LDAP_set_option(LDAPObject *self, int option, PyObject *value)
b415e9
             return 0;
b415e9
         ptr = strval;
b415e9
         break;
b415e9
+
b415e9
     case LDAP_OPT_TIMEOUT:
b415e9
     case LDAP_OPT_NETWORK_TIMEOUT:
b415e9
         /* Float valued timeval options */
b415e9
@@ -239,6 +250,10 @@ LDAP_get_option(LDAPObject *self, int option)
b415e9
     LDAPAPIInfo apiinfo;
b415e9
     LDAPControl **lcs;
b415e9
     char *strval;
b415e9
+#if HAVE_SASL
b415e9
+    /* unsigned long */
b415e9
+    ber_len_t blen;
b415e9
+#endif
b415e9
     PyObject *extensions, *v;
b415e9
     Py_ssize_t i, num_extensions;
b415e9
 
b415e9
@@ -277,9 +292,6 @@ LDAP_get_option(LDAPObject *self, int option)
b415e9
 
b415e9
         return v;
b415e9
 
b415e9
-#ifdef HAVE_SASL
b415e9
-    case LDAP_OPT_X_SASL_SSF:
b415e9
-#endif
b415e9
     case LDAP_OPT_REFERRALS:
b415e9
     case LDAP_OPT_RESTART:
b415e9
     case LDAP_OPT_DEREF:
b415e9
@@ -299,10 +311,6 @@ LDAP_get_option(LDAPObject *self, int option)
b415e9
     case LDAP_OPT_X_TLS_PROTOCOL_MIN:
b415e9
 #endif
b415e9
 #endif
b415e9
-#ifdef HAVE_SASL
b415e9
-    case LDAP_OPT_X_SASL_SSF_MIN:
b415e9
-    case LDAP_OPT_X_SASL_SSF_MAX:
b415e9
-#endif
b415e9
 #ifdef LDAP_OPT_X_SASL_NOCANON
b415e9
     case LDAP_OPT_X_SASL_NOCANON:
b415e9
 #endif
b415e9
@@ -324,6 +332,17 @@ LDAP_get_option(LDAPObject *self, int option)
b415e9
             return option_error(res, "ldap_get_option");
b415e9
         return PyInt_FromLong(intval);
b415e9
 
b415e9
+#ifdef HAVE_SASL
b415e9
+    case LDAP_OPT_X_SASL_SSF:
b415e9
+    case LDAP_OPT_X_SASL_SSF_MIN:
b415e9
+    case LDAP_OPT_X_SASL_SSF_MAX:
b415e9
+#endif
b415e9
+        /* ber_len_t options (unsigned long)*/
b415e9
+        res = LDAP_int_get_option(self, option, &blen);
b415e9
+        if (res != LDAP_OPT_SUCCESS)
b415e9
+            return option_error(res, "ldap_get_option");
b415e9
+        return PyLong_FromUnsignedLong(blen);
b415e9
+
b415e9
     case LDAP_OPT_HOST_NAME:
b415e9
     case LDAP_OPT_URI:
b415e9
 #ifdef LDAP_OPT_DEFBASE
b415e9
diff --git a/Tests/t_ldapobject.py b/Tests/t_ldapobject.py
b415e9
index e54bbfd..0a089c9 100644
b415e9
--- a/Tests/t_ldapobject.py
b415e9
+++ b/Tests/t_ldapobject.py
b415e9
@@ -334,7 +334,7 @@ class Test00_SimpleLDAPObject(SlapdTestCase):
b415e9
 
b415e9
     @requires_sasl()
b415e9
     @requires_ldapi()
b415e9
-    def test006_sasl_extenal_bind_s(self):
b415e9
+    def test006_sasl_external_bind_s(self):
b415e9
         l = self.ldap_object_class(self.server.ldapi_uri)
b415e9
         l.sasl_external_bind_s()
b415e9
         self.assertEqual(l.whoami_s(), 'dn:'+self.server.root_dn.lower())
b415e9
@@ -343,6 +343,27 @@ class Test00_SimpleLDAPObject(SlapdTestCase):
b415e9
         l.sasl_external_bind_s(authz_id=authz_id)
b415e9
         self.assertEqual(l.whoami_s(), authz_id.lower())
b415e9
 
b415e9
+    @requires_sasl()
b415e9
+    @requires_ldapi()
b415e9
+    def test006_sasl_options(self):
b415e9
+        l = self.ldap_object_class(self.server.ldapi_uri)
b415e9
+
b415e9
+        minssf = l.get_option(ldap.OPT_X_SASL_SSF_MIN)
b415e9
+        self.assertGreaterEqual(minssf, 0)
b415e9
+        self.assertLessEqual(minssf, 256)
b415e9
+        maxssf = l.get_option(ldap.OPT_X_SASL_SSF_MAX)
b415e9
+        self.assertGreaterEqual(maxssf, 0)
b415e9
+        # libldap sets SSF_MAX to INT_MAX
b415e9
+        self.assertLessEqual(maxssf, 2**31 - 1)
b415e9
+
b415e9
+        l.set_option(ldap.OPT_X_SASL_SSF_MIN, 56)
b415e9
+        l.set_option(ldap.OPT_X_SASL_SSF_MAX, 256)
b415e9
+        self.assertEqual(l.get_option(ldap.OPT_X_SASL_SSF_MIN), 56)
b415e9
+        self.assertEqual(l.get_option(ldap.OPT_X_SASL_SSF_MAX), 256)
b415e9
+
b415e9
+        l.sasl_external_bind_s()
b415e9
+        self.assertEqual(l.whoami_s(), 'dn:' + self.server.root_dn.lower())
b415e9
+
b415e9
     def test007_timeout(self):
b415e9
         l = self.ldap_object_class(self.server.ldap_uri)
b415e9
         m = l.search_ext(self.server.suffix, ldap.SCOPE_SUBTREE, '(objectClass=*)')
b415e9
-- 
b415e9
2.31.1
b415e9