diff options
author | Michael Adam <obnox@samba.org> | 2009-07-09 10:41:59 +0200 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2009-07-15 14:01:54 +0200 |
commit | 8c7b9604931a787107bc01b359a231d376ed92c0 (patch) | |
tree | ab09e4d978ffe6a4be05b57cfb051a9052a3b8cc /source3 | |
parent | 86d747e19f877c45ac32663ec2a3381ad03cdcf5 (diff) | |
download | samba-8c7b9604931a787107bc01b359a231d376ed92c0.tar.gz samba-8c7b9604931a787107bc01b359a231d376ed92c0.tar.bz2 samba-8c7b9604931a787107bc01b359a231d376ed92c0.zip |
s3:registry: use transaction wrapper in regdb_create_subkey()
Michael
Diffstat (limited to 'source3')
-rw-r--r-- | source3/registry/reg_backend_db.c | 73 |
1 files changed, 42 insertions, 31 deletions
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); |