s3:torture: add SMB2-BASIC
authorStefan Metzmacher <metze@samba.org>
Thu, 5 May 2011 16:12:07 +0000 (18:12 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 7 Jul 2011 23:22:22 +0000 (01:22 +0200)
Based on the initial patch from Volker Lendecke <vl@samba.org>.

metze

source3/Makefile.in
source3/torture/proto.h
source3/torture/test_smb2.c [new file with mode: 0644]
source3/torture/torture.c
source3/wscript_build

index da3cb1a34024feea45ceee0fac97ab26f7589204..92613abdfde53444b51d2060b20e7b8c9fe8ca60 100644 (file)
@@ -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) \
index 6a47a18cd7ce3894ce5fa01f3020fa10ff1c6feb..6b49fba1bdb6753b09d0d157b114efafbfa93e76 100644 (file)
@@ -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 (file)
index 0000000..5139306
--- /dev/null
@@ -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;
+}
index 4a01bf2a9c476507e206a43b80a310adebd57f0e..a6387c1484ed52cb34a68940ff0255ef4ee6549f 100644 (file)
@@ -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},
index fdfba98beef7062ae080185a2d201dcddc0d7285..ae1860cc62649e93af332bc2005b21f87ef378c7 100755 (executable)
@@ -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}