2 Unix SMB/CIFS implementation.
4 test suite for SMB2 connection operations
6 Copyright (C) Andrew Tridgell 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "libcli/smb2/smb2.h"
25 #include "libcli/smb2/smb2_calls.h"
30 static NTSTATUS torture_smb2_close(struct smb2_tree *tree, struct smb2_handle handle)
34 TALLOC_CTX *tmp_ctx = talloc_new(tree);
37 io.in.flags = SMB2_CLOSE_FLAGS_FULL_INFORMATION;
38 io.in.handle = handle;
39 status = smb2_close(tree, &io);
40 if (!NT_STATUS_IS_OK(status)) {
41 printf("close failed - %s\n", nt_errstr(status));
46 printf("Close gave:\n");
47 printf("create_time = %s\n", nt_time_string(tmp_ctx, io.out.create_time));
48 printf("access_time = %s\n", nt_time_string(tmp_ctx, io.out.access_time));
49 printf("write_time = %s\n", nt_time_string(tmp_ctx, io.out.write_time));
50 printf("change_time = %s\n", nt_time_string(tmp_ctx, io.out.change_time));
51 printf("alloc_size = %lld\n", (long long)io.out.alloc_size);
52 printf("size = %lld\n", (long long)io.out.size);
53 printf("file_attr = 0x%x\n", io.out.file_attr);
65 static NTSTATUS torture_smb2_write(struct smb2_tree *tree, struct smb2_handle handle)
74 if (lp_parm_bool(-1, "torture", "dangerous", False)) {
75 data = data_blob_talloc(tree, NULL, 160000);
77 data = data_blob_talloc(tree, NULL, 120000);
79 for (i=0;i<data.length;i++) {
88 status = smb2_write(tree, &w);
89 if (!NT_STATUS_IS_OK(status)) {
90 printf("write failed - %s\n", nt_errstr(status));
94 torture_smb2_all_info(tree, handle);
96 status = smb2_write(tree, &w);
97 if (!NT_STATUS_IS_OK(status)) {
98 printf("write failed - %s\n", nt_errstr(status));
102 torture_smb2_all_info(tree, handle);
105 f.in.handle = handle;
107 status = smb2_flush(tree, &f);
108 if (!NT_STATUS_IS_OK(status)) {
109 printf("flush failed - %s\n", nt_errstr(status));
114 r.in.length = data.length;
116 r.in.handle = handle;
118 status = smb2_read(tree, tree, &r);
119 if (!NT_STATUS_IS_OK(status)) {
120 printf("read failed - %s\n", nt_errstr(status));
124 if (data.length != r.out.data.length ||
125 memcmp(data.data, r.out.data.data, data.length) != 0) {
126 printf("read data mismatch\n");
127 return NT_STATUS_NET_WRITE_FAULT;
137 static struct smb2_handle torture_smb2_create(struct smb2_tree *tree,
140 struct smb2_create io;
142 TALLOC_CTX *tmp_ctx = talloc_new(tree);
145 io.in.oplock_flags = 0;
146 io.in.access_mask = SEC_RIGHTS_FILE_ALL;
147 io.in.file_attr = FILE_ATTRIBUTE_NORMAL;
148 io.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
150 NTCREATEX_SHARE_ACCESS_DELETE|
151 NTCREATEX_SHARE_ACCESS_READ|
152 NTCREATEX_SHARE_ACCESS_WRITE;
153 io.in.create_options = NTCREATEX_OPTIONS_WRITE_THROUGH;
156 status = smb2_create(tree, tmp_ctx, &io);
157 if (!NT_STATUS_IS_OK(status)) {
158 printf("create1 failed - %s\n", nt_errstr(status));
159 return io.out.handle;
163 printf("Open gave:\n");
164 printf("oplock_flags = 0x%x\n", io.out.oplock_flags);
165 printf("create_action = 0x%x\n", io.out.create_action);
166 printf("create_time = %s\n", nt_time_string(tmp_ctx, io.out.create_time));
167 printf("access_time = %s\n", nt_time_string(tmp_ctx, io.out.access_time));
168 printf("write_time = %s\n", nt_time_string(tmp_ctx, io.out.write_time));
169 printf("change_time = %s\n", nt_time_string(tmp_ctx, io.out.change_time));
170 printf("alloc_size = %lld\n", (long long)io.out.alloc_size);
171 printf("size = %lld\n", (long long)io.out.size);
172 printf("file_attr = 0x%x\n", io.out.file_attr);
173 printf("handle = %016llx%016llx\n",
174 (long long)io.out.handle.data[0],
175 (long long)io.out.handle.data[1]);
178 talloc_free(tmp_ctx);
180 return io.out.handle;
185 basic testing of SMB2 connection calls
187 BOOL torture_smb2_connect(void)
189 TALLOC_CTX *mem_ctx = talloc_new(NULL);
190 struct smb2_tree *tree;
191 struct smb2_handle h1, h2;
194 if (!torture_smb2_connection(mem_ctx, &tree)) {
198 h1 = torture_smb2_create(tree, "test9.dat");
199 h2 = torture_smb2_create(tree, "test9.dat");
200 torture_smb2_write(tree, h1);
201 torture_smb2_close(tree, h1);
202 torture_smb2_close(tree, h2);
204 status = smb2_tdis(tree);
205 if (!NT_STATUS_IS_OK(status)) {
206 printf("tdis failed - %s\n", nt_errstr(status));
210 status = smb2_tdis(tree);
211 if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
212 printf("tdis should have disabled session - %s\n", nt_errstr(status));
216 status = smb2_logoff(tree->session);
217 if (!NT_STATUS_IS_OK(status)) {
218 printf("Logoff failed - %s\n", nt_errstr(status));
222 status = smb2_logoff(tree->session);
223 if (!NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
224 printf("Logoff should have disabled session - %s\n", nt_errstr(status));
228 status = smb2_keepalive(tree->session->transport);
229 if (!NT_STATUS_IS_OK(status)) {
230 printf("keepalive failed? - %s\n", nt_errstr(status));
234 talloc_free(mem_ctx);