s3-client: smbclient shows no error if deleting a directory with del failed
authorJeremy Allison <jra@samba.org>
Tue, 12 Nov 2013 23:55:51 +0000 (15:55 -0800)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 14 Nov 2013 20:23:07 +0000 (21:23 +0100)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=10260

In SMB1 the server filters by attribute requested, in SMB2 there is
no attribute sent. Emulate this on the client to provide the same
ABI to callers.

In SMB1 the server returns NT_STATUS_NO_SUCH_FILE if FindFirst
finds no files. Emulate this on the client.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Thu Nov 14 21:23:07 CET 2013 on sn-devel-104

source3/libsmb/cli_smb2_fnum.c
source3/libsmb/cli_smb2_fnum.h
source3/libsmb/clilist.c

index 202000fbbf58edacd4a36e2b9d3091fb50056f9d..d10e1d274c4ed76653d7f5d406c5059608a5289c 100644 (file)
@@ -486,6 +486,7 @@ static bool windows_parent_dirname(TALLOC_CTX *mem_ctx,
 
 NTSTATUS cli_smb2_list(struct cli_state *cli,
                        const char *pathname,
+                       uint16_t attribute,
                        NTSTATUS (*fn)(const char *,
                                struct file_info *,
                                const char *,
@@ -497,6 +498,7 @@ NTSTATUS cli_smb2_list(struct cli_state *cli,
        char *parent_dir = NULL;
        const char *mask = NULL;
        struct smb2_hnd *ph = NULL;
+       bool processed_file = false;
        TALLOC_CTX *frame = talloc_stackframe();
        TALLOC_CTX *subframe = NULL;
 
@@ -590,13 +592,26 @@ NTSTATUS cli_smb2_list(struct cli_state *cli,
                                goto fail;
                        }
 
-                       status = fn(cli->dfs_mountpoint,
+                       if (dir_check_ftype((uint32_t)finfo->mode,
+                                       (uint32_t)attribute)) {
+                               /*
+                                * Only process if attributes match.
+                                * On SMB1 server does this, so on
+                                * SMB2 we need to emulate in the
+                                * client.
+                                *
+                                * https://bugzilla.samba.org/show_bug.cgi?id=10260
+                                */
+                               processed_file = true;
+
+                               status = fn(cli->dfs_mountpoint,
                                        finfo,
                                        pathname,
                                        state);
 
-                       if (!NT_STATUS_IS_OK(status)) {
-                               break;
+                               if (!NT_STATUS_IS_OK(status)) {
+                                       break;
+                               }
                        }
 
                        TALLOC_FREE(finfo);
@@ -616,6 +631,14 @@ NTSTATUS cli_smb2_list(struct cli_state *cli,
                status = NT_STATUS_OK;
        }
 
+       if (NT_STATUS_IS_OK(status) && !processed_file) {
+               /*
+                * In SMB1 findfirst returns NT_STATUS_NO_SUCH_FILE
+                * if no files match. Emulate this in the client.
+                */
+               status = NT_STATUS_NO_SUCH_FILE;
+       }
+
   fail:
 
        if (fnum != 0xffff) {
index 00686866361b6b3d30f806640f13e6f9f6776752..a5cae25a2ba9772b455df9029ddea80acbaf79ac 100644 (file)
@@ -42,6 +42,7 @@ NTSTATUS cli_smb2_rmdir(struct cli_state *cli, const char *dirname);
 NTSTATUS cli_smb2_unlink(struct cli_state *cli,const char *fname);
 NTSTATUS cli_smb2_list(struct cli_state *cli,
                        const char *pathname,
+                       uint16_t attribute,
                        NTSTATUS (*fn)(const char *,
                                struct file_info *,
                                const char *,
index ed970cd896ee1d04440a27b0b7f8161e36a7d4c3..3080fb883dd86b1579bdbaf8c035c431dedacd42 100644 (file)
@@ -942,7 +942,7 @@ NTSTATUS cli_list(struct cli_state *cli, const char *mask, uint16 attribute,
        uint16_t info_level;
 
        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
-               return cli_smb2_list(cli, mask, fn, state);
+               return cli_smb2_list(cli, mask, attribute, fn, state);
        }
 
        frame = talloc_stackframe();