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

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