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 "librpc/gen_ndr/ndr_security.h"
28 #include "lib/cmdline/popt_common.h"
29 #include "lib/events/events.h"
31 #define BASEDIR "\\testsmb2"
33 #define CHECK_STATUS(status, correct) do { \
34 if (!NT_STATUS_EQUAL(status, correct)) { \
35 printf("(%s) Incorrect status %s - should be %s\n", \
36 __location__, nt_errstr(status), nt_errstr(correct)); \
45 static NTSTATUS torture_smb2_close(struct smb2_tree *tree, struct smb2_handle handle)
49 TALLOC_CTX *tmp_ctx = talloc_new(tree);
52 io.in.buffer_code = 0x18;
53 io.in.flags = SMB2_CLOSE_FLAGS_FULL_INFORMATION;
54 io.in.handle = handle;
55 status = smb2_close(tree, &io);
56 if (!NT_STATUS_IS_OK(status)) {
57 printf("close failed - %s\n", nt_errstr(status));
61 printf("Close gave:\n");
62 printf("create_time = %s\n", nt_time_string(tmp_ctx, io.out.create_time));
63 printf("access_time = %s\n", nt_time_string(tmp_ctx, io.out.access_time));
64 printf("write_time = %s\n", nt_time_string(tmp_ctx, io.out.write_time));
65 printf("change_time = %s\n", nt_time_string(tmp_ctx, io.out.change_time));
66 printf("alloc_size = %lld\n", io.out.alloc_size);
67 printf("size = %lld\n", io.out.size);
68 printf("file_attr = 0x%x\n", io.out.file_attr);
79 static struct smb2_handle torture_smb2_create(struct smb2_tree *tree,
82 struct smb2_create io;
84 TALLOC_CTX *tmp_ctx = talloc_new(tree);
87 io.in.buffer_code = 0x39;
88 io.in.oplock_flags = 0;
89 io.in.access_mask = SEC_RIGHTS_FILE_ALL;
90 io.in.file_attr = FILE_ATTRIBUTE_NORMAL;
91 io.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
93 NTCREATEX_SHARE_ACCESS_DELETE|
94 NTCREATEX_SHARE_ACCESS_READ|
95 NTCREATEX_SHARE_ACCESS_WRITE;
96 io.in.create_options = NTCREATEX_OPTIONS_WRITE_THROUGH;
99 status = smb2_create(tree, &io);
100 if (!NT_STATUS_IS_OK(status)) {
101 printf("create1 failed - %s\n", nt_errstr(status));
102 return io.out.handle;
105 printf("Open gave:\n");
106 printf("oplock_flags = 0x%x\n", io.out.oplock_flags);
107 printf("create_action = 0x%x\n", io.out.create_action);
108 printf("create_time = %s\n", nt_time_string(tmp_ctx, io.out.create_time));
109 printf("access_time = %s\n", nt_time_string(tmp_ctx, io.out.access_time));
110 printf("write_time = %s\n", nt_time_string(tmp_ctx, io.out.write_time));
111 printf("change_time = %s\n", nt_time_string(tmp_ctx, io.out.change_time));
112 printf("alloc_size = %lld\n", io.out.alloc_size);
113 printf("size = %lld\n", io.out.size);
114 printf("file_attr = 0x%x\n", io.out.file_attr);
115 printf("handle = %016llx%016llx\n",
116 io.out.handle.data[0],
117 io.out.handle.data[1]);
119 talloc_free(tmp_ctx);
121 return io.out.handle;
125 basic testing of SMB2 connection calls
127 BOOL torture_smb2_connect(void)
129 TALLOC_CTX *mem_ctx = talloc_new(NULL);
130 struct smb2_tree *tree;
131 const char *host = lp_parm_string(-1, "torture", "host");
132 const char *share = lp_parm_string(-1, "torture", "share");
133 struct cli_credentials *credentials = cmdline_credentials;
134 struct smb2_handle h1, h2;
137 status = smb2_connect(mem_ctx, host, share, credentials, &tree,
138 event_context_find(mem_ctx));
139 if (!NT_STATUS_IS_OK(status)) {
140 printf("Connection failed - %s\n", nt_errstr(status));
144 h1 = torture_smb2_create(tree, "test9.dat");
145 h2 = torture_smb2_create(tree, "test9.dat");
146 torture_smb2_close(tree, h1);
147 torture_smb2_close(tree, h2);
149 talloc_free(mem_ctx);