s4/torture/fruit: enhance zero AFP_AfpInfo stream test
authorRalph Boehme <slow@samba.org>
Thu, 7 Dec 2017 12:43:02 +0000 (13:43 +0100)
committerRalph Boehme <slow@samba.org>
Tue, 9 Jan 2018 11:53:32 +0000 (12:53 +0100)
This test more operations in the zeroed out FinderInfo test, ensuring
after zeroing out FinderInfo, operations on the filehandle still work
and that enumerating streams doesn't return the stream anymore.

Bug: https://bugzilla.samba.org/show_bug.cgi?id=13181

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
selftest/knownfail.d/samba3.vfs.fruit
source4/torture/vfs/fruit.c

index 8df25bccb79b6474aac2a6faab4df7495336612f..e8fd5e11fc2ebe4bdafdaffa24f450ff454bbaf2 100644 (file)
@@ -1 +1,3 @@
 ^samba3.vfs.fruit streams_depot.OS X AppleDouble file conversion\(nt4_dc\)
+^samba3.vfs.fruit metadata_stream.delete AFP_AfpInfo by writing all 0\(nt4_dc\)
+^samba3.vfs.fruit streams_depot.delete AFP_AfpInfo by writing all 0\(nt4_dc\)
index 7c1692c00ab6ef939014702e591f15b900c7e159..d071cf6f9af95b06202bb5eae6027af30a36c5c9 100644 (file)
@@ -3346,11 +3346,17 @@ static bool test_afpinfo_all0(struct torture_context *tctx,
 {
        bool ret = true;
        NTSTATUS status;
-       struct smb2_handle h1;
+       struct smb2_create create;
+       struct smb2_handle h1 = {{0}};
+       struct smb2_handle baseh = {{0}};
+       union smb_setfileinfo setfinfo;
+       union smb_fileinfo getfinfo;
        TALLOC_CTX *mem_ctx = talloc_new(tctx);
        const char *fname = BASEDIR "\\file";
+       const char *sname = BASEDIR "\\file" AFPINFO_STREAM;
        const char *type_creator = "SMB,OLE!";
        AfpInfo *info = NULL;
+       char *infobuf = NULL;
        const char *streams_basic[] = {
                "::$DATA"
        };
@@ -3381,13 +3387,88 @@ static bool test_afpinfo_all0(struct torture_context *tctx,
 
        /* Write all 0 to AFP_AfpInfo */
        memset(info->afpi_FinderInfo, 0, AFP_FinderSize);
-       ret = torture_write_afpinfo(tree, tctx, mem_ctx, fname, info);
-       torture_assert_goto(tctx, ret == true, ret, done, "torture_write_afpinfo failed");
+       infobuf = torture_afpinfo_pack(mem_ctx, info);
+       torture_assert_not_null_goto(tctx, infobuf, ret, done,
+                                    "torture_afpinfo_pack failed\n");
+
+       ZERO_STRUCT(create);
+       create.in.desired_access = SEC_FILE_ALL;
+       create.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
+       create.in.create_disposition = NTCREATEX_DISP_OPEN;
+       create.in.share_access = NTCREATEX_SHARE_ACCESS_MASK;
+       create.in.fname = fname;
+
+       status = smb2_create(tree, mem_ctx, &create);
+       torture_assert_goto(tctx, ret == true, ret, done,
+                           "smb2_create failed\n");
+       baseh = create.out.file.handle;
+
+       ZERO_STRUCT(create);
+       create.in.desired_access = SEC_FILE_ALL;
+       create.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
+       create.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
+       create.in.fname = sname;
+
+       status = smb2_create(tree, mem_ctx, &create);
+       torture_assert_goto(tctx, ret == true, ret, done,
+                           "smb2_create failed\n");
+       h1 = create.out.file.handle;
+
+       status = smb2_util_write(tree, h1, infobuf, 0, AFP_INFO_SIZE);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+                                       "smb2_util_write failed\n");
+
+       /*
+        * Get stream information on open handle, must return only default
+        * stream, the AFP_AfpInfo stream must not be returned.
+        */
+
+       ZERO_STRUCT(getfinfo);
+       getfinfo.generic.level = RAW_FILEINFO_STREAM_INFORMATION;
+       getfinfo.generic.in.file.handle = baseh;
+
+       status = smb2_getinfo_file(tree, tctx, &getfinfo);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+                                       "get stream info\n");
+
+       torture_assert_int_equal_goto(tctx, getfinfo.stream_info.out.num_streams,
+                                     1, ret, done, "stream count");
+
+       smb2_util_close(tree, baseh);
+       ZERO_STRUCT(baseh);
+
+       /*
+        * Try to set some file-basic-info (time) on the stream. This catches
+        * naive implementation mistakes that simply deleted the backing store
+        * from the filesystem in the zero-out step.
+        */
+
+       ZERO_STRUCT(setfinfo);
+       unix_to_nt_time(&setfinfo.basic_info.in.write_time, time(NULL));
+       setfinfo.basic_info.in.attrib = 0x20;
+       setfinfo.generic.level = RAW_SFILEINFO_BASIC_INFORMATION;
+       setfinfo.generic.in.file.handle = h1;
+
+       status = smb2_setinfo_file(tree, &setfinfo);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+                                       "smb2_getinfo_file failed\n");
+
+       ret = check_stream_list(tree, tctx, fname, 1, streams_basic, false);
+       torture_assert_goto(tctx, ret == true, ret, done, "check_stream_list");
+
+       smb2_util_close(tree, h1);
+       ZERO_STRUCT(h1);
 
        ret = check_stream_list(tree, tctx, fname, 1, streams_basic, false);
        torture_assert_goto(tctx, ret == true, ret, done, "Bad streams");
 
 done:
+       if (!smb2_util_handle_empty(h1)) {
+               smb2_util_close(tree, h1);
+       }
+       if (!smb2_util_handle_empty(baseh)) {
+               smb2_util_close(tree, baseh);
+       }
        smb2_util_unlink(tree, fname);
        smb2_util_rmdir(tree, BASEDIR);
        return ret;