From 8c7b9604931a787107bc01b359a231d376ed92c0 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 9 Jul 2009 10:41:59 +0200 Subject: s3:registry: use transaction wrapper in regdb_create_subkey() Michael --- source3/registry/reg_backend_db.c | 73 ++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 31 deletions(-) (limited to 'source3') diff --git a/source3/registry/reg_backend_db.c b/source3/registry/reg_backend_db.c index 5c714a40b4..08d72c3215 100644 --- a/source3/registry/reg_backend_db.c +++ b/source3/registry/reg_backend_db.c @@ -934,66 +934,77 @@ bool regdb_store_keys(const char *key, struct regsubkey_ctr *ctr) return regdb_store_keys_internal(regdb, key, ctr); } -static WERROR regdb_create_subkey(const char *key, const char *subkey) +struct regdb_create_subkey_context { + const char *key; + const char *subkey; +}; + +static NTSTATUS regdb_create_subkey_action(struct db_context *db, + void *private_data) { WERROR werr; + struct regdb_create_subkey_context *create_ctx; struct regsubkey_ctr *subkeys; TALLOC_CTX *mem_ctx = talloc_stackframe(); - if (!regdb_key_is_base_key(key) && !regdb_key_exists(regdb, key)) { - werr = WERR_NOT_FOUND; - goto done; - } + create_ctx = (struct regdb_create_subkey_context *)private_data; werr = regsubkey_ctr_init(mem_ctx, &subkeys); W_ERROR_NOT_OK_GOTO_DONE(werr); - if (regdb_fetch_keys_internal(regdb, key, subkeys) < 0) { + if (regdb_fetch_keys_internal(db, create_ctx->key, subkeys) < 0) { werr = WERR_REG_IO_FAILURE; goto done; } - if (regsubkey_ctr_key_exists(subkeys, subkey)) { - werr = WERR_OK; - goto done; + werr = regsubkey_ctr_addkey(subkeys, create_ctx->subkey); + W_ERROR_NOT_OK_GOTO_DONE(werr); + + werr = regdb_store_keys_internal2(db, create_ctx->key, subkeys); + if (!W_ERROR_IS_OK(werr)) { + DEBUG(0, (__location__ " failed to store new subkey list for " + "parent key %s: %s\n", create_ctx->key, + win_errstr(werr))); } - talloc_free(subkeys); +done: + talloc_free(mem_ctx); + return werror_to_ntstatus(werr); +} - if (regdb->transaction_start(regdb) != 0) { - werr = WERR_REG_IO_FAILURE; +static WERROR regdb_create_subkey(const char *key, const char *subkey) +{ + WERROR werr; + struct regsubkey_ctr *subkeys; + TALLOC_CTX *mem_ctx = talloc_stackframe(); + struct regdb_create_subkey_context create_ctx; + + if (!regdb_key_is_base_key(key) && !regdb_key_exists(regdb, key)) { + werr = WERR_NOT_FOUND; goto done; } werr = regsubkey_ctr_init(mem_ctx, &subkeys); - W_ERROR_NOT_OK_GOTO(werr, cancel); + W_ERROR_NOT_OK_GOTO_DONE(werr); if (regdb_fetch_keys_internal(regdb, key, subkeys) < 0) { werr = WERR_REG_IO_FAILURE; - goto cancel; + goto done; } - werr = regsubkey_ctr_addkey(subkeys, subkey); - W_ERROR_NOT_OK_GOTO(werr, cancel); - - werr = regdb_store_keys_internal2(regdb, key, subkeys); - if (!W_ERROR_IS_OK(werr)) { - DEBUG(0, (__location__ " failed to store new subkey list for " - "parent key %s: %s\n", key, win_errstr(werr))); - goto cancel; + if (regsubkey_ctr_key_exists(subkeys, subkey)) { + werr = WERR_OK; + goto done; } - if (regdb->transaction_commit(regdb) != 0) { - werr = WERR_REG_IO_FAILURE; - DEBUG(0, (__location__ " failed to commit transaction\n")); - } + talloc_free(subkeys); - goto done; + create_ctx.key = key; + create_ctx.subkey = subkey; -cancel: - if (regdb->transaction_cancel(regdb) != 0) { - smb_panic("regdb_create_subkey: transaction_cancel failed\n"); - } + werr = ntstatus_to_werror(dbwrap_trans_do(regdb, + regdb_create_subkey_action, + &create_ctx)); done: talloc_free(mem_ctx); -- cgit