Debian Codegraph @

source4/torture/raw/qfsinfo.c

raw
1 /*
2 Unix SMB/CIFS implementation.
3 RAW_QFS_* individual test suite
4 Copyright (C) Andrew Tridgell 2003
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "includes.h"
21 #include <math.h>
22 #include "libcli/libcli.h"
23 #include "torture/util.h"
24 #include "torture/basic/proto.h"
25 #include "torture/raw/proto.h"
26
27
28 static struct {
29 const char *name;
30 enum smb_fsinfo_level level;
31 uint32_t capability_mask;
32 NTSTATUS status;
33 union smb_fsinfo fsinfo;
34 } levels[] = {
35 {
36 .name = "DSKATTR",
37 .level = RAW_QFS_DSKATTR,
38 },
39 {
40 .name = "ALLOCATION",
41 .level = RAW_QFS_ALLOCATION,
42 },
43 {
44 .name = "VOLUME",
45 .level = RAW_QFS_VOLUME,
46 },
47 {
48 .name = "VOLUME_INFO",
49 .level = RAW_QFS_VOLUME_INFO,
50 },
51 {
52 .name = "SIZE_INFO",
53 .level = RAW_QFS_SIZE_INFO,
54 },
55 {
56 .name = "DEVICE_INFO",
57 .level = RAW_QFS_DEVICE_INFO,
58 },
59 {
60 .name = "ATTRIBUTE_INFO",
61 .level = RAW_QFS_ATTRIBUTE_INFO,
62 },
63 {
64 .name = "UNIX_INFO",
65 .level = RAW_QFS_UNIX_INFO,
66 .capability_mask = CAP_UNIX,
67 },
68 {
69 .name = "VOLUME_INFORMATION",
70 .level = RAW_QFS_VOLUME_INFORMATION,
71 },
72 {
73 .name = "SIZE_INFORMATION",
74 .level = RAW_QFS_SIZE_INFORMATION,
75 },
76 {
77 .name = "DEVICE_INFORMATION",
78 .level = RAW_QFS_DEVICE_INFORMATION,
79 },
80 {
81 .name = "ATTRIBUTE_INFORMATION",
82 .level = RAW_QFS_ATTRIBUTE_INFORMATION,
83 },
84 {
85 .name = "QUOTA_INFORMATION",
86 .level = RAW_QFS_QUOTA_INFORMATION,
87 },
88 {
89 .name = "FULL_SIZE_INFORMATION",
90 .level = RAW_QFS_FULL_SIZE_INFORMATION,
91 },
92 #if 0
93 /* w2k3 seems to no longer support this */
94 {"OBJECTID_INFORMATION", RAW_QFS_OBJECTID_INFORMATION, },
95 #endif
96 { .name = NULL, },
97 };
98
99
100 /*
101 find a level in the levels[] table
102 */
103 static union smb_fsinfo *find(const char *name)
104 {
105 int i;
106 for (i=0; levels[i].name; i++) {
107 if (strcmp(name, levels[i].name) == 0 &&
108 NT_STATUS_IS_OK(levels[i].status)) {
109 return &levels[i].fsinfo;
110 }
111 }
112 return NULL;
113 }
114
115 /* local macros to make the code below more readable */
116 #define VAL_EQUAL(n1, v1, n2, v2) do {if (s1->n1.out.v1 != s2->n2.out.v2) { \
117 printf("%s/%s [%u] != %s/%s [%u] at %s(%d)\n", \
118 #n1, #v1, (unsigned int)s1->n1.out.v1, \
119 #n2, #v2, (unsigned int)s2->n2.out.v2, \
120 __FILE__, __LINE__); \
121 ret = false; \
122 }} while(0)
123
124 #define VAL_APPROX_EQUAL(n1, v1, n2, v2) do {if (abs((int)(s1->n1.out.v1) - (int)(s2->n2.out.v2)) > 0.1*s1->n1.out.v1) { \
125 printf("%s/%s [%u] != %s/%s [%u] at %s(%d)\n", \
126 #n1, #v1, (unsigned int)s1->n1.out.v1, \
127 #n2, #v2, (unsigned int)s2->n2.out.v2, \
128 __FILE__, __LINE__); \
129 ret = false; \
130 }} while(0)
131
132 #define STR_EQUAL(n1, v1, n2, v2) do { \
133 if (strcmp_safe(s1->n1.out.v1, s2->n2.out.v2)) { \
134 printf("%s/%s [%s] != %s/%s [%s] at %s(%d)\n", \
135 #n1, #v1, s1->n1.out.v1, \
136 #n2, #v2, s2->n2.out.v2, \
137 __FILE__, __LINE__); \
138 ret = false; \
139 }} while(0)
140
141 #define STRUCT_EQUAL(n1, v1, n2, v2) do {if (memcmp(&s1->n1.out.v1,&s2->n2.out.v2,sizeof(s1->n1.out.v1))) { \
142 printf("%s/%s != %s/%s at %s(%d)\n", \
143 #n1, #v1, \
144 #n2, #v2, \
145 __FILE__, __LINE__); \
146 ret = false; \
147 }} while(0)
148
149 /* used to find hints on unknown values - and to make sure
150 we zero-fill */
151 #define VAL_UNKNOWN(n1, v1) do {if (s1->n1.out.v1 != 0) { \
152 printf("%s/%s non-zero unknown - %u (0x%x) at %s(%d)\n", \
153 #n1, #v1, \
154 (unsigned int)s1->n1.out.v1, \
155 (unsigned int)s1->n1.out.v1, \
156 __FILE__, __LINE__); \
157 ret = false; \
158 }} while(0)
159
160 /* basic testing of all RAW_QFS_* calls
161 for each call we test that it succeeds, and where possible test
162 for consistency between the calls.
163
164 Some of the consistency tests assume that the target filesystem is
165 quiescent, which is sometimes hard to achieve
166 */
167 bool torture_raw_qfsinfo(struct torture_context *torture,
168 struct smbcli_state *cli)
169 {
170 size_t i;
171 bool ret = true;
172 size_t count;
173 union smb_fsinfo *s1, *s2;
174
175 /* scan all the levels, pulling the results */
176 for (i=0; levels[i].name; i++) {
177 torture_comment(torture, "Running level %s\n", levels[i].name);
178 levels[i].fsinfo.generic.level = levels[i].level;
179 levels[i].status = smb_raw_fsinfo(cli->tree, torture, &levels[i].fsinfo);
180 }
181
182 /* check for completely broken levels */
183 for (count=i=0; levels[i].name; i++) {
184 uint32_t cap = cli->transport->negotiate.capabilities;
185 /* see if this server claims to support this level */
186 if ((cap & levels[i].capability_mask) != levels[i].capability_mask) {
187 continue;
188 }
189
190 if (!NT_STATUS_IS_OK(levels[i].status)) {
191 printf("ERROR: level %s failed - %s\n",
192 levels[i].name, nt_errstr(levels[i].status));
193 count++;
194 }
195 }
196
197 if (count != 0) {
198 torture_comment(torture, "%zu levels failed\n", count);
199 torture_assert(torture, count > 13, "too many level failures - giving up");
200 }
201
202 torture_comment(torture, "check for correct aliases\n");
203 s1 = find("SIZE_INFO");
204 s2 = find("SIZE_INFORMATION");
205 if (s1 && s2) {
206 VAL_EQUAL(size_info, total_alloc_units, size_info, total_alloc_units);
207 VAL_APPROX_EQUAL(size_info, avail_alloc_units, size_info, avail_alloc_units);
208 VAL_EQUAL(size_info, sectors_per_unit, size_info, sectors_per_unit);
209 VAL_EQUAL(size_info, bytes_per_sector, size_info, bytes_per_sector);
210 }
211
212 s1 = find("DEVICE_INFO");
213 s2 = find("DEVICE_INFORMATION");
214 if (s1 && s2) {
215 VAL_EQUAL(device_info, device_type, device_info, device_type);
216 VAL_EQUAL(device_info, characteristics, device_info, characteristics);
217 }
218
219 s1 = find("VOLUME_INFO");
220 s2 = find("VOLUME_INFORMATION");
221 if (s1 && s2) {
222 STRUCT_EQUAL(volume_info, create_time, volume_info, create_time);
223 VAL_EQUAL (volume_info, serial_number, volume_info, serial_number);
224 STR_EQUAL (volume_info, volume_name.s, volume_info, volume_name.s);
225 torture_comment(torture, "volume_info.volume_name = '%s'\n", s1->volume_info.out.volume_name.s);
226 }
227
228 s1 = find("ATTRIBUTE_INFO");
229 s2 = find("ATTRIBUTE_INFORMATION");
230 if (s1 && s2) {
231 VAL_EQUAL(attribute_info, fs_attr,
232 attribute_info, fs_attr);
233 VAL_EQUAL(attribute_info, max_file_component_length,
234 attribute_info, max_file_component_length);
235 STR_EQUAL(attribute_info, fs_type.s, attribute_info, fs_type.s);
236 torture_comment(torture, "attribute_info.fs_type = '%s'\n", s1->attribute_info.out.fs_type.s);
237 }
238
239 torture_comment(torture, "check for consistent disk sizes\n");
240 s1 = find("DSKATTR");
241 s2 = find("ALLOCATION");
242 if (s1 && s2) {
243 double size1, size2;
244 double scale = s1->dskattr.out.blocks_per_unit * s1->dskattr.out.block_size;
245 size1 = 1.0 *
246 s1->dskattr.out.units_total *
247 s1->dskattr.out.blocks_per_unit *
248 s1->dskattr.out.block_size / scale;
249 size2 = 1.0 *
250 s2->allocation.out.sectors_per_unit *
251 s2->allocation.out.total_alloc_units *
252 s2->allocation.out.bytes_per_sector / scale;
253 if (fabs(size1 - size2) > 1) {
254 printf("Inconsistent total size in DSKATTR and ALLOCATION - size1=%.0f size2=%.0f\n",
255 size1, size2);
256 ret = false;
257 }
258 torture_comment(torture, "total disk = %.0f MB\n", size1*scale/1.0e6);
259 }
260
261 torture_comment(torture, "check consistent free disk space\n");
262 s1 = find("DSKATTR");
263 s2 = find("ALLOCATION");
264 if (s1 && s2) {
265 double size1, size2;
266 double scale = s1->dskattr.out.blocks_per_unit * s1->dskattr.out.block_size;
267 size1 = 1.0 *
268 s1->dskattr.out.units_free *
269 s1->dskattr.out.blocks_per_unit *
270 s1->dskattr.out.block_size / scale;
271 size2 = 1.0 *
272 s2->allocation.out.sectors_per_unit *
273 s2->allocation.out.avail_alloc_units *
274 s2->allocation.out.bytes_per_sector / scale;
275 if (fabs(size1 - size2) > 1) {
276 printf("Inconsistent avail size in DSKATTR and ALLOCATION - size1=%.0f size2=%.0f\n",
277 size1, size2);
278 ret = false;
279 }
280 torture_comment(torture, "free disk = %.0f MB\n", size1*scale/1.0e6);
281 }
282
283 torture_comment(torture, "volume info consistency\n");
284 s1 = find("VOLUME");
285 s2 = find("VOLUME_INFO");
286 if (s1 && s2) {
287 VAL_EQUAL(volume, serial_number, volume_info, serial_number);
288 STR_EQUAL(volume, volume_name.s, volume_info, volume_name.s);
289 }
290
291 /* disk size consistency - notice that 'avail_alloc_units' maps to the caller
292 available allocation units, not the total */
293 s1 = find("SIZE_INFO");
294 s2 = find("FULL_SIZE_INFORMATION");
295 if (s1 && s2) {
296 VAL_EQUAL(size_info, total_alloc_units, full_size_information, total_alloc_units);
297 VAL_APPROX_EQUAL(size_info, avail_alloc_units, full_size_information, call_avail_alloc_units);
298 VAL_EQUAL(size_info, sectors_per_unit, full_size_information, sectors_per_unit);
299 VAL_EQUAL(size_info, bytes_per_sector, full_size_information, bytes_per_sector);
300 }
301
302 printf("check for non-zero unknown fields\n");
303 s1 = find("QUOTA_INFORMATION");
304 if (s1) {
305 VAL_UNKNOWN(quota_information, unknown[0]);
306 VAL_UNKNOWN(quota_information, unknown[1]);
307 VAL_UNKNOWN(quota_information, unknown[2]);
308 }
309
310 s1 = find("OBJECTID_INFORMATION");
311 if (s1) {
312 VAL_UNKNOWN(objectid_information, unknown[0]);
313 VAL_UNKNOWN(objectid_information, unknown[1]);
314 VAL_UNKNOWN(objectid_information, unknown[2]);
315 VAL_UNKNOWN(objectid_information, unknown[3]);
316 VAL_UNKNOWN(objectid_information, unknown[4]);
317 VAL_UNKNOWN(objectid_information, unknown[5]);
318 }
319
320
321 #define STR_CHECK(sname, stype, field, flags) do { \
322 s1 = find(sname); \
323 if (s1) { \
324 if (s1->stype.out.field.s && wire_bad_flags(&s1->stype.out.field, flags, cli->transport)) { \
325 printf("(%d) incorrect string termination in %s/%s\n", \
326 __LINE__, #stype, #field); \
327 ret = false; \
328 } \
329 }} while (0)
330
331 torture_comment(torture, "check for correct termination\n");
332
333 STR_CHECK("VOLUME", volume, volume_name, 0);
334 STR_CHECK("VOLUME_INFO", volume_info, volume_name, STR_UNICODE);
335 STR_CHECK("VOLUME_INFORMATION", volume_info, volume_name, STR_UNICODE);
336 STR_CHECK("ATTRIBUTE_INFO", attribute_info, fs_type, STR_UNICODE);
337 STR_CHECK("ATTRIBUTE_INFORMATION", attribute_info, fs_type, STR_UNICODE);
338
339 return ret;
340 }