/*
Unix SMB/CIFS implementation.
test alternate data streams
Copyright (C) Andrew Tridgell 2004
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include "includes.h"
#include "libcli/smb2/smb2.h"
#include "libcli/smb2/smb2_calls.h"
#include "smb_constants.h"
#include "torture/torture.h"
#include "torture/smb2/proto.h"
#include "system/filesys.h"
#include "system/locale.h"
#include "lib/util/tsort.h"
#include "libcli/security/security_descriptor.h"
#define DNAME "teststreams"
#define CHECK_STATUS(status, correct) \
torture_assert_ntstatus_equal_goto(tctx, status, correct, ret, done, "CHECK_STATUS")
#define CHECK_VALUE(v, correct) \
torture_assert_u64_equal_goto(tctx, v, correct, ret, done, "CHECK_VALUE")
#define CHECK_NTTIME(v, correct) \
torture_assert_nttime_equal_goto(tctx, v, correct, ret, done, "CHECK_NTTIME")
#define CHECK_STR(v, correct) \
torture_assert_str_equal_goto(tctx, v, correct, ret, done, "CHECK_STR")
static int qsort_string(char * const *s1, char * const *s2)
{
return strcmp(*s1, *s2);
}
static int qsort_stream(const struct stream_struct * s1, const struct stream_struct *s2)
{
return strcmp(s1->stream_name.s, s2->stream_name.s);
}
static bool check_stream(struct torture_context *tctx,
struct smb2_tree *tree,
const char *location,
TALLOC_CTX *mem_ctx,
const char *fname,
const char *sname,
const char *value)
{
struct smb2_handle handle;
struct smb2_create create;
struct smb2_read r;
NTSTATUS status;
const char *full_name;
full_name = talloc_asprintf(mem_ctx, "%s:%s", fname, sname);
ZERO_STRUCT(create);
create.in.desired_access = SEC_RIGHTS_FILE_ALL;
create.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
create.in.create_disposition = NTCREATEX_DISP_OPEN;
create.in.fname = full_name;
status = smb2_create(tree, mem_ctx, &create);
if (!NT_STATUS_IS_OK(status)) {
if (value == NULL) {
return true;
} else {
torture_comment(tctx, "Unable to open stream %s\n",
full_name);
return false;
}
}
handle = create.out.file.handle;
if (value == NULL) {
return true;
}
ZERO_STRUCT(r);
r.in.file.handle = handle;
r.in.length = strlen(value)+11;
r.in.offset = 0;
status = smb2_read(tree, tree, &r);
if (!NT_STATUS_IS_OK(status)) {
torture_comment(tctx, "(%s) Failed to read %lu bytes from "
"stream '%s'\n", location, (long)strlen(value), full_name);
return false;
}
if (memcmp(r.out.data.data, value, strlen(value)) != 0) {
torture_comment(tctx, "(%s) Bad data in stream\n", location);
return false;
}
smb2_util_close(tree, handle);
return true;
}
static bool check_stream_list(struct smb2_tree *tree,
struct torture_context *tctx,
const char *fname,
unsigned int num_exp,
const char **exp,
struct smb2_handle h)
{
union smb_fileinfo finfo;
NTSTATUS status;
unsigned int i;
TALLOC_CTX *tmp_ctx = talloc_new(tctx);
char **exp_sort;
struct stream_struct *stream_sort;
bool ret = false;
finfo.generic.level = RAW_FILEINFO_STREAM_INFORMATION;
finfo.generic.in.file.handle = h;
status = smb2_getinfo_file(tree, tctx, &finfo);
if (!NT_STATUS_IS_OK(status)) {
torture_comment(tctx, "(%s) smb_raw_pathinfo failed: %s\n",
__location__, nt_errstr(status));
goto fail;
}
if (finfo.stream_info.out.num_streams != num_exp) {
torture_comment(tctx, "(%s) expected %d streams, got %d\n",
__location__, num_exp, finfo.stream_info.out.num_streams);
goto fail;
}
if (num_exp == 0) {
ret = true;
goto fail;
}
exp_sort = talloc_memdup(tmp_ctx, exp, num_exp * sizeof(*exp));
if (exp_sort == NULL) {
goto fail;
}
TYPESAFE_QSORT(exp_sort, num_exp, qsort_string);
stream_sort = talloc_memdup(tmp_ctx, finfo.stream_info.out.streams,
finfo.stream_info.out.num_streams *
sizeof(*stream_sort));
if (stream_sort == NULL) {
goto fail;
}
TYPESAFE_QSORT(stream_sort, finfo.stream_info.out.num_streams, qsort_stream);
for (i=0; i expected[%s]\n",
__location__, fname, isprint(i)?(char)i:' ', i,
isprint(i)?"":" (not printable)",
nt_errstr(expected));
}
CHECK_STATUS(status, expected);
talloc_free(path);
}
done:
smb2_util_close(tree, h1);
status = smb2_util_unlink(tree, fname);
smb2_deltree(tree, DNAME);
talloc_free(mem_ctx);
return ret;
}
/*
test case insensitive stream names
*/
static bool test_stream_names3(struct torture_context *tctx,
struct smb2_tree *tree)
{
TALLOC_CTX *mem_ctx = talloc_new(tctx);
NTSTATUS status;
union smb_fsinfo info;
const char *fname = DNAME "\\stream_names3.txt";
const char *sname = NULL;
const char *snamel = NULL;
const char *snameu = NULL;
const char *sdname = NULL;
const char *sdnamel = NULL;
const char *sdnameu = NULL;
bool ret = true;
struct smb2_handle h = {{0}};
struct smb2_handle hf = {{0}};
struct smb2_handle hs = {{0}};
struct smb2_handle hsl = {{0}};
struct smb2_handle hsu = {{0}};
struct smb2_handle hsd = {{0}};
struct smb2_handle hsdl = {{0}};
struct smb2_handle hsdu = {{0}};
const char *streams[] = { "::$DATA", ":StreamName:$DATA", };
smb2_deltree(tree, DNAME);
status = torture_smb2_testdir(tree, DNAME, &h);
CHECK_STATUS(status, NT_STATUS_OK);
ZERO_STRUCT(info);
info.generic.level = RAW_QFS_ATTRIBUTE_INFORMATION;
info.generic.handle = h;
status = smb2_getinfo_fs(tree, tree, &info);
CHECK_STATUS(status, NT_STATUS_OK);
if (!(info.attribute_info.out.fs_attr & FILE_CASE_SENSITIVE_SEARCH)) {
torture_skip(tctx, "No FILE_CASE_SENSITIVE_SEARCH supported");
}
/*
* We create the following file:
*
* teststreams\\stream_names3.txt
*
* and add a stream named 'StreamName'
*
* Then we try to open the stream using the following names:
*
* teststreams\\stream_names3.txt:StreamName
* teststreams\\stream_names3.txt:streamname
* teststreams\\stream_names3.txt:STREAMNAME
* teststreams\\stream_names3.txt:StreamName:$dAtA
* teststreams\\stream_names3.txt:streamname:$data
* teststreams\\stream_names3.txt:STREAMNAME:$DATA
*/
sname = talloc_asprintf(tctx, "%s:StreamName", fname);
torture_assert_not_null(tctx, sname, __location__);
snamel = strlower_talloc(tctx, sname);
torture_assert_not_null(tctx, snamel, __location__);
snameu = strupper_talloc(tctx, sname);
torture_assert_not_null(tctx, snameu, __location__);
sdname = talloc_asprintf(tctx, "%s:$dAtA", sname);
torture_assert_not_null(tctx, sdname, __location__);
sdnamel = strlower_talloc(tctx, sdname);
torture_assert_not_null(tctx, sdnamel, __location__);
sdnameu = strupper_talloc(tctx, sdname);
torture_assert_not_null(tctx, sdnameu, __location__);
torture_comment(tctx, "(%s) testing case insensitive stream names\n",
__location__);
status = torture_smb2_testfile(tree, fname, &hf);
CHECK_STATUS(status, NT_STATUS_OK);
status = torture_smb2_testfile(tree, sname, &hs);
CHECK_STATUS(status, NT_STATUS_OK);
smb2_util_close(tree, hs);
torture_assert(tctx,
check_stream_list(tree, tctx, fname,
ARRAY_SIZE(streams),
streams,
hf),
"streams");
status = torture_smb2_open(tree, sname, SEC_RIGHTS_FILE_ALL, &hs);
CHECK_STATUS(status, NT_STATUS_OK);
status = torture_smb2_open(tree, snamel, SEC_RIGHTS_FILE_ALL, &hsl);
CHECK_STATUS(status, NT_STATUS_OK);
status = torture_smb2_open(tree, snameu, SEC_RIGHTS_FILE_ALL, &hsu);
CHECK_STATUS(status, NT_STATUS_OK);
status = torture_smb2_open(tree, sdname, SEC_RIGHTS_FILE_ALL, &hsd);
CHECK_STATUS(status, NT_STATUS_OK);
status = torture_smb2_open(tree, sdnamel, SEC_RIGHTS_FILE_ALL, &hsdl);
CHECK_STATUS(status, NT_STATUS_OK);
status = torture_smb2_open(tree, sdnameu, SEC_RIGHTS_FILE_ALL, &hsdu);
CHECK_STATUS(status, NT_STATUS_OK);
done:
smb2_util_close(tree, hsdu);
smb2_util_close(tree, hsdl);
smb2_util_close(tree, hsd);
smb2_util_close(tree, hsu);
smb2_util_close(tree, hsl);
smb2_util_close(tree, hs);
smb2_util_close(tree, hf);
smb2_util_close(tree, h);
status = smb2_util_unlink(tree, fname);
smb2_deltree(tree, DNAME);
talloc_free(mem_ctx);
return ret;
}
#define CHECK_CALL_HANDLE(call, rightstatus) do { \
sfinfo.generic.level = RAW_SFILEINFO_ ## call; \
sfinfo.generic.in.file.handle = h1; \
status = smb2_setinfo_file(tree, &sfinfo); \
torture_assert_ntstatus_equal_goto(tctx, status, rightstatus, ret, done, #call); \
finfo1.generic.level = RAW_FILEINFO_ALL_INFORMATION; \
finfo1.generic.in.file.handle = h1; \
status2 = smb2_getinfo_file(tree, tctx, &finfo1); \
torture_assert_ntstatus_ok_goto(tctx, status2, ret, done, "ALL_INFO"); \
} while (0)
/*
test stream renames
*/
static bool test_stream_rename(struct torture_context *tctx,
struct smb2_tree *tree)
{
TALLOC_CTX *mem_ctx = talloc_new(tctx);
NTSTATUS status, status2;
union smb_open io;
const char *fname = DNAME "\\stream_rename.txt";
const char *sname1, *sname2;
union smb_fileinfo finfo1;
union smb_setfileinfo sfinfo;
bool ret = true;
struct smb2_handle h = {{0}};
struct smb2_handle h1 = {{0}};
sname1 = talloc_asprintf(mem_ctx, "%s:%s", fname, "Stream One");
sname2 = talloc_asprintf(mem_ctx, "%s:%s:$DaTa", fname,
"Second Stream");
smb2_util_unlink(tree, fname);
smb2_deltree(tree, DNAME);
status = torture_smb2_testdir(tree, DNAME, &h);
CHECK_STATUS(status, NT_STATUS_OK);
torture_comment(tctx, "(%s) testing stream renames\n", __location__);
ZERO_STRUCT(io.smb2);
io.smb2.in.create_flags = 0;
io.smb2.in.desired_access = SEC_FILE_READ_ATTRIBUTE |
SEC_FILE_WRITE_ATTRIBUTE |
SEC_RIGHTS_FILE_ALL;
io.smb2.in.create_options = 0;
io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE;
io.smb2.in.alloc_size = 0;
io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
io.smb2.in.security_flags = 0;
io.smb2.in.fname = sname1;
/* Create two streams. */
status = smb2_create(tree, mem_ctx, &(io.smb2));
CHECK_STATUS(status, NT_STATUS_OK);
h1 = io.smb2.out.file.handle;
smb2_util_close(tree, h1);
io.smb2.in.fname = sname2;
status = smb2_create(tree, mem_ctx, &(io.smb2));
CHECK_STATUS(status, NT_STATUS_OK);
h1 = io.smb2.out.file.handle;
smb2_util_close(tree, h1);
/*
* Open the second stream.
*/
io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
status = smb2_create(tree, mem_ctx, &(io.smb2));
CHECK_STATUS(status, NT_STATUS_OK);
h1 = io.smb2.out.file.handle;
/*
* Now rename the second stream onto the first.
*/
ZERO_STRUCT(sfinfo);
sfinfo.rename_information.in.overwrite = 1;
sfinfo.rename_information.in.root_fid = 0;
sfinfo.rename_information.in.new_name = ":Stream One";
CHECK_CALL_HANDLE(RENAME_INFORMATION, NT_STATUS_OK);
done:
smb2_util_close(tree, h1);
status = smb2_util_unlink(tree, fname);
smb2_deltree(tree, DNAME);
talloc_free(mem_ctx);
return ret;
}
static bool test_stream_rename2(struct torture_context *tctx,
struct smb2_tree *tree)
{
TALLOC_CTX *mem_ctx = talloc_new(tctx);
NTSTATUS status;
union smb_open io;
const char *fname1 = DNAME "\\stream_rename2.txt";
const char *fname2 = DNAME "\\stream2_rename2.txt";
const char *stream_name1 = ":Stream One:$DATA";
const char *stream_name2 = ":Stream Two:$DATA";
const char *stream_name_default = "::$DATA";
const char *sname1;
const char *sname2;
bool ret = true;
struct smb2_handle h, h1;
union smb_setfileinfo sinfo;
ZERO_STRUCT(h);
ZERO_STRUCT(h1);
sname1 = talloc_asprintf(mem_ctx, "%s:%s", fname1, "Stream One");
sname2 = talloc_asprintf(mem_ctx, "%s:%s", fname1, "Stream Two");
smb2_util_unlink(tree, fname1);
smb2_util_unlink(tree, fname2);
smb2_deltree(tree, DNAME);
status = torture_smb2_testdir(tree, DNAME, &h);
CHECK_STATUS(status, NT_STATUS_OK);
ZERO_STRUCT(io.smb2);
io.smb2.in.create_flags = 0;
io.smb2.in.desired_access = SEC_FILE_READ_DATA |
SEC_FILE_WRITE_DATA |
SEC_STD_DELETE |
SEC_FILE_APPEND_DATA |
SEC_STD_READ_CONTROL;
io.smb2.in.create_options = 0;
io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE;
io.smb2.in.alloc_size = 0;
io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
io.smb2.in.security_flags = 0;
io.smb2.in.fname = sname1;
/* Open/create new stream. */
status = smb2_create(tree, mem_ctx, &(io.smb2));
CHECK_STATUS(status, NT_STATUS_OK);
smb2_util_close(tree, io.smb2.out.file.handle);
/*
* Reopen the stream for SMB2 renames.
*/
io.smb2.in.fname = sname1;
io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
status = smb2_create(tree, mem_ctx, &(io.smb2));
CHECK_STATUS(status, NT_STATUS_OK);
h1 = io.smb2.out.file.handle;
/*
* Check SMB2 rename of a stream using :.
*/
torture_comment(tctx, "(%s) Checking SMB2 rename of a stream using "
":\n", __location__);
ZERO_STRUCT(sinfo);
sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION_SMB2;
sinfo.rename_information.in.file.handle = h1;
sinfo.rename_information.in.overwrite = 1;
sinfo.rename_information.in.root_fid = 0;
sinfo.rename_information.in.new_name = stream_name1;
status = smb2_setinfo_file(tree, &sinfo);
CHECK_STATUS(status, NT_STATUS_OK);
/*
* Check SMB2 rename of an overwriting stream using :.
*/
torture_comment(tctx, "(%s) Checking SMB2 rename of an overwriting "
"stream using :\n", __location__);
/* Create second stream. */
io.smb2.in.fname = sname2;
io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
status = smb2_create(tree, mem_ctx, &(io.smb2));
CHECK_STATUS(status, NT_STATUS_OK);
smb2_util_close(tree, io.smb2.out.file.handle);
/* Rename the first stream onto the second. */
sinfo.rename_information.in.file.handle = h1;
sinfo.rename_information.in.new_name = stream_name2;
status = smb2_setinfo_file(tree, &sinfo);
CHECK_STATUS(status, NT_STATUS_OK);
smb2_util_close(tree, h1);
/*
* Reopen the stream with the new name.
*/
io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
io.smb2.in.fname = sname2;
status = smb2_create(tree, mem_ctx, &(io.smb2));
CHECK_STATUS(status, NT_STATUS_OK);
h1 = io.smb2.out.file.handle;
/*
* Check SMB2 rename of a stream using :.
*/
torture_comment(tctx, "(%s) Checking SMB2 rename of a stream using "
":\n", __location__);
sinfo.rename_information.in.file.handle = h1;
sinfo.rename_information.in.new_name = sname1;
status = smb2_setinfo_file(tree, &sinfo);
CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
if (!torture_setting_bool(tctx, "samba4", false)) {
/*
* Check SMB2 rename to the default stream using :.
*/
torture_comment(tctx, "(%s) Checking SMB2 rename to default stream "
"using :\n", __location__);
sinfo.rename_information.in.file.handle = h1;
sinfo.rename_information.in.new_name = stream_name_default;
status = smb2_setinfo_file(tree, &sinfo);
CHECK_STATUS(status, NT_STATUS_OK);
}
smb2_util_close(tree, h1);
done:
smb2_util_close(tree, h1);
status = smb2_util_unlink(tree, fname1);
status = smb2_util_unlink(tree, fname2);
smb2_deltree(tree, DNAME);
talloc_free(mem_ctx);
return ret;
}
static bool create_file_with_stream(struct torture_context *tctx,
struct smb2_tree *tree,
TALLOC_CTX *mem_ctx,
const char *base_fname,
const char *stream)
{
NTSTATUS status;
bool ret = true;
union smb_open io;
/* Create a file with a stream */
ZERO_STRUCT(io.smb2);
io.smb2.in.create_flags = 0;
io.smb2.in.desired_access = SEC_FILE_READ_DATA |
SEC_FILE_WRITE_DATA |
SEC_FILE_APPEND_DATA |
SEC_STD_READ_CONTROL;
io.smb2.in.create_options = 0;
io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
io.smb2.in.share_access = 0;
io.smb2.in.alloc_size = 0;
io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
io.smb2.in.security_flags = 0;
io.smb2.in.fname = stream;
status = smb2_create(tree, mem_ctx, &(io.smb2));
CHECK_STATUS(status, NT_STATUS_OK);
done:
smb2_util_close(tree, io.smb2.out.file.handle);
return ret;
}
/* Test how streams interact with create dispositions */
static bool test_stream_create_disposition(struct torture_context *tctx,
struct smb2_tree *tree)
{
TALLOC_CTX *mem_ctx = talloc_new(tctx);
NTSTATUS status;
union smb_open io;
const char *fname = DNAME "\\stream_create_disp.txt";
const char *stream = "Stream One:$DATA";
const char *fname_stream;
const char *default_stream_name = "::$DATA";
const char *stream_list[2];
bool ret = true;
struct smb2_handle h = {{0}};
struct smb2_handle h1 = {{0}};
/* clean slate .. */
smb2_util_unlink(tree, fname);
smb2_deltree(tree, fname);
smb2_deltree(tree, DNAME);
status = torture_smb2_testdir(tree, DNAME, &h);
CHECK_STATUS(status, NT_STATUS_OK);
fname_stream = talloc_asprintf(mem_ctx, "%s:%s", fname, stream);
stream_list[0] = talloc_asprintf(mem_ctx, ":%s", stream);
stream_list[1] = default_stream_name;
if (!create_file_with_stream(tctx, tree, mem_ctx, fname,
fname_stream)) {
goto done;
}
/* Open the base file with OPEN */
ZERO_STRUCT(io.smb2);
io.smb2.in.create_flags = 0;
io.smb2.in.desired_access = SEC_FILE_READ_DATA |
SEC_FILE_WRITE_DATA |
SEC_FILE_APPEND_DATA |
SEC_STD_READ_CONTROL;
io.smb2.in.create_options = 0;
io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
io.smb2.in.share_access = 0;
io.smb2.in.alloc_size = 0;
io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
io.smb2.in.security_flags = 0;
io.smb2.in.fname = fname;
/*
* check create open: sanity check
*/
torture_comment(tctx, "(%s) Checking create disp: open\n",
__location__);
io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
status = smb2_create(tree, mem_ctx, &(io.smb2));
CHECK_STATUS(status, NT_STATUS_OK);
if (!check_stream_list(tree, tctx, fname, 2, stream_list,
io.smb2.out.file.handle)) {
goto done;
}
smb2_util_close(tree, io.smb2.out.file.handle);
/*
* check create overwrite
*/
torture_comment(tctx, "(%s) Checking create disp: overwrite\n",
__location__);
io.smb2.in.create_disposition = NTCREATEX_DISP_OVERWRITE;
status = smb2_create(tree, mem_ctx, &(io.smb2));
CHECK_STATUS(status, NT_STATUS_OK);
if (!check_stream_list(tree, tctx, fname, 1, &default_stream_name,
io.smb2.out.file.handle)) {
goto done;
}
smb2_util_close(tree, io.smb2.out.file.handle);
/*
* check create overwrite_if
*/
torture_comment(tctx, "(%s) Checking create disp: overwrite_if\n",
__location__);
smb2_util_unlink(tree, fname);
if (!create_file_with_stream(tctx, tree, mem_ctx, fname, fname_stream))
goto done;
io.smb2.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
status = smb2_create(tree, mem_ctx, &(io.smb2));
CHECK_STATUS(status, NT_STATUS_OK);
if (!check_stream_list(tree, tctx, fname, 1, &default_stream_name,
io.smb2.out.file.handle)) {
goto done;
}
smb2_util_close(tree, io.smb2.out.file.handle);
/*
* check create supersede
*/
torture_comment(tctx, "(%s) Checking create disp: supersede\n",
__location__);
smb2_util_unlink(tree, fname);
if (!create_file_with_stream(tctx, tree, mem_ctx, fname,
fname_stream)) {
goto done;
}
io.smb2.in.create_disposition = NTCREATEX_DISP_SUPERSEDE;
status = smb2_create(tree, mem_ctx, &(io.smb2));
CHECK_STATUS(status, NT_STATUS_OK);
if (!check_stream_list(tree, tctx, fname, 1, &default_stream_name,
io.smb2.out.file.handle)) {
goto done;
}
smb2_util_close(tree, io.smb2.out.file.handle);
/*
* check create overwrite_if on a stream.
*/
torture_comment(tctx, "(%s) Checking create disp: overwrite_if on "
"stream\n", __location__);
smb2_util_unlink(tree, fname);
if (!create_file_with_stream(tctx, tree, mem_ctx, fname,
fname_stream)) {
goto done;
}
io.smb2.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
io.smb2.in.fname = fname_stream;
status = smb2_create(tree, mem_ctx, &(io.smb2));
CHECK_STATUS(status, NT_STATUS_OK);
if (!check_stream_list(tree, tctx, fname, 2, stream_list,
io.smb2.out.file.handle)) {
goto done;
}
smb2_util_close(tree, io.smb2.out.file.handle);
done:
smb2_util_close(tree, h1);
smb2_util_unlink(tree, fname);
smb2_deltree(tree, DNAME);
talloc_free(mem_ctx);
return ret;
}
static bool open_stream(struct smb2_tree *tree,
struct torture_context *mem_ctx,
const char *fname,
struct smb2_handle *h_out)
{
NTSTATUS status;
union smb_open io;
ZERO_STRUCT(io.smb2);
io.smb2.in.create_flags = 0;
io.smb2.in.desired_access = SEC_FILE_READ_DATA |
SEC_FILE_WRITE_DATA |
SEC_FILE_APPEND_DATA |
SEC_STD_READ_CONTROL |
SEC_FILE_WRITE_ATTRIBUTE;
io.smb2.in.create_options = 0;
io.smb2.in.file_attributes = 0;
io.smb2.in.share_access = 0;
io.smb2.in.alloc_size = 0;
io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
io.smb2.in.security_flags = 0;
io.smb2.in.fname = fname;
status = smb2_create(tree, mem_ctx, &(io.smb2));
if (!NT_STATUS_IS_OK(status)) {
return false;
}
*h_out = io.smb2.out.file.handle;
return true;
}
/* Test the effect of setting attributes on a stream. */
static bool test_stream_attributes1(struct torture_context *tctx,
struct smb2_tree *tree)
{
TALLOC_CTX *mem_ctx = talloc_new(tctx);
bool ret = true;
NTSTATUS status;
union smb_open io;
const char *fname = DNAME "\\stream_attr.txt";
const char *stream = "Stream One:$DATA";
const char *fname_stream;
struct smb2_handle h, h1;
union smb_fileinfo finfo;
union smb_setfileinfo sfinfo;
time_t basetime = (time(NULL) - 86400) & ~1;
ZERO_STRUCT(h);
ZERO_STRUCT(h1);
torture_comment(tctx, "(%s) testing attribute setting on stream\n",
__location__);
/* clean slate .. */
smb2_util_unlink(tree, fname);
smb2_deltree(tree, fname);
smb2_deltree(tree, DNAME);
status = torture_smb2_testdir(tree, DNAME, &h);
CHECK_STATUS(status, NT_STATUS_OK);
fname_stream = talloc_asprintf(mem_ctx, "%s:%s", fname, stream);
/* Create a file with a stream with attribute FILE_ATTRIBUTE_ARCHIVE. */
ret = create_file_with_stream(tctx, tree, mem_ctx, fname,
fname_stream);
if (!ret) {
goto done;
}
ZERO_STRUCT(io.smb2);
io.smb2.in.fname = fname;
io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
io.smb2.in.desired_access = SEC_RIGHTS_FILE_ALL;
io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE;
status = smb2_create(tree, mem_ctx, &(io.smb2));
CHECK_STATUS(status, NT_STATUS_OK);
ZERO_STRUCT(finfo);
finfo.generic.level = RAW_FILEINFO_BASIC_INFORMATION;
finfo.generic.in.file.handle = io.smb2.out.file.handle;
status = smb2_getinfo_file(tree, mem_ctx, &finfo);
CHECK_STATUS(status, NT_STATUS_OK);
if (finfo.basic_info.out.attrib != FILE_ATTRIBUTE_ARCHIVE) {
torture_comment(tctx, "(%s) Incorrect attrib %x - should be "
"%x\n", __location__,
(unsigned int)finfo.basic_info.out.attrib,
(unsigned int)FILE_ATTRIBUTE_ARCHIVE);
ret = false;
goto done;
}
smb2_util_close(tree, io.smb2.out.file.handle);
/* Now open the stream name. */
if (!open_stream(tree, tctx, fname_stream, &h1)) {
goto done;
}
/* Change the time on the stream. */
ZERO_STRUCT(sfinfo);
unix_to_nt_time(&sfinfo.basic_info.in.write_time, basetime);
sfinfo.generic.level = RAW_SFILEINFO_BASIC_INFORMATION;
sfinfo.generic.in.file.handle = h1;
status = smb2_setinfo_file(tree, &sfinfo);
if (!NT_STATUS_EQUAL(status, NT_STATUS_OK)) {
torture_comment(tctx, "(%s) %s - %s (should be %s)\n",
__location__, "SETATTR",
nt_errstr(status), nt_errstr(NT_STATUS_OK));
ret = false;
goto done;
}
smb2_util_close(tree, h1);
ZERO_STRUCT(io.smb2);
io.smb2.in.fname = fname;
io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
io.smb2.in.desired_access = SEC_RIGHTS_FILE_ALL;
status = smb2_create(tree, mem_ctx, &(io.smb2));
CHECK_STATUS(status, NT_STATUS_OK);
h1 = io.smb2.out.file.handle;
ZERO_STRUCT(finfo);
finfo.generic.level = RAW_FILEINFO_BASIC_INFORMATION;
finfo.generic.in.file.handle = h1;
status = smb2_getinfo_file(tree, mem_ctx, &finfo);
if (!NT_STATUS_IS_OK(status)) {
torture_comment(tctx, "(%s) %s pathinfo - %s\n",
__location__, "SETATTRE", nt_errstr(status));
ret = false;
goto done;
}
if (nt_time_to_unix(finfo.basic_info.out.write_time) != basetime) {
torture_comment(tctx, "(%s) time incorrect.\n", __location__);
ret = false;
goto done;
}
smb2_util_close(tree, h1);
if (!open_stream(tree, tctx, fname_stream, &h1)) {
goto done;
}
/* Changing attributes on stream */
ZERO_STRUCT(sfinfo);
sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_READONLY;
sfinfo.generic.level = RAW_SFILEINFO_BASIC_INFORMATION;
sfinfo.generic.in.file.handle = h1;
status = smb2_setinfo_file(tree, &sfinfo);
if (!NT_STATUS_EQUAL(status, NT_STATUS_OK)) {
torture_comment(tctx, "(%s) %s - %s (should be %s)\n",
__location__, "SETATTR",
nt_errstr(status), nt_errstr(NT_STATUS_OK));
ret = false;
goto done;
}
smb2_util_close(tree, h1);
ZERO_STRUCT(io.smb2);
io.smb2.in.fname = fname;
io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
io.smb2.in.desired_access = SEC_FILE_READ_DATA;
status = smb2_create(tree, mem_ctx, &(io.smb2));
CHECK_STATUS(status, NT_STATUS_OK);
h1 = io.smb2.out.file.handle;
ZERO_STRUCT(finfo);
finfo.generic.level = RAW_FILEINFO_BASIC_INFORMATION;
finfo.generic.in.file.handle = h1;
status = smb2_getinfo_file(tree, mem_ctx, &finfo);
CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
done:
smb2_util_close(tree, h1);
smb2_util_unlink(tree, fname);
smb2_deltree(tree, DNAME);
talloc_free(mem_ctx);
return ret;
}
static bool check_metadata(struct torture_context *tctx,
struct smb2_tree *tree,
const char *path,
struct smb2_handle _h,
NTTIME expected_btime,
uint32_t expected_attribs)
{
struct smb2_handle h = _h;
union smb_fileinfo getinfo;
NTSTATUS status;
bool ret = true;
if (smb2_util_handle_empty(h)) {
struct smb2_create c;
c = (struct smb2_create) {
.in.desired_access = SEC_FILE_ALL,
.in.share_access = NTCREATEX_SHARE_ACCESS_MASK,
.in.file_attributes = FILE_ATTRIBUTE_HIDDEN,
.in.create_disposition = NTCREATEX_DISP_OPEN,
.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION,
.in.fname = path,
};
status = smb2_create(tree, tctx, &c);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_create failed\n");
h = c.out.file.handle;
}
getinfo = (union smb_fileinfo) {
.generic.level = SMB_QFILEINFO_BASIC_INFORMATION,
.generic.in.file.handle = h,
};
status = smb2_getinfo_file(tree, tctx, &getinfo);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_getinfo_file failed\n");
torture_assert_u64_equal_goto(tctx,
expected_btime,
getinfo.basic_info.out.create_time,
ret, done,
"btime was updated\n");
torture_assert_u32_equal_goto(tctx,
expected_attribs,
getinfo.basic_info.out.attrib,
ret, done,
"btime was updated\n");
done:
if (smb2_util_handle_empty(_h)) {
smb2_util_close(tree, h);
}
return ret;
}
static bool test_stream_attributes2(struct torture_context *tctx,
struct smb2_tree *tree)
{
NTSTATUS status;
struct smb2_create c1;
struct smb2_handle h1 = {{0}};
const char *fname = DNAME "\\test_stream_btime";
const char *sname = DNAME "\\test_stream_btime:stream";
union smb_fileinfo getinfo;
union smb_setfileinfo setinfo;
const char *data = "test data";
struct timespec ts;
NTTIME btime;
uint32_t attrib = FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_ARCHIVE;
bool ret;
smb2_deltree(tree, DNAME);
status = torture_smb2_testdir(tree, DNAME, &h1);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"torture_smb2_testdir failed\n");
smb2_util_close(tree, h1);
torture_comment(tctx, "Let's dance!\n");
/*
* Step 1: create file and get creation date
*/
c1 = (struct smb2_create) {
.in.desired_access = SEC_FILE_ALL,
.in.share_access = NTCREATEX_SHARE_ACCESS_MASK,
.in.file_attributes = FILE_ATTRIBUTE_HIDDEN,
.in.create_disposition = NTCREATEX_DISP_CREATE,
.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION,
.in.fname = fname,
};
status = smb2_create(tree, tctx, &c1);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_create failed\n");
h1 = c1.out.file.handle;
getinfo = (union smb_fileinfo) {
.generic.level = SMB_QFILEINFO_BASIC_INFORMATION,
.generic.in.file.handle = h1,
};
status = smb2_getinfo_file(tree, tctx, &getinfo);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_getinfo_file failed\n");
btime = getinfo.basic_info.out.create_time;
status = smb2_util_close(tree, h1);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_util_close failed\n");
ZERO_STRUCT(h1);
/*
* Step X: write to file, assert btime was not updated
*/
c1 = (struct smb2_create) {
.in.desired_access = SEC_FILE_ALL,
.in.share_access = NTCREATEX_SHARE_ACCESS_MASK,
.in.file_attributes = attrib,
.in.create_disposition = NTCREATEX_DISP_OPEN,
.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION,
.in.fname = fname,
};
status = smb2_create(tree, tctx, &c1);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_create failed\n");
h1 = c1.out.file.handle;
status = smb2_util_write(tree, h1, data, 0, strlen(data));
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_util_write failed\n");
ret = check_metadata(tctx, tree, NULL, h1, btime, attrib);
torture_assert_goto(tctx, ret, ret, done, "Bad metadata\n");
status = smb2_util_close(tree, h1);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_util_close failed\n");
ZERO_STRUCT(h1);
ret = check_metadata(tctx, tree, fname, (struct smb2_handle){{0}},
btime, attrib);
torture_assert_goto(tctx, ret, ret, done, "Bad metadata\n");
/*
* Step X: create stream, assert creation date is the same
* as the one on the basefile
*/
c1 = (struct smb2_create) {
.in.desired_access = SEC_FILE_ALL,
.in.share_access = NTCREATEX_SHARE_ACCESS_MASK,
.in.file_attributes = attrib,
.in.create_disposition = NTCREATEX_DISP_CREATE,
.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION,
.in.fname = sname,
};
status = smb2_create(tree, tctx, &c1);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_create failed\n");
h1 = c1.out.file.handle;
status = smb2_util_close(tree, h1);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_util_close failed\n");
ZERO_STRUCT(h1);
ret = check_metadata(tctx, tree, sname, (struct smb2_handle){{0}},
btime, attrib);
torture_assert_goto(tctx, ret, ret, done, "Bad metadata\n");
/*
* Step X: set btime on stream, verify basefile has the same btime.
*/
c1 = (struct smb2_create) {
.in.desired_access = SEC_FILE_ALL,
.in.share_access = NTCREATEX_SHARE_ACCESS_MASK,
.in.file_attributes = attrib,
.in.create_disposition = NTCREATEX_DISP_OPEN,
.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION,
.in.fname = sname,
};
status = smb2_create(tree, tctx, &c1);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_create failed\n");
h1 = c1.out.file.handle;
setinfo = (union smb_setfileinfo) {
.basic_info.level = RAW_SFILEINFO_BASIC_INFORMATION,
.basic_info.in.file.handle = h1,
};
clock_gettime_mono(&ts);
btime = setinfo.basic_info.in.create_time = full_timespec_to_nt_time(&ts);
status = smb2_setinfo_file(tree, &setinfo);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_setinfo_file failed\n");
ret = check_metadata(tctx, tree, NULL, h1, btime, attrib);
torture_assert_goto(tctx, ret, ret, done, "Bad time on stream\n");
status = smb2_util_close(tree, h1);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_util_close failed\n");
ZERO_STRUCT(h1);
ret = check_metadata(tctx, tree, fname, (struct smb2_handle){{0}},
btime, attrib);
torture_assert_goto(tctx, ret, ret, done, "Bad time on basefile\n");
ret = check_metadata(tctx, tree, sname, (struct smb2_handle){{0}},
btime, attrib);
torture_assert_goto(tctx, ret, ret, done, "Bad time on stream\n");
/*
* Step X: write to stream, assert btime was not updated
*/
c1 = (struct smb2_create) {
.in.desired_access = SEC_FILE_ALL,
.in.share_access = NTCREATEX_SHARE_ACCESS_MASK,
.in.file_attributes = attrib,
.in.create_disposition = NTCREATEX_DISP_OPEN,
.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION,
.in.fname = sname,
};
status = smb2_create(tree, tctx, &c1);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_create failed\n");
h1 = c1.out.file.handle;
status = smb2_util_write(tree, h1, data, 0, strlen(data));
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_util_write failed\n");
ret = check_metadata(tctx, tree, NULL, h1, btime, attrib);
torture_assert_goto(tctx, ret, ret, done, "Bad metadata\n");
status = smb2_util_close(tree, h1);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_util_close failed\n");
ZERO_STRUCT(h1);
ret = check_metadata(tctx, tree, fname, (struct smb2_handle){{0}},
btime, attrib);
torture_assert_goto(tctx, ret, ret, done, "Bad metadata\n");
ret = check_metadata(tctx, tree, sname, (struct smb2_handle){{0}},
btime, attrib);
torture_assert_goto(tctx, ret, ret, done, "Bad metadata\n");
/*
* Step X: modify attributes via stream, verify it's "also" set on the
* basefile.
*/
c1 = (struct smb2_create) {
.in.desired_access = SEC_FILE_ALL,
.in.share_access = NTCREATEX_SHARE_ACCESS_MASK,
.in.file_attributes = attrib,
.in.create_disposition = NTCREATEX_DISP_OPEN,
.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION,
.in.fname = sname,
};
status = smb2_create(tree, tctx, &c1);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_create failed\n");
h1 = c1.out.file.handle;
attrib = FILE_ATTRIBUTE_NORMAL;
setinfo = (union smb_setfileinfo) {
.basic_info.level = RAW_SFILEINFO_BASIC_INFORMATION,
.basic_info.in.file.handle = h1,
.basic_info.in.attrib = attrib,
};
status = smb2_setinfo_file(tree, &setinfo);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_setinfo_file failed\n");
status = smb2_util_close(tree, h1);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_util_close failed\n");
ZERO_STRUCT(h1);
ret = check_metadata(tctx, tree, fname, (struct smb2_handle){{0}},
btime, attrib);
torture_assert_goto(tctx, ret, ret, done, "Bad metadata\n");
ret = check_metadata(tctx, tree, sname, (struct smb2_handle){{0}},
btime, attrib);
torture_assert_goto(tctx, ret, ret, done, "Bad metadata\n");
/*
* Step X: modify attributes via basefile, verify it's "also" set on the
* stream.
*/
c1 = (struct smb2_create) {
.in.desired_access = SEC_FILE_ALL,
.in.share_access = NTCREATEX_SHARE_ACCESS_MASK,
.in.file_attributes = attrib,
.in.create_disposition = NTCREATEX_DISP_OPEN,
.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION,
.in.fname = fname,
};
status = smb2_create(tree, tctx, &c1);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_create failed\n");
h1 = c1.out.file.handle;
attrib = FILE_ATTRIBUTE_HIDDEN;
setinfo = (union smb_setfileinfo) {
.basic_info.level = RAW_SFILEINFO_BASIC_INFORMATION,
.basic_info.in.file.handle = h1,
.basic_info.in.attrib = attrib,
};
status = smb2_setinfo_file(tree, &setinfo);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_setinfo_file failed\n");
status = smb2_util_close(tree, h1);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_util_close failed\n");
ZERO_STRUCT(h1);
ret = check_metadata(tctx, tree, fname, (struct smb2_handle){{0}},
btime, attrib);
torture_assert_goto(tctx, ret, ret, done, "Bad metadata\n");
ret = check_metadata(tctx, tree, sname, (struct smb2_handle){{0}},
btime, attrib);
torture_assert_goto(tctx, ret, ret, done, "Bad metadata\n");
done:
if (!smb2_util_handle_empty(h1)) {
smb2_util_close(tree, h1);
}
smb2_deltree(tree, DNAME);
return ret;
}
static bool test_basefile_rename_with_open_stream(struct torture_context *tctx,
struct smb2_tree *tree)
{
bool ret = true;
NTSTATUS status;
struct smb2_tree *tree2 = NULL;
struct smb2_create create, create2;
struct smb2_handle h1 = {{0}}, h2 = {{0}};
const char *fname = "test_rename_openfile";
const char *sname = "test_rename_openfile:foo";
const char *fname_renamed = "test_rename_openfile_renamed";
union smb_setfileinfo sinfo;
const char *data = "test data";
ret = torture_smb2_connection(tctx, &tree2);
torture_assert_goto(tctx, ret == true, ret, done,
"torture_smb2_connection failed\n");
torture_comment(tctx, "Creating file with stream\n");
ZERO_STRUCT(create);
create.in.desired_access = SEC_FILE_ALL;
create.in.share_access = NTCREATEX_SHARE_ACCESS_MASK;
create.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
create.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
create.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION;
create.in.fname = sname;
status = smb2_create(tree, tctx, &create);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_create failed\n");
h1 = create.out.file.handle;
torture_comment(tctx, "Writing to stream\n");
status = smb2_util_write(tree, h1, data, 0, strlen(data));
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_util_write failed\n");
torture_comment(tctx, "Renaming base file\n");
ZERO_STRUCT(create2);
create2.in.desired_access = SEC_FILE_ALL;
create2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
create2.in.share_access = NTCREATEX_SHARE_ACCESS_MASK;
create2.in.create_disposition = NTCREATEX_DISP_OPEN;
create2.in.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION;
create2.in.fname = fname;
status = smb2_create(tree2, tctx, &create2);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_create failed\n");
h2 = create2.out.file.handle;
ZERO_STRUCT(sinfo);
sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
sinfo.rename_information.in.file.handle = h2;
sinfo.rename_information.in.new_name = fname_renamed;
status = smb2_setinfo_file(tree2, &sinfo);
torture_assert_ntstatus_equal_goto(
tctx, status, NT_STATUS_ACCESS_DENIED, ret, done,
"smb2_setinfo_file didn't return NT_STATUS_ACCESS_DENIED\n");
smb2_util_close(tree2, h2);
done:
if (!smb2_util_handle_empty(h1)) {
smb2_util_close(tree, h1);
}
if (!smb2_util_handle_empty(h2)) {
smb2_util_close(tree2, h2);
}
smb2_util_unlink(tree, fname);
smb2_util_unlink(tree, fname_renamed);
return ret;
}
/*
* Simple test creating a stream on a share with "inherit permissions"
* enabled. This tests specifically bug 15695.
*/
bool test_stream_inherit_perms(struct torture_context *tctx,
struct smb2_tree *tree)
{
NTSTATUS status;
struct smb2_handle h = {};
union smb_fileinfo q = {};
union smb_setfileinfo setinfo = {};
struct security_descriptor *sd = NULL;
struct security_ace ace = {};
const char *fname = DNAME "\\test_stream_inherit_perms:stream";
bool ret = true;
smb2_deltree(tree, DNAME);
status = torture_smb2_testdir(tree, DNAME, &h);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"torture_smb2_testdir failed\n");
torture_comment(tctx, "getting original sd\n");
q.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
q.query_secdesc.in.file.handle = h;
q.query_secdesc.in.secinfo_flags = SECINFO_DACL | SECINFO_OWNER;
status = smb2_getinfo_file(tree, tctx, &q);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_getinfo_file failed\n");
sd = q.query_secdesc.out.sd;
/*
* Add one explicit non-inheriting ACE which will be stored
* as a non-inheriting POSIX ACE. These are the ACEs that
* "inherit permissions" will want to inherit.
*/
ace.type = SEC_ACE_TYPE_ACCESS_ALLOWED;
ace.access_mask = SEC_STD_ALL;
ace.trustee = *(sd->owner_sid);
status = security_descriptor_dacl_add(sd, &ace);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"security_descriptor_dacl_add failed\n");
setinfo.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
setinfo.set_secdesc.in.file.handle = h;
setinfo.set_secdesc.in.secinfo_flags = SECINFO_DACL;
setinfo.set_secdesc.in.sd = sd;
status = smb2_setinfo_file(tree, &setinfo);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"smb2_setinfo_file failed");
smb2_util_close(tree, h);
ZERO_STRUCT(h);
/* This triggers the crash */
status = torture_smb2_testfile(tree, fname, &h);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"torture_smb2_testfile failed");
done:
if (!smb2_util_handle_empty(h)) {
smb2_util_close(tree, h);
}
smb2_deltree(tree, DNAME);
return ret;
}
/*
basic testing of streams calls SMB2
*/
struct torture_suite *torture_smb2_streams_init(TALLOC_CTX *ctx)
{
struct torture_suite *suite =
torture_suite_create(ctx, "streams");
torture_suite_add_1smb2_test(suite, "dir", test_stream_dir);
torture_suite_add_1smb2_test(suite, "io", test_stream_io);
torture_suite_add_1smb2_test(suite, "sharemodes", test_stream_sharemodes);
torture_suite_add_1smb2_test(suite, "names", test_stream_names);
torture_suite_add_1smb2_test(suite, "names2", test_stream_names2);
torture_suite_add_1smb2_test(suite, "names3", test_stream_names3);
torture_suite_add_1smb2_test(suite, "rename", test_stream_rename);
torture_suite_add_1smb2_test(suite, "rename2", test_stream_rename2);
torture_suite_add_1smb2_test(suite, "create-disposition", test_stream_create_disposition);
torture_suite_add_1smb2_test(suite, "attributes1", test_stream_attributes1);
torture_suite_add_1smb2_test(suite, "attributes2", test_stream_attributes2);
torture_suite_add_1smb2_test(suite, "delete", test_stream_delete);
torture_suite_add_1smb2_test(suite, "zero-byte", test_zero_byte_stream);
torture_suite_add_1smb2_test(suite, "basefile-rename-with-open-stream",
test_basefile_rename_with_open_stream);
suite->description = talloc_strdup(suite, "SMB2-STREAM tests");
return suite;
}