summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2011-07-04 13:19:13 +0200
committerMichael Adam <obnox@samba.org>2011-07-04 20:02:08 +0200
commit9e2b2c1fcc6d0bd852df715fdae7854b3ae77027 (patch)
tree94cf9585aab4f764163cfca4e8849c810d3797d7 /source3
parent747c67cf309a5127e78bd78f0d17e3fc094115d2 (diff)
downloadsamba-9e2b2c1fcc6d0bd852df715fdae7854b3ae77027.tar.gz
samba-9e2b2c1fcc6d0bd852df715fdae7854b3ae77027.tar.bz2
samba-9e2b2c1fcc6d0bd852df715fdae7854b3ae77027.zip
s3:registry: rewrite init_registry_key_internal
This rewrites init_registry_key_internal() to correctly also create base keys. It makes use of the existing create functions instead of duplicating the code. Pair-Programmed-With: Gregor Beck <gbeck@sernet.de>
Diffstat (limited to 'source3')
-rw-r--r--source3/registry/reg_backend_db.c142
1 files changed, 52 insertions, 90 deletions
diff --git a/source3/registry/reg_backend_db.c b/source3/registry/reg_backend_db.c
index e5386f7d91..d1ca9f2603 100644
--- a/source3/registry/reg_backend_db.c
+++ b/source3/registry/reg_backend_db.c
@@ -51,6 +51,9 @@ static bool regdb_store_values_internal(struct db_context *db, const char *key,
static NTSTATUS create_sorted_subkeys(const char *key);
static WERROR regdb_create_basekey(struct db_context *db, const char *key);
+static WERROR regdb_create_subkey_internal(struct db_context *db,
+ const char *key,
+ const char *subkey);
/* List the deepest path into the registry. All part components will be created.*/
@@ -115,113 +118,72 @@ static struct builtin_regkey_value builtin_registry_values[] = {
{ NULL, NULL, 0, { NULL } }
};
-/**
- * Initialize a key in the registry:
- * create each component key of the specified path.
- */
-static WERROR init_registry_key_internal(struct db_context *db,
- const char *add_path)
+static WERROR create_key_recursive(struct db_context *db,
+ char *path,
+ const char *subkey)
{
WERROR werr;
- TALLOC_CTX *frame = talloc_stackframe();
- char *path = NULL;
- char *base = NULL;
- char *remaining = NULL;
- char *keyname;
- char *subkeyname;
- struct regsubkey_ctr *subkeys;
- const char *p, *p2;
-
- DEBUG(6, ("init_registry_key: Adding [%s]\n", add_path));
+ char *p;
- path = talloc_strdup(frame, add_path);
- base = talloc_strdup(frame, "");
- if (!path || !base) {
- werr = WERR_NOMEM;
- goto fail;
+ if (subkey == NULL) {
+ return WERR_INVALID_PARAM;
}
- p = path;
- while (next_token_talloc(frame, &p, &keyname, "\\")) {
+ if (path == NULL) {
+ return regdb_create_basekey(db, subkey);
+ }
- /* build up the registry path from the components */
+ p = strrchr_m(path, '\\');
- if (*base) {
- base = talloc_asprintf(frame, "%s\\", base);
- if (!base) {
- werr = WERR_NOMEM;
- goto fail;
- }
- }
- base = talloc_asprintf_append(base, "%s", keyname);
- if (!base) {
- werr = WERR_NOMEM;
- goto fail;
- }
-
- /* get the immediate subkeyname (if we have one ) */
+ if (p == NULL) {
+ werr = create_key_recursive(db, NULL, path);
+ } else {
+ *p = '\0';
+ werr = create_key_recursive(db, path, p+1);
+ *p = '\\';
+ }
- subkeyname = talloc_strdup(frame, "");
- if (!subkeyname) {
- werr = WERR_NOMEM;
- goto fail;
- }
- if (*p) {
- remaining = talloc_strdup(frame, p);
- if (!remaining) {
- werr = WERR_NOMEM;
- goto fail;
- }
- p2 = remaining;
+ if (!W_ERROR_IS_OK(werr)) {
+ goto done;
+ }
- if (!next_token_talloc(frame, &p2,
- &subkeyname, "\\"))
- {
- subkeyname = talloc_strdup(frame,p2);
- if (!subkeyname) {
- werr = WERR_NOMEM;
- goto fail;
- }
- }
- }
+ werr = regdb_create_subkey_internal(db, path, subkey);
- DEBUG(10,("init_registry_key: Storing key [%s] with "
- "subkey [%s]\n", base,
- *subkeyname ? subkeyname : "NULL"));
+done:
+ return werr;
+}
- /* we don't really care if the lookup succeeds or not
- * since we are about to update the record.
- * We just want any subkeys already present */
+/**
+ * Initialize a key in the registry:
+ * create each component key of the specified path.
+ */
+static WERROR init_registry_key_internal(struct db_context *db,
+ const char *add_path)
+{
+ char *subkey, *key;
+ WERROR werr;
+ TALLOC_CTX *frame = talloc_stackframe();
- werr = regsubkey_ctr_init(frame, &subkeys);
- if (!W_ERROR_IS_OK(werr)) {
- DEBUG(0,("talloc() failure!\n"));
- goto fail;
- }
+ if (add_path == NULL) {
+ werr = WERR_INVALID_PARAM;
+ goto done;
+ }
- werr = regdb_fetch_keys_internal(db, base, subkeys);
- if (!W_ERROR_IS_OK(werr) &&
- !W_ERROR_EQUAL(werr, WERR_NOT_FOUND))
- {
- goto fail;
- }
+ key = talloc_strdup(frame, add_path);
- if (*subkeyname) {
- werr = regsubkey_ctr_addkey(subkeys, subkeyname);
- if (!W_ERROR_IS_OK(werr)) {
- goto fail;
- }
- }
- if (!regdb_store_keys_internal(db, base, subkeys)) {
- werr = WERR_CAN_NOT_COMPLETE;
- goto fail;
- }
+ subkey = strrchr_m(key, '\\');
+ if (subkey == NULL) {
+ subkey = key;
+ key = NULL;
+ } else {
+ *subkey = '\0';
+ subkey++;
}
- werr = WERR_OK;
+ werr = create_key_recursive(db, key, subkey);
-fail:
- TALLOC_FREE(frame);
+done:
+ talloc_free(frame);
return werr;
}