From 7de814c5a74b578a717af512aebf1f2d47995e6d Mon Sep 17 00:00:00 2001 From: Vicentiu Ciorbaru Date: Fri, 22 Jul 2011 00:19:58 +0300 Subject: s3-net: Implemented net rpc conf delshare command The function makes use of dcerpc_winreg_delete_subkeys_recursive to clear the share. Signed-off-by: Michael Adam --- source3/utils/net_rpc_conf.c | 99 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 96 insertions(+), 3 deletions(-) (limited to 'source3') diff --git a/source3/utils/net_rpc_conf.c b/source3/utils/net_rpc_conf.c index bc77fb1703..e38e922f96 100644 --- a/source3/utils/net_rpc_conf.c +++ b/source3/utils/net_rpc_conf.c @@ -58,6 +58,15 @@ static int rpc_conf_listshares_usage(struct net_context *c, int argc, return -1; } +static int rpc_conf_delshare_usage(struct net_context *c, int argc, + const char **argv) +{ + d_printf("%s\n%s", + _("Usage:"), + _("net rpc conf delshare \n")); + return -1; +} + static int rpc_conf_showshare_usage(struct net_context *c, int argc, const char **argv) { @@ -449,6 +458,90 @@ error: return status;; } +static NTSTATUS rpc_conf_delshare_internal(struct net_context *c, + const struct dom_sid *domain_sid, + const char *domain_name, + struct cli_state *cli, + struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + int argc, + const char **argv ) +{ + + TALLOC_CTX *frame = talloc_stackframe(); + NTSTATUS status = NT_STATUS_OK; + WERROR werr = WERR_OK; + WERROR _werr; + + struct dcerpc_binding_handle *b = pipe_hnd->binding_handle; + + /* key info */ + struct policy_handle hive_hnd, key_hnd; + + ZERO_STRUCT(hive_hnd); + ZERO_STRUCT(key_hnd); + + + if (argc != 1 || c->display_usage) { + rpc_conf_delshare_usage(c, argc, argv); + status = NT_STATUS_INVALID_PARAMETER; + goto error; + } + + status = rpc_conf_open_conf(frame, + b, + REG_KEY_ALL, + &hive_hnd, + &key_hnd, + &werr); + + if (!(NT_STATUS_IS_OK(status))) { + goto error; + } + + if (!(W_ERROR_IS_OK(werr))) { + goto error; + } + + status = dcerpc_winreg_delete_subkeys_recursive(frame, + b, + &key_hnd, + REG_KEY_ALL, + argv[0], + &werr); + + if (!NT_STATUS_IS_OK(status)) { + d_fprintf(stderr, + "winreg_delete_subkeys: Could not delete key %s: %s\n", + argv[0], nt_errstr(status)); + goto error; + } + + if (W_ERROR_EQUAL(werr, WERR_BADFILE)){ + d_fprintf(stderr, _("ERROR: Key does not exist\n")); + } + + + if (!W_ERROR_IS_OK(werr)) { + d_fprintf(stderr, + "winreg_delete_subkeys: Could not delete key %s: %s\n", + argv[0], win_errstr(werr)); + goto error; + } + +error: + if (!(W_ERROR_IS_OK(werr))) { + status = werror_to_ntstatus(werr); + } + + dcerpc_winreg_CloseKey(b, frame, &hive_hnd, &_werr); + dcerpc_winreg_CloseKey(b, frame, &key_hnd, &_werr); + + TALLOC_FREE(frame); + + return status; +} + static NTSTATUS rpc_conf_list_internal(struct net_context *c, const struct dom_sid *domain_sid, const char *domain_name, @@ -797,9 +890,9 @@ static int rpc_conf_list(struct net_context *c, int argc, static int rpc_conf_delshare(struct net_context *c, int argc, const char **argv) { - d_printf("Function not yet implemented\n"); - return 0; -}; + return run_rpc_command(c, NULL, &ndr_table_winreg.syntax_id, 0, + rpc_conf_delshare_internal, argc, argv ); +} /* function calls */ int net_rpc_conf(struct net_context *c, int argc, -- cgit