summaryrefslogtreecommitdiff
path: root/source3/registry
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2008-03-20 13:59:09 +0100
committerMichael Adam <obnox@samba.org>2008-03-20 15:01:51 +0100
commit1f3139df25112c8c9a99aa14c7cc5d0f9a6b6cf5 (patch)
treecd6e1cce0621a7b27bad280fba035d925afef829 /source3/registry
parent12b9b5621aa78d9216e83a6dd029be8af62fca71 (diff)
downloadsamba-1f3139df25112c8c9a99aa14c7cc5d0f9a6b6cf5.tar.gz
samba-1f3139df25112c8c9a99aa14c7cc5d0f9a6b6cf5.tar.bz2
samba-1f3139df25112c8c9a99aa14c7cc5d0f9a6b6cf5.zip
registry: refactor creation of subkeys out of init_registry_data().
Michael (This used to be commit 55233f875ebe1d515c65d9322cda69eb52d4c7d5)
Diffstat (limited to 'source3/registry')
-rw-r--r--source3/registry/reg_backend_db.c171
1 files changed, 92 insertions, 79 deletions
diff --git a/source3/registry/reg_backend_db.c b/source3/registry/reg_backend_db.c
index 07aaf68d50..fc7d2bc2cf 100644
--- a/source3/registry/reg_backend_db.c
+++ b/source3/registry/reg_backend_db.c
@@ -87,115 +87,128 @@ static struct builtin_regkey_value builtin_registry_values[] = {
{ NULL, NULL, 0, { NULL } }
};
-/***********************************************************************
- Open the registry data in the tdb
- ***********************************************************************/
-
-static bool init_registry_data(void)
+/**
+ * Initialize a key in the registry:
+ * create each component key of the specified path.
+ */
+static bool init_registry_key_internal(const char *add_path)
{
+ bool ret = false;
+ TALLOC_CTX *frame = talloc_stackframe();
char *path = NULL;
char *base = NULL;
char *remaining = NULL;
- TALLOC_CTX *frame = NULL;
char *keyname;
char *subkeyname;
REGSUBKEY_CTR *subkeys;
- REGVAL_CTR *values;
- int i;
const char *p, *p2;
- UNISTR2 data;
- /*
- * There are potentially quite a few store operations which are all
- * indiviually wrapped in tdb transactions. Wrapping them in a single
- * transaction gives just a single transaction_commit() to actually do
- * its fsync()s. See tdb/common/transaction.c for info about nested
- * transaction behaviour.
- */
+ DEBUG(6, ("init_registry_key: Adding [%s]\n", add_path));
- if (regdb->transaction_start(regdb) == -1) {
- DEBUG(0, ("init_registry_data: tdb_transaction_start "
- "failed\n"));
- return false;
+ path = talloc_strdup(frame, add_path);
+ base = talloc_strdup(frame, "");
+ if (!path || !base) {
+ goto fail;
}
+ p = path;
- /* loop over all of the predefined paths and add each component */
-
- for (i=0; builtin_registry_paths[i] != NULL; i++) {
-
- frame = talloc_stackframe();
+ while (next_token_talloc(frame, &p, &keyname, "\\")) {
- DEBUG(6, ("init_registry_data: Adding [%s]\n",
- builtin_registry_paths[i]));
+ /* build up the registry path from the components */
- path = talloc_strdup(frame, builtin_registry_paths[i]);
- base = talloc_strdup(frame, "");
- if (!path || !base) {
- goto fail;
- }
- p = path;
-
- while (next_token_talloc(frame, &p, &keyname, "\\")) {
-
- /* build up the registry path from the components */
-
- if (*base) {
- base = talloc_asprintf(frame, "%s\\", base);
- if (!base) {
- goto fail;
- }
- }
- base = talloc_asprintf_append(base, "%s", keyname);
+ if (*base) {
+ base = talloc_asprintf(frame, "%s\\", base);
if (!base) {
goto fail;
}
+ }
+ base = talloc_asprintf_append(base, "%s", keyname);
+ if (!base) {
+ goto fail;
+ }
- /* get the immediate subkeyname (if we have one ) */
+ /* get the immediate subkeyname (if we have one ) */
- subkeyname = talloc_strdup(frame, "");
- if (!subkeyname) {
+ subkeyname = talloc_strdup(frame, "");
+ if (!subkeyname) {
+ goto fail;
+ }
+ if (*p) {
+ remaining = talloc_strdup(frame, p);
+ if (!remaining) {
goto fail;
}
- if (*p) {
- remaining = talloc_strdup(frame, p);
- if (!remaining) {
+ p2 = remaining;
+
+ if (!next_token_talloc(frame, &p2,
+ &subkeyname, "\\"))
+ {
+ subkeyname = talloc_strdup(frame,p2);
+ if (!subkeyname) {
goto fail;
}
- p2 = remaining;
-
- if (!next_token_talloc(frame, &p2,
- &subkeyname, "\\"))
- {
- subkeyname = talloc_strdup(frame,p2);
- if (!subkeyname) {
- goto fail;
- }
- }
}
+ }
- DEBUG(10,("init_registry_data: Storing key [%s] with "
- "subkey [%s]\n", base,
- *subkeyname ? subkeyname : "NULL"));
+ DEBUG(10,("init_registry_key: Storing key [%s] with "
+ "subkey [%s]\n", base,
+ *subkeyname ? subkeyname : "NULL"));
- /* 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 */
+ /* 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 */
- if (!(subkeys = TALLOC_ZERO_P(frame, REGSUBKEY_CTR))) {
- DEBUG(0,("talloc() failure!\n"));
- goto fail;
- }
+ if (!(subkeys = TALLOC_ZERO_P(frame, REGSUBKEY_CTR))) {
+ DEBUG(0,("talloc() failure!\n"));
+ goto fail;
+ }
- regdb_fetch_keys(base, subkeys);
- if (*subkeyname) {
- regsubkey_ctr_addkey( subkeys, subkeyname);
- }
- if (!regdb_store_keys( base, subkeys)) {
- goto fail;
- }
+ regdb_fetch_keys(base, subkeys);
+ if (*subkeyname) {
+ regsubkey_ctr_addkey( subkeys, subkeyname);
}
+ if (!regdb_store_keys( base, subkeys)) {
+ goto fail;
+ }
+ }
+
+ ret = true;
+fail:
+ TALLOC_FREE(frame);
+ return ret;
+}
+
+/***********************************************************************
+ Open the registry data in the tdb
+ ***********************************************************************/
+
+static bool init_registry_data(void)
+{
+ TALLOC_CTX *frame = NULL;
+ REGVAL_CTR *values;
+ int i;
+ UNISTR2 data;
+
+ /*
+ * There are potentially quite a few store operations which are all
+ * indiviually wrapped in tdb transactions. Wrapping them in a single
+ * transaction gives just a single transaction_commit() to actually do
+ * its fsync()s. See tdb/common/transaction.c for info about nested
+ * transaction behaviour.
+ */
- TALLOC_FREE(frame);
+ if (regdb->transaction_start(regdb) == -1) {
+ DEBUG(0, ("init_registry_data: tdb_transaction_start "
+ "failed\n"));
+ return false;
+ }
+
+ /* loop over all of the predefined paths and add each component */
+
+ for (i=0; builtin_registry_paths[i] != NULL; i++) {
+ if (!init_registry_key_internal(builtin_registry_paths[i])) {
+ goto fail;
+ }
}
/* loop over all of the predefined values and add each component */