2 Unix SMB/CIFS implementation.
3 RAW_OPEN_* individual test suite
4 Copyright (C) Andrew Tridgell 2003
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.
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.
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/>.
21 #include "libcli/raw/libcliraw.h"
22 #include "system/time.h"
23 #include "system/filesys.h"
24 #include "lib/events/events.h"
25 #include "libcli/libcli.h"
26 #include "torture/util.h"
28 /* enum for whether reads/writes are possible on a file */
29 enum rdwr_mode {RDWR_NONE, RDWR_RDONLY, RDWR_WRONLY, RDWR_RDWR};
31 #define BASEDIR "\\rawopen"
34 check if a open file can be read/written
36 static enum rdwr_mode check_rdwr(struct smbcli_tree *tree, int fnum)
39 bool can_read = (smbcli_read(tree, fnum, &c, 0, 1) == 1);
40 bool can_write = (smbcli_write(tree, fnum, 0, &c, 0, 1) == 1);
41 if ( can_read && can_write) return RDWR_RDWR;
42 if ( can_read && !can_write) return RDWR_RDONLY;
43 if (!can_read && can_write) return RDWR_WRONLY;
48 describe a RDWR mode as a string
50 static const char *rdwr_string(enum rdwr_mode m)
53 case RDWR_NONE: return "NONE";
54 case RDWR_RDONLY: return "RDONLY";
55 case RDWR_WRONLY: return "WRONLY";
56 case RDWR_RDWR: return "RDWR";
61 #define CHECK_STATUS(status, correct) do { \
62 if (!NT_STATUS_EQUAL(status, correct)) { \
63 torture_result(tctx, TORTURE_FAIL, \
64 "(%s) Incorrect status %s - should be %s\n", \
65 __location__, nt_errstr(status), nt_errstr(correct)); \
70 #define CREATE_FILE do { \
71 fnum = create_complex_file(cli, tctx, fname); \
73 torture_result(tctx, TORTURE_FAIL, \
74 "(%s) Failed to create %s - %s\n", \
75 __location__, fname, smbcli_errstr(cli->tree)); \
80 #define CHECK_RDWR(fnum, correct) do { \
81 enum rdwr_mode m = check_rdwr(cli->tree, fnum); \
83 torture_result(tctx, TORTURE_FAIL, \
84 "(%s) Incorrect readwrite mode %s - expected %s\n", \
85 __location__, rdwr_string(m), rdwr_string(correct)); \
89 #define CHECK_TIME(t, field) do { \
91 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
92 finfo.all_info.in.file.path = fname; \
93 status = smb_raw_pathinfo(cli->tree, tctx, &finfo); \
94 CHECK_STATUS(status, NT_STATUS_OK); \
96 t2 = nt_time_to_unix(finfo.all_info.out.field) & ~1; \
97 if (abs(t1-t2) > 2) { \
98 torture_result(tctx, TORTURE_FAIL, \
99 "(%s) wrong time for field %s %s - %s\n", \
100 __location__, #field, \
101 timestring(tctx, t1), \
102 timestring(tctx, t2)); \
103 dump_all_info(tctx, &finfo); \
107 #define CHECK_NTTIME(t, field) do { \
109 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
110 finfo.all_info.in.file.path = fname; \
111 status = smb_raw_pathinfo(cli->tree, tctx, &finfo); \
112 CHECK_STATUS(status, NT_STATUS_OK); \
113 t2 = finfo.all_info.out.field; \
115 torture_result(tctx, TORTURE_FAIL, \
116 "(%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); \
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 torture_result(tctx, TORTURE_FAIL, \
131 "(%s) wrong value for field %s 0x%x - 0x%x\n", \
132 __location__, #field, (int)v, (int)(finfo.all_info.out.field)); \
133 dump_all_info(tctx, &finfo); \
137 #define CHECK_VAL(v, correct) do { \
138 if ((v) != (correct)) { \
139 torture_result(tctx, TORTURE_FAIL, \
140 "(%s) wrong value for %s 0x%x - should be 0x%x\n", \
141 __location__, #v, (int)(v), (int)correct); \
145 #define SET_ATTRIB(sattrib) do { \
146 union smb_setfileinfo sfinfo; \
147 ZERO_STRUCT(sfinfo.basic_info.in); \
148 sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFORMATION; \
149 sfinfo.basic_info.in.file.path = fname; \
150 sfinfo.basic_info.in.attrib = sattrib; \
151 status = smb_raw_setpathinfo(cli->tree, &sfinfo); \
152 if (!NT_STATUS_IS_OK(status)) { \
153 torture_warning(tctx, "(%s) Failed to set attrib 0x%x on %s\n", \
154 __location__, sattrib, fname); \
160 static bool test_open(struct smbcli_state *cli, struct torture_context *tctx)
163 union smb_fileinfo finfo;
164 const char *fname = BASEDIR "\\torture_open.txt";
166 int fnum = -1, fnum2;
169 torture_comment(tctx, "Checking RAW_OPEN_OPEN\n");
171 io.openold.level = RAW_OPEN_OPEN;
172 io.openold.in.fname = fname;
173 io.openold.in.open_mode = OPEN_FLAGS_FCB;
174 io.openold.in.search_attrs = 0;
175 status = smb_raw_open(cli->tree, tctx, &io);
176 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
177 fnum = io.openold.out.file.fnum;
179 smbcli_unlink(cli->tree, fname);
181 smbcli_close(cli->tree, fnum);
183 status = smb_raw_open(cli->tree, tctx, &io);
184 CHECK_STATUS(status, NT_STATUS_OK);
185 fnum = io.openold.out.file.fnum;
186 CHECK_RDWR(fnum, RDWR_RDWR);
188 status = smb_raw_open(cli->tree, tctx, &io);
189 CHECK_STATUS(status, NT_STATUS_OK);
190 fnum2 = io.openold.out.file.fnum;
191 CHECK_RDWR(fnum2, RDWR_RDWR);
192 smbcli_close(cli->tree, fnum2);
193 smbcli_close(cli->tree, fnum);
195 /* check the read/write modes */
196 io.openold.level = RAW_OPEN_OPEN;
197 io.openold.in.fname = fname;
198 io.openold.in.search_attrs = 0;
200 io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ;
201 status = smb_raw_open(cli->tree, tctx, &io);
202 CHECK_STATUS(status, NT_STATUS_OK);
203 fnum = io.openold.out.file.fnum;
204 CHECK_RDWR(fnum, RDWR_RDONLY);
205 smbcli_close(cli->tree, fnum);
207 io.openold.in.open_mode = OPEN_FLAGS_OPEN_WRITE;
208 status = smb_raw_open(cli->tree, tctx, &io);
209 CHECK_STATUS(status, NT_STATUS_OK);
210 fnum = io.openold.out.file.fnum;
211 CHECK_RDWR(fnum, RDWR_WRONLY);
212 smbcli_close(cli->tree, fnum);
214 io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR;
215 status = smb_raw_open(cli->tree, tctx, &io);
216 CHECK_STATUS(status, NT_STATUS_OK);
217 fnum = io.openold.out.file.fnum;
218 CHECK_RDWR(fnum, RDWR_RDWR);
219 smbcli_close(cli->tree, fnum);
221 /* check the share modes roughly - not a complete matrix */
222 io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_WRITE;
223 status = smb_raw_open(cli->tree, tctx, &io);
224 CHECK_STATUS(status, NT_STATUS_OK);
225 fnum = io.openold.out.file.fnum;
226 CHECK_RDWR(fnum, RDWR_RDWR);
228 if (io.openold.in.open_mode != io.openold.out.rmode) {
229 torture_warning(tctx, "(%s) rmode should equal open_mode - 0x%x 0x%x\n",
230 __location__, io.openold.out.rmode, io.openold.in.open_mode);
233 io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_NONE;
234 status = smb_raw_open(cli->tree, tctx, &io);
235 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
237 io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ | OPEN_FLAGS_DENY_NONE;
238 status = smb_raw_open(cli->tree, tctx, &io);
239 CHECK_STATUS(status, NT_STATUS_OK);
240 fnum2 = io.openold.out.file.fnum;
241 CHECK_RDWR(fnum2, RDWR_RDONLY);
242 smbcli_close(cli->tree, fnum);
243 smbcli_close(cli->tree, fnum2);
246 /* check the returned write time */
247 io.openold.level = RAW_OPEN_OPEN;
248 io.openold.in.fname = fname;
249 io.openold.in.search_attrs = 0;
250 io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ;
251 status = smb_raw_open(cli->tree, tctx, &io);
252 CHECK_STATUS(status, NT_STATUS_OK);
253 fnum = io.openold.out.file.fnum;
255 /* check other reply fields */
256 CHECK_TIME(io.openold.out.write_time, write_time);
257 CHECK_ALL_INFO(io.openold.out.size, size);
258 CHECK_ALL_INFO(io.openold.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
261 smbcli_close(cli->tree, fnum);
262 smbcli_unlink(cli->tree, fname);
271 static bool test_openx(struct smbcli_state *cli, struct torture_context *tctx)
274 union smb_fileinfo finfo;
275 const char *fname = BASEDIR "\\torture_openx.txt";
276 const char *fname_exe = BASEDIR "\\torture_openx.exe";
278 int fnum = -1, fnum2;
285 NTSTATUS correct_status;
287 { OPENX_OPEN_FUNC_OPEN, true, NT_STATUS_OK },
288 { OPENX_OPEN_FUNC_OPEN, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
289 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OK },
290 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
291 { OPENX_OPEN_FUNC_FAIL, true, NT_STATUS_DOS(ERRDOS, ERRbadaccess) },
292 { OPENX_OPEN_FUNC_FAIL, false, NT_STATUS_DOS(ERRDOS, ERRbadaccess) },
293 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OBJECT_NAME_COLLISION },
294 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
295 { OPENX_OPEN_FUNC_TRUNC, true, NT_STATUS_OK },
296 { OPENX_OPEN_FUNC_TRUNC, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
297 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OK },
298 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
301 torture_comment(tctx, "Checking RAW_OPEN_OPENX\n");
302 smbcli_unlink(cli->tree, fname);
304 io.openx.level = RAW_OPEN_OPENX;
305 io.openx.in.fname = fname;
306 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
307 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
308 io.openx.in.search_attrs = 0;
309 io.openx.in.file_attrs = 0;
310 io.openx.in.write_time = 0;
311 io.openx.in.size = 1024*1024;
312 io.openx.in.timeout = 0;
314 /* check all combinations of open_func */
315 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
316 if (open_funcs[i].with_file) {
317 fnum = create_complex_file(cli, tctx, fname);
319 torture_result(tctx, TORTURE_FAIL,
320 "Failed to create file %s - %s\n",
321 fname, smbcli_errstr(cli->tree));
325 smbcli_close(cli->tree, fnum);
327 io.openx.in.open_func = open_funcs[i].open_func;
328 status = smb_raw_open(cli->tree, tctx, &io);
329 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
330 torture_result(tctx, TORTURE_FAIL,
331 "(%s) incorrect status %s should be %s "
332 "(i=%d with_file=%d open_func=0x%x)\n",
333 __location__, nt_errstr(status),
334 nt_errstr(open_funcs[i].correct_status),
335 i, (int)open_funcs[i].with_file,
336 (int)open_funcs[i].open_func);
339 if (NT_STATUS_IS_OK(status)) {
340 smbcli_close(cli->tree, io.openx.out.file.fnum);
342 if (open_funcs[i].with_file) {
343 smbcli_unlink(cli->tree, fname);
347 smbcli_unlink(cli->tree, fname);
349 /* check the basic return fields */
350 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
351 status = smb_raw_open(cli->tree, tctx, &io);
352 CHECK_STATUS(status, NT_STATUS_OK);
353 fnum = io.openx.out.file.fnum;
355 CHECK_ALL_INFO(io.openx.out.size, size);
356 CHECK_TIME(io.openx.out.write_time, write_time);
357 CHECK_ALL_INFO(io.openx.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
358 CHECK_VAL(io.openx.out.access, OPENX_MODE_ACCESS_RDWR);
359 CHECK_VAL(io.openx.out.ftype, 0);
360 CHECK_VAL(io.openx.out.devstate, 0);
361 CHECK_VAL(io.openx.out.action, OPENX_ACTION_CREATED);
362 CHECK_VAL(io.openx.out.size, 1024*1024);
363 CHECK_ALL_INFO(io.openx.in.size, size);
364 smbcli_close(cli->tree, fnum);
365 smbcli_unlink(cli->tree, fname);
367 /* check the fields when the file already existed */
368 fnum2 = create_complex_file(cli, tctx, fname);
373 smbcli_close(cli->tree, fnum2);
375 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
376 status = smb_raw_open(cli->tree, tctx, &io);
377 CHECK_STATUS(status, NT_STATUS_OK);
378 fnum = io.openx.out.file.fnum;
380 CHECK_ALL_INFO(io.openx.out.size, size);
381 CHECK_TIME(io.openx.out.write_time, write_time);
382 CHECK_VAL(io.openx.out.action, OPENX_ACTION_EXISTED);
383 CHECK_VAL(io.openx.out.unknown, 0);
384 CHECK_ALL_INFO(io.openx.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
385 smbcli_close(cli->tree, fnum);
387 /* now check the search attrib for hidden files - win2003 ignores this? */
388 SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN);
389 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib);
391 io.openx.in.search_attrs = FILE_ATTRIBUTE_HIDDEN;
392 status = smb_raw_open(cli->tree, tctx, &io);
393 CHECK_STATUS(status, NT_STATUS_OK);
394 smbcli_close(cli->tree, io.openx.out.file.fnum);
396 io.openx.in.search_attrs = 0;
397 status = smb_raw_open(cli->tree, tctx, &io);
398 CHECK_STATUS(status, NT_STATUS_OK);
399 smbcli_close(cli->tree, io.openx.out.file.fnum);
401 SET_ATTRIB(FILE_ATTRIBUTE_NORMAL);
402 smbcli_unlink(cli->tree, fname);
404 /* and check attrib on create */
405 io.openx.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE;
406 io.openx.in.search_attrs = 0;
407 io.openx.in.file_attrs = FILE_ATTRIBUTE_SYSTEM;
408 status = smb_raw_open(cli->tree, tctx, &io);
409 CHECK_STATUS(status, NT_STATUS_OK);
410 if (torture_setting_bool(tctx, "samba3", false)) {
411 CHECK_ALL_INFO(FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE,
412 attrib & ~(FILE_ATTRIBUTE_NONINDEXED|
413 FILE_ATTRIBUTE_SPARSE));
416 CHECK_ALL_INFO(FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE,
417 attrib & ~(FILE_ATTRIBUTE_NONINDEXED));
419 smbcli_close(cli->tree, io.openx.out.file.fnum);
420 smbcli_unlink(cli->tree, fname);
422 /* check timeout on create - win2003 ignores the timeout! */
423 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
424 io.openx.in.file_attrs = 0;
425 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL;
426 status = smb_raw_open(cli->tree, tctx, &io);
427 CHECK_STATUS(status, NT_STATUS_OK);
428 fnum = io.openx.out.file.fnum;
430 io.openx.in.timeout = 20000;
431 tv = timeval_current();
432 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_NONE;
433 status = smb_raw_open(cli->tree, tctx, &io);
434 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
435 if (timeval_elapsed(&tv) > 3.0) {
436 torture_result(tctx, TORTURE_FAIL,
437 "(%s) Incorrect timing in openx with timeout "
438 "- waited %.2f seconds\n",
439 __location__, timeval_elapsed(&tv));
442 smbcli_close(cli->tree, fnum);
443 smbcli_unlink(cli->tree, fname);
445 /* now this is a really weird one - open for execute implies create?! */
446 io.openx.in.fname = fname;
447 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
448 io.openx.in.open_mode = OPENX_MODE_ACCESS_EXEC | OPENX_MODE_DENY_NONE;
449 io.openx.in.search_attrs = 0;
450 io.openx.in.open_func = OPENX_OPEN_FUNC_FAIL;
451 io.openx.in.file_attrs = 0;
452 io.openx.in.write_time = 0;
453 io.openx.in.size = 0;
454 io.openx.in.timeout = 0;
455 status = smb_raw_open(cli->tree, tctx, &io);
456 CHECK_STATUS(status, NT_STATUS_OK);
457 smbcli_close(cli->tree, io.openx.out.file.fnum);
459 /* check the extended return flag */
460 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO | OPENX_FLAGS_EXTENDED_RETURN;
461 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
462 status = smb_raw_open(cli->tree, tctx, &io);
463 CHECK_STATUS(status, NT_STATUS_OK);
464 CHECK_VAL(io.openx.out.access_mask, SEC_STD_ALL);
465 smbcli_close(cli->tree, io.openx.out.file.fnum);
467 io.openx.in.fname = "\\A.+,;=[].B";
468 status = smb_raw_open(cli->tree, tctx, &io);
469 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
471 /* Check the mapping for open exec. */
473 /* First create an .exe file. */
474 smbcli_unlink(cli->tree, fname_exe);
475 fnum = create_complex_file(cli, tctx, fname_exe);
476 smbcli_close(cli->tree, fnum);
478 io.openx.level = RAW_OPEN_OPENX;
479 io.openx.in.fname = fname_exe;
480 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
481 io.openx.in.open_mode = OPENX_MODE_ACCESS_EXEC | OPENX_MODE_DENY_NONE;
482 io.openx.in.search_attrs = 0;
483 io.openx.in.file_attrs = 0;
484 io.openx.in.write_time = 0;
485 io.openx.in.size = 0;
486 io.openx.in.timeout = 0;
487 status = smb_raw_open(cli->tree, tctx, &io);
488 CHECK_STATUS(status, NT_STATUS_OK);
490 /* Can we read and write ? */
491 CHECK_RDWR(io.openx.out.file.fnum, RDWR_RDONLY);
492 smbcli_close(cli->tree, io.openx.out.file.fnum);
493 smbcli_unlink(cli->tree, fname);
496 smbcli_close(cli->tree, fnum);
497 smbcli_unlink(cli->tree, fname_exe);
498 smbcli_unlink(cli->tree, fname);
507 many thanks to kukks for a sniff showing how this works with os2->w2k
509 static bool test_t2open(struct smbcli_state *cli, struct torture_context *tctx)
512 union smb_fileinfo finfo;
513 const char *fname1 = BASEDIR "\\torture_t2open_yes.txt";
514 const char *fname2 = BASEDIR "\\torture_t2open_no.txt";
515 const char *fname = BASEDIR "\\torture_t2open_3.txt";
523 NTSTATUS correct_status;
525 { OPENX_OPEN_FUNC_OPEN, true, NT_STATUS_OK },
526 { OPENX_OPEN_FUNC_OPEN, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
527 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OK },
528 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
529 { OPENX_OPEN_FUNC_FAIL, true, NT_STATUS_OBJECT_NAME_COLLISION },
530 { OPENX_OPEN_FUNC_FAIL, false, NT_STATUS_OBJECT_NAME_COLLISION },
531 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OBJECT_NAME_COLLISION },
532 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OBJECT_NAME_COLLISION },
533 { OPENX_OPEN_FUNC_TRUNC, true, NT_STATUS_OK },
534 { OPENX_OPEN_FUNC_TRUNC, false, NT_STATUS_OK },
535 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OK },
536 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
539 fnum = create_complex_file(cli, tctx, fname1);
541 torture_result(tctx, TORTURE_FAIL,
542 "(%s): Failed to create file %s - %s\n",
543 __location__, fname1, smbcli_errstr(cli->tree));
547 smbcli_close(cli->tree, fnum);
549 torture_comment(tctx, "Checking RAW_OPEN_T2OPEN\n");
551 io.t2open.level = RAW_OPEN_T2OPEN;
552 io.t2open.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
553 io.t2open.in.open_mode = OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR;
554 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
555 io.t2open.in.search_attrs = 0;
556 io.t2open.in.file_attrs = 0;
557 io.t2open.in.write_time = 0;
558 io.t2open.in.size = 0;
559 io.t2open.in.timeout = 0;
561 io.t2open.in.num_eas = 3;
562 io.t2open.in.eas = talloc_array(tctx, struct ea_struct, io.t2open.in.num_eas);
563 io.t2open.in.eas[0].flags = 0;
564 io.t2open.in.eas[0].name.s = ".CLASSINFO";
565 io.t2open.in.eas[0].value = data_blob_talloc(tctx, "first value", 11);
566 io.t2open.in.eas[1].flags = 0;
567 io.t2open.in.eas[1].name.s = "EA TWO";
568 io.t2open.in.eas[1].value = data_blob_talloc(tctx, "foo", 3);
569 io.t2open.in.eas[2].flags = 0;
570 io.t2open.in.eas[2].name.s = "X THIRD";
571 io.t2open.in.eas[2].value = data_blob_talloc(tctx, "xy", 2);
573 /* check all combinations of open_func */
574 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
576 if (open_funcs[i].with_file) {
577 io.t2open.in.fname = fname1;
579 io.t2open.in.fname = fname2;
581 io.t2open.in.open_func = open_funcs[i].open_func;
582 status = smb_raw_open(cli->tree, tctx, &io);
583 if ((io.t2open.in.num_eas != 0)
584 && NT_STATUS_EQUAL(status, NT_STATUS_EAS_NOT_SUPPORTED)
585 && torture_setting_bool(tctx, "samba3", false)) {
586 torture_warning(tctx, "(%s) EAs not supported, not "
587 "treating as fatal in Samba3 test\n",
589 io.t2open.in.num_eas = 0;
593 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
594 torture_result(tctx, TORTURE_FAIL,
595 "(%s) incorrect status %s should be %s "
596 "(i=%d with_file=%d open_func=0x%x)\n",
597 __location__, nt_errstr(status),
598 nt_errstr(open_funcs[i].correct_status),
599 i, (int)open_funcs[i].with_file,
600 (int)open_funcs[i].open_func);
603 if (NT_STATUS_IS_OK(status)) {
604 smbcli_close(cli->tree, io.t2open.out.file.fnum);
608 smbcli_unlink(cli->tree, fname1);
609 smbcli_unlink(cli->tree, fname2);
611 /* check the basic return fields */
612 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
613 io.t2open.in.write_time = 0;
614 io.t2open.in.fname = fname;
615 status = smb_raw_open(cli->tree, tctx, &io);
616 CHECK_STATUS(status, NT_STATUS_OK);
617 fnum = io.t2open.out.file.fnum;
619 CHECK_ALL_INFO(io.t2open.out.size, size);
621 /* windows appears to leak uninitialised memory here */
622 CHECK_VAL(io.t2open.out.write_time, 0);
624 CHECK_ALL_INFO(io.t2open.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
625 CHECK_VAL(io.t2open.out.access, OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR);
626 CHECK_VAL(io.t2open.out.ftype, 0);
627 CHECK_VAL(io.t2open.out.devstate, 0);
628 CHECK_VAL(io.t2open.out.action, OPENX_ACTION_CREATED);
629 smbcli_close(cli->tree, fnum);
631 status = torture_check_ea(cli, fname, ".CLASSINFO", "first value");
632 CHECK_STATUS(status, io.t2open.in.num_eas
633 ? NT_STATUS_OK : NT_STATUS_EAS_NOT_SUPPORTED);
634 status = torture_check_ea(cli, fname, "EA TWO", "foo");
635 CHECK_STATUS(status, io.t2open.in.num_eas
636 ? NT_STATUS_OK : NT_STATUS_EAS_NOT_SUPPORTED);
637 status = torture_check_ea(cli, fname, "X THIRD", "xy");
638 CHECK_STATUS(status, io.t2open.in.num_eas
639 ? NT_STATUS_OK : NT_STATUS_EAS_NOT_SUPPORTED);
641 /* now check the search attrib for hidden files - win2003 ignores this? */
642 SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN);
643 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib);
645 status = smb_raw_open(cli->tree, tctx, &io);
646 CHECK_STATUS(status, NT_STATUS_OK);
647 smbcli_close(cli->tree, io.t2open.out.file.fnum);
649 status = smb_raw_open(cli->tree, tctx, &io);
650 CHECK_STATUS(status, NT_STATUS_OK);
651 smbcli_close(cli->tree, io.t2open.out.file.fnum);
653 SET_ATTRIB(FILE_ATTRIBUTE_NORMAL);
654 smbcli_unlink(cli->tree, fname);
656 /* and check attrib on create */
657 io.t2open.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE;
658 io.t2open.in.file_attrs = FILE_ATTRIBUTE_SYSTEM;
659 status = smb_raw_open(cli->tree, tctx, &io);
660 CHECK_STATUS(status, NT_STATUS_OK);
662 /* check timeout on create - win2003 ignores the timeout! */
663 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
664 io.t2open.in.file_attrs = 0;
665 io.t2open.in.timeout = 20000;
666 io.t2open.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL;
667 status = smb_raw_open(cli->tree, tctx, &io);
668 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
671 smbcli_close(cli->tree, fnum);
672 smbcli_unlink(cli->tree, fname);
679 test RAW_OPEN_NTCREATEX
681 static bool test_ntcreatex(struct smbcli_state *cli, struct torture_context *tctx)
684 union smb_fileinfo finfo;
685 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
686 const char *dname = BASEDIR "\\torture_ntcreatex.dir";
694 NTSTATUS correct_status;
696 { NTCREATEX_DISP_SUPERSEDE, true, NT_STATUS_OK },
697 { NTCREATEX_DISP_SUPERSEDE, false, NT_STATUS_OK },
698 { NTCREATEX_DISP_OPEN, true, NT_STATUS_OK },
699 { NTCREATEX_DISP_OPEN, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
700 { NTCREATEX_DISP_CREATE, true, NT_STATUS_OBJECT_NAME_COLLISION },
701 { NTCREATEX_DISP_CREATE, false, NT_STATUS_OK },
702 { NTCREATEX_DISP_OPEN_IF, true, NT_STATUS_OK },
703 { NTCREATEX_DISP_OPEN_IF, false, NT_STATUS_OK },
704 { NTCREATEX_DISP_OVERWRITE, true, NT_STATUS_OK },
705 { NTCREATEX_DISP_OVERWRITE, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
706 { NTCREATEX_DISP_OVERWRITE_IF, true, NT_STATUS_OK },
707 { NTCREATEX_DISP_OVERWRITE_IF, false, NT_STATUS_OK },
708 { 6, true, NT_STATUS_INVALID_PARAMETER },
709 { 6, false, NT_STATUS_INVALID_PARAMETER },
712 torture_comment(tctx, "Checking RAW_OPEN_NTCREATEX\n");
714 /* reasonable default parameters */
715 io.generic.level = RAW_OPEN_NTCREATEX;
716 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
717 io.ntcreatex.in.root_fid.fnum = 0;
718 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
719 io.ntcreatex.in.alloc_size = 1024*1024;
720 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
721 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
722 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
723 io.ntcreatex.in.create_options = 0;
724 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
725 io.ntcreatex.in.security_flags = 0;
726 io.ntcreatex.in.fname = fname;
728 /* test the open disposition */
729 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
730 if (open_funcs[i].with_file) {
731 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE);
733 torture_result(tctx, TORTURE_FAIL,
734 "Failed to create file %s - %s\n",
735 fname, smbcli_errstr(cli->tree));
739 smbcli_close(cli->tree, fnum);
741 io.ntcreatex.in.open_disposition = open_funcs[i].open_disp;
742 status = smb_raw_open(cli->tree, tctx, &io);
743 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
744 torture_result(tctx, TORTURE_FAIL,
745 "(%s) incorrect status %s should be %s "
746 "(i=%d with_file=%d open_disp=%d)\n",
747 __location__, nt_errstr(status),
748 nt_errstr(open_funcs[i].correct_status),
749 i, (int)open_funcs[i].with_file,
750 (int)open_funcs[i].open_disp);
753 if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
754 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
755 smbcli_unlink(cli->tree, fname);
759 /* basic field testing */
760 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
762 status = smb_raw_open(cli->tree, tctx, &io);
763 CHECK_STATUS(status, NT_STATUS_OK);
764 fnum = io.ntcreatex.out.file.fnum;
766 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
767 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
768 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
769 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
770 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
771 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
772 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
773 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
774 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
775 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
776 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
778 /* check fields when the file already existed */
779 smbcli_close(cli->tree, fnum);
780 smbcli_unlink(cli->tree, fname);
781 fnum = create_complex_file(cli, tctx, fname);
786 smbcli_close(cli->tree, fnum);
788 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
789 status = smb_raw_open(cli->tree, tctx, &io);
790 CHECK_STATUS(status, NT_STATUS_OK);
791 fnum = io.ntcreatex.out.file.fnum;
793 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
794 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
795 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
796 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
797 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
798 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
799 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
800 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
801 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
802 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
803 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
804 smbcli_close(cli->tree, fnum);
805 smbcli_unlink(cli->tree, fname);
808 /* create a directory */
809 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
810 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
811 io.ntcreatex.in.alloc_size = 0;
812 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
813 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
814 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
815 io.ntcreatex.in.create_options = 0;
816 io.ntcreatex.in.fname = dname;
819 smbcli_rmdir(cli->tree, fname);
820 smbcli_unlink(cli->tree, fname);
822 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
823 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
824 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
825 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
826 status = smb_raw_open(cli->tree, tctx, &io);
827 CHECK_STATUS(status, NT_STATUS_OK);
828 fnum = io.ntcreatex.out.file.fnum;
830 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
831 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
832 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
833 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
834 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
835 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
836 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
837 CHECK_VAL(io.ntcreatex.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED,
838 FILE_ATTRIBUTE_DIRECTORY);
839 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
840 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
841 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
842 CHECK_VAL(io.ntcreatex.out.is_directory, 1);
843 CHECK_VAL(io.ntcreatex.out.size, 0);
844 CHECK_VAL(io.ntcreatex.out.alloc_size, 0);
845 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
846 smbcli_unlink(cli->tree, fname);
850 smbcli_close(cli->tree, fnum);
851 smbcli_unlink(cli->tree, fname);
858 test RAW_OPEN_NTTRANS_CREATE
860 static bool test_nttrans_create(struct smbcli_state *cli, struct torture_context *tctx)
863 union smb_fileinfo finfo;
864 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
865 const char *dname = BASEDIR "\\torture_ntcreatex.dir";
870 uint32_t ok_mask, not_supported_mask, invalid_parameter_mask;
871 uint32_t not_a_directory_mask, unexpected_mask;
875 NTSTATUS correct_status;
877 { NTCREATEX_DISP_SUPERSEDE, true, NT_STATUS_OK },
878 { NTCREATEX_DISP_SUPERSEDE, false, NT_STATUS_OK },
879 { NTCREATEX_DISP_OPEN, true, NT_STATUS_OK },
880 { NTCREATEX_DISP_OPEN, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
881 { NTCREATEX_DISP_CREATE, true, NT_STATUS_OBJECT_NAME_COLLISION },
882 { NTCREATEX_DISP_CREATE, false, NT_STATUS_OK },
883 { NTCREATEX_DISP_OPEN_IF, true, NT_STATUS_OK },
884 { NTCREATEX_DISP_OPEN_IF, false, NT_STATUS_OK },
885 { NTCREATEX_DISP_OVERWRITE, true, NT_STATUS_OK },
886 { NTCREATEX_DISP_OVERWRITE, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
887 { NTCREATEX_DISP_OVERWRITE_IF, true, NT_STATUS_OK },
888 { NTCREATEX_DISP_OVERWRITE_IF, false, NT_STATUS_OK },
889 { 6, true, NT_STATUS_INVALID_PARAMETER },
890 { 6, false, NT_STATUS_INVALID_PARAMETER },
893 torture_comment(tctx, "Checking RAW_OPEN_NTTRANS_CREATE\n");
895 /* reasonable default parameters */
896 io.generic.level = RAW_OPEN_NTTRANS_CREATE;
897 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
898 io.ntcreatex.in.root_fid.fnum = 0;
899 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
900 io.ntcreatex.in.alloc_size = 1024*1024;
901 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
902 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
903 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
904 io.ntcreatex.in.create_options = 0;
905 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
906 io.ntcreatex.in.security_flags = 0;
907 io.ntcreatex.in.fname = fname;
908 io.ntcreatex.in.sec_desc = NULL;
909 io.ntcreatex.in.ea_list = NULL;
911 /* test the open disposition */
912 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
913 if (open_funcs[i].with_file) {
914 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE);
916 torture_result(tctx, TORTURE_FAIL,
917 "Failed to create file %s - %s\n",
918 fname, smbcli_errstr(cli->tree));
922 smbcli_close(cli->tree, fnum);
924 io.ntcreatex.in.open_disposition = open_funcs[i].open_disp;
925 status = smb_raw_open(cli->tree, tctx, &io);
926 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
927 torture_result(tctx, TORTURE_FAIL,
928 "(%s) incorrect status %s should be %s "
929 "(i=%d with_file=%d open_disp=%d)\n",
930 __location__, nt_errstr(status),
931 nt_errstr(open_funcs[i].correct_status),
932 i, (int)open_funcs[i].with_file,
933 (int)open_funcs[i].open_disp);
936 if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
937 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
938 smbcli_unlink(cli->tree, fname);
942 /* basic field testing */
943 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
945 status = smb_raw_open(cli->tree, tctx, &io);
946 CHECK_STATUS(status, NT_STATUS_OK);
947 fnum = io.ntcreatex.out.file.fnum;
949 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
950 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
951 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
952 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
953 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
954 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
955 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
956 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
957 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
958 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
959 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
961 /* check fields when the file already existed */
962 smbcli_close(cli->tree, fnum);
963 smbcli_unlink(cli->tree, fname);
964 fnum = create_complex_file(cli, tctx, fname);
969 smbcli_close(cli->tree, fnum);
971 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
972 status = smb_raw_open(cli->tree, tctx, &io);
973 CHECK_STATUS(status, NT_STATUS_OK);
974 fnum = io.ntcreatex.out.file.fnum;
976 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
977 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
978 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
979 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
980 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
981 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
982 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
983 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
984 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
985 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
986 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
987 smbcli_close(cli->tree, fnum);
989 /* check no-recall - don't pull a file from tape on a HSM */
990 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_NO_RECALL;
991 status = smb_raw_open(cli->tree, tctx, &io);
992 CHECK_STATUS(status, NT_STATUS_OK);
993 fnum = io.ntcreatex.out.file.fnum;
995 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
996 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
997 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
998 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
999 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
1000 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
1001 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
1002 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
1003 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
1004 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
1005 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
1006 smbcli_close(cli->tree, fnum);
1008 /* Check some create options (these all should be ignored) */
1009 for (i=0; i < 32; i++) {
1010 uint32_t create_option = (1 << i) & NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
1011 if (create_option == 0) {
1014 io.ntcreatex.in.create_options = create_option;
1015 status = smb_raw_open(cli->tree, tctx, &io);
1016 if (!NT_STATUS_IS_OK(status)) {
1017 torture_warning(tctx, "ntcreatex create option 0x%08x "
1018 "gave %s - should give NT_STATUS_OK\n",
1019 create_option, nt_errstr(status));
1021 CHECK_STATUS(status, NT_STATUS_OK);
1022 fnum = io.ntcreatex.out.file.fnum;
1024 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
1025 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
1026 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
1027 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
1028 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
1029 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
1030 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
1031 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
1032 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
1033 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
1034 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
1035 smbcli_close(cli->tree, fnum);
1038 io.ntcreatex.in.file_attr = 0;
1039 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
1040 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1042 /* Check for options that should return NOT_SUPPORTED, OK or INVALID_PARAMETER */
1044 not_supported_mask = 0;
1045 invalid_parameter_mask = 0;
1046 not_a_directory_mask = 0;
1047 unexpected_mask = 0;
1048 for (i=0; i < 32; i++) {
1049 uint32_t create_option = 1<<i;
1050 if (create_option & NTCREATEX_OPTIONS_DELETE_ON_CLOSE) {
1053 io.ntcreatex.in.create_options = create_option;
1054 status = smb_raw_open(cli->tree, tctx, &io);
1055 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
1056 not_supported_mask |= create_option;
1057 } else if (NT_STATUS_EQUAL(status, NT_STATUS_OK)) {
1058 ok_mask |= create_option;
1059 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
1060 } else if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
1061 invalid_parameter_mask |= create_option;
1062 } else if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_A_DIRECTORY)) {
1063 not_a_directory_mask |= 1<<i;
1065 unexpected_mask |= 1<<i;
1066 torture_comment(tctx, "create option 0x%08x returned %s\n",
1067 create_option, nt_errstr(status));
1071 CHECK_VAL(ok_mask, 0x00efcfce);
1072 CHECK_VAL(not_a_directory_mask, 0x00000001);
1073 CHECK_VAL(not_supported_mask, 0x00002000);
1074 CHECK_VAL(invalid_parameter_mask, 0xff100030);
1075 CHECK_VAL(unexpected_mask, 0x00000000);
1077 smbcli_unlink(cli->tree, fname);
1080 /* create a directory */
1081 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1082 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
1083 io.ntcreatex.in.alloc_size = 0;
1084 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
1085 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
1086 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1087 io.ntcreatex.in.create_options = 0;
1088 io.ntcreatex.in.fname = dname;
1091 smbcli_rmdir(cli->tree, fname);
1092 smbcli_unlink(cli->tree, fname);
1094 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1095 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1096 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1097 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1098 status = smb_raw_open(cli->tree, tctx, &io);
1099 CHECK_STATUS(status, NT_STATUS_OK);
1100 fnum = io.ntcreatex.out.file.fnum;
1102 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
1103 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
1104 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
1105 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
1106 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
1107 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
1108 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
1109 CHECK_VAL(io.ntcreatex.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED,
1110 FILE_ATTRIBUTE_DIRECTORY);
1111 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
1112 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
1113 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
1114 CHECK_VAL(io.ntcreatex.out.is_directory, 1);
1115 CHECK_VAL(io.ntcreatex.out.size, 0);
1116 CHECK_VAL(io.ntcreatex.out.alloc_size, 0);
1117 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
1118 smbcli_unlink(cli->tree, fname);
1122 smbcli_close(cli->tree, fnum);
1123 smbcli_unlink(cli->tree, fname);
1129 test RAW_OPEN_NTCREATEX with an already opened and byte range locked file
1131 I've got an application that does a similar sequence of ntcreate&x,
1132 locking&x and another ntcreate&x with
1133 open_disposition==NTCREATEX_DISP_OVERWRITE_IF. Windows 2003 allows the
1136 static bool test_ntcreatex_brlocked(struct smbcli_state *cli, struct torture_context *tctx)
1138 union smb_open io, io1;
1140 struct smb_lock_entry lock[1];
1141 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
1145 torture_comment(tctx, "Testing ntcreatex with a byte range locked file\n");
1147 io.generic.level = RAW_OPEN_NTCREATEX;
1148 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
1149 io.ntcreatex.in.root_fid.fnum = 0;
1150 io.ntcreatex.in.access_mask = 0x2019f;
1151 io.ntcreatex.in.alloc_size = 0;
1152 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1153 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1154 NTCREATEX_SHARE_ACCESS_WRITE;
1155 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1156 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
1157 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
1158 io.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC |
1159 NTCREATEX_SECURITY_ALL;
1160 io.ntcreatex.in.fname = fname;
1162 status = smb_raw_open(cli->tree, tctx, &io);
1163 CHECK_STATUS(status, NT_STATUS_OK);
1165 io2.lockx.level = RAW_LOCK_LOCKX;
1166 io2.lockx.in.file.fnum = io.ntcreatex.out.file.fnum;
1167 io2.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
1168 io2.lockx.in.timeout = 0;
1169 io2.lockx.in.ulock_cnt = 0;
1170 io2.lockx.in.lock_cnt = 1;
1171 lock[0].pid = cli->session->pid;
1173 lock[0].count = 0x1;
1174 io2.lockx.in.locks = &lock[0];
1175 status = smb_raw_lock(cli->tree, &io2);
1176 CHECK_STATUS(status, NT_STATUS_OK);
1178 io1.generic.level = RAW_OPEN_NTCREATEX;
1179 io1.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
1180 io1.ntcreatex.in.root_fid.fnum = 0;
1181 io1.ntcreatex.in.access_mask = 0x20196;
1182 io1.ntcreatex.in.alloc_size = 0;
1183 io1.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1184 io1.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1185 NTCREATEX_SHARE_ACCESS_WRITE;
1186 io1.ntcreatex.in.open_disposition = NTCREATEX_DISP_OVERWRITE_IF;
1187 io1.ntcreatex.in.create_options = 0;
1188 io1.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
1189 io1.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC |
1190 NTCREATEX_SECURITY_ALL;
1191 io1.ntcreatex.in.fname = fname;
1193 status = smb_raw_open(cli->tree, tctx, &io1);
1194 CHECK_STATUS(status, NT_STATUS_OK);
1197 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
1198 smbcli_close(cli->tree, io1.ntcreatex.out.file.fnum);
1199 smbcli_unlink(cli->tree, fname);
1206 static bool test_mknew(struct smbcli_state *cli, struct torture_context *tctx)
1209 const char *fname = BASEDIR "\\torture_mknew.txt";
1213 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1214 union smb_fileinfo finfo;
1216 torture_comment(tctx, "Checking RAW_OPEN_MKNEW\n");
1218 io.mknew.level = RAW_OPEN_MKNEW;
1219 io.mknew.in.attrib = 0;
1220 io.mknew.in.write_time = 0;
1221 io.mknew.in.fname = fname;
1222 status = smb_raw_open(cli->tree, tctx, &io);
1223 CHECK_STATUS(status, NT_STATUS_OK);
1224 fnum = io.mknew.out.file.fnum;
1226 status = smb_raw_open(cli->tree, tctx, &io);
1227 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
1229 smbcli_close(cli->tree, fnum);
1230 smbcli_unlink(cli->tree, fname);
1232 /* make sure write_time works */
1233 io.mknew.in.write_time = basetime;
1234 status = smb_raw_open(cli->tree, tctx, &io);
1235 CHECK_STATUS(status, NT_STATUS_OK);
1236 fnum = io.mknew.out.file.fnum;
1237 CHECK_TIME(basetime, write_time);
1239 smbcli_close(cli->tree, fnum);
1240 smbcli_unlink(cli->tree, fname);
1242 /* make sure file_attrs works */
1243 io.mknew.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1244 status = smb_raw_open(cli->tree, tctx, &io);
1245 CHECK_STATUS(status, NT_STATUS_OK);
1246 fnum = io.mknew.out.file.fnum;
1247 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE,
1248 attrib & ~FILE_ATTRIBUTE_NONINDEXED);
1251 smbcli_close(cli->tree, fnum);
1252 smbcli_unlink(cli->tree, fname);
1259 test RAW_OPEN_CREATE
1261 static bool test_create(struct smbcli_state *cli, struct torture_context *tctx)
1264 const char *fname = BASEDIR "\\torture_create.txt";
1268 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1269 union smb_fileinfo finfo;
1271 torture_comment(tctx, "Checking RAW_OPEN_CREATE\n");
1273 io.create.level = RAW_OPEN_CREATE;
1274 io.create.in.attrib = 0;
1275 io.create.in.write_time = 0;
1276 io.create.in.fname = fname;
1277 status = smb_raw_open(cli->tree, tctx, &io);
1278 CHECK_STATUS(status, NT_STATUS_OK);
1279 fnum = io.create.out.file.fnum;
1281 status = smb_raw_open(cli->tree, tctx, &io);
1282 CHECK_STATUS(status, NT_STATUS_OK);
1284 smbcli_close(cli->tree, io.create.out.file.fnum);
1285 smbcli_close(cli->tree, fnum);
1286 smbcli_unlink(cli->tree, fname);
1288 /* make sure write_time works */
1289 io.create.in.write_time = basetime;
1290 status = smb_raw_open(cli->tree, tctx, &io);
1291 CHECK_STATUS(status, NT_STATUS_OK);
1292 fnum = io.create.out.file.fnum;
1293 CHECK_TIME(basetime, write_time);
1295 smbcli_close(cli->tree, fnum);
1296 smbcli_unlink(cli->tree, fname);
1298 /* make sure file_attrs works */
1299 io.create.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1300 status = smb_raw_open(cli->tree, tctx, &io);
1301 CHECK_STATUS(status, NT_STATUS_OK);
1302 fnum = io.create.out.file.fnum;
1303 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE,
1304 attrib & ~FILE_ATTRIBUTE_NONINDEXED);
1307 smbcli_close(cli->tree, fnum);
1308 smbcli_unlink(cli->tree, fname);
1317 static bool test_ctemp(struct smbcli_state *cli, TALLOC_CTX *tctx)
1323 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1324 union smb_fileinfo finfo;
1325 const char *name, *fname = NULL;
1327 torture_comment(tctx, "Checking RAW_OPEN_CTEMP\n");
1329 io.ctemp.level = RAW_OPEN_CTEMP;
1330 io.ctemp.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1331 io.ctemp.in.write_time = basetime;
1332 io.ctemp.in.directory = BASEDIR;
1333 status = smb_raw_open(cli->tree, tctx, &io);
1334 CHECK_STATUS(status, NT_STATUS_OK);
1335 fnum = io.ctemp.out.file.fnum;
1337 name = io.ctemp.out.name;
1339 finfo.generic.level = RAW_FILEINFO_NAME_INFO;
1340 finfo.generic.in.file.fnum = fnum;
1341 status = smb_raw_fileinfo(cli->tree, tctx, &finfo);
1342 CHECK_STATUS(status, NT_STATUS_OK);
1344 fname = finfo.name_info.out.fname.s;
1345 torture_comment(tctx, "ctemp name=%s real name=%s\n", name, fname);
1348 smbcli_close(cli->tree, fnum);
1350 smbcli_unlink(cli->tree, fname);
1358 test chained RAW_OPEN_OPENX_READX
1360 static bool test_chained(struct smbcli_state *cli, TALLOC_CTX *tctx)
1363 const char *fname = BASEDIR "\\torture_chained.txt";
1367 const char *buf = "test";
1370 torture_comment(tctx, "Checking RAW_OPEN_OPENX chained with READX\n");
1371 smbcli_unlink(cli->tree, fname);
1373 fnum = create_complex_file(cli, tctx, fname);
1375 smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf));
1377 smbcli_close(cli->tree, fnum);
1379 io.openxreadx.level = RAW_OPEN_OPENX_READX;
1380 io.openxreadx.in.fname = fname;
1381 io.openxreadx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
1382 io.openxreadx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
1383 io.openxreadx.in.open_func = OPENX_OPEN_FUNC_OPEN;
1384 io.openxreadx.in.search_attrs = 0;
1385 io.openxreadx.in.file_attrs = 0;
1386 io.openxreadx.in.write_time = 0;
1387 io.openxreadx.in.size = 1024*1024;
1388 io.openxreadx.in.timeout = 0;
1390 io.openxreadx.in.offset = 0;
1391 io.openxreadx.in.mincnt = sizeof(buf);
1392 io.openxreadx.in.maxcnt = sizeof(buf);
1393 io.openxreadx.in.remaining = 0;
1394 io.openxreadx.out.data = (uint8_t *)buf2;
1396 status = smb_raw_open(cli->tree, tctx, &io);
1397 CHECK_STATUS(status, NT_STATUS_OK);
1398 fnum = io.openxreadx.out.file.fnum;
1400 if (memcmp(buf, buf2, sizeof(buf)) != 0) {
1401 torture_result(tctx, TORTURE_FAIL,
1402 "wrong data in reply buffer\n");
1407 smbcli_close(cli->tree, fnum);
1408 smbcli_unlink(cli->tree, fname);
1414 test RAW_OPEN_OPENX without a leading slash on the path.
1415 NetApp filers are known to fail on this.
1418 static bool test_no_leading_slash(struct smbcli_state *cli, TALLOC_CTX *tctx)
1421 const char *fname = BASEDIR "\\torture_no_leading_slash.txt";
1425 const char *buf = "test";
1427 torture_comment(tctx, "Checking RAW_OPEN_OPENX without leading "
1429 smbcli_unlink(cli->tree, fname);
1431 /* Create the file */
1432 fnum = create_complex_file(cli, tctx, fname);
1433 smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf));
1434 smbcli_close(cli->tree, fnum);
1436 /* Prepare to open the file using path without leading slash */
1437 io.openx.level = RAW_OPEN_OPENX;
1438 io.openx.in.fname = fname + 1;
1439 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
1440 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
1441 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
1442 io.openx.in.search_attrs = 0;
1443 io.openx.in.file_attrs = 0;
1444 io.openx.in.write_time = 0;
1445 io.openx.in.size = 1024*1024;
1446 io.openx.in.timeout = 0;
1448 status = smb_raw_open(cli->tree, tctx, &io);
1449 CHECK_STATUS(status, NT_STATUS_OK);
1450 fnum = io.openx.out.file.fnum;
1453 smbcli_close(cli->tree, fnum);
1454 smbcli_unlink(cli->tree, fname);
1460 test RAW_OPEN_OPENX against an existing directory to
1461 ensure it returns NT_STATUS_FILE_IS_A_DIRECTORY.
1462 Samba 3.2.0 - 3.2.6 are known to fail this.
1465 static bool test_openx_over_dir(struct smbcli_state *cli, TALLOC_CTX *tctx)
1468 const char *fname = BASEDIR "\\openx_over_dir";
1474 torture_comment(tctx, "Checking RAW_OPEN_OPENX over an existing directory\n");
1475 smbcli_unlink(cli->tree, fname);
1477 /* Create the Directory */
1478 status = create_directory_handle(cli->tree, fname, &d_fnum);
1479 smbcli_close(cli->tree, d_fnum);
1481 /* Prepare to open the file over the directory. */
1482 io.openx.level = RAW_OPEN_OPENX;
1483 io.openx.in.fname = fname;
1484 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
1485 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
1486 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
1487 io.openx.in.search_attrs = 0;
1488 io.openx.in.file_attrs = 0;
1489 io.openx.in.write_time = 0;
1490 io.openx.in.size = 1024*1024;
1491 io.openx.in.timeout = 0;
1493 status = smb_raw_open(cli->tree, tctx, &io);
1494 CHECK_STATUS(status, NT_STATUS_FILE_IS_A_DIRECTORY);
1495 fnum = io.openx.out.file.fnum;
1498 smbcli_close(cli->tree, fnum);
1499 smbcli_unlink(cli->tree, fname);
1505 /* A little torture test to expose a race condition in Samba 3.0.20 ... :-) */
1507 static bool test_raw_open_multi(struct torture_context *tctx)
1509 struct smbcli_state *cli;
1510 TALLOC_CTX *mem_ctx = talloc_init("torture_test_oplock_multi");
1511 const char *fname = "\\test_oplock.dat";
1515 struct smbcli_state **clients;
1516 struct smbcli_request **requests;
1517 union smb_open *ios;
1518 const char *host = torture_setting_string(tctx, "host", NULL);
1519 const char *share = torture_setting_string(tctx, "share", NULL);
1520 int i, num_files = 3;
1522 int num_collision = 0;
1524 clients = talloc_array(mem_ctx, struct smbcli_state *, num_files);
1525 requests = talloc_array(mem_ctx, struct smbcli_request *, num_files);
1526 ios = talloc_array(mem_ctx, union smb_open, num_files);
1527 if ((tctx->ev == NULL) || (clients == NULL) || (requests == NULL) ||
1529 torture_result(tctx, TORTURE_FAIL, "(%s): talloc failed\n",
1534 if (!torture_open_connection_share(mem_ctx, &cli, tctx, host, share, tctx->ev)) {
1538 cli->tree->session->transport->options.request_timeout = 60;
1540 for (i=0; i<num_files; i++) {
1541 if (!torture_open_connection_share(mem_ctx, &(clients[i]),
1542 tctx, host, share, tctx->ev)) {
1543 torture_result(tctx, TORTURE_FAIL,
1544 "(%s): Could not open %d'th connection\n",
1548 clients[i]->tree->session->transport->options.request_timeout = 60;
1552 smbcli_unlink(cli->tree, fname);
1555 base ntcreatex parms
1557 io.generic.level = RAW_OPEN_NTCREATEX;
1558 io.ntcreatex.in.root_fid.fnum = 0;
1559 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
1560 io.ntcreatex.in.alloc_size = 0;
1561 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1562 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ|
1563 NTCREATEX_SHARE_ACCESS_WRITE|
1564 NTCREATEX_SHARE_ACCESS_DELETE;
1565 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1566 io.ntcreatex.in.create_options = 0;
1567 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1568 io.ntcreatex.in.security_flags = 0;
1569 io.ntcreatex.in.fname = fname;
1570 io.ntcreatex.in.flags = 0;
1572 for (i=0; i<num_files; i++) {
1574 requests[i] = smb_raw_open_send(clients[i]->tree, &ios[i]);
1575 if (requests[i] == NULL) {
1576 torture_result(tctx, TORTURE_FAIL,
1577 "(%s): could not send %d'th request\n",
1583 torture_comment(tctx, "waiting for replies\n");
1585 bool unreplied = false;
1586 for (i=0; i<num_files; i++) {
1587 if (requests[i] == NULL) {
1590 if (requests[i]->state < SMBCLI_REQUEST_DONE) {
1594 status = smb_raw_open_recv(requests[i], mem_ctx,
1597 torture_comment(tctx, "File %d returned status %s\n", i,
1600 if (NT_STATUS_IS_OK(status)) {
1604 if (NT_STATUS_EQUAL(status,
1605 NT_STATUS_OBJECT_NAME_COLLISION)) {
1615 if (event_loop_once(tctx->ev) != 0) {
1616 torture_result(tctx, TORTURE_FAIL,
1617 "(%s): event_loop_once failed\n", __location__);
1622 if ((num_ok != 1) || (num_ok + num_collision != num_files)) {
1626 for (i=0; i<num_files; i++) {
1627 torture_close_connection(clients[i]);
1629 talloc_free(mem_ctx);
1634 test opening for delete on a read-only attribute file.
1636 static bool test_open_for_delete(struct smbcli_state *cli, struct torture_context *tctx)
1639 union smb_fileinfo finfo;
1640 const char *fname = BASEDIR "\\torture_open_for_delete.txt";
1645 torture_comment(tctx, "Checking RAW_NTCREATEX for delete on a readonly file.\n");
1647 /* reasonable default parameters */
1648 io.generic.level = RAW_OPEN_NTCREATEX;
1649 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
1650 io.ntcreatex.in.root_fid.fnum = 0;
1651 io.ntcreatex.in.alloc_size = 0;
1652 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
1653 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_READONLY;
1654 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
1655 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1656 io.ntcreatex.in.create_options = 0;
1657 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1658 io.ntcreatex.in.security_flags = 0;
1659 io.ntcreatex.in.fname = fname;
1661 /* Create the readonly file. */
1663 status = smb_raw_open(cli->tree, tctx, &io);
1664 CHECK_STATUS(status, NT_STATUS_OK);
1665 fnum = io.ntcreatex.out.file.fnum;
1667 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
1668 io.ntcreatex.in.create_options = 0;
1669 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
1670 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
1671 smbcli_close(cli->tree, fnum);
1673 /* Now try and open for delete only - should succeed. */
1674 io.ntcreatex.in.access_mask = SEC_STD_DELETE;
1675 io.ntcreatex.in.file_attr = 0;
1676 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
1677 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1678 status = smb_raw_open(cli->tree, tctx, &io);
1679 CHECK_STATUS(status, NT_STATUS_OK);
1681 smbcli_unlink(cli->tree, fname);
1684 smbcli_close(cli->tree, fnum);
1685 smbcli_unlink(cli->tree, fname);
1691 test chained RAW_OPEN_NTCREATEX_READX
1692 Send chained NTCREATEX_READX on a file that doesn't exist, then create
1693 the file and try again.
1695 static bool test_chained_ntcreatex_readx(struct smbcli_state *cli, struct torture_context *tctx)
1697 TALLOC_CTX *mem_ctx = talloc_new(tctx);
1699 const char *fname = BASEDIR "\\torture_chained.txt";
1703 const char *buf = "test";
1706 torture_comment(tctx, "Checking RAW_NTCREATEX_READX chained on "
1707 "non-existant file \n");
1708 smbcli_unlink(cli->tree, fname);
1710 /* ntcreatex parameters */
1711 io.generic.level = RAW_OPEN_NTCREATEX_READX;
1712 io.ntcreatexreadx.in.flags = 0;
1713 io.ntcreatexreadx.in.root_fid.fnum = 0;
1714 io.ntcreatexreadx.in.access_mask = SEC_FILE_READ_DATA;
1715 io.ntcreatexreadx.in.alloc_size = 0;
1716 io.ntcreatexreadx.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1717 io.ntcreatexreadx.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1718 NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
1719 io.ntcreatexreadx.in.open_disposition = NTCREATEX_DISP_OPEN;
1720 io.ntcreatexreadx.in.create_options = 0;
1721 io.ntcreatexreadx.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
1722 io.ntcreatexreadx.in.security_flags = 0;
1723 io.ntcreatexreadx.in.fname = fname;
1725 /* readx parameters */
1726 io.ntcreatexreadx.in.offset = 0;
1727 io.ntcreatexreadx.in.mincnt = sizeof(buf);
1728 io.ntcreatexreadx.in.maxcnt = sizeof(buf);
1729 io.ntcreatexreadx.in.remaining = 0;
1730 io.ntcreatexreadx.out.data = (uint8_t *)buf2;
1732 /* try to open the non-existant file */
1733 status = smb_raw_open(cli->tree, mem_ctx, &io);
1734 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
1735 fnum = io.ntcreatexreadx.out.file.fnum;
1737 smbcli_close(cli->tree, fnum);
1738 smbcli_unlink(cli->tree, fname);
1740 torture_comment(tctx, "Checking RAW_NTCREATEX_READX chained on "
1741 "existing file \n");
1743 fnum = create_complex_file(cli, mem_ctx, fname);
1744 smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf));
1745 smbcli_close(cli->tree, fnum);
1747 status = smb_raw_open(cli->tree, mem_ctx, &io);
1748 CHECK_STATUS(status, NT_STATUS_OK);
1749 fnum = io.ntcreatexreadx.out.file.fnum;
1751 if (memcmp(buf, buf2, sizeof(buf)) != 0) {
1752 torture_result(tctx, TORTURE_FAIL,
1753 "(%s): wrong data in reply buffer\n", __location__);
1758 smbcli_close(cli->tree, fnum);
1759 smbcli_unlink(cli->tree, fname);
1760 talloc_free(mem_ctx);
1765 #define FILL_NTCREATEX(_struct, _init...) \
1767 (_struct)->generic.level = RAW_OPEN_NTCREATEX; \
1768 (_struct)->ntcreatex.in \
1769 = (typeof((_struct)->ntcreatex.in)) {_init};\
1772 static bool test_ntcreatex_opendisp_dir(struct smbcli_state *cli,
1773 struct torture_context *tctx)
1776 const char *dname = BASEDIR "\\torture_ntcreatex_opendisp_dir";
1783 NTSTATUS correct_status;
1784 } open_funcs_dir[] = {
1785 { NTCREATEX_DISP_SUPERSEDE, true, NT_STATUS_INVALID_PARAMETER },
1786 { NTCREATEX_DISP_SUPERSEDE, false, NT_STATUS_INVALID_PARAMETER },
1787 { NTCREATEX_DISP_OPEN, true, NT_STATUS_OK },
1788 { NTCREATEX_DISP_OPEN, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
1789 { NTCREATEX_DISP_CREATE, true, NT_STATUS_OBJECT_NAME_COLLISION },
1790 { NTCREATEX_DISP_CREATE, false, NT_STATUS_OK },
1791 { NTCREATEX_DISP_OPEN_IF, true, NT_STATUS_OK },
1792 { NTCREATEX_DISP_OPEN_IF, false, NT_STATUS_OK },
1793 { NTCREATEX_DISP_OVERWRITE, true, NT_STATUS_INVALID_PARAMETER },
1794 { NTCREATEX_DISP_OVERWRITE, false, NT_STATUS_INVALID_PARAMETER },
1795 { NTCREATEX_DISP_OVERWRITE_IF, true, NT_STATUS_INVALID_PARAMETER },
1796 { NTCREATEX_DISP_OVERWRITE_IF, false, NT_STATUS_INVALID_PARAMETER },
1797 { 6, true, NT_STATUS_INVALID_PARAMETER },
1798 { 6, false, NT_STATUS_INVALID_PARAMETER },
1801 if (!torture_setup_dir(cli, BASEDIR)) {
1806 .flags = NTCREATEX_FLAGS_EXTENDED,
1807 .access_mask = SEC_FLAG_MAXIMUM_ALLOWED,
1808 .file_attr = FILE_ATTRIBUTE_DIRECTORY,
1809 .share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE,
1810 .create_options = NTCREATEX_OPTIONS_DIRECTORY,
1814 smbcli_rmdir(cli->tree, dname);
1815 smbcli_unlink(cli->tree, dname);
1817 /* test the open disposition for directories */
1818 torture_comment(tctx, "Testing open dispositions for directories...\n");
1820 for (i=0; i<ARRAY_SIZE(open_funcs_dir); i++) {
1821 if (open_funcs_dir[i].dir_exists) {
1822 status = smbcli_mkdir(cli->tree, dname);
1823 if (!NT_STATUS_IS_OK(status)) {
1824 torture_result(tctx, TORTURE_FAIL,
1825 "(%s): Failed to make directory "
1826 "%s - %s\n", __location__, dname,
1827 smbcli_errstr(cli->tree));
1833 io.ntcreatex.in.open_disposition = open_funcs_dir[i].open_disp;
1834 status = smb_raw_open(cli->tree, tctx, &io);
1835 if (!NT_STATUS_EQUAL(status, open_funcs_dir[i].correct_status)) {
1836 torture_result(tctx, TORTURE_FAIL,
1837 "(%s) incorrect status %s should be %s "
1838 "(i=%d dir_exists=%d open_disp=%d)\n",
1839 __location__, nt_errstr(status),
1840 nt_errstr(open_funcs_dir[i].correct_status),
1841 i, (int)open_funcs_dir[i].dir_exists,
1842 (int)open_funcs_dir[i].open_disp);
1845 if (NT_STATUS_IS_OK(status) || open_funcs_dir[i].dir_exists) {
1846 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
1847 smbcli_rmdir(cli->tree, dname);
1852 smbcli_rmdir(cli->tree, dname);
1853 smbcli_deltree(cli->tree, BASEDIR);
1858 /* basic testing of all RAW_OPEN_* calls
1860 bool torture_raw_open(struct torture_context *torture, struct smbcli_state *cli)
1864 if (!torture_setup_dir(cli, BASEDIR)) {
1868 ret &= test_ntcreatex_brlocked(cli, torture);
1869 ret &= test_open(cli, torture);
1870 ret &= test_raw_open_multi(torture);
1871 ret &= test_openx(cli, torture);
1872 ret &= test_ntcreatex(cli, torture);
1873 ret &= test_nttrans_create(cli, torture);
1874 ret &= test_t2open(cli, torture);
1875 ret &= test_mknew(cli, torture);
1876 ret &= test_create(cli, torture);
1877 ret &= test_ctemp(cli, torture);
1878 ret &= test_chained(cli, torture);
1879 ret &= test_chained_ntcreatex_readx(cli, torture);
1880 ret &= test_no_leading_slash(cli, torture);
1881 ret &= test_openx_over_dir(cli, torture);
1882 ret &= test_open_for_delete(cli, torture);
1883 ret &= test_ntcreatex_opendisp_dir(cli, torture);
1885 smb_raw_exit(cli->session);
1886 smbcli_deltree(cli->tree, BASEDIR);