summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorMatthias Dieter Wallnöfer <mdw@samba.org>2010-06-24 21:12:19 +0200
committerMatthias Dieter Wallnöfer <mdw@samba.org>2010-07-01 15:48:04 +0200
commit809c74790006c985ac64eb7823a4a450498c832f (patch)
tree20e808bca1a023aa605222163b1cfb236923b8c7 /source4
parent50ae292e60e53275f87ad2281b25eda34d0af59c (diff)
downloadsamba-809c74790006c985ac64eb7823a4a450498c832f.tar.gz
samba-809c74790006c985ac64eb7823a4a450498c832f.tar.bz2
samba-809c74790006c985ac64eb7823a4a450498c832f.zip
s4:lib/registry/ldb.c - refactor "reg_path_to_ldb"
This makes it easier to understand and would also support splitting in more DN components.
Diffstat (limited to 'source4')
-rw-r--r--source4/lib/registry/ldb.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/source4/lib/registry/ldb.c b/source4/lib/registry/ldb.c
index 541d658444..b4eae9a341 100644
--- a/source4/lib/registry/ldb.c
+++ b/source4/lib/registry/ldb.c
@@ -277,44 +277,46 @@ static struct ldb_dn *reg_path_to_ldb(TALLOC_CTX *mem_ctx,
const char *path, const char *add)
{
struct ldb_dn *ret;
- char *mypath = talloc_strdup(mem_ctx, path);
+ char *mypath;
char *begin;
struct ldb_key_data *kd = talloc_get_type(from, struct ldb_key_data);
struct ldb_context *ldb = kd->ldb;
+ mypath = talloc_strdup(mem_ctx, path);
+ if (mypath == NULL) {
+ return NULL;
+ }
+
ret = ldb_dn_new(mem_ctx, ldb, add);
if (!ldb_dn_validate(ret)) {
talloc_free(ret);
return NULL;
}
- while (mypath) {
- char *keyname;
-
- begin = strrchr(mypath, '\\');
+ if (!ldb_dn_add_base(ret, kd->dn)) {
+ talloc_free(ret);
+ return NULL;
+ }
- if (begin) keyname = begin + 1;
- else keyname = mypath;
+ while (mypath[0] != '\0') {
+ begin = strchr(mypath, '\\');
+ if (begin != NULL) {
+ *begin = '\0';
+ }
- if (keyname[0] != '\0') {
- if (!ldb_dn_add_base_fmt(ret, "key=%s",
- reg_ldb_escape(mem_ctx,
- keyname)))
- {
- talloc_free(ret);
- return NULL;
- }
+ if (!ldb_dn_add_child_fmt(ret, "key=%s",
+ reg_ldb_escape(mem_ctx, mypath))) {
+ talloc_free(ret);
+ return NULL;
}
- if(begin) {
- *begin = '\0';
+ if (begin != NULL) {
+ mypath = begin + 1;
} else {
break;
}
}
- ldb_dn_add_base(ret, kd->dn);
-
return ret;
}