From 9e6294668aa58408863bc6bb2c2510608bf916f3 Mon Sep 17 00:00:00 2001 From: Gary Lockyer Date: Fri, 20 Jul 2018 07:25:32 +1200 Subject: [PATCH] lib ldb: fix formatting of ldb_kv rename. Clean up the code format after the rename in the previous commit. Hopefully doing a rename commit followed by a reformat commit makes the code easier to review. Signed-off-by: Gary Lockyer Reviewed-by: Andrew Bartlett --- lib/ldb/ldb_tdb/ldb_index.c | 315 ++++++++++++++++++----------------- lib/ldb/ldb_tdb/ldb_search.c | 59 +++---- lib/ldb/ldb_tdb/ldb_tdb.c | 273 +++++++++++++++--------------- lib/ldb/ldb_tdb/ldb_tdb.h | 110 ++++++------ 4 files changed, 390 insertions(+), 367 deletions(-) diff --git a/lib/ldb/ldb_tdb/ldb_index.c b/lib/ldb/ldb_tdb/ldb_index.c index 75073a19b4c..23b8aa005cb 100644 --- a/lib/ldb/ldb_tdb/ldb_index.c +++ b/lib/ldb/ldb_tdb/ldb_index.c @@ -309,7 +309,9 @@ static int ldb_kv_dn_list_find_msg(struct ltdb_private *ltdb, checks and also copes with CPUs that are fussy about pointer alignment */ -static struct dn_list *ldb_kv_index_idxptr(struct ldb_module *module, TDB_DATA rec, bool check_parent) +static struct dn_list *ldb_kv_index_idxptr(struct ldb_module *module, + TDB_DATA rec, + bool check_parent) { struct dn_list *list; if (rec.dsize != sizeof(void *)) { @@ -342,8 +344,9 @@ static struct dn_list *ldb_kv_index_idxptr(struct ldb_module *module, TDB_DATA r struct dn_list */ static int ldb_kv_dn_list_load(struct ldb_module *module, - struct ltdb_private *ltdb, - struct ldb_dn *dn, struct dn_list *list) + struct ltdb_private *ltdb, + struct ldb_dn *dn, + struct dn_list *list) { struct ldb_message *msg; int ret, version; @@ -386,9 +389,11 @@ normal_index: return LDB_ERR_OPERATIONS_ERROR; } - ret = ldb_kv_search_dn1(module, dn, msg, - LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC - |LDB_UNPACK_DATA_FLAG_NO_DN); + ret = ldb_kv_search_dn1(module, + dn, + msg, + LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC | + LDB_UNPACK_DATA_FLAG_NO_DN); if (ret != LDB_SUCCESS) { talloc_free(msg); return ret; @@ -474,10 +479,10 @@ normal_index: } int ldb_kv_key_dn_from_idx(struct ldb_module *module, - struct ltdb_private *ltdb, - TALLOC_CTX *mem_ctx, - struct ldb_dn *dn, - TDB_DATA *tdb_key) + struct ltdb_private *ltdb, + TALLOC_CTX *mem_ctx, + struct ldb_dn *dn, + TDB_DATA *tdb_key) { struct ldb_context *ldb = ldb_module_get_ctx(module); int ret; @@ -489,7 +494,6 @@ int ldb_kv_key_dn_from_idx(struct ldb_module *module, return LDB_ERR_OPERATIONS_ERROR; } - ret = ldb_kv_index_dn_base_dn(module, ltdb, dn, list, &truncation); if (ret != LDB_SUCCESS) { TALLOC_FREE(list); @@ -534,17 +538,15 @@ int ldb_kv_key_dn_from_idx(struct ldb_module *module, return LDB_ERR_OPERATIONS_ERROR; } - ret = ldb_kv_idx_to_key(module, ltdb, - ldb, &list->dn[i], - &key); + ret = ldb_kv_idx_to_key( + module, ltdb, ldb, &list->dn[i], &key); if (ret != LDB_SUCCESS) { TALLOC_FREE(list); TALLOC_FREE(rec); return ret; } - ret = ldb_kv_search_key(module, ltdb, key, - rec, flags); + ret = ldb_kv_search_key(module, ltdb, key, rec, flags); if (key.dptr != guid_key) { TALLOC_FREE(key.dptr); } @@ -588,8 +590,7 @@ int ldb_kv_key_dn_from_idx(struct ldb_module *module, } /* The tdb_key memory is allocated by the caller */ - ret = ldb_kv_guid_to_key(module, ltdb, - &list->dn[index], tdb_key); + ret = ldb_kv_guid_to_key(module, ltdb, &list->dn[index], tdb_key); TALLOC_FREE(list); if (ret != LDB_SUCCESS) { @@ -605,9 +606,9 @@ int ldb_kv_key_dn_from_idx(struct ldb_module *module, save a dn_list into a full @IDX style record */ static int ldb_kv_dn_list_store_full(struct ldb_module *module, - struct ltdb_private *ltdb, - struct ldb_dn *dn, - struct dn_list *list) + struct ltdb_private *ltdb, + struct ldb_dn *dn, + struct dn_list *list) { struct ldb_message *msg; int ret; @@ -699,8 +700,9 @@ static int ldb_kv_dn_list_store_full(struct ldb_module *module, /* save a dn_list into the database, in either @IDX or internal format */ -static int ldb_kv_dn_list_store(struct ldb_module *module, struct ldb_dn *dn, - struct dn_list *list) +static int ldb_kv_dn_list_store(struct ldb_module *module, + struct ldb_dn *dn, + struct dn_list *list) { struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module), struct ltdb_private); TDB_DATA rec, key; @@ -708,8 +710,7 @@ static int ldb_kv_dn_list_store(struct ldb_module *module, struct ldb_dn *dn, struct dn_list *list2; if (ltdb->idxptr == NULL) { - return ldb_kv_dn_list_store_full(module, ltdb, - dn, list); + return ldb_kv_dn_list_store_full(module, ltdb, dn, list); } if (ltdb->idxptr->itdb == NULL) { @@ -763,7 +764,10 @@ static int ldb_kv_dn_list_store(struct ldb_module *module, struct ldb_dn *dn, /* traverse function for storing the in-memory index entries on disk */ -static int ldb_kv_index_traverse_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state) +static int ldb_kv_index_traverse_store(struct tdb_context *tdb, + TDB_DATA key, + TDB_DATA data, + void *state) { struct ldb_module *module = state; struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module), struct ltdb_private); @@ -788,8 +792,7 @@ static int ldb_kv_index_traverse_store(struct tdb_context *tdb, TDB_DATA key, TD return -1; } - ltdb->idxptr->error = ldb_kv_dn_list_store_full(module, ltdb, - dn, list); + ltdb->idxptr->error = ldb_kv_dn_list_store_full(module, ltdb, dn, list); talloc_free(dn); if (ltdb->idxptr->error != 0) { return -1; @@ -808,7 +811,8 @@ int ldb_kv_index_transaction_commit(struct ldb_module *module) ldb_reset_err_string(ldb); if (ltdb->idxptr->itdb) { - tdb_traverse(ltdb->idxptr->itdb, ldb_kv_index_traverse_store, module); + tdb_traverse( + ltdb->idxptr->itdb, ldb_kv_index_traverse_store, module); tdb_close(ltdb->idxptr->itdb); } @@ -843,10 +847,11 @@ int ldb_kv_index_transaction_cancel(struct ldb_module *module) the caller is responsible for freeing */ static struct ldb_dn *ldb_kv_index_key(struct ldb_context *ldb, - struct ltdb_private *ltdb, - const char *attr, const struct ldb_val *value, - const struct ldb_schema_attribute **ap, - enum key_truncation *truncation) + struct ltdb_private *ltdb, + const char *attr, + const struct ldb_val *value, + const struct ldb_schema_attribute **ap, + enum key_truncation *truncation) { struct ldb_dn *ret; struct ldb_val v; @@ -1028,8 +1033,8 @@ static struct ldb_dn *ldb_kv_index_key(struct ldb_context *ldb, see if a attribute value is in the list of indexed attributes */ static bool ldb_kv_is_indexed(struct ldb_module *module, - struct ltdb_private *ltdb, - const char *attr) + struct ltdb_private *ltdb, + const char *attr) { struct ldb_context *ldb = ldb_module_get_ctx(module); unsigned int i; @@ -1091,9 +1096,9 @@ static bool ldb_kv_is_indexed(struct ldb_module *module, equality search only) */ static int ldb_kv_index_dn_simple(struct ldb_module *module, - struct ltdb_private *ltdb, - const struct ldb_parse_tree *tree, - struct dn_list *list) + struct ltdb_private *ltdb, + const struct ldb_parse_tree *tree, + struct dn_list *list) { struct ldb_context *ldb; struct ldb_dn *dn; @@ -1113,9 +1118,12 @@ static int ldb_kv_index_dn_simple(struct ldb_module *module, /* the attribute is indexed. Pull the list of DNs that match the search criterion */ - dn = ldb_kv_index_key(ldb, ltdb, - tree->u.equality.attr, - &tree->u.equality.value, NULL, &truncation); + dn = ldb_kv_index_key(ldb, + ltdb, + tree->u.equality.attr, + &tree->u.equality.value, + NULL, + &truncation); /* * We ignore truncation here and allow multi-valued matches * as ltdb_search_indexed will filter out the wrong one in @@ -1137,9 +1145,9 @@ static bool list_union(struct ldb_context *ldb, return a list of dn's that might match a leaf indexed search */ static int ldb_kv_index_dn_leaf(struct ldb_module *module, - struct ltdb_private *ltdb, - const struct ldb_parse_tree *tree, - struct dn_list *list) + struct ltdb_private *ltdb, + const struct ldb_parse_tree *tree, + struct dn_list *list) { if (ltdb->disallow_dn_filter && (ldb_attr_cmp(tree->u.equality.attr, "dn") == 0)) { @@ -1174,8 +1182,8 @@ static int ldb_kv_index_dn_leaf(struct ldb_module *module, * We can't call TALLOC_FREE(dn) as this must belong * to list for the memory to remain valid. */ - return ldb_kv_index_dn_base_dn(module, ltdb, dn, list, - &truncation); + return ldb_kv_index_dn_base_dn( + module, ltdb, dn, list, &truncation); /* * We ignore truncation here and allow multi-valued matches * as ltdb_search_indexed will filter out the wrong one in @@ -1276,8 +1284,8 @@ static bool list_intersect(struct ldb_context *ldb, for (i=0;icount;i++) { /* For the GUID index case, this is a binary search */ - if (ldb_kv_dn_list_find_val(ltdb, long_list, - &short_list->dn[i]) != -1) { + if (ldb_kv_dn_list_find_val( + ltdb, long_list, &short_list->dn[i]) != -1) { list3->dn[list3->count] = short_list->dn[i]; list3->count++; } @@ -1373,18 +1381,17 @@ static bool list_union(struct ldb_context *ldb, } static int ldb_kv_index_dn(struct ldb_module *module, - struct ltdb_private *ltdb, - const struct ldb_parse_tree *tree, - struct dn_list *list); - + struct ltdb_private *ltdb, + const struct ldb_parse_tree *tree, + struct dn_list *list); /* process an OR list (a union) */ static int ldb_kv_index_dn_or(struct ldb_module *module, - struct ltdb_private *ltdb, - const struct ldb_parse_tree *tree, - struct dn_list *list) + struct ltdb_private *ltdb, + const struct ldb_parse_tree *tree, + struct dn_list *list) { struct ldb_context *ldb; unsigned int i; @@ -1403,8 +1410,8 @@ static int ldb_kv_index_dn_or(struct ldb_module *module, return LDB_ERR_OPERATIONS_ERROR; } - ret = ldb_kv_index_dn(module, ltdb, - tree->u.list.elements[i], list2); + ret = ldb_kv_index_dn( + module, ltdb, tree->u.list.elements[i], list2); if (ret == LDB_ERR_NO_SUCH_OBJECT) { /* X || 0 == X */ @@ -1436,9 +1443,9 @@ static int ldb_kv_index_dn_or(struct ldb_module *module, NOT an index results */ static int ldb_kv_index_dn_not(struct ldb_module *module, - struct ltdb_private *ltdb, - const struct ldb_parse_tree *tree, - struct dn_list *list) + struct ltdb_private *ltdb, + const struct ldb_parse_tree *tree, + struct dn_list *list) { /* the only way to do an indexed not would be if we could negate the not via another not or if we knew the total @@ -1456,8 +1463,8 @@ static int ldb_kv_index_dn_not(struct ldb_module *module, * by GUID, DN or a unique attribute */ static bool ldb_kv_index_unique(struct ldb_context *ldb, - struct ltdb_private *ltdb, - const char *attr) + struct ltdb_private *ltdb, + const char *attr) { const struct ldb_schema_attribute *a; if (ltdb->cache->GUID_index_attribute != NULL) { @@ -1480,9 +1487,9 @@ static bool ldb_kv_index_unique(struct ldb_context *ldb, process an AND expression (intersection) */ static int ldb_kv_index_dn_and(struct ldb_module *module, - struct ltdb_private *ltdb, - const struct ldb_parse_tree *tree, - struct dn_list *list) + struct ltdb_private *ltdb, + const struct ldb_parse_tree *tree, + struct dn_list *list) { struct ldb_context *ldb; unsigned int i; @@ -1501,8 +1508,7 @@ static int ldb_kv_index_dn_and(struct ldb_module *module, int ret; if (subtree->operation != LDB_OP_EQUALITY || - !ldb_kv_index_unique(ldb, ltdb, - subtree->u.equality.attr)) { + !ldb_kv_index_unique(ldb, ltdb, subtree->u.equality.attr)) { continue; } @@ -1583,11 +1589,11 @@ static int ldb_kv_index_dn_and(struct ldb_module *module, return a list of matching objects using a one-level index */ static int ldb_kv_index_dn_attr(struct ldb_module *module, - struct ltdb_private *ltdb, - const char *attr, - struct ldb_dn *dn, - struct dn_list *list, - enum key_truncation *truncation) + struct ltdb_private *ltdb, + const char *attr, + struct ldb_dn *dn, + struct dn_list *list, + enum key_truncation *truncation) { struct ldb_context *ldb; struct ldb_dn *key; @@ -1622,26 +1628,25 @@ static int ldb_kv_index_dn_attr(struct ldb_module *module, return a list of matching objects using a one-level index */ static int ldb_kv_index_dn_one(struct ldb_module *module, - struct ltdb_private *ltdb, - struct ldb_dn *parent_dn, - struct dn_list *list, - enum key_truncation *truncation) + struct ltdb_private *ltdb, + struct ldb_dn *parent_dn, + struct dn_list *list, + enum key_truncation *truncation) { /* Ensure we do not shortcut on intersection for this list */ list->strict = true; - return ldb_kv_index_dn_attr(module, ltdb, - LTDB_IDXONE, parent_dn, list, truncation); - + return ldb_kv_index_dn_attr( + module, ltdb, LTDB_IDXONE, parent_dn, list, truncation); } /* return a list of matching objects using the DN index */ static int ldb_kv_index_dn_base_dn(struct ldb_module *module, - struct ltdb_private *ltdb, - struct ldb_dn *base_dn, - struct dn_list *dn_list, - enum key_truncation *truncation) + struct ltdb_private *ltdb, + struct ldb_dn *base_dn, + struct dn_list *dn_list, + enum key_truncation *truncation) { const struct ldb_val *guid_val = NULL; if (ltdb->cache->GUID_index_attribute == NULL) { @@ -1677,8 +1682,8 @@ static int ldb_kv_index_dn_base_dn(struct ldb_module *module, return LDB_SUCCESS; } - return ldb_kv_index_dn_attr(module, ltdb, - LTDB_IDXDN, base_dn, dn_list, truncation); + return ldb_kv_index_dn_attr( + module, ltdb, LTDB_IDXDN, base_dn, dn_list, truncation); } /* @@ -1686,9 +1691,9 @@ static int ldb_kv_index_dn_base_dn(struct ldb_module *module, an error. return LDB_ERR_NO_SUCH_OBJECT for no matches, or LDB_SUCCESS for matches */ static int ldb_kv_index_dn(struct ldb_module *module, - struct ltdb_private *ltdb, - const struct ldb_parse_tree *tree, - struct dn_list *list) + struct ltdb_private *ltdb, + const struct ldb_parse_tree *tree, + struct dn_list *list) { int ret = LDB_ERR_OPERATIONS_ERROR; @@ -1728,10 +1733,10 @@ static int ldb_kv_index_dn(struct ldb_module *module, extracting just the given attributes */ static int ldb_kv_index_filter(struct ltdb_private *ltdb, - const struct dn_list *dn_list, - struct ltdb_context *ac, - uint32_t *match_count, - enum key_truncation scope_one_truncation) + const struct dn_list *dn_list, + struct ltdb_context *ac, + uint32_t *match_count, + enum key_truncation scope_one_truncation) { struct ldb_context *ldb = ldb_module_get_ctx(ac->module); struct ldb_message *msg; @@ -1784,11 +1789,8 @@ static int ldb_kv_index_filter(struct ltdb_private *ltdb, for (i = 0; i < dn_list->count; i++) { int ret; - ret = ldb_kv_idx_to_key(ac->module, - ltdb, - keys, - &dn_list->dn[i], - &keys[num_keys]); + ret = ldb_kv_idx_to_key( + ac->module, ltdb, keys, &dn_list->dn[i], &keys[num_keys]); if (ret != LDB_SUCCESS) { talloc_free(keys); return ret; @@ -1832,10 +1834,13 @@ static int ldb_kv_index_filter(struct ltdb_private *ltdb, return LDB_ERR_OPERATIONS_ERROR; } - ret = ldb_kv_search_key(ac->module, ltdb, - keys[i], msg, - LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC| - LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC); + ret = + ldb_kv_search_key(ac->module, + ltdb, + keys[i], + msg, + LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC | + LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC); if (ret == LDB_ERR_NO_SUCH_OBJECT) { /* * the record has disappeared? yes, this can @@ -1911,8 +1916,7 @@ static int ldb_kv_index_filter(struct ltdb_private *ltdb, /* sort a DN list */ -static void ldb_kv_dn_list_sort(struct ltdb_private *ltdb, - struct dn_list *list) +static void ldb_kv_dn_list_sort(struct ltdb_private *ltdb, struct dn_list *list) { if (list->count < 2) { return; @@ -1980,8 +1984,8 @@ int ldb_kv_search_indexed(struct ltdb_context *ac, uint32_t *match_count) * the tree, we must ensure we strictly intersect with * this list, as we trust the ONELEVEL index */ - ret = ldb_kv_index_dn_one(ac->module, ltdb, ac->base, dn_list, - &scope_one_truncation); + ret = ldb_kv_index_dn_one( + ac->module, ltdb, ac->base, dn_list, &scope_one_truncation); if (ret != LDB_SUCCESS) { talloc_free(dn_list); return ret; @@ -2019,8 +2023,8 @@ int ldb_kv_search_indexed(struct ltdb_context *ac, uint32_t *match_count) * index can't trim the result list down then * the ONELEVEL index is still good enough. */ - ret = ldb_kv_index_dn(ac->module, ltdb, ac->tree, - idx_one_tree_list); + ret = ldb_kv_index_dn( + ac->module, ltdb, ac->tree, idx_one_tree_list); if (ret == LDB_SUCCESS) { if (!list_intersect(ldb, ltdb, dn_list, @@ -2062,8 +2066,8 @@ int ldb_kv_search_indexed(struct ltdb_context *ac, uint32_t *match_count) * processing as the truncation here refers only to the * SCOPE_ONELEVEL index. */ - ret = ldb_kv_index_filter(ltdb, dn_list, ac, match_count, - scope_one_truncation); + ret = ldb_kv_index_filter( + ltdb, dn_list, ac, match_count, scope_one_truncation); talloc_free(dn_list); return ret; } @@ -2089,9 +2093,10 @@ int ldb_kv_search_indexed(struct ltdb_context *ac, uint32_t *match_count) * @return An ldb error code */ static int ldb_kv_index_add1(struct ldb_module *module, - struct ltdb_private *ltdb, - const struct ldb_message *msg, - struct ldb_message_element *el, int v_idx) + struct ltdb_private *ltdb, + const struct ldb_message *msg, + struct ldb_message_element *el, + int v_idx) { struct ldb_context *ldb; struct ldb_dn *dn_key; @@ -2109,8 +2114,8 @@ static int ldb_kv_index_add1(struct ldb_module *module, return LDB_ERR_OPERATIONS_ERROR; } - dn_key = ldb_kv_index_key(ldb, ltdb, - el->name, &el->values[v_idx], &a, &truncation); + dn_key = ldb_kv_index_key( + ldb, ltdb, el->name, &el->values[v_idx], &a, &truncation); if (!dn_key) { talloc_free(list); return LDB_ERR_OPERATIONS_ERROR; @@ -2178,17 +2183,15 @@ static int ldb_kv_index_add1(struct ldb_module *module, return LDB_ERR_OPERATIONS_ERROR; } - ret = ldb_kv_idx_to_key(module, ltdb, - ldb, &list->dn[i], - &key); + ret = ldb_kv_idx_to_key( + module, ltdb, ldb, &list->dn[i], &key); if (ret != LDB_SUCCESS) { TALLOC_FREE(list); TALLOC_FREE(rec); return ret; } - ret = ldb_kv_search_key(module, ltdb, key, - rec, flags); + ret = ldb_kv_search_key(module, ltdb, key, rec, flags); if (key.dptr != guid_key) { TALLOC_FREE(key.dptr); } @@ -2371,14 +2374,13 @@ static int ldb_kv_index_add1(struct ldb_module *module, add index entries for one elements in a message */ static int ldb_kv_index_add_el(struct ldb_module *module, - struct ltdb_private *ltdb, - const struct ldb_message *msg, - struct ldb_message_element *el) + struct ltdb_private *ltdb, + const struct ldb_message *msg, + struct ldb_message_element *el) { unsigned int i; for (i = 0; i < el->num_values; i++) { - int ret = ldb_kv_index_add1(module, ltdb, - msg, el, i); + int ret = ldb_kv_index_add1(module, ltdb, msg, el, i); if (ret != LDB_SUCCESS) { return ret; } @@ -2391,8 +2393,8 @@ static int ldb_kv_index_add_el(struct ldb_module *module, add index entries for all elements in a message */ static int ldb_kv_index_add_all(struct ldb_module *module, - struct ltdb_private *ltdb, - const struct ldb_message *msg) + struct ltdb_private *ltdb, + const struct ldb_message *msg) { struct ldb_message_element *elements = msg->elements; unsigned int i; @@ -2422,8 +2424,7 @@ static int ldb_kv_index_add_all(struct ldb_module *module, if (!ldb_kv_is_indexed(module, ltdb, elements[i].name)) { continue; } - ret = ldb_kv_index_add_el(module, ltdb, - msg, &elements[i]); + ret = ldb_kv_index_add_el(module, ltdb, msg, &elements[i]); if (ret != LDB_SUCCESS) { struct ldb_context *ldb = ldb_module_get_ctx(module); ldb_asprintf_errstring(ldb, @@ -2442,10 +2443,11 @@ static int ldb_kv_index_add_all(struct ldb_module *module, insert a DN index for a message */ static int ldb_kv_modify_index_dn(struct ldb_module *module, - struct ltdb_private *ltdb, - const struct ldb_message *msg, - struct ldb_dn *dn, - const char *index, int add) + struct ltdb_private *ltdb, + const struct ldb_message *msg, + struct ldb_dn *dn, + const char *index, + int add) { struct ldb_message_element el; struct ldb_val val; @@ -2495,7 +2497,8 @@ static int ldb_kv_modify_index_dn(struct ldb_module *module, insert a one level index for a message */ static int ldb_kv_index_onelevel(struct ldb_module *module, - const struct ldb_message *msg, int add) + const struct ldb_message *msg, + int add) { struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module), struct ltdb_private); @@ -2511,8 +2514,7 @@ static int ldb_kv_index_onelevel(struct ldb_module *module, if (pdn == NULL) { return LDB_ERR_OPERATIONS_ERROR; } - ret = ldb_kv_modify_index_dn(module, ltdb, - msg, pdn, LTDB_IDXONE, add); + ret = ldb_kv_modify_index_dn(module, ltdb, msg, pdn, LTDB_IDXONE, add); talloc_free(pdn); @@ -2523,8 +2525,8 @@ static int ldb_kv_index_onelevel(struct ldb_module *module, insert a one level index for a message */ static int ldb_kv_write_index_dn_guid(struct ldb_module *module, - const struct ldb_message *msg, - int add) + const struct ldb_message *msg, + int add) { int ret; struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module), @@ -2535,8 +2537,8 @@ static int ldb_kv_write_index_dn_guid(struct ldb_module *module, return LDB_SUCCESS; } - ret = ldb_kv_modify_index_dn(module, ltdb, msg, msg->dn, - LTDB_IDXDN, add); + ret = + ldb_kv_modify_index_dn(module, ltdb, msg, msg->dn, LTDB_IDXDN, add); if (ret == LDB_ERR_CONSTRAINT_VIOLATION) { ldb_asprintf_errstring(ldb_module_get_ctx(module), @@ -2552,9 +2554,9 @@ static int ldb_kv_write_index_dn_guid(struct ldb_module *module, The caller guarantees that these element values are not yet indexed */ int ldb_kv_index_add_element(struct ldb_module *module, - struct ltdb_private *ltdb, - const struct ldb_message *msg, - struct ldb_message_element *el) + struct ltdb_private *ltdb, + const struct ldb_message *msg, + struct ldb_message_element *el) { if (ldb_dn_is_special(msg->dn)) { return LDB_SUCCESS; @@ -2569,8 +2571,8 @@ int ldb_kv_index_add_element(struct ldb_module *module, add the index entries for a new record */ int ldb_kv_index_add_new(struct ldb_module *module, - struct ltdb_private *ltdb, - const struct ldb_message *msg) + struct ltdb_private *ltdb, + const struct ldb_message *msg) { int ret; @@ -2610,9 +2612,10 @@ int ldb_kv_index_add_new(struct ldb_module *module, delete an index entry for one message element */ int ldb_kv_index_del_value(struct ldb_module *module, - struct ltdb_private *ltdb, - const struct ldb_message *msg, - struct ldb_message_element *el, unsigned int v_idx) + struct ltdb_private *ltdb, + const struct ldb_message *msg, + struct ldb_message_element *el, + unsigned int v_idx) { struct ldb_context *ldb; struct ldb_dn *dn_key; @@ -2634,9 +2637,8 @@ int ldb_kv_index_del_value(struct ldb_module *module, return LDB_SUCCESS; } - dn_key = ldb_kv_index_key(ldb, ltdb, - el->name, &el->values[v_idx], - NULL, &truncation); + dn_key = ldb_kv_index_key( + ldb, ltdb, el->name, &el->values[v_idx], NULL, &truncation); /* * We ignore key truncation in ltdb_index_add1() so * match that by ignoring it here as well @@ -2700,9 +2702,9 @@ int ldb_kv_index_del_value(struct ldb_module *module, return -1 on failure */ int ldb_kv_index_del_element(struct ldb_module *module, - struct ltdb_private *ltdb, - const struct ldb_message *msg, - struct ldb_message_element *el) + struct ltdb_private *ltdb, + const struct ldb_message *msg, + struct ldb_message_element *el) { const char *dn_str; int ret; @@ -2739,7 +2741,8 @@ int ldb_kv_index_del_element(struct ldb_module *module, delete the index entries for a record return -1 on failure */ -int ldb_kv_index_delete(struct ldb_module *module, const struct ldb_message *msg) +int ldb_kv_index_delete(struct ldb_module *module, + const struct ldb_message *msg) { struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module), struct ltdb_private); int ret; @@ -2765,8 +2768,8 @@ int ldb_kv_index_delete(struct ldb_module *module, const struct ldb_message *msg } for (i = 0; i < msg->num_elements; i++) { - ret = ldb_kv_index_del_element(module, ltdb, - msg, &msg->elements[i]); + ret = ldb_kv_index_del_element( + module, ltdb, msg, &msg->elements[i]); if (ret != LDB_SUCCESS) { return ret; } diff --git a/lib/ldb/ldb_tdb/ldb_search.c b/lib/ldb/ldb_tdb/ldb_search.c index 4f6704797d4..a0df5d0b8a7 100644 --- a/lib/ldb/ldb_tdb/ldb_search.c +++ b/lib/ldb/ldb_tdb/ldb_search.c @@ -117,9 +117,9 @@ static int msg_add_distinguished_name(struct ldb_message *msg) and LDB_SUCCESS on success */ int ldb_kv_search_base(struct ldb_module *module, - TALLOC_CTX *mem_ctx, - struct ldb_dn *dn, - struct ldb_dn **ret_dn) + TALLOC_CTX *mem_ctx, + struct ldb_dn *dn, + struct ldb_dn **ret_dn) { int exists; int ret; @@ -141,9 +141,7 @@ int ldb_kv_search_base(struct ldb_module *module, return LDB_ERR_OPERATIONS_ERROR; } - ret = ldb_kv_search_dn1(module, dn, - msg, - LDB_UNPACK_DATA_FLAG_NO_ATTRS); + ret = ldb_kv_search_dn1(module, dn, msg, LDB_UNPACK_DATA_FLAG_NO_ATTRS); if (ret == LDB_SUCCESS) { const char *dn_linearized = ldb_dn_get_linearized(dn); @@ -184,8 +182,8 @@ struct ltdb_parse_data_unpack_ctx { }; static int ldb_kv_parse_data_unpack(struct ldb_val key, - struct ldb_val data, - void *private_data) + struct ldb_val data, + void *private_data) { struct ltdb_parse_data_unpack_ctx *ctx = private_data; unsigned int nb_elements_in_db; @@ -236,10 +234,11 @@ static int ldb_kv_parse_data_unpack(struct ldb_val key, return LDB_ERR_NO_SUCH_OBJECT on record-not-found and LDB_SUCCESS on success */ -int ldb_kv_search_key(struct ldb_module *module, struct ltdb_private *ltdb, - const struct TDB_DATA tdb_key, - struct ldb_message *msg, - unsigned int unpack_flags) +int ldb_kv_search_key(struct ldb_module *module, + struct ltdb_private *ltdb, + const struct TDB_DATA tdb_key, + struct ldb_message *msg, + unsigned int unpack_flags) { int ret; struct ltdb_parse_data_unpack_ctx ctx = { @@ -257,8 +256,8 @@ int ldb_kv_search_key(struct ldb_module *module, struct ltdb_private *ltdb, msg->num_elements = 0; msg->elements = NULL; - ret = ltdb->kv_ops->fetch_and_parse(ltdb, ldb_key, - ldb_kv_parse_data_unpack, &ctx); + ret = ltdb->kv_ops->fetch_and_parse( + ltdb, ldb_key, ldb_kv_parse_data_unpack, &ctx); if (ret == -1) { ret = ltdb->kv_ops->error(ltdb); @@ -284,8 +283,10 @@ int ldb_kv_search_key(struct ldb_module *module, struct ltdb_private *ltdb, return LDB_ERR_NO_SUCH_OBJECT on record-not-found and LDB_SUCCESS on success */ -int ldb_kv_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_message *msg, - unsigned int unpack_flags) +int ldb_kv_search_dn1(struct ldb_module *module, + struct ldb_dn *dn, + struct ldb_message *msg, + unsigned int unpack_flags) { void *data = ldb_module_get_private(module); struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); @@ -319,9 +320,7 @@ int ldb_kv_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_m * used for internal memory. * */ - ret = ldb_kv_key_dn_from_idx(module, ltdb, - msg, - dn, &tdb_key); + ret = ldb_kv_key_dn_from_idx(module, ltdb, msg, dn, &tdb_key); if (ret != LDB_SUCCESS) { return ret; } @@ -356,8 +355,9 @@ int ldb_kv_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_m */ int ldb_kv_filter_attrs(TALLOC_CTX *mem_ctx, - const struct ldb_message *msg, const char * const *attrs, - struct ldb_message **filtered_msg) + const struct ldb_message *msg, + const char *const *attrs, + struct ldb_message **filtered_msg) { unsigned int i; bool keep_all = false; @@ -597,7 +597,7 @@ static int ldb_kv_search_full(struct ltdb_context *ctx) } static int ldb_kv_search_and_return_base(struct ltdb_private *ltdb, - struct ltdb_context *ctx) + struct ltdb_context *ctx) { struct ldb_message *msg, *filtered_msg; struct ldb_context *ldb = ldb_module_get_ctx(ctx->module); @@ -610,9 +610,11 @@ static int ldb_kv_search_and_return_base(struct ltdb_private *ltdb, if (!msg) { return LDB_ERR_OPERATIONS_ERROR; } - ret = ldb_kv_search_dn1(ctx->module, ctx->base, msg, - LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC| - LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC); + ret = ldb_kv_search_dn1(ctx->module, + ctx->base, + msg, + LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC | + LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC); if (ret == LDB_ERR_NO_SUCH_OBJECT) { if (ltdb->check_base == false) { @@ -781,10 +783,9 @@ int ldb_kv_search(struct ltdb_context *ctx) * dn. Also optimise the subsequent filter by filling * in the ctx->base to be exactly case correct */ - ret = ldb_kv_search_base(module, ctx, - req->op.search.base, - &ctx->base); - + ret = ldb_kv_search_base( + module, ctx, req->op.search.base, &ctx->base); + if (ret == LDB_ERR_NO_SUCH_OBJECT) { ldb_asprintf_errstring(ldb, "No such Base DN: %s", diff --git a/lib/ldb/ldb_tdb/ldb_tdb.c b/lib/ldb/ldb_tdb/ldb_tdb.c index a18e613c858..c0938c0824c 100644 --- a/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/lib/ldb/ldb_tdb/ldb_tdb.c @@ -197,8 +197,9 @@ bool ldb_kv_key_is_record(TDB_DATA key) note that the key for a record can depend on whether the dn refers to a case sensitive index record or not */ -TDB_DATA ldb_kv_key_dn(struct ldb_module *module, TALLOC_CTX *mem_ctx, - struct ldb_dn *dn) +TDB_DATA ldb_kv_key_dn(struct ldb_module *module, + TALLOC_CTX *mem_ctx, + struct ldb_dn *dn) { TDB_DATA key; char *key_str = NULL; @@ -245,9 +246,9 @@ failed: /* The caller is to provide a correctly sized key */ int ldb_kv_guid_to_key(struct ldb_module *module, - struct ltdb_private *ltdb, - const struct ldb_val *GUID_val, - TDB_DATA *key) + struct ltdb_private *ltdb, + const struct ldb_val *GUID_val, + TDB_DATA *key) { const char *GUID_prefix = LTDB_GUID_KEY_PREFIX; const int GUID_prefix_len = sizeof(LTDB_GUID_KEY_PREFIX) - 1; @@ -267,17 +268,16 @@ int ldb_kv_guid_to_key(struct ldb_module *module, * the GUID index mode */ int ldb_kv_idx_to_key(struct ldb_module *module, - struct ltdb_private *ltdb, - TALLOC_CTX *mem_ctx, - const struct ldb_val *idx_val, - TDB_DATA *key) + struct ltdb_private *ltdb, + TALLOC_CTX *mem_ctx, + const struct ldb_val *idx_val, + TDB_DATA *key) { struct ldb_context *ldb = ldb_module_get_ctx(module); struct ldb_dn *dn; if (ltdb->cache->GUID_index_attribute != NULL) { - return ldb_kv_guid_to_key(module, ltdb, - idx_val, key); + return ldb_kv_guid_to_key(module, ltdb, idx_val, key); } dn = ldb_dn_from_ldb_val(mem_ctx, ldb, idx_val); @@ -305,8 +305,9 @@ int ldb_kv_idx_to_key(struct ldb_module *module, note that the key for a record can depend on whether a GUID index is in use, or the DN is used as the key */ -TDB_DATA ldb_kv_key_msg(struct ldb_module *module, TALLOC_CTX *mem_ctx, - const struct ldb_message *msg) +TDB_DATA ldb_kv_key_msg(struct ldb_module *module, + TALLOC_CTX *mem_ctx, + const struct ldb_message *msg) { void *data = ldb_module_get_private(module); struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); @@ -363,7 +364,7 @@ TDB_DATA ldb_kv_key_msg(struct ldb_module *module, TALLOC_CTX *mem_ctx, currently only @ATTRIBUTES is checked */ static int ldb_kv_check_special_dn(struct ldb_module *module, - const struct ldb_message *msg) + const struct ldb_message *msg) { struct ldb_context *ldb = ldb_module_get_ctx(module); unsigned int i, j; @@ -379,7 +380,8 @@ static int ldb_kv_check_special_dn(struct ldb_module *module, if (ldb_attr_cmp(msg->elements[i].name, "distinguishedName") == 0) continue; for (j = 0; j < msg->elements[i].num_values; j++) { - if (ldb_kv_check_at_attributes_values(&msg->elements[i].values[j]) != 0) { + if (ldb_kv_check_at_attributes_values( + &msg->elements[i].values[j]) != 0) { ldb_set_errstring(ldb, "Invalid attribute value in an @ATTRIBUTES entry"); return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX; } @@ -439,8 +441,10 @@ static int ldb_kv_modified(struct ldb_module *module, struct ldb_dn *dn) return ret; } -static int ltdb_store(struct ltdb_private *ltdb, struct ldb_val ldb_key, - struct ldb_val ldb_data, int flags) +static int ltdb_store(struct ltdb_private *ltdb, + struct ldb_val ldb_key, + struct ldb_val ldb_data, + int flags) { TDB_DATA key = { .dptr = ldb_key.data, @@ -470,10 +474,9 @@ static const char *ltdb_errorstr(struct ltdb_private *ltdb) /* store a record into the db */ -int ldb_kv_store( - struct ldb_module *module, - const struct ldb_message *msg, - int flgs) +int ldb_kv_store(struct ldb_module *module, + const struct ldb_message *msg, + int flgs) { void *data = ldb_module_get_private(module); struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); @@ -537,7 +540,7 @@ done: check if a attribute is a single valued, for a given element */ static bool ldb_kv_single_valued(const struct ldb_schema_attribute *a, - struct ldb_message_element *el) + struct ldb_message_element *el) { if (!a) return false; if (el != NULL) { @@ -562,9 +565,9 @@ static bool ldb_kv_single_valued(const struct ldb_schema_attribute *a, } static int ldb_kv_add_internal(struct ldb_module *module, - struct ltdb_private *ltdb, - const struct ldb_message *msg, - bool check_single_value) + struct ltdb_private *ltdb, + const struct ldb_message *msg, + bool check_single_value) { struct ldb_context *ldb = ldb_module_get_ctx(module); int ret = LDB_SUCCESS; @@ -579,9 +582,8 @@ static int ldb_kv_add_internal(struct ldb_module *module, el->name, ldb_dn_get_linearized(msg->dn)); return LDB_ERR_CONSTRAINT_VIOLATION; } - if (check_single_value && - el->num_values > 1 && - ldb_kv_single_valued(a, el)) { + if (check_single_value && el->num_values > 1 && + ldb_kv_single_valued(a, el)) { ldb_asprintf_errstring(ldb, "SINGLE-VALUE attribute %s on %s specified more than once", el->name, ldb_dn_get_linearized(msg->dn)); return LDB_ERR_CONSTRAINT_VIOLATION; @@ -630,8 +632,8 @@ static int ldb_kv_add_internal(struct ldb_module *module, if (mem_ctx == NULL) { return ldb_module_operr(module); } - ret2 = ldb_kv_search_base(module, mem_ctx, - msg->dn, &dn2); + ret2 = + ldb_kv_search_base(module, mem_ctx, msg->dn, &dn2); TALLOC_FREE(mem_ctx); if (ret2 == LDB_SUCCESS) { ret = LDB_ERR_ENTRY_ALREADY_EXISTS; @@ -698,8 +700,7 @@ static int ldb_kv_add(struct ltdb_context *ctx) return LDB_ERR_OPERATIONS_ERROR; } - ret = ldb_kv_add_internal(module, ltdb, - req->op.add.message, true); + ret = ldb_kv_add_internal(module, ltdb, req->op.add.message, true); return ret; } @@ -722,7 +723,7 @@ static int ltdb_delete(struct ltdb_private *ltdb, struct ldb_val ldb_key) index records) */ int ldb_kv_delete_noindex(struct ldb_module *module, - const struct ldb_message *msg) + const struct ldb_message *msg) { void *data = ldb_module_get_private(module); struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); @@ -771,7 +772,8 @@ static int ldb_kv_delete_internal(struct ldb_module *module, struct ldb_dn *dn) /* in case any attribute of the message was indexed, we need to fetch the old record */ - ret = ldb_kv_search_dn1(module, dn, msg, LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC); + ret = ldb_kv_search_dn1( + module, dn, msg, LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC); if (ret != LDB_SUCCESS) { /* not finding the old record is an error */ goto done; @@ -845,7 +847,7 @@ static int ldb_kv_find_element(const struct ldb_message *msg, const char *name) returns 0 on success, -1 on failure (and sets errno) */ static int ldb_kv_msg_add_element(struct ldb_message *msg, - struct ldb_message_element *el) + struct ldb_message_element *el) { struct ldb_message_element *e2; unsigned int i; @@ -888,8 +890,9 @@ static int ldb_kv_msg_add_element(struct ldb_message *msg, delete all elements having a specified attribute name */ static int ldb_kv_msg_delete_attribute(struct ldb_module *module, - struct ltdb_private *ltdb, - struct ldb_message *msg, const char *name) + struct ltdb_private *ltdb, + struct ldb_message *msg, + const char *name) { unsigned int i; int ret; @@ -934,10 +937,10 @@ static int ldb_kv_msg_delete_attribute(struct ldb_module *module, return LDB Error on failure */ static int ldb_kv_msg_delete_element(struct ldb_module *module, - struct ltdb_private *ltdb, - struct ldb_message *msg, - const char *name, - const struct ldb_val *val) + struct ltdb_private *ltdb, + struct ldb_message *msg, + const char *name, + const struct ldb_val *val) { struct ldb_context *ldb = ldb_module_get_ctx(module); unsigned int i; @@ -967,8 +970,8 @@ static int ldb_kv_msg_delete_element(struct ldb_module *module, } if (matched) { if (el->num_values == 1) { - return ldb_kv_msg_delete_attribute(module, - ltdb, msg, name); + return ldb_kv_msg_delete_attribute( + module, ltdb, msg, name); } ret = ldb_kv_index_del_value(module, ltdb, msg, el, i); @@ -1003,8 +1006,8 @@ static int ldb_kv_msg_delete_element(struct ldb_module *module, 'req' is optional, and is used to specify controls if supplied */ int ldb_kv_modify_internal(struct ldb_module *module, - const struct ldb_message *msg, - struct ldb_request *req) + const struct ldb_message *msg, + struct ldb_request *req) { struct ldb_context *ldb = ldb_module_get_ctx(module); void *data = ldb_module_get_private(module); @@ -1030,9 +1033,8 @@ int ldb_kv_modify_internal(struct ldb_module *module, goto done; } - ret = ldb_kv_search_dn1(module, msg->dn, - msg2, - LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC); + ret = ldb_kv_search_dn1( + module, msg->dn, msg2, LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC); if (ret != LDB_SUCCESS) { goto done; } @@ -1094,9 +1096,8 @@ int ldb_kv_modify_internal(struct ldb_module *module, ret = LDB_ERR_OTHER; goto done; } - ret = ldb_kv_index_add_element(module, ltdb, - msg2, - el); + ret = ldb_kv_index_add_element( + module, ltdb, msg2, el); if (ret != LDB_SUCCESS) { goto done; } @@ -1176,8 +1177,8 @@ int ldb_kv_modify_internal(struct ldb_module *module, el2->values = vals; el2->num_values += el->num_values; - ret = ldb_kv_index_add_element(module, ltdb, - msg2, el); + ret = ldb_kv_index_add_element( + module, ltdb, msg2, el); if (ret != LDB_SUCCESS) { goto done; } @@ -1241,9 +1242,8 @@ int ldb_kv_modify_internal(struct ldb_module *module, } /* Delete the attribute if it exists in the DB */ - if (ldb_kv_msg_delete_attribute(module, ltdb, - msg2, - el->name) != 0) { + if (ldb_kv_msg_delete_attribute( + module, ltdb, msg2, el->name) != 0) { ret = LDB_ERR_OTHER; goto done; } @@ -1255,8 +1255,7 @@ int ldb_kv_modify_internal(struct ldb_module *module, goto done; } - ret = ldb_kv_index_add_element(module, ltdb, - msg2, el); + ret = ldb_kv_index_add_element(module, ltdb, msg2, el); if (ret != LDB_SUCCESS) { goto done; } @@ -1272,10 +1271,8 @@ int ldb_kv_modify_internal(struct ldb_module *module, if (msg->elements[i].num_values == 0) { /* Delete the whole attribute */ - ret = ldb_kv_msg_delete_attribute(module, - ltdb, - msg2, - msg->elements[i].name); + ret = ldb_kv_msg_delete_attribute( + module, ltdb, msg2, msg->elements[i].name); if (ret == LDB_ERR_NO_SUCH_ATTRIBUTE && control_permissive) { ret = LDB_SUCCESS; @@ -1290,11 +1287,12 @@ int ldb_kv_modify_internal(struct ldb_module *module, } else { /* Delete specified values from an attribute */ for (j=0; j < msg->elements[i].num_values; j++) { - ret = ldb_kv_msg_delete_element(module, - ltdb, - msg2, - msg->elements[i].name, - &msg->elements[i].values[j]); + ret = ldb_kv_msg_delete_element( + module, + ltdb, + msg2, + msg->elements[i].name, + &msg->elements[i].values[j]); if (ret == LDB_ERR_NO_SUCH_ATTRIBUTE && control_permissive) { ret = LDB_SUCCESS; @@ -1385,8 +1383,10 @@ static int ldb_kv_rename(struct ltdb_context *ctx) } /* we need to fetch the old record to re-add under the new name */ - ret = ldb_kv_search_dn1(module, req->op.rename.olddn, msg, - LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC); + ret = ldb_kv_search_dn1(module, + req->op.rename.olddn, + msg, + LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC); if (ret != LDB_SUCCESS) { /* not finding the old record is an error */ return ret; @@ -1418,9 +1418,8 @@ static int ldb_kv_rename(struct ltdb_context *ctx) */ if (tdb_key_old.dsize != tdb_key.dsize || memcmp(tdb_key.dptr, tdb_key_old.dptr, tdb_key.dsize) != 0) { - ret = ldb_kv_search_base(module, msg, - req->op.rename.newdn, - &db_dn); + ret = ldb_kv_search_base( + module, msg, req->op.rename.newdn, &db_dn); if (ret == LDB_SUCCESS) { ret = LDB_ERR_ENTRY_ALREADY_EXISTS; } else if (ret == LDB_ERR_NO_SUCH_OBJECT) { @@ -1566,7 +1565,6 @@ static int ldb_kv_start_trans(struct ldb_module *module) return ltdb->kv_ops->error(ltdb); } - ldb_kv_index_transaction_start(module); ltdb->reindex_failed = false; @@ -1676,7 +1674,6 @@ static int ldb_kv_del_trans(struct ldb_module *module) void *data = ldb_module_get_private(module); struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); - if (ldb_kv_index_transaction_cancel(module) != 0) { ltdb->kv_ops->abort_write(ltdb); return ltdb->kv_ops->error(ltdb); @@ -1690,7 +1687,7 @@ static int ldb_kv_del_trans(struct ldb_module *module) return sequenceNumber from @BASEINFO */ static int ldb_kv_sequence_number(struct ltdb_context *ctx, - struct ldb_extended **ext) + struct ldb_extended **ext) { struct ldb_context *ldb; struct ldb_module *module = ctx->module; @@ -1809,9 +1806,9 @@ static void ldb_kv_request_done(struct ltdb_context *ctx, int error) } static void ldb_kv_timeout(struct tevent_context *ev, - struct tevent_timer *te, - struct timeval t, - void *private_data) + struct tevent_timer *te, + struct timeval t, + void *private_data) { struct ltdb_context *ctx; ctx = talloc_get_type(private_data, struct ltdb_context); @@ -1830,8 +1827,8 @@ static void ldb_kv_timeout(struct tevent_context *ev, } static void ldb_kv_request_extended_done(struct ltdb_context *ctx, - struct ldb_extended *ext, - int error) + struct ldb_extended *ext, + int error) { struct ldb_context *ldb; struct ldb_request *req; @@ -1884,7 +1881,10 @@ struct kv_ctx { void *private_data); }; -static int ltdb_traverse_fn_wrapper(struct tdb_context *tdb, TDB_DATA tdb_key, TDB_DATA tdb_data, void *ctx) +static int ltdb_traverse_fn_wrapper(struct tdb_context *tdb, + TDB_DATA tdb_key, + TDB_DATA tdb_data, + void *ctx) { struct kv_ctx *kv_ctx = ctx; struct ldb_val key = { @@ -1898,7 +1898,9 @@ static int ltdb_traverse_fn_wrapper(struct tdb_context *tdb, TDB_DATA tdb_key, T return kv_ctx->kv_traverse_fn(kv_ctx->ltdb, key, data, kv_ctx->ctx); } -static int ltdb_traverse_fn(struct ltdb_private *ltdb, ldb_kv_traverse_fn fn, void *ctx) +static int ltdb_traverse_fn(struct ltdb_private *ltdb, + ldb_kv_traverse_fn fn, + void *ctx) { struct kv_ctx kv_ctx = { .kv_traverse_fn = fn, @@ -1906,16 +1908,19 @@ static int ltdb_traverse_fn(struct ltdb_private *ltdb, ldb_kv_traverse_fn fn, vo .ltdb = ltdb }; if (tdb_transaction_active(ltdb->tdb)) { - return tdb_traverse(ltdb->tdb, ltdb_traverse_fn_wrapper, &kv_ctx); + return tdb_traverse( + ltdb->tdb, ltdb_traverse_fn_wrapper, &kv_ctx); } else { - return tdb_traverse_read(ltdb->tdb, ltdb_traverse_fn_wrapper, &kv_ctx); + return tdb_traverse_read( + ltdb->tdb, ltdb_traverse_fn_wrapper, &kv_ctx); } } static int ltdb_update_in_iterate(struct ltdb_private *ltdb, - struct ldb_val ldb_key, - struct ldb_val ldb_key2, - struct ldb_val ldb_data, void *state) + struct ldb_val ldb_key, + struct ldb_val ldb_key2, + struct ldb_val ldb_data, + void *state) { int tdb_ret; struct ldb_context *ldb; @@ -1964,8 +1969,9 @@ static int ltdb_update_in_iterate(struct ltdb_private *ltdb, return tdb_ret; } -static int ltdb_parse_record_wrapper(TDB_DATA tdb_key, TDB_DATA tdb_data, - void *ctx) +static int ltdb_parse_record_wrapper(TDB_DATA tdb_key, + TDB_DATA tdb_data, + void *ctx) { struct kv_ctx *kv_ctx = ctx; struct ldb_val key = { @@ -1981,11 +1987,11 @@ static int ltdb_parse_record_wrapper(TDB_DATA tdb_key, TDB_DATA tdb_data, } static int ltdb_parse_record(struct ltdb_private *ltdb, - struct ldb_val ldb_key, - int (*parser)(struct ldb_val key, - struct ldb_val data, - void *private_data), - void *ctx) + struct ldb_val ldb_key, + int (*parser)(struct ldb_val key, + struct ldb_val data, + void *private_data), + void *ctx) { struct kv_ctx kv_ctx = { .parser = parser, @@ -2003,15 +2009,15 @@ static int ltdb_parse_record(struct ltdb_private *ltdb, return LDB_ERR_PROTOCOL_ERROR; } - ret = tdb_parse_record(ltdb->tdb, key, ltdb_parse_record_wrapper, - &kv_ctx); + ret = tdb_parse_record( + ltdb->tdb, key, ltdb_parse_record_wrapper, &kv_ctx); if (ret == 0) { return LDB_SUCCESS; } return ltdb_err_map(tdb_error(ltdb->tdb)); } -static const char * ltdb_name(struct ltdb_private *ltdb) +static const char *ltdb_name(struct ltdb_private *ltdb) { return tdb_name(ltdb->tdb); } @@ -2032,28 +2038,28 @@ static bool ltdb_transaction_active(struct ltdb_private *ltdb) } static const struct kv_db_ops key_value_ops = { - .store = ltdb_store, - .delete = ltdb_delete, - .iterate = ltdb_traverse_fn, - .update_in_iterate = ltdb_update_in_iterate, - .fetch_and_parse = ltdb_parse_record, - .lock_read = ltdb_lock_read, - .unlock_read = ltdb_unlock_read, - .begin_write = ltdb_transaction_start, - .prepare_write = ltdb_transaction_prepare_commit, - .finish_write = ltdb_transaction_commit, - .abort_write = ltdb_transaction_cancel, - .error = ltdb_error, - .errorstr = ltdb_errorstr, - .name = ltdb_name, - .has_changed = ltdb_changed, - .transaction_active = ltdb_transaction_active, + .store = ltdb_store, + .delete = ltdb_delete, + .iterate = ltdb_traverse_fn, + .update_in_iterate = ltdb_update_in_iterate, + .fetch_and_parse = ltdb_parse_record, + .lock_read = ltdb_lock_read, + .unlock_read = ltdb_unlock_read, + .begin_write = ltdb_transaction_start, + .prepare_write = ltdb_transaction_prepare_commit, + .finish_write = ltdb_transaction_commit, + .abort_write = ltdb_transaction_cancel, + .error = ltdb_error, + .errorstr = ltdb_errorstr, + .name = ltdb_name, + .has_changed = ltdb_changed, + .transaction_active = ltdb_transaction_active, }; static void ldb_kv_callback(struct tevent_context *ev, - struct tevent_timer *te, - struct timeval t, - void *private_data) + struct tevent_timer *te, + struct timeval t, + void *private_data) { struct ltdb_context *ctx; int ret; @@ -2116,7 +2122,7 @@ static int ldb_kv_request_destructor(void *ptr) } static int ldb_kv_handle_request(struct ldb_module *module, - struct ldb_request *req) + struct ldb_request *req) { struct ldb_control *control_permissive; struct ldb_context *ldb; @@ -2167,8 +2173,8 @@ static int ldb_kv_handle_request(struct ldb_module *module, if (req->timeout > 0) { tv.tv_sec = req->starttime + req->timeout; tv.tv_usec = 0; - ac->timeout_event = tevent_add_timer(ev, ac, tv, - ldb_kv_timeout, ac); + ac->timeout_event = + tevent_add_timer(ev, ac, tv, ldb_kv_timeout, ac); if (NULL == ac->timeout_event) { talloc_free(ac); return LDB_ERR_OPERATIONS_ERROR; @@ -2198,7 +2204,6 @@ static int ldb_kv_init_rootdse(struct ldb_module *module) return LDB_SUCCESS; } - static int ldb_kv_lock_read(struct ldb_module *module) { void *data = ldb_module_get_private(module); @@ -2214,20 +2219,20 @@ static int ldb_kv_unlock_read(struct ldb_module *module) } static const struct ldb_module_ops ldb_kv_ops = { - .name = "tdb", - .init_context = ldb_kv_init_rootdse, - .search = ldb_kv_handle_request, - .add = ldb_kv_handle_request, - .modify = ldb_kv_handle_request, - .del = ldb_kv_handle_request, - .rename = ldb_kv_handle_request, - .extended = ldb_kv_handle_request, - .start_transaction = ldb_kv_start_trans, - .end_transaction = ldb_kv_end_trans, - .prepare_commit = ldb_kv_prepare_commit, - .del_transaction = ldb_kv_del_trans, - .read_lock = ldb_kv_lock_read, - .read_unlock = ldb_kv_unlock_read, + .name = "tdb", + .init_context = ldb_kv_init_rootdse, + .search = ldb_kv_handle_request, + .add = ldb_kv_handle_request, + .modify = ldb_kv_handle_request, + .del = ldb_kv_handle_request, + .rename = ldb_kv_handle_request, + .extended = ldb_kv_handle_request, + .start_transaction = ldb_kv_start_trans, + .end_transaction = ldb_kv_end_trans, + .prepare_commit = ldb_kv_prepare_commit, + .del_transaction = ldb_kv_del_trans, + .read_lock = ldb_kv_lock_read, + .read_unlock = ldb_kv_unlock_read, }; int ldb_kv_init_store(struct ltdb_private *ltdb, diff --git a/lib/ldb/ldb_tdb/ldb_tdb.h b/lib/ldb/ldb_tdb/ldb_tdb.h index 675355ea416..861d94a124f 100644 --- a/lib/ldb/ldb_tdb/ldb_tdb.h +++ b/lib/ldb/ldb_tdb/ldb_tdb.h @@ -164,49 +164,55 @@ struct ldb_parse_tree; int ldb_kv_search_indexed(struct ltdb_context *ctx, uint32_t *); int ldb_kv_index_add_new(struct ldb_module *module, - struct ltdb_private *ltdb, - const struct ldb_message *msg); -int ldb_kv_index_delete(struct ldb_module *module, const struct ldb_message *msg); -int ldb_kv_index_del_element(struct ldb_module *module, - struct ltdb_private *ltdb, - const struct ldb_message *msg, - struct ldb_message_element *el); -int ldb_kv_index_add_element(struct ldb_module *module, - struct ltdb_private *ltdb, - const struct ldb_message *msg, - struct ldb_message_element *el); -int ldb_kv_index_del_value(struct ldb_module *module, struct ltdb_private *ltdb, - const struct ldb_message *msg, - struct ldb_message_element *el, unsigned int v_idx); + const struct ldb_message *msg); +int ldb_kv_index_delete(struct ldb_module *module, + const struct ldb_message *msg); +int ldb_kv_index_del_element(struct ldb_module *module, + struct ltdb_private *ltdb, + const struct ldb_message *msg, + struct ldb_message_element *el); +int ldb_kv_index_add_element(struct ldb_module *module, + struct ltdb_private *ltdb, + const struct ldb_message *msg, + struct ldb_message_element *el); +int ldb_kv_index_del_value(struct ldb_module *module, + struct ltdb_private *ltdb, + const struct ldb_message *msg, + struct ldb_message_element *el, + unsigned int v_idx); int ldb_kv_reindex(struct ldb_module *module); int ldb_kv_index_transaction_start(struct ldb_module *module); int ldb_kv_index_transaction_commit(struct ldb_module *module); int ldb_kv_index_transaction_cancel(struct ldb_module *module); int ldb_kv_key_dn_from_idx(struct ldb_module *module, - struct ltdb_private *ltdb, - TALLOC_CTX *mem_ctx, - struct ldb_dn *dn, - TDB_DATA *tdb_key); + struct ltdb_private *ltdb, + TALLOC_CTX *mem_ctx, + struct ldb_dn *dn, + TDB_DATA *tdb_key); /* The following definitions come from lib/ldb/ldb_tdb/ldb_search.c */ int ltdb_has_wildcard(struct ldb_module *module, const char *attr_name, const struct ldb_val *val); void ltdb_search_dn1_free(struct ldb_module *module, struct ldb_message *msg); -int ldb_kv_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_message *msg, - unsigned int unpack_flags); +int ldb_kv_search_dn1(struct ldb_module *module, + struct ldb_dn *dn, + struct ldb_message *msg, + unsigned int unpack_flags); int ldb_kv_search_base(struct ldb_module *module, - TALLOC_CTX *mem_ctx, - struct ldb_dn *dn, - struct ldb_dn **ret_dn); -int ldb_kv_search_key(struct ldb_module *module, struct ltdb_private *ltdb, - struct TDB_DATA tdb_key, - struct ldb_message *msg, - unsigned int unpack_flags); + TALLOC_CTX *mem_ctx, + struct ldb_dn *dn, + struct ldb_dn **ret_dn); +int ldb_kv_search_key(struct ldb_module *module, + struct ltdb_private *ltdb, + struct TDB_DATA tdb_key, + struct ldb_message *msg, + unsigned int unpack_flags); int ldb_kv_filter_attrs(TALLOC_CTX *mem_ctx, - const struct ldb_message *msg, const char * const *attrs, - struct ldb_message **filtered_msg); + const struct ldb_message *msg, + const char *const *attrs, + struct ldb_message **filtered_msg); int ldb_kv_search(struct ltdb_context *ctx); /* The following definitions come from lib/ldb/ldb_tdb/ldb_tdb.c */ @@ -215,32 +221,40 @@ int ldb_kv_search(struct ltdb_context *ctx); * index, the old DN index and a possible future ID= */ bool ldb_kv_key_is_record(TDB_DATA key); -TDB_DATA ldb_kv_key_dn(struct ldb_module *module, TALLOC_CTX *mem_ctx, - struct ldb_dn *dn); -TDB_DATA ldb_kv_key_msg(struct ldb_module *module, TALLOC_CTX *mem_ctx, - const struct ldb_message *msg); -int ldb_kv_guid_to_key(struct ldb_module *module, - struct ltdb_private *ltdb, - const struct ldb_val *GUID_val, - TDB_DATA *key); -int ldb_kv_idx_to_key(struct ldb_module *module, - struct ltdb_private *ltdb, - TALLOC_CTX *mem_ctx, - const struct ldb_val *idx_val, - TDB_DATA *key); -TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn); -int ldb_kv_store(struct ldb_module *module, const struct ldb_message *msg, int flgs); -int ldb_kv_modify_internal(struct ldb_module *module, const struct ldb_message *msg, struct ldb_request *req); -int ldb_kv_delete_noindex(struct ldb_module *module, +TDB_DATA ldb_kv_key_dn(struct ldb_module *module, + TALLOC_CTX *mem_ctx, + struct ldb_dn *dn); +TDB_DATA ldb_kv_key_msg(struct ldb_module *module, + TALLOC_CTX *mem_ctx, const struct ldb_message *msg); +int ldb_kv_guid_to_key(struct ldb_module *module, + struct ltdb_private *ltdb, + const struct ldb_val *GUID_val, + TDB_DATA *key); +int ldb_kv_idx_to_key(struct ldb_module *module, + struct ltdb_private *ltdb, + TALLOC_CTX *mem_ctx, + const struct ldb_val *idx_val, + TDB_DATA *key); +TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn); +int ldb_kv_store(struct ldb_module *module, + const struct ldb_message *msg, + int flgs); +int ldb_kv_modify_internal(struct ldb_module *module, + const struct ldb_message *msg, + struct ldb_request *req); +int ldb_kv_delete_noindex(struct ldb_module *module, + const struct ldb_message *msg); int ltdb_err_map(enum TDB_ERROR tdb_code); struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx, const char *path, int hash_size, int tdb_flags, int open_flags, mode_t mode, struct ldb_context *ldb); -int ldb_kv_init_store(struct ltdb_private *ltdb, const char *name, - struct ldb_context *ldb, const char *options[], +int ldb_kv_init_store(struct ltdb_private *ltdb, + const char *name, + struct ldb_context *ldb, + const char *options[], struct ldb_module **_module); int ltdb_connect(struct ldb_context *ldb, const char *url,