]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbclient: Slightly simplify do_list()
authorVolker Lendecke <vl@samba.org>
Fri, 5 Jun 2020 05:58:35 +0000 (07:58 +0200)
committerJeremy Allison <jra@samba.org>
Wed, 10 Jun 2020 22:20:46 +0000 (22:20 +0000)
Nonrecursive listing is just a special case of recursive
listing. do_list_helper() checks that.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/client/client.c

index c423f0b8e71fcf26114039abf6326490bb5b5f29..953b7443b905c067f630e9b1b8bf0e33aa7b1378 100644 (file)
@@ -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;