summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/Makefile.in3
-rw-r--r--source3/torture/proto.h2
-rw-r--r--source3/torture/test_smb2.c133
-rw-r--r--source3/torture/torture.c16
-rwxr-xr-xsource3/wscript_build1
5 files changed, 153 insertions, 2 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in
index da3cb1a340..92613abdfd 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -1252,7 +1252,8 @@ SMBTORTURE_OBJ1 = torture/torture.o torture/nbio.o torture/scanner.o torture/uta
torture/test_notify_online.o \
torture/test_addrchange.o \
torture/test_case_insensitive.o \
- torture/test_posix_append.o
+ torture/test_posix_append.o \
+ torture/test_smb2.o
SMBTORTURE_OBJ = $(SMBTORTURE_OBJ1) $(PARAM_OBJ) $(TLDAP_OBJ) \
$(LIBSMB_OBJ) $(KRBCLIENT_OBJ) $(LIB_NONSMBD_OBJ) \
diff --git a/source3/torture/proto.h b/source3/torture/proto.h
index 6a47a18cd7..6b49fba1bd 100644
--- a/source3/torture/proto.h
+++ b/source3/torture/proto.h
@@ -67,6 +67,7 @@ void *shm_setup(int size);
bool smbcli_parse_unc(const char *unc_name, TALLOC_CTX *mem_ctx,
char **hostname, char **sharename);
bool torture_open_connection(struct cli_state **c, int conn_index);
+bool torture_init_connection(struct cli_state **pcli);
bool torture_cli_session_setup2(struct cli_state *cli, uint16 *new_vuid);
bool torture_close_connection(struct cli_state *c);
bool torture_ioctl_test(int dummy);
@@ -91,5 +92,6 @@ bool run_smb_any_connect(int dummy);
bool run_addrchange(int dummy);
bool run_notify_online(int dummy);
bool run_nttrans_create(int dummy);
+bool run_smb2_basic(int dummy);
#endif /* __TORTURE_H__ */
diff --git a/source3/torture/test_smb2.c b/source3/torture/test_smb2.c
new file mode 100644
index 0000000000..513930613a
--- /dev/null
+++ b/source3/torture/test_smb2.c
@@ -0,0 +1,133 @@
+/*
+ Unix SMB/CIFS implementation.
+ Initial test for the smb2 client lib
+ Copyright (C) Volker Lendecke 2011
+
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "torture/proto.h"
+#include "client.h"
+#include "libsmb/smb2cli.h"
+#include "libcli/security/security.h"
+
+extern fstring host, workgroup, share, password, username, myname;
+
+bool run_smb2_basic(int dummy)
+{
+ struct cli_state *cli;
+ NTSTATUS status;
+ uint64_t fid_persistent, fid_volatile;
+ const char *hello = "Hello, world\n";
+ uint8_t *result;
+ uint32_t nread;
+ uint8_t *dir_data;
+ uint32_t dir_data_length;
+
+ printf("Starting SMB2-BASIC\n");
+
+ if (!torture_init_connection(&cli)) {
+ return false;
+ }
+ cli->smb2.pid = 0xFEFF;
+
+ status = smb2cli_negprot(cli);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("smb2cli_negprot returned %s\n", nt_errstr(status));
+ return false;
+ }
+
+ status = smb2cli_sesssetup(cli, username, workgroup, password);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("smb2cli_sesssetup returned %s\n", nt_errstr(status));
+ return false;
+ }
+
+ status = smb2cli_tcon(cli, share);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("smb2cli_tcon returned %s\n", nt_errstr(status));
+ return false;
+ }
+
+ status = smb2cli_create(
+ cli, "test.txt", SMB2_OPLOCK_LEVEL_NONE, 0,
+ MAXIMUM_ALLOWED_ACCESS, FILE_ATTRIBUTE_NORMAL,
+ FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+ FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, NULL,
+ &fid_persistent, &fid_volatile);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("smb2cli_create returned %s\n", nt_errstr(status));
+ return false;
+ }
+
+ status = smb2cli_write(cli, strlen(hello), 0, fid_persistent,
+ fid_volatile, 0, 0, (const uint8_t *)hello);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("smb2cli_write returned %s\n", nt_errstr(status));
+ return false;
+ }
+
+ status = smb2cli_read(cli, 0x10000, 0, fid_persistent,
+ fid_volatile, 2, 0,
+ talloc_tos(), &result, &nread);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("smb2cli_read returned %s\n", nt_errstr(status));
+ return false;
+ }
+
+ if (nread != strlen(hello)) {
+ printf("smb2cli_read returned %d bytes, expected %d\n",
+ (int)nread, (int)strlen(hello));
+ return false;
+ }
+
+ if (memcmp(hello, result, nread) != 0) {
+ printf("smb2cli_read returned '%s', expected '%s'\n",
+ result, hello);
+ return false;
+ }
+
+ status = smb2cli_close(cli, 0, fid_persistent, fid_volatile);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("smb2cli_close returned %s\n", nt_errstr(status));
+ return false;
+ }
+
+ status = smb2cli_create(
+ cli, "", SMB2_OPLOCK_LEVEL_NONE, 0,
+ MAXIMUM_ALLOWED_ACCESS, FILE_ATTRIBUTE_DIRECTORY, 0,
+ FILE_OPEN, 0, NULL, &fid_persistent, &fid_volatile);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("smb2cli_create returned %s\n", nt_errstr(status));
+ return false;
+ }
+
+ status = smb2cli_query_directory(
+ cli, 1, 0, 0, fid_persistent, fid_volatile, "*", 0xffff,
+ talloc_tos(), &dir_data, &dir_data_length);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
+ return false;
+ }
+
+ status = smb2cli_close(cli, 0, fid_persistent, fid_volatile);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("smb2cli_close returned %s\n", nt_errstr(status));
+ return false;
+ }
+
+ return true;
+}
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index 4a01bf2a9c..a6387c1484 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -42,7 +42,7 @@
extern char *optarg;
extern int optind;
-static fstring host, workgroup, share, password, username, myname;
+fstring host, workgroup, share, password, username, myname;
static int max_protocol = PROTOCOL_NT1;
static const char *sockops="TCP_NODELAY";
static int nprocs=1;
@@ -414,6 +414,19 @@ bool torture_open_connection(struct cli_state **c, int conn_index)
return torture_open_connection_share(c, host, share);
}
+bool torture_init_connection(struct cli_state **pcli)
+{
+ struct cli_state *cli;
+
+ cli = open_nbt_connection();
+ if (cli == NULL) {
+ return false;
+ }
+
+ *pcli = cli;
+ return true;
+}
+
bool torture_cli_session_setup2(struct cli_state *cli, uint16 *new_vuid)
{
uint16 old_vuid = cli->vuid;
@@ -8695,6 +8708,7 @@ static struct {
{ "BAD-NBT-SESSION", run_bad_nbt_session },
{ "SMB-ANY-CONNECT", run_smb_any_connect },
{ "NOTIFY-ONLINE", run_notify_online },
+ { "SMB2-BASIC", run_smb2_basic },
{ "LOCAL-SUBSTITUTE", run_local_substitute, 0},
{ "LOCAL-GENCACHE", run_local_gencache, 0},
{ "LOCAL-TALLOC-DICT", run_local_talloc_dict, 0},
diff --git a/source3/wscript_build b/source3/wscript_build
index fdfba98bee..ae1860cc62 100755
--- a/source3/wscript_build
+++ b/source3/wscript_build
@@ -574,6 +574,7 @@ SMBTORTURE_SRC1 = '''torture/torture.c torture/nbio.c torture/scanner.c torture/
torture/test_nttrans_create.c
torture/test_case_insensitive.c
torture/test_notify_online.c
+ torture/test_smb2.c
torture/test_smbsock_any_connect.c'''
SMBTORTURE_SRC = '''${SMBTORTURE_SRC1}