2 Unix SMB/CIFS implementation.
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"
27 #include "torture/smb2/proto.h"
33 union smb_search_data data;
35 #define LEVEL(x) #x, x
36 { LEVEL(SMB2_FIND_ID_BOTH_DIRECTORY_INFO) },
37 { LEVEL(SMB2_FIND_DIRECTORY_INFO) },
38 { LEVEL(SMB2_FIND_FULL_DIRECTORY_INFO) },
39 { LEVEL(SMB2_FIND_NAME_INFO) },
40 { LEVEL(SMB2_FIND_BOTH_DIRECTORY_INFO) },
41 { LEVEL(SMB2_FIND_ID_FULL_DIRECTORY_INFO) },
44 #define FNAME "smb2-find.dat"
46 #define CHECK_VALUE(call_name, stype, field) do { \
47 union smb_search_data *d = find_level("SMB2_FIND_" #call_name); \
48 if (io.all_info2.out.field != d->stype.field) { \
49 printf("(%s) %s/%s should be 0x%llx - 0x%llx\n", __location__, \
51 (long long)io.all_info2.out.field, (long long)d->stype.field); \
55 #define CHECK_STRING(call_name, stype, field1, field2) do { \
56 union smb_search_data *d = find_level("SMB2_FIND_" #call_name); \
57 if (strcmp(io.all_info2.out.field2.s, d->stype.field1.s) != 0) { \
58 printf("(%s) %s/%s should be '%s' - '%s'\n", __location__, \
59 #call_name, #field2, \
60 io.all_info2.out.field2.s, d->stype.field1.s); \
64 #define CHECK_CONST_STRING(call_name, stype, field, str) do { \
65 union smb_search_data *d = find_level("SMB2_FIND_" #call_name); \
66 if (strcmp(str, d->stype.field.s) != 0) { \
67 printf("(%s) %s/%s should be '%s' - '%s'\n", __location__, \
69 str, d->stype.field.s); \
73 static union smb_search_data *find_level(const char *name)
76 for (i=0;i<ARRAY_SIZE(levels);i++) {
77 if (strcmp(name, levels[i].name) == 0) {
78 return &levels[i].data;
87 static BOOL torture_smb2_find_levels(struct smb2_tree *tree)
89 struct smb2_handle handle;
94 union smb_fileinfo io;
97 status = smb2_create_complex_file(tree, FNAME, &handle);
98 if (!NT_STATUS_IS_OK(status)) {
102 io.generic.level = RAW_FILEINFO_ALT_NAME_INFORMATION;
103 io.generic.in.file.handle = handle;
104 status = smb2_getinfo_file(tree, tree, &io);
105 if (!NT_STATUS_IS_OK(status)) {
108 alt_name = talloc_strdup(tree, io.alt_name_info.out.fname.s);
110 io.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
111 io.generic.in.file.handle = handle;
112 status = smb2_getinfo_file(tree, tree, &io);
113 if (!NT_STATUS_IS_OK(status)) {
117 status = smb2_util_roothandle(tree, &handle);
118 if (!NT_STATUS_IS_OK(status)) {
123 f.in.handle = handle;
124 f.in.pattern = FNAME;
125 f.in.continue_flags = SMB2_CONTINUE_FLAG_RESTART;
126 f.in.max_response_size = 0x10000;
128 for (i=0;i<ARRAY_SIZE(levels);i++) {
129 union smb_search_data *d;
132 f.in.level = levels[i].level - 0x100;
134 levels[i].status = smb2_find_level(tree, tree, &f, &count, &d);
135 if (!NT_STATUS_IS_OK(levels[i].status)) {
136 printf("%s failed - %s\n", levels[i].name,
137 nt_errstr(levels[i].status));
141 printf("Expected count 1 - got %d in %s\n", count, levels[i].name);
145 levels[i].data = d[0];
148 CHECK_VALUE(DIRECTORY_INFO, directory_info, create_time);
149 CHECK_VALUE(DIRECTORY_INFO, directory_info, access_time);
150 CHECK_VALUE(DIRECTORY_INFO, directory_info, write_time);
151 CHECK_VALUE(DIRECTORY_INFO, directory_info, change_time);
152 CHECK_VALUE(DIRECTORY_INFO, directory_info, size);
153 CHECK_VALUE(DIRECTORY_INFO, directory_info, alloc_size);
154 CHECK_VALUE(DIRECTORY_INFO, directory_info, attrib);
155 CHECK_CONST_STRING(DIRECTORY_INFO, directory_info, name, FNAME);
157 CHECK_VALUE(FULL_DIRECTORY_INFO, full_directory_info, create_time);
158 CHECK_VALUE(FULL_DIRECTORY_INFO, full_directory_info, access_time);
159 CHECK_VALUE(FULL_DIRECTORY_INFO, full_directory_info, write_time);
160 CHECK_VALUE(FULL_DIRECTORY_INFO, full_directory_info, change_time);
161 CHECK_VALUE(FULL_DIRECTORY_INFO, full_directory_info, size);
162 CHECK_VALUE(FULL_DIRECTORY_INFO, full_directory_info, alloc_size);
163 CHECK_VALUE(FULL_DIRECTORY_INFO, full_directory_info, attrib);
164 CHECK_VALUE(FULL_DIRECTORY_INFO, full_directory_info, ea_size);
165 CHECK_CONST_STRING(FULL_DIRECTORY_INFO, full_directory_info, name, FNAME);
167 CHECK_VALUE(BOTH_DIRECTORY_INFO, both_directory_info, create_time);
168 CHECK_VALUE(BOTH_DIRECTORY_INFO, both_directory_info, access_time);
169 CHECK_VALUE(BOTH_DIRECTORY_INFO, both_directory_info, write_time);
170 CHECK_VALUE(BOTH_DIRECTORY_INFO, both_directory_info, change_time);
171 CHECK_VALUE(BOTH_DIRECTORY_INFO, both_directory_info, size);
172 CHECK_VALUE(BOTH_DIRECTORY_INFO, both_directory_info, alloc_size);
173 CHECK_VALUE(BOTH_DIRECTORY_INFO, both_directory_info, attrib);
174 CHECK_VALUE(BOTH_DIRECTORY_INFO, both_directory_info, ea_size);
175 CHECK_CONST_STRING(BOTH_DIRECTORY_INFO, both_directory_info, short_name, alt_name);
176 CHECK_CONST_STRING(BOTH_DIRECTORY_INFO, both_directory_info, name, FNAME);
178 CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, create_time);
179 CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, access_time);
180 CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, write_time);
181 CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, change_time);
182 CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, size);
183 CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, alloc_size);
184 CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, attrib);
185 CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, ea_size);
186 CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, file_id);
187 CHECK_CONST_STRING(ID_FULL_DIRECTORY_INFO, id_full_directory_info, name, FNAME);
189 CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, create_time);
190 CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, access_time);
191 CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, write_time);
192 CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, change_time);
193 CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, size);
194 CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, alloc_size);
195 CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, attrib);
196 CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, ea_size);
197 CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, file_id);
198 CHECK_CONST_STRING(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, name, FNAME);
205 /* basic testing of all SMB2 find levels
207 BOOL torture_smb2_find(void)
209 TALLOC_CTX *mem_ctx = talloc_new(NULL);
210 struct smb2_tree *tree;
214 if (!torture_smb2_connection(mem_ctx, &tree)) {
218 status = torture_setup_complex_file(tree, FNAME);
219 if (!NT_STATUS_IS_OK(status)) {
222 torture_setup_complex_file(tree, FNAME ":streamtwo");
224 ret &= torture_smb2_find_levels(tree);
226 talloc_free(mem_ctx);