Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into v4-0-wsgi
[kai/samba.git] / source / torture / raw / open.c
1 /* 
2    Unix SMB/CIFS implementation.
3    RAW_OPEN_* 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 "torture/torture.h"
22 #include "libcli/raw/libcliraw.h"
23 #include "libcli/raw/raw_proto.h"
24 #include "system/time.h"
25 #include "system/filesys.h"
26 #include "librpc/gen_ndr/security.h"
27 #include "lib/events/events.h"
28 #include "libcli/libcli.h"
29 #include "torture/util.h"
30 #include "auth/credentials/credentials.h"
31 #include "lib/cmdline/popt_common.h"
32 #include "param/param.h"
33
34 /* enum for whether reads/writes are possible on a file */
35 enum rdwr_mode {RDWR_NONE, RDWR_RDONLY, RDWR_WRONLY, RDWR_RDWR};
36
37 #define BASEDIR "\\rawopen"
38
39 /*
40   check if a open file can be read/written
41 */
42 static enum rdwr_mode check_rdwr(struct smbcli_tree *tree, int fnum)
43 {
44         uint8_t c = 1;
45         bool can_read  = (smbcli_read(tree, fnum, &c, 0, 1) == 1);
46         bool can_write = (smbcli_write(tree, fnum, 0, &c, 0, 1) == 1);
47         if ( can_read &&  can_write) return RDWR_RDWR;
48         if ( can_read && !can_write) return RDWR_RDONLY;
49         if (!can_read &&  can_write) return RDWR_WRONLY;
50         return RDWR_NONE;
51 }
52
53 /*
54   describe a RDWR mode as a string
55 */
56 static const char *rdwr_string(enum rdwr_mode m)
57 {
58         switch (m) {
59         case RDWR_NONE: return "NONE";
60         case RDWR_RDONLY: return "RDONLY";
61         case RDWR_WRONLY: return "WRONLY";
62         case RDWR_RDWR: return "RDWR";
63         }
64         return "-";
65 }
66
67 #define CHECK_STATUS(status, correct) do { \
68         if (!NT_STATUS_EQUAL(status, correct)) { \
69                 printf("(%s) Incorrect status %s - should be %s\n", \
70                        __location__, nt_errstr(status), nt_errstr(correct)); \
71                 ret = false; \
72                 goto done; \
73         }} while (0)
74
75 #define CREATE_FILE do { \
76         fnum = create_complex_file(cli, tctx, fname); \
77         if (fnum == -1) { \
78                 printf("(%s) Failed to create %s - %s\n", __location__, fname, smbcli_errstr(cli->tree)); \
79                 ret = false; \
80                 goto done; \
81         }} while (0)
82
83 #define CHECK_RDWR(fnum, correct) do { \
84         enum rdwr_mode m = check_rdwr(cli->tree, fnum); \
85         if (m != correct) { \
86                 printf("(%s) Incorrect readwrite mode %s - expected %s\n", \
87                        __location__, rdwr_string(m), rdwr_string(correct)); \
88                 ret = false; \
89         }} while (0)
90
91 #define CHECK_TIME(t, field) do { \
92         time_t t1, t2; \
93         finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
94         finfo.all_info.in.file.path = fname; \
95         status = smb_raw_pathinfo(cli->tree, tctx, &finfo); \
96         CHECK_STATUS(status, NT_STATUS_OK); \
97         t1 = t & ~1; \
98         t2 = nt_time_to_unix(finfo.all_info.out.field) & ~1; \
99         if (abs(t1-t2) > 2) { \
100                 printf("(%s) wrong time for field %s  %s - %s\n", \
101                        __location__, #field, \
102                        timestring(tctx, t1), \
103                        timestring(tctx, t2)); \
104                 dump_all_info(tctx, &finfo); \
105                 ret = false; \
106         }} while (0)
107
108 #define CHECK_NTTIME(t, field) do { \
109         NTTIME t2; \
110         finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
111         finfo.all_info.in.file.path = fname; \
112         status = smb_raw_pathinfo(cli->tree, tctx, &finfo); \
113         CHECK_STATUS(status, NT_STATUS_OK); \
114         t2 = finfo.all_info.out.field; \
115         if (t != t2) { \
116                 printf("(%s) wrong time for field %s  %s - %s\n", \
117                        __location__, #field, \
118                        nt_time_string(tctx, t), \
119                        nt_time_string(tctx, t2)); \
120                 dump_all_info(tctx, &finfo); \
121                 ret = false; \
122         }} while (0)
123
124 #define CHECK_ALL_INFO(v, field) do { \
125         finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
126         finfo.all_info.in.file.path = fname; \
127         status = smb_raw_pathinfo(cli->tree, tctx, &finfo); \
128         CHECK_STATUS(status, NT_STATUS_OK); \
129         if ((v) != (finfo.all_info.out.field)) { \
130                 printf("(%s) wrong value for field %s  0x%x - 0x%x\n", \
131                        __location__, #field, (int)v, (int)(finfo.all_info.out.field)); \
132                 dump_all_info(tctx, &finfo); \
133                 ret = false; \
134         }} while (0)
135
136 #define CHECK_VAL(v, correct) do { \
137         if ((v) != (correct)) { \
138                 printf("(%s) wrong value for %s  0x%x - should be 0x%x\n", \
139                        __location__, #v, (int)(v), (int)correct); \
140                 ret = false; \
141         }} while (0)
142
143 #define SET_ATTRIB(sattrib) do { \
144         union smb_setfileinfo sfinfo; \
145         ZERO_STRUCT(sfinfo.basic_info.in); \
146         sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFORMATION; \
147         sfinfo.basic_info.in.file.path = fname; \
148         sfinfo.basic_info.in.attrib = sattrib; \
149         status = smb_raw_setpathinfo(cli->tree, &sfinfo); \
150         if (!NT_STATUS_IS_OK(status)) { \
151                 printf("(%s) Failed to set attrib 0x%x on %s\n", \
152                        __location__, sattrib, fname); \
153         }} while (0)
154
155 /*
156   test RAW_OPEN_OPEN
157 */
158 static bool test_open(struct smbcli_state *cli, struct torture_context *tctx)
159 {
160         union smb_open io;
161         union smb_fileinfo finfo;
162         const char *fname = BASEDIR "\\torture_open.txt";
163         NTSTATUS status;
164         int fnum = -1, fnum2;
165         bool ret = true;
166
167         printf("Checking RAW_OPEN_OPEN\n");
168
169         io.openold.level = RAW_OPEN_OPEN;
170         io.openold.in.fname = fname;
171         io.openold.in.open_mode = OPEN_FLAGS_FCB;
172         io.openold.in.search_attrs = 0;
173         status = smb_raw_open(cli->tree, tctx, &io);
174         CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
175         fnum = io.openold.out.file.fnum;
176
177         smbcli_unlink(cli->tree, fname);
178         CREATE_FILE;
179         smbcli_close(cli->tree, fnum);
180
181         status = smb_raw_open(cli->tree, tctx, &io);
182         CHECK_STATUS(status, NT_STATUS_OK);
183         fnum = io.openold.out.file.fnum;
184         CHECK_RDWR(fnum, RDWR_RDWR);
185
186         status = smb_raw_open(cli->tree, tctx, &io);
187         CHECK_STATUS(status, NT_STATUS_OK);
188         fnum2 = io.openold.out.file.fnum;
189         CHECK_RDWR(fnum2, RDWR_RDWR);
190         smbcli_close(cli->tree, fnum2);
191         smbcli_close(cli->tree, fnum);
192
193         /* check the read/write modes */
194         io.openold.level = RAW_OPEN_OPEN;
195         io.openold.in.fname = fname;
196         io.openold.in.search_attrs = 0;
197
198         io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ;
199         status = smb_raw_open(cli->tree, tctx, &io);
200         CHECK_STATUS(status, NT_STATUS_OK);
201         fnum = io.openold.out.file.fnum;
202         CHECK_RDWR(fnum, RDWR_RDONLY);
203         smbcli_close(cli->tree, fnum);
204
205         io.openold.in.open_mode = OPEN_FLAGS_OPEN_WRITE;
206         status = smb_raw_open(cli->tree, tctx, &io);
207         CHECK_STATUS(status, NT_STATUS_OK);
208         fnum = io.openold.out.file.fnum;
209         CHECK_RDWR(fnum, RDWR_WRONLY);
210         smbcli_close(cli->tree, fnum);
211
212         io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR;
213         status = smb_raw_open(cli->tree, tctx, &io);
214         CHECK_STATUS(status, NT_STATUS_OK);
215         fnum = io.openold.out.file.fnum;
216         CHECK_RDWR(fnum, RDWR_RDWR);
217         smbcli_close(cli->tree, fnum);
218
219         /* check the share modes roughly - not a complete matrix */
220         io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_WRITE;
221         status = smb_raw_open(cli->tree, tctx, &io);
222         CHECK_STATUS(status, NT_STATUS_OK);
223         fnum = io.openold.out.file.fnum;
224         CHECK_RDWR(fnum, RDWR_RDWR);
225         
226         if (io.openold.in.open_mode != io.openold.out.rmode) {
227                 printf("(%s) rmode should equal open_mode - 0x%x 0x%x\n",
228                        __location__, io.openold.out.rmode, io.openold.in.open_mode);
229         }
230
231         io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_NONE;
232         status = smb_raw_open(cli->tree, tctx, &io);
233         CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
234
235         io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ | OPEN_FLAGS_DENY_NONE;
236         status = smb_raw_open(cli->tree, tctx, &io);
237         CHECK_STATUS(status, NT_STATUS_OK);
238         fnum2 = io.openold.out.file.fnum;
239         CHECK_RDWR(fnum2, RDWR_RDONLY);
240         smbcli_close(cli->tree, fnum);
241         smbcli_close(cli->tree, fnum2);
242
243
244         /* check the returned write time */
245         io.openold.level = RAW_OPEN_OPEN;
246         io.openold.in.fname = fname;
247         io.openold.in.search_attrs = 0;
248         io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ;
249         status = smb_raw_open(cli->tree, tctx, &io);
250         CHECK_STATUS(status, NT_STATUS_OK);
251         fnum = io.openold.out.file.fnum;
252
253         /* check other reply fields */
254         CHECK_TIME(io.openold.out.write_time, write_time);
255         CHECK_ALL_INFO(io.openold.out.size, size);
256         CHECK_ALL_INFO(io.openold.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
257
258 done:
259         smbcli_close(cli->tree, fnum);
260         smbcli_unlink(cli->tree, fname);
261
262         return ret;
263 }
264
265
266 /*
267   test RAW_OPEN_OPENX
268 */
269 static bool test_openx(struct smbcli_state *cli, struct torture_context *tctx)
270 {
271         union smb_open io;
272         union smb_fileinfo finfo;
273         const char *fname = BASEDIR "\\torture_openx.txt";
274         const char *fname_exe = BASEDIR "\\torture_openx.exe";
275         NTSTATUS status;
276         int fnum = -1, fnum2;
277         bool ret = true;
278         int i;
279         struct timeval tv;
280         struct {
281                 uint16_t open_func;
282                 bool with_file;
283                 NTSTATUS correct_status;
284         } open_funcs[] = {
285                 { OPENX_OPEN_FUNC_OPEN,                           true,  NT_STATUS_OK },
286                 { OPENX_OPEN_FUNC_OPEN,                           false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
287                 { OPENX_OPEN_FUNC_OPEN  | OPENX_OPEN_FUNC_CREATE, true,  NT_STATUS_OK },
288                 { OPENX_OPEN_FUNC_OPEN  | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
289                 { OPENX_OPEN_FUNC_FAIL,                           true,  NT_STATUS_DOS(ERRDOS, ERRbadaccess) },
290                 { OPENX_OPEN_FUNC_FAIL,                           false, NT_STATUS_DOS(ERRDOS, ERRbadaccess) },
291                 { OPENX_OPEN_FUNC_FAIL  | OPENX_OPEN_FUNC_CREATE, true,  NT_STATUS_OBJECT_NAME_COLLISION },
292                 { OPENX_OPEN_FUNC_FAIL  | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
293                 { OPENX_OPEN_FUNC_TRUNC,                          true,  NT_STATUS_OK },
294                 { OPENX_OPEN_FUNC_TRUNC,                          false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
295                 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, true,  NT_STATUS_OK },
296                 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
297         };
298
299         printf("Checking RAW_OPEN_OPENX\n");
300         smbcli_unlink(cli->tree, fname);
301
302         io.openx.level = RAW_OPEN_OPENX;
303         io.openx.in.fname = fname;
304         io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
305         io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
306         io.openx.in.search_attrs = 0;
307         io.openx.in.file_attrs = 0;
308         io.openx.in.write_time = 0;
309         io.openx.in.size = 1024*1024;
310         io.openx.in.timeout = 0;
311
312         /* check all combinations of open_func */
313         for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
314                 if (open_funcs[i].with_file) {
315                         fnum = create_complex_file(cli, tctx, fname);
316                         if (fnum == -1) {
317                                 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
318                                 ret = false;
319                                 goto done;
320                         }
321                         smbcli_close(cli->tree, fnum);
322                 }
323                 io.openx.in.open_func = open_funcs[i].open_func;
324                 status = smb_raw_open(cli->tree, tctx, &io);
325                 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
326                         printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n", 
327                                __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
328                                i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_func);
329                         ret = false;
330                 }
331                 if (NT_STATUS_IS_OK(status)) {
332                         smbcli_close(cli->tree, io.openx.out.file.fnum);
333                 }
334                 if (open_funcs[i].with_file) {
335                         smbcli_unlink(cli->tree, fname);
336                 }
337         }
338
339         smbcli_unlink(cli->tree, fname);
340
341         /* check the basic return fields */
342         io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
343         status = smb_raw_open(cli->tree, tctx, &io);
344         CHECK_STATUS(status, NT_STATUS_OK);
345         fnum = io.openx.out.file.fnum;
346
347         CHECK_ALL_INFO(io.openx.out.size, size);
348         CHECK_TIME(io.openx.out.write_time, write_time);
349         CHECK_ALL_INFO(io.openx.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
350         CHECK_VAL(io.openx.out.access, OPENX_MODE_ACCESS_RDWR);
351         CHECK_VAL(io.openx.out.ftype, 0);
352         CHECK_VAL(io.openx.out.devstate, 0);
353         CHECK_VAL(io.openx.out.action, OPENX_ACTION_CREATED);
354         CHECK_VAL(io.openx.out.size, 1024*1024);
355         CHECK_ALL_INFO(io.openx.in.size, size);
356         smbcli_close(cli->tree, fnum);
357         smbcli_unlink(cli->tree, fname);
358
359         /* check the fields when the file already existed */
360         fnum2 = create_complex_file(cli, tctx, fname);
361         if (fnum2 == -1) {
362                 ret = false;
363                 goto done;
364         }
365         smbcli_close(cli->tree, fnum2);
366
367         io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
368         status = smb_raw_open(cli->tree, tctx, &io);
369         CHECK_STATUS(status, NT_STATUS_OK);
370         fnum = io.openx.out.file.fnum;
371
372         CHECK_ALL_INFO(io.openx.out.size, size);
373         CHECK_TIME(io.openx.out.write_time, write_time);
374         CHECK_VAL(io.openx.out.action, OPENX_ACTION_EXISTED);
375         CHECK_VAL(io.openx.out.unknown, 0);
376         CHECK_ALL_INFO(io.openx.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
377         smbcli_close(cli->tree, fnum);
378
379         /* now check the search attrib for hidden files - win2003 ignores this? */
380         SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN);
381         CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib);
382
383         io.openx.in.search_attrs = FILE_ATTRIBUTE_HIDDEN;
384         status = smb_raw_open(cli->tree, tctx, &io);
385         CHECK_STATUS(status, NT_STATUS_OK);
386         smbcli_close(cli->tree, io.openx.out.file.fnum);
387
388         io.openx.in.search_attrs = 0;
389         status = smb_raw_open(cli->tree, tctx, &io);
390         CHECK_STATUS(status, NT_STATUS_OK);
391         smbcli_close(cli->tree, io.openx.out.file.fnum);
392
393         SET_ATTRIB(FILE_ATTRIBUTE_NORMAL);
394         smbcli_unlink(cli->tree, fname);
395
396         /* and check attrib on create */
397         io.openx.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE;
398         io.openx.in.search_attrs = 0;
399         io.openx.in.file_attrs = FILE_ATTRIBUTE_SYSTEM;
400         status = smb_raw_open(cli->tree, tctx, &io);
401         CHECK_STATUS(status, NT_STATUS_OK);
402         if (torture_setting_bool(tctx, "samba3", false)) {
403                 CHECK_ALL_INFO(FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE, 
404                                attrib & ~(FILE_ATTRIBUTE_NONINDEXED|
405                                           FILE_ATTRIBUTE_SPARSE));
406         }
407         else {
408                 CHECK_ALL_INFO(FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE, 
409                                attrib & ~(FILE_ATTRIBUTE_NONINDEXED));
410         }
411         smbcli_close(cli->tree, io.openx.out.file.fnum);
412         smbcli_unlink(cli->tree, fname);
413
414         /* check timeout on create - win2003 ignores the timeout! */
415         io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
416         io.openx.in.file_attrs = 0;
417         io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL;
418         status = smb_raw_open(cli->tree, tctx, &io);
419         CHECK_STATUS(status, NT_STATUS_OK);
420         fnum = io.openx.out.file.fnum;
421
422         io.openx.in.timeout = 20000;
423         tv = timeval_current();
424         io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_NONE;
425         status = smb_raw_open(cli->tree, tctx, &io);
426         CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
427         if (timeval_elapsed(&tv) > 3.0) {
428                 printf("(%s) Incorrect timing in openx with timeout - waited %.2f seconds\n",
429                        __location__, timeval_elapsed(&tv));
430                 ret = false;
431         }
432         smbcli_close(cli->tree, fnum);
433         smbcli_unlink(cli->tree, fname);
434
435         /* now this is a really weird one - open for execute implies create?! */
436         io.openx.in.fname = fname;
437         io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
438         io.openx.in.open_mode = OPENX_MODE_ACCESS_EXEC | OPENX_MODE_DENY_NONE;
439         io.openx.in.search_attrs = 0;
440         io.openx.in.open_func = OPENX_OPEN_FUNC_FAIL;
441         io.openx.in.file_attrs = 0;
442         io.openx.in.write_time = 0;
443         io.openx.in.size = 0;
444         io.openx.in.timeout = 0;
445         status = smb_raw_open(cli->tree, tctx, &io);
446         CHECK_STATUS(status, NT_STATUS_OK);
447         smbcli_close(cli->tree, io.openx.out.file.fnum);
448
449         /* check the extended return flag */
450         io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO | OPENX_FLAGS_EXTENDED_RETURN;
451         io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
452         status = smb_raw_open(cli->tree, tctx, &io);
453         CHECK_STATUS(status, NT_STATUS_OK);
454         CHECK_VAL(io.openx.out.access_mask, SEC_STD_ALL);
455         smbcli_close(cli->tree, io.openx.out.file.fnum);
456
457         io.openx.in.fname = "\\A.+,;=[].B";
458         status = smb_raw_open(cli->tree, tctx, &io);
459         CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
460
461         /* Check the mapping for open exec. */
462
463         /* First create an .exe file. */
464         smbcli_unlink(cli->tree, fname_exe);
465         fnum = create_complex_file(cli, tctx, fname_exe);
466         smbcli_close(cli->tree, fnum);
467
468         io.openx.level = RAW_OPEN_OPENX;
469         io.openx.in.fname = fname_exe;
470         io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
471         io.openx.in.open_mode = OPENX_MODE_ACCESS_EXEC | OPENX_MODE_DENY_NONE;
472         io.openx.in.search_attrs = 0;
473         io.openx.in.file_attrs = 0;
474         io.openx.in.write_time = 0;
475         io.openx.in.size = 0;
476         io.openx.in.timeout = 0;
477         status = smb_raw_open(cli->tree, tctx, &io);
478         CHECK_STATUS(status, NT_STATUS_OK);
479
480         /* Can we read and write ? */
481         CHECK_RDWR(io.openx.out.file.fnum, RDWR_RDONLY);
482         smbcli_close(cli->tree, io.openx.out.file.fnum);
483         smbcli_unlink(cli->tree, fname);
484
485 done:
486         smbcli_close(cli->tree, fnum);
487         smbcli_unlink(cli->tree, fname_exe);
488         smbcli_unlink(cli->tree, fname);
489
490         return ret;
491 }
492
493
494 /*
495   test RAW_OPEN_T2OPEN
496
497   many thanks to kukks for a sniff showing how this works with os2->w2k
498 */
499 static bool test_t2open(struct smbcli_state *cli, struct torture_context *tctx)
500 {
501         union smb_open io;
502         union smb_fileinfo finfo;
503         const char *fname1 = BASEDIR "\\torture_t2open_yes.txt";
504         const char *fname2 = BASEDIR "\\torture_t2open_no.txt";
505         const char *fname = BASEDIR "\\torture_t2open_3.txt";
506         NTSTATUS status;
507         int fnum;
508         bool ret = true;
509         int i;
510         struct {
511                 uint16_t open_func;
512                 bool with_file;
513                 NTSTATUS correct_status;
514         } open_funcs[] = {
515                 { OPENX_OPEN_FUNC_OPEN,                           true,  NT_STATUS_OK },
516                 { OPENX_OPEN_FUNC_OPEN,                           false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
517                 { OPENX_OPEN_FUNC_OPEN  | OPENX_OPEN_FUNC_CREATE, true,  NT_STATUS_OK },
518                 { OPENX_OPEN_FUNC_OPEN  | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
519                 { OPENX_OPEN_FUNC_FAIL,                           true,  NT_STATUS_OBJECT_NAME_COLLISION },
520                 { OPENX_OPEN_FUNC_FAIL,                           false, NT_STATUS_OBJECT_NAME_COLLISION },
521                 { OPENX_OPEN_FUNC_FAIL  | OPENX_OPEN_FUNC_CREATE, true,  NT_STATUS_OBJECT_NAME_COLLISION },
522                 { OPENX_OPEN_FUNC_FAIL  | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OBJECT_NAME_COLLISION },
523                 { OPENX_OPEN_FUNC_TRUNC,                          true,  NT_STATUS_OK },
524                 { OPENX_OPEN_FUNC_TRUNC,                          false, NT_STATUS_OK },
525                 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, true,  NT_STATUS_OK },
526                 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
527         };
528
529         fnum = create_complex_file(cli, tctx, fname1);
530         if (fnum == -1) {
531                 d_printf("Failed to create file %s - %s\n", fname1, smbcli_errstr(cli->tree));
532                 ret = false;
533                 goto done;
534         }
535         smbcli_close(cli->tree, fnum);
536
537         printf("Checking RAW_OPEN_T2OPEN\n");
538
539         io.t2open.level = RAW_OPEN_T2OPEN;
540         io.t2open.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
541         io.t2open.in.open_mode = OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR;
542         io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
543         io.t2open.in.search_attrs = 0;
544         io.t2open.in.file_attrs = 0;
545         io.t2open.in.write_time = 0;
546         io.t2open.in.size = 0;
547         io.t2open.in.timeout = 0;
548
549         io.t2open.in.num_eas = 3;
550         io.t2open.in.eas = talloc_array(tctx, struct ea_struct, io.t2open.in.num_eas);
551         io.t2open.in.eas[0].flags = 0;
552         io.t2open.in.eas[0].name.s = ".CLASSINFO";
553         io.t2open.in.eas[0].value = data_blob_talloc(tctx, "first value", 11);
554         io.t2open.in.eas[1].flags = 0;
555         io.t2open.in.eas[1].name.s = "EA TWO";
556         io.t2open.in.eas[1].value = data_blob_talloc(tctx, "foo", 3);
557         io.t2open.in.eas[2].flags = 0;
558         io.t2open.in.eas[2].name.s = "X THIRD";
559         io.t2open.in.eas[2].value = data_blob_talloc(tctx, "xy", 2);
560
561         /* check all combinations of open_func */
562         for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
563         again:
564                 if (open_funcs[i].with_file) {
565                         io.t2open.in.fname = fname1;
566                 } else {
567                         io.t2open.in.fname = fname2;
568                 }
569                 io.t2open.in.open_func = open_funcs[i].open_func;
570                 status = smb_raw_open(cli->tree, tctx, &io);
571                 if ((io.t2open.in.num_eas != 0)
572                     && NT_STATUS_EQUAL(status, NT_STATUS_EAS_NOT_SUPPORTED)
573                     && torture_setting_bool(tctx, "samba3", false)) {
574                         printf("(%s) EAs not supported, not treating as fatal "
575                                "in Samba3 test\n", __location__);
576                         io.t2open.in.num_eas = 0;
577                         goto again;
578                 }
579
580                 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
581                         printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n", 
582                                __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
583                                i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_func);
584                         ret = false;
585                 }
586                 if (NT_STATUS_IS_OK(status)) {
587                         smbcli_close(cli->tree, io.t2open.out.file.fnum);
588                 }
589         }
590
591         smbcli_unlink(cli->tree, fname1);
592         smbcli_unlink(cli->tree, fname2);
593
594         /* check the basic return fields */
595         io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
596         io.t2open.in.write_time = 0;
597         io.t2open.in.fname = fname;
598         status = smb_raw_open(cli->tree, tctx, &io);
599         CHECK_STATUS(status, NT_STATUS_OK);
600         fnum = io.t2open.out.file.fnum;
601
602         CHECK_ALL_INFO(io.t2open.out.size, size);
603 #if 0
604         /* windows appears to leak uninitialised memory here */
605         CHECK_VAL(io.t2open.out.write_time, 0);
606 #endif
607         CHECK_ALL_INFO(io.t2open.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
608         CHECK_VAL(io.t2open.out.access, OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR);
609         CHECK_VAL(io.t2open.out.ftype, 0);
610         CHECK_VAL(io.t2open.out.devstate, 0);
611         CHECK_VAL(io.t2open.out.action, OPENX_ACTION_CREATED);
612         smbcli_close(cli->tree, fnum);
613
614         status = torture_check_ea(cli, fname, ".CLASSINFO", "first value");
615         CHECK_STATUS(status, io.t2open.in.num_eas
616                      ? NT_STATUS_OK : NT_STATUS_EAS_NOT_SUPPORTED);
617         status = torture_check_ea(cli, fname, "EA TWO", "foo");
618         CHECK_STATUS(status, io.t2open.in.num_eas
619                      ? NT_STATUS_OK : NT_STATUS_EAS_NOT_SUPPORTED);
620         status = torture_check_ea(cli, fname, "X THIRD", "xy");
621         CHECK_STATUS(status, io.t2open.in.num_eas
622                      ? NT_STATUS_OK : NT_STATUS_EAS_NOT_SUPPORTED);
623
624         /* now check the search attrib for hidden files - win2003 ignores this? */
625         SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN);
626         CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib);
627
628         status = smb_raw_open(cli->tree, tctx, &io);
629         CHECK_STATUS(status, NT_STATUS_OK);
630         smbcli_close(cli->tree, io.t2open.out.file.fnum);
631
632         status = smb_raw_open(cli->tree, tctx, &io);
633         CHECK_STATUS(status, NT_STATUS_OK);
634         smbcli_close(cli->tree, io.t2open.out.file.fnum);
635
636         SET_ATTRIB(FILE_ATTRIBUTE_NORMAL);
637         smbcli_unlink(cli->tree, fname);
638
639         /* and check attrib on create */
640         io.t2open.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE;
641         io.t2open.in.file_attrs = FILE_ATTRIBUTE_SYSTEM;
642         status = smb_raw_open(cli->tree, tctx, &io);
643         CHECK_STATUS(status, NT_STATUS_OK);
644
645         /* check timeout on create - win2003 ignores the timeout! */
646         io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
647         io.t2open.in.file_attrs = 0;
648         io.t2open.in.timeout = 20000;
649         io.t2open.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL;
650         status = smb_raw_open(cli->tree, tctx, &io);
651         CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
652
653 done:
654         smbcli_close(cli->tree, fnum);
655         smbcli_unlink(cli->tree, fname);
656
657         return ret;
658 }
659         
660
661 /*
662   test RAW_OPEN_NTCREATEX
663 */
664 static bool test_ntcreatex(struct smbcli_state *cli, struct torture_context *tctx)
665 {
666         union smb_open io;
667         union smb_fileinfo finfo;
668         const char *fname = BASEDIR "\\torture_ntcreatex.txt";
669         const char *dname = BASEDIR "\\torture_ntcreatex.dir";
670         NTSTATUS status;
671         int fnum = -1;
672         bool ret = true;
673         int i;
674         struct {
675                 uint32_t open_disp;
676                 bool with_file;
677                 NTSTATUS correct_status;
678         } open_funcs[] = {
679                 { NTCREATEX_DISP_SUPERSEDE,     true,  NT_STATUS_OK },
680                 { NTCREATEX_DISP_SUPERSEDE,     false, NT_STATUS_OK },
681                 { NTCREATEX_DISP_OPEN,          true,  NT_STATUS_OK },
682                 { NTCREATEX_DISP_OPEN,          false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
683                 { NTCREATEX_DISP_CREATE,        true,  NT_STATUS_OBJECT_NAME_COLLISION },
684                 { NTCREATEX_DISP_CREATE,        false, NT_STATUS_OK },
685                 { NTCREATEX_DISP_OPEN_IF,       true,  NT_STATUS_OK },
686                 { NTCREATEX_DISP_OPEN_IF,       false, NT_STATUS_OK },
687                 { NTCREATEX_DISP_OVERWRITE,     true,  NT_STATUS_OK },
688                 { NTCREATEX_DISP_OVERWRITE,     false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
689                 { NTCREATEX_DISP_OVERWRITE_IF,  true,  NT_STATUS_OK },
690                 { NTCREATEX_DISP_OVERWRITE_IF,  false, NT_STATUS_OK },
691                 { 6,                            true,  NT_STATUS_INVALID_PARAMETER },
692                 { 6,                            false, NT_STATUS_INVALID_PARAMETER },
693         };
694
695         printf("Checking RAW_OPEN_NTCREATEX\n");
696
697         /* reasonable default parameters */
698         io.generic.level = RAW_OPEN_NTCREATEX;
699         io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
700         io.ntcreatex.in.root_fid = 0;
701         io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
702         io.ntcreatex.in.alloc_size = 1024*1024;
703         io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
704         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
705         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
706         io.ntcreatex.in.create_options = 0;
707         io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
708         io.ntcreatex.in.security_flags = 0;
709         io.ntcreatex.in.fname = fname;
710
711         /* test the open disposition */
712         for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
713                 if (open_funcs[i].with_file) {
714                         fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE);
715                         if (fnum == -1) {
716                                 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
717                                 ret = false;
718                                 goto done;
719                         }
720                         smbcli_close(cli->tree, fnum);
721                 }
722                 io.ntcreatex.in.open_disposition = open_funcs[i].open_disp;
723                 status = smb_raw_open(cli->tree, tctx, &io);
724                 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
725                         printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_disp=%d)\n", 
726                                __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
727                                i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_disp);
728                         ret = false;
729                 }
730                 if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
731                         smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
732                         smbcli_unlink(cli->tree, fname);
733                 }
734         }
735
736         /* basic field testing */
737         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
738
739         status = smb_raw_open(cli->tree, tctx, &io);
740         CHECK_STATUS(status, NT_STATUS_OK);
741         fnum = io.ntcreatex.out.file.fnum;
742
743         CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
744         CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
745         CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
746         CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
747         CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
748         CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
749         CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
750         CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
751         CHECK_ALL_INFO(io.ntcreatex.out.size, size);
752         CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
753         CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
754
755         /* check fields when the file already existed */
756         smbcli_close(cli->tree, fnum);
757         smbcli_unlink(cli->tree, fname);
758         fnum = create_complex_file(cli, tctx, fname);
759         if (fnum == -1) {
760                 ret = false;
761                 goto done;
762         }
763         smbcli_close(cli->tree, fnum);
764
765         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
766         status = smb_raw_open(cli->tree, tctx, &io);
767         CHECK_STATUS(status, NT_STATUS_OK);
768         fnum = io.ntcreatex.out.file.fnum;
769
770         CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
771         CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
772         CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
773         CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
774         CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
775         CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
776         CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
777         CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
778         CHECK_ALL_INFO(io.ntcreatex.out.size, size);
779         CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
780         CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
781         smbcli_close(cli->tree, fnum);
782         smbcli_unlink(cli->tree, fname);
783
784
785         /* create a directory */
786         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
787         io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
788         io.ntcreatex.in.alloc_size = 0;
789         io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
790         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
791         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
792         io.ntcreatex.in.create_options = 0;
793         io.ntcreatex.in.fname = dname;
794         fname = dname;
795
796         smbcli_rmdir(cli->tree, fname);
797         smbcli_unlink(cli->tree, fname);
798
799         io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
800         io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
801         io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
802         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
803         status = smb_raw_open(cli->tree, tctx, &io);
804         CHECK_STATUS(status, NT_STATUS_OK);
805         fnum = io.ntcreatex.out.file.fnum;
806
807         CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
808         CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
809         CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
810         CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
811         CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
812         CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
813         CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
814         CHECK_VAL(io.ntcreatex.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED, 
815                   FILE_ATTRIBUTE_DIRECTORY);
816         CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
817         CHECK_ALL_INFO(io.ntcreatex.out.size, size);
818         CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
819         CHECK_VAL(io.ntcreatex.out.is_directory, 1);
820         CHECK_VAL(io.ntcreatex.out.size, 0);
821         CHECK_VAL(io.ntcreatex.out.alloc_size, 0);
822         CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
823         smbcli_unlink(cli->tree, fname);
824         
825
826 done:
827         smbcli_close(cli->tree, fnum);
828         smbcli_unlink(cli->tree, fname);
829
830         return ret;
831 }
832
833
834 /*
835   test RAW_OPEN_NTTRANS_CREATE
836 */
837 static bool test_nttrans_create(struct smbcli_state *cli, struct torture_context *tctx)
838 {
839         union smb_open io;
840         union smb_fileinfo finfo;
841         const char *fname = BASEDIR "\\torture_ntcreatex.txt";
842         const char *dname = BASEDIR "\\torture_ntcreatex.dir";
843         NTSTATUS status;
844         int fnum = -1;
845         bool ret = true;
846         int i;
847         struct {
848                 uint32_t open_disp;
849                 bool with_file;
850                 NTSTATUS correct_status;
851         } open_funcs[] = {
852                 { NTCREATEX_DISP_SUPERSEDE,     true,  NT_STATUS_OK },
853                 { NTCREATEX_DISP_SUPERSEDE,     false, NT_STATUS_OK },
854                 { NTCREATEX_DISP_OPEN,          true,  NT_STATUS_OK },
855                 { NTCREATEX_DISP_OPEN,          false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
856                 { NTCREATEX_DISP_CREATE,        true,  NT_STATUS_OBJECT_NAME_COLLISION },
857                 { NTCREATEX_DISP_CREATE,        false, NT_STATUS_OK },
858                 { NTCREATEX_DISP_OPEN_IF,       true,  NT_STATUS_OK },
859                 { NTCREATEX_DISP_OPEN_IF,       false, NT_STATUS_OK },
860                 { NTCREATEX_DISP_OVERWRITE,     true,  NT_STATUS_OK },
861                 { NTCREATEX_DISP_OVERWRITE,     false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
862                 { NTCREATEX_DISP_OVERWRITE_IF,  true,  NT_STATUS_OK },
863                 { NTCREATEX_DISP_OVERWRITE_IF,  false, NT_STATUS_OK },
864                 { 6,                            true,  NT_STATUS_INVALID_PARAMETER },
865                 { 6,                            false, NT_STATUS_INVALID_PARAMETER },
866         };
867
868         printf("Checking RAW_OPEN_NTTRANS_CREATE\n");
869
870         /* reasonable default parameters */
871         io.generic.level = RAW_OPEN_NTTRANS_CREATE;
872         io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
873         io.ntcreatex.in.root_fid = 0;
874         io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
875         io.ntcreatex.in.alloc_size = 1024*1024;
876         io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
877         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
878         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
879         io.ntcreatex.in.create_options = 0;
880         io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
881         io.ntcreatex.in.security_flags = 0;
882         io.ntcreatex.in.fname = fname;
883         io.ntcreatex.in.sec_desc = NULL;
884         io.ntcreatex.in.ea_list = NULL;
885
886         /* test the open disposition */
887         for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
888                 if (open_funcs[i].with_file) {
889                         fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE);
890                         if (fnum == -1) {
891                                 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
892                                 ret = false;
893                                 goto done;
894                         }
895                         smbcli_close(cli->tree, fnum);
896                 }
897                 io.ntcreatex.in.open_disposition = open_funcs[i].open_disp;
898                 status = smb_raw_open(cli->tree, tctx, &io);
899                 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
900                         printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_disp=%d)\n", 
901                                __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
902                                i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_disp);
903                         ret = false;
904                 }
905                 if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
906                         smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
907                         smbcli_unlink(cli->tree, fname);
908                 }
909         }
910
911         /* basic field testing */
912         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
913
914         status = smb_raw_open(cli->tree, tctx, &io);
915         CHECK_STATUS(status, NT_STATUS_OK);
916         fnum = io.ntcreatex.out.file.fnum;
917
918         CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
919         CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
920         CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
921         CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
922         CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
923         CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
924         CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
925         CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
926         CHECK_ALL_INFO(io.ntcreatex.out.size, size);
927         CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
928         CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
929
930         /* check fields when the file already existed */
931         smbcli_close(cli->tree, fnum);
932         smbcli_unlink(cli->tree, fname);
933         fnum = create_complex_file(cli, tctx, fname);
934         if (fnum == -1) {
935                 ret = false;
936                 goto done;
937         }
938         smbcli_close(cli->tree, fnum);
939
940         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
941         status = smb_raw_open(cli->tree, tctx, &io);
942         CHECK_STATUS(status, NT_STATUS_OK);
943         fnum = io.ntcreatex.out.file.fnum;
944
945         CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
946         CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
947         CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
948         CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
949         CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
950         CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
951         CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
952         CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
953         CHECK_ALL_INFO(io.ntcreatex.out.size, size);
954         CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
955         CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
956         smbcli_close(cli->tree, fnum);
957         smbcli_unlink(cli->tree, fname);
958
959
960         /* create a directory */
961         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
962         io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
963         io.ntcreatex.in.alloc_size = 0;
964         io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
965         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
966         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
967         io.ntcreatex.in.create_options = 0;
968         io.ntcreatex.in.fname = dname;
969         fname = dname;
970
971         smbcli_rmdir(cli->tree, fname);
972         smbcli_unlink(cli->tree, fname);
973
974         io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
975         io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
976         io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
977         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
978         status = smb_raw_open(cli->tree, tctx, &io);
979         CHECK_STATUS(status, NT_STATUS_OK);
980         fnum = io.ntcreatex.out.file.fnum;
981
982         CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
983         CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
984         CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
985         CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
986         CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
987         CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
988         CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
989         CHECK_VAL(io.ntcreatex.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED, 
990                   FILE_ATTRIBUTE_DIRECTORY);
991         CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
992         CHECK_ALL_INFO(io.ntcreatex.out.size, size);
993         CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
994         CHECK_VAL(io.ntcreatex.out.is_directory, 1);
995         CHECK_VAL(io.ntcreatex.out.size, 0);
996         CHECK_VAL(io.ntcreatex.out.alloc_size, 0);
997         CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
998         smbcli_unlink(cli->tree, fname);
999         
1000
1001 done:
1002         smbcli_close(cli->tree, fnum);
1003         smbcli_unlink(cli->tree, fname);
1004
1005         return ret;
1006 }
1007
1008 /*
1009   test RAW_OPEN_NTCREATEX with an already opened and byte range locked file
1010
1011   I've got an application that does a similar sequence of ntcreate&x,
1012   locking&x and another ntcreate&x with
1013   open_disposition==NTCREATEX_DISP_OVERWRITE_IF. Windows 2003 allows the
1014   second open.
1015 */
1016 static bool test_ntcreatex_brlocked(struct smbcli_state *cli, struct torture_context *tctx)
1017 {
1018         union smb_open io, io1;
1019         union smb_lock io2;
1020         struct smb_lock_entry lock[1];
1021         const char *fname = BASEDIR "\\torture_ntcreatex.txt";
1022         NTSTATUS status;
1023         bool ret = true;
1024
1025         printf("Testing ntcreatex with a byte range locked file\n");
1026
1027         io.generic.level = RAW_OPEN_NTCREATEX;
1028         io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
1029         io.ntcreatex.in.root_fid = 0;
1030         io.ntcreatex.in.access_mask = 0x2019f;
1031         io.ntcreatex.in.alloc_size = 0;
1032         io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1033         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1034                 NTCREATEX_SHARE_ACCESS_WRITE;
1035         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1036         io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
1037         io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
1038         io.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC |
1039                 NTCREATEX_SECURITY_ALL;
1040         io.ntcreatex.in.fname = fname;
1041
1042         status = smb_raw_open(cli->tree, tctx, &io);
1043         CHECK_STATUS(status, NT_STATUS_OK);
1044
1045         io2.lockx.level = RAW_LOCK_LOCKX;
1046         io2.lockx.in.file.fnum = io.ntcreatex.out.file.fnum;
1047         io2.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
1048         io2.lockx.in.timeout = 0;
1049         io2.lockx.in.ulock_cnt = 0;
1050         io2.lockx.in.lock_cnt = 1;
1051         lock[0].pid = cli->session->pid;
1052         lock[0].offset = 0;
1053         lock[0].count = 0x1;
1054         io2.lockx.in.locks = &lock[0];
1055         status = smb_raw_lock(cli->tree, &io2);
1056         CHECK_STATUS(status, NT_STATUS_OK);
1057
1058         io1.generic.level = RAW_OPEN_NTCREATEX;
1059         io1.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
1060         io1.ntcreatex.in.root_fid = 0;
1061         io1.ntcreatex.in.access_mask = 0x20196;
1062         io1.ntcreatex.in.alloc_size = 0;
1063         io1.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1064         io1.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1065                 NTCREATEX_SHARE_ACCESS_WRITE;
1066         io1.ntcreatex.in.open_disposition = NTCREATEX_DISP_OVERWRITE_IF;
1067         io1.ntcreatex.in.create_options = 0;
1068         io1.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
1069         io1.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC |
1070                 NTCREATEX_SECURITY_ALL;
1071         io1.ntcreatex.in.fname = fname;
1072
1073         status = smb_raw_open(cli->tree, tctx, &io1);
1074         CHECK_STATUS(status, NT_STATUS_OK);
1075
1076  done:
1077         smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
1078         smbcli_close(cli->tree, io1.ntcreatex.out.file.fnum);
1079         smbcli_unlink(cli->tree, fname);
1080         return ret;
1081 }
1082
1083 /*
1084   test RAW_OPEN_MKNEW
1085 */
1086 static bool test_mknew(struct smbcli_state *cli, struct torture_context *tctx)
1087 {
1088         union smb_open io;
1089         const char *fname = BASEDIR "\\torture_mknew.txt";
1090         NTSTATUS status;
1091         int fnum = -1;
1092         bool ret = true;
1093         time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1094         union smb_fileinfo finfo;
1095
1096         printf("Checking RAW_OPEN_MKNEW\n");
1097
1098         io.mknew.level = RAW_OPEN_MKNEW;
1099         io.mknew.in.attrib = 0;
1100         io.mknew.in.write_time = 0;
1101         io.mknew.in.fname = fname;
1102         status = smb_raw_open(cli->tree, tctx, &io);
1103         CHECK_STATUS(status, NT_STATUS_OK);
1104         fnum = io.mknew.out.file.fnum;
1105
1106         status = smb_raw_open(cli->tree, tctx, &io);
1107         CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
1108
1109         smbcli_close(cli->tree, fnum);
1110         smbcli_unlink(cli->tree, fname);
1111
1112         /* make sure write_time works */
1113         io.mknew.in.write_time = basetime;
1114         status = smb_raw_open(cli->tree, tctx, &io);
1115         CHECK_STATUS(status, NT_STATUS_OK);
1116         fnum = io.mknew.out.file.fnum;
1117         CHECK_TIME(basetime, write_time);
1118
1119         smbcli_close(cli->tree, fnum);
1120         smbcli_unlink(cli->tree, fname);
1121
1122         /* make sure file_attrs works */
1123         io.mknew.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1124         status = smb_raw_open(cli->tree, tctx, &io);
1125         CHECK_STATUS(status, NT_STATUS_OK);
1126         fnum = io.mknew.out.file.fnum;
1127         CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE, 
1128                        attrib & ~FILE_ATTRIBUTE_NONINDEXED);
1129         
1130 done:
1131         smbcli_close(cli->tree, fnum);
1132         smbcli_unlink(cli->tree, fname);
1133
1134         return ret;
1135 }
1136
1137
1138 /*
1139   test RAW_OPEN_CREATE
1140 */
1141 static bool test_create(struct smbcli_state *cli, struct torture_context *tctx)
1142 {
1143         union smb_open io;
1144         const char *fname = BASEDIR "\\torture_create.txt";
1145         NTSTATUS status;
1146         int fnum = -1;
1147         bool ret = true;
1148         time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1149         union smb_fileinfo finfo;
1150
1151         printf("Checking RAW_OPEN_CREATE\n");
1152
1153         io.create.level = RAW_OPEN_CREATE;
1154         io.create.in.attrib = 0;
1155         io.create.in.write_time = 0;
1156         io.create.in.fname = fname;
1157         status = smb_raw_open(cli->tree, tctx, &io);
1158         CHECK_STATUS(status, NT_STATUS_OK);
1159         fnum = io.create.out.file.fnum;
1160
1161         status = smb_raw_open(cli->tree, tctx, &io);
1162         CHECK_STATUS(status, NT_STATUS_OK);
1163
1164         smbcli_close(cli->tree, io.create.out.file.fnum);
1165         smbcli_close(cli->tree, fnum);
1166         smbcli_unlink(cli->tree, fname);
1167
1168         /* make sure write_time works */
1169         io.create.in.write_time = basetime;
1170         status = smb_raw_open(cli->tree, tctx, &io);
1171         CHECK_STATUS(status, NT_STATUS_OK);
1172         fnum = io.create.out.file.fnum;
1173         CHECK_TIME(basetime, write_time);
1174
1175         smbcli_close(cli->tree, fnum);
1176         smbcli_unlink(cli->tree, fname);
1177
1178         /* make sure file_attrs works */
1179         io.create.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1180         status = smb_raw_open(cli->tree, tctx, &io);
1181         CHECK_STATUS(status, NT_STATUS_OK);
1182         fnum = io.create.out.file.fnum;
1183         CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE, 
1184                        attrib & ~FILE_ATTRIBUTE_NONINDEXED);
1185         
1186 done:
1187         smbcli_close(cli->tree, fnum);
1188         smbcli_unlink(cli->tree, fname);
1189
1190         return ret;
1191 }
1192
1193
1194 /*
1195   test RAW_OPEN_CTEMP
1196 */
1197 static bool test_ctemp(struct smbcli_state *cli, TALLOC_CTX *tctx)
1198 {
1199         union smb_open io;
1200         NTSTATUS status;
1201         int fnum = -1;
1202         bool ret = true;
1203         time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1204         union smb_fileinfo finfo;
1205         const char *name, *fname = NULL;
1206
1207         printf("Checking RAW_OPEN_CTEMP\n");
1208
1209         io.ctemp.level = RAW_OPEN_CTEMP;
1210         io.ctemp.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1211         io.ctemp.in.write_time = basetime;
1212         io.ctemp.in.directory = BASEDIR;
1213         status = smb_raw_open(cli->tree, tctx, &io);
1214         CHECK_STATUS(status, NT_STATUS_OK);
1215         fnum = io.ctemp.out.file.fnum;
1216
1217         name = io.ctemp.out.name;
1218
1219         finfo.generic.level = RAW_FILEINFO_NAME_INFO;
1220         finfo.generic.in.file.fnum = fnum;
1221         status = smb_raw_fileinfo(cli->tree, tctx, &finfo);
1222         CHECK_STATUS(status, NT_STATUS_OK);
1223
1224         fname = finfo.name_info.out.fname.s;
1225         d_printf("ctemp name=%s  real name=%s\n", name, fname);
1226
1227 done:
1228         smbcli_close(cli->tree, fnum);
1229         if (fname) {
1230                 smbcli_unlink(cli->tree, fname);
1231         }
1232
1233         return ret;
1234 }
1235
1236
1237 /*
1238   test chained RAW_OPEN_OPENX_READX
1239 */
1240 static bool test_chained(struct smbcli_state *cli, TALLOC_CTX *tctx)
1241 {
1242         union smb_open io;
1243         const char *fname = BASEDIR "\\torture_chained.txt";
1244         NTSTATUS status;
1245         int fnum = -1;
1246         bool ret = true;
1247         const char *buf = "test";
1248         char buf2[4];
1249
1250         printf("Checking RAW_OPEN_OPENX chained with READX\n");
1251         smbcli_unlink(cli->tree, fname);
1252
1253         fnum = create_complex_file(cli, tctx, fname);
1254
1255         smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf));
1256
1257         smbcli_close(cli->tree, fnum);  
1258
1259         io.openxreadx.level = RAW_OPEN_OPENX_READX;
1260         io.openxreadx.in.fname = fname;
1261         io.openxreadx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
1262         io.openxreadx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
1263         io.openxreadx.in.open_func = OPENX_OPEN_FUNC_OPEN;
1264         io.openxreadx.in.search_attrs = 0;
1265         io.openxreadx.in.file_attrs = 0;
1266         io.openxreadx.in.write_time = 0;
1267         io.openxreadx.in.size = 1024*1024;
1268         io.openxreadx.in.timeout = 0;
1269         
1270         io.openxreadx.in.offset = 0;
1271         io.openxreadx.in.mincnt = sizeof(buf);
1272         io.openxreadx.in.maxcnt = sizeof(buf);
1273         io.openxreadx.in.remaining = 0;
1274         io.openxreadx.out.data = (uint8_t *)buf2;
1275
1276         status = smb_raw_open(cli->tree, tctx, &io);
1277         CHECK_STATUS(status, NT_STATUS_OK);
1278         fnum = io.openxreadx.out.file.fnum;
1279
1280         if (memcmp(buf, buf2, sizeof(buf)) != 0) {
1281                 d_printf("wrong data in reply buffer\n");
1282                 ret = false;
1283         }
1284
1285 done:
1286         smbcli_close(cli->tree, fnum);
1287         smbcli_unlink(cli->tree, fname);
1288
1289         return ret;
1290 }
1291
1292 /*
1293   test RAW_OPEN_OPENX without a leading slash on the path.
1294   NetApp filers are known to fail on this.
1295   
1296 */
1297 static bool test_no_leading_slash(struct smbcli_state *cli, TALLOC_CTX *tctx)
1298 {
1299         union smb_open io;
1300         const char *fname = BASEDIR "\\torture_no_leading_slash.txt";
1301         NTSTATUS status;
1302         int fnum = -1;
1303         bool ret = true;
1304         const char *buf = "test";
1305
1306         printf("Checking RAW_OPEN_OPENX without leading slash on path\n");
1307         smbcli_unlink(cli->tree, fname);
1308
1309         /* Create the file */
1310         fnum = create_complex_file(cli, tctx, fname);
1311         smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf));
1312         smbcli_close(cli->tree, fnum);  
1313
1314         /* Prepare to open the file using path without leading slash */
1315         io.openx.level = RAW_OPEN_OPENX;
1316         io.openx.in.fname = fname + 1;
1317         io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
1318         io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
1319         io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
1320         io.openx.in.search_attrs = 0;
1321         io.openx.in.file_attrs = 0;
1322         io.openx.in.write_time = 0;
1323         io.openx.in.size = 1024*1024;
1324         io.openx.in.timeout = 0;
1325
1326         status = smb_raw_open(cli->tree, tctx, &io);
1327         CHECK_STATUS(status, NT_STATUS_OK);
1328         fnum = io.openx.out.file.fnum;
1329
1330 done:
1331         smbcli_close(cli->tree, fnum);
1332         smbcli_unlink(cli->tree, fname);
1333
1334         return ret;
1335 }
1336
1337 /* A little torture test to expose a race condition in Samba 3.0.20 ... :-) */
1338
1339 static bool test_raw_open_multi(struct torture_context *tctx)
1340 {
1341         struct smbcli_state *cli;
1342         TALLOC_CTX *mem_ctx = talloc_init("torture_test_oplock_multi");
1343         const char *fname = "\\test_oplock.dat";
1344         NTSTATUS status;
1345         bool ret = true;
1346         union smb_open io;
1347         struct smbcli_state **clients;
1348         struct smbcli_request **requests;
1349         union smb_open *ios;
1350         const char *host = torture_setting_string(tctx, "host", NULL);
1351         const char *share = torture_setting_string(tctx, "share", NULL);
1352         int i, num_files = 3;
1353         int num_ok = 0;
1354         int num_collision = 0;
1355         
1356         clients = talloc_array(mem_ctx, struct smbcli_state *, num_files);
1357         requests = talloc_array(mem_ctx, struct smbcli_request *, num_files);
1358         ios = talloc_array(mem_ctx, union smb_open, num_files);
1359         if ((tctx->ev == NULL) || (clients == NULL) || (requests == NULL) ||
1360             (ios == NULL)) {
1361                 DEBUG(0, ("talloc failed\n"));
1362                 return false;
1363         }
1364
1365         if (!torture_open_connection_share(mem_ctx, &cli, tctx, host, share, tctx->ev)) {
1366                 return false;
1367         }
1368
1369         cli->tree->session->transport->options.request_timeout = 60;
1370
1371         for (i=0; i<num_files; i++) {
1372                 if (!torture_open_connection_share(mem_ctx, &(clients[i]),
1373                                                    tctx, host, share, tctx->ev)) {
1374                         DEBUG(0, ("Could not open %d'th connection\n", i));
1375                         return false;
1376                 }
1377                 clients[i]->tree->session->transport->options.request_timeout = 60;
1378         }
1379
1380         /* cleanup */
1381         smbcli_unlink(cli->tree, fname);
1382
1383         /*
1384           base ntcreatex parms
1385         */
1386         io.generic.level = RAW_OPEN_NTCREATEX;
1387         io.ntcreatex.in.root_fid = 0;
1388         io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
1389         io.ntcreatex.in.alloc_size = 0;
1390         io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1391         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ|
1392                 NTCREATEX_SHARE_ACCESS_WRITE|
1393                 NTCREATEX_SHARE_ACCESS_DELETE;
1394         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1395         io.ntcreatex.in.create_options = 0;
1396         io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1397         io.ntcreatex.in.security_flags = 0;
1398         io.ntcreatex.in.fname = fname;
1399         io.ntcreatex.in.flags = 0;
1400
1401         for (i=0; i<num_files; i++) {
1402                 ios[i] = io;
1403                 requests[i] = smb_raw_open_send(clients[i]->tree, &ios[i]);
1404                 if (requests[i] == NULL) {
1405                         DEBUG(0, ("could not send %d'th request\n", i));
1406                         return false;
1407                 }
1408         }
1409
1410         DEBUG(10, ("waiting for replies\n"));
1411         while (1) {
1412                 bool unreplied = false;
1413                 for (i=0; i<num_files; i++) {
1414                         if (requests[i] == NULL) {
1415                                 continue;
1416                         }
1417                         if (requests[i]->state < SMBCLI_REQUEST_DONE) {
1418                                 unreplied = true;
1419                                 break;
1420                         }
1421                         status = smb_raw_open_recv(requests[i], mem_ctx,
1422                                                    &ios[i]);
1423
1424                         DEBUG(0, ("File %d returned status %s\n", i,
1425                                   nt_errstr(status)));
1426
1427                         if (NT_STATUS_IS_OK(status)) {
1428                                 num_ok += 1;
1429                         } 
1430
1431                         if (NT_STATUS_EQUAL(status,
1432                                             NT_STATUS_OBJECT_NAME_COLLISION)) {
1433                                 num_collision += 1;
1434                         }
1435
1436                         requests[i] = NULL;
1437                 }
1438                 if (!unreplied) {
1439                         break;
1440                 }
1441
1442                 if (event_loop_once(tctx->ev) != 0) {
1443                         DEBUG(0, ("event_loop_once failed\n"));
1444                         return false;
1445                 }
1446         }
1447
1448         if ((num_ok != 1) || (num_ok + num_collision != num_files)) {
1449                 ret = false;
1450         }
1451
1452         for (i=0; i<num_files; i++) {
1453                 torture_close_connection(clients[i]);
1454         }
1455         talloc_free(mem_ctx);
1456         return ret;
1457 }
1458
1459 /* basic testing of all RAW_OPEN_* calls 
1460 */
1461 bool torture_raw_open(struct torture_context *torture, struct smbcli_state *cli)
1462 {
1463         bool ret = true;
1464
1465         if (!torture_setup_dir(cli, BASEDIR)) {
1466                 return false;
1467         }
1468
1469         ret &= test_ntcreatex_brlocked(cli, torture);
1470         ret &= test_open(cli, torture);
1471         ret &= test_raw_open_multi(torture);
1472         ret &= test_openx(cli, torture);
1473         ret &= test_ntcreatex(cli, torture);
1474         ret &= test_nttrans_create(cli, torture);
1475         ret &= test_t2open(cli, torture);
1476         ret &= test_mknew(cli, torture);
1477         ret &= test_create(cli, torture);
1478         ret &= test_ctemp(cli, torture);
1479         ret &= test_chained(cli, torture);
1480         ret &= test_no_leading_slash(cli, torture);
1481
1482         smb_raw_exit(cli->session);
1483         smbcli_deltree(cli->tree, BASEDIR);
1484
1485         return ret;
1486 }