summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Beck <gbeck@sernet.de>2012-05-04 09:35:37 +0200
committerMichael Adam <obnox@samba.org>2012-06-26 19:57:18 +0200
commit69add7e4fd64c0fc264414991e2d7b0edee09aed (patch)
treeb3baa1c6da682090726fb5556b8acf122a47b15b
parentcc052d0c7784a184b7d52ca08adc0bdf6d820420 (diff)
downloadsamba-69add7e4fd64c0fc264414991e2d7b0edee09aed.tar.gz
samba-69add7e4fd64c0fc264414991e2d7b0edee09aed.tar.bz2
samba-69add7e4fd64c0fc264414991e2d7b0edee09aed.zip
s3:net registry import: check return values + codecleanup
Signed-off-by: Michael Adam <obnox@samba.org>
-rw-r--r--source3/utils/net_registry.c46
1 files changed, 30 insertions, 16 deletions
diff --git a/source3/utils/net_registry.c b/source3/utils/net_registry.c
index eb7d19aec0..b466e7e7b7 100644
--- a/source3/utils/net_registry.c
+++ b/source3/utils/net_registry.c
@@ -1033,7 +1033,10 @@ static WERROR import_delete_val (struct import_ctx* ctx, struct registry_key* pa
static int net_registry_import(struct net_context *c, int argc,
const char **argv)
{
- struct import_ctx import_ctx;
+ TALLOC_CTX *frame = talloc_stackframe();
+ struct import_ctx import_ctx = {
+ .mem_ctx = frame,
+ };
struct reg_import_callback import_callback = {
.openkey = NULL,
.closekey = (reg_import_callback_closekey_t)&import_close_key,
@@ -1048,7 +1051,8 @@ static int net_registry_import(struct net_context *c, int argc,
.data = &import_ctx
};
- int ret;
+ int ret = -1;
+ WERROR werr;
if (argc < 1 || argc > 2 || c->display_usage) {
d_printf("%s\n%s",
@@ -1057,30 +1061,40 @@ static int net_registry_import(struct net_context *c, int argc,
d_printf("%s\n%s",
_("Example:"),
_("net registry import file.reg enc=CP1252\n"));
- return -1;
+ goto done;
}
- ZERO_STRUCT(import_ctx);
- import_ctx.mem_ctx = talloc_stackframe();
-
- regdb_open();
- regdb_transaction_start();
+ werr = regdb_open();
+ if (!W_ERROR_IS_OK(werr)) {
+ d_printf("Failed to open regdb: %s\n", win_errstr(werr));
+ goto done;
+ }
+ werr = regdb_transaction_start();
+ if (!W_ERROR_IS_OK(werr)) {
+ d_printf("Failed to start transaction on regdb: %s\n",
+ win_errstr(werr));
+ goto done;
+ }
ret = reg_parse_file(argv[0],
- reg_import_adapter(import_ctx.mem_ctx,
- import_callback),
- (argc > 1) ? argv[1] : NULL
- );
+ reg_import_adapter(frame, import_callback),
+ (argc > 1) ? argv[1] : NULL);
+
if (ret < 0) {
d_printf("reg_parse_file failed: transaction canceled\n");
regdb_transaction_cancel();
- } else{
- regdb_transaction_commit();
+ } else {
+ werr = regdb_transaction_commit();
+ if (!W_ERROR_IS_OK(werr)) {
+ d_printf("Failed to commit transaction on regdb: %s\n",
+ win_errstr(werr));
+ goto done;
+ }
}
regdb_close();
- talloc_free(import_ctx.mem_ctx);
-
+done:
+ talloc_free(frame);
return ret;
}
/**@}*/