amoralej / rpms / 389-ds-base

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

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

b045b9
From 8d79d7c81157e77f4da595a723a6ed10a8e9789b Mon Sep 17 00:00:00 2001
fb1149
From: Thierry Bordaz <tbordaz@redhat.com>
b045b9
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:
b045b9
    Indexing of the internationalized matching rules tests if a
b045b9
    matching rule indexer handle or not a given OID.
b045b9
    A side effect of https://pagure.io/389-ds-base/issue/49097 is that
b045b9
    the returned indexing callbacks are lost.
b045b9
    Indeed, the indexing callbacks (and potentially others fields) were
b045b9
    stored in the temporary pblock that was memcpy to the provided
b045b9
    pblock in case of success
fb1149
fb1149
Fix Description:
b045b9
    The fix basically restores the previous behavior but do not
b045b9
    memcpy pblock. It read/store the pblock fields that are
b045b9
    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
---
b045b9
 ldap/servers/slapd/plugin_mr.c | 148 ++++++++++++++++++++++++++++-------------
b045b9
 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
b045b9
index bd2baff6c..ca4fe00e1 100644
fb1149
--- a/ldap/servers/slapd/plugin_mr.c
fb1149
+++ b/ldap/servers/slapd/plugin_mr.c
b045b9
@@ -143,6 +143,82 @@ plugin_mr_bind(char *oid, struct slapdplugin *plugin)
b045b9
     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;
b045b9
+
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);
b045b9
+
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);
b045b9
+
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);
b045b9
+
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
b045b9
+ *
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 */
b045b9
     slapi_mr_indexer_create(Slapi_PBlock *opb)
