andykimpe / rpms / 389-ds-base

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

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

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