1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
|
/*
Unix SMB/CIFS implementation.
RAW_SFILEINFO_* individual test suite
Copyright (C) Andrew Tridgell 2003
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include "torture/torture.h"
#include "system/time.h"
#include "libcli/raw/libcliraw.h"
#include "libcli/libcli.h"
#include "torture/util.h"
#define BASEDIR "\\testsfileinfo"
/* basic testing of all RAW_SFILEINFO_* calls
for each call we test that it succeeds, and where possible test
for consistency between the calls.
*/
BOOL torture_raw_sfileinfo(struct torture_context *torture)
{
struct smbcli_state *cli;
BOOL ret = True;
TALLOC_CTX *mem_ctx;
int fnum_saved, d_fnum, fnum2, fnum = -1;
char *fnum_fname;
char *fnum_fname_new;
char *path_fname;
char *path_fname_new;
union smb_fileinfo finfo1, finfo2;
union smb_setfileinfo sfinfo;
NTSTATUS status, status2;
const char *call_name;
time_t basetime = (time(NULL) - 86400) & ~1;
BOOL check_fnum;
int n = time(NULL) % 100;
asprintf(&path_fname, BASEDIR "\\fname_test_%d.txt", n);
asprintf(&path_fname_new, BASEDIR "\\fname_test_new_%d.txt", n);
asprintf(&fnum_fname, BASEDIR "\\fnum_test_%d.txt", n);
asprintf(&fnum_fname_new, BASEDIR "\\fnum_test_new_%d.txt", n);
if (!torture_open_connection(&cli, 0)) {
return False;
}
mem_ctx = talloc_init("torture_sfileinfo");
if (!torture_setup_dir(cli, BASEDIR)) {
return False;
}
#define RECREATE_FILE(fname) do { \
if (fnum != -1) smbcli_close(cli->tree, fnum); \
fnum = create_complex_file(cli, mem_ctx, fname); \
if (fnum == -1) { \
printf("(%s) ERROR: open of %s failed (%s)\n", \
__location__, fname, smbcli_errstr(cli->tree)); \
ret = False; \
goto done; \
}} while (0)
#define RECREATE_BOTH do { \
RECREATE_FILE(path_fname); \
smbcli_close(cli->tree, fnum); \
RECREATE_FILE(fnum_fname); \
} while (0)
RECREATE_BOTH;
#define CHECK_CALL_FNUM(call, rightstatus) do { \
check_fnum = True; \
call_name = #call; \
sfinfo.generic.level = RAW_SFILEINFO_ ## call; \
sfinfo.generic.in.file.fnum = fnum; \
status = smb_raw_setfileinfo(cli->tree, &sfinfo); \
if (!NT_STATUS_EQUAL(status, rightstatus)) { \
printf("(%s) %s - %s (should be %s)\n", __location__, #call, \
nt_errstr(status), nt_errstr(rightstatus)); \
ret = False; \
} \
finfo1.generic.level = RAW_FILEINFO_ALL_INFO; \
finfo1.generic.in.file.fnum = fnum; \
status2 = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); \
if (!NT_STATUS_IS_OK(status2)) { \
printf("(%s) %s pathinfo - %s\n", __location__, #call, nt_errstr(status)); \
ret = False; \
}} while (0)
#define CHECK_CALL_PATH(call, rightstatus) do { \
check_fnum = False; \
call_name = #call; \
sfinfo.generic.level = RAW_SFILEINFO_ ## call; \
sfinfo.generic.in.file.path = path_fname; \
status = smb_raw_setpathinfo(cli->tree, &sfinfo); \
if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) { \
sfinfo.generic.in.file.path = path_fname_new; \
status = smb_raw_setpathinfo(cli->tree, &sfinfo); \
} \
if (!NT_STATUS_EQUAL(status, rightstatus)) { \
printf("(%s) %s - %s (should be %s)\n", __location__, #call, \
nt_errstr(status), nt_errstr(rightstatus)); \
ret = False; \
} \
finfo1.generic.level = RAW_FILEINFO_ALL_INFO; \
finfo1.generic.in.file.path = path_fname; \
status2 = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo1); \
if (NT_STATUS_EQUAL(status2, NT_STATUS_OBJECT_NAME_NOT_FOUND)) { \
finfo1.generic.in.file.path = path_fname_new; \
status2 = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo1); \
} \
if (!NT_STATUS_IS_OK(status2)) { \
printf("(%s) %s pathinfo - %s\n", __location__, #call, nt_errstr(status2)); \
ret = False; \
}} while (0)
#define CHECK1(call) \
do { if (NT_STATUS_IS_OK(status)) { \
finfo2.generic.level = RAW_FILEINFO_ ## call; \
if (check_fnum) { \
finfo2.generic.in.file.fnum = fnum; \
status2 = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); \
} else { \
finfo2.generic.in.file.path = path_fname; \
status2 = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo2); \
if (NT_STATUS_EQUAL(status2, NT_STATUS_OBJECT_NAME_NOT_FOUND)) { \
finfo2.generic.in.file.path = path_fname_new; \
status2 = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo2); \
} \
} \
if (!NT_STATUS_IS_OK(status2)) { \
printf("%s - %s\n", #call, nt_errstr(status2)); \
ret = False; \
} \
}} while (0)
#define CHECK_VALUE(call, stype, field, value) do { \
CHECK1(call); \
if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(status2) && finfo2.stype.out.field != value) { \
printf("(%s) %s - %s/%s should be 0x%x - 0x%x\n", __location__, \
call_name, #stype, #field, \
(uint_t)value, (uint_t)finfo2.stype.out.field); \
dump_all_info(mem_ctx, &finfo1); \
ret = False; \
}} while (0)
#define CHECK_TIME(call, stype, field, value) do { \
CHECK1(call); \
if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(status2) && nt_time_to_unix(finfo2.stype.out.field) != value) { \
printf("(%s) %s - %s/%s should be 0x%x - 0x%x\n", __location__, \
call_name, #stype, #field, \
(uint_t)value, \
(uint_t)nt_time_to_unix(finfo2.stype.out.field)); \
printf("\t%s", timestring(mem_ctx, value)); \
printf("\t%s\n", nt_time_string(mem_ctx, finfo2.stype.out.field)); \
dump_all_info(mem_ctx, &finfo1); \
ret = False; \
}} while (0)
#define CHECK_STR(call, stype, field, value) do { \
CHECK1(call); \
if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(status2) && strcmp(finfo2.stype.out.field, value) != 0) { \
printf("(%s) %s - %s/%s should be '%s' - '%s'\n", __location__, \
call_name, #stype, #field, \
value, \
finfo2.stype.out.field); \
dump_all_info(mem_ctx, &finfo1); \
ret = False; \
}} while (0)
#define CHECK_STATUS(status, correct) do { \
if (!NT_STATUS_EQUAL(status, correct)) { \
printf("(%s) Incorrect status %s - should be %s\n", \
__location__, nt_errstr(status), nt_errstr(correct)); \
ret = False; \
goto done; \
}} while (0)
printf("test setattr\n");
sfinfo.setattr.in.attrib = FILE_ATTRIBUTE_READONLY;
sfinfo.setattr.in.write_time = basetime;
CHECK_CALL_PATH(SETATTR, NT_STATUS_OK);
CHECK_VALUE (ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_READONLY);
CHECK_TIME (ALL_INFO, all_info, write_time, basetime);
printf("setting to NORMAL doesn't do anything\n");
sfinfo.setattr.in.attrib = FILE_ATTRIBUTE_NORMAL;
sfinfo.setattr.in.write_time = 0;
CHECK_CALL_PATH(SETATTR, NT_STATUS_OK);
CHECK_VALUE(ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_READONLY);
CHECK_TIME (ALL_INFO, all_info, write_time, basetime);
printf("a zero write_time means don't change\n");
sfinfo.setattr.in.attrib = 0;
sfinfo.setattr.in.write_time = 0;
CHECK_CALL_PATH(SETATTR, NT_STATUS_OK);
CHECK_VALUE(ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_NORMAL);
CHECK_TIME (ALL_INFO, all_info, write_time, basetime);
printf("test setattre\n");
sfinfo.setattre.in.create_time = basetime + 20;
sfinfo.setattre.in.access_time = basetime + 30;
sfinfo.setattre.in.write_time = basetime + 40;
CHECK_CALL_FNUM(SETATTRE, NT_STATUS_OK);
CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 20);
CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 30);
CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 40);
sfinfo.setattre.in.create_time = 0;
sfinfo.setattre.in.access_time = 0;
sfinfo.setattre.in.write_time = 0;
CHECK_CALL_FNUM(SETATTRE, NT_STATUS_OK);
CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 20);
CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 30);
CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 40);
printf("test standard level\n");
sfinfo.standard.in.create_time = basetime + 100;
sfinfo.standard.in.access_time = basetime + 200;
sfinfo.standard.in.write_time = basetime + 300;
CHECK_CALL_FNUM(STANDARD, NT_STATUS_OK);
CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 100);
CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 200);
CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 300);
printf("test basic_info level\n");
basetime += 86400;
unix_to_nt_time(&sfinfo.basic_info.in.create_time, basetime + 100);
unix_to_nt_time(&sfinfo.basic_info.in.access_time, basetime + 200);
unix_to_nt_time(&sfinfo.basic_info.in.write_time, basetime + 300);
unix_to_nt_time(&sfinfo.basic_info.in.change_time, basetime + 400);
sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_READONLY;
CHECK_CALL_FNUM(BASIC_INFO, NT_STATUS_OK);
CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 100);
CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 200);
CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 300);
CHECK_TIME(ALL_INFO, all_info, change_time, basetime + 400);
CHECK_VALUE(ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_READONLY);
printf("a zero time means don't change\n");
unix_to_nt_time(&sfinfo.basic_info.in.create_time, 0);
unix_to_nt_time(&sfinfo.basic_info.in.access_time, 0);
unix_to_nt_time(&sfinfo.basic_info.in.write_time, 0);
unix_to_nt_time(&sfinfo.basic_info.in.change_time, 0);
sfinfo.basic_info.in.attrib = 0;
CHECK_CALL_FNUM(BASIC_INFO, NT_STATUS_OK);
CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 100);
CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 200);
CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 300);
CHECK_TIME(ALL_INFO, all_info, change_time, basetime + 400);
CHECK_VALUE(ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_READONLY);
printf("test basic_information level\n");
basetime += 86400;
unix_to_nt_time(&sfinfo.basic_info.in.create_time, basetime + 100);
unix_to_nt_time(&sfinfo.basic_info.in.access_time, basetime + 200);
unix_to_nt_time(&sfinfo.basic_info.in.write_time, basetime + 300);
unix_to_nt_time(&sfinfo.basic_info.in.change_time, basetime + 400);
sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_NORMAL;
CHECK_CALL_FNUM(BASIC_INFORMATION, NT_STATUS_OK);
CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 100);
CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 200);
CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 300);
CHECK_TIME(ALL_INFO, all_info, change_time, basetime + 400);
CHECK_VALUE(ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_NORMAL);
CHECK_CALL_PATH(BASIC_INFORMATION, NT_STATUS_OK);
CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 100);
CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 200);
CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 300);
CHECK_TIME(ALL_INFO, all_info, change_time, basetime + 400);
CHECK_VALUE(ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_NORMAL);
printf("a zero time means don't change\n");
unix_to_nt_time(&sfinfo.basic_info.in.create_time, 0);
unix_to_nt_time(&sfinfo.basic_info.in.access_time, 0);
unix_to_nt_time(&sfinfo.basic_info.in.write_time, 0);
unix_to_nt_time(&sfinfo.basic_info.in.change_time, 0);
sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_NORMAL;
CHECK_CALL_FNUM(BASIC_INFORMATION, NT_STATUS_OK);
CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 100);
CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 200);
CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 300);
CHECK_TIME(ALL_INFO, all_info, change_time, basetime + 400);
CHECK_VALUE(ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_NORMAL);
CHECK_CALL_PATH(BASIC_INFORMATION, NT_STATUS_OK);
CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 100);
CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 200);
CHECK_TIME(ALL_INFO, all_info, write_time, basetime + 300);
/* interesting - w2k3 leaves change_time as current time for 0 change time
in setpathinfo
CHECK_TIME(ALL_INFO, all_info, change_time, basetime + 400);
*/
CHECK_VALUE(ALL_INFO, all_info, attrib, FILE_ATTRIBUTE_NORMAL);
printf("test disposition_info level\n");
sfinfo.disposition_info.in.delete_on_close = 1;
CHECK_CALL_FNUM(DISPOSITION_INFO, NT_STATUS_OK);
CHECK_VALUE(ALL_INFO, all_info, delete_pending, 1);
CHECK_VALUE(ALL_INFO, all_info, nlink, 0);
sfinfo.disposition_info.in.delete_on_close = 0;
CHECK_CALL_FNUM(DISPOSITION_INFO, NT_STATUS_OK);
CHECK_VALUE(ALL_INFO, all_info, delete_pending, 0);
CHECK_VALUE(ALL_INFO, all_info, nlink, 1);
printf("test disposition_information level\n");
sfinfo.disposition_info.in.delete_on_close = 1;
CHECK_CALL_FNUM(DISPOSITION_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(ALL_INFO, all_info, delete_pending, 1);
CHECK_VALUE(ALL_INFO, all_info, nlink, 0);
/* this would delete the file! */
/*
CHECK_CALL_PATH(DISPOSITION_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(ALL_INFO, all_info, delete_pending, 1);
CHECK_VALUE(ALL_INFO, all_info, nlink, 0);
*/
sfinfo.disposition_info.in.delete_on_close = 0;
CHECK_CALL_FNUM(DISPOSITION_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(ALL_INFO, all_info, delete_pending, 0);
CHECK_VALUE(ALL_INFO, all_info, nlink, 1);
CHECK_CALL_PATH(DISPOSITION_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(ALL_INFO, all_info, delete_pending, 0);
CHECK_VALUE(ALL_INFO, all_info, nlink, 1);
printf("test allocation_info level\n");
sfinfo.allocation_info.in.alloc_size = 0;
CHECK_CALL_FNUM(ALLOCATION_INFO, NT_STATUS_OK);
CHECK_VALUE(ALL_INFO, all_info, size, 0);
CHECK_VALUE(ALL_INFO, all_info, alloc_size, 0);
sfinfo.allocation_info.in.alloc_size = 4096;
CHECK_CALL_FNUM(ALLOCATION_INFO, NT_STATUS_OK);
CHECK_VALUE(ALL_INFO, all_info, alloc_size, 4096);
CHECK_VALUE(ALL_INFO, all_info, size, 0);
RECREATE_BOTH;
sfinfo.allocation_info.in.alloc_size = 0;
CHECK_CALL_FNUM(ALLOCATION_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(ALL_INFO, all_info, size, 0);
CHECK_VALUE(ALL_INFO, all_info, alloc_size, 0);
CHECK_CALL_PATH(ALLOCATION_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(ALL_INFO, all_info, size, 0);
CHECK_VALUE(ALL_INFO, all_info, alloc_size, 0);
sfinfo.allocation_info.in.alloc_size = 4096;
CHECK_CALL_FNUM(ALLOCATION_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(ALL_INFO, all_info, alloc_size, 4096);
CHECK_VALUE(ALL_INFO, all_info, size, 0);
/* setting the allocation size up via setpathinfo seems
to be broken in w2k3 */
CHECK_CALL_PATH(ALLOCATION_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(ALL_INFO, all_info, alloc_size, 0);
CHECK_VALUE(ALL_INFO, all_info, size, 0);
printf("test end_of_file_info level\n");
sfinfo.end_of_file_info.in.size = 37;
CHECK_CALL_FNUM(END_OF_FILE_INFO, NT_STATUS_OK);
CHECK_VALUE(ALL_INFO, all_info, size, 37);
sfinfo.end_of_file_info.in.size = 7;
CHECK_CALL_FNUM(END_OF_FILE_INFO, NT_STATUS_OK);
CHECK_VALUE(ALL_INFO, all_info, size, 7);
sfinfo.end_of_file_info.in.size = 37;
CHECK_CALL_FNUM(END_OF_FILE_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(ALL_INFO, all_info, size, 37);
CHECK_CALL_PATH(END_OF_FILE_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(ALL_INFO, all_info, size, 37);
sfinfo.end_of_file_info.in.size = 7;
CHECK_CALL_FNUM(END_OF_FILE_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(ALL_INFO, all_info, size, 7);
CHECK_CALL_PATH(END_OF_FILE_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(ALL_INFO, all_info, size, 7);
printf("test position_information level\n");
sfinfo.position_information.in.position = 123456;
CHECK_CALL_FNUM(POSITION_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(POSITION_INFORMATION, position_information, position, 123456);
CHECK_CALL_PATH(POSITION_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(POSITION_INFORMATION, position_information, position, 0);
printf("test mode_information level\n");
sfinfo.mode_information.in.mode = 2;
CHECK_CALL_FNUM(MODE_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(MODE_INFORMATION, mode_information, mode, 2);
CHECK_CALL_PATH(MODE_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(MODE_INFORMATION, mode_information, mode, 0);
sfinfo.mode_information.in.mode = 1;
CHECK_CALL_FNUM(MODE_INFORMATION, NT_STATUS_INVALID_PARAMETER);
CHECK_CALL_PATH(MODE_INFORMATION, NT_STATUS_INVALID_PARAMETER);
sfinfo.mode_information.in.mode = 0;
CHECK_CALL_FNUM(MODE_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(MODE_INFORMATION, mode_information, mode, 0);
CHECK_CALL_PATH(MODE_INFORMATION, NT_STATUS_OK);
CHECK_VALUE(MODE_INFORMATION, mode_information, mode, 0);
#if 0
printf("test unix_basic level\n");
CHECK_CALL_FNUM(UNIX_BASIC, NT_STATUS_OK);
CHECK_CALL_PATH(UNIX_BASIC, NT_STATUS_OK);
printf("test unix_link level\n");
CHECK_CALL_FNUM(UNIX_LINK, NT_STATUS_OK);
CHECK_CALL_PATH(UNIX_LINK, NT_STATUS_OK);
#endif
done:
smb_raw_exit(cli->session);
smbcli_close(cli->tree, fnum);
if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fnum_fname))) {
printf("Failed to delete %s - %s\n", fnum_fname, smbcli_errstr(cli->tree));
}
if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, path_fname))) {
printf("Failed to delete %s - %s\n", path_fname, smbcli_errstr(cli->tree));
}
torture_close_connection(cli);
talloc_free(mem_ctx);
return ret;
}
/*
* basic testing of all RAW_SFILEINFO_RENAME call
*/
BOOL torture_raw_sfileinfo_rename(struct torture_context *torture)
{
struct smbcli_state *cli;
BOOL ret = True;
TALLOC_CTX *mem_ctx;
int fnum_saved, d_fnum, fnum2, fnum = -1;
char *fnum_fname;
char *fnum_fname_new;
char *path_fname;
char *path_fname_new;
union smb_fileinfo finfo1, finfo2;
union smb_setfileinfo sfinfo;
NTSTATUS status, status2;
const char *call_name;
BOOL check_fnum;
int n = time(NULL) % 100;
asprintf(&path_fname, BASEDIR "\\fname_test_%d.txt", n);
asprintf(&path_fname_new, BASEDIR "\\fname_test_new_%d.txt", n);
asprintf(&fnum_fname, BASEDIR "\\fnum_test_%d.txt", n);
asprintf(&fnum_fname_new, BASEDIR "\\fnum_test_new_%d.txt", n);
if (!torture_open_connection(&cli, 0)) {
return False;
}
mem_ctx = talloc_init("torture_sfileinfo");
if (!torture_setup_dir(cli, BASEDIR)) {
return False;
}
RECREATE_BOTH;
ZERO_STRUCT(sfinfo);
smbcli_close(cli->tree, create_complex_file(cli, mem_ctx, fnum_fname_new));
smbcli_close(cli->tree, create_complex_file(cli, mem_ctx, path_fname_new));
sfinfo.rename_information.in.overwrite = 0;
sfinfo.rename_information.in.root_fid = 0;
sfinfo.rename_information.in.new_name = fnum_fname_new+strlen(BASEDIR)+1;
CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OBJECT_NAME_COLLISION);
sfinfo.rename_information.in.new_name = path_fname_new+strlen(BASEDIR)+1;
CHECK_CALL_PATH(RENAME_INFORMATION, NT_STATUS_OBJECT_NAME_COLLISION);
sfinfo.rename_information.in.new_name = fnum_fname_new;
sfinfo.rename_information.in.overwrite = 1;
CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_NOT_SUPPORTED);
sfinfo.rename_information.in.new_name = fnum_fname_new+strlen(BASEDIR)+1;
sfinfo.rename_information.in.overwrite = 1;
CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK);
CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname_new);
printf("Trying rename with dest file open\n");
fnum2 = create_complex_file(cli, mem_ctx, fnum_fname);
sfinfo.rename_information.in.new_name = fnum_fname+strlen(BASEDIR)+1;
sfinfo.rename_information.in.overwrite = 1;
CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_ACCESS_DENIED);
CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname_new);
fnum_saved = fnum;
fnum = fnum2;
sfinfo.disposition_info.in.delete_on_close = 1;
CHECK_CALL_FNUM(DISPOSITION_INFO, NT_STATUS_OK);
fnum = fnum_saved;
printf("Trying rename with dest file open and delete_on_close\n");
sfinfo.rename_information.in.new_name = fnum_fname+strlen(BASEDIR)+1;
sfinfo.rename_information.in.overwrite = 1;
CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_ACCESS_DENIED);
smbcli_close(cli->tree, fnum2);
CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK);
CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname);
printf("Trying rename with source file open twice\n");
sfinfo.rename_information.in.new_name = fnum_fname+strlen(BASEDIR)+1;
sfinfo.rename_information.in.overwrite = 1;
CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK);
CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname);
fnum2 = create_complex_file(cli, mem_ctx, fnum_fname);
sfinfo.rename_information.in.new_name = fnum_fname_new+strlen(BASEDIR)+1;
sfinfo.rename_information.in.overwrite = 0;
CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK);
CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname_new);
smbcli_close(cli->tree, fnum2);
sfinfo.rename_information.in.new_name = fnum_fname+strlen(BASEDIR)+1;
sfinfo.rename_information.in.overwrite = 0;
CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK);
CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname);
sfinfo.rename_information.in.new_name = path_fname_new+strlen(BASEDIR)+1;
sfinfo.rename_information.in.overwrite = 1;
CHECK_CALL_PATH(RENAME_INFORMATION, NT_STATUS_OK);
CHECK_STR(NAME_INFO, name_info, fname.s, path_fname_new);
sfinfo.rename_information.in.new_name = fnum_fname+strlen(BASEDIR)+1;
CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK);
CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname);
sfinfo.rename_information.in.new_name = path_fname+strlen(BASEDIR)+1;
CHECK_CALL_PATH(RENAME_INFORMATION, NT_STATUS_OK);
CHECK_STR(NAME_INFO, name_info, fname.s, path_fname);
printf("Trying rename with a root fid\n");
status = create_directory_handle(cli->tree, BASEDIR, &d_fnum);
CHECK_STATUS(status, NT_STATUS_OK);
sfinfo.rename_information.in.new_name = fnum_fname_new+strlen(BASEDIR)+1;
sfinfo.rename_information.in.root_fid = d_fnum;
CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_INVALID_PARAMETER);
CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname);
done:
smb_raw_exit(cli->session);
smbcli_close(cli->tree, fnum);
if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fnum_fname))) {
printf("Failed to delete %s - %s\n", fnum_fname, smbcli_errstr(cli->tree));
}
if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, path_fname))) {
printf("Failed to delete %s - %s\n", path_fname, smbcli_errstr(cli->tree));
}
torture_close_connection(cli);
talloc_free(mem_ctx);
return ret;
}
/*
look for the w2k3 setpathinfo STANDARD bug
*/
BOOL torture_raw_sfileinfo_bug(struct torture_context *torture)
{
struct smbcli_state *cli;
TALLOC_CTX *mem_ctx;
const char *fname = "\\bug3.txt";
union smb_setfileinfo sfinfo;
NTSTATUS status;
int fnum;
if (!torture_setting_bool(torture, "dangerous", False)) {
printf("torture_raw_sfileinfo_bug disabled - enable dangerous tests to use\n");
return True;
}
if (!torture_open_connection(&cli, 0)) {
return False;
}
mem_ctx = talloc_init("torture_sfileinfo");
fnum = create_complex_file(cli, mem_ctx, fname);
smbcli_close(cli->tree, fnum);
sfinfo.generic.level = RAW_SFILEINFO_STANDARD;
sfinfo.generic.in.file.path = fname;
sfinfo.standard.in.create_time = 0;
sfinfo.standard.in.access_time = 0;
sfinfo.standard.in.write_time = 0;
status = smb_raw_setpathinfo(cli->tree, &sfinfo);
printf("%s - %s\n", fname, nt_errstr(status));
printf("now try and delete %s\n", fname);
return True;
}
|