From 9352a95bfda2d1a3255d8ad158af0fcef442b53e Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Mon, 29 Aug 2011 17:06:27 +0200 Subject: 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. --- source3/registry/reg_backend_db.c | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'source3/registry') 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 -- cgit