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 3 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, see <http://www.gnu.org/licenses/>.
23 #include "libcli/smb2/smb2.h"
24 #include "libcli/smb2/smb2_calls.h"
26 #include "torture/torture.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_CONST_STRING(call_name, stype, field, str) do { \
56 union smb_search_data *d = find_level("SMB2_FIND_" #call_name); \
57 if (strcmp(str, d->stype.field.s) != 0) { \
58 printf("(%s) %s/%s should be '%s' - '%s'\n", __location__, \
60 str, d->stype.field.s); \
64 static union smb_search_data *find_level(const char *name)
67 for (i=0;i<ARRAY_SIZE(levels);i++) {
68 if (strcmp(name, levels[i].name) == 0) {
69 return &levels[i].data;
78 static bool torture_smb2_find_levels(struct smb2_tree *tree)
80 struct smb2_handle handle;
85 union smb_fileinfo io;
88 status = smb2_create_complex_file(tree, FNAME, &handle);
89 if (!NT_STATUS_IS_OK(status)) {
93 io.generic.level = RAW_FILEINFO_ALT_NAME_INFORMATION;
94 io.generic.in.file.handle = handle;
95 status = smb2_getinfo_file(tree, tree, &io);
96 if (!NT_STATUS_IS_OK(status)) {
99 alt_name = talloc_strdup(tree, io.alt_name_info.out.fname.s);
101 io.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
102 io.generic.in.file.handle = handle;
103 status = smb2_getinfo_file(tree, tree, &io);
104 if (!NT_STATUS_IS_OK(status)) {
108 status = smb2_util_roothandle(tree, &handle);
109 if (!NT_STATUS_IS_OK(status)) {
114 f.in.file.handle = handle;
115 f.in.pattern = FNAME;
116 f.in.continue_flags = SMB2_CONTINUE_FLAG_RESTART;
117 f.in.max_response_size = 0x10000;
119 for (i=0;i<ARRAY_SIZE(levels);i++) {
120 union smb_search_data *d;
123 f.in.level = levels[i].level - 0x100;
125 levels[i].status = smb2_find_level(tree, tree, &f, &count, &d);
126 if (!NT_STATUS_IS_OK(levels[i].status)) {
127 printf("%s failed - %s\n", levels[i].name,
128 nt_errstr(levels[i].status));
132 printf("Expected count 1 - got %d in %s\n", count, levels[i].name);
136 levels[i].data = d[0];
139 CHECK_VALUE(DIRECTORY_INFO, directory_info, create_time);
140 CHECK_VALUE(DIRECTORY_INFO, directory_info, access_time);
141 CHECK_VALUE(DIRECTORY_INFO, directory_info, write_time);
142 CHECK_VALUE(DIRECTORY_INFO, directory_info, change_time);
143 CHECK_VALUE(DIRECTORY_INFO, directory_info, size);
144 CHECK_VALUE(DIRECTORY_INFO, directory_info, alloc_size);
145 CHECK_VALUE(DIRECTORY_INFO, directory_info, attrib);
146 CHECK_CONST_STRING(DIRECTORY_INFO, directory_info, name, FNAME);
148 CHECK_VALUE(FULL_DIRECTORY_INFO, full_directory_info, create_time);
149 CHECK_VALUE(FULL_DIRECTORY_INFO, full_directory_info, access_time);
150 CHECK_VALUE(FULL_DIRECTORY_INFO, full_directory_info, write_time);
151 CHECK_VALUE(FULL_DIRECTORY_INFO, full_directory_info, change_time);
152 CHECK_VALUE(FULL_DIRECTORY_INFO, full_directory_info, size);
153 CHECK_VALUE(FULL_DIRECTORY_INFO, full_directory_info, alloc_size);
154 CHECK_VALUE(FULL_DIRECTORY_INFO, full_directory_info, attrib);
155 CHECK_VALUE(FULL_DIRECTORY_INFO, full_directory_info, ea_size);
156 CHECK_CONST_STRING(FULL_DIRECTORY_INFO, full_directory_info, name, FNAME);
158 CHECK_VALUE(BOTH_DIRECTORY_INFO, both_directory_info, create_time);
159 CHECK_VALUE(BOTH_DIRECTORY_INFO, both_directory_info, access_time);
160 CHECK_VALUE(BOTH_DIRECTORY_INFO, both_directory_info, write_time);
161 CHECK_VALUE(BOTH_DIRECTORY_INFO, both_directory_info, change_time);
162 CHECK_VALUE(BOTH_DIRECTORY_INFO, both_directory_info, size);
163 CHECK_VALUE(BOTH_DIRECTORY_INFO, both_directory_info, alloc_size);
164 CHECK_VALUE(BOTH_DIRECTORY_INFO, both_directory_info, attrib);
165 CHECK_VALUE(BOTH_DIRECTORY_INFO, both_directory_info, ea_size);
166 CHECK_CONST_STRING(BOTH_DIRECTORY_INFO, both_directory_info, short_name, alt_name);
167 CHECK_CONST_STRING(BOTH_DIRECTORY_INFO, both_directory_info, name, FNAME);
169 CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, create_time);
170 CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, access_time);
171 CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, write_time);
172 CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, change_time);
173 CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, size);
174 CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, alloc_size);
175 CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, attrib);
176 CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, ea_size);
177 CHECK_VALUE(ID_FULL_DIRECTORY_INFO, id_full_directory_info, file_id);
178 CHECK_CONST_STRING(ID_FULL_DIRECTORY_INFO, id_full_directory_info, name, FNAME);
180 CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, create_time);
181 CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, access_time);
182 CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, write_time);
183 CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, change_time);
184 CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, size);
185 CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, alloc_size);
186 CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, attrib);
187 CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, ea_size);
188 CHECK_VALUE(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, file_id);
189 CHECK_CONST_STRING(ID_BOTH_DIRECTORY_INFO, id_both_directory_info, name, FNAME);
196 /* basic testing of all SMB2 find levels
198 bool torture_smb2_find(struct torture_context *torture)
200 TALLOC_CTX *mem_ctx = talloc_new(NULL);
201 struct smb2_tree *tree;
205 if (!torture_smb2_connection(mem_ctx, &tree)) {
209 status = torture_setup_complex_file(tree, FNAME);
210 if (!NT_STATUS_IS_OK(status)) {
213 torture_setup_complex_file(tree, FNAME ":streamtwo");
215 ret &= torture_smb2_find_levels(tree);
217 talloc_free(mem_ctx);