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

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