andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone

Blame SOURCES/0039-Ticket-49474-sasl-allow-mechs-does-not-operate-corre.patch

96373c
From bfaf5b56bb1a416c5e058a9925642098c87e0330 Mon Sep 17 00:00:00 2001
96373c
From: William Brown <firstyear@redhat.com>
96373c
Date: Thu, 30 Nov 2017 14:06:59 +0100
96373c
Subject: [PATCH] Ticket 49474 - sasl allow mechs does not operate correctly
96373c
96373c
Bug Description:  In a fix to sasl allowed mechs, the logic
96373c
was not properly configured.
96373c
96373c
Fix Description:  Alter the ids_sasl_supported_mech to be
96373c
clearer and simpler in it's design.
96373c
96373c
https://pagure.io/389-ds-base/issue/49474
96373c
96373c
Author: wibrown
96373c
96373c
Review by: tbordaz (Thank you!)
96373c
96373c
Cherry picked from f75cfbce07b79272a7f1a2e387dc232d45c169f5
96373c
---
96373c
 ldap/servers/slapd/saslbind.c | 49 ++++++++-----------------------------------
96373c
 1 file changed, 9 insertions(+), 40 deletions(-)
96373c
96373c
diff --git a/ldap/servers/slapd/saslbind.c b/ldap/servers/slapd/saslbind.c
96373c
index 6734c32a7..67da97148 100644
96373c
--- a/ldap/servers/slapd/saslbind.c
96373c
+++ b/ldap/servers/slapd/saslbind.c
96373c
@@ -835,52 +835,21 @@ ids_sasl_listmech(Slapi_PBlock *pb)
96373c
 static int
96373c
 ids_sasl_mech_supported(Slapi_PBlock *pb, const char *mech)
96373c
 {
96373c
-    int i, ret = 0;
96373c
-    char **mechs;
96373c
-    char **allowed_mechs = NULL;
96373c
-    char *dupstr;
96373c
-    const char *str;
96373c
-    int sasl_result = 0;
96373c
-    Connection *pb_conn = NULL;
96373c
-
96373c
-    slapi_pblock_get(pb, SLAPI_CONNECTION, &pb_conn);
96373c
-    sasl_conn_t *sasl_conn = (sasl_conn_t *)pb_conn->c_sasl_conn;
96373c
     slapi_log_err(SLAPI_LOG_TRACE, "ids_sasl_mech_supported", "=>\n");
96373c
 
96373c
-    /* sasl_listmech is not thread-safe - caller must lock pb_conn */
96373c
-    sasl_result = sasl_listmech(sasl_conn,
96373c
-                                NULL, /* username */
96373c
-                                "", ",", "",
96373c
-                                &str, NULL, NULL);
96373c
-    if (sasl_result != SASL_OK) {
96373c
-        return 0;
96373c
-    }
96373c
-
96373c
-    dupstr = slapi_ch_strdup(str);
96373c
-    mechs = slapi_str2charray(dupstr, ",");
96373c
-    allowed_mechs = config_get_allowed_sasl_mechs_array();
96373c
+    char **allowed_mechs = ids_sasl_listmech(pb);
96373c
 
96373c
-    for (i = 0; mechs[i] != NULL; i++) {
96373c
-        if (strcasecmp(mech, mechs[i]) == 0) {
96373c
-            if (allowed_mechs) {
96373c
-                if (charray_inlist(allowed_mechs, (char *)mech) == 0) {
96373c
-                    ret = 1;
96373c
-                }
96373c
-                break;
96373c
-            } else {
96373c
-                ret = 1;
96373c
-                break;
96373c
-            }
96373c
-        }
96373c
+    /* 0 indicates "now allowed" */
96373c
+    int allowed_mech_present = 0;
96373c
+    if (allowed_mechs != NULL) {
96373c
+        /* Returns 1 if present and allowed. */
96373c
+        allowed_mech_present = charray_inlist(allowed_mechs, (char *)mech);
96373c
+        charray_free(allowed_mechs);
96373c
     }
96373c
 
96373c
-    charray_free(allowed_mechs);
96373c
-    charray_free(mechs);
96373c
-    slapi_ch_free((void **)&dupstr);
96373c
-
96373c
     slapi_log_err(SLAPI_LOG_TRACE, "ids_sasl_mech_supported", "<=\n");
96373c
 
96373c
-    return ret;
96373c
+    return allowed_mech_present;
96373c
 }
96373c
 
96373c
 /*
96373c
@@ -944,7 +913,7 @@ ids_sasl_check_bind(Slapi_PBlock *pb)
96373c
      * different error code to SASL_NOMECH.  Must be called
96373c
      * while holding the pb_conn lock
96373c
      */
96373c
-    if (!ids_sasl_mech_supported(pb, mech)) {
96373c
+    if (ids_sasl_mech_supported(pb, mech) == 0) {
96373c
         rc = SASL_NOMECH;
96373c
         goto sasl_check_result;
96373c
     }
96373c
-- 
96373c
2.13.6
96373c