summaryrefslogtreecommitdiff
path: root/source3/registry
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2012-04-12 22:17:35 +0200
committerAndreas Schneider <asn@samba.org>2012-04-25 14:31:10 +0200
commit32ac4f4b34dd2788498f0c09c946532165d6af74 (patch)
tree9fa76681175a8e4b5c97dcac420df954bc6e884f /source3/registry
parent1af68be008a11bffdf78d70c8d1635003a3c4407 (diff)
downloadsamba-32ac4f4b34dd2788498f0c09c946532165d6af74.tar.gz
samba-32ac4f4b34dd2788498f0c09c946532165d6af74.tar.bz2
samba-32ac4f4b34dd2788498f0c09c946532165d6af74.zip
s3:registry: wrap reg_createkey() in a transaction
This is wrong layering (calling into regdb_transaction* in the reg_api code) but fixes a potential race. It makes the multi-step create procedure atomic. This should completely be done in the backend. Signed-off-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'source3/registry')
-rw-r--r--source3/registry/reg_api.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/source3/registry/reg_api.c b/source3/registry/reg_api.c
index 3d051b3f2d..405a10591c 100644
--- a/source3/registry/reg_api.c
+++ b/source3/registry/reg_api.c
@@ -580,6 +580,13 @@ WERROR reg_createkey(TALLOC_CTX *ctx, struct registry_key *parent,
goto done;
}
+ err = regdb_transaction_start();
+ if (!W_ERROR_IS_OK(err)) {
+ DEBUG(0, ("reg_createkey: failed to start transaction: %s\n",
+ win_errstr(err)));
+ goto done;
+ }
+
while ((end = strchr(path, '\\')) != NULL) {
struct registry_key *tmp;
enum winreg_CreateAction action;
@@ -589,7 +596,7 @@ WERROR reg_createkey(TALLOC_CTX *ctx, struct registry_key *parent,
err = reg_createkey(mem_ctx, key, path,
KEY_ENUMERATE_SUB_KEYS, &tmp, &action);
if (!W_ERROR_IS_OK(err)) {
- goto done;
+ goto trans_done;
}
if (key != parent) {
@@ -610,14 +617,14 @@ WERROR reg_createkey(TALLOC_CTX *ctx, struct registry_key *parent,
if (paction != NULL) {
*paction = REG_OPENED_EXISTING_KEY;
}
- goto done;
+ goto trans_done;
}
if (!W_ERROR_EQUAL(err, WERR_BADFILE)) {
/*
* Something but "notfound" has happened, so bail out
*/
- goto done;
+ goto trans_done;
}
/*
@@ -628,7 +635,7 @@ WERROR reg_createkey(TALLOC_CTX *ctx, struct registry_key *parent,
err = reg_openkey(mem_ctx, key, "", KEY_CREATE_SUB_KEY,
&create_parent);
if (!W_ERROR_IS_OK(err)) {
- goto done;
+ goto trans_done;
}
/*
@@ -636,10 +643,14 @@ WERROR reg_createkey(TALLOC_CTX *ctx, struct registry_key *parent,
*/
err = fill_subkey_cache(create_parent);
- if (!W_ERROR_IS_OK(err)) goto done;
+ if (!W_ERROR_IS_OK(err)) {
+ goto trans_done;
+ }
err = create_reg_subkey(key->key, path);
- W_ERROR_NOT_OK_GOTO_DONE(err);
+ if (!W_ERROR_IS_OK(err)) {
+ goto trans_done;
+ }
/*
* Now open the newly created key
@@ -650,6 +661,19 @@ WERROR reg_createkey(TALLOC_CTX *ctx, struct registry_key *parent,
*paction = REG_CREATED_NEW_KEY;
}
+trans_done:
+ if (W_ERROR_IS_OK(err)) {
+ err = regdb_transaction_commit();
+ if (!W_ERROR_IS_OK(err)) {
+ DEBUG(0, ("reg_createkey: Error committing transaction: %s\n", win_errstr(err)));
+ }
+ } else {
+ WERROR err1 = regdb_transaction_cancel();
+ if (!W_ERROR_IS_OK(err1)) {
+ DEBUG(0, ("reg_createkey: Error cancelling transaction: %s\n", win_errstr(err1)));
+ }
+ }
+
done:
TALLOC_FREE(mem_ctx);
return err;