diff options
author | Michael Adam <obnox@samba.org> | 2011-08-29 17:06:27 +0200 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2011-09-01 23:18:18 +0200 |
commit | 9352a95bfda2d1a3255d8ad158af0fcef442b53e (patch) | |
tree | bd3fa9cd8295d4857e5eff72a281fd2e4f895288 /source3 | |
parent | 5ef11737bc8e32446f3819df17af4ae0e93270a0 (diff) | |
download | samba-9352a95bfda2d1a3255d8ad158af0fcef442b53e.tar.gz samba-9352a95bfda2d1a3255d8ad158af0fcef442b53e.tar.bz2 samba-9352a95bfda2d1a3255d8ad158af0fcef442b53e.zip |
s3:registry: add regdb_trans_do(): a transaction wrapper that will check the regdb version
If the version has changed since initialization, the write will
fail with ACCESS_DENIED.
Diffstat (limited to 'source3')
-rw-r--r-- | source3/registry/reg_backend_db.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/source3/registry/reg_backend_db.c b/source3/registry/reg_backend_db.c index f3a0e1d0d7..821ed6b386 100644 --- a/source3/registry/reg_backend_db.c +++ b/source3/registry/reg_backend_db.c @@ -59,6 +59,48 @@ static WERROR regdb_create_subkey_internal(struct db_context *db, const char *key, const char *subkey); + +struct regdb_trans_ctx { + NTSTATUS (*action)(struct db_context *, void *); + void *private_data; +}; + +static NTSTATUS regdb_trans_do_action(struct db_context *db, void *private_data) +{ + NTSTATUS status; + int32_t version_id; + struct regdb_trans_ctx *ctx = (struct regdb_trans_ctx *)private_data; + + version_id = dbwrap_fetch_int32(db, REGDB_VERSION_KEYNAME); + + if (version_id != REGVER_V3) { + DEBUG(0, ("ERROR: changed registry version %d found while " + "trying to write to the registry. Version %d " + "expected. Denying access.\n", + version_id, REGVER_V3)); + return NT_STATUS_ACCESS_DENIED; + } + + status = ctx->action(db, ctx->private_data); + return status; +} + +static WERROR regdb_trans_do(struct db_context *db, + NTSTATUS (*action)(struct db_context *, void *), + void *private_data) +{ + NTSTATUS status; + struct regdb_trans_ctx ctx; + + + ctx.action = action; + ctx.private_data = private_data; + + status = dbwrap_trans_do(db, regdb_trans_do_action, &ctx); + + return ntstatus_to_werror(status); +} + /* List the deepest path into the registry. All part components will be created.*/ /* If you want to have a part of the path controlled by the tdb and part by |