summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/tools
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2006-11-22 00:59:34 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:28:22 -0500
commit4889eb9f7aae9349e426d0f6d2217adff67eaebd (patch)
tree7eb63c32bcbd19bf64d5c315f01785f30d3a789c /source4/lib/ldb/tools
parentce0c2236b953dc977655dbceef40916825e843ae (diff)
downloadsamba-4889eb9f7aae9349e426d0f6d2217adff67eaebd.tar.gz
samba-4889eb9f7aae9349e426d0f6d2217adff67eaebd.tar.bz2
samba-4889eb9f7aae9349e426d0f6d2217adff67eaebd.zip
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)
Diffstat (limited to 'source4/lib/ldb/tools')
-rw-r--r--source4/lib/ldb/tools/ad2oLschema.c4
-rw-r--r--source4/lib/ldb/tools/ldbdel.c8
-rw-r--r--source4/lib/ldb/tools/ldbedit.c8
-rw-r--r--source4/lib/ldb/tools/ldbrename.c15
-rw-r--r--source4/lib/ldb/tools/ldbsearch.c9
-rw-r--r--source4/lib/ldb/tools/ldbtest.c36
-rw-r--r--source4/lib/ldb/tools/oLschema2ldif.c9
7 files changed, 54 insertions, 35 deletions
diff --git a/source4/lib/ldb/tools/ad2oLschema.c b/source4/lib/ldb/tools/ad2oLschema.c
index 62c6e01c2e..49c4fa1fd6 100644
--- a/source4/lib/ldb/tools/ad2oLschema.c
+++ b/source4/lib/ldb/tools/ad2oLschema.c
@@ -200,7 +200,7 @@ static struct ldb_dn *find_schema_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ct
{
const char *rootdse_attrs[] = {"schemaNamingContext", NULL};
struct ldb_dn *schemadn;
- struct ldb_dn *basedn = ldb_dn_explode(mem_ctx, "");
+ struct ldb_dn *basedn = ldb_dn_new(mem_ctx, ldb, NULL);
struct ldb_result *rootdse_res;
int ldb_ret;
if (!basedn) {
@@ -222,7 +222,7 @@ static struct ldb_dn *find_schema_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ct
}
/* Locate schema */
- schemadn = ldb_msg_find_attr_as_dn(mem_ctx, rootdse_res->msgs[0], "schemaNamingContext");
+ schemadn = ldb_msg_find_attr_as_dn(ldb, mem_ctx, rootdse_res->msgs[0], "schemaNamingContext");
if (!schemadn) {
return NULL;
}
diff --git a/source4/lib/ldb/tools/ldbdel.c b/source4/lib/ldb/tools/ldbdel.c
index 94f1da9903..b4da806b51 100644
--- a/source4/lib/ldb/tools/ldbdel.c
+++ b/source4/lib/ldb/tools/ldbdel.c
@@ -36,7 +36,7 @@
#include "ldb/include/includes.h"
#include "ldb/tools/cmdline.h"
-static int ldb_delete_recursive(struct ldb_context *ldb, const struct ldb_dn *dn)
+static int ldb_delete_recursive(struct ldb_context *ldb, struct ldb_dn *dn)
{
int ret, i, total=0;
const char *attrs[] = { NULL };
@@ -91,10 +91,10 @@ int main(int argc, const char **argv)
}
for (i=0;i<options->argc;i++) {
- const struct ldb_dn *dn;
+ struct ldb_dn *dn;
- dn = ldb_dn_explode(ldb, options->argv[i]);
- if (dn == NULL) {
+ dn = ldb_dn_new(ldb, ldb, options->argv[i]);
+ if ( ! ldb_dn_validate(dn)) {
printf("Invalid DN format\n");
exit(1);
}
diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c
index 17ade152b7..429febb75b 100644
--- a/source4/lib/ldb/tools/ldbedit.c
+++ b/source4/lib/ldb/tools/ldbedit.c
@@ -91,11 +91,11 @@ static int modify_record(struct ldb_context *ldb,
static struct ldb_message *msg_find(struct ldb_context *ldb,
struct ldb_message **msgs,
int count,
- const struct ldb_dn *dn)
+ struct ldb_dn *dn)
{
int i;
for (i=0;i<count;i++) {
- if (ldb_dn_compare(ldb, dn, msgs[i]->dn) == 0) {
+ if (ldb_dn_compare(dn, msgs[i]->dn) == 0) {
return msgs[i];
}
}
@@ -300,8 +300,8 @@ int main(int argc, const char **argv)
}
if (options->basedn != NULL) {
- basedn = ldb_dn_explode(ldb, options->basedn);
- if (basedn == NULL) {
+ basedn = ldb_dn_new(ldb, ldb, options->basedn);
+ if ( ! ldb_dn_validate(basedn)) {
printf("Invalid Base DN format\n");
exit(1);
}
diff --git a/source4/lib/ldb/tools/ldbrename.c b/source4/lib/ldb/tools/ldbrename.c
index 9c0870721d..d7e1347fea 100644
--- a/source4/lib/ldb/tools/ldbrename.c
+++ b/source4/lib/ldb/tools/ldbrename.c
@@ -56,7 +56,7 @@ int main(int argc, const char **argv)
struct ldb_context *ldb;
int ret;
struct ldb_cmdline *options;
- const struct ldb_dn *dn1, *dn2;
+ struct ldb_dn *dn1, *dn2;
ldb_global_init();
@@ -68,8 +68,17 @@ int main(int argc, const char **argv)
usage();
}
- dn1 = ldb_dn_explode(ldb, options->argv[0]);
- dn2 = ldb_dn_explode(ldb, options->argv[1]);
+ dn1 = ldb_dn_new(ldb, ldb, options->argv[0]);
+ dn2 = ldb_dn_new(ldb, ldb, options->argv[1]);
+
+ if ( ! ldb_dn_validate(dn1)) {
+ printf("Invalid DN1: %s\n", options->argv[0]);
+ return -1;
+ }
+ if ( ! ldb_dn_validate(dn2)) {
+ printf("Invalid DN2: %s\n", options->argv[1]);
+ return -1;
+ }
ret = ldb_rename(ldb, dn1, dn2);
if (ret == 0) {
diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c
index 837dfc9088..7bf9d64fc2 100644
--- a/source4/lib/ldb/tools/ldbsearch.c
+++ b/source4/lib/ldb/tools/ldbsearch.c
@@ -54,8 +54,7 @@ static int do_compare_msg(struct ldb_message **el1,
struct ldb_message **el2,
void *opaque)
{
- struct ldb_context *ldb = talloc_get_type(opaque, struct ldb_context);
- return ldb_dn_compare(ldb, (*el1)->dn, (*el2)->dn);
+ return ldb_dn_compare((*el1)->dn, (*el2)->dn);
}
struct search_context {
@@ -185,7 +184,7 @@ static int search_callback(struct ldb_context *ldb, void *context, struct ldb_re
}
static int do_search(struct ldb_context *ldb,
- const struct ldb_dn *basedn,
+ struct ldb_dn *basedn,
struct ldb_cmdline *options,
const char *expression,
const char * const *attrs)
@@ -298,8 +297,8 @@ int main(int argc, const char **argv)
}
if (options->basedn != NULL) {
- basedn = ldb_dn_explode(ldb, options->basedn);
- if (basedn == NULL) {
+ basedn = ldb_dn_new(ldb, ldb, options->basedn);
+ if ( ! ldb_dn_validate(basedn)) {
fprintf(stderr, "Invalid Base DN format\n");
exit(1);
}
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;i<count;i++) {
struct ldb_dn *dn;
char *name = talloc_asprintf(ldb, "Test%d", i);
- dn = ldb_dn_build_child(name, "cn", name, basedn);
+ dn = ldb_dn_copy(name, basedn);
+ ldb_dn_add_child_fmt(dn, "cn=%s", name);
printf("Deleting uid Test%d\r", i);
fflush(stdout);
if (ldb_delete(ldb, dn) != 0) {
- printf("Delete of %s failed - %s\n", ldb_dn_linearize(ldb, dn), ldb_errstring(ldb));
+ printf("Delete of %s failed - %s\n", ldb_dn_get_linearized(dn), ldb_errstring(ldb));
exit(1);
}
talloc_free(name);
@@ -252,7 +255,11 @@ static void start_test(struct ldb_context *ldb, int nrecords, int nsearches)
{
struct ldb_dn *basedn;
- basedn = ldb_dn_explode(ldb, options->basedn);
+ 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));
diff --git a/source4/lib/ldb/tools/oLschema2ldif.c b/source4/lib/ldb/tools/oLschema2ldif.c
index a9e157e323..7863f5dcb7 100644
--- a/source4/lib/ldb/tools/oLschema2ldif.c
+++ b/source4/lib/ldb/tools/oLschema2ldif.c
@@ -388,9 +388,8 @@ static struct ldb_message *process_entry(TALLOC_CTX *mem_ctx, const char *entry)
MSG_ADD_STRING("cn", token->value);
MSG_ADD_STRING("name", token->value);
MSG_ADD_STRING("lDAPDisplayName", token->value);
- msg->dn = ldb_dn_string_compose(msg, basedn,
- "CN=%s,CN=Schema,CN=Configuration",
- token->value);
+ msg->dn = ldb_dn_copy(msg, basedn);
+ ldb_dn_add_child_fmt(msg->dn, "CN=%s,CN=Schema,CN=Configuration", token->value);
break;
case SCHEMA_SUP:
@@ -575,8 +574,8 @@ static void usage(void)
perror("Base DN not specified");
exit(1);
} else {
- basedn = ldb_dn_explode(ctx, options->basedn);
- if (basedn == NULL) {
+ basedn = ldb_dn_new(ctx, ldb_ctx, options->basedn);
+ if ( ! ldb_dn_validate(basedn)) {
perror("Malformed Base DN");
exit(1);
}