s3:selftest: add a VSS test reading a stream
authorRalph Boehme <slow@samba.org>
Fri, 23 Nov 2018 13:36:56 +0000 (14:36 +0100)
committerRalph Boehme <slow@samba.org>
Tue, 27 Nov 2018 06:13:13 +0000 (07:13 +0100)
Bug: https://bugzilla.samba.org/show_bug.cgi?id=13455

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
selftest/knownfail.d/samba3.blackbox [new file with mode: 0644]
selftest/target/Samba3.pm
source3/script/tests/test_shadow_copy_torture.sh
source4/torture/smb2/create.c

diff --git a/selftest/knownfail.d/samba3.blackbox b/selftest/knownfail.d/samba3.blackbox
new file mode 100644 (file)
index 0000000..a15359e
--- /dev/null
@@ -0,0 +1 @@
+^samba3.blackbox.shadow_copy_torture.reading stream of a shadow copy of a file\(fileserver\)
index 0e1ffd1101aa1b552872f795ba9a0c974b904512..888f3bd5154aa4cc5b34d044206b9bfa537ae64e 100755 (executable)
@@ -2194,7 +2194,7 @@ sub provision($$$$$$$$$)
 [shadow_write]
        path = $shadow_tstdir
        comment = previous versions snapshots under mount point
-       vfs objects = shadow_copy2 error_inject
+       vfs objects = shadow_copy2 streams_xattr error_inject
        aio write size = 0
        error_inject:pwrite = EBADF
        shadow:mountpoint = $shadow_tstdir
index d47cd512a20249a397165e14021b8c9feeb8cccc..3b05fc50f72d0cced55dfda4078ecb3c2f582f7f 100755 (executable)
@@ -48,6 +48,13 @@ build_snapshots()
     build_files $snapdir/$SNAPSHOT
 }
 
+build_stream_on_snapshot()
+{
+    file=$WORKDIR/.snapshots/$SNAPSHOT/foo
+
+    setfattr -n 'user.DosStream.bar:$DATA' -v baz $file || return 1
+}
+
 test_shadow_copy_write()
 {
     local msg
@@ -68,9 +75,40 @@ test_shadow_copy_write()
         failed=`expr $failed + 1`
 }
 
+test_shadow_copy_stream()
+{
+    local msg
+
+    msg=$1
+
+    #delete snapshots from previous tests
+    find $WORKDIR -name ".snapshots" -exec rm -rf {} \; 1>/dev/null 2>&1
+    build_snapshots
+    build_stream_on_snapshot || {
+       subunit_start_test msg
+       subunit_skip_test msg <<EOF
+test_shadow_copy_stream needs an fs with xattrs
+EOF
+       return 0
+    }
+
+    testit "reading stream of a shadow copy of a file" \
+          $SMBTORTURE \
+          -U$USERNAME%$PASSWORD \
+          "//$SERVER/shadow_write" \
+          --option="torture:twrp_file=foo" \
+          --option="torture:twrp_stream=bar" \
+          --option="torture:twrp_stream_size=3" \
+          --option="torture:twrp_snapshot=$SNAPSHOT" \
+          smb2.twrp.stream || \
+        failed=`expr $failed + 1`
+}
+
 build_files $WORKDIR
 
 # test open for writing and write behaviour of snapshoted files
 test_shadow_copy_write "write behaviour of snapshoted files"
 
+test_shadow_copy_stream "reading stream of snapshotted file"
+
 exit $failed
index 68447935bd0b792ece458543634ca8ca304695d3..912efaac2724072f528d1e5cead041d160c3e2e8 100644 (file)
@@ -1809,6 +1809,92 @@ done:
        return ret;
 }
 
+static bool test_twrp_stream(struct torture_context *tctx,
+                            struct smb2_tree *tree)
+{
+       struct smb2_create io;
+       NTSTATUS status;
+       bool ret = true;
+       char *p = NULL;
+       struct tm tm;
+       time_t t;
+       uint64_t nttime;
+       const char *file = NULL;
+       const char *stream = NULL;
+       const char *snapshot = NULL;
+       int stream_size;
+       char *path = NULL;
+       uint8_t *buf = NULL;
+       struct smb2_handle h1 = {{0}};
+       struct smb2_read r;
+
+       file = torture_setting_string(tctx, "twrp_file", NULL);
+       if (file == NULL) {
+               torture_skip(tctx, "missing 'twrp_file' option\n");
+       }
+
+       stream = torture_setting_string(tctx, "twrp_stream", NULL);
+       if (stream == NULL) {
+               torture_skip(tctx, "missing 'twrp_stream' option\n");
+       }
+
+       snapshot = torture_setting_string(tctx, "twrp_snapshot", NULL);
+       if (snapshot == NULL) {
+               torture_skip(tctx, "missing 'twrp_snapshot' option\n");
+       }
+
+       stream_size = torture_setting_int(tctx, "twrp_stream_size", 0);
+       if (stream_size == 0) {
+               torture_skip(tctx, "missing 'twrp_stream_size' option\n");
+       }
+
+       torture_comment(tctx, "Testing timewarp on stream (%s) (%s)\n",
+                       file, snapshot);
+
+       path = talloc_asprintf(tree, "%s:%s", file, stream);
+       torture_assert_not_null_goto(tctx, path, ret, done, "path\n");
+
+       buf = talloc_zero_array(tree, uint8_t, stream_size);
+       torture_assert_not_null_goto(tctx, buf, ret, done, "buf\n");
+
+       setenv("TZ", "GMT", 1);
+       p = strptime(snapshot, "@GMT-%Y.%m.%d-%H.%M.%S", &tm);
+       torture_assert_goto(tctx, p != NULL, ret, done, "strptime\n");
+       torture_assert_goto(tctx, *p == '\0', ret, done, "strptime\n");
+
+       t = mktime(&tm);
+       unix_to_nt_time(&nttime, t);
+
+       io = (struct smb2_create) {
+               .in.desired_access = SEC_FILE_READ_DATA,
+               .in.file_attributes = FILE_ATTRIBUTE_NORMAL,
+               .in.create_disposition = NTCREATEX_DISP_OPEN,
+               .in.share_access = NTCREATEX_SHARE_ACCESS_MASK,
+               .in.fname = path,
+               .in.timewarp = nttime,
+       };
+
+       status = smb2_create(tree, tctx, &io);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+                                       "smb2_create\n");
+       h1 = io.out.file.handle;
+
+       r = (struct smb2_read) {
+               .in.file.handle = h1,
+               .in.length = stream_size,
+               .in.offset = 0,
+       };
+
+       status = smb2_read(tree, tree, &r);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+                                       "smb2_create\n");
+
+       smb2_util_close(tree, h1);
+
+done:
+       return ret;
+}
+
 /*
    basic testing of SMB2 read
 */
@@ -1840,6 +1926,7 @@ struct torture_suite *torture_smb2_twrp_init(TALLOC_CTX *ctx)
        struct torture_suite *suite = torture_suite_create(ctx, "twrp");
 
        torture_suite_add_1smb2_test(suite, "write", test_twrp_write);
+       torture_suite_add_1smb2_test(suite, "stream", test_twrp_stream);
 
        suite->description = talloc_strdup(suite, "SMB2-TWRP tests");