1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

s3:selftest: add a VSS test reading a stream

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>
This commit is contained in:
Ralph Boehme 2018-11-23 14:36:56 +01:00
parent cf95756235
commit cfffa2e242
4 changed files with 127 additions and 1 deletions

View File

@ -0,0 +1 @@
^samba3.blackbox.shadow_copy_torture.reading stream of a shadow copy of a file\(fileserver\)

View File

@ -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

View File

@ -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

View 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");