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/tools/ldbtest.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'source4/lib/ldb/tools/ldbtest.c') diff --git a/source4/lib/ldb/tools/ldbtest.c b/source4/lib/ldb/tools/ldbtest.c index 6cc8dfe19b..70b2b0148a 100644 --- a/source4/lib/ldb/tools/ldbtest.c +++ b/source4/lib/ldb/tools/ldbtest.c @@ -52,7 +52,7 @@ static double _end_timer(void) } static void add_records(struct ldb_context *ldb, - const struct ldb_dn *basedn, + struct ldb_dn *basedn, int count) { struct ldb_message msg; @@ -72,7 +72,8 @@ static void add_records(struct ldb_context *ldb, name = talloc_asprintf(tmp_ctx, "Test%d", i); - msg.dn = ldb_dn_build_child(tmp_ctx, "cn", name, basedn); + msg.dn = ldb_dn_copy(tmp_ctx, basedn); + ldb_dn_add_child_fmt(msg.dn, "cn=%s", name); msg.num_elements = 6; msg.elements = el; @@ -140,7 +141,7 @@ static void add_records(struct ldb_context *ldb, } static void modify_records(struct ldb_context *ldb, - const struct ldb_dn *basedn, + struct ldb_dn *basedn, int count) { struct ldb_message msg; @@ -153,7 +154,8 @@ static void modify_records(struct ldb_context *ldb, TALLOC_CTX *tmp_ctx = talloc_new(ldb); name = talloc_asprintf(tmp_ctx, "Test%d", i); - msg.dn = ldb_dn_build_child(tmp_ctx, "cn", name, basedn); + msg.dn = ldb_dn_copy(tmp_ctx, basedn); + ldb_dn_add_child_fmt(msg.dn, "cn=%s", name); msg.num_elements = 3; msg.elements = el; @@ -192,7 +194,7 @@ static void modify_records(struct ldb_context *ldb, static void delete_records(struct ldb_context *ldb, - const struct ldb_dn *basedn, + struct ldb_dn *basedn, int count) { int i; @@ -200,13 +202,14 @@ static void delete_records(struct ldb_context *ldb, for (i=0;ibasedn); + basedn = ldb_dn_new(ldb, ldb, options->basedn); + if ( ! ldb_dn_validate(basedn)) { + printf("Invalid base DN\n"); + exit(1); + } printf("Adding %d records\n", nrecords); add_records(ldb, basedn, nrecords); @@ -305,7 +312,7 @@ static void start_test_index(struct ldb_context **ldb) printf("Starting index test\n"); - indexlist = ldb_dn_explode(NULL, "@INDEXLIST"); + indexlist = ldb_dn_new(*ldb, *ldb, "@INDEXLIST"); ldb_delete(*ldb, indexlist); @@ -319,10 +326,11 @@ static void start_test_index(struct ldb_context **ldb) exit(1); } - basedn = ldb_dn_explode(NULL, options->basedn); + basedn = ldb_dn_new(*ldb, *ldb, options->basedn); memset(msg, 0, sizeof(*msg)); - msg->dn = ldb_dn_build_child(msg, "cn", "test", basedn); + msg->dn = ldb_dn_copy(msg, basedn); + ldb_dn_add_child_fmt(msg->dn, "cn=test"); ldb_msg_add_string(msg, "cn", strdup("test")); ldb_msg_add_string(msg, "sn", strdup("test")); ldb_msg_add_string(msg, "uid", strdup("test")); @@ -339,13 +347,15 @@ static void start_test_index(struct ldb_context **ldb) } (*ldb) = ldb_init(options); - + ret = ldb_connect(*ldb, options->url, flags, NULL); if (ret != 0) { printf("failed to connect to %s\n", options->url); exit(1); } + basedn = ldb_dn_new(*ldb, *ldb, options->basedn); + ret = ldb_search(*ldb, basedn, LDB_SCOPE_SUBTREE, "uid=test", NULL, &res); if (ret != LDB_SUCCESS) { printf("Search with (uid=test) filter failed!\n"); @@ -356,6 +366,8 @@ static void start_test_index(struct ldb_context **ldb) exit(1); } + indexlist = ldb_dn_new(*ldb, *ldb, "@INDEXLIST"); + if (ldb_delete(*ldb, msg->dn) != 0 || ldb_delete(*ldb, indexlist) != 0) { printf("cleanup failed - %s\n", ldb_errstring(*ldb)); -- cgit