]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s4:smbtorture: Fix samba3.smb.dir on btrfs
authorAndreas Schneider <asn@samba.org>
Fri, 29 Nov 2024 06:37:54 +0000 (07:37 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Fri, 29 Nov 2024 15:10:13 +0000 (15:10 +0000)
"If a file is removed from or added to the directory after the most recent call
to opendir() or rewinddir(), whether a subsequent call to readdir() returns
an entry for that file is unspecified."
https://pubs.opengroup.org/onlinepubs/009604599/functions/readdir.html

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Fri Nov 29 15:10:13 UTC 2024 on atb-devel-224

source4/torture/smb2/dir.c

index 4020e6b86720e025cf662a8d0b9a668433eb8cdb..c495f09d861253c80bdcf9497185c1793245f6cf 100644 (file)
@@ -53,6 +53,7 @@ static NTSTATUS populate_tree(struct torture_context *tctx,
                              struct smb2_handle *h_out)
 {
        struct smb2_create create;
+       struct smb2_handle dirh;
        char **strs = NULL;
        NTSTATUS status;
        bool ret = true;
@@ -72,7 +73,7 @@ static NTSTATUS populate_tree(struct torture_context *tctx,
 
        status = smb2_create(tree, mem_ctx, &create);
        torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "");
-       *h_out = create.out.file.handle;
+       dirh = create.out.file.handle;
 
        ZERO_STRUCT(create);
        create.in.desired_access = SEC_RIGHTS_FILE_ALL;
@@ -93,6 +94,29 @@ static NTSTATUS populate_tree(struct torture_context *tctx,
                files[i].create_time = create.out.create_time;
                smb2_util_close(tree, create.out.file.handle);
        }
+       /* Close the dir handle */
+       smb2_util_close(tree, dirh);
+
+       /*
+        * Reopen the directory handle that the readdir() in smbd will see the
+        * created files.
+        */
+       ZERO_STRUCT(create);
+       create.in.desired_access = SEC_RIGHTS_DIR_ALL;
+       create.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
+       create.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
+       create.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
+                                NTCREATEX_SHARE_ACCESS_WRITE |
+                                NTCREATEX_SHARE_ACCESS_DELETE;
+       create.in.create_disposition = NTCREATEX_DISP_OPEN;
+       create.in.fname = DNAME;
+
+       status = smb2_create(tree, mem_ctx, &create);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "");
+       dirh = create.out.file.handle;
+
+       *h_out = dirh;
+
  done:
        if (!ret) {
                return status;
@@ -1204,6 +1228,16 @@ static bool test_file_index(struct torture_context *tctx,
                smb2_util_close(tree, create.out.file.handle);
        }
 
+       /* Close the dir handle */
+       smb2_util_close(tree, h);
+
+       /*
+        * Reopen the directory handle, that the readdir() in smbd will see the
+        * created files.
+        */
+       status = torture_smb2_testdir(tree, DNAME, &h);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "");
+
        ZERO_STRUCT(result);
        result.tctx = tctx;
 
@@ -1342,6 +1376,27 @@ static bool test_large_files(struct torture_context *tctx,
                smb2_util_close(tree, create.out.file.handle);
        }
 
+       /* Close dir handle */
+       smb2_util_close(tree, h);
+
+       /*
+        * Reopen the directory handle that the readdir() in smbd will see the
+        * created files.
+        */
+       ZERO_STRUCT(create);
+       create.in.desired_access = SEC_RIGHTS_DIR_ALL;
+       create.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
+       create.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
+       create.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
+                                NTCREATEX_SHARE_ACCESS_WRITE |
+                                NTCREATEX_SHARE_ACCESS_DELETE;
+       create.in.create_disposition = NTCREATEX_DISP_OPEN;
+       create.in.fname = DNAME;
+
+       status = smb2_create(tree, mem_ctx, &create);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "");
+       h = create.out.file.handle;
+
        ZERO_STRUCT(f);
        f.in.file.handle        = h;
        f.in.pattern            = "*";