From: Andreas Schneider Date: Fri, 29 Nov 2024 06:37:54 +0000 (+0100) Subject: s4:smbtorture: Fix samba3.smb.dir on btrfs X-Git-Tag: tdb-1.4.13~452 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fe96aa111cdcc0f753075cccb8f1fd44791abaab;p=thirdparty%2Fsamba.git s4:smbtorture: Fix samba3.smb.dir on btrfs "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 Reviewed-by: Ralph Boehme Autobuild-User(master): Andreas Schneider Autobuild-Date(master): Fri Nov 29 15:10:13 UTC 2024 on atb-devel-224 --- diff --git a/source4/torture/smb2/dir.c b/source4/torture/smb2/dir.c index 4020e6b8672..c495f09d861 100644 --- a/source4/torture/smb2/dir.c +++ b/source4/torture/smb2/dir.c @@ -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 = "*";