From: Volker Lendecke Date: Fri, 5 Jun 2020 05:58:35 +0000 (+0200) Subject: smbclient: Slightly simplify do_list() X-Git-Tag: ldb-2.2.0~147 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a10dbe17456513fcd6d4e0efb79024875774918e;p=thirdparty%2Fsamba.git smbclient: Slightly simplify do_list() Nonrecursive listing is just a special case of recursive listing. do_list_helper() checks that. Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/client/client.c b/source3/client/client.c index c423f0b8e71..953b7443b90 100644 --- a/source3/client/client.c +++ b/source3/client/client.c @@ -878,85 +878,65 @@ NTSTATUS do_list(const char *mask, do_list_dirs = dirs; do_list_fn = fn; - if (rec) { - init_do_list_queue(); - add_to_do_list_queue(mask); - - while (!do_list_queue_empty()) { - /* - * Need to copy head so that it doesn't become - * invalid inside the call to cli_list. This - * would happen if the list were expanded - * during the call. - * Fix from E. Jay Berkenbilt (ejb@ql.org) - */ - char *head = talloc_strdup(ctx, do_list_queue_head()); + init_do_list_queue(); + add_to_do_list_queue(mask); - if (!head) { - return NT_STATUS_NO_MEMORY; - } + while (!do_list_queue_empty()) { + /* + * Need to copy head so that it doesn't become + * invalid inside the call to cli_list. This + * would happen if the list were expanded + * during the call. + * Fix from E. Jay Berkenbilt (ejb@ql.org) + */ + char *head = talloc_strdup(ctx, do_list_queue_head()); - /* check for dfs */ + if (!head) { + return NT_STATUS_NO_MEMORY; + } - status = cli_resolve_path(ctx, "", - popt_get_cmdline_auth_info(), - cli, head, &targetcli, &targetpath); - if (!NT_STATUS_IS_OK(status)) { - d_printf("do_list: [%s] %s\n", head, - nt_errstr(status)); - remove_do_list_queue_head(); - continue; - } + /* check for dfs */ - status = cli_list(targetcli, targetpath, attribute, - do_list_helper, targetcli); - if (!NT_STATUS_IS_OK(status)) { - d_printf("%s listing %s\n", - nt_errstr(status), targetpath); - ret_status = status; - } + status = cli_resolve_path(ctx, "", + popt_get_cmdline_auth_info(), + cli, head, &targetcli, &targetpath); + if (!NT_STATUS_IS_OK(status)) { + d_printf("do_list: [%s] %s\n", head, + nt_errstr(status)); remove_do_list_queue_head(); - if ((! do_list_queue_empty()) && (fn == display_finfo)) { - char *next_file = do_list_queue_head(); - char *save_ch = 0; - if ((strlen(next_file) >= 2) && - (next_file[strlen(next_file) - 1] == '*') && - (next_file[strlen(next_file) - 2] == CLI_DIRSEP_CHAR)) { - save_ch = next_file + - strlen(next_file) - 2; - *save_ch = '\0'; - if (showacls) { - /* cwd is only used if showacls is on */ - client_set_cwd(next_file); - } - } - if (!showacls) /* don't disturbe the showacls output */ - d_printf("\n%s\n",next_file); - if (save_ch) { - *save_ch = CLI_DIRSEP_CHAR; + continue; + } + + status = cli_list(targetcli, targetpath, attribute, + do_list_helper, targetcli); + if (!NT_STATUS_IS_OK(status)) { + d_printf("%s listing %s\n", + nt_errstr(status), targetpath); + ret_status = status; + } + remove_do_list_queue_head(); + if ((! do_list_queue_empty()) && (fn == display_finfo)) { + char *next_file = do_list_queue_head(); + char *save_ch = 0; + if ((strlen(next_file) >= 2) && + (next_file[strlen(next_file) - 1] == '*') && + (next_file[strlen(next_file) - 2] == CLI_DIRSEP_CHAR)) { + save_ch = next_file + + strlen(next_file) - 2; + *save_ch = '\0'; + if (showacls) { + /* cwd is only used if showacls is on */ + client_set_cwd(next_file); } } - TALLOC_FREE(head); - TALLOC_FREE(targetpath); - } - } else { - /* check for dfs */ - status = cli_resolve_path(ctx, "", - popt_get_cmdline_auth_info(), cli, mask, - &targetcli, &targetpath); - if (NT_STATUS_IS_OK(status)) { - status = cli_list(targetcli, targetpath, attribute, - do_list_helper, targetcli); - if (!NT_STATUS_IS_OK(status)) { - d_printf("%s listing %s\n", - nt_errstr(status), targetpath); - ret_status = status; + if (!showacls) /* don't disturbe the showacls output */ + d_printf("\n%s\n",next_file); + if (save_ch) { + *save_ch = CLI_DIRSEP_CHAR; } - TALLOC_FREE(targetpath); - } else { - d_printf("do_list: [%s] %s\n", mask, nt_errstr(status)); - ret_status = status; } + TALLOC_FREE(head); + TALLOC_FREE(targetpath); } in_do_list = 0;