diff options
author | Michael Adam <obnox@samba.org> | 2011-07-01 15:47:50 +0200 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2011-07-04 20:02:08 +0200 |
commit | 322eaf1e9ef927bdec7fca947e894470196c1049 (patch) | |
tree | 6c0c3db61e00826d50a41206ff0a81c069e54cf0 | |
parent | 394ca1446e712c9cb3649c8a2c4fd2ebe638d8cd (diff) | |
download | samba-322eaf1e9ef927bdec7fca947e894470196c1049.tar.gz samba-322eaf1e9ef927bdec7fca947e894470196c1049.tar.bz2 samba-322eaf1e9ef927bdec7fca947e894470196c1049.zip |
s3:registry: refactor creation of subkey list out into regdb_store_subkey_list()
Pair-Programmed-With: Gregor Beck <gbeck@sernet.de>
-rw-r--r-- | source3/registry/reg_backend_db.c | 74 |
1 files changed, 52 insertions, 22 deletions
diff --git a/source3/registry/reg_backend_db.c b/source3/registry/reg_backend_db.c index 9d33f2cf9d..554114d6eb 100644 --- a/source3/registry/reg_backend_db.c +++ b/source3/registry/reg_backend_db.c @@ -854,6 +854,53 @@ done: return werr; } +/** + * Utility function to store a new empty list of + * subkeys of given key specified as parent and subkey name + * (thereby creating the key). + * If the subkey list does already exist, it is not modified. + * + * Must be called from within a transaction. + */ +static WERROR regdb_store_subkey_list(struct db_context *db, const char *parent, + const char *key) +{ + WERROR werr; + char *path = NULL; + struct regsubkey_ctr *subkeys = NULL; + TALLOC_CTX *frame = talloc_stackframe(); + + path = talloc_asprintf(frame, "%s\\%s", parent, key); + if (!path) { + werr = WERR_NOMEM; + goto done; + } + + werr = regsubkey_ctr_init(frame, &subkeys); + W_ERROR_NOT_OK_GOTO_DONE(werr); + + werr = regdb_fetch_keys_internal(db, path, subkeys); + if (W_ERROR_IS_OK(werr)) { + /* subkey list exists already - don't modify */ + goto done; + } + + werr = regsubkey_ctr_reinit(subkeys); + W_ERROR_NOT_OK_GOTO_DONE(werr); + + /* create a record with 0 subkeys */ + werr = regdb_store_keys_internal2(db, path, subkeys); + if (!W_ERROR_IS_OK(werr)) { + DEBUG(0, ("regdb_store_keys: Failed to store new record for " + "key [%s]: %s\n", path, win_errstr(werr))); + goto done; + } + +done: + talloc_free(frame); + return werr; +} + /*********************************************************************** Store the new subkey record and create any child key records that do not currently exist @@ -871,7 +918,7 @@ static NTSTATUS regdb_store_keys_action(struct db_context *db, WERROR werr; int num_subkeys, i; char *path = NULL; - struct regsubkey_ctr *subkeys = NULL, *old_subkeys = NULL; + struct regsubkey_ctr *old_subkeys = NULL; char *oldkeyname = NULL; TALLOC_CTX *mem_ctx = talloc_stackframe(); @@ -955,29 +1002,12 @@ static NTSTATUS regdb_store_keys_action(struct db_context *db, num_subkeys = regsubkey_ctr_numkeys(store_ctx->ctr); for (i=0; i<num_subkeys; i++) { - path = talloc_asprintf(mem_ctx, "%s\\%s", store_ctx->key, - regsubkey_ctr_specific_key(store_ctx->ctr, i)); - if (!path) { - werr = WERR_NOMEM; - goto done; - } - werr = regsubkey_ctr_init(mem_ctx, &subkeys); - W_ERROR_NOT_OK_GOTO_DONE(werr); + const char *subkey; - werr = regdb_fetch_keys_internal(db, path, subkeys); - if (!W_ERROR_IS_OK(werr)) { - /* create a record with 0 subkeys */ - werr = regdb_store_keys_internal2(db, path, subkeys); - if (!W_ERROR_IS_OK(werr)) { - DEBUG(0,("regdb_store_keys: Failed to store " - "new record for key [%s]: %s\n", path, - win_errstr(werr))); - goto done; - } - } + subkey = regsubkey_ctr_specific_key(store_ctx->ctr, i); - TALLOC_FREE(subkeys); - TALLOC_FREE(path); + werr = regdb_store_subkey_list(db, store_ctx->key, subkey); + W_ERROR_NOT_OK_GOTO_DONE(werr); } werr = WERR_OK; |