ldb_tdb: change the arguments to ldb_is_indexed() to provide the ltdb_private
authorAndrew Bartlett <abartlet@samba.org>
Thu, 30 Mar 2017 00:07:16 +0000 (13:07 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 31 May 2017 04:34:26 +0000 (06:34 +0200)
By doing this, we can be more efficient in locating if we have an index in
the future.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
lib/ldb/ldb_tdb/ldb_index.c

index 53fcde5a31d5f342210a3f7a09cdaba4087d8eda..fc21bac90bdbd495ae88389289930ff881b799cc 100644 (file)
@@ -445,12 +445,14 @@ static struct ldb_dn *ltdb_index_key(struct ldb_context *ldb,
 /*
   see if a attribute value is in the list of indexed attributes
 */
-static bool ltdb_is_indexed(const struct ldb_message *index_list, const char *attr)
+static bool ltdb_is_indexed(struct ldb_module *module,
+                           struct ltdb_private *ltdb,
+                           const char *attr)
 {
        unsigned int i;
        struct ldb_message_element *el;
 
-       el = ldb_msg_find_element(index_list, LTDB_IDXATTR);
+       el = ldb_msg_find_element(ltdb->cache->indexlist, LTDB_IDXATTR);
        if (el == NULL) {
                return false;
        }
@@ -481,8 +483,8 @@ static bool ltdb_is_indexed(const struct ldb_message *index_list, const char *at
   equality search only)
  */
 static int ltdb_index_dn_simple(struct ldb_module *module,
+                               struct ltdb_private *ltdb,
                                const struct ldb_parse_tree *tree,
-                               const struct ldb_message *index_list,
                                struct dn_list *list)
 {
        struct ldb_context *ldb;
@@ -496,7 +498,7 @@ static int ltdb_index_dn_simple(struct ldb_module *module,
 
        /* if the attribute isn't in the list of indexed attributes then
           this node needs a full search */
-       if (!ltdb_is_indexed(index_list, tree->u.equality.attr)) {
+       if (!ltdb_is_indexed(module, ltdb, tree->u.equality.attr)) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
@@ -517,12 +519,10 @@ static bool list_union(struct ldb_context *, struct dn_list *, const struct dn_l
   return a list of dn's that might match a leaf indexed search
  */
 static int ltdb_index_dn_leaf(struct ldb_module *module,
+                             struct ltdb_private *ltdb,
                              const struct ldb_parse_tree *tree,
-                             const struct ldb_message *index_list,
                              struct dn_list *list)
 {
-       struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module),
-                                                   struct ltdb_private);
        if (ltdb->disallow_dn_filter &&
            (ldb_attr_cmp(tree->u.equality.attr, "dn") == 0)) {
                /* in AD mode we do not support "(dn=...)" search filters */
@@ -540,7 +540,7 @@ static int ltdb_index_dn_leaf(struct ldb_module *module,
                list->count = 1;
                return LDB_SUCCESS;
        }
-       return ltdb_index_dn_simple(module, tree, index_list, list);
+       return ltdb_index_dn_simple(module, ltdb, tree, list);
 }
 
 
@@ -653,8 +653,8 @@ static bool list_union(struct ldb_context *ldb,
 }
 
 static int ltdb_index_dn(struct ldb_module *module,
+                        struct ltdb_private *ltdb,
                         const struct ldb_parse_tree *tree,
-                        const struct ldb_message *index_list,
                         struct dn_list *list);
 
 
@@ -662,8 +662,8 @@ static int ltdb_index_dn(struct ldb_module *module,
   process an OR list (a union)
  */
 static int ltdb_index_dn_or(struct ldb_module *module,
+                           struct ltdb_private *ltdb,
                            const struct ldb_parse_tree *tree,
-                           const struct ldb_message *index_list,
                            struct dn_list *list)
 {
        struct ldb_context *ldb;
@@ -683,7 +683,8 @@ static int ltdb_index_dn_or(struct ldb_module *module,
                        return LDB_ERR_OPERATIONS_ERROR;
                }
 
-               ret = ltdb_index_dn(module, tree->u.list.elements[i], index_list, list2);
+               ret = ltdb_index_dn(module, ltdb,
+                                   tree->u.list.elements[i], list2);
 
                if (ret == LDB_ERR_NO_SUCH_OBJECT) {
                        /* X || 0 == X */
@@ -715,8 +716,8 @@ static int ltdb_index_dn_or(struct ldb_module *module,
   NOT an index results
  */
 static int ltdb_index_dn_not(struct ldb_module *module,
+                            struct ltdb_private *ltdb,
                             const struct ldb_parse_tree *tree,
-                            const struct ldb_message *index_list,
                             struct dn_list *list)
 {
        /* the only way to do an indexed not would be if we could
@@ -746,8 +747,8 @@ static bool ltdb_index_unique(struct ldb_context *ldb,
   process an AND expression (intersection)
  */
 static int ltdb_index_dn_and(struct ldb_module *module,
+                            struct ltdb_private *ltdb,
                             const struct ldb_parse_tree *tree,
-                            const struct ldb_message *index_list,
                             struct dn_list *list)
 {
        struct ldb_context *ldb;
@@ -771,7 +772,7 @@ static int ltdb_index_dn_and(struct ldb_module *module,
                        continue;
                }
 
-               ret = ltdb_index_dn(module, subtree, index_list, list);
+               ret = ltdb_index_dn(module, ltdb, subtree, list);
                if (ret == LDB_ERR_NO_SUCH_OBJECT) {
                        /* 0 && X == 0 */
                        return LDB_ERR_NO_SUCH_OBJECT;
@@ -798,7 +799,7 @@ static int ltdb_index_dn_and(struct ldb_module *module,
                        return ldb_module_oom(module);
                }
 
-               ret = ltdb_index_dn(module, subtree, index_list, list2);
+               ret = ltdb_index_dn(module, ltdb, subtree, list2);
 
                if (ret == LDB_ERR_NO_SUCH_OBJECT) {
                        /* X && 0 == 0 */
@@ -884,27 +885,27 @@ static int ltdb_index_dn_one(struct ldb_module *module,
   an error. return LDB_ERR_NO_SUCH_OBJECT for no matches, or LDB_SUCCESS for matches
  */
 static int ltdb_index_dn(struct ldb_module *module,
+                        struct ltdb_private *ltdb,
                         const struct ldb_parse_tree *tree,
-                        const struct ldb_message *index_list,
                         struct dn_list *list)
 {
        int ret = LDB_ERR_OPERATIONS_ERROR;
 
        switch (tree->operation) {
        case LDB_OP_AND:
-               ret = ltdb_index_dn_and(module, tree, index_list, list);
+               ret = ltdb_index_dn_and(module, ltdb, tree, list);
                break;
 
        case LDB_OP_OR:
-               ret = ltdb_index_dn_or(module, tree, index_list, list);
+               ret = ltdb_index_dn_or(module, ltdb, tree, list);
                break;
 
        case LDB_OP_NOT:
-               ret = ltdb_index_dn_not(module, tree, index_list, list);
+               ret = ltdb_index_dn_not(module, ltdb, tree, list);
                break;
 
        case LDB_OP_EQUALITY:
-               ret = ltdb_index_dn_leaf(module, tree, index_list, list);
+               ret = ltdb_index_dn_leaf(module, ltdb, tree, list);
                break;
 
        case LDB_OP_SUBSTRING:
@@ -1087,7 +1088,7 @@ int ltdb_search_indexed(struct ltdb_context *ac, uint32_t *match_count)
                        talloc_free(dn_list);
                        return LDB_ERR_OPERATIONS_ERROR;
                }
-               ret = ltdb_index_dn(ac->module, ac->tree, ltdb->cache->indexlist, dn_list);
+               ret = ltdb_index_dn(ac->module, ltdb, ac->tree, dn_list);
                if (ret != LDB_SUCCESS) {
                        talloc_free(dn_list);
                        return ret;
@@ -1228,7 +1229,7 @@ static int ltdb_index_add_all(struct ldb_module *module, const char *dn,
 
        for (i = 0; i < num_el; i++) {
                int ret;
-               if (!ltdb_is_indexed(ltdb->cache->indexlist, elements[i].name)) {
+               if (!ltdb_is_indexed(module, ltdb, elements[i].name)) {
                        continue;
                }
                ret = ltdb_index_add_el(module, dn, &elements[i], is_new);
@@ -1306,7 +1307,7 @@ int ltdb_index_add_element(struct ldb_module *module, struct ldb_dn *dn,
        if (ldb_dn_is_special(dn)) {
                return LDB_SUCCESS;
        }
-       if (!ltdb_is_indexed(ltdb->cache->indexlist, el->name)) {
+       if (!ltdb_is_indexed(module, ltdb, el->name)) {
                return LDB_SUCCESS;
        }
        return ltdb_index_add_el(module, ldb_dn_get_linearized(dn), el, true);
@@ -1439,7 +1440,7 @@ int ltdb_index_del_element(struct ldb_module *module, struct ldb_dn *dn,
                return LDB_SUCCESS;
        }
 
-       if (!ltdb_is_indexed(ltdb->cache->indexlist, el->name)) {
+       if (!ltdb_is_indexed(module, ltdb, el->name)) {
                return LDB_SUCCESS;
        }
        for (i = 0; i < el->num_values; i++) {