Blame SOURCES/0045-Ticket-49509-Indexing-of-internationalized-matching-.patch

058656
From 8d79d7c81157e77f4da595a723a6ed10a8e9789b Mon Sep 17 00:00:00 2001
fb1149
From: Thierry Bordaz <tbordaz@redhat.com>
058656
Date: Thu, 11 Jan 2018 18:52:43 +0100
fb1149
Subject: [PATCH] Ticket 49509 - Indexing of internationalized matching rules
fb1149
 is failing
fb1149
fb1149
Bug Description:
058656
    Indexing of the internationalized matching rules tests if a
058656
    matching rule indexer handle or not a given OID.
058656
    A side effect of https://pagure.io/389-ds-base/issue/49097 is that
058656
    the returned indexing callbacks are lost.
058656
    Indeed, the indexing callbacks (and potentially others fields) were
058656
    stored in the temporary pblock that was memcpy to the provided
058656
    pblock in case of success
fb1149
fb1149
Fix Description:
058656
    The fix basically restores the previous behavior but do not
058656
    memcpy pblock. It read/store the pblock fields that are
058656
    inputs/outputs of slapi_mr_indexer_create.
fb1149
fb1149
https://pagure.io/389-ds-base/issue/49509
fb1149
fb1149
Reviewed by: Ludwig Krispenz
fb1149
fb1149
Platforms tested: F23
fb1149
fb1149
Flag Day: no
fb1149
fb1149
Doc impact: no
fb1149
---
058656
 ldap/servers/slapd/plugin_mr.c | 148 ++++++++++++++++++++++++++++-------------
058656
 1 file changed, 103 insertions(+), 45 deletions(-)
fb1149
fb1149
diff --git a/ldap/servers/slapd/plugin_mr.c b/ldap/servers/slapd/plugin_mr.c
058656
index bd2baff6c..ca4fe00e1 100644
fb1149
--- a/ldap/servers/slapd/plugin_mr.c
fb1149
+++ b/ldap/servers/slapd/plugin_mr.c
058656
@@ -143,6 +143,82 @@ plugin_mr_bind(char *oid, struct slapdplugin *plugin)
058656
     slapi_log_err(SLAPI_LOG_FILTER, "plugin_mr_bind", "<=\n");
fb1149
 }
fb1149
 
