Description: Fix net rpc share allowedusers to work with 2008r2 The RAP NetShareEnum command was removed in 2008r2, so use the RPC equivalent instead. Author: Olly Betts --- --- samba-3.4.7~dfsg.orig/source3/utils/net_rpc.c +++ samba-3.4.7~dfsg/source3/utils/net_rpc.c @@ -4334,28 +4334,6 @@ static void show_userlist(struct rpc_pip return; } -struct share_list { - int num_shares; - char **shares; -}; - -static void collect_share(const char *name, uint32 m, - const char *comment, void *state) -{ - struct share_list *share_list = (struct share_list *)state; - - if (m != STYPE_DISKTREE) - return; - - share_list->num_shares += 1; - share_list->shares = SMB_REALLOC_ARRAY(share_list->shares, char *, share_list->num_shares); - if (!share_list->shares) { - share_list->num_shares = 0; - return; - } - share_list->shares[share_list->num_shares-1] = SMB_STRDUP(name); -} - /** * List shares on a remote RPC server, including the security descriptors. * @@ -4381,16 +4359,18 @@ static NTSTATUS rpc_share_allowedusers_i int argc, const char **argv) { - int ret; bool r; - uint32 i; FILE *f; + NET_API_STATUS status; + struct SHARE_INFO_1 *i1 = NULL; + uint32_t entries_read = 0; + uint32_t total_entries = 0; + uint32_t resume_handle = 0; + uint32_t i, level = 1; struct user_token *tokens = NULL; int num_tokens = 0; - struct share_list share_list; - if (argc == 0) { f = stdin; } else { @@ -4415,20 +4395,24 @@ static NTSTATUS rpc_share_allowedusers_i for (i=0; iopt_host, + level, + (uint8_t **)(void *)&i1, + (uint32_t)-1, + &entries_read, + &total_entries, + &resume_handle); + if (status != 0) { goto done; } - for (i = 0; i < share_list.num_shares; i++) { - char *netname = share_list.shares[i]; - + for (i = 0; i < entries_read; i++) { + struct SHARE_INFO_1 *r = &i1[i]; + const char *netname; + if (r->shi1_type != STYPE_DISKTREE) continue; + netname = r->shi1_netname; + /* FIXME: Do we need to check for a $ suffix as well as + * STYPE_DISKTREE? */ if (netname[strlen(netname)-1] == '$') continue; @@ -4442,7 +4426,6 @@ static NTSTATUS rpc_share_allowedusers_i free_user_token(&tokens[i].token); } SAFE_FREE(tokens); - SAFE_FREE(share_list.shares); return NT_STATUS_OK; }