1901338e21c6c408579358c117a3f46b14f9db39
[kai/samba.git] / source4 / 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
958         /* check no-recall - don't pull a file from tape on a HSM */
959         io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_NO_RECALL;
960         status = smb_raw_open(cli->tree, tctx, &io);
961         CHECK_STATUS(status, NT_STATUS_OK);
962         fnum = io.ntcreatex.out.file.fnum;
963
964         CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
965         CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
966         CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
967         CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
968         CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
969         CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
970         CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
971         CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
972         CHECK_ALL_INFO(io.ntcreatex.out.size, size);
973         CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
974         CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
975         smbcli_close(cli->tree, fnum);
976
977         /* Check some create options (these all should be ignored) */
978         for (i=0; i < 32; i++) {
979                 uint32_t create_option = (1 << i) & NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
980                 if (create_option == 0) {
981                         continue;
982                 }
983                 io.ntcreatex.in.create_options = create_option;
984                 status = smb_raw_open(cli->tree, tctx, &io);
985                 CHECK_STATUS(status, NT_STATUS_OK);
986
987                 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
988                 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
989                 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
990                 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
991                 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
992                 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
993                 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
994                 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
995                 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
996                 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
997                 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
998                 smbcli_close(cli->tree, fnum);
999         }
1000
1001         smbcli_unlink(cli->tree, fname);
1002
1003
1004         /* create a directory */
1005         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1006         io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
1007         io.ntcreatex.in.alloc_size = 0;
1008         io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
1009         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
1010         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1011         io.ntcreatex.in.create_options = 0;
1012         io.ntcreatex.in.fname = dname;
1013         fname = dname;
1014
1015         smbcli_rmdir(cli->tree, fname);
1016         smbcli_unlink(cli->tree, fname);
1017
1018         io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1019         io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1020         io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1021         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1022         status = smb_raw_open(cli->tree, tctx, &io);
1023         CHECK_STATUS(status, NT_STATUS_OK);
1024         fnum = io.ntcreatex.out.file.fnum;
1025
1026         CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
1027         CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
1028         CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
1029         CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
1030         CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
1031         CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
1032         CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
1033         CHECK_VAL(io.ntcreatex.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED, 
1034                   FILE_ATTRIBUTE_DIRECTORY);
1035         CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
1036         CHECK_ALL_INFO(io.ntcreatex.out.size, size);
1037         CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
1038         CHECK_VAL(io.ntcreatex.out.is_directory, 1);
1039         CHECK_VAL(io.ntcreatex.out.size, 0);
1040         CHECK_VAL(io.ntcreatex.out.alloc_size, 0);
1041         CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
1042         smbcli_unlink(cli->tree, fname);
1043         
1044
1045 done:
1046         smbcli_close(cli->tree, fnum);
1047         smbcli_unlink(cli->tree, fname);
1048
1049         return ret;
1050 }
1051
1052 /*
1053   test RAW_OPEN_NTCREATEX with an already opened and byte range locked file
1054
1055   I've got an application that does a similar sequence of ntcreate&x,
1056   locking&x and another ntcreate&x with
1057   open_disposition==NTCREATEX_DISP_OVERWRITE_IF. Windows 2003 allows the
1058   second open.
1059 */
1060 static bool test_ntcreatex_brlocked(struct smbcli_state *cli, struct torture_context *tctx)
1061 {
1062         union smb_open io, io1;
1063         union smb_lock io2;
1064         struct smb_lock_entry lock[1];
1065         const char *fname = BASEDIR "\\torture_ntcreatex.txt";
1066         NTSTATUS status;
1067         bool ret = true;
1068
1069         printf("Testing ntcreatex with a byte range locked file\n");
1070
1071         io.generic.level = RAW_OPEN_NTCREATEX;
1072         io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
1073         io.ntcreatex.in.root_fid = 0;
1074         io.ntcreatex.in.access_mask = 0x2019f;
1075         io.ntcreatex.in.alloc_size = 0;
1076         io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1077         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1078                 NTCREATEX_SHARE_ACCESS_WRITE;
1079         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1080         io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
1081         io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
1082         io.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC |
1083                 NTCREATEX_SECURITY_ALL;
1084         io.ntcreatex.in.fname = fname;
1085
1086         status = smb_raw_open(cli->tree, tctx, &io);
1087         CHECK_STATUS(status, NT_STATUS_OK);
1088
1089         io2.lockx.level = RAW_LOCK_LOCKX;
1090         io2.lockx.in.file.fnum = io.ntcreatex.out.file.fnum;
1091         io2.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
1092         io2.lockx.in.timeout = 0;
1093         io2.lockx.in.ulock_cnt = 0;
1094         io2.lockx.in.lock_cnt = 1;
1095         lock[0].pid = cli->session->pid;
1096         lock[0].offset = 0;
1097         lock[0].count = 0x1;
1098         io2.lockx.in.locks = &lock[0];
1099         status = smb_raw_lock(cli->tree, &io2);
1100         CHECK_STATUS(status, NT_STATUS_OK);
1101
1102         io1.generic.level = RAW_OPEN_NTCREATEX;
1103         io1.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
1104         io1.ntcreatex.in.root_fid = 0;
1105         io1.ntcreatex.in.access_mask = 0x20196;
1106         io1.ntcreatex.in.alloc_size = 0;
1107         io1.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1108         io1.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1109                 NTCREATEX_SHARE_ACCESS_WRITE;
1110         io1.ntcreatex.in.open_disposition = NTCREATEX_DISP_OVERWRITE_IF;
1111         io1.ntcreatex.in.create_options = 0;
1112         io1.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
1113         io1.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC |
1114                 NTCREATEX_SECURITY_ALL;
1115         io1.ntcreatex.in.fname = fname;
1116
1117         status = smb_raw_open(cli->tree, tctx, &io1);
1118         CHECK_STATUS(status, NT_STATUS_OK);
1119
1120  done:
1121         smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
1122         smbcli_close(cli->tree, io1.ntcreatex.out.file.fnum);
1123         smbcli_unlink(cli->tree, fname);
1124         return ret;
1125 }
1126
1127 /*
1128   test RAW_OPEN_MKNEW
1129 */
1130 static bool test_mknew(struct smbcli_state *cli, struct torture_context *tctx)
1131 {
1132         union smb_open io;
1133         const char *fname = BASEDIR "\\torture_mknew.txt";
1134         NTSTATUS status;
1135         int fnum = -1;
1136         bool ret = true;
1137         time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1138         union smb_fileinfo finfo;
1139
1140         printf("Checking RAW_OPEN_MKNEW\n");
1141
1142         io.mknew.level = RAW_OPEN_MKNEW;
1143         io.mknew.in.attrib = 0;
1144         io.mknew.in.write_time = 0;
1145         io.mknew.in.fname = fname;
1146         status = smb_raw_open(cli->tree, tctx, &io);
1147         CHECK_STATUS(status, NT_STATUS_OK);
1148         fnum = io.mknew.out.file.fnum;
1149
1150         status = smb_raw_open(cli->tree, tctx, &io);
1151         CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
1152
1153         smbcli_close(cli->tree, fnum);
1154         smbcli_unlink(cli->tree, fname);
1155
1156         /* make sure write_time works */
1157         io.mknew.in.write_time = basetime;
1158         status = smb_raw_open(cli->tree, tctx, &io);
1159         CHECK_STATUS(status, NT_STATUS_OK);
1160         fnum = io.mknew.out.file.fnum;
1161         CHECK_TIME(basetime, write_time);
1162
1163         smbcli_close(cli->tree, fnum);
1164         smbcli_unlink(cli->tree, fname);
1165
1166         /* make sure file_attrs works */
1167         io.mknew.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1168         status = smb_raw_open(cli->tree, tctx, &io);
1169         CHECK_STATUS(status, NT_STATUS_OK);
1170         fnum = io.mknew.out.file.fnum;
1171         CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE, 
1172                        attrib & ~FILE_ATTRIBUTE_NONINDEXED);
1173         
1174 done:
1175         smbcli_close(cli->tree, fnum);
1176         smbcli_unlink(cli->tree, fname);
1177
1178         return ret;
1179 }
1180
1181
1182 /*
1183   test RAW_OPEN_CREATE
1184 */
1185 static bool test_create(struct smbcli_state *cli, struct torture_context *tctx)
1186 {
1187         union smb_open io;
1188         const char *fname = BASEDIR "\\torture_create.txt";
1189         NTSTATUS status;
1190         int fnum = -1;
1191         bool ret = true;
1192         time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1193         union smb_fileinfo finfo;
1194
1195         printf("Checking RAW_OPEN_CREATE\n");
1196
1197         io.create.level = RAW_OPEN_CREATE;
1198         io.create.in.attrib = 0;
1199         io.create.in.write_time = 0;
1200         io.create.in.fname = fname;
1201         status = smb_raw_open(cli->tree, tctx, &io);
1202         CHECK_STATUS(status, NT_STATUS_OK);
1203         fnum = io.create.out.file.fnum;
1204
1205         status = smb_raw_open(cli->tree, tctx, &io);
1206         CHECK_STATUS(status, NT_STATUS_OK);
1207
1208         smbcli_close(cli->tree, io.create.out.file.fnum);
1209         smbcli_close(cli->tree, fnum);
1210         smbcli_unlink(cli->tree, fname);
1211
1212         /* make sure write_time works */
1213         io.create.in.write_time = basetime;
1214         status = smb_raw_open(cli->tree, tctx, &io);
1215         CHECK_STATUS(status, NT_STATUS_OK);
1216         fnum = io.create.out.file.fnum;
1217         CHECK_TIME(basetime, write_time);
1218
1219         smbcli_close(cli->tree, fnum);
1220         smbcli_unlink(cli->tree, fname);
1221
1222         /* make sure file_attrs works */
1223         io.create.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1224         status = smb_raw_open(cli->tree, tctx, &io);
1225         CHECK_STATUS(status, NT_STATUS_OK);
1226         fnum = io.create.out.file.fnum;
1227         CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE, 
1228                        attrib & ~FILE_ATTRIBUTE_NONINDEXED);
1229         
1230 done:
1231         smbcli_close(cli->tree, fnum);
1232         smbcli_unlink(cli->tree, fname);
1233
1234         return ret;
1235 }
1236
1237
1238 /*
1239   test RAW_OPEN_CTEMP
1240 */
1241 static bool test_ctemp(struct smbcli_state *cli, TALLOC_CTX *tctx)
1242 {
1243         union smb_open io;
1244         NTSTATUS status;
1245         int fnum = -1;
1246         bool ret = true;
1247         time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1248         union smb_fileinfo finfo;
1249         const char *name, *fname = NULL;
1250
1251         printf("Checking RAW_OPEN_CTEMP\n");
1252
1253         io.ctemp.level = RAW_OPEN_CTEMP;
1254         io.ctemp.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1255         io.ctemp.in.write_time = basetime;
1256         io.ctemp.in.directory = BASEDIR;
1257         status = smb_raw_open(cli->tree, tctx, &io);
1258         CHECK_STATUS(status, NT_STATUS_OK);
1259         fnum = io.ctemp.out.file.fnum;
1260
1261         name = io.ctemp.out.name;
1262
1263         finfo.generic.level = RAW_FILEINFO_NAME_INFO;
1264         finfo.generic.in.file.fnum = fnum;
1265         status = smb_raw_fileinfo(cli->tree, tctx, &finfo);
1266         CHECK_STATUS(status, NT_STATUS_OK);
1267
1268         fname = finfo.name_info.out.fname.s;
1269         d_printf("ctemp name=%s  real name=%s\n", name, fname);
1270
1271 done:
1272         smbcli_close(cli->tree, fnum);
1273         if (fname) {
1274                 smbcli_unlink(cli->tree, fname);
1275         }
1276
1277         return ret;
1278 }
1279
1280
1281 /*
1282   test chained RAW_OPEN_OPENX_READX
1283 */
1284 static bool test_chained(struct smbcli_state *cli, TALLOC_CTX *tctx)
1285 {
1286         union smb_open io;
1287         const char *fname = BASEDIR "\\torture_chained.txt";
1288         NTSTATUS status;
1289         int fnum = -1;
1290         bool ret = true;
1291         const char *buf = "test";
1292         char buf2[4];
1293
1294         printf("Checking RAW_OPEN_OPENX chained with READX\n");
1295         smbcli_unlink(cli->tree, fname);
1296
1297         fnum = create_complex_file(cli, tctx, fname);
1298
1299         smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf));
1300
1301         smbcli_close(cli->tree, fnum);  
1302
1303         io.openxreadx.level = RAW_OPEN_OPENX_READX;
1304         io.openxreadx.in.fname = fname;
1305         io.openxreadx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
1306         io.openxreadx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
1307         io.openxreadx.in.open_func = OPENX_OPEN_FUNC_OPEN;
1308         io.openxreadx.in.search_attrs = 0;
1309         io.openxreadx.in.file_attrs = 0;
1310         io.openxreadx.in.write_time = 0;
1311         io.openxreadx.in.size = 1024*1024;
1312         io.openxreadx.in.timeout = 0;
1313         
1314         io.openxreadx.in.offset = 0;
1315         io.openxreadx.in.mincnt = sizeof(buf);
1316         io.openxreadx.in.maxcnt = sizeof(buf);
1317         io.openxreadx.in.remaining = 0;
1318         io.openxreadx.out.data = (uint8_t *)buf2;
1319
1320         status = smb_raw_open(cli->tree, tctx, &io);
1321         CHECK_STATUS(status, NT_STATUS_OK);
1322         fnum = io.openxreadx.out.file.fnum;
1323
1324         if (memcmp(buf, buf2, sizeof(buf)) != 0) {
1325                 d_printf("wrong data in reply buffer\n");
1326                 ret = false;
1327         }
1328
1329 done:
1330         smbcli_close(cli->tree, fnum);
1331         smbcli_unlink(cli->tree, fname);
1332
1333         return ret;
1334 }
1335
1336 /*
1337   test RAW_OPEN_OPENX without a leading slash on the path.
1338   NetApp filers are known to fail on this.
1339   
1340 */
1341 static bool test_no_leading_slash(struct smbcli_state *cli, TALLOC_CTX *tctx)
1342 {
1343         union smb_open io;
1344         const char *fname = BASEDIR "\\torture_no_leading_slash.txt";
1345         NTSTATUS status;
1346         int fnum = -1;
1347         bool ret = true;
1348         const char *buf = "test";
1349
1350         printf("Checking RAW_OPEN_OPENX without leading slash on path\n");
1351         smbcli_unlink(cli->tree, fname);
1352
1353         /* Create the file */
1354         fnum = create_complex_file(cli, tctx, fname);
1355         smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf));
1356         smbcli_close(cli->tree, fnum);  
1357
1358         /* Prepare to open the file using path without leading slash */
1359         io.openx.level = RAW_OPEN_OPENX;
1360         io.openx.in.fname = fname + 1;
1361         io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
1362         io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
1363         io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
1364         io.openx.in.search_attrs = 0;
1365         io.openx.in.file_attrs = 0;
1366         io.openx.in.write_time = 0;
1367         io.openx.in.size = 1024*1024;
1368         io.openx.in.timeout = 0;
1369
1370         status = smb_raw_open(cli->tree, tctx, &io);
1371         CHECK_STATUS(status, NT_STATUS_OK);
1372         fnum = io.openx.out.file.fnum;
1373
1374 done:
1375         smbcli_close(cli->tree, fnum);
1376         smbcli_unlink(cli->tree, fname);
1377
1378         return ret;
1379 }
1380
1381 /* A little torture test to expose a race condition in Samba 3.0.20 ... :-) */
1382
1383 static bool test_raw_open_multi(struct torture_context *tctx)
1384 {
1385         struct smbcli_state *cli;
1386         TALLOC_CTX *mem_ctx = talloc_init("torture_test_oplock_multi");
1387         const char *fname = "\\test_oplock.dat";
1388         NTSTATUS status;
1389         bool ret = true;
1390         union smb_open io;
1391         struct smbcli_state **clients;
1392         struct smbcli_request **requests;
1393         union smb_open *ios;
1394         const char *host = torture_setting_string(tctx, "host", NULL);
1395         const char *share = torture_setting_string(tctx, "share", NULL);
1396         int i, num_files = 3;
1397         int num_ok = 0;
1398         int num_collision = 0;
1399         
1400         clients = talloc_array(mem_ctx, struct smbcli_state *, num_files);
1401         requests = talloc_array(mem_ctx, struct smbcli_request *, num_files);
1402         ios = talloc_array(mem_ctx, union smb_open, num_files);
1403         if ((tctx->ev == NULL) || (clients == NULL) || (requests == NULL) ||
1404             (ios == NULL)) {
1405                 DEBUG(0, ("talloc failed\n"));
1406                 return false;
1407         }
1408
1409         if (!torture_open_connection_share(mem_ctx, &cli, tctx, host, share, tctx->ev)) {
1410                 return false;
1411         }
1412
1413         cli->tree->session->transport->options.request_timeout = 60;
1414
1415         for (i=0; i<num_files; i++) {
1416                 if (!torture_open_connection_share(mem_ctx, &(clients[i]),
1417                                                    tctx, host, share, tctx->ev)) {
1418                         DEBUG(0, ("Could not open %d'th connection\n", i));
1419                         return false;
1420                 }
1421                 clients[i]->tree->session->transport->options.request_timeout = 60;
1422         }
1423
1424         /* cleanup */
1425         smbcli_unlink(cli->tree, fname);
1426
1427         /*
1428           base ntcreatex parms
1429         */
1430         io.generic.level = RAW_OPEN_NTCREATEX;
1431         io.ntcreatex.in.root_fid = 0;
1432         io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
1433         io.ntcreatex.in.alloc_size = 0;
1434         io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1435         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ|
1436                 NTCREATEX_SHARE_ACCESS_WRITE|
1437                 NTCREATEX_SHARE_ACCESS_DELETE;
1438         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1439         io.ntcreatex.in.create_options = 0;
1440         io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1441         io.ntcreatex.in.security_flags = 0;
1442         io.ntcreatex.in.fname = fname;
1443         io.ntcreatex.in.flags = 0;
1444
1445         for (i=0; i<num_files; i++) {
1446                 ios[i] = io;
1447                 requests[i] = smb_raw_open_send(clients[i]->tree, &ios[i]);
1448                 if (requests[i] == NULL) {
1449                         DEBUG(0, ("could not send %d'th request\n", i));
1450                         return false;
1451                 }
1452         }
1453
1454         DEBUG(10, ("waiting for replies\n"));
1455         while (1) {
1456                 bool unreplied = false;
1457                 for (i=0; i<num_files; i++) {
1458                         if (requests[i] == NULL) {
1459                                 continue;
1460                         }
1461                         if (requests[i]->state < SMBCLI_REQUEST_DONE) {
1462                                 unreplied = true;
1463                                 break;
1464                         }
1465                         status = smb_raw_open_recv(requests[i], mem_ctx,
1466                                                    &ios[i]);
1467
1468                         DEBUG(0, ("File %d returned status %s\n", i,
1469                                   nt_errstr(status)));
1470
1471                         if (NT_STATUS_IS_OK(status)) {
1472                                 num_ok += 1;
1473                         } 
1474
1475                         if (NT_STATUS_EQUAL(status,
1476                                             NT_STATUS_OBJECT_NAME_COLLISION)) {
1477                                 num_collision += 1;
1478                         }
1479
1480                         requests[i] = NULL;
1481                 }
1482                 if (!unreplied) {
1483                         break;
1484                 }
1485
1486                 if (event_loop_once(tctx->ev) != 0) {
1487                         DEBUG(0, ("event_loop_once failed\n"));
1488                         return false;
1489                 }
1490         }
1491
1492         if ((num_ok != 1) || (num_ok + num_collision != num_files)) {
1493                 ret = false;
1494         }
1495
1496         for (i=0; i<num_files; i++) {
1497                 torture_close_connection(clients[i]);
1498         }
1499         talloc_free(mem_ctx);
1500         return ret;
1501 }
1502
1503 /* basic testing of all RAW_OPEN_* calls 
1504 */
1505 bool torture_raw_open(struct torture_context *torture, struct smbcli_state *cli)
1506 {
1507         bool ret = true;
1508
1509         if (!torture_setup_dir(cli, BASEDIR)) {
1510                 return false;
1511         }
1512
1513         ret &= test_ntcreatex_brlocked(cli, torture);
1514         ret &= test_open(cli, torture);
1515         ret &= test_raw_open_multi(torture);
1516         ret &= test_openx(cli, torture);
1517         ret &= test_ntcreatex(cli, torture);
1518         ret &= test_nttrans_create(cli, torture);
1519         ret &= test_t2open(cli, torture);
1520         ret &= test_mknew(cli, torture);
1521         ret &= test_create(cli, torture);
1522         ret &= test_ctemp(cli, torture);
1523         ret &= test_chained(cli, torture);
1524         ret &= test_no_leading_slash(cli, torture);
1525
1526         smb_raw_exit(cli->session);
1527         smbcli_deltree(cli->tree, BASEDIR);
1528
1529         return ret;
1530 }