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