diff options
author | Simo Sorce <idra@samba.org> | 2006-11-22 00:59:34 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:28:22 -0500 |
commit | 4889eb9f7aae9349e426d0f6d2217adff67eaebd (patch) | |
tree | 7eb63c32bcbd19bf64d5c315f01785f30d3a789c /source4/lib/registry | |
parent | ce0c2236b953dc977655dbceef40916825e843ae (diff) | |
download | samba-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/registry')
-rw-r--r-- | source4/lib/registry/reg_backend_ldb.c | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/source4/lib/registry/reg_backend_ldb.c b/source4/lib/registry/reg_backend_ldb.c index b9bfe8a230..5f9481fa67 100644 --- a/source4/lib/registry/reg_backend_ldb.c +++ b/source4/lib/registry/reg_backend_ldb.c @@ -27,7 +27,7 @@ struct ldb_key_data { - const struct ldb_dn *dn; + struct ldb_dn *dn; struct ldb_message **subkeys, **values; int subkey_count, value_count; }; @@ -115,15 +115,24 @@ static int reg_close_ldb_key(struct registry_key *key) static struct ldb_dn *reg_path_to_ldb(TALLOC_CTX *mem_ctx, const struct registry_key *from, const char *path, const char *add) { TALLOC_CTX *local_ctx; - struct ldb_dn *ret = ldb_dn_new(mem_ctx); + struct ldb_dn *ret; char *mypath = talloc_strdup(mem_ctx, path); char *begin; struct ldb_key_data *kd = talloc_get_type(from->backend_data, struct ldb_key_data); + struct ldb_context *ldb = talloc_get_type(from->hive->backend_data, struct ldb_context); local_ctx = talloc_new(mem_ctx); - if (add) - ret = ldb_dn_compose(local_ctx, ret, ldb_dn_explode(mem_ctx, add)); + if (add) { + ret = ldb_dn_new(mem_ctx, ldb, add); + } else { + ret = ldb_dn_new(mem_ctx, ldb, NULL); + } + if ( ! ldb_dn_validate(ret)) { + talloc_free(ret); + talloc_free(local_ctx); + return NULL; + } while(mypath) { char *keyname; @@ -134,10 +143,7 @@ static struct ldb_dn *reg_path_to_ldb(TALLOC_CTX *mem_ctx, const struct registry else keyname = mypath; if(strlen(keyname)) { - struct ldb_dn *base; - - base = ldb_dn_build_child(local_ctx, "key", keyname, NULL); - ret = ldb_dn_compose(local_ctx, ret, base); + ldb_dn_add_base_fmt(ret, "key=%s", keyname); } if(begin) { @@ -147,7 +153,7 @@ static struct ldb_dn *reg_path_to_ldb(TALLOC_CTX *mem_ctx, const struct registry } } - ret = ldb_dn_compose(mem_ctx, ret, kd->dn); + ldb_dn_add_base(ret, kd->dn); talloc_free(local_ctx); @@ -277,7 +283,7 @@ static WERROR ldb_open_hive(struct registry_hive *hive, struct registry_key **k) talloc_set_destructor (hive, ldb_free_hive); (*k)->name = talloc_strdup(*k, ""); (*k)->backend_data = kd = talloc_zero(*k, struct ldb_key_data); - kd->dn = ldb_dn_explode(*k, "hive=NONE"); + kd->dn = ldb_dn_new(*k, wrap, "hive=NONE"); return WERR_OK; @@ -316,7 +322,10 @@ static WERROR ldb_del_key (const struct registry_key *key, const char *child) struct ldb_context *ctx = talloc_get_type(key->hive->backend_data, struct ldb_context); int ret; struct ldb_key_data *kd = talloc_get_type(key->backend_data, struct ldb_key_data); - struct ldb_dn *childdn = ldb_dn_build_child(ctx, "key", child, kd->dn); + struct ldb_dn *childdn; + + childdn = ldb_dn_copy(ctx, kd->dn); + ldb_dn_add_child_fmt(childdn, "key=%s", child); ret = ldb_delete(ctx, childdn); @@ -335,7 +344,10 @@ static WERROR ldb_del_value (const struct registry_key *key, const char *child) int ret; struct ldb_context *ctx = talloc_get_type(key->hive->backend_data, struct ldb_context); struct ldb_key_data *kd = talloc_get_type(key->backend_data, struct ldb_key_data); - struct ldb_dn *childdn = ldb_dn_build_child(ctx, "value", child, kd->dn); + struct ldb_dn *childdn; + + childdn = ldb_dn_copy(ctx, kd->dn); + ldb_dn_add_child_fmt(childdn, "value=%s", child); ret = ldb_delete(ctx, childdn); @@ -359,7 +371,8 @@ static WERROR ldb_set_value (const struct registry_key *parent, const char *name msg = reg_ldb_pack_value(ctx, mem_ctx, name, type, data); - msg->dn = ldb_dn_build_child(msg, "value", name, kd->dn); + msg->dn = ldb_dn_copy(msg, kd->dn); + ldb_dn_add_child_fmt(msg->dn, "value=%s", name); ret = ldb_add(ctx, msg); if (ret < 0) { |