s3:registry: use transaction wrapper in regdb_create_subkey()
authorMichael Adam <obnox@samba.org>
Thu, 9 Jul 2009 08:41:59 +0000 (10:41 +0200)
committerMichael Adam <obnox@samba.org>
Wed, 15 Jul 2009 12:01:54 +0000 (14:01 +0200)
Michael

source3/registry/reg_backend_db.c

index 5c714a40b46f7c36b078121685b929d715e8fd0c..08d72c32158616a2dee6c374862d071ed0e9b608 100644 (file)
@@ -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);