2 Unix SMB/CIFS implementation.
3 Initial test for the smb2 client lib
4 Copyright (C) Volker Lendecke 2011
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "torture/proto.h"
23 #include "libsmb/smb2cli.h"
24 #include "libcli/security/security.h"
26 extern fstring host, workgroup, share, password, username, myname;
28 bool run_smb2_basic(int dummy)
30 struct cli_state *cli;
32 uint64_t fid_persistent, fid_volatile;
33 const char *hello = "Hello, world\n";
37 uint32_t dir_data_length;
39 printf("Starting SMB2-BASIC\n");
41 if (!torture_init_connection(&cli)) {
44 cli->smb2.pid = 0xFEFF;
46 status = smb2cli_negprot(cli);
47 if (!NT_STATUS_IS_OK(status)) {
48 printf("smb2cli_negprot returned %s\n", nt_errstr(status));
52 status = smb2cli_sesssetup(cli, username, workgroup, password);
53 if (!NT_STATUS_IS_OK(status)) {
54 printf("smb2cli_sesssetup returned %s\n", nt_errstr(status));
58 status = smb2cli_tcon(cli, share);
59 if (!NT_STATUS_IS_OK(status)) {
60 printf("smb2cli_tcon returned %s\n", nt_errstr(status));
64 status = smb2cli_create(
65 cli, "test.txt", SMB2_OPLOCK_LEVEL_NONE, 0,
66 MAXIMUM_ALLOWED_ACCESS, FILE_ATTRIBUTE_NORMAL,
67 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
68 FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, NULL,
69 &fid_persistent, &fid_volatile);
70 if (!NT_STATUS_IS_OK(status)) {
71 printf("smb2cli_create returned %s\n", nt_errstr(status));
75 status = smb2cli_write(cli, strlen(hello), 0, fid_persistent,
76 fid_volatile, 0, 0, (const uint8_t *)hello);
77 if (!NT_STATUS_IS_OK(status)) {
78 printf("smb2cli_write returned %s\n", nt_errstr(status));
82 status = smb2cli_read(cli, 0x10000, 0, fid_persistent,
84 talloc_tos(), &result, &nread);
85 if (!NT_STATUS_IS_OK(status)) {
86 printf("smb2cli_read returned %s\n", nt_errstr(status));
90 if (nread != strlen(hello)) {
91 printf("smb2cli_read returned %d bytes, expected %d\n",
92 (int)nread, (int)strlen(hello));
96 if (memcmp(hello, result, nread) != 0) {
97 printf("smb2cli_read returned '%s', expected '%s'\n",
102 status = smb2cli_close(cli, 0, fid_persistent, fid_volatile);
103 if (!NT_STATUS_IS_OK(status)) {
104 printf("smb2cli_close returned %s\n", nt_errstr(status));
108 status = smb2cli_create(
109 cli, "", SMB2_OPLOCK_LEVEL_NONE, 0,
110 MAXIMUM_ALLOWED_ACCESS, FILE_ATTRIBUTE_DIRECTORY, 0,
111 FILE_OPEN, 0, NULL, &fid_persistent, &fid_volatile);
112 if (!NT_STATUS_IS_OK(status)) {
113 printf("smb2cli_create returned %s\n", nt_errstr(status));
117 status = smb2cli_query_directory(
118 cli, 1, 0, 0, fid_persistent, fid_volatile, "*", 0xffff,
119 talloc_tos(), &dir_data, &dir_data_length);
121 if (!NT_STATUS_IS_OK(status)) {
122 printf("smb2cli_query_directory returned %s\n", nt_errstr(status));
126 status = smb2cli_close(cli, 0, fid_persistent, fid_volatile);
127 if (!NT_STATUS_IS_OK(status)) {
128 printf("smb2cli_close returned %s\n", nt_errstr(status));