fb1149
 {
b045b9
@@ -152,28 +228,33 @@ int /* an LDAP error code, hopefully LDAP_SUCCESS */
b045b9
         IFP createFn = NULL;
b045b9
         struct slapdplugin *mrp = plugin_mr_find_registered(oid);
b045b9
         if (mrp != NULL) {
fb1149
+            /* Great the matching OID -> MR plugin was already found, just reuse it */
b045b9
             if (!(rc = slapi_pblock_set(opb, SLAPI_PLUGIN, mrp)) &&
b045b9
                 !(rc = slapi_pblock_get(opb, SLAPI_PLUGIN_MR_INDEXER_CREATE_FN, &createFn)) &&
b045b9
                 createFn != NULL) {
b045b9
                 rc = createFn(opb);
b045b9
             }
b045b9
         } else {
b045b9
-            /* 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
+             */
b045b9
             rc = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
b045b9
-            // We need to get the type and usage from the caller.
b045b9
-            char *type;
b045b9
-            uint32_t usage;
b045b9
-            slapi_pblock_get(opb, SLAPI_PLUGIN_MR_TYPE, &type);
b045b9
-            slapi_pblock_get(opb, SLAPI_PLUGIN_MR_USAGE, &usage);
61f723
+
b045b9
             for (mrp = get_plugin_list(PLUGIN_LIST_MATCHINGRULE); mrp != NULL; mrp = mrp->plg_next) {
b045b9
 
b045b9
                 Slapi_PBlock *pb = slapi_pblock_new();
fb1149
+                mr_indexer_init_pb(opb, pb);
b045b9
                 slapi_pblock_set(pb, SLAPI_PLUGIN, mrp);
b045b9
-                /* From filtercmp.c and matchrule.c, these are the values we need to set. into pb */
b045b9
-                slapi_pblock_set(pb, SLAPI_PLUGIN_MR_OID, oid);
b045b9
-                slapi_pblock_set(pb, SLAPI_PLUGIN_MR_TYPE, type);
b045b9
-                slapi_pblock_set(pb, SLAPI_PLUGIN_MR_USAGE, &usage);
b045b9
-
b045b9
                 /* This is associated with the pb_plugin struct, so it comes with mrp */
b045b9
                 if (slapi_pblock_get(pb, SLAPI_PLUGIN_MR_INDEXER_CREATE_FN, &createFn)) {
b045b9
                     /* plugin not a matchingrule type */
b045b9
@@ -185,14 +266,11 @@ int /* an LDAP error code, hopefully LDAP_SUCCESS */
b045b9
                     IFP indexFn = NULL;
b045b9
                     IFP indexSvFn = NULL;
b045b9
                     /* These however, are in the pblock direct, so we need to copy them. */
b045b9
-                    slapi_pblock_get(opb, SLAPI_PLUGIN_MR_INDEX_FN, &indexFn);
b045b9
-                    slapi_pblock_get(opb, SLAPI_PLUGIN_MR_INDEX_SV_FN, &indexSvFn);
b045b9
-                    slapi_pblock_set(pb, SLAPI_PLUGIN_MR_INDEX_FN, indexFn);
b045b9
-                    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);
b045b9
                     if (indexFn || indexSvFn) {
b045b9
                         /* Success: this plugin can handle it. */
b045b9
-                        /* call create on the opb? */
b045b9
-                        createFn(opb);
fb1149
+                        mr_indexer_init_pb(pb, opb);
b045b9
                         plugin_mr_bind(oid, mrp); /* for future reference */
b045b9
                         rc = 0;                   /* success */
b045b9
                         slapi_pblock_destroy(pb);
b045b9
@@ -205,37 +283,12 @@ int /* an LDAP error code, hopefully LDAP_SUCCESS */
b045b9
                 /* look for a new syntax-style mr plugin */
b045b9
                 struct slapdplugin *pi = plugin_mr_find(oid);
b045b9
                 if (pi) {
b045b9
-                    Slapi_PBlock *pb = slapi_pblock_new();
b045b9
-                    slapi_pblock_set(pb, SLAPI_PLUGIN_MR_OID, oid);
b045b9
-                    slapi_pblock_set(pb, SLAPI_PLUGIN_MR_TYPE, type);
b045b9
-                    slapi_pblock_set(pb, SLAPI_PLUGIN_MR_USAGE, &usage);
b045b9
-                    slapi_pblock_set(pb, SLAPI_PLUGIN, pi);
b045b9
-                    rc = default_mr_indexer_create(pb);
fb1149
+                    slapi_pblock_set(opb, SLAPI_PLUGIN, pi);
fb1149
+                    rc = default_mr_indexer_create(opb);
b045b9
                     if (!rc) {
b045b9
-                        /* On success, copy the needed values in. These are added by default_mr_indexer_create */
b045b9
-                        void *pb_object = NULL;
b045b9
-                        IFP destroy_fn = NULL;
b045b9
-                        IFP index_fn = NULL;
b045b9
-                        IFP index_sv_fn = NULL;
b045b9
-
b045b9
-                        slapi_pblock_get(pb, SLAPI_PLUGIN_OBJECT, &pb_object);
b045b9
-                        slapi_pblock_get(pb, SLAPI_PLUGIN_DESTROY_FN, &destroy_fn);
b045b9
-                        slapi_pblock_get(pb, SLAPI_PLUGIN_MR_INDEX_FN, &index_fn);
b045b9
-                        slapi_pblock_get(pb, SLAPI_PLUGIN_MR_INDEX_SV_FN, &index_sv_fn);
b045b9
-
b045b9
-                        /* SLAPI_PLUGIN_MR_INDEXER_CREATE_FN, and SLAPI_PLUGIN_MR_FILTER_CREATE_FN, are part of pb_plugin */
b045b9
-                        slapi_pblock_set(opb, SLAPI_PLUGIN, pi);
b045b9
-                        slapi_pblock_set(opb, SLAPI_PLUGIN_MR_OID, oid);
b045b9
-                        slapi_pblock_set(opb, SLAPI_PLUGIN_MR_TYPE, type);
b045b9
-                        slapi_pblock_set(opb, SLAPI_PLUGIN_MR_USAGE, &usage);
b045b9
-                        slapi_pblock_set(opb, SLAPI_PLUGIN_OBJECT, pb_object);
b045b9
-                        slapi_pblock_set(opb, SLAPI_PLUGIN_DESTROY_FN, destroy_fn);
b045b9
-                        slapi_pblock_set(opb, SLAPI_PLUGIN_MR_INDEX_FN, index_fn);
b045b9
-                        slapi_pblock_set(opb, SLAPI_PLUGIN_MR_INDEX_SV_FN, index_sv_fn);
b045b9
-
b045b9
                         plugin_mr_bind(oid, pi); /* for future reference */
b045b9
                     }
b045b9
-                    slapi_pblock_destroy(pb);
fb1149
+                    slapi_pblock_set(opb, SLAPI_PLUGIN, NULL);
b045b9
                 }
b045b9
             }
b045b9
         }
b045b9
@@ -706,6 +759,11 @@ default_mr_indexer_create(Slapi_PBlock *pb)
b045b9
     slapi_pblock_set(pb, SLAPI_PLUGIN_MR_INDEX_FN, mr_wrap_mr_index_fn);
b045b9
     slapi_pblock_set(pb, SLAPI_PLUGIN_MR_INDEX_SV_FN, mr_wrap_mr_index_sv_fn);
b045b9
     slapi_pblock_set(pb, SLAPI_PLUGIN_DESTROY_FN, default_mr_indexer_destroy);
fb1149
+
b045b9
+    /* Note the two following setting are in the slapdplugin struct SLAPI_PLUGIN
b045b9
+     * so they are not really output of the function but will just
b045b9
+     * be stored in the bound (OID <--> plugin) list (plugin_mr_find_registered/plugin_mr_bind)
b045b9
+     */
b045b9
     slapi_pblock_set(pb, SLAPI_PLUGIN_MR_INDEXER_CREATE_FN, default_mr_indexer_create);
b045b9
     slapi_pblock_set(pb, SLAPI_PLUGIN_MR_FILTER_CREATE_FN, default_mr_filter_create);
b045b9
     rc = 0;
fb1149
-- 
fb1149
2.13.6
fb1149