From c3bbd35b24b15f067c6e3702e66096d0063b0d92 Mon Sep 17 00:00:00 2001 From: Gregor Beck Date: Wed, 29 Sep 2010 15:12:49 +0200 Subject: [PATCH] s3-net: add command rpc registry export --- source3/utils/net_rpc_registry.c | 266 ++++++++++++++++++++++++++++++- 1 file changed, 265 insertions(+), 1 deletion(-) diff --git a/source3/utils/net_rpc_registry.c b/source3/utils/net_rpc_registry.c index d76e72e541..0c52f7fffc 100644 --- a/source3/utils/net_rpc_registry.c +++ b/source3/utils/net_rpc_registry.c @@ -22,6 +22,7 @@ #include "utils/net_registry_util.h" #include "regfio.h" #include "reg_objects.h" +#include "registry/reg_format.h" #include "registry/reg_import.h" #include @@ -334,6 +335,118 @@ static NTSTATUS registry_enumvalues(TALLOC_CTX *ctx, return status; } +static NTSTATUS registry_enumvalues2(TALLOC_CTX *ctx, + struct rpc_pipe_client *pipe_hnd, + struct policy_handle *key_hnd, + uint32 *pnum_values, char ***pvalnames, + struct regval_blob ***pvalues) +{ + TALLOC_CTX *mem_ctx; + NTSTATUS status; + uint32 num_subkeys, max_subkeylen, max_classlen; + uint32 num_values, max_valnamelen, max_valbufsize; + uint32 i; + NTTIME last_changed_time; + uint32 secdescsize; + struct winreg_String classname; + struct regval_blob **values; + char **names; + + if (!(mem_ctx = talloc_new(ctx))) { + return NT_STATUS_NO_MEMORY; + } + + ZERO_STRUCT(classname); + status = rpccli_winreg_QueryInfoKey( + pipe_hnd, mem_ctx, key_hnd, &classname, &num_subkeys, + &max_subkeylen, &max_classlen, &num_values, &max_valnamelen, + &max_valbufsize, &secdescsize, &last_changed_time, NULL ); + + if (!NT_STATUS_IS_OK(status)) { + goto error; + } + + if (num_values == 0) { + *pnum_values = 0; + TALLOC_FREE(mem_ctx); + return NT_STATUS_OK; + } + + if ((!(names = TALLOC_ARRAY(mem_ctx, char *, num_values))) || + (!(values = TALLOC_ARRAY(mem_ctx, struct regval_blob *, + num_values)))) { + status = NT_STATUS_NO_MEMORY; + goto error; + } + + for (i=0; idisplay_usage) { + d_printf("%s\n%s", + "Usage:", + "net rpc registry export [opt]\n"); + d_printf("%s net rpc registry export " + "'HKLM\\Software\\Samba' samba.reg\n", "Example:"); + return NT_STATUS_INVALID_PARAMETER; + } + + status = registry_openkey(mem_ctx, pipe_hnd, argv[0], REG_KEY_READ, + &pol_hive, &pol_key); + if (!NT_STATUS_IS_OK(status)) { + d_fprintf(stderr, "registry_openkey failed: %s\n", + nt_errstr(status)); + return status; + } + + f = reg_format_file(mem_ctx, argv[1], (argc > 2) ? argv[2] : NULL); + if (f == NULL) { + d_fprintf(stderr, "open file failed: %s\n", strerror(errno)); + return map_nt_error_from_unix(errno); + } + + status = registry_export(pipe_hnd, mem_ctx, &pol_key, + f, argv[0], NULL ); + if (!NT_STATUS_IS_OK(status)) + return status; + + rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &pol_key, NULL); + rpccli_winreg_CloseKey(pipe_hnd, mem_ctx, &pol_hive, NULL); + + return status; +} + +static int rpc_registry_export(struct net_context *c, int argc, + const char **argv ) +{ + return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0, + rpc_registry_export_internal, argc, argv ); +} + +/**@}*/ + +/******************************************************************** + ********************************************************************/ + /** * @defgroup net_rpc_registry_import Import * @ingroup net_rpc_registry @@ -1593,6 +1850,13 @@ int net_rpc_registry(struct net_context *c, int argc, const char **argv) "net rpc registry getsd\n" " Get security descriptior" }, + { + "export", + rpc_registry_export, + NET_TRANSPORT_RPC, + "net registry export\n" + " Export .reg file" + }, { "import", rpc_registry_import, -- 2.34.1