fb1149
+void
fb1149
+mr_indexer_init_pb(Slapi_PBlock* src_pb, Slapi_PBlock* dst_pb)
fb1149
+{
fb1149
+    char* oid;
fb1149
+    char *type;
fb1149
+    uint32_t usage;
fb1149
+    void *object;
fb1149
+    IFP destroyFn;
fb1149
+    IFP indexFn, indexSvFn;
058656
+
fb1149
+    /* matching rule plugin arguments */
fb1149
+    slapi_pblock_get(src_pb, SLAPI_PLUGIN_MR_OID,             &oid);
fb1149
+    slapi_pblock_get(src_pb, SLAPI_PLUGIN_MR_TYPE,            &type);
fb1149
+    slapi_pblock_get(src_pb, SLAPI_PLUGIN_MR_USAGE,           &usage);
058656
+
fb1149
+    slapi_pblock_set(dst_pb, SLAPI_PLUGIN_MR_OID,             oid);
fb1149
+    slapi_pblock_set(dst_pb, SLAPI_PLUGIN_MR_TYPE,            type);
fb1149
+    slapi_pblock_set(dst_pb, SLAPI_PLUGIN_MR_USAGE,           &usage);
058656
+
fb1149
+    /* matching rule plugin functions */
fb1149
+    slapi_pblock_get(src_pb, SLAPI_PLUGIN_MR_INDEX_FN,          &indexFn);
fb1149
+    slapi_pblock_get(src_pb, SLAPI_PLUGIN_MR_INDEX_SV_FN,       &indexSvFn);
058656
+
fb1149
+    slapi_pblock_set(dst_pb, SLAPI_PLUGIN_MR_INDEX_FN,          indexFn);
fb1149
+    slapi_pblock_set(dst_pb, SLAPI_PLUGIN_MR_INDEX_SV_FN,       indexSvFn);
fb1149
+
fb1149
+    /* common */
fb1149
+    slapi_pblock_get(src_pb, SLAPI_PLUGIN_OBJECT,        &object);
fb1149
+    slapi_pblock_get(src_pb, SLAPI_PLUGIN_DESTROY_FN,    &destroyFn);
fb1149
+
fb1149
+    slapi_pblock_set(dst_pb, SLAPI_PLUGIN_OBJECT,        object);
fb1149
+    slapi_pblock_set(dst_pb, SLAPI_PLUGIN_DESTROY_FN,    destroyFn);
fb1149
+
fb1149
+
fb1149
+}
fb1149
+
fb1149
+/*
fb1149
+ *  Retrieves the matching rule plugin able to index/sort the provided OID/type
058656
+ *
fb1149
+ *  The Matching rules able to index/sort a given OID are stored in a global list: global_mr_oids
fb1149
+ *
fb1149
+ *  The retrieval is done in 3 phases:
fb1149
+ *      - It first searches (in global_mr_oids) for the already bound OID->MR
fb1149
+ *      - Else, look first in old style MR plugin
fb1149
+ *        for each registered 'syntax' and 'matchingrule' plugins having a
fb1149
+ *        SLAPI_PLUGIN_MR_INDEXER_CREATE_FN, it binds (plugin_mr_bind) the first
fb1149
+ *        plugin that support the OID
fb1149
+ *      - Else, look in new style MR plugin
fb1149
+ *        for each registered 'syntax' and 'matchingrule' plugins, it binds (plugin_mr_bind) the first
fb1149
+ *        plugin that contains OID in its plg_mr_names
fb1149
+ *
fb1149
+ * Inputs:
fb1149
+ *  SLAPI_PLUGIN_MR_OID
fb1149
+ *      should contain the OID of the matching rule that you want used for indexing or sorting.
fb1149
+ *  SLAPI_PLUGIN_MR_TYPE
fb1149
+ *      should contain the attribute type that you want used for indexing or sorting.
fb1149
+ *  SLAPI_PLUGIN_MR_USAGE
fb1149
+ *      should specify if the indexer will be used for indexing (SLAPI_PLUGIN_MR_USAGE_INDEX)
fb1149
+ *      or for sorting (SLAPI_PLUGIN_MR_USAGE_SORT)
fb1149
+ *
fb1149
+ *
fb1149
+ * Output:
fb1149
+ *
fb1149
+ *  SLAPI_PLUGIN_MR_OID
fb1149
+ *      contain the OFFICIAL OID of the matching rule that you want used for indexing or sorting.
fb1149
+ *  SLAPI_PLUGIN_MR_INDEX_FN
fb1149
+ *      specifies the indexer function responsible for indexing or sorting of struct berval **
fb1149
+ *  SLAPI_PLUGIN_MR_INDEX_SV_FN
fb1149
+ *      specifies the indexer function responsible for indexing or sorting of Slapi_Value **
fb1149
+ *  SLAPI_PLUGIN_OBJECT
fb1149
+ *      contain any information that you want passed to the indexer function.
fb1149
+ *  SLAPI_PLUGIN_DESTROY_FN
fb1149
+ *      specifies the function responsible for freeing any memory allocated by this indexer factory function.
fb1149
+ *      For example, memory allocated for a structure that you pass to the indexer function using SLAPI_PLUGIN_OBJECT.
fb1149
+ *
fb1149
+ */
fb1149
 int /* an LDAP error code, hopefully LDAP_SUCCESS */
058656
     slapi_mr_indexer_create(Slapi_PBlock *opb)
