From: Gary Lockyer Date: Thu, 19 Jul 2018 19:23:10 +0000 (+1200) Subject: lib ldb: Rename functions to ldb_kv X-Git-Tag: ldb-1.5.0~92 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c8ea099ce57ae35879e9a1cebcfd2de5c89bfdf;p=thirdparty%2Fsamba.git lib ldb: Rename functions to ldb_kv Rename the ldb key value functions from ltdb_* to ldb_kv_*. The renaming is preparation for the separation of the tdb specific code from the key value code. This work is a follow on from the addition of the lmdb backend. Note that the next commit tidies up the code formatting. Signed-off-by: Gary Lockyer Reviewed-by: Andrew Bartlett --- diff --git a/lib/ldb/ldb_mdb/ldb_mdb.c b/lib/ldb/ldb_mdb/ldb_mdb.c index bd84fe10bcd..befcb2a7fa0 100644 --- a/lib/ldb/ldb_mdb/ldb_mdb.c +++ b/lib/ldb/ldb_mdb/ldb_mdb.c @@ -885,5 +885,6 @@ int lmdb_connect(struct ldb_context *ldb, */ ltdb->max_key_length = LDB_MDB_MAX_KEY_LENGTH; - return init_store(ltdb, "ldb_mdb backend", ldb, options, _module); + return ldb_kv_init_store( + ltdb, "ldb_mdb backend", ldb, options, _module); } diff --git a/lib/ldb/ldb_tdb/ldb_cache.c b/lib/ldb/ldb_tdb/ldb_cache.c index 1856fb13877..e9da45db2d5 100644 --- a/lib/ldb/ldb_tdb/ldb_cache.c +++ b/lib/ldb/ldb_tdb/ldb_cache.c @@ -42,7 +42,7 @@ static const struct { const char *name; int value; -} ltdb_valid_attr_flags[] = { +} ldb_kv_valid_attr_flags[] = { { "CASE_INSENSITIVE", LTDB_FLAG_CASE_INSENSITIVE }, { "INTEGER", LTDB_FLAG_INTEGER }, { "HIDDEN", 0 }, @@ -51,11 +51,10 @@ static const struct { { NULL, 0 } }; - /* de-register any special handlers for @ATTRIBUTES */ -static void ltdb_attributes_unload(struct ldb_module *module) +static void ldb_kv_attributes_unload(struct ldb_module *module) { struct ldb_context *ldb = ldb_module_get_ctx(module); @@ -66,20 +65,20 @@ static void ltdb_attributes_unload(struct ldb_module *module) /* add up the attrib flags for a @ATTRIBUTES element */ -static int ltdb_attributes_flags(struct ldb_message_element *el, unsigned *v) +static int ldb_kv_attributes_flags(struct ldb_message_element *el, unsigned *v) { unsigned int i; unsigned value = 0; for (i=0;inum_values;i++) { unsigned int j; - for (j=0;ltdb_valid_attr_flags[j].name;j++) { - if (strcmp(ltdb_valid_attr_flags[j].name, + for (j = 0; ldb_kv_valid_attr_flags[j].name; j++) { + if (strcmp(ldb_kv_valid_attr_flags[j].name, (char *)el->values[i].data) == 0) { - value |= ltdb_valid_attr_flags[j].value; + value |= ldb_kv_valid_attr_flags[j].value; break; } } - if (ltdb_valid_attr_flags[j].name == NULL) { + if (ldb_kv_valid_attr_flags[j].name == NULL) { return -1; } } @@ -97,7 +96,7 @@ static int ldb_schema_attribute_compare(const void *p1, const void *p2) /* register any special handlers from @ATTRIBUTES */ -static int ltdb_attributes_load(struct ldb_module *module) +static int ldb_kv_attributes_load(struct ldb_module *module) { struct ldb_schema_attribute *attrs; struct ldb_context *ldb; @@ -123,10 +122,12 @@ static int ltdb_attributes_load(struct ldb_module *module) dn = ldb_dn_new(module, ldb, LTDB_ATTRIBUTES); if (dn == NULL) goto failed; - r = ltdb_search_dn1(module, dn, attrs_msg, - LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC - |LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC - |LDB_UNPACK_DATA_FLAG_NO_DN); + r = ldb_kv_search_dn1(module, + dn, + attrs_msg, + LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC | + LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC | + LDB_UNPACK_DATA_FLAG_NO_DN); talloc_free(dn); if (r != LDB_SUCCESS && r != LDB_ERR_NO_SUCH_OBJECT) { goto failed; @@ -162,7 +163,8 @@ static int ltdb_attributes_load(struct ldb_module *module) continue; } - if (ltdb_attributes_flags(&attrs_msg->elements[i], &flags) != 0) { + if (ldb_kv_attributes_flags(&attrs_msg->elements[i], &flags) != + 0) { ldb_debug(ldb, LDB_DEBUG_ERROR, "Invalid @ATTRIBUTES element for '%s'", attrs_msg->elements[i].name); @@ -233,8 +235,8 @@ failed: /* register any index records we find for the DB */ -static int ltdb_index_load(struct ldb_module *module, - struct ltdb_private *ltdb) +static int ldb_kv_index_load(struct ldb_module *module, + struct ltdb_private *ltdb) { struct ldb_context *ldb = ldb_module_get_ctx(module); struct ldb_dn *indexlist_dn; @@ -268,10 +270,12 @@ static int ltdb_index_load(struct ldb_module *module, return -1; } - r = ltdb_search_dn1(module, indexlist_dn, ltdb->cache->indexlist, - LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC - |LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC - |LDB_UNPACK_DATA_FLAG_NO_DN); + r = ldb_kv_search_dn1(module, + indexlist_dn, + ltdb->cache->indexlist, + LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC | + LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC | + LDB_UNPACK_DATA_FLAG_NO_DN); TALLOC_FREE(indexlist_dn); if (r != LDB_SUCCESS && r != LDB_ERR_NO_SUCH_OBJECT) { @@ -311,7 +315,7 @@ static int ltdb_index_load(struct ldb_module *module, /* initialise the baseinfo record */ -static int ltdb_baseinfo_init(struct ldb_module *module) +static int ldb_kv_baseinfo_init(struct ldb_module *module) { struct ldb_context *ldb; void *data = ldb_module_get_private(module); @@ -352,8 +356,8 @@ static int ltdb_baseinfo_init(struct ldb_module *module) goto failed; } val.length = 1; - - ret = ltdb_store(module, msg, TDB_INSERT); + + ret = ldb_kv_store(module, msg, TDB_INSERT); talloc_free(msg); @@ -368,7 +372,7 @@ failed: /* free any cache records */ -static void ltdb_cache_free(struct ldb_module *module) +static void ldb_kv_cache_free(struct ldb_module *module) { void *data = ldb_module_get_private(module); struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); @@ -381,17 +385,17 @@ static void ltdb_cache_free(struct ldb_module *module) /* force a cache reload */ -int ltdb_cache_reload(struct ldb_module *module) +int ldb_kv_cache_reload(struct ldb_module *module) { - ltdb_attributes_unload(module); - ltdb_cache_free(module); - return ltdb_cache_load(module); + ldb_kv_attributes_unload(module); + ldb_kv_cache_free(module); + return ldb_kv_cache_load(module); } /* load the cache records */ -int ltdb_cache_load(struct ldb_module *module) +int ldb_kv_cache_load(struct ldb_module *module) { struct ldb_context *ldb; void *data = ldb_module_get_private(module); @@ -425,7 +429,7 @@ int ltdb_cache_load(struct ldb_module *module) if (r != LDB_SUCCESS) { goto failed; } - r= ltdb_search_dn1(module, baseinfo_dn, baseinfo, 0); + r = ldb_kv_search_dn1(module, baseinfo_dn, baseinfo, 0); if (r != LDB_SUCCESS && r != LDB_ERR_NO_SUCH_OBJECT) { goto failed_and_unlock; } @@ -447,9 +451,10 @@ int ltdb_cache_load(struct ldb_module *module) /* error handling for ltdb_baseinfo_init() is by looking for the record again. */ - ltdb_baseinfo_init(module); + ldb_kv_baseinfo_init(module); - if (ltdb_search_dn1(module, baseinfo_dn, baseinfo, 0) != LDB_SUCCESS) { + if (ldb_kv_search_dn1(module, baseinfo_dn, baseinfo, 0) != + LDB_SUCCESS) { goto failed_and_unlock; } @@ -474,7 +479,7 @@ int ltdb_cache_load(struct ldb_module *module) options_dn = ldb_dn_new(options, ldb, LTDB_OPTIONS); if (options_dn == NULL) goto failed_and_unlock; - r= ltdb_search_dn1(module, options_dn, options, 0); + r = ldb_kv_search_dn1(module, options_dn, options, 0); talloc_free(options_dn); if (r != LDB_SUCCESS && r != LDB_ERR_NO_SUCH_OBJECT) { goto failed_and_unlock; @@ -501,9 +506,9 @@ int ltdb_cache_load(struct ldb_module *module) * the handlers across all databases when used under Samba's * partition module. */ - ltdb_attributes_unload(module); + ldb_kv_attributes_unload(module); - if (ltdb_index_load(module, ltdb) == -1) { + if (ldb_kv_index_load(module, ltdb) == -1) { goto failed_and_unlock; } @@ -512,7 +517,7 @@ int ltdb_cache_load(struct ldb_module *module) * the handlers across all databases when used under Samba's * partition module. */ - if (ltdb_attributes_load(module) == -1) { + if (ldb_kv_attributes_load(module) == -1) { goto failed_and_unlock; } @@ -557,7 +562,7 @@ failed: /* increase the sequence number to indicate a database change */ -int ltdb_increase_sequence_number(struct ldb_module *module) +int ldb_kv_increase_sequence_number(struct ldb_module *module) { struct ldb_context *ldb; void *data = ldb_module_get_private(module); @@ -624,7 +629,7 @@ int ltdb_increase_sequence_number(struct ldb_module *module) val_time.data = (uint8_t *)s; val_time.length = strlen(s); - ret = ltdb_modify_internal(module, msg, NULL); + ret = ldb_kv_modify_internal(module, msg, NULL); talloc_free(msg); @@ -639,12 +644,13 @@ int ltdb_increase_sequence_number(struct ldb_module *module) return ret; } -int ltdb_check_at_attributes_values(const struct ldb_val *value) +int ldb_kv_check_at_attributes_values(const struct ldb_val *value) { unsigned int i; - for (i = 0; ltdb_valid_attr_flags[i].name != NULL; i++) { - if ((strcmp(ltdb_valid_attr_flags[i].name, (char *)value->data) == 0)) { + for (i = 0; ldb_kv_valid_attr_flags[i].name != NULL; i++) { + if ((strcmp(ldb_kv_valid_attr_flags[i].name, + (char *)value->data) == 0)) { return 0; } } diff --git a/lib/ldb/ldb_tdb/ldb_index.c b/lib/ldb/ldb_tdb/ldb_index.c index fb606124fb4..75073a19b4c 100644 --- a/lib/ldb/ldb_tdb/ldb_index.c +++ b/lib/ldb/ldb_tdb/ldb_index.c @@ -170,17 +170,17 @@ enum key_truncation { KEY_TRUNCATED, }; -static int ltdb_write_index_dn_guid(struct ldb_module *module, - const struct ldb_message *msg, - int add); -static int ltdb_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); +static int ldb_kv_write_index_dn_guid(struct ldb_module *module, + const struct ldb_message *msg, + int add); +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); -static void ltdb_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); /* we put a @IDXVERSION attribute on index entries. This allows us to tell if it was written by an older version @@ -189,7 +189,8 @@ static void ltdb_dn_list_sort(struct ltdb_private *ltdb, #define LTDB_GUID_INDEXING_VERSION 3 -static unsigned ltdb_max_key_length(struct ltdb_private *ltdb) { +static unsigned ldb_kv_max_key_length(struct ltdb_private *ltdb) +{ if (ltdb->max_key_length == 0){ return UINT_MAX; } @@ -197,7 +198,7 @@ static unsigned ltdb_max_key_length(struct ltdb_private *ltdb) { } /* enable the idxptr mode when transactions start */ -int ltdb_index_transaction_start(struct ldb_module *module) +int ldb_kv_index_transaction_start(struct ldb_module *module) { struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module), struct ltdb_private); ltdb->idxptr = talloc_zero(ltdb, struct ltdb_idxptr); @@ -247,9 +248,9 @@ static int ldb_val_equal_exact_ordered(const struct ldb_val v1, This is therefore safe when the value is a GUID in the future */ -static int ltdb_dn_list_find_val(struct ltdb_private *ltdb, - const struct dn_list *list, - const struct ldb_val *v) +static int ldb_kv_dn_list_find_val(struct ltdb_private *ltdb, + const struct dn_list *list, + const struct ldb_val *v) { unsigned int i; struct ldb_val *exact = NULL, *next = NULL; @@ -282,9 +283,9 @@ static int ltdb_dn_list_find_val(struct ltdb_private *ltdb, find a entry in a dn_list. Uses a case sensitive comparison with the dn returns -1 if not found */ -static int ltdb_dn_list_find_msg(struct ltdb_private *ltdb, - struct dn_list *list, - const struct ldb_message *msg) +static int ldb_kv_dn_list_find_msg(struct ltdb_private *ltdb, + struct dn_list *list, + const struct ldb_message *msg) { struct ldb_val v; const struct ldb_val *key_val; @@ -300,7 +301,7 @@ static int ltdb_dn_list_find_msg(struct ltdb_private *ltdb, } v = *key_val; } - return ltdb_dn_list_find_val(ltdb, list, &v); + return ldb_kv_dn_list_find_val(ltdb, list, &v); } /* @@ -308,7 +309,7 @@ static int ltdb_dn_list_find_msg(struct ltdb_private *ltdb, checks and also copes with CPUs that are fussy about pointer alignment */ -static struct dn_list *ltdb_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 *)) { @@ -340,7 +341,7 @@ static struct dn_list *ltdb_index_idxptr(struct ldb_module *module, TDB_DATA rec return the @IDX list in an index entry for a dn as a struct dn_list */ -static int ltdb_dn_list_load(struct ldb_module *module, +static int ldb_kv_dn_list_load(struct ldb_module *module, struct ltdb_private *ltdb, struct ldb_dn *dn, struct dn_list *list) { @@ -369,7 +370,7 @@ static int ltdb_dn_list_load(struct ldb_module *module, } /* we've found an in-memory index entry */ - list2 = ltdb_index_idxptr(module, rec, true); + list2 = ldb_kv_index_idxptr(module, rec, true); if (list2 == NULL) { free(rec.dptr); return LDB_ERR_OPERATIONS_ERROR; @@ -385,7 +386,7 @@ normal_index: return LDB_ERR_OPERATIONS_ERROR; } - ret = ltdb_search_dn1(module, dn, msg, + 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) { @@ -472,7 +473,7 @@ normal_index: return LDB_SUCCESS; } -int ltdb_key_dn_from_idx(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, @@ -489,7 +490,7 @@ int ltdb_key_dn_from_idx(struct ldb_module *module, } - ret = ltdb_index_dn_base_dn(module, ltdb, dn, list, &truncation); + ret = ldb_kv_index_dn_base_dn(module, ltdb, dn, list, &truncation); if (ret != LDB_SUCCESS) { TALLOC_FREE(list); return ret; @@ -533,7 +534,7 @@ int ltdb_key_dn_from_idx(struct ldb_module *module, return LDB_ERR_OPERATIONS_ERROR; } - ret = ltdb_idx_to_key(module, ltdb, + ret = ldb_kv_idx_to_key(module, ltdb, ldb, &list->dn[i], &key); if (ret != LDB_SUCCESS) { @@ -542,7 +543,7 @@ int ltdb_key_dn_from_idx(struct ldb_module *module, return ret; } - ret = ltdb_search_key(module, ltdb, key, + ret = ldb_kv_search_key(module, ltdb, key, rec, flags); if (key.dptr != guid_key) { TALLOC_FREE(key.dptr); @@ -587,7 +588,7 @@ int ltdb_key_dn_from_idx(struct ldb_module *module, } /* The tdb_key memory is allocated by the caller */ - ret = ltdb_guid_to_key(module, ltdb, + ret = ldb_kv_guid_to_key(module, ltdb, &list->dn[index], tdb_key); TALLOC_FREE(list); @@ -603,7 +604,7 @@ int ltdb_key_dn_from_idx(struct ldb_module *module, /* save a dn_list into a full @IDX style record */ -static int ltdb_dn_list_store_full(struct ldb_module *module, +static int ldb_kv_dn_list_store_full(struct ldb_module *module, struct ltdb_private *ltdb, struct ldb_dn *dn, struct dn_list *list) @@ -619,7 +620,7 @@ static int ltdb_dn_list_store_full(struct ldb_module *module, msg->dn = dn; if (list->count == 0) { - ret = ltdb_delete_noindex(module, msg); + ret = ldb_kv_delete_noindex(module, msg); if (ret == LDB_ERR_NO_SUCH_OBJECT) { ret = LDB_SUCCESS; } @@ -690,7 +691,7 @@ static int ltdb_dn_list_store_full(struct ldb_module *module, } } - ret = ltdb_store(module, msg, TDB_REPLACE); + ret = ldb_kv_store(module, msg, TDB_REPLACE); talloc_free(msg); return ret; } @@ -698,7 +699,7 @@ static int ltdb_dn_list_store_full(struct ldb_module *module, /* save a dn_list into the database, in either @IDX or internal format */ -static int ltdb_dn_list_store(struct ldb_module *module, struct ldb_dn *dn, +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); @@ -707,7 +708,7 @@ static int ltdb_dn_list_store(struct ldb_module *module, struct ldb_dn *dn, struct dn_list *list2; if (ltdb->idxptr == NULL) { - return ltdb_dn_list_store_full(module, ltdb, + return ldb_kv_dn_list_store_full(module, ltdb, dn, list); } @@ -726,7 +727,7 @@ static int ltdb_dn_list_store(struct ldb_module *module, struct ldb_dn *dn, rec = tdb_fetch(ltdb->idxptr->itdb, key); if (rec.dptr != NULL) { - list2 = ltdb_index_idxptr(module, rec, false); + list2 = ldb_kv_index_idxptr(module, rec, false); if (list2 == NULL) { free(rec.dptr); return LDB_ERR_OPERATIONS_ERROR; @@ -762,7 +763,7 @@ static int ltdb_dn_list_store(struct ldb_module *module, struct ldb_dn *dn, /* traverse function for storing the in-memory index entries on disk */ -static int ltdb_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); @@ -771,7 +772,7 @@ static int ltdb_index_traverse_store(struct tdb_context *tdb, TDB_DATA key, TDB_ struct ldb_val v; struct dn_list *list; - list = ltdb_index_idxptr(module, data, true); + list = ldb_kv_index_idxptr(module, data, true); if (list == NULL) { ltdb->idxptr->error = LDB_ERR_OPERATIONS_ERROR; return -1; @@ -787,7 +788,7 @@ static int ltdb_index_traverse_store(struct tdb_context *tdb, TDB_DATA key, TDB_ return -1; } - ltdb->idxptr->error = ltdb_dn_list_store_full(module, ltdb, + ltdb->idxptr->error = ldb_kv_dn_list_store_full(module, ltdb, dn, list); talloc_free(dn); if (ltdb->idxptr->error != 0) { @@ -797,7 +798,7 @@ static int ltdb_index_traverse_store(struct tdb_context *tdb, TDB_DATA key, TDB_ } /* cleanup the idxptr mode when transaction commits */ -int ltdb_index_transaction_commit(struct ldb_module *module) +int ldb_kv_index_transaction_commit(struct ldb_module *module) { struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module), struct ltdb_private); int ret; @@ -807,7 +808,7 @@ int ltdb_index_transaction_commit(struct ldb_module *module) ldb_reset_err_string(ldb); if (ltdb->idxptr->itdb) { - tdb_traverse(ltdb->idxptr->itdb, ltdb_index_traverse_store, module); + tdb_traverse(ltdb->idxptr->itdb, ldb_kv_index_traverse_store, module); tdb_close(ltdb->idxptr->itdb); } @@ -825,7 +826,7 @@ int ltdb_index_transaction_commit(struct ldb_module *module) } /* cleanup the idxptr mode when transaction cancels */ -int ltdb_index_transaction_cancel(struct ldb_module *module) +int ldb_kv_index_transaction_cancel(struct ldb_module *module) { struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module), struct ltdb_private); if (ltdb->idxptr && ltdb->idxptr->itdb) { @@ -841,7 +842,7 @@ int ltdb_index_transaction_cancel(struct ldb_module *module) return the dn key to be used for an index the caller is responsible for freeing */ -static struct ldb_dn *ltdb_index_key(struct ldb_context *ldb, +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, @@ -855,7 +856,7 @@ static struct ldb_dn *ltdb_index_key(struct ldb_context *ldb, int r; bool should_b64_encode; - unsigned int max_key_length = ltdb_max_key_length(ltdb); + unsigned int max_key_length = ldb_kv_max_key_length(ltdb); size_t key_len = 0; size_t attr_len = 0; const size_t indx_len = sizeof(LTDB_INDEX) - 1; @@ -1026,7 +1027,7 @@ 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(struct ldb_module *module, +static bool ldb_kv_is_indexed(struct ldb_module *module, struct ltdb_private *ltdb, const char *attr) { @@ -1089,7 +1090,7 @@ static bool ltdb_is_indexed(struct ldb_module *module, return a list of dn's that might match a simple indexed search (an equality search only) */ -static int ltdb_index_dn_simple(struct ldb_module *module, +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) @@ -1106,13 +1107,13 @@ 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(module, ltdb, tree->u.equality.attr)) { + if (!ldb_kv_is_indexed(module, ltdb, tree->u.equality.attr)) { return LDB_ERR_OPERATIONS_ERROR; } /* the attribute is indexed. Pull the list of DNs that match the search criterion */ - dn = ltdb_index_key(ldb, ltdb, + dn = ldb_kv_index_key(ldb, ltdb, tree->u.equality.attr, &tree->u.equality.value, NULL, &truncation); /* @@ -1122,7 +1123,7 @@ static int ltdb_index_dn_simple(struct ldb_module *module, */ if (!dn) return LDB_ERR_OPERATIONS_ERROR; - ret = ltdb_dn_list_load(module, ltdb, dn, list); + ret = ldb_kv_dn_list_load(module, ltdb, dn, list); talloc_free(dn); return ret; } @@ -1135,7 +1136,7 @@ static bool list_union(struct ldb_context *ldb, /* return a list of dn's that might match a leaf indexed search */ -static int ltdb_index_dn_leaf(struct ldb_module *module, +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) @@ -1173,7 +1174,7 @@ static int ltdb_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 ltdb_index_dn_base_dn(module, ltdb, dn, list, + return ldb_kv_index_dn_base_dn(module, ltdb, dn, list, &truncation); /* * We ignore truncation here and allow multi-valued matches @@ -1207,7 +1208,7 @@ static int ltdb_index_dn_leaf(struct ldb_module *module, return LDB_SUCCESS; } - return ltdb_index_dn_simple(module, ltdb, tree, list); + return ldb_kv_index_dn_simple(module, ltdb, tree, list); } @@ -1275,7 +1276,7 @@ static bool list_intersect(struct ldb_context *ldb, for (i=0;icount;i++) { /* For the GUID index case, this is a binary search */ - if (ltdb_dn_list_find_val(ltdb, long_list, + 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++; @@ -1326,8 +1327,8 @@ static bool list_union(struct ldb_context *ldb, * NOTE: This can sort the in-memory index values, as list or * list2 might not be a copy! */ - ltdb_dn_list_sort(ltdb, list); - ltdb_dn_list_sort(ltdb, list2); + ldb_kv_dn_list_sort(ltdb, list); + ldb_kv_dn_list_sort(ltdb, list2); dn3 = talloc_array(list, struct ldb_val, list->count + list2->count); if (!dn3) { @@ -1371,7 +1372,7 @@ static bool list_union(struct ldb_context *ldb, return true; } -static int ltdb_index_dn(struct ldb_module *module, +static int ldb_kv_index_dn(struct ldb_module *module, struct ltdb_private *ltdb, const struct ldb_parse_tree *tree, struct dn_list *list); @@ -1380,7 +1381,7 @@ 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, +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) @@ -1402,7 +1403,7 @@ static int ltdb_index_dn_or(struct ldb_module *module, return LDB_ERR_OPERATIONS_ERROR; } - ret = ltdb_index_dn(module, ltdb, + ret = ldb_kv_index_dn(module, ltdb, tree->u.list.elements[i], list2); if (ret == LDB_ERR_NO_SUCH_OBJECT) { @@ -1434,7 +1435,7 @@ static int ltdb_index_dn_or(struct ldb_module *module, /* NOT an index results */ -static int ltdb_index_dn_not(struct ldb_module *module, +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) @@ -1454,7 +1455,7 @@ static int ltdb_index_dn_not(struct ldb_module *module, * These things are unique, so avoid a full scan if this is a search * by GUID, DN or a unique attribute */ -static bool ltdb_index_unique(struct ldb_context *ldb, +static bool ldb_kv_index_unique(struct ldb_context *ldb, struct ltdb_private *ltdb, const char *attr) { @@ -1478,7 +1479,7 @@ static bool ltdb_index_unique(struct ldb_context *ldb, /* process an AND expression (intersection) */ -static int ltdb_index_dn_and(struct ldb_module *module, +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) @@ -1500,12 +1501,12 @@ static int ltdb_index_dn_and(struct ldb_module *module, int ret; if (subtree->operation != LDB_OP_EQUALITY || - !ltdb_index_unique(ldb, ltdb, + !ldb_kv_index_unique(ldb, ltdb, subtree->u.equality.attr)) { continue; } - ret = ltdb_index_dn(module, ltdb, subtree, list); + ret = ldb_kv_index_dn(module, ltdb, subtree, list); if (ret == LDB_ERR_NO_SUCH_OBJECT) { /* 0 && X == 0 */ return LDB_ERR_NO_SUCH_OBJECT; @@ -1532,7 +1533,7 @@ static int ltdb_index_dn_and(struct ldb_module *module, return ldb_module_oom(module); } - ret = ltdb_index_dn(module, ltdb, subtree, list2); + ret = ldb_kv_index_dn(module, ltdb, subtree, list2); if (ret == LDB_ERR_NO_SUCH_OBJECT) { /* X && 0 == 0 */ @@ -1581,7 +1582,7 @@ static int ltdb_index_dn_and(struct ldb_module *module, /* return a list of matching objects using a one-level index */ -static int ltdb_index_dn_attr(struct ldb_module *module, +static int ldb_kv_index_dn_attr(struct ldb_module *module, struct ltdb_private *ltdb, const char *attr, struct ldb_dn *dn, @@ -1598,13 +1599,13 @@ static int ltdb_index_dn_attr(struct ldb_module *module, /* work out the index key from the parent DN */ val.data = (uint8_t *)((uintptr_t)ldb_dn_get_casefold(dn)); val.length = strlen((char *)val.data); - key = ltdb_index_key(ldb, ltdb, attr, &val, NULL, truncation); + key = ldb_kv_index_key(ldb, ltdb, attr, &val, NULL, truncation); if (!key) { ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } - ret = ltdb_dn_list_load(module, ltdb, key, list); + ret = ldb_kv_dn_list_load(module, ltdb, key, list); talloc_free(key); if (ret != LDB_SUCCESS) { return ret; @@ -1620,7 +1621,7 @@ static int ltdb_index_dn_attr(struct ldb_module *module, /* return a list of matching objects using a one-level index */ -static int ltdb_index_dn_one(struct ldb_module *module, +static int ldb_kv_index_dn_one(struct ldb_module *module, struct ltdb_private *ltdb, struct ldb_dn *parent_dn, struct dn_list *list, @@ -1628,7 +1629,7 @@ static int ltdb_index_dn_one(struct ldb_module *module, { /* Ensure we do not shortcut on intersection for this list */ list->strict = true; - return ltdb_index_dn_attr(module, ltdb, + return ldb_kv_index_dn_attr(module, ltdb, LTDB_IDXONE, parent_dn, list, truncation); } @@ -1636,7 +1637,7 @@ static int ltdb_index_dn_one(struct ldb_module *module, /* return a list of matching objects using the DN index */ -static int ltdb_index_dn_base_dn(struct ldb_module *module, +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, @@ -1676,7 +1677,7 @@ static int ltdb_index_dn_base_dn(struct ldb_module *module, return LDB_SUCCESS; } - return ltdb_index_dn_attr(module, ltdb, + return ldb_kv_index_dn_attr(module, ltdb, LTDB_IDXDN, base_dn, dn_list, truncation); } @@ -1684,7 +1685,7 @@ static int ltdb_index_dn_base_dn(struct ldb_module *module, return a list of dn's that might match a indexed search or 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, +static int ldb_kv_index_dn(struct ldb_module *module, struct ltdb_private *ltdb, const struct ldb_parse_tree *tree, struct dn_list *list) @@ -1693,19 +1694,19 @@ static int ltdb_index_dn(struct ldb_module *module, switch (tree->operation) { case LDB_OP_AND: - ret = ltdb_index_dn_and(module, ltdb, tree, list); + ret = ldb_kv_index_dn_and(module, ltdb, tree, list); break; case LDB_OP_OR: - ret = ltdb_index_dn_or(module, ltdb, tree, list); + ret = ldb_kv_index_dn_or(module, ltdb, tree, list); break; case LDB_OP_NOT: - ret = ltdb_index_dn_not(module, ltdb, tree, list); + ret = ldb_kv_index_dn_not(module, ltdb, tree, list); break; case LDB_OP_EQUALITY: - ret = ltdb_index_dn_leaf(module, ltdb, tree, list); + ret = ldb_kv_index_dn_leaf(module, ltdb, tree, list); break; case LDB_OP_SUBSTRING: @@ -1726,7 +1727,7 @@ static int ltdb_index_dn(struct ldb_module *module, filter a candidate dn_list from an indexed search into a set of results extracting just the given attributes */ -static int ltdb_index_filter(struct ltdb_private *ltdb, +static int ldb_kv_index_filter(struct ltdb_private *ltdb, const struct dn_list *dn_list, struct ltdb_context *ac, uint32_t *match_count, @@ -1783,7 +1784,7 @@ static int ltdb_index_filter(struct ltdb_private *ltdb, for (i = 0; i < dn_list->count; i++) { int ret; - ret = ltdb_idx_to_key(ac->module, + ret = ldb_kv_idx_to_key(ac->module, ltdb, keys, &dn_list->dn[i], @@ -1831,7 +1832,7 @@ static int ltdb_index_filter(struct ltdb_private *ltdb, return LDB_ERR_OPERATIONS_ERROR; } - ret = ltdb_search_key(ac->module, ltdb, + 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); @@ -1881,7 +1882,7 @@ static int ltdb_index_filter(struct ltdb_private *ltdb, } /* filter the attributes that the user wants */ - ret = ltdb_filter_attrs(ac, msg, ac->attrs, &filtered_msg); + ret = ldb_kv_filter_attrs(ac, msg, ac->attrs, &filtered_msg); talloc_free(msg); @@ -1910,7 +1911,7 @@ static int ltdb_index_filter(struct ltdb_private *ltdb, /* sort a DN list */ -static void ltdb_dn_list_sort(struct ltdb_private *ltdb, +static void ldb_kv_dn_list_sort(struct ltdb_private *ltdb, struct dn_list *list) { if (list->count < 2) { @@ -1931,7 +1932,7 @@ static void ltdb_dn_list_sort(struct ltdb_private *ltdb, returns -1 if an indexed search is not possible, in which case the caller should call ltdb_search_full() */ -int ltdb_search_indexed(struct ltdb_context *ac, uint32_t *match_count) +int ldb_kv_search_indexed(struct ltdb_context *ac, uint32_t *match_count) { struct ldb_context *ldb = ldb_module_get_ctx(ac->module); struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(ac->module), struct ltdb_private); @@ -1979,7 +1980,7 @@ int ltdb_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 = ltdb_index_dn_one(ac->module, ltdb, ac->base, dn_list, + ret = ldb_kv_index_dn_one(ac->module, ltdb, ac->base, dn_list, &scope_one_truncation); if (ret != LDB_SUCCESS) { talloc_free(dn_list); @@ -2018,7 +2019,7 @@ int ltdb_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 = ltdb_index_dn(ac->module, ltdb, ac->tree, + ret = ldb_kv_index_dn(ac->module, ltdb, ac->tree, idx_one_tree_list); if (ret == LDB_SUCCESS) { if (!list_intersect(ldb, ltdb, @@ -2042,7 +2043,7 @@ int ltdb_search_indexed(struct ltdb_context *ac, uint32_t *match_count) * Here we load the index for the tree. We have no * index for the subtree. */ - ret = ltdb_index_dn(ac->module, ltdb, ac->tree, dn_list); + ret = ldb_kv_index_dn(ac->module, ltdb, ac->tree, dn_list); if (ret != LDB_SUCCESS) { talloc_free(dn_list); return ret; @@ -2061,7 +2062,7 @@ int ltdb_search_indexed(struct ltdb_context *ac, uint32_t *match_count) * processing as the truncation here refers only to the * SCOPE_ONELEVEL index. */ - ret = ltdb_index_filter(ltdb, dn_list, ac, match_count, + ret = ldb_kv_index_filter(ltdb, dn_list, ac, match_count, scope_one_truncation); talloc_free(dn_list); return ret; @@ -2087,7 +2088,7 @@ int ltdb_search_indexed(struct ltdb_context *ac, uint32_t *match_count) * * @return An ldb error code */ -static int ltdb_index_add1(struct ldb_module *module, +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) @@ -2108,7 +2109,7 @@ static int ltdb_index_add1(struct ldb_module *module, return LDB_ERR_OPERATIONS_ERROR; } - dn_key = ltdb_index_key(ldb, ltdb, + dn_key = ldb_kv_index_key(ldb, ltdb, el->name, &el->values[v_idx], &a, &truncation); if (!dn_key) { talloc_free(list); @@ -2135,7 +2136,7 @@ static int ltdb_index_add1(struct ldb_module *module, } talloc_steal(list, dn_key); - ret = ltdb_dn_list_load(module, ltdb, dn_key, list); + ret = ldb_kv_dn_list_load(module, ltdb, dn_key, list); if (ret != LDB_SUCCESS && ret != LDB_ERR_NO_SUCH_OBJECT) { talloc_free(list); return ret; @@ -2177,7 +2178,7 @@ static int ltdb_index_add1(struct ldb_module *module, return LDB_ERR_OPERATIONS_ERROR; } - ret = ltdb_idx_to_key(module, ltdb, + ret = ldb_kv_idx_to_key(module, ltdb, ldb, &list->dn[i], &key); if (ret != LDB_SUCCESS) { @@ -2186,7 +2187,7 @@ static int ltdb_index_add1(struct ldb_module *module, return ret; } - ret = ltdb_search_key(module, ltdb, key, + ret = ldb_kv_search_key(module, ltdb, key, rec, flags); if (key.dptr != guid_key) { TALLOC_FREE(key.dptr); @@ -2359,7 +2360,7 @@ static int ltdb_index_add1(struct ldb_module *module, } list->count++; - ret = ltdb_dn_list_store(module, dn_key, list); + ret = ldb_kv_dn_list_store(module, dn_key, list); talloc_free(list); @@ -2369,14 +2370,14 @@ static int ltdb_index_add1(struct ldb_module *module, /* add index entries for one elements in a message */ -static int ltdb_index_add_el(struct ldb_module *module, +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) { unsigned int i; for (i = 0; i < el->num_values; i++) { - int ret = ltdb_index_add1(module, ltdb, + int ret = ldb_kv_index_add1(module, ltdb, msg, el, i); if (ret != LDB_SUCCESS) { return ret; @@ -2389,7 +2390,7 @@ static int ltdb_index_add_el(struct ldb_module *module, /* add index entries for all elements in a message */ -static int ltdb_index_add_all(struct ldb_module *module, +static int ldb_kv_index_add_all(struct ldb_module *module, struct ltdb_private *ltdb, const struct ldb_message *msg) { @@ -2407,7 +2408,7 @@ static int ltdb_index_add_all(struct ldb_module *module, return LDB_ERR_OPERATIONS_ERROR; } - ret = ltdb_write_index_dn_guid(module, msg, 1); + ret = ldb_kv_write_index_dn_guid(module, msg, 1); if (ret != LDB_SUCCESS) { return ret; } @@ -2418,10 +2419,10 @@ static int ltdb_index_add_all(struct ldb_module *module, } for (i = 0; i < msg->num_elements; i++) { - if (!ltdb_is_indexed(module, ltdb, elements[i].name)) { + if (!ldb_kv_is_indexed(module, ltdb, elements[i].name)) { continue; } - ret = ltdb_index_add_el(module, ltdb, + ret = ldb_kv_index_add_el(module, ltdb, msg, &elements[i]); if (ret != LDB_SUCCESS) { struct ldb_context *ldb = ldb_module_get_ctx(module); @@ -2440,7 +2441,7 @@ static int ltdb_index_add_all(struct ldb_module *module, /* insert a DN index for a message */ -static int ltdb_modify_index_dn(struct ldb_module *module, +static int ldb_kv_modify_index_dn(struct ldb_module *module, struct ltdb_private *ltdb, const struct ldb_message *msg, struct ldb_dn *dn, @@ -2470,9 +2471,9 @@ static int ltdb_modify_index_dn(struct ldb_module *module, el.num_values = 1; if (add) { - ret = ltdb_index_add1(module, ltdb, msg, &el, 0); + ret = ldb_kv_index_add1(module, ltdb, msg, &el, 0); } else { /* delete */ - ret = ltdb_index_del_value(module, ltdb, msg, &el, 0); + ret = ldb_kv_index_del_value(module, ltdb, msg, &el, 0); } if (ret != LDB_SUCCESS) { @@ -2493,7 +2494,7 @@ static int ltdb_modify_index_dn(struct ldb_module *module, /* insert a one level index for a message */ -static int ltdb_index_onelevel(struct ldb_module *module, +static int ldb_kv_index_onelevel(struct ldb_module *module, const struct ldb_message *msg, int add) { struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module), @@ -2510,7 +2511,7 @@ static int ltdb_index_onelevel(struct ldb_module *module, if (pdn == NULL) { return LDB_ERR_OPERATIONS_ERROR; } - ret = ltdb_modify_index_dn(module, ltdb, + ret = ldb_kv_modify_index_dn(module, ltdb, msg, pdn, LTDB_IDXONE, add); talloc_free(pdn); @@ -2521,7 +2522,7 @@ static int ltdb_index_onelevel(struct ldb_module *module, /* insert a one level index for a message */ -static int ltdb_write_index_dn_guid(struct ldb_module *module, +static int ldb_kv_write_index_dn_guid(struct ldb_module *module, const struct ldb_message *msg, int add) { @@ -2534,7 +2535,7 @@ static int ltdb_write_index_dn_guid(struct ldb_module *module, return LDB_SUCCESS; } - ret = ltdb_modify_index_dn(module, ltdb, msg, msg->dn, + ret = ldb_kv_modify_index_dn(module, ltdb, msg, msg->dn, LTDB_IDXDN, add); if (ret == LDB_ERR_CONSTRAINT_VIOLATION) { @@ -2550,7 +2551,7 @@ static int ltdb_write_index_dn_guid(struct ldb_module *module, add the index entries for a new element in a record The caller guarantees that these element values are not yet indexed */ -int ltdb_index_add_element(struct ldb_module *module, +int ldb_kv_index_add_element(struct ldb_module *module, struct ltdb_private *ltdb, const struct ldb_message *msg, struct ldb_message_element *el) @@ -2558,16 +2559,16 @@ int ltdb_index_add_element(struct ldb_module *module, if (ldb_dn_is_special(msg->dn)) { return LDB_SUCCESS; } - if (!ltdb_is_indexed(module, ltdb, el->name)) { + if (!ldb_kv_is_indexed(module, ltdb, el->name)) { return LDB_SUCCESS; } - return ltdb_index_add_el(module, ltdb, msg, el); + return ldb_kv_index_add_el(module, ltdb, msg, el); } /* add the index entries for a new record */ -int ltdb_index_add_new(struct ldb_module *module, +int ldb_kv_index_add_new(struct ldb_module *module, struct ltdb_private *ltdb, const struct ldb_message *msg) { @@ -2577,7 +2578,7 @@ int ltdb_index_add_new(struct ldb_module *module, return LDB_SUCCESS; } - ret = ltdb_index_add_all(module, ltdb, msg); + ret = ldb_kv_index_add_all(module, ltdb, msg); if (ret != LDB_SUCCESS) { /* * Because we can't trust the caller to be doing @@ -2586,11 +2587,11 @@ int ltdb_index_add_new(struct ldb_module *module, * cleanup */ - ltdb_index_delete(module, msg); + ldb_kv_index_delete(module, msg); return ret; } - ret = ltdb_index_onelevel(module, msg, 1); + ret = ldb_kv_index_onelevel(module, msg, 1); if (ret != LDB_SUCCESS) { /* * Because we can't trust the caller to be doing @@ -2598,7 +2599,7 @@ int ltdb_index_add_new(struct ldb_module *module, * entry rather than relying on a transaction * cleanup */ - ltdb_index_delete(module, msg); + ldb_kv_index_delete(module, msg); return ret; } return ret; @@ -2608,7 +2609,7 @@ int ltdb_index_add_new(struct ldb_module *module, /* delete an index entry for one message element */ -int ltdb_index_del_value(struct ldb_module *module, +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) @@ -2633,7 +2634,7 @@ int ltdb_index_del_value(struct ldb_module *module, return LDB_SUCCESS; } - dn_key = ltdb_index_key(ldb, ltdb, + dn_key = ldb_kv_index_key(ldb, ltdb, el->name, &el->values[v_idx], NULL, &truncation); /* @@ -2652,7 +2653,7 @@ int ltdb_index_del_value(struct ldb_module *module, return LDB_ERR_OPERATIONS_ERROR; } - ret = ltdb_dn_list_load(module, ltdb, dn_key, list); + ret = ldb_kv_dn_list_load(module, ltdb, dn_key, list); if (ret == LDB_ERR_NO_SUCH_OBJECT) { /* it wasn't indexed. Did we have an earlier error? If we did then its gone now */ @@ -2668,7 +2669,7 @@ int ltdb_index_del_value(struct ldb_module *module, /* * Find one of the values matching this message to remove */ - i = ltdb_dn_list_find_msg(ltdb, list, msg); + i = ldb_kv_dn_list_find_msg(ltdb, list, msg); if (i == -1) { /* nothing to delete */ talloc_free(dn_key); @@ -2687,7 +2688,7 @@ int ltdb_index_del_value(struct ldb_module *module, list->dn = talloc_realloc(list, list->dn, struct ldb_val, list->count); } - ret = ltdb_dn_list_store(module, dn_key, list); + ret = ldb_kv_dn_list_store(module, dn_key, list); talloc_free(dn_key); @@ -2698,7 +2699,7 @@ int ltdb_index_del_value(struct ldb_module *module, delete the index entries for a element return -1 on failure */ -int ltdb_index_del_element(struct ldb_module *module, +int ldb_kv_index_del_element(struct ldb_module *module, struct ltdb_private *ltdb, const struct ldb_message *msg, struct ldb_message_element *el) @@ -2721,11 +2722,11 @@ int ltdb_index_del_element(struct ldb_module *module, return LDB_SUCCESS; } - if (!ltdb_is_indexed(module, ltdb, el->name)) { + if (!ldb_kv_is_indexed(module, ltdb, el->name)) { return LDB_SUCCESS; } for (i = 0; i < el->num_values; i++) { - ret = ltdb_index_del_value(module, ltdb, msg, el, i); + ret = ldb_kv_index_del_value(module, ltdb, msg, el, i); if (ret != LDB_SUCCESS) { return ret; } @@ -2738,7 +2739,7 @@ int ltdb_index_del_element(struct ldb_module *module, delete the index entries for a record return -1 on failure */ -int ltdb_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; @@ -2748,12 +2749,12 @@ int ltdb_index_delete(struct ldb_module *module, const struct ldb_message *msg) return LDB_SUCCESS; } - ret = ltdb_index_onelevel(module, msg, 0); + ret = ldb_kv_index_onelevel(module, msg, 0); if (ret != LDB_SUCCESS) { return ret; } - ret = ltdb_write_index_dn_guid(module, msg, 0); + ret = ldb_kv_write_index_dn_guid(module, msg, 0); if (ret != LDB_SUCCESS) { return ret; } @@ -2764,7 +2765,7 @@ int ltdb_index_delete(struct ldb_module *module, const struct ldb_message *msg) } for (i = 0; i < msg->num_elements; i++) { - ret = ltdb_index_del_element(module, ltdb, + ret = ldb_kv_index_del_element(module, ltdb, msg, &msg->elements[i]); if (ret != LDB_SUCCESS) { return ret; @@ -2810,7 +2811,7 @@ static int delete_index(struct ltdb_private *ltdb, struct ldb_val key, struct ld * This does not actually touch the DB quite yet, just * the in-memory index cache */ - ret = ltdb_dn_list_store(module, dn, &list); + ret = ldb_kv_dn_list_store(module, dn, &list); if (ret != LDB_SUCCESS) { ldb_asprintf_errstring(ldb_module_get_ctx(module), "Unable to store null index for %s\n", @@ -2847,7 +2848,7 @@ static int re_key(struct ltdb_private *ltdb, struct ldb_val ldb_key, struct ldb_ return 0; } - is_record = ltdb_key_is_record(key); + is_record = ldb_kv_key_is_record(key); if (is_record == false) { return 0; } @@ -2883,7 +2884,7 @@ static int re_key(struct ltdb_private *ltdb, struct ldb_val ldb_key, struct ldb_ /* check if the DN key has changed, perhaps due to the case insensitivity of an element changing, or a change from DN to GUID keys */ - key2 = ltdb_key_msg(module, msg, msg); + key2 = ldb_kv_key_msg(module, msg, msg); if (key2.dptr == NULL) { /* probably a corrupt record ... darn */ ldb_debug(ldb, LDB_DEBUG_ERROR, "Invalid DN in re_index: %s", @@ -2937,7 +2938,7 @@ static int re_index(struct ltdb_private *ltdb, struct ldb_val ldb_key, struct ld return 0; } - is_record = ltdb_key_is_record(key); + is_record = ldb_kv_key_is_record(key); if (is_record == false) { return 0; } @@ -2970,7 +2971,7 @@ static int re_index(struct ltdb_private *ltdb, struct ldb_val ldb_key, struct ld return -1; } - ret = ltdb_index_onelevel(module, msg, 1); + ret = ldb_kv_index_onelevel(module, msg, 1); if (ret != LDB_SUCCESS) { ldb_debug(ldb, LDB_DEBUG_ERROR, "Adding special ONE LEVEL index failed (%s)!", @@ -2979,7 +2980,7 @@ static int re_index(struct ltdb_private *ltdb, struct ldb_val ldb_key, struct ld return -1; } - ret = ltdb_index_add_all(module, ltdb, msg); + ret = ldb_kv_index_add_all(module, ltdb, msg); if (ret != LDB_SUCCESS) { ctx->error = ret; @@ -3002,7 +3003,7 @@ static int re_index(struct ltdb_private *ltdb, struct ldb_val ldb_key, struct ld /* force a complete reindex of the database */ -int ltdb_reindex(struct ldb_module *module) +int ldb_kv_reindex(struct ldb_module *module) { struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module), struct ltdb_private); int ret; @@ -3016,7 +3017,7 @@ int ltdb_reindex(struct ldb_module *module) return LDB_ERR_UNWILLING_TO_PERFORM; } - if (ltdb_cache_reload(module) != 0) { + if (ldb_kv_cache_reload(module) != 0) { return LDB_ERR_OPERATIONS_ERROR; } @@ -3025,9 +3026,9 @@ int ltdb_reindex(struct ldb_module *module) * DB, no values stored so far are any use as we want to do a * re-index */ - ltdb_index_transaction_cancel(module); + ldb_kv_index_transaction_cancel(module); - ret = ltdb_index_transaction_start(module); + ret = ldb_kv_index_transaction_start(module); 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 832be9a598b..4f6704797d4 100644 --- a/lib/ldb/ldb_tdb/ldb_search.c +++ b/lib/ldb/ldb_tdb/ldb_search.c @@ -116,7 +116,7 @@ static int msg_add_distinguished_name(struct ldb_message *msg) return LDB_ERR_NO_SUCH_OBJECT on record-not-found and LDB_SUCCESS on success */ -int ltdb_search_base(struct ldb_module *module, +int ldb_kv_search_base(struct ldb_module *module, TALLOC_CTX *mem_ctx, struct ldb_dn *dn, struct ldb_dn **ret_dn) @@ -141,7 +141,7 @@ int ltdb_search_base(struct ldb_module *module, return LDB_ERR_OPERATIONS_ERROR; } - ret = ltdb_search_dn1(module, dn, + ret = ldb_kv_search_dn1(module, dn, msg, LDB_UNPACK_DATA_FLAG_NO_ATTRS); if (ret == LDB_SUCCESS) { @@ -183,7 +183,7 @@ struct ltdb_parse_data_unpack_ctx { unsigned int unpack_flags; }; -static int ltdb_parse_data_unpack(struct ldb_val key, +static int ldb_kv_parse_data_unpack(struct ldb_val key, struct ldb_val data, void *private_data) { @@ -236,7 +236,7 @@ static int ltdb_parse_data_unpack(struct ldb_val key, return LDB_ERR_NO_SUCH_OBJECT on record-not-found and LDB_SUCCESS on success */ -int ltdb_search_key(struct ldb_module *module, struct ltdb_private *ltdb, +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) @@ -258,7 +258,7 @@ int ltdb_search_key(struct ldb_module *module, struct ltdb_private *ltdb, msg->elements = NULL; ret = ltdb->kv_ops->fetch_and_parse(ltdb, ldb_key, - ltdb_parse_data_unpack, &ctx); + ldb_kv_parse_data_unpack, &ctx); if (ret == -1) { ret = ltdb->kv_ops->error(ltdb); @@ -284,7 +284,7 @@ int ltdb_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 ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, 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) { void *data = ldb_module_get_private(module); @@ -306,7 +306,7 @@ int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_mes } /* form the key */ - tdb_key = ltdb_key_dn(module, tdb_key_ctx, dn); + tdb_key = ldb_kv_key_dn(module, tdb_key_ctx, dn); if (!tdb_key.dptr) { TALLOC_FREE(tdb_key_ctx); return LDB_ERR_OPERATIONS_ERROR; @@ -319,7 +319,7 @@ int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_mes * used for internal memory. * */ - ret = ltdb_key_dn_from_idx(module, ltdb, + ret = ldb_kv_key_dn_from_idx(module, ltdb, msg, dn, &tdb_key); if (ret != LDB_SUCCESS) { @@ -327,7 +327,7 @@ int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_mes } } - ret = ltdb_search_key(module, ltdb, tdb_key, msg, unpack_flags); + ret = ldb_kv_search_key(module, ltdb, tdb_key, msg, unpack_flags); TALLOC_FREE(tdb_key_ctx); @@ -355,7 +355,7 @@ int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_mes individually allocated, which is what our callers expect. */ -int ltdb_filter_attrs(TALLOC_CTX *mem_ctx, +int ldb_kv_filter_attrs(TALLOC_CTX *mem_ctx, const struct ldb_message *msg, const char * const *attrs, struct ldb_message **filtered_msg) { @@ -509,7 +509,7 @@ static int search_func(struct ltdb_private *ltdb, struct ldb_val key, struct ldb ac = talloc_get_type(state, struct ltdb_context); ldb = ldb_module_get_ctx(ac->module); - if (ltdb_key_is_record(tdb_key) == false) { + if (ldb_kv_key_is_record(tdb_key) == false) { return 0; } @@ -556,7 +556,7 @@ static int search_func(struct ltdb_private *ltdb, struct ldb_val key, struct ldb } /* filter the attributes that the user wants */ - ret = ltdb_filter_attrs(ac, msg, ac->attrs, &filtered_msg); + ret = ldb_kv_filter_attrs(ac, msg, ac->attrs, &filtered_msg); talloc_free(msg); if (ret == -1) { @@ -580,7 +580,7 @@ static int search_func(struct ltdb_private *ltdb, struct ldb_val key, struct ldb search the database with a LDAP-like expression. this is the "full search" non-indexed variant */ -static int ltdb_search_full(struct ltdb_context *ctx) +static int ldb_kv_search_full(struct ltdb_context *ctx) { void *data = ldb_module_get_private(ctx->module); struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); @@ -596,7 +596,7 @@ static int ltdb_search_full(struct ltdb_context *ctx) return ctx->error; } -static int ltdb_search_and_return_base(struct ltdb_private *ltdb, +static int ldb_kv_search_and_return_base(struct ltdb_private *ltdb, struct ltdb_context *ctx) { struct ldb_message *msg, *filtered_msg; @@ -610,7 +610,7 @@ static int ltdb_search_and_return_base(struct ltdb_private *ltdb, if (!msg) { return LDB_ERR_OPERATIONS_ERROR; } - ret = ltdb_search_dn1(ctx->module, ctx->base, msg, + ret = ldb_kv_search_dn1(ctx->module, ctx->base, msg, LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC| LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC); @@ -671,7 +671,7 @@ static int ltdb_search_and_return_base(struct ltdb_private *ltdb, * This copies msg->dn including the casefolding, so the above * assignment is safe */ - ret = ltdb_filter_attrs(ctx, msg, ctx->attrs, &filtered_msg); + ret = ldb_kv_filter_attrs(ctx, msg, ctx->attrs, &filtered_msg); /* * Remove any extended components possibly copied in from @@ -700,7 +700,7 @@ static int ltdb_search_and_return_base(struct ltdb_private *ltdb, search the database with a LDAP-like expression. choses a search method */ -int ltdb_search(struct ltdb_context *ctx) +int ldb_kv_search(struct ltdb_context *ctx) { struct ldb_context *ldb; struct ldb_module *module = ctx->module; @@ -717,7 +717,7 @@ int ltdb_search(struct ltdb_context *ctx) return LDB_ERR_OPERATIONS_ERROR; } - if (ltdb_cache_load(module) != 0) { + if (ldb_kv_cache_load(module) != 0) { ltdb->kv_ops->unlock_read(module); return LDB_ERR_OPERATIONS_ERROR; } @@ -768,7 +768,7 @@ int ltdb_search(struct ltdb_context *ctx) * will try to look up an index record for a special * record (which doesn't exist). */ - ret = ltdb_search_and_return_base(ltdb, ctx); + ret = ldb_kv_search_and_return_base(ltdb, ctx); ltdb->kv_ops->unlock_read(module); @@ -781,7 +781,7 @@ int ltdb_search(struct ltdb_context *ctx) * dn. Also optimise the subsequent filter by filling * in the ctx->base to be exactly case correct */ - ret = ltdb_search_base(module, ctx, + ret = ldb_kv_search_base(module, ctx, req->op.search.base, &ctx->base); @@ -799,7 +799,7 @@ int ltdb_search(struct ltdb_context *ctx) if (ret == LDB_SUCCESS) { uint32_t match_count = 0; - ret = ltdb_search_indexed(ctx, &match_count); + ret = ldb_kv_search_indexed(ctx, &match_count); if (ret == LDB_ERR_NO_SUCH_OBJECT) { /* Not in the index, therefore OK! */ ret = LDB_SUCCESS; @@ -844,7 +844,7 @@ int ltdb_search(struct ltdb_context *ctx) return LDB_ERR_INAPPROPRIATE_MATCHING; } - ret = ltdb_search_full(ctx); + ret = ldb_kv_search_full(ctx); if (ret != LDB_SUCCESS) { ldb_set_errstring(ldb, "Indexed and full searches both failed!\n"); } diff --git a/lib/ldb/ldb_tdb/ldb_tdb.c b/lib/ldb/ldb_tdb/ldb_tdb.c index daf9a778f5b..a18e613c858 100644 --- a/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/lib/ldb/ldb_tdb/ldb_tdb.c @@ -164,7 +164,7 @@ static int ltdb_unlock_read(struct ldb_module *module) * Determine if this key could hold a record. We allow the new GUID * index, the old DN index and a possible future ID= */ -bool ltdb_key_is_record(TDB_DATA key) +bool ldb_kv_key_is_record(TDB_DATA key) { if (key.dsize < 4) { return false; @@ -197,7 +197,7 @@ bool ltdb_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 ltdb_key_dn(struct ldb_module *module, TALLOC_CTX *mem_ctx, +TDB_DATA ldb_kv_key_dn(struct ldb_module *module, TALLOC_CTX *mem_ctx, struct ldb_dn *dn) { TDB_DATA key; @@ -244,7 +244,7 @@ failed: } /* The caller is to provide a correctly sized key */ -int ltdb_guid_to_key(struct ldb_module *module, +int ldb_kv_guid_to_key(struct ldb_module *module, struct ltdb_private *ltdb, const struct ldb_val *GUID_val, TDB_DATA *key) @@ -266,7 +266,7 @@ int ltdb_guid_to_key(struct ldb_module *module, * The caller is to provide a correctly sized key, used only in * the GUID index mode */ -int ltdb_idx_to_key(struct ldb_module *module, +int ldb_kv_idx_to_key(struct ldb_module *module, struct ltdb_private *ltdb, TALLOC_CTX *mem_ctx, const struct ldb_val *idx_val, @@ -276,7 +276,7 @@ int ltdb_idx_to_key(struct ldb_module *module, struct ldb_dn *dn; if (ltdb->cache->GUID_index_attribute != NULL) { - return ltdb_guid_to_key(module, ltdb, + return ldb_kv_guid_to_key(module, ltdb, idx_val, key); } @@ -289,7 +289,7 @@ int ltdb_idx_to_key(struct ldb_module *module, return LDB_ERR_OPERATIONS_ERROR; } /* form the key */ - *key = ltdb_key_dn(module, mem_ctx, dn); + *key = ldb_kv_key_dn(module, mem_ctx, dn); TALLOC_FREE(dn); if (!key->dptr) { return ldb_module_oom(module); @@ -305,7 +305,7 @@ int ltdb_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 ltdb_key_msg(struct ldb_module *module, TALLOC_CTX *mem_ctx, +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); @@ -315,11 +315,11 @@ TDB_DATA ltdb_key_msg(struct ldb_module *module, TALLOC_CTX *mem_ctx, int ret; if (ltdb->cache->GUID_index_attribute == NULL) { - return ltdb_key_dn(module, mem_ctx, msg->dn); + return ldb_kv_key_dn(module, mem_ctx, msg->dn); } if (ldb_dn_is_special(msg->dn)) { - return ltdb_key_dn(module, mem_ctx, msg->dn); + return ldb_kv_key_dn(module, mem_ctx, msg->dn); } guid_val = ldb_msg_find_ldb_val(msg, @@ -347,7 +347,7 @@ TDB_DATA ltdb_key_msg(struct ldb_module *module, TALLOC_CTX *mem_ctx, } key.dsize = talloc_get_size(key.dptr); - ret = ltdb_guid_to_key(module, ltdb, guid_val, &key); + ret = ldb_kv_guid_to_key(module, ltdb, guid_val, &key); if (ret != LDB_SUCCESS) { errno = EINVAL; @@ -362,7 +362,7 @@ TDB_DATA ltdb_key_msg(struct ldb_module *module, TALLOC_CTX *mem_ctx, check special dn's have valid attributes currently only @ATTRIBUTES is checked */ -static int ltdb_check_special_dn(struct ldb_module *module, +static int ldb_kv_check_special_dn(struct ldb_module *module, const struct ldb_message *msg) { struct ldb_context *ldb = ldb_module_get_ctx(module); @@ -379,7 +379,7 @@ static int ltdb_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 (ltdb_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; } @@ -394,7 +394,7 @@ static int ltdb_check_special_dn(struct ldb_module *module, we've made a modification to a dn - possibly reindex and update sequence number */ -static int ltdb_modified(struct ldb_module *module, struct ldb_dn *dn) +static int ldb_kv_modified(struct ldb_module *module, struct ldb_dn *dn) { int ret = LDB_SUCCESS; struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module), struct ltdb_private); @@ -415,21 +415,21 @@ static int ltdb_modified(struct ldb_module *module, struct ldb_dn *dn) LDB_DEBUG_ERROR, "Reindexing %s due to modification on %s", ltdb->kv_ops->name(ltdb), ldb_dn_get_linearized(dn)); } - ret = ltdb_reindex(module); + ret = ldb_kv_reindex(module); } /* If the modify was to a normal record, or any special except @BASEINFO, update the seq number */ if (ret == LDB_SUCCESS && !(ldb_dn_is_special(dn) && ldb_dn_check_special(dn, LTDB_BASEINFO)) ) { - ret = ltdb_increase_sequence_number(module); + ret = ldb_kv_increase_sequence_number(module); } /* If the modify was to @OPTIONS, reload the cache */ if (ret == LDB_SUCCESS && ldb_dn_is_special(dn) && (ldb_dn_check_special(dn, LTDB_OPTIONS)) ) { - ret = ltdb_cache_reload(module); + ret = ldb_kv_cache_reload(module); } if (ret != LDB_SUCCESS) { @@ -439,7 +439,7 @@ static int ltdb_modified(struct ldb_module *module, struct ldb_dn *dn) return ret; } -static int ltdb_tdb_store(struct ltdb_private *ltdb, struct ldb_val ldb_key, +static int ltdb_store(struct ltdb_private *ltdb, struct ldb_val ldb_key, struct ldb_val ldb_data, int flags) { TDB_DATA key = { @@ -470,7 +470,10 @@ static const char *ltdb_errorstr(struct ltdb_private *ltdb) /* store a record into the db */ -int ltdb_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); @@ -489,7 +492,7 @@ int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flg return LDB_ERR_UNWILLING_TO_PERFORM; } - tdb_key = ltdb_key_msg(module, tdb_key_ctx, msg); + tdb_key = ldb_kv_key_msg(module, tdb_key_ctx, msg); if (tdb_key.dptr == NULL) { TALLOC_FREE(tdb_key_ctx); return LDB_ERR_OTHER; @@ -533,7 +536,7 @@ done: /* check if a attribute is a single valued, for a given element */ -static bool ldb_tdb_single_valued(const struct ldb_schema_attribute *a, +static bool ldb_kv_single_valued(const struct ldb_schema_attribute *a, struct ldb_message_element *el) { if (!a) return false; @@ -558,7 +561,7 @@ static bool ldb_tdb_single_valued(const struct ldb_schema_attribute *a, return false; } -static int ltdb_add_internal(struct ldb_module *module, +static int ldb_kv_add_internal(struct ldb_module *module, struct ltdb_private *ltdb, const struct ldb_message *msg, bool check_single_value) @@ -578,7 +581,7 @@ static int ltdb_add_internal(struct ldb_module *module, } if (check_single_value && el->num_values > 1 && - ldb_tdb_single_valued(a, el)) { + 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; @@ -614,7 +617,7 @@ static int ltdb_add_internal(struct ldb_module *module, } } - ret = ltdb_store(module, msg, TDB_INSERT); + ret = ldb_kv_store(module, msg, TDB_INSERT); if (ret != LDB_SUCCESS) { /* * Try really hard to get the right error code for @@ -627,7 +630,7 @@ static int ltdb_add_internal(struct ldb_module *module, if (mem_ctx == NULL) { return ldb_module_operr(module); } - ret2 = ltdb_search_base(module, mem_ctx, + ret2 = ldb_kv_search_base(module, mem_ctx, msg->dn, &dn2); TALLOC_FREE(mem_ctx); if (ret2 == LDB_SUCCESS) { @@ -642,7 +645,7 @@ static int ltdb_add_internal(struct ldb_module *module, return ret; } - ret = ltdb_index_add_new(module, ltdb, msg); + ret = ldb_kv_index_add_new(module, ltdb, msg); if (ret != LDB_SUCCESS) { /* * If we failed to index, delete the message again. @@ -654,11 +657,11 @@ static int ltdb_add_internal(struct ldb_module *module, * Note that the caller may not cancel the transation * and this means the above add might really show up! */ - ltdb_delete_noindex(module, msg); + ldb_kv_delete_noindex(module, msg); return ret; } - ret = ltdb_modified(module, msg->dn); + ret = ldb_kv_modified(module, msg->dn); return ret; } @@ -666,7 +669,7 @@ static int ltdb_add_internal(struct ldb_module *module, /* add a record to the database */ -static int ltdb_add(struct ltdb_context *ctx) +static int ldb_kv_add(struct ltdb_context *ctx) { struct ldb_module *module = ctx->module; struct ldb_request *req = ctx->req; @@ -684,24 +687,24 @@ static int ltdb_add(struct ltdb_context *ctx) return LDB_ERR_UNWILLING_TO_PERFORM; } - ret = ltdb_check_special_dn(module, req->op.add.message); + ret = ldb_kv_check_special_dn(module, req->op.add.message); if (ret != LDB_SUCCESS) { return ret; } ldb_request_set_state(req, LDB_ASYNC_PENDING); - if (ltdb_cache_load(module) != 0) { + if (ldb_kv_cache_load(module) != 0) { return LDB_ERR_OPERATIONS_ERROR; } - ret = ltdb_add_internal(module, ltdb, + ret = ldb_kv_add_internal(module, ltdb, req->op.add.message, true); return ret; } -static int ltdb_tdb_delete(struct ltdb_private *ltdb, struct ldb_val ldb_key) +static int ltdb_delete(struct ltdb_private *ltdb, struct ldb_val ldb_key) { TDB_DATA tdb_key = { .dptr = ldb_key.data, @@ -718,7 +721,7 @@ static int ltdb_tdb_delete(struct ltdb_private *ltdb, struct ldb_val ldb_key) delete a record from the database, not updating indexes (used for deleting index records) */ -int ltdb_delete_noindex(struct ldb_module *module, +int ldb_kv_delete_noindex(struct ldb_module *module, const struct ldb_message *msg) { void *data = ldb_module_get_private(module); @@ -737,7 +740,7 @@ int ltdb_delete_noindex(struct ldb_module *module, return LDB_ERR_UNWILLING_TO_PERFORM; } - tdb_key = ltdb_key_msg(module, tdb_key_ctx, msg); + tdb_key = ldb_kv_key_msg(module, tdb_key_ctx, msg); if (!tdb_key.dptr) { TALLOC_FREE(tdb_key_ctx); return LDB_ERR_OTHER; @@ -756,7 +759,7 @@ int ltdb_delete_noindex(struct ldb_module *module, return ret; } -static int ltdb_delete_internal(struct ldb_module *module, struct ldb_dn *dn) +static int ldb_kv_delete_internal(struct ldb_module *module, struct ldb_dn *dn) { struct ldb_message *msg; int ret = LDB_SUCCESS; @@ -768,24 +771,24 @@ static int ltdb_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 = ltdb_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; } - ret = ltdb_delete_noindex(module, msg); + ret = ldb_kv_delete_noindex(module, msg); if (ret != LDB_SUCCESS) { goto done; } /* remove any indexed attributes */ - ret = ltdb_index_delete(module, msg); + ret = ldb_kv_index_delete(module, msg); if (ret != LDB_SUCCESS) { goto done; } - ret = ltdb_modified(module, dn); + ret = ldb_kv_modified(module, dn); if (ret != LDB_SUCCESS) { goto done; } @@ -798,7 +801,7 @@ done: /* delete a record from the database */ -static int ltdb_delete(struct ltdb_context *ctx) +static int ldb_kv_delete(struct ltdb_context *ctx) { struct ldb_module *module = ctx->module; struct ldb_request *req = ctx->req; @@ -806,11 +809,11 @@ static int ltdb_delete(struct ltdb_context *ctx) ldb_request_set_state(req, LDB_ASYNC_PENDING); - if (ltdb_cache_load(module) != 0) { + if (ldb_kv_cache_load(module) != 0) { return LDB_ERR_OPERATIONS_ERROR; } - ret = ltdb_delete_internal(module, req->op.del.dn); + ret = ldb_kv_delete_internal(module, req->op.del.dn); return ret; } @@ -822,7 +825,7 @@ static int ltdb_delete(struct ltdb_context *ctx) return the index of the first matching element if found, otherwise -1 */ -static int find_element(const struct ldb_message *msg, const char *name) +static int ldb_kv_find_element(const struct ldb_message *msg, const char *name) { unsigned int i; for (i=0;inum_elements;i++) { @@ -841,7 +844,7 @@ static int find_element(const struct ldb_message *msg, const char *name) returns 0 on success, -1 on failure (and sets errno) */ -static int ltdb_msg_add_element(struct ldb_message *msg, +static int ldb_kv_msg_add_element(struct ldb_message *msg, struct ldb_message_element *el) { struct ldb_message_element *e2; @@ -884,7 +887,7 @@ static int ltdb_msg_add_element(struct ldb_message *msg, /* delete all elements having a specified attribute name */ -static int msg_delete_attribute(struct ldb_module *module, +static int ldb_kv_msg_delete_attribute(struct ldb_module *module, struct ltdb_private *ltdb, struct ldb_message *msg, const char *name) { @@ -909,7 +912,7 @@ static int msg_delete_attribute(struct ldb_module *module, } i = el - msg->elements; - ret = ltdb_index_del_element(module, ltdb, msg, el); + ret = ldb_kv_index_del_element(module, ltdb, msg, el); if (ret != LDB_SUCCESS) { return ret; } @@ -930,7 +933,7 @@ static int msg_delete_attribute(struct ldb_module *module, return LDB Error on failure */ -static int msg_delete_element(struct ldb_module *module, +static int ldb_kv_msg_delete_element(struct ldb_module *module, struct ltdb_private *ltdb, struct ldb_message *msg, const char *name, @@ -942,7 +945,7 @@ static int msg_delete_element(struct ldb_module *module, struct ldb_message_element *el; const struct ldb_schema_attribute *a; - found = find_element(msg, name); + found = ldb_kv_find_element(msg, name); if (found == -1) { return LDB_ERR_NO_SUCH_ATTRIBUTE; } @@ -964,11 +967,11 @@ static int msg_delete_element(struct ldb_module *module, } if (matched) { if (el->num_values == 1) { - return msg_delete_attribute(module, + return ldb_kv_msg_delete_attribute(module, ltdb, msg, name); } - ret = ltdb_index_del_value(module, ltdb, msg, el, i); + ret = ldb_kv_index_del_value(module, ltdb, msg, el, i); if (ret != LDB_SUCCESS) { return ret; } @@ -999,7 +1002,7 @@ static int msg_delete_element(struct ldb_module *module, 'req' is optional, and is used to specify controls if supplied */ -int ltdb_modify_internal(struct ldb_module *module, +int ldb_kv_modify_internal(struct ldb_module *module, const struct ldb_message *msg, struct ldb_request *req) { @@ -1027,7 +1030,7 @@ int ltdb_modify_internal(struct ldb_module *module, goto done; } - ret = ltdb_search_dn1(module, msg->dn, + ret = ldb_kv_search_dn1(module, msg->dn, msg2, LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC); if (ret != LDB_SUCCESS) { @@ -1077,7 +1080,7 @@ int ltdb_modify_internal(struct ldb_module *module, } } - if (el->num_values > 1 && ldb_tdb_single_valued(a, el)) { + if (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(msg2->dn)); ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS; @@ -1085,13 +1088,13 @@ int ltdb_modify_internal(struct ldb_module *module, } /* Checks if element already exists */ - idx = find_element(msg2, el->name); + idx = ldb_kv_find_element(msg2, el->name); if (idx == -1) { - if (ltdb_msg_add_element(msg2, el) != 0) { + if (ldb_kv_msg_add_element(msg2, el) != 0) { ret = LDB_ERR_OTHER; goto done; } - ret = ltdb_index_add_element(module, ltdb, + ret = ldb_kv_index_add_element(module, ltdb, msg2, el); if (ret != LDB_SUCCESS) { @@ -1103,7 +1106,7 @@ int ltdb_modify_internal(struct ldb_module *module, /* We cannot add another value on a existing one if the attribute is single-valued */ - if (ldb_tdb_single_valued(a, el)) { + if (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(msg2->dn)); ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS; @@ -1173,7 +1176,7 @@ int ltdb_modify_internal(struct ldb_module *module, el2->values = vals; el2->num_values += el->num_values; - ret = ltdb_index_add_element(module, ltdb, + ret = ldb_kv_index_add_element(module, ltdb, msg2, el); if (ret != LDB_SUCCESS) { goto done; @@ -1184,7 +1187,7 @@ int ltdb_modify_internal(struct ldb_module *module, case LDB_FLAG_MOD_REPLACE: - if (el->num_values > 1 && ldb_tdb_single_valued(a, el)) { + if (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(msg2->dn)); ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS; @@ -1221,7 +1224,7 @@ int ltdb_modify_internal(struct ldb_module *module, } /* Checks if element already exists */ - idx = find_element(msg2, el->name); + idx = ldb_kv_find_element(msg2, el->name); if (idx != -1) { j = (unsigned int) idx; el2 = &(msg2->elements[j]); @@ -1238,7 +1241,7 @@ int ltdb_modify_internal(struct ldb_module *module, } /* Delete the attribute if it exists in the DB */ - if (msg_delete_attribute(module, ltdb, + if (ldb_kv_msg_delete_attribute(module, ltdb, msg2, el->name) != 0) { ret = LDB_ERR_OTHER; @@ -1247,12 +1250,12 @@ int ltdb_modify_internal(struct ldb_module *module, } /* Recreate it with the new values */ - if (ltdb_msg_add_element(msg2, el) != 0) { + if (ldb_kv_msg_add_element(msg2, el) != 0) { ret = LDB_ERR_OTHER; goto done; } - ret = ltdb_index_add_element(module, ltdb, + ret = ldb_kv_index_add_element(module, ltdb, msg2, el); if (ret != LDB_SUCCESS) { goto done; @@ -1269,7 +1272,7 @@ int ltdb_modify_internal(struct ldb_module *module, if (msg->elements[i].num_values == 0) { /* Delete the whole attribute */ - ret = msg_delete_attribute(module, + ret = ldb_kv_msg_delete_attribute(module, ltdb, msg2, msg->elements[i].name); @@ -1287,7 +1290,7 @@ int ltdb_modify_internal(struct ldb_module *module, } else { /* Delete specified values from an attribute */ for (j=0; j < msg->elements[i].num_values; j++) { - ret = msg_delete_element(module, + ret = ldb_kv_msg_delete_element(module, ltdb, msg2, msg->elements[i].name, @@ -1316,12 +1319,12 @@ int ltdb_modify_internal(struct ldb_module *module, } } - ret = ltdb_store(module, msg2, TDB_MODIFY); + ret = ldb_kv_store(module, msg2, TDB_MODIFY); if (ret != LDB_SUCCESS) { goto done; } - ret = ltdb_modified(module, msg2->dn); + ret = ldb_kv_modified(module, msg2->dn); if (ret != LDB_SUCCESS) { goto done; } @@ -1334,24 +1337,24 @@ done: /* modify a record */ -static int ltdb_modify(struct ltdb_context *ctx) +static int ldb_kv_modify(struct ltdb_context *ctx) { struct ldb_module *module = ctx->module; struct ldb_request *req = ctx->req; int ret = LDB_SUCCESS; - ret = ltdb_check_special_dn(module, req->op.mod.message); + ret = ldb_kv_check_special_dn(module, req->op.mod.message); if (ret != LDB_SUCCESS) { return ret; } ldb_request_set_state(req, LDB_ASYNC_PENDING); - if (ltdb_cache_load(module) != 0) { + if (ldb_kv_cache_load(module) != 0) { return LDB_ERR_OPERATIONS_ERROR; } - ret = ltdb_modify_internal(module, req->op.mod.message, req); + ret = ldb_kv_modify_internal(module, req->op.mod.message, req); return ret; } @@ -1359,7 +1362,7 @@ static int ltdb_modify(struct ltdb_context *ctx) /* rename a record */ -static int ltdb_rename(struct ltdb_context *ctx) +static int ldb_kv_rename(struct ltdb_context *ctx) { struct ldb_module *module = ctx->module; void *data = ldb_module_get_private(module); @@ -1372,7 +1375,7 @@ static int ltdb_rename(struct ltdb_context *ctx) ldb_request_set_state(req, LDB_ASYNC_PENDING); - if (ltdb_cache_load(ctx->module) != 0) { + if (ldb_kv_cache_load(ctx->module) != 0) { return LDB_ERR_OPERATIONS_ERROR; } @@ -1382,7 +1385,7 @@ static int ltdb_rename(struct ltdb_context *ctx) } /* we need to fetch the old record to re-add under the new name */ - ret = ltdb_search_dn1(module, req->op.rename.olddn, msg, + 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 */ @@ -1396,13 +1399,13 @@ static int ltdb_rename(struct ltdb_context *ctx) * Even in GUID index mode we use ltdb_key_dn() as we are * trying to figure out if this is just a case rename */ - tdb_key = ltdb_key_dn(module, msg, req->op.rename.newdn); + tdb_key = ldb_kv_key_dn(module, msg, req->op.rename.newdn); if (!tdb_key.dptr) { talloc_free(msg); return LDB_ERR_OPERATIONS_ERROR; } - tdb_key_old = ltdb_key_dn(module, msg, req->op.rename.olddn); + tdb_key_old = ldb_kv_key_dn(module, msg, req->op.rename.olddn); if (!tdb_key_old.dptr) { talloc_free(msg); talloc_free(tdb_key.dptr); @@ -1415,7 +1418,7 @@ static int ltdb_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 = ltdb_search_base(module, msg, + ret = ldb_kv_search_base(module, msg, req->op.rename.newdn, &db_dn); if (ret == LDB_SUCCESS) { @@ -1446,7 +1449,7 @@ static int ltdb_rename(struct ltdb_context *ctx) * unique indexes. We rely on the transaction to make this * atomic */ - ret = ltdb_delete_internal(module, msg->dn); + ret = ldb_kv_delete_internal(module, msg->dn); if (ret != LDB_SUCCESS) { talloc_free(msg); return ret; @@ -1462,14 +1465,14 @@ static int ltdb_rename(struct ltdb_context *ctx) * deleted attributes. We could go through all elements but that's * maybe not the most efficient way */ - ret = ltdb_add_internal(module, ltdb, msg, false); + ret = ldb_kv_add_internal(module, ltdb, msg, false); talloc_free(msg); return ret; } -static int ltdb_tdb_transaction_start(struct ltdb_private *ltdb) +static int ltdb_transaction_start(struct ltdb_private *ltdb) { pid_t pid = getpid(); @@ -1486,7 +1489,7 @@ static int ltdb_tdb_transaction_start(struct ltdb_private *ltdb) return tdb_transaction_start(ltdb->tdb); } -static int ltdb_tdb_transaction_cancel(struct ltdb_private *ltdb) +static int ltdb_transaction_cancel(struct ltdb_private *ltdb) { pid_t pid = getpid(); @@ -1503,7 +1506,7 @@ static int ltdb_tdb_transaction_cancel(struct ltdb_private *ltdb) return tdb_transaction_cancel(ltdb->tdb); } -static int ltdb_tdb_transaction_prepare_commit(struct ltdb_private *ltdb) +static int ltdb_transaction_prepare_commit(struct ltdb_private *ltdb) { pid_t pid = getpid(); @@ -1520,7 +1523,7 @@ static int ltdb_tdb_transaction_prepare_commit(struct ltdb_private *ltdb) return tdb_transaction_prepare_commit(ltdb->tdb); } -static int ltdb_tdb_transaction_commit(struct ltdb_private *ltdb) +static int ltdb_transaction_commit(struct ltdb_private *ltdb) { pid_t pid = getpid(); @@ -1537,7 +1540,7 @@ static int ltdb_tdb_transaction_commit(struct ltdb_private *ltdb) return tdb_transaction_commit(ltdb->tdb); } -static int ltdb_start_trans(struct ldb_module *module) +static int ldb_kv_start_trans(struct ldb_module *module) { void *data = ldb_module_get_private(module); struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); @@ -1564,7 +1567,7 @@ static int ltdb_start_trans(struct ldb_module *module) } - ltdb_index_transaction_start(module); + ldb_kv_index_transaction_start(module); ltdb->reindex_failed = false; @@ -1575,9 +1578,9 @@ static int ltdb_start_trans(struct ldb_module *module) * Forward declaration to allow prepare_commit to in fact abort the * transaction */ -static int ltdb_del_trans(struct ldb_module *module); +static int ldb_kv_del_trans(struct ldb_module *module); -static int ltdb_prepare_commit(struct ldb_module *module) +static int ldb_kv_prepare_commit(struct ldb_module *module) { int ret; void *data = ldb_module_get_private(module); @@ -1612,14 +1615,14 @@ static int ltdb_prepare_commit(struct ldb_module *module) * We must instead abort the transaction so we get the * old values and old index back */ - ltdb_del_trans(module); + ldb_kv_del_trans(module); ldb_set_errstring(ldb_module_get_ctx(module), "Failure during re-index, so " "transaction must be aborted."); return LDB_ERR_OPERATIONS_ERROR; } - ret = ltdb_index_transaction_commit(module); + ret = ldb_kv_index_transaction_commit(module); if (ret != LDB_SUCCESS) { ltdb->kv_ops->abort_write(ltdb); return ret; @@ -1641,14 +1644,14 @@ static int ltdb_prepare_commit(struct ldb_module *module) return LDB_SUCCESS; } -static int ltdb_end_trans(struct ldb_module *module) +static int ldb_kv_end_trans(struct ldb_module *module) { int ret; void *data = ldb_module_get_private(module); struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); if (!ltdb->prepared_commit) { - ret = ltdb_prepare_commit(module); + ret = ldb_kv_prepare_commit(module); if (ret != LDB_SUCCESS) { return ret; } @@ -1668,13 +1671,13 @@ static int ltdb_end_trans(struct ldb_module *module) return LDB_SUCCESS; } -static int ltdb_del_trans(struct ldb_module *module) +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 (ltdb_index_transaction_cancel(module) != 0) { + if (ldb_kv_index_transaction_cancel(module) != 0) { ltdb->kv_ops->abort_write(ltdb); return ltdb->kv_ops->error(ltdb); } @@ -1686,7 +1689,7 @@ static int ltdb_del_trans(struct ldb_module *module) /* return sequenceNumber from @BASEINFO */ -static int ltdb_sequence_number(struct ltdb_context *ctx, +static int ldb_kv_sequence_number(struct ltdb_context *ctx, struct ldb_extended **ext) { struct ldb_context *ldb; @@ -1740,7 +1743,7 @@ static int ltdb_sequence_number(struct ltdb_context *ctx, goto done; } - ret = ltdb_search_dn1(module, dn, msg, 0); + ret = ldb_kv_search_dn1(module, dn, msg, 0); if (ret != LDB_SUCCESS) { goto done; } @@ -1779,7 +1782,7 @@ done: return ret; } -static void ltdb_request_done(struct ltdb_context *ctx, int error) +static void ldb_kv_request_done(struct ltdb_context *ctx, int error) { struct ldb_context *ldb; struct ldb_request *req; @@ -1805,7 +1808,7 @@ static void ltdb_request_done(struct ltdb_context *ctx, int error) req->callback(req, ares); } -static void ltdb_timeout(struct tevent_context *ev, +static void ldb_kv_timeout(struct tevent_context *ev, struct tevent_timer *te, struct timeval t, void *private_data) @@ -1815,7 +1818,7 @@ static void ltdb_timeout(struct tevent_context *ev, if (!ctx->request_terminated) { /* request is done now */ - ltdb_request_done(ctx, LDB_ERR_TIME_LIMIT_EXCEEDED); + ldb_kv_request_done(ctx, LDB_ERR_TIME_LIMIT_EXCEEDED); } if (ctx->spy) { @@ -1826,7 +1829,7 @@ static void ltdb_timeout(struct tevent_context *ev, talloc_free(ctx); } -static void ltdb_request_extended_done(struct ltdb_context *ctx, +static void ldb_kv_request_extended_done(struct ltdb_context *ctx, struct ldb_extended *ext, int error) { @@ -1855,7 +1858,7 @@ static void ltdb_request_extended_done(struct ltdb_context *ctx, req->callback(req, ares); } -static void ltdb_handle_extended(struct ltdb_context *ctx) +static void ldb_kv_handle_extended(struct ltdb_context *ctx) { struct ldb_extended *ext = NULL; int ret; @@ -1863,13 +1866,13 @@ static void ltdb_handle_extended(struct ltdb_context *ctx) if (strcmp(ctx->req->op.extended.oid, LDB_EXTENDED_SEQUENCE_NUMBER) == 0) { /* get sequence number */ - ret = ltdb_sequence_number(ctx, &ext); + ret = ldb_kv_sequence_number(ctx, &ext); } else { /* not recognized */ ret = LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; } - ltdb_request_extended_done(ctx, ext, ret); + ldb_kv_request_extended_done(ctx, ext, ret); } struct kv_ctx { @@ -1881,7 +1884,7 @@ struct kv_ctx { void *private_data); }; -static int ldb_tdb_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 = { @@ -1895,7 +1898,7 @@ static int ldb_tdb_traverse_fn_wrapper(struct tdb_context *tdb, TDB_DATA tdb_key return kv_ctx->kv_traverse_fn(kv_ctx->ltdb, key, data, kv_ctx->ctx); } -static int ltdb_tdb_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, @@ -1903,13 +1906,13 @@ static int ltdb_tdb_traverse_fn(struct ltdb_private *ltdb, ldb_kv_traverse_fn fn .ltdb = ltdb }; if (tdb_transaction_active(ltdb->tdb)) { - return tdb_traverse(ltdb->tdb, ldb_tdb_traverse_fn_wrapper, &kv_ctx); + return tdb_traverse(ltdb->tdb, ltdb_traverse_fn_wrapper, &kv_ctx); } else { - return tdb_traverse_read(ltdb->tdb, ldb_tdb_traverse_fn_wrapper, &kv_ctx); + return tdb_traverse_read(ltdb->tdb, ltdb_traverse_fn_wrapper, &kv_ctx); } } -static int ltdb_tdb_update_in_iterate(struct ltdb_private *ltdb, +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) @@ -1961,7 +1964,7 @@ static int ltdb_tdb_update_in_iterate(struct ltdb_private *ltdb, return tdb_ret; } -static int ltdb_tdb_parse_record_wrapper(TDB_DATA tdb_key, TDB_DATA tdb_data, +static int ltdb_parse_record_wrapper(TDB_DATA tdb_key, TDB_DATA tdb_data, void *ctx) { struct kv_ctx *kv_ctx = ctx; @@ -1977,7 +1980,7 @@ static int ltdb_tdb_parse_record_wrapper(TDB_DATA tdb_key, TDB_DATA tdb_data, return kv_ctx->parser(key, data, kv_ctx->ctx); } -static int ltdb_tdb_parse_record(struct ltdb_private *ltdb, +static int ltdb_parse_record(struct ltdb_private *ltdb, struct ldb_val ldb_key, int (*parser)(struct ldb_val key, struct ldb_val data, @@ -2000,7 +2003,7 @@ static int ltdb_tdb_parse_record(struct ltdb_private *ltdb, return LDB_ERR_PROTOCOL_ERROR; } - ret = tdb_parse_record(ltdb->tdb, key, ltdb_tdb_parse_record_wrapper, + ret = tdb_parse_record(ltdb->tdb, key, ltdb_parse_record_wrapper, &kv_ctx); if (ret == 0) { return LDB_SUCCESS; @@ -2008,12 +2011,12 @@ static int ltdb_tdb_parse_record(struct ltdb_private *ltdb, return ltdb_err_map(tdb_error(ltdb->tdb)); } -static const char * ltdb_tdb_name(struct ltdb_private *ltdb) +static const char * ltdb_name(struct ltdb_private *ltdb) { return tdb_name(ltdb->tdb); } -static bool ltdb_tdb_changed(struct ltdb_private *ltdb) +static bool ltdb_changed(struct ltdb_private *ltdb) { int seq = tdb_get_seqnum(ltdb->tdb); bool has_changed = (seq != ltdb->tdb_seqnum); @@ -2029,25 +2032,25 @@ static bool ltdb_transaction_active(struct ltdb_private *ltdb) } static const struct kv_db_ops key_value_ops = { - .store = ltdb_tdb_store, - .delete = ltdb_tdb_delete, - .iterate = ltdb_tdb_traverse_fn, - .update_in_iterate = ltdb_tdb_update_in_iterate, - .fetch_and_parse = ltdb_tdb_parse_record, + .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_tdb_transaction_start, - .prepare_write = ltdb_tdb_transaction_prepare_commit, - .finish_write = ltdb_tdb_transaction_commit, - .abort_write = ltdb_tdb_transaction_cancel, + .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_tdb_name, - .has_changed = ltdb_tdb_changed, + .name = ltdb_name, + .has_changed = ltdb_changed, .transaction_active = ltdb_transaction_active, }; -static void ltdb_callback(struct tevent_context *ev, +static void ldb_kv_callback(struct tevent_context *ev, struct tevent_timer *te, struct timeval t, void *private_data) @@ -2063,22 +2066,22 @@ static void ltdb_callback(struct tevent_context *ev, switch (ctx->req->operation) { case LDB_SEARCH: - ret = ltdb_search(ctx); + ret = ldb_kv_search(ctx); break; case LDB_ADD: - ret = ltdb_add(ctx); + ret = ldb_kv_add(ctx); break; case LDB_MODIFY: - ret = ltdb_modify(ctx); + ret = ldb_kv_modify(ctx); break; case LDB_DELETE: - ret = ltdb_delete(ctx); + ret = ldb_kv_delete(ctx); break; case LDB_RENAME: - ret = ltdb_rename(ctx); + ret = ldb_kv_rename(ctx); break; case LDB_EXTENDED: - ltdb_handle_extended(ctx); + ldb_kv_handle_extended(ctx); goto done; default: /* no other op supported */ @@ -2087,7 +2090,7 @@ static void ltdb_callback(struct tevent_context *ev, if (!ctx->request_terminated) { /* request is done now */ - ltdb_request_done(ctx, ret); + ldb_kv_request_done(ctx, ret); } done: @@ -2099,7 +2102,7 @@ done: talloc_free(ctx); } -static int ltdb_request_destructor(void *ptr) +static int ldb_kv_request_destructor(void *ptr) { struct ltdb_req_spy *spy = talloc_get_type(ptr, struct ltdb_req_spy); @@ -2112,7 +2115,7 @@ static int ltdb_request_destructor(void *ptr) return 0; } -static int ltdb_handle_request(struct ldb_module *module, +static int ldb_kv_handle_request(struct ldb_module *module, struct ldb_request *req) { struct ldb_control *control_permissive; @@ -2155,7 +2158,7 @@ static int ltdb_handle_request(struct ldb_module *module, tv.tv_sec = 0; tv.tv_usec = 0; - te = tevent_add_timer(ev, ac, tv, ltdb_callback, ac); + te = tevent_add_timer(ev, ac, tv, ldb_kv_callback, ac); if (NULL == te) { talloc_free(ac); return LDB_ERR_OPERATIONS_ERROR; @@ -2165,7 +2168,7 @@ static int ltdb_handle_request(struct ldb_module *module, tv.tv_sec = req->starttime + req->timeout; tv.tv_usec = 0; ac->timeout_event = tevent_add_timer(ev, ac, tv, - ltdb_timeout, ac); + ldb_kv_timeout, ac); if (NULL == ac->timeout_event) { talloc_free(ac); return LDB_ERR_OPERATIONS_ERROR; @@ -2181,12 +2184,12 @@ static int ltdb_handle_request(struct ldb_module *module, } ac->spy->ctx = ac; - talloc_set_destructor((TALLOC_CTX *)ac->spy, ltdb_request_destructor); + talloc_set_destructor((TALLOC_CTX *)ac->spy, ldb_kv_request_destructor); return LDB_SUCCESS; } -static int ltdb_init_rootdse(struct ldb_module *module) +static int ldb_kv_init_rootdse(struct ldb_module *module) { /* ignore errors on this - we expect it for non-sam databases */ ldb_mod_register_control(module, LDB_CONTROL_PERMISSIVE_MODIFY_OID); @@ -2196,38 +2199,38 @@ static int ltdb_init_rootdse(struct ldb_module *module) } -static int generic_lock_read(struct ldb_module *module) +static int ldb_kv_lock_read(struct ldb_module *module) { void *data = ldb_module_get_private(module); struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); return ltdb->kv_ops->lock_read(module); } -static int generic_unlock_read(struct ldb_module *module) +static int ldb_kv_unlock_read(struct ldb_module *module) { void *data = ldb_module_get_private(module); struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); return ltdb->kv_ops->unlock_read(module); } -static const struct ldb_module_ops ltdb_ops = { +static const struct ldb_module_ops ldb_kv_ops = { .name = "tdb", - .init_context = ltdb_init_rootdse, - .search = ltdb_handle_request, - .add = ltdb_handle_request, - .modify = ltdb_handle_request, - .del = ltdb_handle_request, - .rename = ltdb_handle_request, - .extended = ltdb_handle_request, - .start_transaction = ltdb_start_trans, - .end_transaction = ltdb_end_trans, - .prepare_commit = ltdb_prepare_commit, - .del_transaction = ltdb_del_trans, - .read_lock = generic_lock_read, - .read_unlock = generic_unlock_read, + .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 init_store(struct ltdb_private *ltdb, +int ldb_kv_init_store(struct ltdb_private *ltdb, const char *name, struct ldb_context *ldb, const char *options[], @@ -2245,7 +2248,7 @@ int init_store(struct ltdb_private *ltdb, ltdb->pid = getpid(); - ltdb->module = ldb_module_new(ldb, ldb, name, <db_ops); + ltdb->module = ldb_module_new(ldb, ldb, name, &ldb_kv_ops); if (!ltdb->module) { ldb_oom(ldb); talloc_free(ltdb); @@ -2254,7 +2257,7 @@ int init_store(struct ltdb_private *ltdb, ldb_module_set_private(ltdb->module, ltdb); talloc_steal(ltdb->module, ltdb); - if (ltdb_cache_load(ltdb->module) != 0) { + if (ldb_kv_cache_load(ltdb->module) != 0) { ldb_asprintf_errstring(ldb, "Unable to load ltdb cache " "records for backend '%s'", name); talloc_free(ltdb->module); @@ -2390,5 +2393,6 @@ int ltdb_connect(struct ldb_context *ldb, const char *url, return LDB_ERR_OPERATIONS_ERROR; } - return init_store(ltdb, "ldb_tdb backend", ldb, options, _module); + return ldb_kv_init_store( + ltdb, "ldb_tdb backend", ldb, options, _module); } diff --git a/lib/ldb/ldb_tdb/ldb_tdb.h b/lib/ldb/ldb_tdb/ldb_tdb.h index 2896c6376b8..675355ea416 100644 --- a/lib/ldb/ldb_tdb/ldb_tdb.h +++ b/lib/ldb/ldb_tdb/ldb_tdb.h @@ -153,37 +153,37 @@ struct ltdb_reindex_context { /* The following definitions come from lib/ldb/ldb_tdb/ldb_cache.c */ -int ltdb_cache_reload(struct ldb_module *module); -int ltdb_cache_load(struct ldb_module *module); -int ltdb_increase_sequence_number(struct ldb_module *module); -int ltdb_check_at_attributes_values(const struct ldb_val *value); +int ldb_kv_cache_reload(struct ldb_module *module); +int ldb_kv_cache_load(struct ldb_module *module); +int ldb_kv_increase_sequence_number(struct ldb_module *module); +int ldb_kv_check_at_attributes_values(const struct ldb_val *value); /* The following definitions come from lib/ldb/ldb_tdb/ldb_index.c */ struct ldb_parse_tree; -int ltdb_search_indexed(struct ltdb_context *ctx, uint32_t *); -int ltdb_index_add_new(struct ldb_module *module, +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 ltdb_index_delete(struct ldb_module *module, const struct ldb_message *msg); -int ltdb_index_del_element(struct ldb_module *module, +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 ltdb_index_add_element(struct ldb_module *module, +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 ltdb_index_del_value(struct ldb_module *module, +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 ltdb_reindex(struct ldb_module *module); -int ltdb_index_transaction_start(struct ldb_module *module); -int ltdb_index_transaction_commit(struct ldb_module *module); -int ltdb_index_transaction_cancel(struct ldb_module *module); -int ltdb_key_dn_from_idx(struct ldb_module *module, +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, @@ -194,44 +194,44 @@ int ltdb_key_dn_from_idx(struct ldb_module *module, 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 ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, 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 ltdb_search_base(struct ldb_module *module, +int ldb_kv_search_base(struct ldb_module *module, TALLOC_CTX *mem_ctx, struct ldb_dn *dn, struct ldb_dn **ret_dn); -int ltdb_search_key(struct ldb_module *module, struct ltdb_private *ltdb, +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 ltdb_filter_attrs(TALLOC_CTX *mem_ctx, +int ldb_kv_filter_attrs(TALLOC_CTX *mem_ctx, const struct ldb_message *msg, const char * const *attrs, struct ldb_message **filtered_msg); -int ltdb_search(struct ltdb_context *ctx); +int ldb_kv_search(struct ltdb_context *ctx); /* The following definitions come from lib/ldb/ldb_tdb/ldb_tdb.c */ /* * Determine if this key could hold a record. We allow the new GUID * index, the old DN index and a possible future ID= */ -bool ltdb_key_is_record(TDB_DATA key); -TDB_DATA ltdb_key_dn(struct ldb_module *module, TALLOC_CTX *mem_ctx, +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 ltdb_key_msg(struct ldb_module *module, TALLOC_CTX *mem_ctx, +TDB_DATA ldb_kv_key_msg(struct ldb_module *module, TALLOC_CTX *mem_ctx, const struct ldb_message *msg); -int ltdb_guid_to_key(struct ldb_module *module, +int ldb_kv_guid_to_key(struct ldb_module *module, struct ltdb_private *ltdb, const struct ldb_val *GUID_val, TDB_DATA *key); -int ltdb_idx_to_key(struct ldb_module *module, +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 ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flgs); -int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *msg, struct ldb_request *req); -int ltdb_delete_noindex(struct ldb_module *module, +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); @@ -239,9 +239,9 @@ 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 init_store(struct ltdb_private *ltdb, const char *name, - struct ldb_context *ldb, const char *options[], - struct ldb_module **_module); +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, unsigned int flags, const char *options[],