Blame SOURCES/0021-fix-for-cve-2017-2668-simple-return-text-if-suffix-n.patch

b69e47
From ea60248d99abb8fed9f7a2b1ab7325c5523b8562 Mon Sep 17 00:00:00 2001
b69e47
From: Ludwig Krispenz <lkrispen@redhat.com>
b69e47
Date: Mon, 3 Apr 2017 09:32:20 +0200
b69e47
Subject: [PATCH] fix for cve 2017-2668 - simple return text if suffix not
b69e47
 found
b69e47
b69e47
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1436575
b69e47
b69e47
Signed-off-by: Mark Reynolds <mreynolds@redhat.com>
b69e47
---
b69e47
 ldap/servers/slapd/defbackend.c | 75 ++---------------------------------------
b69e47
 1 file changed, 2 insertions(+), 73 deletions(-)
b69e47
b69e47
diff --git a/ldap/servers/slapd/defbackend.c b/ldap/servers/slapd/defbackend.c
b69e47
index 6fd74a3..6cd2c04 100644
b69e47
--- a/ldap/servers/slapd/defbackend.c
b69e47
+++ b/ldap/servers/slapd/defbackend.c
b69e47
@@ -166,50 +166,7 @@ defbackend_abandon( Slapi_PBlock *pb )
b69e47
 }
b69e47
 
b69e47
 
b69e47
-#define DEFBE_NO_SUCH_SUFFIX "No such suffix"
b69e47
-/*
b69e47
- * Generate a "No such suffix" return text
b69e47
- * Example:
b69e47
- *   cn=X,dc=bogus,dc=com ==> "No such suffix (dc=bogus,dc=com)" 
b69e47
- *     if the last rdn starts with "dc=", print all last dc= rdn's.
b69e47
- *   cn=X,cn=bogus ==> "No such suffix (cn=bogus)"
b69e47
- *     otherwise, print the very last rdn.
b69e47
- *   cn=X,z=bogus ==> "No such suffix (x=bogus)"
b69e47
- *     it is true even if it is an invalid rdn.
b69e47
- *   cn=X,bogus ==> "No such suffix (bogus)"
b69e47
- *     another example of invalid rdn.
b69e47
- */
b69e47
-static void
b69e47
-_defbackend_gen_returntext(char *buffer, size_t buflen, char **dns)
b69e47
-{
b69e47
-    int dnidx;
b69e47
-    int sidx;
b69e47
-    struct suffix_repeat {
b69e47
-        char *suffix;
b69e47
-        int size;
b69e47
-    } candidates[] = {
b69e47
-        {"dc=", 3}, /* dc could be repeated.  otherwise the last rdn is used. */
b69e47
-        {NULL, 0}
b69e47
-    };
b69e47
-    PR_snprintf(buffer, buflen, "%s (", DEFBE_NO_SUCH_SUFFIX);
b69e47
-    for (dnidx = 0; dns[dnidx]; dnidx++) ; /* finding the last */
b69e47
-    dnidx--; /* last rdn */
b69e47
-    for (sidx = 0; candidates[sidx].suffix; sidx++) {
b69e47
-        if (!PL_strncasecmp(dns[dnidx], candidates[sidx].suffix, candidates[sidx].size)) {
b69e47
-            while (!PL_strncasecmp(dns[--dnidx], candidates[sidx].suffix, candidates[sidx].size)) ;
b69e47
-            PL_strcat(buffer, dns[++dnidx]); /* the first "dn=", e.g. */
b69e47
-            for (++dnidx; dns[dnidx]; dnidx++) {
b69e47
-                PL_strcat(buffer, ",");
b69e47
-                PL_strcat(buffer, dns[dnidx]);
b69e47
-            }
b69e47
-            PL_strcat(buffer, ")");
b69e47
-            return; /* finished the task */
b69e47
-        }
b69e47
-    }
b69e47
-    PL_strcat(buffer, dns[dnidx]);
b69e47
-    PL_strcat(buffer, ")");
b69e47
-    return;
b69e47
-}
b69e47
+#define DEFBE_NO_SUCH_SUFFIX "No suffix for bind dn found"
b69e47
 
b69e47
 static int
b69e47
 defbackend_bind( Slapi_PBlock *pb )
b69e47
@@ -231,36 +188,8 @@ defbackend_bind( Slapi_PBlock *pb )
b69e47
         slapi_counter_increment(g_get_global_snmp_vars()->ops_tbl.dsAnonymousBinds);
b69e47
         rc = SLAPI_BIND_ANONYMOUS;
b69e47
     } else {
b69e47
-        Slapi_DN *sdn = NULL;
b69e47
-        char *suffix = NULL;
b69e47
-        char **dns = NULL;
b69e47
-        
b69e47
-        if (pb->pb_op) {
b69e47
-            sdn = operation_get_target_spec(pb->pb_op);
b69e47
-            if (sdn) {
b69e47
-                dns = slapi_ldap_explode_dn(slapi_sdn_get_dn(sdn), 0);
b69e47
-                if (dns) {
b69e47
-                    size_t dnlen = slapi_sdn_get_ndn_len(sdn);
b69e47
-                    size_t len = dnlen + sizeof(DEFBE_NO_SUCH_SUFFIX) + 4;
b69e47
-                    suffix = slapi_ch_malloc(len);
b69e47
-                    if (dnlen) {
b69e47
-                        _defbackend_gen_returntext(suffix, len, dns);
b69e47
-                    } else {
b69e47
-                        PR_snprintf(suffix, len, "%s", DEFBE_NO_SUCH_SUFFIX);
b69e47
-                    }
b69e47
-                }
b69e47
-            }
b69e47
-        }
b69e47
-        if (suffix) {
b69e47
-            slapi_pblock_set(pb, SLAPI_PB_RESULT_TEXT, suffix);
b69e47
-        } else {
b69e47
-            slapi_pblock_set(pb, SLAPI_PB_RESULT_TEXT, DEFBE_NO_SUCH_SUFFIX);
b69e47
-        }
b69e47
+        slapi_pblock_set(pb, SLAPI_PB_RESULT_TEXT, DEFBE_NO_SUCH_SUFFIX);
b69e47
         send_ldap_result(pb, LDAP_INVALID_CREDENTIALS, NULL, "", 0, NULL);
b69e47
-        if (dns) {
b69e47
-            slapi_ldap_value_free(dns);
b69e47
-        }
b69e47
-        slapi_ch_free_string(&suffix);
b69e47
         rc = SLAPI_BIND_FAIL;
b69e47
     }
b69e47
 
b69e47
-- 
b69e47
2.9.3
b69e47