From 96ba0cb8f2a02a5f991ef92ed9eeb81d1a42216b Mon Sep 17 00:00:00 2001 From: Gregor Beck Date: Mon, 20 Sep 2010 16:45:57 +0200 Subject: s3-net: add command rpc registry export Signed-off-by: Michael Adam --- source3/utils/net_rpc_registry.c | 270 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 268 insertions(+), 2 deletions(-) diff --git a/source3/utils/net_rpc_registry.c b/source3/utils/net_rpc_registry.c index 76e8555a3f..d0d09481ed 100644 --- a/source3/utils/net_rpc_registry.c +++ b/source3/utils/net_rpc_registry.c @@ -26,6 +26,9 @@ #include "../librpc/gen_ndr/cli_winreg.h" #include "registry/reg_objects.h" #include "../librpc/gen_ndr/ndr_security.h" +#include "registry/reg_format.h" +#include + /******************************************************************* connect to a registry hive root (open a registry policy) @@ -378,6 +381,120 @@ 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; i 3 || c->display_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 ); +} + +/**@}*/ + int net_rpc_registry(struct net_context *c, int argc, const char **argv) { @@ -1366,8 +1626,14 @@ int net_rpc_registry(struct net_context *c, int argc, const char **argv) N_("net rpc registry getsd\n" " Get security descriptior") }, + { + "export", + rpc_registry_export, + NET_TRANSPORT_RPC, + N_("net registry export\n" + " Export .reg file") + }, {NULL, NULL, 0, NULL, NULL} }; - return net_run_function(c, argc, argv, "net rpc registry", func); } -- cgit