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/raw/libcliraw.h"
25 #include "libcli/smb2/smb2.h"
26 #include "libcli/smb2/smb2_calls.h"
27 #include "lib/cmdline/popt_common.h"
28 #include "lib/events/events.h"
33 static NTSTATUS torture_smb2_close(struct smb2_tree *tree, struct smb2_handle handle)
37 TALLOC_CTX *tmp_ctx = talloc_new(tree);
40 io.in.buffer_code = 0x18;
41 io.in.flags = SMB2_CLOSE_FLAGS_FULL_INFORMATION;
42 io.in.handle = handle;
43 status = smb2_close(tree, &io);
44 if (!NT_STATUS_IS_OK(status)) {
45 printf("close failed - %s\n", nt_errstr(status));
50 printf("Close gave:\n");
51 printf("create_time = %s\n", nt_time_string(tmp_ctx, io.out.create_time));
52 printf("access_time = %s\n", nt_time_string(tmp_ctx, io.out.access_time));
53 printf("write_time = %s\n", nt_time_string(tmp_ctx, io.out.write_time));
54 printf("change_time = %s\n", nt_time_string(tmp_ctx, io.out.change_time));
55 printf("alloc_size = %lld\n", io.out.alloc_size);
56 printf("size = %lld\n", io.out.size);
57 printf("file_attr = 0x%x\n", io.out.file_attr);
69 static struct smb2_handle torture_smb2_create(struct smb2_tree *tree,
72 struct smb2_create io;
74 TALLOC_CTX *tmp_ctx = talloc_new(tree);
77 io.in.buffer_code = 0x39;
78 io.in.oplock_flags = 0;
79 io.in.access_mask = SEC_RIGHTS_FILE_ALL;
80 io.in.file_attr = FILE_ATTRIBUTE_NORMAL;
81 io.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
83 NTCREATEX_SHARE_ACCESS_DELETE|
84 NTCREATEX_SHARE_ACCESS_READ|
85 NTCREATEX_SHARE_ACCESS_WRITE;
86 io.in.create_options = NTCREATEX_OPTIONS_WRITE_THROUGH;
89 status = smb2_create(tree, &io);
90 if (!NT_STATUS_IS_OK(status)) {
91 printf("create1 failed - %s\n", nt_errstr(status));
96 printf("Open gave:\n");
97 printf("oplock_flags = 0x%x\n", io.out.oplock_flags);
98 printf("create_action = 0x%x\n", io.out.create_action);
99 printf("create_time = %s\n", nt_time_string(tmp_ctx, io.out.create_time));
100 printf("access_time = %s\n", nt_time_string(tmp_ctx, io.out.access_time));
101 printf("write_time = %s\n", nt_time_string(tmp_ctx, io.out.write_time));
102 printf("change_time = %s\n", nt_time_string(tmp_ctx, io.out.change_time));
103 printf("alloc_size = %lld\n", io.out.alloc_size);
104 printf("size = %lld\n", io.out.size);
105 printf("file_attr = 0x%x\n", io.out.file_attr);
106 printf("handle = %016llx%016llx\n",
107 io.out.handle.data[0],
108 io.out.handle.data[1]);
111 talloc_free(tmp_ctx);
113 return io.out.handle;
118 basic testing of SMB2 connection calls
120 BOOL torture_smb2_connect(void)
122 TALLOC_CTX *mem_ctx = talloc_new(NULL);
123 struct smb2_tree *tree;
124 const char *host = lp_parm_string(-1, "torture", "host");
125 const char *share = lp_parm_string(-1, "torture", "share");
126 struct cli_credentials *credentials = cmdline_credentials;
127 struct smb2_handle h1, h2;
130 status = smb2_connect(mem_ctx, host, share, credentials, &tree,
131 event_context_find(mem_ctx));
132 if (!NT_STATUS_IS_OK(status)) {
133 printf("Connection failed - %s\n", nt_errstr(status));
137 h1 = torture_smb2_create(tree, "test9.dat");
138 h2 = torture_smb2_create(tree, "test9.dat");
139 torture_smb2_close(tree, h1);
140 torture_smb2_close(tree, h2);
142 talloc_free(mem_ctx);