fb1149
 {
058656
@@ -152,28 +228,33 @@ int /* an LDAP error code, hopefully LDAP_SUCCESS */
058656
         IFP createFn = NULL;
058656
         struct slapdplugin *mrp = plugin_mr_find_registered(oid);
058656
         if (mrp != NULL) {
fb1149
+            /* Great the matching OID -> MR plugin was already found, just reuse it */
058656
             if (!(rc = slapi_pblock_set(opb, SLAPI_PLUGIN, mrp)) &&
058656
                 !(rc = slapi_pblock_get(opb, SLAPI_PLUGIN_MR_INDEXER_CREATE_FN, &createFn)) &&
058656
                 createFn != NULL) {
058656
                 rc = createFn(opb);
058656
             }
058656
         } else {
058656
-            /* call each plugin, until one is able to handle this request. */
fb1149
+            /* We need to find in the MR plugins list, the MR plugin that will be able to handle OID
fb1149
+             *
fb1149
+             * It can be "old style" MR plugin (i.e. collation) that define indexer
fb1149
+             *
fb1149
+             * It can be "now style" MR plugin that contain OID string in 'plg_mr_names'
fb1149
+             * (ie. ces, cis, bin...) where plg_mr_names is defined in 'mr_plugin_table' in each file
fb1149
+             * ces.c, cis.c...
fb1149
+             * New style MR plugin have NULL indexer create function but rather use a default indexer
fb1149
+             */
fb1149
+
fb1149
+            /* Look for a old syntax-style mr plugin
fb1149
+             * call each plugin, until one is able to handle this request.
fb1149
+             */
058656
             rc = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
058656
-            // We need to get the type and usage from the caller.
058656
-            char *type;
058656
-            uint32_t usage;
058656
-            slapi_pblock_get(opb, SLAPI_PLUGIN_MR_TYPE, &type);
058656
-            slapi_pblock_get(opb, SLAPI_PLUGIN_MR_USAGE, &usage);
fb1149
+
058656
             for (mrp = get_plugin_list(PLUGIN_LIST_MATCHINGRULE); mrp != NULL; mrp = mrp->plg_next) {
058656
 
058656
                 Slapi_PBlock *pb = slapi_pblock_new();
fb1149
+                mr_indexer_init_pb(opb, pb);
058656
                 slapi_pblock_set(pb, SLAPI_PLUGIN, mrp);
058656
-                /* From filtercmp.c and matchrule.c, these are the values we need to set. into pb */
058656
-                slapi_pblock_set(pb, SLAPI_PLUGIN_MR_OID, oid);
058656
-                slapi_pblock_set(pb, SLAPI_PLUGIN_MR_TYPE, type);
058656
-                slapi_pblock_set(pb, SLAPI_PLUGIN_MR_USAGE, &usage);
058656
-
058656
                 /* This is associated with the pb_plugin struct, so it comes with mrp */
058656
                 if (slapi_pblock_get(pb, SLAPI_PLUGIN_MR_INDEXER_CREATE_FN, &createFn)) {
058656
                     /* plugin not a matchingrule type */
058656
@@ -185,14 +266,11 @@ int /* an LDAP error code, hopefully LDAP_SUCCESS */
058656
                     IFP indexFn = NULL;
058656
                     IFP indexSvFn = NULL;
058656
                     /* These however, are in the pblock direct, so we need to copy them. */
058656
-                    slapi_pblock_get(opb, SLAPI_PLUGIN_MR_INDEX_FN, &indexFn);
058656
-                    slapi_pblock_get(opb, SLAPI_PLUGIN_MR_INDEX_SV_FN, &indexSvFn);
058656
-                    slapi_pblock_set(pb, SLAPI_PLUGIN_MR_INDEX_FN, indexFn);
058656
-                    slapi_pblock_set(pb, SLAPI_PLUGIN_MR_INDEX_SV_FN, indexSvFn);
fb1149
+                    slapi_pblock_get(pb, SLAPI_PLUGIN_MR_INDEX_FN, &indexFn);
fb1149
+                    slapi_pblock_get(pb, SLAPI_PLUGIN_MR_INDEX_SV_FN, &indexSvFn);
058656
                     if (indexFn || indexSvFn) {
058656
                         /* Success: this plugin can handle it. */
058656
-                        /* call create on the opb? */
058656
-                        createFn(opb);
fb1149
+                        mr_indexer_init_pb(pb, opb);
058656
                         plugin_mr_bind(oid, mrp); /* for future reference */
058656
                         rc = 0;                   /* success */
058656
                         slapi_pblock_destroy(pb);
058656
@@ -205,37 +283,12 @@ int /* an LDAP error code, hopefully LDAP_SUCCESS */
058656
                 /* look for a new syntax-style mr plugin */
058656
                 struct slapdplugin *pi = plugin_mr_find(oid);
058656
                 if (pi) {
058656
-                    Slapi_PBlock *pb = slapi_pblock_new();
058656
-                    slapi_pblock_set(pb, SLAPI_PLUGIN_MR_OID, oid);
058656
-                    slapi_pblock_set(pb, SLAPI_PLUGIN_MR_TYPE, type);
058656
-                    slapi_pblock_set(pb, SLAPI_PLUGIN_MR_USAGE, &usage);
058656
-                    slapi_pblock_set(pb, SLAPI_PLUGIN, pi);
058656
-                    rc = default_mr_indexer_create(pb);
fb1149
+                    slapi_pblock_set(opb, SLAPI_PLUGIN, pi);
fb1149
+                    rc = default_mr_indexer_create(opb);
058656
                     if (!rc) {
058656
-                        /* On success, copy the needed values in. These are added by default_mr_indexer_create */
058656
-                        void *pb_object = NULL;
058656
-                        IFP destroy_fn = NULL;
058656
-                        IFP index_fn = NULL;
058656
-                        IFP index_sv_fn = NULL;
058656
-
058656
-                        slapi_pblock_get(pb, SLAPI_PLUGIN_OBJECT, &pb_object);
058656
-                        slapi_pblock_get(pb, SLAPI_PLUGIN_DESTROY_FN, &destroy_fn);
058656
-                        slapi_pblock_get(pb, SLAPI_PLUGIN_MR_INDEX_FN, &index_fn);
058656
-                        slapi_pblock_get(pb, SLAPI_PLUGIN_MR_INDEX_SV_FN, &index_sv_fn);
058656
-
058656
-                        /* SLAPI_PLUGIN_MR_INDEXER_CREATE_FN, and SLAPI_PLUGIN_MR_FILTER_CREATE_FN, are part of pb_plugin */
058656
-                        slapi_pblock_set(opb, SLAPI_PLUGIN, pi);
058656
-                        slapi_pblock_set(opb, SLAPI_PLUGIN_MR_OID, oid);
058656
-                        slapi_pblock_set(opb, SLAPI_PLUGIN_MR_TYPE, type);
058656
-                        slapi_pblock_set(opb, SLAPI_PLUGIN_MR_USAGE, &usage);
058656
-                        slapi_pblock_set(opb, SLAPI_PLUGIN_OBJECT, pb_object);
058656
-                        slapi_pblock_set(opb, SLAPI_PLUGIN_DESTROY_FN, destroy_fn);
058656
-                        slapi_pblock_set(opb, SLAPI_PLUGIN_MR_INDEX_FN, index_fn);
058656
-                        slapi_pblock_set(opb, SLAPI_PLUGIN_MR_INDEX_SV_FN, index_sv_fn);
058656
-
058656
                         plugin_mr_bind(oid, pi); /* for future reference */
058656
                     }
058656
-                    slapi_pblock_destroy(pb);
fb1149
+                    slapi_pblock_set(opb, SLAPI_PLUGIN, NULL);
058656
                 }
058656
             }
058656
         }
058656
@@ -706,6 +759,11 @@ default_mr_indexer_create(Slapi_PBlock *pb)
058656
     slapi_pblock_set(pb, SLAPI_PLUGIN_MR_INDEX_FN, mr_wrap_mr_index_fn);
058656
     slapi_pblock_set(pb, SLAPI_PLUGIN_MR_INDEX_SV_FN, mr_wrap_mr_index_sv_fn);
058656
     slapi_pblock_set(pb, SLAPI_PLUGIN_DESTROY_FN, default_mr_indexer_destroy);
fb1149
+
058656
+    /* Note the two following setting are in the slapdplugin struct SLAPI_PLUGIN
058656
+     * so they are not really output of the function but will just
058656
+     * be stored in the bound (OID <--> plugin) list (plugin_mr_find_registered/plugin_mr_bind)
058656
+     */
058656
     slapi_pblock_set(pb, SLAPI_PLUGIN_MR_INDEXER_CREATE_FN, default_mr_indexer_create);
058656
     slapi_pblock_set(pb, SLAPI_PLUGIN_MR_FILTER_CREATE_FN, default_mr_filter_create);
058656
     rc = 0;
fb1149
-- 
fb1149
2.13.6
fb1149