wmi-1.3.16 from opsview.com

This commit is contained in:
Are Casilla
2019-02-16 00:16:52 +01:00
parent 163fdd3d1b
commit 17b3af2911
2146 changed files with 678824 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
#################################
# Start SUBSYSTEM TORTURE_SMB2
[MODULE::TORTURE_SMB2]
SUBSYSTEM = torture
INIT_FUNCTION = torture_smb2_init
PRIVATE_PROTO_HEADER = \
proto.h
OBJ_FILES = \
connect.o \
scan.o \
util.o \
getinfo.o \
setinfo.o \
find.o \
lock.o \
notify.o \
smb2.o
PUBLIC_DEPENDENCIES = \
LIBCLI_SMB2 POPT_CREDENTIALS
# End SUBSYSTEM TORTURE_SMB2
#################################
+260
View File
@@ -0,0 +1,260 @@
/*
Unix SMB/CIFS implementation.
test suite for SMB2 connection operations
Copyright (C) Andrew Tridgell 2005
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 2 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, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "librpc/gen_ndr/security.h"
#include "libcli/smb2/smb2.h"
#include "libcli/smb2/smb2_calls.h"
#include "torture/torture.h"
#include "torture/smb2/proto.h"
/*
send a close
*/
static NTSTATUS torture_smb2_close(struct smb2_tree *tree, struct smb2_handle handle)
{
struct smb2_close io;
NTSTATUS status;
TALLOC_CTX *tmp_ctx = talloc_new(tree);
ZERO_STRUCT(io);
io.in.file.handle = handle;
io.in.flags = SMB2_CLOSE_FLAGS_FULL_INFORMATION;
status = smb2_close(tree, &io);
if (!NT_STATUS_IS_OK(status)) {
printf("close failed - %s\n", nt_errstr(status));
return status;
}
if (DEBUGLVL(1)) {
printf("Close gave:\n");
printf("create_time = %s\n", nt_time_string(tmp_ctx, io.out.create_time));
printf("access_time = %s\n", nt_time_string(tmp_ctx, io.out.access_time));
printf("write_time = %s\n", nt_time_string(tmp_ctx, io.out.write_time));
printf("change_time = %s\n", nt_time_string(tmp_ctx, io.out.change_time));
printf("alloc_size = %lld\n", (long long)io.out.alloc_size);
printf("size = %lld\n", (long long)io.out.size);
printf("file_attr = 0x%x\n", io.out.file_attr);
}
talloc_free(tmp_ctx);
return status;
}
/*
test writing
*/
static NTSTATUS torture_smb2_write(struct smb2_tree *tree, struct smb2_handle handle)
{
struct smb2_write w;
struct smb2_read r;
struct smb2_flush f;
NTSTATUS status;
DATA_BLOB data;
int i;
if (lp_parm_bool(-1, "torture", "dangerous", False)) {
data = data_blob_talloc(tree, NULL, 160000);
} else if (lp_parm_bool(-1, "torture", "samba4", False)) {
data = data_blob_talloc(tree, NULL, UINT16_MAX);
} else {
data = data_blob_talloc(tree, NULL, 120000);
}
for (i=0;i<data.length;i++) {
data.data[i] = i;
}
ZERO_STRUCT(w);
w.in.file.handle = handle;
w.in.offset = 0;
w.in.data = data;
status = smb2_write(tree, &w);
if (!NT_STATUS_IS_OK(status)) {
printf("write failed - %s\n", nt_errstr(status));
return status;
}
torture_smb2_all_info(tree, handle);
status = smb2_write(tree, &w);
if (!NT_STATUS_IS_OK(status)) {
printf("write failed - %s\n", nt_errstr(status));
return status;
}
torture_smb2_all_info(tree, handle);
ZERO_STRUCT(f);
f.in.file.handle = handle;
status = smb2_flush(tree, &f);
if (!NT_STATUS_IS_OK(status)) {
printf("flush failed - %s\n", nt_errstr(status));
return status;
}
ZERO_STRUCT(r);
r.in.file.handle = handle;
r.in.length = data.length;
r.in.offset = 0;
status = smb2_read(tree, tree, &r);
if (!NT_STATUS_IS_OK(status)) {
printf("read failed - %s\n", nt_errstr(status));
return status;
}
if (data.length != r.out.data.length ||
memcmp(data.data, r.out.data.data, data.length) != 0) {
printf("read data mismatch\n");
return NT_STATUS_NET_WRITE_FAULT;
}
return status;
}
/*
send a create
*/
static struct smb2_handle torture_smb2_create(struct smb2_tree *tree,
const char *fname)
{
struct smb2_create io;
NTSTATUS status;
TALLOC_CTX *tmp_ctx = talloc_new(tree);
ZERO_STRUCT(io);
io.in.oplock_flags = 0;
io.in.access_mask = SEC_RIGHTS_FILE_ALL;
io.in.file_attr = FILE_ATTRIBUTE_NORMAL;
io.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
io.in.share_access =
NTCREATEX_SHARE_ACCESS_DELETE|
NTCREATEX_SHARE_ACCESS_READ|
NTCREATEX_SHARE_ACCESS_WRITE;
io.in.create_options = NTCREATEX_OPTIONS_WRITE_THROUGH;
io.in.fname = fname;
status = smb2_create(tree, tmp_ctx, &io);
if (!NT_STATUS_IS_OK(status)) {
printf("create1 failed - %s\n", nt_errstr(status));
return io.out.file.handle;
}
if (DEBUGLVL(1)) {
printf("Open gave:\n");
printf("oplock_flags = 0x%x\n", io.out.oplock_flags);
printf("create_action = 0x%x\n", io.out.create_action);
printf("create_time = %s\n", nt_time_string(tmp_ctx, io.out.create_time));
printf("access_time = %s\n", nt_time_string(tmp_ctx, io.out.access_time));
printf("write_time = %s\n", nt_time_string(tmp_ctx, io.out.write_time));
printf("change_time = %s\n", nt_time_string(tmp_ctx, io.out.change_time));
printf("alloc_size = %lld\n", (long long)io.out.alloc_size);
printf("size = %lld\n", (long long)io.out.size);
printf("file_attr = 0x%x\n", io.out.file_attr);
printf("handle = %016llx%016llx\n",
(long long)io.out.file.handle.data[0],
(long long)io.out.file.handle.data[1]);
}
talloc_free(tmp_ctx);
return io.out.file.handle;
}
/*
basic testing of SMB2 connection calls
*/
BOOL torture_smb2_connect(struct torture_context *torture)
{
TALLOC_CTX *mem_ctx = talloc_new(NULL);
struct smb2_tree *tree;
struct smb2_handle h1, h2;
NTSTATUS status;
if (!torture_smb2_connection(mem_ctx, &tree)) {
return False;
}
h1 = torture_smb2_create(tree, "test9.dat");
h2 = torture_smb2_create(tree, "test9.dat");
status = torture_smb2_write(tree, h1);
if (!NT_STATUS_IS_OK(status)) {
printf("Write failed - %s\n", nt_errstr(status));
return False;
}
status = torture_smb2_close(tree, h1);
if (!NT_STATUS_IS_OK(status)) {
printf("Close failed - %s\n", nt_errstr(status));
return False;
}
status = torture_smb2_close(tree, h2);
if (!NT_STATUS_IS_OK(status)) {
printf("Close failed - %s\n", nt_errstr(status));
return False;
}
status = smb2_util_close(tree, h1);
if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
printf("close should have closed the handle - %s\n", nt_errstr(status));
return False;
}
status = smb2_tdis(tree);
if (!NT_STATUS_IS_OK(status)) {
printf("tdis failed - %s\n", nt_errstr(status));
return False;
}
status = smb2_tdis(tree);
if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
printf("tdis should have disabled session - %s\n", nt_errstr(status));
return False;
}
status = smb2_logoff(tree->session);
if (!NT_STATUS_IS_OK(status)) {
printf("Logoff failed - %s\n", nt_errstr(status));
return False;
}
status = smb2_logoff(tree->session);
if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
printf("Logoff should have disabled session - %s\n", nt_errstr(status));
return False;
}
status = smb2_keepalive(tree->session->transport);
if (!NT_STATUS_IS_OK(status)) {
printf("keepalive failed? - %s\n", nt_errstr(status));
return False;
}
talloc_free(mem_ctx);
return True;
}
+94
View File
@@ -0,0 +1,94 @@
/*
Unix SMB/CIFS implementation.
SMB2 dir list test suite
Copyright (C) Andrew Tridgell 2005
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 2 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, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "libcli/smb2/smb2.h"
#include "libcli/smb2/smb2_calls.h"
#include "torture/torture.h"
#include "torture/smb2/proto.h"
/*
test find continue
*/
static BOOL torture_smb2_find_dir(struct smb2_tree *tree)
{
struct smb2_handle handle;
NTSTATUS status;
int i;
struct smb2_find f;
BOOL ret = True;
union smb_search_data *d;
uint_t count;
status = smb2_util_roothandle(tree, &handle);
if (!NT_STATUS_IS_OK(status)) {
return False;
}
ZERO_STRUCT(f);
f.in.file.handle = handle;
f.in.pattern = "*";
f.in.continue_flags = SMB2_CONTINUE_FLAG_SINGLE;
f.in.max_response_size = 0x100;
f.in.level = SMB2_FIND_BOTH_DIRECTORY_INFO;
do {
status = smb2_find_level(tree, tree, &f, &count, &d);
if (!NT_STATUS_IS_OK(status)) {
printf("SMB2_FIND_ID_BOTH_DIRECTORY_INFO failed - %s\n", nt_errstr(status));
break;
}
printf("Got %d files\n", count);
for (i=0;i<count;i++) {
printf("\t'%s'\n",
d[i].both_directory_info.name.s);
}
f.in.continue_flags = 0;
f.in.max_response_size = 4096;
} while (count != 0);
return ret;
}
/*
basic testing of directory listing with continue
*/
BOOL torture_smb2_dir(struct torture_context *torture)
{
TALLOC_CTX *mem_ctx = talloc_new(NULL);
struct smb2_tree *tree;
BOOL ret = True;
if (!torture_smb2_connection(mem_ctx, &tree)) {
return False;
}
ret &= torture_smb2_find_dir(tree);
talloc_free(mem_ctx);
return ret;
}
+221
View File
@@ -0,0 +1,221 @@
/*
Unix SMB/CIFS implementation.
SMB2 find test suite
Copyright (C) Andrew Tridgell 2005
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 2 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, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "libcli/smb2/smb2.h"
#include "libcli/smb2/smb2_calls.h"
#include "torture/torture.h"
#include "torture/smb2/proto.h"
static struct {
const char *name;
uint16_t level;
NTSTATUS status;
union smb_search_data data;
} levels[] = {
#define LEVEL(x) #x, x
{ LEVEL(SMB2_FIND_ID_BOTH_DIRECTORY_INFO) },
{ LEVEL(SMB2_FIND_DIRECTORY_INFO) },
{ LEVEL(SMB2_FIND_FULL_DIRECTORY_INFO) },
{ LEVEL(SMB2_FIND_NAME_INFO) },
{ LEVEL(SMB2_FIND_BOTH_DIRECTORY_INFO) },
{ LEVEL(SMB2_FIND_ID_FULL_DIRECTORY_INFO) },
};
#define FNAME "smb2-find.dat"
#define CHECK_VALUE(call_name, stype, field) do { \
union smb_search_data *d = find_level("SMB2_FIND_" #call_name); \
if (io.all_info2.out.field != d->stype.field) { \
printf("(%s) %s/%s should be 0x%llx - 0x%llx\n", __location__, \
#call_name, #field, \
(long long)io.all_info2.out.field, (long long)d->stype.field); \
ret = False; \
}} while (0)
#define CHECK_CONST_STRING(call_name, stype, field, str) do { \
union smb_search_data *d = find_level("SMB2_FIND_" #call_name); \
if (strcmp(str, d->stype.field.s) != 0) { \
printf("(%s) %s/%s should be '%s' - '%s'\n", __location__, \
#call_name, #field, \
str, d->stype.field.s); \
ret = False; \
}} while (0)
static union smb_search_data *find_level(const char *name)
{
int i;
for (i=0;i<ARRAY_SIZE(levels);i++) {
if (strcmp(name, levels[i].name) == 0) {
return &levels[i].data;
}
}
return NULL;
}
/*
test find levels
*/
static BOOL torture_smb2_find_levels(struct smb2_tree *tree)
{
struct smb2_handle handle;
NTSTATUS status;
int i;
struct smb2_find f;
BOOL ret = True;
union smb_fileinfo io;
const char *alt_name;
status = smb2_create_complex_file(tree, FNAME, &handle);
if (!NT_STATUS_IS_OK(status)) {
return False;
}
io.generic.level = RAW_FILEINFO_ALT_NAME_INFORMATION;
io.generic.in.file.handle = handle;
status = smb2_getinfo_file(tree, tree, &io);
if (!NT_STATUS_IS_OK(status)) {
return False;
}
alt_name = talloc_strdup(tree, io.alt_name_info.out.fname.s);
io.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
io.generic.in.file.handle = handle;
status = smb2_getinfo_file(tree, tree, &io);
if (!NT_STATUS_IS_OK(status)) {
return False;
}
status = smb2_util_roothandle(tree, &handle);
if (!NT_STATUS_IS_OK(status)) {
return False;
}
ZERO_STRUCT(f);
f.in.file.handle = handle;
f.in.pattern = FNAME;
f.in.continue_flags = SMB2_CONTINUE_FLAG_RESTART;
f.in.max_response_size = 0x10000;
for (i=0;i<ARRAY_SIZE(levels);i++) {
union smb_search_data *d;
uint_t count;
f.in.level = levels[i].level - 0x100;
levels[i].status = smb2_find_level(tree, tree, &f, &count, &d);
if (!NT_STATUS_IS_OK(levels[i].status)) {
printf("%s failed - %s\n", levels[i].name,
nt_errstr(levels[i].status));
}
if (count != 1) {
printf("Expected count 1 - got %d in %s\n", count, levels[i].name);
ret = False;
}
levels[i].data = d[0];
}
CHECK_VALUE(DIRECTORY_INFO, directory_info, create_time);
CHECK_VALUE(DIRECTORY_INFO, directory_info, access_time);
CHECK_VALUE(DIRECTORY_INFO, directory_info, write_time);
CHECK_VALUE(DIRECTORY_INFO, directory_info, change_time);
CHECK_VALUE(DIRECTORY_INFO, directory_info, size);
CHECK_VALUE(DIRECTORY_INFO, directory_info, alloc_size);
CHECK_VALUE(DIRECTORY_INFO, directory_info, attrib);
CHECK_CONST_STRING(DIRECTORY_INFO, directory_info, name, FNAME);
CHECK_VALUE(FULL_DIRECTORY_INFO, full_directory_info, create_time);
CHECK_VALUE(FULL_DIRECTORY_INFO, full_directory_info, access_time);
CHECK_VALUE(FULL_DIRECTORY_INFO, full_directory_info, write_time);
CHECK_VALUE(FULL_DIRECTORY_INFO, full_directory_info, change_time);
CHECK_VALUE(FULL_DIRECTORY_INFO, full_directory_info, size);
CHECK_VALUE(FULL_DIRECTORY_INFO, full_directory_info, alloc_size);
CHECK_VALUE(FULL_DIRECTORY_INFO, full_directory_info, attrib);
CHECK_VALUE(FULL_DIRECTORY_INFO, full_directory_info, ea_size);
CHECK_CONST_STRING(FULL_DIRECTORY_INFO, full_directory_info, name, FNAME);
CHECK_VALUE(BOTH_DIRECTORY_INFO, both_directory_info, create_time);
CHECK_VALUE(BOTH_DIRECTORY_INFO, both_directory_info, access_time);
CHECK_VALUE(BOTH_DIRECTORY_INFO, both_directory_info, write_time);
CHECK_VALUE(BOTH_DIRECTORY_INFO, both_directory_info, change_time);
CHECK_VALUE(BOTH_DIRECTORY_INFO, both_directory_info, size);
CHECK_VALUE(BOTH_DIRECTORY_INFO, both_directory_info, alloc_size);
CHECK_VALUE(BOTH_DIRECTORY_INFO, both_directory_info, attrib);
CHECK_VALUE(BOTH_DIRECTORY_INFO, both_directory_info, ea_size);
CHECK_CONST_STRING(BOTH_DIRECTORY_INFO, both_directory_info, short_name, alt_name);
CHECK_CONST_STRING(BOTH_DIRECTORY_INFO, both_directory_info, name, FNAME);
CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, create_time);
CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, access_time);
CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, write_time);
CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, change_time);
CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, size);
CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, alloc_size);
CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, attrib);
CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, ea_size);
CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, file_id);
CHECK_CONST_STRING(ID_FULL_DIRECTORY_INFO, id_full_directory_info, name, FNAME);
CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, create_time);
CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, access_time);
CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, write_time);
CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, change_time);
CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, size);
CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, alloc_size);
CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, attrib);
CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, ea_size);
CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, file_id);
CHECK_CONST_STRING(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, name, FNAME);
return ret;
}
/* basic testing of all SMB2 find levels
*/
BOOL torture_smb2_find(struct torture_context *torture)
{
TALLOC_CTX *mem_ctx = talloc_new(NULL);
struct smb2_tree *tree;
BOOL ret = True;
NTSTATUS status;
if (!torture_smb2_connection(mem_ctx, &tree)) {
return False;
}
status = torture_setup_complex_file(tree, FNAME);
if (!NT_STATUS_IS_OK(status)) {
return False;
}
torture_setup_complex_file(tree, FNAME ":streamtwo");
ret &= torture_smb2_find_levels(tree);
talloc_free(mem_ctx);
return ret;
}
+200
View File
@@ -0,0 +1,200 @@
/*
Unix SMB/CIFS implementation.
SMB2 getinfo test suite
Copyright (C) Andrew Tridgell 2005
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 2 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, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "libcli/smb2/smb2.h"
#include "libcli/smb2/smb2_calls.h"
#include "torture/torture.h"
#include "torture/smb2/proto.h"
static struct {
const char *name;
uint16_t level;
NTSTATUS fstatus;
NTSTATUS dstatus;
union smb_fileinfo finfo;
union smb_fileinfo dinfo;
} file_levels[] = {
#define LEVEL(x) #x, x
{ LEVEL(RAW_FILEINFO_BASIC_INFORMATION) },
{ LEVEL(RAW_FILEINFO_STANDARD_INFORMATION) },
{ LEVEL(RAW_FILEINFO_INTERNAL_INFORMATION) },
{ LEVEL(RAW_FILEINFO_EA_INFORMATION) },
{ LEVEL(RAW_FILEINFO_ACCESS_INFORMATION) },
{ LEVEL(RAW_FILEINFO_POSITION_INFORMATION) },
{ LEVEL(RAW_FILEINFO_MODE_INFORMATION) },
{ LEVEL(RAW_FILEINFO_ALIGNMENT_INFORMATION) },
{ LEVEL(RAW_FILEINFO_ALL_INFORMATION) },
{ LEVEL(RAW_FILEINFO_ALT_NAME_INFORMATION) },
{ LEVEL(RAW_FILEINFO_STREAM_INFORMATION) },
{ LEVEL(RAW_FILEINFO_COMPRESSION_INFORMATION) },
{ LEVEL(RAW_FILEINFO_NETWORK_OPEN_INFORMATION) },
{ LEVEL(RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION) },
{ LEVEL(RAW_FILEINFO_SMB2_ALL_EAS) },
{ LEVEL(RAW_FILEINFO_SMB2_ALL_INFORMATION) },
{ LEVEL(RAW_FILEINFO_SEC_DESC) }
};
static struct {
const char *name;
uint16_t level;
NTSTATUS status;
union smb_fsinfo info;
} fs_levels[] = {
{ LEVEL(RAW_QFS_VOLUME_INFORMATION) },
{ LEVEL(RAW_QFS_SIZE_INFORMATION) },
{ LEVEL(RAW_QFS_DEVICE_INFORMATION) },
{ LEVEL(RAW_QFS_ATTRIBUTE_INFORMATION) },
{ LEVEL(RAW_QFS_QUOTA_INFORMATION) },
{ LEVEL(RAW_QFS_FULL_SIZE_INFORMATION) },
{ LEVEL(RAW_QFS_OBJECTID_INFORMATION) }
};
#define FNAME "testsmb2_file.dat"
#define DNAME "testsmb2_dir"
/*
test fileinfo levels
*/
static BOOL torture_smb2_fileinfo(struct smb2_tree *tree)
{
struct smb2_handle hfile, hdir;
NTSTATUS status;
int i;
status = torture_smb2_testfile(tree, FNAME, &hfile);
if (!NT_STATUS_IS_OK(status)) {
printf("Unable to create test file '%s' - %s\n", FNAME, nt_errstr(status));
goto failed;
}
status = torture_smb2_testdir(tree, DNAME, &hdir);
if (!NT_STATUS_IS_OK(status)) {
printf("Unable to create test directory '%s' - %s\n", DNAME, nt_errstr(status));
goto failed;
}
printf("Testing file info levels\n");
torture_smb2_all_info(tree, hfile);
torture_smb2_all_info(tree, hdir);
for (i=0;i<ARRAY_SIZE(file_levels);i++) {
if (file_levels[i].level == RAW_FILEINFO_SEC_DESC) {
file_levels[i].finfo.query_secdesc.in.secinfo_flags = 0x7;
file_levels[i].dinfo.query_secdesc.in.secinfo_flags = 0x7;
}
if (file_levels[i].level == RAW_FILEINFO_SMB2_ALL_EAS) {
if (lp_parm_bool(-1, "torture", "samba4", False)) {
continue;
}
file_levels[i].finfo.all_eas.in.continue_flags =
SMB2_CONTINUE_FLAG_RESTART;
file_levels[i].dinfo.all_eas.in.continue_flags =
SMB2_CONTINUE_FLAG_RESTART;
}
file_levels[i].finfo.generic.level = file_levels[i].level;
file_levels[i].finfo.generic.in.file.handle = hfile;
file_levels[i].fstatus = smb2_getinfo_file(tree, tree, &file_levels[i].finfo);
if (!NT_STATUS_IS_OK(file_levels[i].fstatus)) {
printf("(%s) %s failed on file - %s\n", __location__,
file_levels[i].name, nt_errstr(file_levels[i].fstatus));
goto failed;
}
file_levels[i].dinfo.generic.level = file_levels[i].level;
file_levels[i].dinfo.generic.in.file.handle = hdir;
file_levels[i].dstatus = smb2_getinfo_file(tree, tree, &file_levels[i].dinfo);
if (!NT_STATUS_IS_OK(file_levels[i].dstatus)) {
printf("(%s) %s failed on dir - %s\n", __location__,
file_levels[i].name, nt_errstr(file_levels[i].dstatus));
goto failed;
}
}
return True;
failed:
return False;
}
/*
test fsinfo levels
*/
static BOOL torture_smb2_fsinfo(struct smb2_tree *tree)
{
int i;
NTSTATUS status;
struct smb2_handle handle;
printf("Testing fsinfo levels\n");
status = smb2_util_roothandle(tree, &handle);
if (!NT_STATUS_IS_OK(status)) {
printf("Unable to create test directory '%s' - %s\n", DNAME, nt_errstr(status));
return False;
}
for (i=0;i<ARRAY_SIZE(fs_levels);i++) {
fs_levels[i].info.generic.level = fs_levels[i].level;
fs_levels[i].info.generic.handle = handle;
fs_levels[i].status = smb2_getinfo_fs(tree, tree, &fs_levels[i].info);
if (!NT_STATUS_IS_OK(fs_levels[i].status)) {
printf("%s failed - %s\n", fs_levels[i].name, nt_errstr(fs_levels[i].status));
return False;
}
}
return True;
}
/* basic testing of all SMB2 getinfo levels
*/
BOOL torture_smb2_getinfo(struct torture_context *torture)
{
TALLOC_CTX *mem_ctx = talloc_new(NULL);
struct smb2_tree *tree;
BOOL ret = True;
NTSTATUS status;
if (!torture_smb2_connection(mem_ctx, &tree)) {
return False;
}
status = torture_setup_complex_file(tree, FNAME);
if (!NT_STATUS_IS_OK(status)) {
return False;
}
torture_setup_complex_file(tree, FNAME ":streamtwo");
status = torture_setup_complex_dir(tree, DNAME);
if (!NT_STATUS_IS_OK(status)) {
return False;
}
torture_setup_complex_file(tree, DNAME ":streamtwo");
ret &= torture_smb2_fileinfo(tree);
ret &= torture_smb2_fsinfo(tree);
talloc_free(mem_ctx);
return ret;
}
+215
View File
@@ -0,0 +1,215 @@
/*
Unix SMB/CIFS implementation.
SMB2 lock test suite
Copyright (C) Stefan Metzmacher 2006
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 2 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, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "libcli/smb2/smb2.h"
#include "libcli/smb2/smb2_calls.h"
#include "torture/torture.h"
#include "torture/smb2/proto.h"
#define CHECK_STATUS(status, correct) do { \
if (!NT_STATUS_EQUAL(status, correct)) { \
printf("(%s) Incorrect status %s - should be %s\n", \
__location__, nt_errstr(status), nt_errstr(correct)); \
ret = False; \
goto done; \
}} while (0)
#define CHECK_VALUE(v, correct) do { \
if ((v) != (correct)) { \
printf("(%s) Incorrect value %s=%d - should be %d\n", \
__location__, #v, v, correct); \
ret = False; \
goto done; \
}} while (0)
static BOOL test_valid_request(TALLOC_CTX *mem_ctx, struct smb2_tree *tree)
{
BOOL ret = True;
NTSTATUS status;
struct smb2_handle h;
uint8_t buf[200];
struct smb2_lock lck;
ZERO_STRUCT(buf);
status = torture_smb2_testfile(tree, "lock1.txt", &h);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb2_util_write(tree, h, buf, 0, ARRAY_SIZE(buf));
CHECK_STATUS(status, NT_STATUS_OK);
lck.in.unknown1 = 0x0000;
lck.in.unknown2 = 0x00000000;
lck.in.file.handle = h;
lck.in.offset = 0x0000000000000000;
lck.in.count = 0x0000000000000000;
lck.in.unknown5 = 0x0000000000000000;
lck.in.flags = 0x00000000;
status = smb2_lock(tree, &lck);
CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
lck.in.unknown1 = 0x0001;
lck.in.unknown2 = 0x00000000;
lck.in.file.handle = h;
lck.in.offset = 0;
lck.in.count = 0;
lck.in.unknown5 = 0x00000000;
lck.in.flags = SMB2_LOCK_FLAG_NONE;
status = smb2_lock(tree, &lck);
CHECK_STATUS(status, NT_STATUS_OK);
CHECK_VALUE(lck.out.unknown1, 0);
lck.in.file.handle.data[0] +=1;
status = smb2_lock(tree, &lck);
CHECK_STATUS(status, NT_STATUS_FILE_CLOSED);
lck.in.file.handle.data[0] -=1;
lck.in.unknown1 = 0x0001;
lck.in.unknown2 = 0xFFFFFFFF;
lck.in.file.handle = h;
lck.in.offset = UINT64_MAX;
lck.in.count = UINT64_MAX;
lck.in.unknown5 = 0x00000000;
lck.in.flags = SMB2_LOCK_FLAG_EXCLUSIV;
status = smb2_lock(tree, &lck);
CHECK_STATUS(status, NT_STATUS_OK);
CHECK_VALUE(lck.out.unknown1, 0);
status = smb2_lock(tree, &lck);
CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
status = smb2_lock(tree, &lck);
CHECK_STATUS(status, NT_STATUS_OK);
CHECK_VALUE(lck.out.unknown1, 0);
status = smb2_lock(tree, &lck);
CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
status = smb2_lock(tree, &lck);
CHECK_STATUS(status, NT_STATUS_OK);
CHECK_VALUE(lck.out.unknown1, 0);
lck.in.unknown1 = 0x0001;
lck.in.unknown2 = 0x12345678;
lck.in.file.handle = h;
lck.in.offset = UINT32_MAX;
lck.in.count = UINT32_MAX;
lck.in.unknown5 = 0x87654321;
lck.in.flags = SMB2_LOCK_FLAG_EXCLUSIV;
status = smb2_lock(tree, &lck);
CHECK_STATUS(status, NT_STATUS_OK);
CHECK_VALUE(lck.out.unknown1, 0);
status = smb2_lock(tree, &lck);
CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
status = smb2_lock(tree, &lck);
CHECK_STATUS(status, NT_STATUS_OK);
CHECK_VALUE(lck.out.unknown1, 0);
status = smb2_lock(tree, &lck);
CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
status = smb2_lock(tree, &lck);
CHECK_STATUS(status, NT_STATUS_OK);
CHECK_VALUE(lck.out.unknown1, 0);
lck.in.flags = 0x00000000;
status = smb2_lock(tree, &lck);
CHECK_STATUS(status, NT_STATUS_OK);
CHECK_VALUE(lck.out.unknown1, 0);
status = smb2_lock(tree, &lck);
CHECK_STATUS(status, NT_STATUS_OK);
CHECK_VALUE(lck.out.unknown1, 0);
lck.in.flags = 0x00000001;
status = smb2_lock(tree, &lck);
CHECK_STATUS(status, NT_STATUS_OK);
CHECK_VALUE(lck.out.unknown1, 0);
status = smb2_lock(tree, &lck);
CHECK_STATUS(status, NT_STATUS_OK);
CHECK_VALUE(lck.out.unknown1, 0);
lck.in.unknown1 = 0x0001;
lck.in.unknown2 = 0x87654321;
lck.in.file.handle = h;
lck.in.offset = 0x00000000FFFFFFFF;
lck.in.count = 0x00000000FFFFFFFF;
lck.in.unknown5 = 0x12345678;
lck.in.flags = SMB2_LOCK_FLAG_UNLOCK;
status = smb2_lock(tree, &lck);
CHECK_STATUS(status, NT_STATUS_OK);
CHECK_VALUE(lck.out.unknown1, 0);
lck.in.unknown1 = 0x0001;
lck.in.unknown2 = 0x12345678;
lck.in.file.handle = h;
lck.in.offset = 0x00000000FFFFFFFF;
lck.in.count = 0x00000000FFFFFFFF;
lck.in.unknown5 = 0x00000000;
lck.in.flags = SMB2_LOCK_FLAG_UNLOCK;
status = smb2_lock(tree, &lck);
CHECK_STATUS(status, NT_STATUS_OK);
CHECK_VALUE(lck.out.unknown1, 0);
status = smb2_lock(tree, &lck);
CHECK_STATUS(status, NT_STATUS_OK);
CHECK_VALUE(lck.out.unknown1, 0);
status = smb2_lock(tree, &lck);
CHECK_STATUS(status, NT_STATUS_OK);
CHECK_VALUE(lck.out.unknown1, 0);
status = smb2_lock(tree, &lck);
CHECK_STATUS(status, NT_STATUS_OK);
CHECK_VALUE(lck.out.unknown1, 0);
status = smb2_lock(tree, &lck);
CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
status = smb2_lock(tree, &lck);
CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
status = smb2_lock(tree, &lck);
CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
done:
return ret;
}
/* basic testing of SMB2 locking
*/
BOOL torture_smb2_lock(struct torture_context *torture)
{
TALLOC_CTX *mem_ctx = talloc_new(NULL);
struct smb2_tree *tree;
BOOL ret = True;
if (!torture_smb2_connection(mem_ctx, &tree)) {
return False;
}
ret &= test_valid_request(mem_ctx, tree);
talloc_free(mem_ctx);
return ret;
}
+136
View File
@@ -0,0 +1,136 @@
/*
Unix SMB/CIFS implementation.
test suite for SMB2 write operations
Copyright (C) Andrew Tridgell 2006
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 2 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, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "librpc/gen_ndr/security.h"
#include "libcli/smb2/smb2.h"
#include "libcli/smb2/smb2_calls.h"
#include "torture/torture.h"
#include "torture/smb2/proto.h"
#define FNAME "testmaxwrite.dat"
/*
test writing
*/
static NTSTATUS torture_smb2_write(TALLOC_CTX *mem_ctx,
struct smb2_tree *tree,
struct smb2_handle handle)
{
struct smb2_write w;
struct smb2_read r;
NTSTATUS status;
int i, len;
int max = 80000000;
int min = 1;
while (max > min) {
TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
len = 1+(min+max)/2;
ZERO_STRUCT(w);
w.in.file.handle = handle;
w.in.offset = 0;
w.in.data = data_blob_talloc(tmp_ctx, NULL, len);
for (i=0;i<len;i++) {
w.in.data.data[i] = i % 256;
}
printf("trying to write %d bytes (min=%d max=%d)\n",
len, min, max);
status = smb2_write(tree, &w);
if (!NT_STATUS_IS_OK(status)) {
printf("write failed - %s\n", nt_errstr(status));
max = len-1;
status = smb2_util_close(tree, handle);
if (!NT_STATUS_IS_OK(status)) {
/* vista bug */
printf("coping with server disconnect\n");
talloc_free(tree);
if (!torture_smb2_connection(mem_ctx, &tree)) {
printf("failed to reconnect\n");
return NT_STATUS_NET_WRITE_FAULT;
}
}
handle = torture_smb2_create(tree, FNAME);
continue;
} else {
min = len;
}
ZERO_STRUCT(r);
r.in.file.handle = handle;
r.in.length = len;
r.in.offset = 0;
printf("reading %d bytes\n", len);
status = smb2_read(tree, tmp_ctx, &r);
if (!NT_STATUS_IS_OK(status)) {
printf("read failed - %s\n", nt_errstr(status));
} else if (w.in.data.length != r.out.data.length ||
memcmp(w.in.data.data, r.out.data.data, len) != 0) {
printf("read data mismatch\n");
}
talloc_free(tmp_ctx);
}
printf("converged: len=%d\n", max);
smb2_util_close(tree, handle);
smb2_util_unlink(tree, FNAME);
return NT_STATUS_OK;
}
/*
basic testing of SMB2 connection calls
*/
BOOL torture_smb2_maxwrite(struct torture_context *torture)
{
TALLOC_CTX *mem_ctx = talloc_new(NULL);
struct smb2_tree *tree;
struct smb2_handle h1;
NTSTATUS status;
if (!torture_smb2_connection(mem_ctx, &tree)) {
return False;
}
h1 = torture_smb2_create(tree, FNAME);
status = torture_smb2_write(mem_ctx, tree, h1);
if (!NT_STATUS_IS_OK(status)) {
printf("Write failed - %s\n", nt_errstr(status));
return False;
}
talloc_free(mem_ctx);
return True;
}
+175
View File
@@ -0,0 +1,175 @@
/*
Unix SMB/CIFS implementation.
SMB2 notify test suite
Copyright (C) Stefan Metzmacher 2006
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 2 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, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "libcli/smb2/smb2.h"
#include "libcli/smb2/smb2_calls.h"
#include "torture/torture.h"
#include "torture/smb2/proto.h"
#define CHECK_STATUS(status, correct) do { \
if (!NT_STATUS_EQUAL(status, correct)) { \
printf("(%s) Incorrect status %s - should be %s\n", \
__location__, nt_errstr(status), nt_errstr(correct)); \
ret = False; \
goto done; \
}} while (0)
#define CHECK_VALUE(v, correct) do { \
if ((v) != (correct)) { \
printf("(%s) Incorrect value %s=%d - should be %d\n", \
__location__, #v, v, correct); \
ret = False; \
goto done; \
}} while (0)
#define CHECK_WIRE_STR(field, value) do { \
if (!field.s || strcmp(field.s, value)) { \
printf("(%s) %s [%s] != %s\n", \
__location__, #field, field.s, value); \
ret = False; \
goto done; \
}} while (0)
#define FNAME "smb2-notify01.dat"
static BOOL test_valid_request(TALLOC_CTX *mem_ctx, struct smb2_tree *tree)
{
BOOL ret = True;
NTSTATUS status;
struct smb2_handle dh;
struct smb2_notify n;
struct smb2_request *req;
status = smb2_util_roothandle(tree, &dh);
CHECK_STATUS(status, NT_STATUS_OK);
n.in.recursive = 0x0000;
n.in.buffer_size = 0x00080000;
n.in.file.handle = dh;
n.in.completion_filter = 0x00000FFF;
n.in.unknown = 0x00000000;
req = smb2_notify_send(tree, &n);
status = torture_setup_complex_file(tree, FNAME);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb2_notify_recv(req, mem_ctx, &n);
CHECK_STATUS(status, NT_STATUS_OK);
CHECK_VALUE(n.out.num_changes, 1);
CHECK_VALUE(n.out.changes[0].action, NOTIFY_ACTION_REMOVED);
CHECK_WIRE_STR(n.out.changes[0].name, FNAME);
/*
* if the change response doesn't fit in the buffer
* NOTIFY_ENUM_DIR is returned.
*/
n.in.buffer_size = 0x00000000;
req = smb2_notify_send(tree, &n);
status = torture_setup_complex_file(tree, FNAME);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb2_notify_recv(req, mem_ctx, &n);
CHECK_STATUS(status, STATUS_NOTIFY_ENUM_DIR);
/*
* if the change response fits in the buffer we get
* NT_STATUS_OK again
*/
n.in.buffer_size = 0x00080000;
req = smb2_notify_send(tree, &n);
status = torture_setup_complex_file(tree, FNAME);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb2_notify_recv(req, mem_ctx, &n);
CHECK_STATUS(status, NT_STATUS_OK);
CHECK_VALUE(n.out.num_changes, 3);
CHECK_VALUE(n.out.changes[0].action, NOTIFY_ACTION_REMOVED);
CHECK_WIRE_STR(n.out.changes[0].name, FNAME);
CHECK_VALUE(n.out.changes[1].action, NOTIFY_ACTION_ADDED);
CHECK_WIRE_STR(n.out.changes[1].name, FNAME);
CHECK_VALUE(n.out.changes[2].action, NOTIFY_ACTION_MODIFIED);
CHECK_WIRE_STR(n.out.changes[2].name, FNAME);
/* if the first notify returns NOTIFY_ENUM_DIR, all do */
status = smb2_util_close(tree, dh);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb2_util_roothandle(tree, &dh);
CHECK_STATUS(status, NT_STATUS_OK);
n.in.recursive = 0x0000;
n.in.buffer_size = 0x00000001;
n.in.file.handle = dh;
n.in.completion_filter = 0x00000FFF;
n.in.unknown = 0x00000000;
req = smb2_notify_send(tree, &n);
status = torture_setup_complex_file(tree, FNAME);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb2_notify_recv(req, mem_ctx, &n);
CHECK_STATUS(status, STATUS_NOTIFY_ENUM_DIR);
n.in.buffer_size = 0x00080000;
req = smb2_notify_send(tree, &n);
status = torture_setup_complex_file(tree, FNAME);
CHECK_STATUS(status, NT_STATUS_OK);
status = smb2_notify_recv(req, mem_ctx, &n);
CHECK_STATUS(status, STATUS_NOTIFY_ENUM_DIR);
/* if the buffer size is too large, we get invalid parameter */
n.in.recursive = 0x0000;
n.in.buffer_size = 0x00080001;
n.in.file.handle = dh;
n.in.completion_filter = 0x00000FFF;
n.in.unknown = 0x00000000;
req = smb2_notify_send(tree, &n);
status = smb2_notify_recv(req, mem_ctx, &n);
CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
done:
return ret;
}
/* basic testing of SMB2 notify
*/
BOOL torture_smb2_notify(struct torture_context *torture)
{
TALLOC_CTX *mem_ctx = talloc_new(NULL);
struct smb2_tree *tree;
BOOL ret = True;
if (!torture_smb2_connection(mem_ctx, &tree)) {
return False;
}
ret &= test_valid_request(mem_ctx, tree);
talloc_free(mem_ctx);
return ret;
}
+243
View File
@@ -0,0 +1,243 @@
/*
Unix SMB/CIFS implementation.
SMB2 opcode scanner
Copyright (C) Andrew Tridgell 2005
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 2 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, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "libcli/smb2/smb2.h"
#include "libcli/smb2/smb2_calls.h"
#include "lib/cmdline/popt_common.h"
#include "lib/events/events.h"
#include "torture/torture.h"
#include "torture/smb2/proto.h"
#define FNAME "scan-getinfo.dat"
#define DNAME "scan-getinfo.dir"
/*
scan for valid SMB2 getinfo levels
*/
BOOL torture_smb2_getinfo_scan(struct torture_context *torture)
{
TALLOC_CTX *mem_ctx = talloc_new(NULL);
struct smb2_tree *tree;
NTSTATUS status;
struct smb2_getinfo io;
struct smb2_handle fhandle, dhandle;
int c, i;
if (!torture_smb2_connection(mem_ctx, &tree)) {
return False;
}
status = torture_setup_complex_file(tree, FNAME);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to setup complex file '%s'\n", FNAME);
return False;
}
torture_setup_complex_file(tree, FNAME ":2ndstream");
status = torture_setup_complex_dir(tree, DNAME);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to setup complex dir '%s'\n", DNAME);
return False;
}
torture_setup_complex_file(tree, DNAME ":2ndstream");
torture_smb2_testfile(tree, FNAME, &fhandle);
torture_smb2_testdir(tree, DNAME, &dhandle);
ZERO_STRUCT(io);
io.in.max_response_size = 0xFFFF;
for (c=1;c<5;c++) {
for (i=0;i<0x100;i++) {
io.in.level = (i<<8) | c;
io.in.file.handle = fhandle;
status = smb2_getinfo(tree, mem_ctx, &io);
if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_INFO_CLASS) &&
!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER) &&
!NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
printf("file level 0x%04x is %ld bytes - %s\n",
io.in.level, (long)io.out.blob.length, nt_errstr(status));
dump_data(1, io.out.blob.data, io.out.blob.length);
}
io.in.file.handle = dhandle;
status = smb2_getinfo(tree, mem_ctx, &io);
if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_INFO_CLASS) &&
!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER) &&
!NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
printf("dir level 0x%04x is %ld bytes - %s\n",
io.in.level, (long)io.out.blob.length, nt_errstr(status));
dump_data(1, io.out.blob.data, io.out.blob.length);
}
}
}
talloc_free(mem_ctx);
return True;
}
/*
scan for valid SMB2 setinfo levels
*/
BOOL torture_smb2_setinfo_scan(struct torture_context *torture)
{
TALLOC_CTX *mem_ctx = talloc_new(NULL);
struct smb2_tree *tree;
NTSTATUS status;
struct smb2_setinfo io;
struct smb2_handle handle;
int c, i;
if (!torture_smb2_connection(mem_ctx, &tree)) {
return False;
}
status = torture_setup_complex_file(tree, FNAME);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to setup complex file '%s'\n", FNAME);
return False;
}
torture_setup_complex_file(tree, FNAME ":2ndstream");
torture_smb2_testfile(tree, FNAME, &handle);
ZERO_STRUCT(io);
io.in.blob = data_blob_talloc(mem_ctx, NULL, 1024);
for (c=1;c<5;c++) {
for (i=0;i<0x100;i++) {
io.in.level = (i<<8) | c;
io.in.file.handle = handle;
status = smb2_setinfo(tree, &io);
if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_INFO_CLASS) &&
!NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
printf("file level 0x%04x - %s\n",
io.in.level, nt_errstr(status));
}
}
}
talloc_free(mem_ctx);
return True;
}
/*
scan for valid SMB2 scan levels
*/
BOOL torture_smb2_find_scan(struct torture_context *torture)
{
TALLOC_CTX *mem_ctx = talloc_new(NULL);
struct smb2_tree *tree;
NTSTATUS status;
struct smb2_find io;
struct smb2_handle handle;
int i;
if (!torture_smb2_connection(mem_ctx, &tree)) {
return False;
}
status = smb2_util_roothandle(tree, &handle);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to open roothandle - %s\n", nt_errstr(status));
return False;
}
ZERO_STRUCT(io);
io.in.file.handle = handle;
io.in.pattern = "*";
io.in.continue_flags = SMB2_CONTINUE_FLAG_RESTART;
io.in.max_response_size = 0x10000;
for (i=1;i<0x100;i++) {
io.in.level = i;
io.in.file.handle = handle;
status = smb2_find(tree, mem_ctx, &io);
if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_INFO_CLASS) &&
!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER) &&
!NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
printf("find level 0x%04x is %ld bytes - %s\n",
io.in.level, (long)io.out.blob.length, nt_errstr(status));
dump_data(1, io.out.blob.data, io.out.blob.length);
}
}
talloc_free(mem_ctx);
return True;
}
/*
scan for valid SMB2 opcodes
*/
BOOL torture_smb2_scan(struct torture_context *torture)
{
TALLOC_CTX *mem_ctx = talloc_new(NULL);
struct smb2_tree *tree;
const char *host = torture_setting_string(torture, "host", NULL);
const char *share = torture_setting_string(torture, "share", NULL);
struct cli_credentials *credentials = cmdline_credentials;
NTSTATUS status;
int opcode;
struct smb2_request *req;
status = smb2_connect(mem_ctx, host, share, credentials, &tree,
event_context_find(mem_ctx));
if (!NT_STATUS_IS_OK(status)) {
printf("Connection failed - %s\n", nt_errstr(status));
return False;
}
tree->session->transport->options.timeout = 3;
for (opcode=0;opcode<1000;opcode++) {
req = smb2_request_init_tree(tree, opcode, 2, False, 0);
SSVAL(req->out.body, 0, 0);
smb2_transport_send(req);
if (!smb2_request_receive(req)) {
talloc_free(tree);
status = smb2_connect(mem_ctx, host, share, credentials, &tree,
event_context_find(mem_ctx));
if (!NT_STATUS_IS_OK(status)) {
printf("Connection failed - %s\n", nt_errstr(status));
return False;
}
tree->session->transport->options.timeout = 3;
} else {
status = smb2_request_destroy(req);
printf("active opcode %4d gave status %s\n", opcode, nt_errstr(status));
}
}
talloc_free(mem_ctx);
return True;
}
+299
View File
@@ -0,0 +1,299 @@
/*
Unix SMB/CIFS implementation.
SMB2 setinfo individual test suite
Copyright (C) Andrew Tridgell 2005
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 2 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, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "system/time.h"
#include "libcli/smb2/smb2.h"
#include "libcli/smb2/smb2_calls.h"
#include "torture/torture.h"
#include "torture/smb2/proto.h"
#include "libcli/security/security.h"
#include "librpc/gen_ndr/ndr_security.h"
#define BASEDIR ""
/* basic testing of all SMB2 setinfo calls
for each call we test that it succeeds, and where possible test
for consistency between the calls.
*/
BOOL torture_smb2_setinfo(struct torture_context *torture)
{
struct smb2_tree *tree;
BOOL ret = True;
TALLOC_CTX *mem_ctx = talloc_new(NULL);
struct smb2_handle handle;
char *fname;
char *fname_new;
union smb_fileinfo finfo2;
union smb_setfileinfo sfinfo;
struct security_ace ace;
struct security_descriptor *sd;
struct dom_sid *test_sid;
NTSTATUS status, status2=NT_STATUS_OK;
const char *call_name;
time_t basetime = (time(NULL) - 86400) & ~1;
int n = time(NULL) % 100;
ZERO_STRUCT(handle);
fname = talloc_asprintf(mem_ctx, BASEDIR "fnum_test_%d.txt", n);
fname_new = talloc_asprintf(mem_ctx, BASEDIR "fnum_test_new_%d.txt", n);
if (!torture_smb2_connection(mem_ctx, &tree)) {
return False;
}
#define RECREATE_FILE(fname) do { \
smb2_util_close(tree, handle); \
status = smb2_create_complex_file(tree, fname, &handle); \
if (!NT_STATUS_IS_OK(status)) { \
printf("(%s) ERROR: open of %s failed (%s)\n", \
__location__, fname, nt_errstr(status)); \
ret = False; \
goto done; \
}} while (0)
#define RECREATE_BOTH do { \
RECREATE_FILE(fname); \
} while (0)
RECREATE_BOTH;
#define CHECK_CALL(call, rightstatus) do { \
call_name = #call; \
sfinfo.generic.level = RAW_SFILEINFO_ ## call; \
sfinfo.generic.in.file.handle = handle; \
status = smb2_setinfo_file(tree, &sfinfo); \
if (!NT_STATUS_EQUAL(status, rightstatus)) { \
printf("(%s) %s - %s (should be %s)\n", __location__, #call, \
nt_errstr(status), nt_errstr(rightstatus)); \
ret = False; \
goto done; \
} \
} while (0)
#define CHECK1(call) \
do { if (NT_STATUS_IS_OK(status)) { \
finfo2.generic.level = RAW_FILEINFO_ ## call; \
finfo2.generic.in.file.handle = handle; \
status2 = smb2_getinfo_file(tree, mem_ctx, &finfo2); \
if (!NT_STATUS_IS_OK(status2)) { \
printf("(%s) %s - %s\n", __location__, #call, nt_errstr(status2)); \
ret = False; \
goto done; \
} \
}} while (0)
#define CHECK_VALUE(call, stype, field, value) do { \
CHECK1(call); \
if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(status2) && finfo2.stype.out.field != value) { \
printf("(%s) %s - %s/%s should be 0x%x - 0x%x\n", __location__, \
call_name, #stype, #field, \
(uint_t)value, (uint_t)finfo2.stype.out.field); \
torture_smb2_all_info(tree, handle); \
ret = False; \
goto done; \
}} while (0)
#define CHECK_TIME(call, stype, field, value) do { \
CHECK1(call); \
if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(status2) && nt_time_to_unix(finfo2.stype.out.field) != value) { \
printf("(%s) %s - %s/%s should be 0x%x - 0x%x\n", __location__, \
call_name, #stype, #field, \
(uint_t)value, \
(uint_t)nt_time_to_unix(finfo2.stype.out.field)); \
printf("\t%s", timestring(mem_ctx, value)); \
printf("\t%s\n", nt_time_string(mem_ctx, finfo2.stype.out.field)); \
torture_smb2_all_info(tree, handle); \
ret = False; \
goto done; \
}} while (0)
#define CHECK_STATUS(status, correct) do { \
if (!NT_STATUS_EQUAL(status, correct)) { \
printf("(%s) Incorrect status %s - should be %s\n", \
__location__, nt_errstr(status), nt_errstr(correct)); \
ret = False; \
goto done; \
}} while (0)
torture_smb2_all_info(tree, handle);
printf("test basic_information level\n");
basetime += 86400;
unix_to_nt_time(&sfinfo.basic_info.in.create_time, basetime + 100);
unix_to_nt_time(&sfinfo.basic_info.in.access_time, basetime + 200);
unix_to_nt_time(&sfinfo.basic_info.in.write_time, basetime + 300);
unix_to_nt_time(&sfinfo.basic_info.in.change_time, basetime + 400);
sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_READONLY;
CHECK_CALL(BASIC_INFORMATION, NT_STATUS_OK);
CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, create_time, basetime + 100);
CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, access_time, basetime + 200);
CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, write_time, basetime + 300);
CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, change_time, basetime + 400);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, attrib, FILE_ATTRIBUTE_READONLY);
printf("a zero time means don't change\n");
unix_to_nt_time(&sfinfo.basic_info.in.create_time, 0);
unix_to_nt_time(&sfinfo.basic_info.in.access_time, 0);
unix_to_nt_time(&sfinfo.basic_info.in.write_time, 0);
unix_to_nt_time(&sfinfo.basic_info.in.change_time, 0);
sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_NORMAL;
CHECK_CALL(BASIC_INFORMATION, NT_STATUS_OK);
CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, create_time, basetime + 100);
CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, access_time, basetime + 200);
CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, write_time, basetime + 300);
CHECK_TIME(SMB2_ALL_INFORMATION, all_info2, change_time, basetime + 400);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, attrib, FILE_ATTRIBUTE_NORMAL);
printf("change the attribute\n");
sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_HIDDEN;
CHECK_CALL(BASIC_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, attrib, FILE_ATTRIBUTE_HIDDEN);
printf("zero attrib means don't change\n");
sfinfo.basic_info.in.attrib = 0;
CHECK_CALL(BASIC_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, attrib, FILE_ATTRIBUTE_HIDDEN);
printf("restore attribute\n");
sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_NORMAL;
CHECK_CALL(BASIC_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, attrib, FILE_ATTRIBUTE_NORMAL);
printf("test disposition_information level\n");
sfinfo.disposition_info.in.delete_on_close = 1;
CHECK_CALL(DISPOSITION_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, delete_pending, 1);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, nlink, 0);
sfinfo.disposition_info.in.delete_on_close = 0;
CHECK_CALL(DISPOSITION_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, delete_pending, 0);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, nlink, 1);
printf("test allocation_information level\n");
sfinfo.allocation_info.in.alloc_size = 0;
CHECK_CALL(ALLOCATION_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, size, 0);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, alloc_size, 0);
sfinfo.allocation_info.in.alloc_size = 4096;
CHECK_CALL(ALLOCATION_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, alloc_size, 4096);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, size, 0);
printf("test end_of_file_info level\n");
sfinfo.end_of_file_info.in.size = 37;
CHECK_CALL(END_OF_FILE_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, size, 37);
sfinfo.end_of_file_info.in.size = 7;
CHECK_CALL(END_OF_FILE_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, size, 7);
printf("test position_information level\n");
sfinfo.position_information.in.position = 123456;
CHECK_CALL(POSITION_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(POSITION_INFORMATION, position_information, position, 123456);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, position, 123456);
printf("test mode_information level\n");
sfinfo.mode_information.in.mode = 2;
CHECK_CALL(MODE_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(MODE_INFORMATION, mode_information, mode, 2);
CHECK_VALUE(SMB2_ALL_INFORMATION, all_info2, mode, 2);
sfinfo.mode_information.in.mode = 1;
CHECK_CALL(MODE_INFORMATION, NT_STATUS_INVALID_PARAMETER);
sfinfo.mode_information.in.mode = 0;
CHECK_CALL(MODE_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(MODE_INFORMATION, mode_information, mode, 0);
printf("test sec_desc level\n");
ZERO_STRUCT(finfo2);
finfo2.query_secdesc.in.secinfo_flags =
SECINFO_OWNER |
SECINFO_GROUP |
SECINFO_DACL;
CHECK1(SEC_DESC);
sd = finfo2.query_secdesc.out.sd;
test_sid = dom_sid_parse_talloc(mem_ctx, "S-1-5-32-1234-5432");
ZERO_STRUCT(ace);
ace.type = SEC_ACE_TYPE_ACCESS_ALLOWED;
ace.flags = 0;
ace.access_mask = SEC_STD_ALL;
ace.trustee = *test_sid;
status = security_descriptor_dacl_add(sd, &ace);
CHECK_STATUS(status, NT_STATUS_OK);
printf("add a new ACE to the DACL\n");
sfinfo.set_secdesc.in.secinfo_flags = finfo2.query_secdesc.in.secinfo_flags;
sfinfo.set_secdesc.in.sd = sd;
CHECK_CALL(SEC_DESC, NT_STATUS_OK);
CHECK1(SEC_DESC);
if (!security_acl_equal(finfo2.query_secdesc.out.sd->dacl, sd->dacl)) {
printf("%s: security descriptors don't match!\n", __location__);
printf("got:\n");
NDR_PRINT_DEBUG(security_descriptor, finfo2.query_secdesc.out.sd);
printf("expected:\n");
NDR_PRINT_DEBUG(security_descriptor, sd);
ret = False;
}
printf("remove it again\n");
status = security_descriptor_dacl_del(sd, test_sid);
CHECK_STATUS(status, NT_STATUS_OK);
sfinfo.set_secdesc.in.secinfo_flags = finfo2.query_secdesc.in.secinfo_flags;
sfinfo.set_secdesc.in.sd = sd;
CHECK_CALL(SEC_DESC, NT_STATUS_OK);
CHECK1(SEC_DESC);
if (!security_acl_equal(finfo2.query_secdesc.out.sd->dacl, sd->dacl)) {
printf("%s: security descriptors don't match!\n", __location__);
printf("got:\n");
NDR_PRINT_DEBUG(security_descriptor, finfo2.query_secdesc.out.sd);
printf("expected:\n");
NDR_PRINT_DEBUG(security_descriptor, sd);
ret = False;
}
done:
status = smb2_util_close(tree, handle);
if (NT_STATUS_IS_ERR(status)) {
printf("Failed to delete %s - %s\n", fname, nt_errstr(status));
}
smb2_util_unlink(tree, fname);
talloc_free(mem_ctx);
return ret;
}
+50
View File
@@ -0,0 +1,50 @@
/*
Unix SMB/CIFS implementation.
SMB torture tester
Copyright (C) Jelmer Vernooij 2006
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 2 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, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "libcli/smb2/smb2.h"
#include "libcli/smb2/smb2_calls.h"
#include "torture/torture.h"
#include "torture/smb2/proto.h"
NTSTATUS torture_smb2_init(void)
{
struct torture_suite *suite = torture_suite_create(
talloc_autofree_context(),
"SMB2");
torture_suite_add_simple_test(suite, "CONNECT", torture_smb2_connect);
torture_suite_add_simple_test(suite, "SCAN", torture_smb2_scan);
torture_suite_add_simple_test(suite, "SCANGETINFO", torture_smb2_getinfo_scan);
torture_suite_add_simple_test(suite, "SCANSETINFO", torture_smb2_setinfo_scan);
torture_suite_add_simple_test(suite, "SCANFIND", torture_smb2_find_scan);
torture_suite_add_simple_test(suite, "GETINFO", torture_smb2_getinfo);
torture_suite_add_simple_test(suite, "SETINFO", torture_smb2_setinfo);
torture_suite_add_simple_test(suite, "FIND", torture_smb2_find);
torture_suite_add_simple_test(suite, "LOCK", torture_smb2_lock);
torture_suite_add_simple_test(suite, "NOTIFY", torture_smb2_notify);
suite->description = talloc_strdup(suite,
"SMB2-specific tests");
torture_register_suite(suite);
return NT_STATUS_OK;
}
+433
View File
@@ -0,0 +1,433 @@
/*
Unix SMB/CIFS implementation.
helper functions for SMB2 test suite
Copyright (C) Andrew Tridgell 2005
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 2 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, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#include "libcli/smb2/smb2.h"
#include "libcli/smb2/smb2_calls.h"
#include "lib/cmdline/popt_common.h"
#include "lib/events/events.h"
#include "system/time.h"
#include "librpc/gen_ndr/ndr_security.h"
/*
close a handle with SMB2
*/
NTSTATUS smb2_util_close(struct smb2_tree *tree, struct smb2_handle h)
{
struct smb2_close c;
ZERO_STRUCT(c);
c.in.file.handle = h;
return smb2_close(tree, &c);
}
/*
unlink a file with SMB2
*/
NTSTATUS smb2_util_unlink(struct smb2_tree *tree, const char *fname)
{
struct smb2_create io;
NTSTATUS status;
ZERO_STRUCT(io);
io.in.access_mask = SEC_RIGHTS_FILE_ALL;
io.in.file_attr = FILE_ATTRIBUTE_NORMAL;
io.in.open_disposition = NTCREATEX_DISP_OPEN;
io.in.share_access =
NTCREATEX_SHARE_ACCESS_DELETE|
NTCREATEX_SHARE_ACCESS_READ|
NTCREATEX_SHARE_ACCESS_WRITE;
io.in.create_options = NTCREATEX_OPTIONS_DELETE_ON_CLOSE;
io.in.fname = fname;
status = smb2_create(tree, tree, &io);
if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
return NT_STATUS_OK;
}
NT_STATUS_NOT_OK_RETURN(status);
return smb2_util_close(tree, io.out.file.handle);
}
/*
write to a file on SMB2
*/
NTSTATUS smb2_util_write(struct smb2_tree *tree,
struct smb2_handle handle,
const void *buf, off_t offset, size_t size)
{
struct smb2_write w;
ZERO_STRUCT(w);
w.in.file.handle = handle;
w.in.offset = offset;
w.in.data = data_blob_const(buf, size);
return smb2_write(tree, &w);
}
/*
create a complex file/dir using the SMB2 protocol
*/
static NTSTATUS smb2_create_complex(struct smb2_tree *tree, const char *fname,
struct smb2_handle *handle, BOOL dir)
{
TALLOC_CTX *tmp_ctx = talloc_new(tree);
char buf[7] = "abc";
struct smb2_create io;
union smb_setfileinfo setfile;
union smb_fileinfo fileinfo;
time_t t = (time(NULL) & ~1);
NTSTATUS status;
smb2_util_unlink(tree, fname);
ZERO_STRUCT(io);
io.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
io.in.file_attr = FILE_ATTRIBUTE_NORMAL;
io.in.open_disposition = NTCREATEX_DISP_OVERWRITE_IF;
io.in.share_access =
NTCREATEX_SHARE_ACCESS_DELETE|
NTCREATEX_SHARE_ACCESS_READ|
NTCREATEX_SHARE_ACCESS_WRITE;
io.in.create_options = 0;
io.in.fname = fname;
if (dir) {
io.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
io.in.share_access &= ~NTCREATEX_SHARE_ACCESS_DELETE;
io.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
io.in.open_disposition = NTCREATEX_DISP_CREATE;
}
if (strchr(fname, ':') == NULL) {
/* setup some EAs */
io.in.eas.num_eas = 2;
io.in.eas.eas = talloc_array(tmp_ctx, struct ea_struct, 2);
io.in.eas.eas[0].flags = 0;
io.in.eas.eas[0].name.s = "EAONE";
io.in.eas.eas[0].value = data_blob_talloc(tmp_ctx, "VALUE1", 6);
io.in.eas.eas[1].flags = 0;
io.in.eas.eas[1].name.s = "SECONDEA";
io.in.eas.eas[1].value = data_blob_talloc(tmp_ctx, "ValueTwo", 8);
}
status = smb2_create(tree, tmp_ctx, &io);
talloc_free(tmp_ctx);
NT_STATUS_NOT_OK_RETURN(status);
*handle = io.out.file.handle;
if (!dir) {
status = smb2_util_write(tree, *handle, buf, 0, sizeof(buf));
NT_STATUS_NOT_OK_RETURN(status);
}
/* make sure all the timestamps aren't the same, and are also
in different DST zones*/
setfile.generic.level = RAW_SFILEINFO_BASIC_INFORMATION;
setfile.generic.in.file.handle = *handle;
unix_to_nt_time(&setfile.basic_info.in.create_time, t + 9*30*24*60*60);
unix_to_nt_time(&setfile.basic_info.in.access_time, t + 6*30*24*60*60);
unix_to_nt_time(&setfile.basic_info.in.write_time, t + 3*30*24*60*60);
unix_to_nt_time(&setfile.basic_info.in.change_time, t + 1*30*24*60*60);
setfile.basic_info.in.attrib = FILE_ATTRIBUTE_NORMAL;
status = smb2_setinfo_file(tree, &setfile);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to setup file times - %s\n", nt_errstr(status));
return status;
}
/* make sure all the timestamps aren't the same */
fileinfo.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
fileinfo.generic.in.file.handle = *handle;
status = smb2_getinfo_file(tree, tree, &fileinfo);
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to query file times - %s\n", nt_errstr(status));
return status;
}
#define CHECK_TIME(field) do {\
if (setfile.basic_info.in.field != fileinfo.all_info2.out.field) { \
printf("(%s) " #field " not setup correctly: %s(%llu) => %s(%llu)\n", \
__location__, \
nt_time_string(tree, setfile.basic_info.in.field), \
(unsigned long long)setfile.basic_info.in.field, \
nt_time_string(tree, fileinfo.basic_info.out.field), \
(unsigned long long)fileinfo.basic_info.out.field); \
status = NT_STATUS_INVALID_PARAMETER; \
} \
} while (0)
CHECK_TIME(create_time);
CHECK_TIME(access_time);
CHECK_TIME(write_time);
CHECK_TIME(change_time);
return status;
}
/*
create a complex file using the SMB2 protocol
*/
NTSTATUS smb2_create_complex_file(struct smb2_tree *tree, const char *fname,
struct smb2_handle *handle)
{
return smb2_create_complex(tree, fname, handle, False);
}
/*
create a complex dir using the SMB2 protocol
*/
NTSTATUS smb2_create_complex_dir(struct smb2_tree *tree, const char *fname,
struct smb2_handle *handle)
{
return smb2_create_complex(tree, fname, handle, True);
}
/*
show lots of information about a file
*/
void torture_smb2_all_info(struct smb2_tree *tree, struct smb2_handle handle)
{
NTSTATUS status;
TALLOC_CTX *tmp_ctx = talloc_new(tree);
union smb_fileinfo io;
io.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
io.generic.in.file.handle = handle;
status = smb2_getinfo_file(tree, tmp_ctx, &io);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0,("getinfo failed - %s\n", nt_errstr(status)));
talloc_free(tmp_ctx);
return;
}
d_printf("all_info for '%s'\n", io.all_info2.out.fname.s);
d_printf("\tcreate_time: %s\n", nt_time_string(tmp_ctx, io.all_info2.out.create_time));
d_printf("\taccess_time: %s\n", nt_time_string(tmp_ctx, io.all_info2.out.access_time));
d_printf("\twrite_time: %s\n", nt_time_string(tmp_ctx, io.all_info2.out.write_time));
d_printf("\tchange_time: %s\n", nt_time_string(tmp_ctx, io.all_info2.out.change_time));
d_printf("\tattrib: 0x%x\n", io.all_info2.out.attrib);
d_printf("\tunknown1: 0x%x\n", io.all_info2.out.unknown1);
d_printf("\talloc_size: %llu\n", (long long)io.all_info2.out.alloc_size);
d_printf("\tsize: %llu\n", (long long)io.all_info2.out.size);
d_printf("\tnlink: %u\n", io.all_info2.out.nlink);
d_printf("\tdelete_pending: %u\n", io.all_info2.out.delete_pending);
d_printf("\tdirectory: %u\n", io.all_info2.out.directory);
d_printf("\tfile_id: %llu\n", (long long)io.all_info2.out.file_id);
d_printf("\tea_size: %u\n", io.all_info2.out.ea_size);
d_printf("\taccess_mask: 0x%08x\n", io.all_info2.out.access_mask);
d_printf("\tposition: 0x%llx\n", (long long)io.all_info2.out.position);
d_printf("\tmode: 0x%llx\n", (long long)io.all_info2.out.mode);
/* short name, if any */
io.generic.level = RAW_FILEINFO_ALT_NAME_INFORMATION;
status = smb2_getinfo_file(tree, tmp_ctx, &io);
if (NT_STATUS_IS_OK(status)) {
d_printf("\tshort name: '%s'\n", io.alt_name_info.out.fname.s);
}
/* the EAs, if any */
io.generic.level = RAW_FILEINFO_SMB2_ALL_EAS;
status = smb2_getinfo_file(tree, tmp_ctx, &io);
if (NT_STATUS_IS_OK(status)) {
int i;
for (i=0;i<io.all_eas.out.num_eas;i++) {
d_printf("\tEA[%d] flags=%d len=%d '%s'\n", i,
io.all_eas.out.eas[i].flags,
(int)io.all_eas.out.eas[i].value.length,
io.all_eas.out.eas[i].name.s);
}
}
/* streams, if available */
io.generic.level = RAW_FILEINFO_STREAM_INFORMATION;
status = smb2_getinfo_file(tree, tmp_ctx, &io);
if (NT_STATUS_IS_OK(status)) {
int i;
for (i=0;i<io.stream_info.out.num_streams;i++) {
d_printf("\tstream %d:\n", i);
d_printf("\t\tsize %ld\n",
(long)io.stream_info.out.streams[i].size);
d_printf("\t\talloc size %ld\n",
(long)io.stream_info.out.streams[i].alloc_size);
d_printf("\t\tname %s\n", io.stream_info.out.streams[i].stream_name.s);
}
}
if (DEBUGLVL(1)) {
/* the security descriptor */
io.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
io.query_secdesc.in.secinfo_flags =
SECINFO_OWNER|SECINFO_GROUP|
SECINFO_DACL;
status = smb2_getinfo_file(tree, tmp_ctx, &io);
if (NT_STATUS_IS_OK(status)) {
NDR_PRINT_DEBUG(security_descriptor, io.query_secdesc.out.sd);
}
}
talloc_free(tmp_ctx);
}
/*
open a smb2 connection
*/
BOOL torture_smb2_connection(TALLOC_CTX *mem_ctx, struct smb2_tree **tree)
{
NTSTATUS status;
const char *host = lp_parm_string(-1, "torture", "host");
const char *share = lp_parm_string(-1, "torture", "share");
struct cli_credentials *credentials = cmdline_credentials;
status = smb2_connect(mem_ctx, host, share, credentials, tree,
event_context_find(mem_ctx));
if (!NT_STATUS_IS_OK(status)) {
printf("Failed to connect to SMB2 share \\\\%s\\%s - %s\n",
host, share, nt_errstr(status));
return False;
}
return True;
}
/*
create and return a handle to a test file
*/
NTSTATUS torture_smb2_testfile(struct smb2_tree *tree, const char *fname,
struct smb2_handle *handle)
{
struct smb2_create io;
struct smb2_read r;
NTSTATUS status;
ZERO_STRUCT(io);
io.in.oplock_flags = 0;
io.in.access_mask = SEC_RIGHTS_FILE_ALL;
io.in.file_attr = FILE_ATTRIBUTE_NORMAL;
io.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
io.in.share_access =
NTCREATEX_SHARE_ACCESS_DELETE|
NTCREATEX_SHARE_ACCESS_READ|
NTCREATEX_SHARE_ACCESS_WRITE;
io.in.create_options = 0;
io.in.fname = fname;
status = smb2_create(tree, tree, &io);
NT_STATUS_NOT_OK_RETURN(status);
*handle = io.out.file.handle;
ZERO_STRUCT(r);
r.in.file.handle = *handle;
r.in.length = 5;
r.in.offset = 0;
smb2_read(tree, tree, &r);
return NT_STATUS_OK;
}
/*
create and return a handle to a test directory
*/
NTSTATUS torture_smb2_testdir(struct smb2_tree *tree, const char *fname,
struct smb2_handle *handle)
{
struct smb2_create io;
NTSTATUS status;
ZERO_STRUCT(io);
io.in.oplock_flags = 0;
io.in.access_mask = SEC_RIGHTS_DIR_ALL;
io.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
io.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
io.in.share_access = NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE;
io.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
io.in.fname = fname;
status = smb2_create(tree, tree, &io);
NT_STATUS_NOT_OK_RETURN(status);
*handle = io.out.file.handle;
return NT_STATUS_OK;
}
/*
create a complex file using the old SMB protocol, to make it easier to
find fields in SMB2 getinfo levels
*/
NTSTATUS torture_setup_complex_file(struct smb2_tree *tree, const char *fname)
{
struct smb2_handle handle;
NTSTATUS status = smb2_create_complex_file(tree, fname, &handle);
NT_STATUS_NOT_OK_RETURN(status);
return smb2_util_close(tree, handle);
}
/*
create a complex dir using the old SMB protocol, to make it easier to
find fields in SMB2 getinfo levels
*/
NTSTATUS torture_setup_complex_dir(struct smb2_tree *tree, const char *fname)
{
struct smb2_handle handle;
NTSTATUS status = smb2_create_complex_dir(tree, fname, &handle);
NT_STATUS_NOT_OK_RETURN(status);
return smb2_util_close(tree, handle);
}
/*
return a handle to the root of the share
*/
NTSTATUS smb2_util_roothandle(struct smb2_tree *tree, struct smb2_handle *handle)
{
struct smb2_create io;
NTSTATUS status;
ZERO_STRUCT(io);
io.in.oplock_flags = 0;
io.in.access_mask = SEC_STD_SYNCHRONIZE | SEC_DIR_READ_ATTRIBUTE | SEC_DIR_LIST;
io.in.file_attr = 0;
io.in.open_disposition = NTCREATEX_DISP_OPEN;
io.in.share_access = NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_DELETE;
io.in.create_options = NTCREATEX_OPTIONS_ASYNC_ALERT;
io.in.fname = "";
status = smb2_create(tree, tree, &io);
NT_STATUS_NOT_OK_RETURN(status);
*handle = io.out.file.handle;
return NT_STATUS_OK;
}