From 809c74790006c985ac64eb7823a4a450498c832f Mon Sep 17 00:00:00 2001 From: Matthias Dieter Wallnöfer Date: Thu, 24 Jun 2010 21:12:19 +0200 Subject: 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. --- source4/lib/registry/ldb.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'source4/lib/registry') 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; } -- cgit