From 4889eb9f7aae9349e426d0f6d2217adff67eaebd Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 22 Nov 2006 00:59:34 +0000 Subject: r19831: Big ldb_dn optimization and interfaces enhancement patch This patch changes a lot of the code in ldb_dn.c, and also removes and add a number of manipulation functions around. The aim is to avoid validating a dn if not necessary as the validation code is necessarily slow. This is mainly to speed up internal operations where input is not user generated and so we can assume the DNs need no validation. The code is designed to keep the data as a string if possible. The code is not yet 100% perfect, but pass all the tests so far. A memleak is certainly present, I'll work on that next. Simo. (This used to be commit a580c871d3784602a9cce32d33419e63c8236e63) --- source4/lib/ldb/ldb_tdb/ldb_cache.c | 12 ++++++------ source4/lib/ldb/ldb_tdb/ldb_index.c | 4 ++-- source4/lib/ldb/ldb_tdb/ldb_pack.c | 2 +- source4/lib/ldb/ldb_tdb/ldb_search.c | 6 +++--- source4/lib/ldb/ldb_tdb/ldb_tdb.c | 14 ++++++-------- source4/lib/ldb/ldb_tdb/ldb_tdb.h | 8 ++++---- 6 files changed, 22 insertions(+), 24 deletions(-) (limited to 'source4/lib/ldb/ldb_tdb') diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 467f1ac34d..756c198106 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -112,7 +112,7 @@ static int ltdb_attributes_load(struct ldb_module *module) struct ldb_dn *dn; int i; - dn = ldb_dn_explode(module->ldb, LTDB_ATTRIBUTES); + dn = ldb_dn_new(module, module->ldb, LTDB_ATTRIBUTES); if (dn == NULL) goto failed; if (ltdb_search_dn1(module, dn, msg) == -1) { @@ -180,7 +180,7 @@ static int ltdb_subclasses_load(struct ldb_module *module) struct ldb_dn *dn; int i, j; - dn = ldb_dn_explode(module->ldb, LTDB_SUBCLASSES); + dn = ldb_dn_new(module, module->ldb, LTDB_SUBCLASSES); if (dn == NULL) goto failed; if (ltdb_search_dn1(module, dn, msg) == -1) { @@ -253,7 +253,7 @@ static int ltdb_baseinfo_init(struct ldb_module *module) msg->num_elements = 1; msg->elements = ⪙ - msg->dn = ldb_dn_explode(msg, LTDB_BASEINFO); + msg->dn = ldb_dn_new(msg, module->ldb, LTDB_BASEINFO); if (!msg->dn) { goto failed; } @@ -338,7 +338,7 @@ int ltdb_cache_load(struct ldb_module *module) baseinfo = talloc(ltdb->cache, struct ldb_message); if (baseinfo == NULL) goto failed; - baseinfo_dn = ldb_dn_explode(module->ldb, LTDB_BASEINFO); + baseinfo_dn = ldb_dn_new(module, module->ldb, LTDB_BASEINFO); if (baseinfo_dn == NULL) goto failed; if (ltdb_search_dn1(module, baseinfo_dn, baseinfo) == -1) { @@ -383,7 +383,7 @@ int ltdb_cache_load(struct ldb_module *module) goto failed; } - indexlist_dn = ldb_dn_explode(module->ldb, LTDB_INDEXLIST); + indexlist_dn = ldb_dn_new(module, module->ldb, LTDB_INDEXLIST); if (indexlist_dn == NULL) goto failed; if (ltdb_search_dn1(module, indexlist_dn, ltdb->cache->indexlist) == -1) { @@ -439,7 +439,7 @@ int ltdb_increase_sequence_number(struct ldb_module *module) msg->num_elements = ARRAY_SIZE(el); msg->elements = el; - msg->dn = ldb_dn_explode(msg, LTDB_BASEINFO); + msg->dn = ldb_dn_new(msg, module->ldb, LTDB_BASEINFO); if (msg->dn == NULL) { talloc_free(msg); errno = ENOMEM; diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c index 0c9d1f33a1..874d047186 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_index.c +++ b/source4/lib/ldb/ldb_tdb/ldb_index.c @@ -147,7 +147,7 @@ static struct ldb_dn *ldb_dn_key(struct ldb_context *ldb, talloc_free(attr_folded); done: - ret = ldb_dn_explode(ldb, dn); + ret = ldb_dn_new(ldb, ldb, dn); talloc_free(dn); return ret; } @@ -662,7 +662,7 @@ static int ltdb_index_filter(const struct dn_list *dn_list, } - dn = ldb_dn_explode(ares->message, dn_list->dn[i]); + dn = ldb_dn_new(ares->message, ac->module->ldb, dn_list->dn[i]); if (dn == NULL) { talloc_free(ares); return LDB_ERR_OPERATIONS_ERROR; diff --git a/source4/lib/ldb/ldb_tdb/ldb_pack.c b/source4/lib/ldb/ldb_tdb/ldb_pack.c index c6edf663ae..258c54356c 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_pack.c +++ b/source4/lib/ldb/ldb_tdb/ldb_pack.c @@ -196,7 +196,7 @@ int ltdb_unpack_data(struct ldb_module *module, errno = EIO; goto failed; } - message->dn = ldb_dn_explode(message, (char *)p); + message->dn = ldb_dn_new(message, ldb, (char *)p); if (message->dn == NULL) { errno = ENOMEM; goto failed; diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 884eccd362..3f04994ce4 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -209,7 +209,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, return 1 on success, 0 on record-not-found and -1 on error */ -int ltdb_search_dn1(struct ldb_module *module, const struct ldb_dn *dn, struct ldb_message *msg) +int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_message *msg) { struct ltdb_private *ltdb = module->private_data; int ret; @@ -394,7 +394,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi } if (!ares->message->dn) { - ares->message->dn = ldb_dn_explode(ares->message, (char *)key.dptr + 3); + ares->message->dn = ldb_dn_new(ares->message, ac->module->ldb, (char *)key.dptr + 3); if (ares->message->dn == NULL) { handle->status = LDB_ERR_OPERATIONS_ERROR; handle->state = LDB_ASYNC_DONE; @@ -464,7 +464,7 @@ int ltdb_search(struct ldb_module *module, struct ldb_request *req) struct ldb_reply *ares; int ret; - if ((req->op.search.base == NULL || ldb_dn_get_comp_num(req->op.search.base) == 0) && + if ((( ! ldb_dn_is_valid(req->op.search.base)) || ldb_dn_is_null(req->op.search.base)) && (req->op.search.scope == LDB_SCOPE_BASE || req->op.search.scope == LDB_SCOPE_ONELEVEL)) return LDB_ERR_OPERATIONS_ERROR; diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 3f9db39097..d950ab9cf0 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -118,7 +118,7 @@ struct ldb_handle *init_ltdb_handle(struct ltdb_private *ltdb, struct ldb_module note that the key for a record can depend on whether the dn refers to a case sensitive index record or not */ -struct TDB_DATA ltdb_key(struct ldb_module *module, const struct ldb_dn *dn) +struct TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn) { struct ldb_context *ldb = module->ldb; TDB_DATA key; @@ -137,15 +137,13 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const struct ldb_dn *dn) the rest */ - dn_folded = ldb_dn_linearize_casefold(ldb, ldb, dn); + dn_folded = ldb_dn_get_casefold(dn); if (!dn_folded) { goto failed; } key_str = talloc_asprintf(ldb, "DN=%s", dn_folded); - talloc_free(dn_folded); - if (!key_str) { goto failed; } @@ -194,7 +192,7 @@ int ltdb_check_special_dn(struct ldb_module *module, const struct ldb_message *m we've made a modification to a dn - possibly reindex and update sequence number */ -static int ltdb_modified(struct ldb_module *module, const struct ldb_dn *dn) +static int ltdb_modified(struct ldb_module *module, struct ldb_dn *dn) { int ret = 0; @@ -330,7 +328,7 @@ done: delete a record from the database, not updating indexes (used for deleting index records) */ -int ltdb_delete_noindex(struct ldb_module *module, const struct ldb_dn *dn) +int ltdb_delete_noindex(struct ldb_module *module, struct ldb_dn *dn) { struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); @@ -352,7 +350,7 @@ int ltdb_delete_noindex(struct ldb_module *module, const struct ldb_dn *dn) return ret; } -static int ltdb_delete_internal(struct ldb_module *module, const struct ldb_dn *dn) +static int ltdb_delete_internal(struct ldb_module *module, struct ldb_dn *dn) { struct ldb_message *msg; int ret; @@ -936,7 +934,7 @@ static int ltdb_sequence_number(struct ldb_module *module, struct ldb_request *r { TALLOC_CTX *tmp_ctx = talloc_new(req); struct ldb_message *msg = NULL; - struct ldb_dn *dn = ldb_dn_explode(tmp_ctx, LTDB_BASEINFO); + struct ldb_dn *dn = ldb_dn_new(tmp_ctx, module->ldb, LTDB_BASEINFO); int tret; if (tmp_ctx == NULL) { diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.h b/source4/lib/ldb/ldb_tdb/ldb_tdb.h index 42f3dc2421..6b556153ad 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.h +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.h @@ -46,7 +46,7 @@ struct ltdb_context { /* search stuff */ const struct ldb_parse_tree *tree; - const struct ldb_dn *base; + struct ldb_dn *base; enum ldb_scope scope; const char * const *attrs; @@ -101,7 +101,7 @@ int ltdb_unpack_data(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, const struct ldb_dn *dn, struct ldb_message *msg); +int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_message *msg); int ltdb_add_attr_results(struct ldb_module *module, TALLOC_CTX *mem_ctx, struct ldb_message *msg, @@ -114,9 +114,9 @@ int ltdb_search(struct ldb_module *module, struct ldb_request *req); /* The following definitions come from lib/ldb/ldb_tdb/ldb_tdb.c */ struct ldb_handle *init_ltdb_handle(struct ltdb_private *ltdb, struct ldb_module *module, struct ldb_request *req); -struct TDB_DATA ltdb_key(struct ldb_module *module, const struct ldb_dn *dn); +struct 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_delete_noindex(struct ldb_module *module, const struct ldb_dn *dn); +int ltdb_delete_noindex(struct ldb_module *module, struct ldb_dn *dn); int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *msg); int ltdb_index_del_value(struct ldb_module *module, const char *dn, -- cgit