From 91350d562b670a3789779e906850d76a141fa857 Mon Sep 17 00:00:00 2001 From: Christof Schmitt Date: Tue, 21 May 2019 11:11:56 -0700 Subject: [PATCH] net: Return share name in correct case from net rpc conf showshare Signed-off-by: Christof Schmitt Reviewed-by: Jeremy Allison --- source3/utils/net_rpc_conf.c | 39 +++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/source3/utils/net_rpc_conf.c b/source3/utils/net_rpc_conf.c index 4747da98325..a68d3f70607 100644 --- a/source3/utils/net_rpc_conf.c +++ b/source3/utils/net_rpc_conf.c @@ -418,8 +418,9 @@ static NTSTATUS rpc_conf_get_share(TALLOC_CTX *mem_ctx, WERROR _werr; struct policy_handle child_hnd; int32_t includes_cnt, includes_idx = -1; - uint32_t num_vals, i, param_cnt = 0; + uint32_t num_vals, num_subkeys, i, param_cnt = 0; const char **val_names; + const char **subkeys = NULL; enum winreg_Type *types; DATA_BLOB *data; struct winreg_String key = { 0, }; @@ -429,7 +430,39 @@ static NTSTATUS rpc_conf_get_share(TALLOC_CTX *mem_ctx, ZERO_STRUCT(tmp_share); - key.name = share_name; + /* + * Determine correct upper/lowercase. + */ + status = dcerpc_winreg_enum_keys(frame, + b, + parent_hnd, + &num_subkeys, + &subkeys, + &result); + if (!(NT_STATUS_IS_OK(status))) { + d_fprintf(stderr, _("Failed to enumerate shares: %s\n"), + nt_errstr(status)); + goto error; + } + if (!(W_ERROR_IS_OK(result))) { + d_fprintf(stderr, _("Failed to enumerate shares: %s\n"), + win_errstr(result)); + goto error; + } + + for (i = 0; i < num_subkeys; i++) { + if (!strequal(share_name, subkeys[i])) { + continue; + } + + key.name = subkeys[i]; + } + + if (key.name == NULL) { + d_fprintf(stderr, _("Could not find share.\n")); + goto error; + } + status = dcerpc_winreg_OpenKey(b, frame, parent_hnd, key, 0, REG_KEY_READ, &child_hnd, &result); @@ -487,7 +520,7 @@ static NTSTATUS rpc_conf_get_share(TALLOC_CTX *mem_ctx, includes_cnt ++); } /* place the name of the share in the smbconf_service struct */ - tmp_share.name = talloc_strdup(frame, share_name); + tmp_share.name = talloc_strdup(frame, key.name); if (tmp_share.name == NULL) { result = WERR_NOT_ENOUGH_MEMORY; d_fprintf(stderr, _("Failed to create share: %s\n"), -- 2.34.1