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

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