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 "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"
33 /* enum for whether reads/writes are possible on a file */
34 enum rdwr_mode {RDWR_NONE, RDWR_RDONLY, RDWR_WRONLY, RDWR_RDWR};
36 #define BASEDIR "\\rawopen"
39 check if a open file can be read/written
41 static enum rdwr_mode check_rdwr(struct smbcli_tree *tree, int fnum)
44 bool can_read = (smbcli_read(tree, fnum, &c, 0, 1) == 1);
45 bool can_write = (smbcli_write(tree, fnum, 0, &c, 0, 1) == 1);
46 if ( can_read && can_write) return RDWR_RDWR;
47 if ( can_read && !can_write) return RDWR_RDONLY;
48 if (!can_read && can_write) return RDWR_WRONLY;
53 describe a RDWR mode as a string
55 static const char *rdwr_string(enum rdwr_mode m)
58 case RDWR_NONE: return "NONE";
59 case RDWR_RDONLY: return "RDONLY";
60 case RDWR_WRONLY: return "WRONLY";
61 case RDWR_RDWR: return "RDWR";
66 #define CHECK_STATUS(status, correct) do { \
67 if (!NT_STATUS_EQUAL(status, correct)) { \
68 torture_result(tctx, TORTURE_FAIL, \
69 "(%s) Incorrect status %s - should be %s\n", \
70 __location__, nt_errstr(status), nt_errstr(correct)); \
75 #define CREATE_FILE do { \
76 fnum = create_complex_file(cli, tctx, fname); \
78 torture_result(tctx, TORTURE_FAIL, \
79 "(%s) Failed to create %s - %s\n", \
80 __location__, fname, smbcli_errstr(cli->tree)); \
85 #define CHECK_RDWR(fnum, correct) do { \
86 enum rdwr_mode m = check_rdwr(cli->tree, fnum); \
88 torture_result(tctx, TORTURE_FAIL, \
89 "(%s) Incorrect readwrite mode %s - expected %s\n", \
90 __location__, rdwr_string(m), rdwr_string(correct)); \
94 #define CHECK_TIME(t, field) do { \
96 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
97 finfo.all_info.in.file.path = fname; \
98 status = smb_raw_pathinfo(cli->tree, tctx, &finfo); \
99 CHECK_STATUS(status, NT_STATUS_OK); \
101 t2 = nt_time_to_unix(finfo.all_info.out.field) & ~1; \
102 if (abs(t1-t2) > 2) { \
103 torture_result(tctx, TORTURE_FAIL, \
104 "(%s) wrong time for field %s %s - %s\n", \
105 __location__, #field, \
106 timestring(tctx, t1), \
107 timestring(tctx, t2)); \
108 dump_all_info(tctx, &finfo); \
112 #define CHECK_NTTIME(t, field) do { \
114 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
115 finfo.all_info.in.file.path = fname; \
116 status = smb_raw_pathinfo(cli->tree, tctx, &finfo); \
117 CHECK_STATUS(status, NT_STATUS_OK); \
118 t2 = finfo.all_info.out.field; \
120 torture_result(tctx, TORTURE_FAIL, \
121 "(%s) wrong time for field %s %s - %s\n", \
122 __location__, #field, \
123 nt_time_string(tctx, t), \
124 nt_time_string(tctx, t2)); \
125 dump_all_info(tctx, &finfo); \
129 #define CHECK_ALL_INFO(v, field) do { \
130 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
131 finfo.all_info.in.file.path = fname; \
132 status = smb_raw_pathinfo(cli->tree, tctx, &finfo); \
133 CHECK_STATUS(status, NT_STATUS_OK); \
134 if ((v) != (finfo.all_info.out.field)) { \
135 torture_result(tctx, TORTURE_FAIL, \
136 "(%s) wrong value for field %s 0x%x - 0x%x\n", \
137 __location__, #field, (int)v, (int)(finfo.all_info.out.field)); \
138 dump_all_info(tctx, &finfo); \
142 #define CHECK_VAL(v, correct) do { \
143 if ((v) != (correct)) { \
144 torture_result(tctx, TORTURE_FAIL, \
145 "(%s) wrong value for %s 0x%x - should be 0x%x\n", \
146 __location__, #v, (int)(v), (int)correct); \
150 #define SET_ATTRIB(sattrib) do { \
151 union smb_setfileinfo sfinfo; \
152 ZERO_STRUCT(sfinfo.basic_info.in); \
153 sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFORMATION; \
154 sfinfo.basic_info.in.file.path = fname; \
155 sfinfo.basic_info.in.attrib = sattrib; \
156 status = smb_raw_setpathinfo(cli->tree, &sfinfo); \
157 if (!NT_STATUS_IS_OK(status)) { \
158 torture_warning(tctx, "(%s) Failed to set attrib 0x%x on %s\n", \
159 __location__, sattrib, fname); \
165 static bool test_open(struct smbcli_state *cli, struct torture_context *tctx)
168 union smb_fileinfo finfo;
169 const char *fname = BASEDIR "\\torture_open.txt";
171 int fnum = -1, fnum2;
174 torture_comment(tctx, "Checking RAW_OPEN_OPEN\n");
176 io.openold.level = RAW_OPEN_OPEN;
177 io.openold.in.fname = fname;
178 io.openold.in.open_mode = OPEN_FLAGS_FCB;
179 io.openold.in.search_attrs = 0;
180 status = smb_raw_open(cli->tree, tctx, &io);
181 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
182 fnum = io.openold.out.file.fnum;
184 smbcli_unlink(cli->tree, fname);
186 smbcli_close(cli->tree, fnum);
188 status = smb_raw_open(cli->tree, tctx, &io);
189 CHECK_STATUS(status, NT_STATUS_OK);
190 fnum = io.openold.out.file.fnum;
191 CHECK_RDWR(fnum, RDWR_RDWR);
193 status = smb_raw_open(cli->tree, tctx, &io);
194 CHECK_STATUS(status, NT_STATUS_OK);
195 fnum2 = io.openold.out.file.fnum;
196 CHECK_RDWR(fnum2, RDWR_RDWR);
197 smbcli_close(cli->tree, fnum2);
198 smbcli_close(cli->tree, fnum);
200 /* check the read/write modes */
201 io.openold.level = RAW_OPEN_OPEN;
202 io.openold.in.fname = fname;
203 io.openold.in.search_attrs = 0;
205 io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ;
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_RDONLY);
210 smbcli_close(cli->tree, fnum);
212 io.openold.in.open_mode = OPEN_FLAGS_OPEN_WRITE;
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_WRONLY);
217 smbcli_close(cli->tree, fnum);
219 io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR;
220 status = smb_raw_open(cli->tree, tctx, &io);
221 CHECK_STATUS(status, NT_STATUS_OK);
222 fnum = io.openold.out.file.fnum;
223 CHECK_RDWR(fnum, RDWR_RDWR);
224 smbcli_close(cli->tree, fnum);
226 /* check the share modes roughly - not a complete matrix */
227 io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_WRITE;
228 status = smb_raw_open(cli->tree, tctx, &io);
229 CHECK_STATUS(status, NT_STATUS_OK);
230 fnum = io.openold.out.file.fnum;
231 CHECK_RDWR(fnum, RDWR_RDWR);
233 if (io.openold.in.open_mode != io.openold.out.rmode) {
234 torture_warning(tctx, "(%s) rmode should equal open_mode - 0x%x 0x%x\n",
235 __location__, io.openold.out.rmode, io.openold.in.open_mode);
238 io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_NONE;
239 status = smb_raw_open(cli->tree, tctx, &io);
240 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
242 io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ | OPEN_FLAGS_DENY_NONE;
243 status = smb_raw_open(cli->tree, tctx, &io);
244 CHECK_STATUS(status, NT_STATUS_OK);
245 fnum2 = io.openold.out.file.fnum;
246 CHECK_RDWR(fnum2, RDWR_RDONLY);
247 smbcli_close(cli->tree, fnum);
248 smbcli_close(cli->tree, fnum2);
251 /* check the returned write time */
252 io.openold.level = RAW_OPEN_OPEN;
253 io.openold.in.fname = fname;
254 io.openold.in.search_attrs = 0;
255 io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ;
256 status = smb_raw_open(cli->tree, tctx, &io);
257 CHECK_STATUS(status, NT_STATUS_OK);
258 fnum = io.openold.out.file.fnum;
260 /* check other reply fields */
261 CHECK_TIME(io.openold.out.write_time, write_time);
262 CHECK_ALL_INFO(io.openold.out.size, size);
263 CHECK_ALL_INFO(io.openold.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
266 smbcli_close(cli->tree, fnum);
267 smbcli_unlink(cli->tree, fname);
276 static bool test_openx(struct smbcli_state *cli, struct torture_context *tctx)
279 union smb_fileinfo finfo;
280 const char *fname = BASEDIR "\\torture_openx.txt";
281 const char *fname_exe = BASEDIR "\\torture_openx.exe";
283 int fnum = -1, fnum2;
290 NTSTATUS correct_status;
292 { OPENX_OPEN_FUNC_OPEN, true, NT_STATUS_OK },
293 { OPENX_OPEN_FUNC_OPEN, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
294 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OK },
295 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
296 { OPENX_OPEN_FUNC_FAIL, true, NT_STATUS_DOS(ERRDOS, ERRbadaccess) },
297 { OPENX_OPEN_FUNC_FAIL, false, NT_STATUS_DOS(ERRDOS, ERRbadaccess) },
298 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OBJECT_NAME_COLLISION },
299 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
300 { OPENX_OPEN_FUNC_TRUNC, true, NT_STATUS_OK },
301 { OPENX_OPEN_FUNC_TRUNC, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
302 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OK },
303 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
306 torture_comment(tctx, "Checking RAW_OPEN_OPENX\n");
307 smbcli_unlink(cli->tree, fname);
309 io.openx.level = RAW_OPEN_OPENX;
310 io.openx.in.fname = fname;
311 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
312 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
313 io.openx.in.search_attrs = 0;
314 io.openx.in.file_attrs = 0;
315 io.openx.in.write_time = 0;
316 io.openx.in.size = 1024*1024;
317 io.openx.in.timeout = 0;
319 /* check all combinations of open_func */
320 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
321 if (open_funcs[i].with_file) {
322 fnum = create_complex_file(cli, tctx, fname);
324 torture_result(tctx, TORTURE_FAIL,
325 "Failed to create file %s - %s\n",
326 fname, smbcli_errstr(cli->tree));
330 smbcli_close(cli->tree, fnum);
332 io.openx.in.open_func = open_funcs[i].open_func;
333 status = smb_raw_open(cli->tree, tctx, &io);
334 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
335 torture_result(tctx, TORTURE_FAIL,
336 "(%s) incorrect status %s should be %s "
337 "(i=%d with_file=%d open_func=0x%x)\n",
338 __location__, nt_errstr(status),
339 nt_errstr(open_funcs[i].correct_status),
340 i, (int)open_funcs[i].with_file,
341 (int)open_funcs[i].open_func);
344 if (NT_STATUS_IS_OK(status)) {
345 smbcli_close(cli->tree, io.openx.out.file.fnum);
347 if (open_funcs[i].with_file) {
348 smbcli_unlink(cli->tree, fname);
352 smbcli_unlink(cli->tree, fname);
354 /* check the basic return fields */
355 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
356 status = smb_raw_open(cli->tree, tctx, &io);
357 CHECK_STATUS(status, NT_STATUS_OK);
358 fnum = io.openx.out.file.fnum;
360 CHECK_ALL_INFO(io.openx.out.size, size);
361 CHECK_TIME(io.openx.out.write_time, write_time);
362 CHECK_ALL_INFO(io.openx.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
363 CHECK_VAL(io.openx.out.access, OPENX_MODE_ACCESS_RDWR);
364 CHECK_VAL(io.openx.out.ftype, 0);
365 CHECK_VAL(io.openx.out.devstate, 0);
366 CHECK_VAL(io.openx.out.action, OPENX_ACTION_CREATED);
367 CHECK_VAL(io.openx.out.size, 1024*1024);
368 CHECK_ALL_INFO(io.openx.in.size, size);
369 smbcli_close(cli->tree, fnum);
370 smbcli_unlink(cli->tree, fname);
372 /* check the fields when the file already existed */
373 fnum2 = create_complex_file(cli, tctx, fname);
378 smbcli_close(cli->tree, fnum2);
380 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
381 status = smb_raw_open(cli->tree, tctx, &io);
382 CHECK_STATUS(status, NT_STATUS_OK);
383 fnum = io.openx.out.file.fnum;
385 CHECK_ALL_INFO(io.openx.out.size, size);
386 CHECK_TIME(io.openx.out.write_time, write_time);
387 CHECK_VAL(io.openx.out.action, OPENX_ACTION_EXISTED);
388 CHECK_VAL(io.openx.out.unknown, 0);
389 CHECK_ALL_INFO(io.openx.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
390 smbcli_close(cli->tree, fnum);
392 /* now check the search attrib for hidden files - win2003 ignores this? */
393 SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN);
394 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib);
396 io.openx.in.search_attrs = FILE_ATTRIBUTE_HIDDEN;
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 io.openx.in.search_attrs = 0;
402 status = smb_raw_open(cli->tree, tctx, &io);
403 CHECK_STATUS(status, NT_STATUS_OK);
404 smbcli_close(cli->tree, io.openx.out.file.fnum);
406 SET_ATTRIB(FILE_ATTRIBUTE_NORMAL);
407 smbcli_unlink(cli->tree, fname);
409 /* and check attrib on create */
410 io.openx.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE;
411 io.openx.in.search_attrs = 0;
412 io.openx.in.file_attrs = FILE_ATTRIBUTE_SYSTEM;
413 status = smb_raw_open(cli->tree, tctx, &io);
414 CHECK_STATUS(status, NT_STATUS_OK);
415 if (torture_setting_bool(tctx, "samba3", false)) {
416 CHECK_ALL_INFO(FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE,
417 attrib & ~(FILE_ATTRIBUTE_NONINDEXED|
418 FILE_ATTRIBUTE_SPARSE));
421 CHECK_ALL_INFO(FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE,
422 attrib & ~(FILE_ATTRIBUTE_NONINDEXED));
424 smbcli_close(cli->tree, io.openx.out.file.fnum);
425 smbcli_unlink(cli->tree, fname);
427 /* check timeout on create - win2003 ignores the timeout! */
428 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
429 io.openx.in.file_attrs = 0;
430 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL;
431 status = smb_raw_open(cli->tree, tctx, &io);
432 CHECK_STATUS(status, NT_STATUS_OK);
433 fnum = io.openx.out.file.fnum;
435 io.openx.in.timeout = 20000;
436 tv = timeval_current();
437 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_NONE;
438 status = smb_raw_open(cli->tree, tctx, &io);
439 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
440 if (timeval_elapsed(&tv) > 3.0) {
441 torture_result(tctx, TORTURE_FAIL,
442 "(%s) Incorrect timing in openx with timeout "
443 "- waited %.2f seconds\n",
444 __location__, timeval_elapsed(&tv));
447 smbcli_close(cli->tree, fnum);
448 smbcli_unlink(cli->tree, fname);
450 /* now this is a really weird one - open for execute implies create?! */
451 io.openx.in.fname = fname;
452 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
453 io.openx.in.open_mode = OPENX_MODE_ACCESS_EXEC | OPENX_MODE_DENY_NONE;
454 io.openx.in.search_attrs = 0;
455 io.openx.in.open_func = OPENX_OPEN_FUNC_FAIL;
456 io.openx.in.file_attrs = 0;
457 io.openx.in.write_time = 0;
458 io.openx.in.size = 0;
459 io.openx.in.timeout = 0;
460 status = smb_raw_open(cli->tree, tctx, &io);
461 CHECK_STATUS(status, NT_STATUS_OK);
462 smbcli_close(cli->tree, io.openx.out.file.fnum);
464 /* check the extended return flag */
465 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO | OPENX_FLAGS_EXTENDED_RETURN;
466 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
467 status = smb_raw_open(cli->tree, tctx, &io);
468 CHECK_STATUS(status, NT_STATUS_OK);
469 CHECK_VAL(io.openx.out.access_mask, SEC_STD_ALL);
470 smbcli_close(cli->tree, io.openx.out.file.fnum);
472 io.openx.in.fname = "\\A.+,;=[].B";
473 status = smb_raw_open(cli->tree, tctx, &io);
474 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
476 /* Check the mapping for open exec. */
478 /* First create an .exe file. */
479 smbcli_unlink(cli->tree, fname_exe);
480 fnum = create_complex_file(cli, tctx, fname_exe);
481 smbcli_close(cli->tree, fnum);
483 io.openx.level = RAW_OPEN_OPENX;
484 io.openx.in.fname = fname_exe;
485 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
486 io.openx.in.open_mode = OPENX_MODE_ACCESS_EXEC | OPENX_MODE_DENY_NONE;
487 io.openx.in.search_attrs = 0;
488 io.openx.in.file_attrs = 0;
489 io.openx.in.write_time = 0;
490 io.openx.in.size = 0;
491 io.openx.in.timeout = 0;
492 status = smb_raw_open(cli->tree, tctx, &io);
493 CHECK_STATUS(status, NT_STATUS_OK);
495 /* Can we read and write ? */
496 CHECK_RDWR(io.openx.out.file.fnum, RDWR_RDONLY);
497 smbcli_close(cli->tree, io.openx.out.file.fnum);
498 smbcli_unlink(cli->tree, fname);
501 smbcli_close(cli->tree, fnum);
502 smbcli_unlink(cli->tree, fname_exe);
503 smbcli_unlink(cli->tree, fname);
512 many thanks to kukks for a sniff showing how this works with os2->w2k
514 static bool test_t2open(struct smbcli_state *cli, struct torture_context *tctx)
517 union smb_fileinfo finfo;
518 const char *fname1 = BASEDIR "\\torture_t2open_yes.txt";
519 const char *fname2 = BASEDIR "\\torture_t2open_no.txt";
520 const char *fname = BASEDIR "\\torture_t2open_3.txt";
528 NTSTATUS correct_status;
530 { OPENX_OPEN_FUNC_OPEN, true, NT_STATUS_OK },
531 { OPENX_OPEN_FUNC_OPEN, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
532 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OK },
533 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
534 { OPENX_OPEN_FUNC_FAIL, true, NT_STATUS_OBJECT_NAME_COLLISION },
535 { OPENX_OPEN_FUNC_FAIL, false, NT_STATUS_OBJECT_NAME_COLLISION },
536 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OBJECT_NAME_COLLISION },
537 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OBJECT_NAME_COLLISION },
538 { OPENX_OPEN_FUNC_TRUNC, true, NT_STATUS_OK },
539 { OPENX_OPEN_FUNC_TRUNC, false, NT_STATUS_OK },
540 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OK },
541 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
544 fnum = create_complex_file(cli, tctx, fname1);
546 torture_result(tctx, TORTURE_FAIL,
547 "(%s): Failed to create file %s - %s\n",
548 __location__, fname1, smbcli_errstr(cli->tree));
552 smbcli_close(cli->tree, fnum);
554 torture_comment(tctx, "Checking RAW_OPEN_T2OPEN\n");
556 io.t2open.level = RAW_OPEN_T2OPEN;
557 io.t2open.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
558 io.t2open.in.open_mode = OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR;
559 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
560 io.t2open.in.search_attrs = 0;
561 io.t2open.in.file_attrs = 0;
562 io.t2open.in.write_time = 0;
563 io.t2open.in.size = 0;
564 io.t2open.in.timeout = 0;
566 io.t2open.in.num_eas = 3;
567 io.t2open.in.eas = talloc_array(tctx, struct ea_struct, io.t2open.in.num_eas);
568 io.t2open.in.eas[0].flags = 0;
569 io.t2open.in.eas[0].name.s = ".CLASSINFO";
570 io.t2open.in.eas[0].value = data_blob_talloc(tctx, "first value", 11);
571 io.t2open.in.eas[1].flags = 0;
572 io.t2open.in.eas[1].name.s = "EA TWO";
573 io.t2open.in.eas[1].value = data_blob_talloc(tctx, "foo", 3);
574 io.t2open.in.eas[2].flags = 0;
575 io.t2open.in.eas[2].name.s = "X THIRD";
576 io.t2open.in.eas[2].value = data_blob_talloc(tctx, "xy", 2);
578 /* check all combinations of open_func */
579 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
581 if (open_funcs[i].with_file) {
582 io.t2open.in.fname = fname1;
584 io.t2open.in.fname = fname2;
586 io.t2open.in.open_func = open_funcs[i].open_func;
587 status = smb_raw_open(cli->tree, tctx, &io);
588 if ((io.t2open.in.num_eas != 0)
589 && NT_STATUS_EQUAL(status, NT_STATUS_EAS_NOT_SUPPORTED)
590 && torture_setting_bool(tctx, "samba3", false)) {
591 torture_warning(tctx, "(%s) EAs not supported, not "
592 "treating as fatal in Samba3 test\n",
594 io.t2open.in.num_eas = 0;
598 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
599 torture_result(tctx, TORTURE_FAIL,
600 "(%s) incorrect status %s should be %s "
601 "(i=%d with_file=%d open_func=0x%x)\n",
602 __location__, nt_errstr(status),
603 nt_errstr(open_funcs[i].correct_status),
604 i, (int)open_funcs[i].with_file,
605 (int)open_funcs[i].open_func);
608 if (NT_STATUS_IS_OK(status)) {
609 smbcli_close(cli->tree, io.t2open.out.file.fnum);
613 smbcli_unlink(cli->tree, fname1);
614 smbcli_unlink(cli->tree, fname2);
616 /* check the basic return fields */
617 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
618 io.t2open.in.write_time = 0;
619 io.t2open.in.fname = fname;
620 status = smb_raw_open(cli->tree, tctx, &io);
621 CHECK_STATUS(status, NT_STATUS_OK);
622 fnum = io.t2open.out.file.fnum;
624 CHECK_ALL_INFO(io.t2open.out.size, size);
626 /* windows appears to leak uninitialised memory here */
627 CHECK_VAL(io.t2open.out.write_time, 0);
629 CHECK_ALL_INFO(io.t2open.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
630 CHECK_VAL(io.t2open.out.access, OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR);
631 CHECK_VAL(io.t2open.out.ftype, 0);
632 CHECK_VAL(io.t2open.out.devstate, 0);
633 CHECK_VAL(io.t2open.out.action, OPENX_ACTION_CREATED);
634 smbcli_close(cli->tree, fnum);
636 status = torture_check_ea(cli, fname, ".CLASSINFO", "first value");
637 CHECK_STATUS(status, io.t2open.in.num_eas
638 ? NT_STATUS_OK : NT_STATUS_EAS_NOT_SUPPORTED);
639 status = torture_check_ea(cli, fname, "EA TWO", "foo");
640 CHECK_STATUS(status, io.t2open.in.num_eas
641 ? NT_STATUS_OK : NT_STATUS_EAS_NOT_SUPPORTED);
642 status = torture_check_ea(cli, fname, "X THIRD", "xy");
643 CHECK_STATUS(status, io.t2open.in.num_eas
644 ? NT_STATUS_OK : NT_STATUS_EAS_NOT_SUPPORTED);
646 /* now check the search attrib for hidden files - win2003 ignores this? */
647 SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN);
648 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib);
650 status = smb_raw_open(cli->tree, tctx, &io);
651 CHECK_STATUS(status, NT_STATUS_OK);
652 smbcli_close(cli->tree, io.t2open.out.file.fnum);
654 status = smb_raw_open(cli->tree, tctx, &io);
655 CHECK_STATUS(status, NT_STATUS_OK);
656 smbcli_close(cli->tree, io.t2open.out.file.fnum);
658 SET_ATTRIB(FILE_ATTRIBUTE_NORMAL);
659 smbcli_unlink(cli->tree, fname);
661 /* and check attrib on create */
662 io.t2open.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE;
663 io.t2open.in.file_attrs = FILE_ATTRIBUTE_SYSTEM;
664 status = smb_raw_open(cli->tree, tctx, &io);
665 CHECK_STATUS(status, NT_STATUS_OK);
667 /* check timeout on create - win2003 ignores the timeout! */
668 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
669 io.t2open.in.file_attrs = 0;
670 io.t2open.in.timeout = 20000;
671 io.t2open.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL;
672 status = smb_raw_open(cli->tree, tctx, &io);
673 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
676 smbcli_close(cli->tree, fnum);
677 smbcli_unlink(cli->tree, fname);
684 test RAW_OPEN_NTCREATEX
686 static bool test_ntcreatex(struct smbcli_state *cli, struct torture_context *tctx)
689 union smb_fileinfo finfo;
690 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
691 const char *dname = BASEDIR "\\torture_ntcreatex.dir";
699 NTSTATUS correct_status;
701 { NTCREATEX_DISP_SUPERSEDE, true, NT_STATUS_OK },
702 { NTCREATEX_DISP_SUPERSEDE, false, NT_STATUS_OK },
703 { NTCREATEX_DISP_OPEN, true, NT_STATUS_OK },
704 { NTCREATEX_DISP_OPEN, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
705 { NTCREATEX_DISP_CREATE, true, NT_STATUS_OBJECT_NAME_COLLISION },
706 { NTCREATEX_DISP_CREATE, false, NT_STATUS_OK },
707 { NTCREATEX_DISP_OPEN_IF, true, NT_STATUS_OK },
708 { NTCREATEX_DISP_OPEN_IF, false, NT_STATUS_OK },
709 { NTCREATEX_DISP_OVERWRITE, true, NT_STATUS_OK },
710 { NTCREATEX_DISP_OVERWRITE, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
711 { NTCREATEX_DISP_OVERWRITE_IF, true, NT_STATUS_OK },
712 { NTCREATEX_DISP_OVERWRITE_IF, false, NT_STATUS_OK },
713 { 6, true, NT_STATUS_INVALID_PARAMETER },
714 { 6, false, NT_STATUS_INVALID_PARAMETER },
717 torture_comment(tctx, "Checking RAW_OPEN_NTCREATEX\n");
719 /* reasonable default parameters */
720 io.generic.level = RAW_OPEN_NTCREATEX;
721 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
722 io.ntcreatex.in.root_fid.fnum = 0;
723 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
724 io.ntcreatex.in.alloc_size = 1024*1024;
725 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
726 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
727 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
728 io.ntcreatex.in.create_options = 0;
729 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
730 io.ntcreatex.in.security_flags = 0;
731 io.ntcreatex.in.fname = fname;
733 /* test the open disposition */
734 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
735 if (open_funcs[i].with_file) {
736 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE);
738 torture_result(tctx, TORTURE_FAIL,
739 "Failed to create file %s - %s\n",
740 fname, smbcli_errstr(cli->tree));
744 smbcli_close(cli->tree, fnum);
746 io.ntcreatex.in.open_disposition = open_funcs[i].open_disp;
747 status = smb_raw_open(cli->tree, tctx, &io);
748 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
749 torture_result(tctx, TORTURE_FAIL,
750 "(%s) incorrect status %s should be %s "
751 "(i=%d with_file=%d open_disp=%d)\n",
752 __location__, nt_errstr(status),
753 nt_errstr(open_funcs[i].correct_status),
754 i, (int)open_funcs[i].with_file,
755 (int)open_funcs[i].open_disp);
758 if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
759 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
760 smbcli_unlink(cli->tree, fname);
764 /* basic field testing */
765 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
767 status = smb_raw_open(cli->tree, tctx, &io);
768 CHECK_STATUS(status, NT_STATUS_OK);
769 fnum = io.ntcreatex.out.file.fnum;
771 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
772 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
773 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
774 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
775 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
776 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
777 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
778 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
779 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
780 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
781 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
783 /* check fields when the file already existed */
784 smbcli_close(cli->tree, fnum);
785 smbcli_unlink(cli->tree, fname);
786 fnum = create_complex_file(cli, tctx, fname);
791 smbcli_close(cli->tree, fnum);
793 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
794 status = smb_raw_open(cli->tree, tctx, &io);
795 CHECK_STATUS(status, NT_STATUS_OK);
796 fnum = io.ntcreatex.out.file.fnum;
798 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
799 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
800 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
801 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
802 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
803 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
804 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
805 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
806 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
807 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
808 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
809 smbcli_close(cli->tree, fnum);
810 smbcli_unlink(cli->tree, fname);
813 /* create a directory */
814 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
815 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
816 io.ntcreatex.in.alloc_size = 0;
817 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
818 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
819 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
820 io.ntcreatex.in.create_options = 0;
821 io.ntcreatex.in.fname = dname;
824 smbcli_rmdir(cli->tree, fname);
825 smbcli_unlink(cli->tree, fname);
827 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
828 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
829 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
830 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
831 status = smb_raw_open(cli->tree, tctx, &io);
832 CHECK_STATUS(status, NT_STATUS_OK);
833 fnum = io.ntcreatex.out.file.fnum;
835 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
836 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
837 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
838 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
839 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
840 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
841 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
842 CHECK_VAL(io.ntcreatex.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED,
843 FILE_ATTRIBUTE_DIRECTORY);
844 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
845 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
846 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
847 CHECK_VAL(io.ntcreatex.out.is_directory, 1);
848 CHECK_VAL(io.ntcreatex.out.size, 0);
849 CHECK_VAL(io.ntcreatex.out.alloc_size, 0);
850 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
851 smbcli_unlink(cli->tree, fname);
855 smbcli_close(cli->tree, fnum);
856 smbcli_unlink(cli->tree, fname);
863 test RAW_OPEN_NTTRANS_CREATE
865 static bool test_nttrans_create(struct smbcli_state *cli, struct torture_context *tctx)
868 union smb_fileinfo finfo;
869 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
870 const char *dname = BASEDIR "\\torture_ntcreatex.dir";
875 uint32_t ok_mask, not_supported_mask, invalid_parameter_mask;
876 uint32_t not_a_directory_mask, unexpected_mask;
880 NTSTATUS correct_status;
882 { NTCREATEX_DISP_SUPERSEDE, true, NT_STATUS_OK },
883 { NTCREATEX_DISP_SUPERSEDE, false, NT_STATUS_OK },
884 { NTCREATEX_DISP_OPEN, true, NT_STATUS_OK },
885 { NTCREATEX_DISP_OPEN, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
886 { NTCREATEX_DISP_CREATE, true, NT_STATUS_OBJECT_NAME_COLLISION },
887 { NTCREATEX_DISP_CREATE, false, NT_STATUS_OK },
888 { NTCREATEX_DISP_OPEN_IF, true, NT_STATUS_OK },
889 { NTCREATEX_DISP_OPEN_IF, false, NT_STATUS_OK },
890 { NTCREATEX_DISP_OVERWRITE, true, NT_STATUS_OK },
891 { NTCREATEX_DISP_OVERWRITE, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
892 { NTCREATEX_DISP_OVERWRITE_IF, true, NT_STATUS_OK },
893 { NTCREATEX_DISP_OVERWRITE_IF, false, NT_STATUS_OK },
894 { 6, true, NT_STATUS_INVALID_PARAMETER },
895 { 6, false, NT_STATUS_INVALID_PARAMETER },
898 torture_comment(tctx, "Checking RAW_OPEN_NTTRANS_CREATE\n");
900 /* reasonable default parameters */
901 io.generic.level = RAW_OPEN_NTTRANS_CREATE;
902 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
903 io.ntcreatex.in.root_fid.fnum = 0;
904 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
905 io.ntcreatex.in.alloc_size = 1024*1024;
906 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
907 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
908 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
909 io.ntcreatex.in.create_options = 0;
910 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
911 io.ntcreatex.in.security_flags = 0;
912 io.ntcreatex.in.fname = fname;
913 io.ntcreatex.in.sec_desc = NULL;
914 io.ntcreatex.in.ea_list = NULL;
916 /* test the open disposition */
917 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
918 if (open_funcs[i].with_file) {
919 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE);
921 torture_result(tctx, TORTURE_FAIL,
922 "Failed to create file %s - %s\n",
923 fname, smbcli_errstr(cli->tree));
927 smbcli_close(cli->tree, fnum);
929 io.ntcreatex.in.open_disposition = open_funcs[i].open_disp;
930 status = smb_raw_open(cli->tree, tctx, &io);
931 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
932 torture_result(tctx, TORTURE_FAIL,
933 "(%s) incorrect status %s should be %s "
934 "(i=%d with_file=%d open_disp=%d)\n",
935 __location__, nt_errstr(status),
936 nt_errstr(open_funcs[i].correct_status),
937 i, (int)open_funcs[i].with_file,
938 (int)open_funcs[i].open_disp);
941 if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
942 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
943 smbcli_unlink(cli->tree, fname);
947 /* basic field testing */
948 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
950 status = smb_raw_open(cli->tree, tctx, &io);
951 CHECK_STATUS(status, NT_STATUS_OK);
952 fnum = io.ntcreatex.out.file.fnum;
954 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
955 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
956 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
957 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
958 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
959 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
960 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
961 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
962 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
963 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
964 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
966 /* check fields when the file already existed */
967 smbcli_close(cli->tree, fnum);
968 smbcli_unlink(cli->tree, fname);
969 fnum = create_complex_file(cli, tctx, fname);
974 smbcli_close(cli->tree, fnum);
976 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
977 status = smb_raw_open(cli->tree, tctx, &io);
978 CHECK_STATUS(status, NT_STATUS_OK);
979 fnum = io.ntcreatex.out.file.fnum;
981 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
982 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
983 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
984 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
985 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
986 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
987 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
988 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
989 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
990 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
991 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
992 smbcli_close(cli->tree, fnum);
994 /* check no-recall - don't pull a file from tape on a HSM */
995 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_NO_RECALL;
996 status = smb_raw_open(cli->tree, tctx, &io);
997 CHECK_STATUS(status, NT_STATUS_OK);
998 fnum = io.ntcreatex.out.file.fnum;
1000 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
1001 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
1002 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
1003 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
1004 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
1005 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
1006 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
1007 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
1008 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
1009 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
1010 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
1011 smbcli_close(cli->tree, fnum);
1013 /* Check some create options (these all should be ignored) */
1014 for (i=0; i < 32; i++) {
1015 uint32_t create_option = (1 << i) & NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
1016 if (create_option == 0) {
1019 io.ntcreatex.in.create_options = create_option;
1020 status = smb_raw_open(cli->tree, tctx, &io);
1021 if (!NT_STATUS_IS_OK(status)) {
1022 torture_warning(tctx, "ntcreatex create option 0x%08x "
1023 "gave %s - should give NT_STATUS_OK\n",
1024 create_option, nt_errstr(status));
1026 CHECK_STATUS(status, NT_STATUS_OK);
1027 fnum = io.ntcreatex.out.file.fnum;
1029 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
1030 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
1031 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
1032 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
1033 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
1034 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
1035 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
1036 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
1037 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
1038 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
1039 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
1040 smbcli_close(cli->tree, fnum);
1043 io.ntcreatex.in.file_attr = 0;
1044 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
1045 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1047 /* Check for options that should return NOT_SUPPORTED, OK or INVALID_PARAMETER */
1049 not_supported_mask = 0;
1050 invalid_parameter_mask = 0;
1051 not_a_directory_mask = 0;
1052 unexpected_mask = 0;
1053 for (i=0; i < 32; i++) {
1054 uint32_t create_option = 1<<i;
1055 if (create_option & NTCREATEX_OPTIONS_DELETE_ON_CLOSE) {
1058 io.ntcreatex.in.create_options = create_option;
1059 status = smb_raw_open(cli->tree, tctx, &io);
1060 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
1061 not_supported_mask |= create_option;
1062 } else if (NT_STATUS_EQUAL(status, NT_STATUS_OK)) {
1063 ok_mask |= create_option;
1064 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
1065 } else if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
1066 invalid_parameter_mask |= create_option;
1067 } else if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_A_DIRECTORY)) {
1068 not_a_directory_mask |= 1<<i;
1070 unexpected_mask |= 1<<i;
1071 torture_comment(tctx, "create option 0x%08x returned %s\n",
1072 create_option, nt_errstr(status));
1076 CHECK_VAL(ok_mask, 0x00efcfce);
1077 CHECK_VAL(not_a_directory_mask, 0x00000001);
1078 CHECK_VAL(not_supported_mask, 0x00002000);
1079 CHECK_VAL(invalid_parameter_mask, 0xff100030);
1080 CHECK_VAL(unexpected_mask, 0x00000000);
1082 smbcli_unlink(cli->tree, fname);
1085 /* create a directory */
1086 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1087 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
1088 io.ntcreatex.in.alloc_size = 0;
1089 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
1090 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
1091 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1092 io.ntcreatex.in.create_options = 0;
1093 io.ntcreatex.in.fname = dname;
1096 smbcli_rmdir(cli->tree, fname);
1097 smbcli_unlink(cli->tree, fname);
1099 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1100 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1101 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1102 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1103 status = smb_raw_open(cli->tree, tctx, &io);
1104 CHECK_STATUS(status, NT_STATUS_OK);
1105 fnum = io.ntcreatex.out.file.fnum;
1107 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
1108 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
1109 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
1110 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
1111 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
1112 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
1113 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
1114 CHECK_VAL(io.ntcreatex.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED,
1115 FILE_ATTRIBUTE_DIRECTORY);
1116 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
1117 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
1118 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
1119 CHECK_VAL(io.ntcreatex.out.is_directory, 1);
1120 CHECK_VAL(io.ntcreatex.out.size, 0);
1121 CHECK_VAL(io.ntcreatex.out.alloc_size, 0);
1122 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
1123 smbcli_unlink(cli->tree, fname);
1127 smbcli_close(cli->tree, fnum);
1128 smbcli_unlink(cli->tree, fname);
1134 test RAW_OPEN_NTCREATEX with an already opened and byte range locked file
1136 I've got an application that does a similar sequence of ntcreate&x,
1137 locking&x and another ntcreate&x with
1138 open_disposition==NTCREATEX_DISP_OVERWRITE_IF. Windows 2003 allows the
1141 static bool test_ntcreatex_brlocked(struct smbcli_state *cli, struct torture_context *tctx)
1143 union smb_open io, io1;
1145 struct smb_lock_entry lock[1];
1146 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
1150 torture_comment(tctx, "Testing ntcreatex with a byte range locked file\n");
1152 io.generic.level = RAW_OPEN_NTCREATEX;
1153 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
1154 io.ntcreatex.in.root_fid.fnum = 0;
1155 io.ntcreatex.in.access_mask = 0x2019f;
1156 io.ntcreatex.in.alloc_size = 0;
1157 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1158 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1159 NTCREATEX_SHARE_ACCESS_WRITE;
1160 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1161 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
1162 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
1163 io.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC |
1164 NTCREATEX_SECURITY_ALL;
1165 io.ntcreatex.in.fname = fname;
1167 status = smb_raw_open(cli->tree, tctx, &io);
1168 CHECK_STATUS(status, NT_STATUS_OK);
1170 io2.lockx.level = RAW_LOCK_LOCKX;
1171 io2.lockx.in.file.fnum = io.ntcreatex.out.file.fnum;
1172 io2.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
1173 io2.lockx.in.timeout = 0;
1174 io2.lockx.in.ulock_cnt = 0;
1175 io2.lockx.in.lock_cnt = 1;
1176 lock[0].pid = cli->session->pid;
1178 lock[0].count = 0x1;
1179 io2.lockx.in.locks = &lock[0];
1180 status = smb_raw_lock(cli->tree, &io2);
1181 CHECK_STATUS(status, NT_STATUS_OK);
1183 io1.generic.level = RAW_OPEN_NTCREATEX;
1184 io1.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
1185 io1.ntcreatex.in.root_fid.fnum = 0;
1186 io1.ntcreatex.in.access_mask = 0x20196;
1187 io1.ntcreatex.in.alloc_size = 0;
1188 io1.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1189 io1.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1190 NTCREATEX_SHARE_ACCESS_WRITE;
1191 io1.ntcreatex.in.open_disposition = NTCREATEX_DISP_OVERWRITE_IF;
1192 io1.ntcreatex.in.create_options = 0;
1193 io1.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
1194 io1.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC |
1195 NTCREATEX_SECURITY_ALL;
1196 io1.ntcreatex.in.fname = fname;
1198 status = smb_raw_open(cli->tree, tctx, &io1);
1199 CHECK_STATUS(status, NT_STATUS_OK);
1202 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
1203 smbcli_close(cli->tree, io1.ntcreatex.out.file.fnum);
1204 smbcli_unlink(cli->tree, fname);
1211 static bool test_mknew(struct smbcli_state *cli, struct torture_context *tctx)
1214 const char *fname = BASEDIR "\\torture_mknew.txt";
1218 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1219 union smb_fileinfo finfo;
1221 torture_comment(tctx, "Checking RAW_OPEN_MKNEW\n");
1223 io.mknew.level = RAW_OPEN_MKNEW;
1224 io.mknew.in.attrib = 0;
1225 io.mknew.in.write_time = 0;
1226 io.mknew.in.fname = fname;
1227 status = smb_raw_open(cli->tree, tctx, &io);
1228 CHECK_STATUS(status, NT_STATUS_OK);
1229 fnum = io.mknew.out.file.fnum;
1231 status = smb_raw_open(cli->tree, tctx, &io);
1232 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
1234 smbcli_close(cli->tree, fnum);
1235 smbcli_unlink(cli->tree, fname);
1237 /* make sure write_time works */
1238 io.mknew.in.write_time = basetime;
1239 status = smb_raw_open(cli->tree, tctx, &io);
1240 CHECK_STATUS(status, NT_STATUS_OK);
1241 fnum = io.mknew.out.file.fnum;
1242 CHECK_TIME(basetime, write_time);
1244 smbcli_close(cli->tree, fnum);
1245 smbcli_unlink(cli->tree, fname);
1247 /* make sure file_attrs works */
1248 io.mknew.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1249 status = smb_raw_open(cli->tree, tctx, &io);
1250 CHECK_STATUS(status, NT_STATUS_OK);
1251 fnum = io.mknew.out.file.fnum;
1252 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE,
1253 attrib & ~FILE_ATTRIBUTE_NONINDEXED);
1256 smbcli_close(cli->tree, fnum);
1257 smbcli_unlink(cli->tree, fname);
1264 test RAW_OPEN_CREATE
1266 static bool test_create(struct smbcli_state *cli, struct torture_context *tctx)
1269 const char *fname = BASEDIR "\\torture_create.txt";
1273 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1274 union smb_fileinfo finfo;
1276 torture_comment(tctx, "Checking RAW_OPEN_CREATE\n");
1278 io.create.level = RAW_OPEN_CREATE;
1279 io.create.in.attrib = 0;
1280 io.create.in.write_time = 0;
1281 io.create.in.fname = fname;
1282 status = smb_raw_open(cli->tree, tctx, &io);
1283 CHECK_STATUS(status, NT_STATUS_OK);
1284 fnum = io.create.out.file.fnum;
1286 status = smb_raw_open(cli->tree, tctx, &io);
1287 CHECK_STATUS(status, NT_STATUS_OK);
1289 smbcli_close(cli->tree, io.create.out.file.fnum);
1290 smbcli_close(cli->tree, fnum);
1291 smbcli_unlink(cli->tree, fname);
1293 /* make sure write_time works */
1294 io.create.in.write_time = basetime;
1295 status = smb_raw_open(cli->tree, tctx, &io);
1296 CHECK_STATUS(status, NT_STATUS_OK);
1297 fnum = io.create.out.file.fnum;
1298 CHECK_TIME(basetime, write_time);
1300 smbcli_close(cli->tree, fnum);
1301 smbcli_unlink(cli->tree, fname);
1303 /* make sure file_attrs works */
1304 io.create.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1305 status = smb_raw_open(cli->tree, tctx, &io);
1306 CHECK_STATUS(status, NT_STATUS_OK);
1307 fnum = io.create.out.file.fnum;
1308 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE,
1309 attrib & ~FILE_ATTRIBUTE_NONINDEXED);
1312 smbcli_close(cli->tree, fnum);
1313 smbcli_unlink(cli->tree, fname);
1322 static bool test_ctemp(struct smbcli_state *cli, TALLOC_CTX *tctx)
1328 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1329 union smb_fileinfo finfo;
1330 const char *name, *fname = NULL;
1332 torture_comment(tctx, "Checking RAW_OPEN_CTEMP\n");
1334 io.ctemp.level = RAW_OPEN_CTEMP;
1335 io.ctemp.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1336 io.ctemp.in.write_time = basetime;
1337 io.ctemp.in.directory = BASEDIR;
1338 status = smb_raw_open(cli->tree, tctx, &io);
1339 CHECK_STATUS(status, NT_STATUS_OK);
1340 fnum = io.ctemp.out.file.fnum;
1342 name = io.ctemp.out.name;
1344 finfo.generic.level = RAW_FILEINFO_NAME_INFO;
1345 finfo.generic.in.file.fnum = fnum;
1346 status = smb_raw_fileinfo(cli->tree, tctx, &finfo);
1347 CHECK_STATUS(status, NT_STATUS_OK);
1349 fname = finfo.name_info.out.fname.s;
1350 torture_comment(tctx, "ctemp name=%s real name=%s\n", name, fname);
1353 smbcli_close(cli->tree, fnum);
1355 smbcli_unlink(cli->tree, fname);
1363 test chained RAW_OPEN_OPENX_READX
1365 static bool test_chained(struct smbcli_state *cli, TALLOC_CTX *tctx)
1368 const char *fname = BASEDIR "\\torture_chained.txt";
1372 const char *buf = "test";
1375 torture_comment(tctx, "Checking RAW_OPEN_OPENX chained with READX\n");
1376 smbcli_unlink(cli->tree, fname);
1378 fnum = create_complex_file(cli, tctx, fname);
1380 smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf));
1382 smbcli_close(cli->tree, fnum);
1384 io.openxreadx.level = RAW_OPEN_OPENX_READX;
1385 io.openxreadx.in.fname = fname;
1386 io.openxreadx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
1387 io.openxreadx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
1388 io.openxreadx.in.open_func = OPENX_OPEN_FUNC_OPEN;
1389 io.openxreadx.in.search_attrs = 0;
1390 io.openxreadx.in.file_attrs = 0;
1391 io.openxreadx.in.write_time = 0;
1392 io.openxreadx.in.size = 1024*1024;
1393 io.openxreadx.in.timeout = 0;
1395 io.openxreadx.in.offset = 0;
1396 io.openxreadx.in.mincnt = sizeof(buf);
1397 io.openxreadx.in.maxcnt = sizeof(buf);
1398 io.openxreadx.in.remaining = 0;
1399 io.openxreadx.out.data = (uint8_t *)buf2;
1401 status = smb_raw_open(cli->tree, tctx, &io);
1402 CHECK_STATUS(status, NT_STATUS_OK);
1403 fnum = io.openxreadx.out.file.fnum;
1405 if (memcmp(buf, buf2, sizeof(buf)) != 0) {
1406 torture_result(tctx, TORTURE_FAIL,
1407 "wrong data in reply buffer\n");
1412 smbcli_close(cli->tree, fnum);
1413 smbcli_unlink(cli->tree, fname);
1419 test RAW_OPEN_OPENX without a leading slash on the path.
1420 NetApp filers are known to fail on this.
1423 static bool test_no_leading_slash(struct smbcli_state *cli, TALLOC_CTX *tctx)
1426 const char *fname = BASEDIR "\\torture_no_leading_slash.txt";
1430 const char *buf = "test";
1432 torture_comment(tctx, "Checking RAW_OPEN_OPENX without leading "
1434 smbcli_unlink(cli->tree, fname);
1436 /* Create the file */
1437 fnum = create_complex_file(cli, tctx, fname);
1438 smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf));
1439 smbcli_close(cli->tree, fnum);
1441 /* Prepare to open the file using path without leading slash */
1442 io.openx.level = RAW_OPEN_OPENX;
1443 io.openx.in.fname = fname + 1;
1444 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
1445 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
1446 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
1447 io.openx.in.search_attrs = 0;
1448 io.openx.in.file_attrs = 0;
1449 io.openx.in.write_time = 0;
1450 io.openx.in.size = 1024*1024;
1451 io.openx.in.timeout = 0;
1453 status = smb_raw_open(cli->tree, tctx, &io);
1454 CHECK_STATUS(status, NT_STATUS_OK);
1455 fnum = io.openx.out.file.fnum;
1458 smbcli_close(cli->tree, fnum);
1459 smbcli_unlink(cli->tree, fname);
1465 test RAW_OPEN_OPENX against an existing directory to
1466 ensure it returns NT_STATUS_FILE_IS_A_DIRECTORY.
1467 Samba 3.2.0 - 3.2.6 are known to fail this.
1470 static bool test_openx_over_dir(struct smbcli_state *cli, TALLOC_CTX *tctx)
1473 const char *fname = BASEDIR "\\openx_over_dir";
1479 torture_comment(tctx, "Checking RAW_OPEN_OPENX over an existing directory\n");
1480 smbcli_unlink(cli->tree, fname);
1482 /* Create the Directory */
1483 status = create_directory_handle(cli->tree, fname, &d_fnum);
1484 smbcli_close(cli->tree, d_fnum);
1486 /* Prepare to open the file over the directory. */
1487 io.openx.level = RAW_OPEN_OPENX;
1488 io.openx.in.fname = fname;
1489 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
1490 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
1491 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
1492 io.openx.in.search_attrs = 0;
1493 io.openx.in.file_attrs = 0;
1494 io.openx.in.write_time = 0;
1495 io.openx.in.size = 1024*1024;
1496 io.openx.in.timeout = 0;
1498 status = smb_raw_open(cli->tree, tctx, &io);
1499 CHECK_STATUS(status, NT_STATUS_FILE_IS_A_DIRECTORY);
1500 fnum = io.openx.out.file.fnum;
1503 smbcli_close(cli->tree, fnum);
1504 smbcli_unlink(cli->tree, fname);
1510 /* A little torture test to expose a race condition in Samba 3.0.20 ... :-) */
1512 static bool test_raw_open_multi(struct torture_context *tctx)
1514 struct smbcli_state *cli;
1515 TALLOC_CTX *mem_ctx = talloc_init("torture_test_oplock_multi");
1516 const char *fname = "\\test_oplock.dat";
1520 struct smbcli_state **clients;
1521 struct smbcli_request **requests;
1522 union smb_open *ios;
1523 const char *host = torture_setting_string(tctx, "host", NULL);
1524 const char *share = torture_setting_string(tctx, "share", NULL);
1525 int i, num_files = 3;
1527 int num_collision = 0;
1529 clients = talloc_array(mem_ctx, struct smbcli_state *, num_files);
1530 requests = talloc_array(mem_ctx, struct smbcli_request *, num_files);
1531 ios = talloc_array(mem_ctx, union smb_open, num_files);
1532 if ((tctx->ev == NULL) || (clients == NULL) || (requests == NULL) ||
1534 torture_result(tctx, TORTURE_FAIL, "(%s): talloc failed\n",
1539 if (!torture_open_connection_share(mem_ctx, &cli, tctx, host, share, tctx->ev)) {
1543 cli->tree->session->transport->options.request_timeout = 60;
1545 for (i=0; i<num_files; i++) {
1546 if (!torture_open_connection_share(mem_ctx, &(clients[i]),
1547 tctx, host, share, tctx->ev)) {
1548 torture_result(tctx, TORTURE_FAIL,
1549 "(%s): Could not open %d'th connection\n",
1553 clients[i]->tree->session->transport->options.request_timeout = 60;
1557 smbcli_unlink(cli->tree, fname);
1560 base ntcreatex parms
1562 io.generic.level = RAW_OPEN_NTCREATEX;
1563 io.ntcreatex.in.root_fid.fnum = 0;
1564 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
1565 io.ntcreatex.in.alloc_size = 0;
1566 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1567 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ|
1568 NTCREATEX_SHARE_ACCESS_WRITE|
1569 NTCREATEX_SHARE_ACCESS_DELETE;
1570 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1571 io.ntcreatex.in.create_options = 0;
1572 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1573 io.ntcreatex.in.security_flags = 0;
1574 io.ntcreatex.in.fname = fname;
1575 io.ntcreatex.in.flags = 0;
1577 for (i=0; i<num_files; i++) {
1579 requests[i] = smb_raw_open_send(clients[i]->tree, &ios[i]);
1580 if (requests[i] == NULL) {
1581 torture_result(tctx, TORTURE_FAIL,
1582 "(%s): could not send %d'th request\n",
1588 torture_comment(tctx, "waiting for replies\n");
1590 bool unreplied = false;
1591 for (i=0; i<num_files; i++) {
1592 if (requests[i] == NULL) {
1595 if (requests[i]->state < SMBCLI_REQUEST_DONE) {
1599 status = smb_raw_open_recv(requests[i], mem_ctx,
1602 torture_comment(tctx, "File %d returned status %s\n", i,
1605 if (NT_STATUS_IS_OK(status)) {
1609 if (NT_STATUS_EQUAL(status,
1610 NT_STATUS_OBJECT_NAME_COLLISION)) {
1620 if (event_loop_once(tctx->ev) != 0) {
1621 torture_result(tctx, TORTURE_FAIL,
1622 "(%s): event_loop_once failed\n", __location__);
1627 if ((num_ok != 1) || (num_ok + num_collision != num_files)) {
1631 for (i=0; i<num_files; i++) {
1632 torture_close_connection(clients[i]);
1634 talloc_free(mem_ctx);
1639 test opening for delete on a read-only attribute file.
1641 static bool test_open_for_delete(struct smbcli_state *cli, struct torture_context *tctx)
1644 union smb_fileinfo finfo;
1645 const char *fname = BASEDIR "\\torture_open_for_delete.txt";
1650 torture_comment(tctx, "Checking RAW_NTCREATEX for delete on a readonly file.\n");
1652 /* reasonable default parameters */
1653 io.generic.level = RAW_OPEN_NTCREATEX;
1654 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
1655 io.ntcreatex.in.root_fid.fnum = 0;
1656 io.ntcreatex.in.alloc_size = 0;
1657 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
1658 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_READONLY;
1659 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
1660 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1661 io.ntcreatex.in.create_options = 0;
1662 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1663 io.ntcreatex.in.security_flags = 0;
1664 io.ntcreatex.in.fname = fname;
1666 /* Create the readonly file. */
1668 status = smb_raw_open(cli->tree, tctx, &io);
1669 CHECK_STATUS(status, NT_STATUS_OK);
1670 fnum = io.ntcreatex.out.file.fnum;
1672 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
1673 io.ntcreatex.in.create_options = 0;
1674 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
1675 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
1676 smbcli_close(cli->tree, fnum);
1678 /* Now try and open for delete only - should succeed. */
1679 io.ntcreatex.in.access_mask = SEC_STD_DELETE;
1680 io.ntcreatex.in.file_attr = 0;
1681 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
1682 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
1683 status = smb_raw_open(cli->tree, tctx, &io);
1684 CHECK_STATUS(status, NT_STATUS_OK);
1686 smbcli_unlink(cli->tree, fname);
1689 smbcli_close(cli->tree, fnum);
1690 smbcli_unlink(cli->tree, fname);
1696 test chained RAW_OPEN_NTCREATEX_READX
1697 Send chained NTCREATEX_READX on a file that doesn't exist, then create
1698 the file and try again.
1700 static bool test_chained_ntcreatex_readx(struct smbcli_state *cli, struct torture_context *tctx)
1702 TALLOC_CTX *mem_ctx = talloc_new(tctx);
1704 const char *fname = BASEDIR "\\torture_chained.txt";
1708 const char *buf = "test";
1711 torture_comment(tctx, "Checking RAW_NTCREATEX_READX chained on "
1712 "non-existant file \n");
1713 smbcli_unlink(cli->tree, fname);
1715 /* ntcreatex parameters */
1716 io.generic.level = RAW_OPEN_NTCREATEX_READX;
1717 io.ntcreatexreadx.in.flags = 0;
1718 io.ntcreatexreadx.in.root_fid.fnum = 0;
1719 io.ntcreatexreadx.in.access_mask = SEC_FILE_READ_DATA;
1720 io.ntcreatexreadx.in.alloc_size = 0;
1721 io.ntcreatexreadx.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1722 io.ntcreatexreadx.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1723 NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
1724 io.ntcreatexreadx.in.open_disposition = NTCREATEX_DISP_OPEN;
1725 io.ntcreatexreadx.in.create_options = 0;
1726 io.ntcreatexreadx.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
1727 io.ntcreatexreadx.in.security_flags = 0;
1728 io.ntcreatexreadx.in.fname = fname;
1730 /* readx parameters */
1731 io.ntcreatexreadx.in.offset = 0;
1732 io.ntcreatexreadx.in.mincnt = sizeof(buf);
1733 io.ntcreatexreadx.in.maxcnt = sizeof(buf);
1734 io.ntcreatexreadx.in.remaining = 0;
1735 io.ntcreatexreadx.out.data = (uint8_t *)buf2;
1737 /* try to open the non-existant file */
1738 status = smb_raw_open(cli->tree, mem_ctx, &io);
1739 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
1740 fnum = io.ntcreatexreadx.out.file.fnum;
1742 smbcli_close(cli->tree, fnum);
1743 smbcli_unlink(cli->tree, fname);
1745 torture_comment(tctx, "Checking RAW_NTCREATEX_READX chained on "
1746 "existing file \n");
1748 fnum = create_complex_file(cli, mem_ctx, fname);
1749 smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf));
1750 smbcli_close(cli->tree, fnum);
1752 status = smb_raw_open(cli->tree, mem_ctx, &io);
1753 CHECK_STATUS(status, NT_STATUS_OK);
1754 fnum = io.ntcreatexreadx.out.file.fnum;
1756 if (memcmp(buf, buf2, sizeof(buf)) != 0) {
1757 torture_result(tctx, TORTURE_FAIL,
1758 "(%s): wrong data in reply buffer\n", __location__);
1763 smbcli_close(cli->tree, fnum);
1764 smbcli_unlink(cli->tree, fname);
1765 talloc_free(mem_ctx);
1770 #define FILL_NTCREATEX(_struct, _init...) \
1772 (_struct)->generic.level = RAW_OPEN_NTCREATEX; \
1773 (_struct)->ntcreatex.in \
1774 = (typeof((_struct)->ntcreatex.in)) {_init};\
1777 static bool test_ntcreatex_opendisp_dir(struct smbcli_state *cli,
1778 struct torture_context *tctx)
1781 const char *dname = BASEDIR "\\torture_ntcreatex_opendisp_dir";
1788 NTSTATUS correct_status;
1789 } open_funcs_dir[] = {
1790 { NTCREATEX_DISP_SUPERSEDE, true, NT_STATUS_INVALID_PARAMETER },
1791 { NTCREATEX_DISP_SUPERSEDE, false, NT_STATUS_INVALID_PARAMETER },
1792 { NTCREATEX_DISP_OPEN, true, NT_STATUS_OK },
1793 { NTCREATEX_DISP_OPEN, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
1794 { NTCREATEX_DISP_CREATE, true, NT_STATUS_OBJECT_NAME_COLLISION },
1795 { NTCREATEX_DISP_CREATE, false, NT_STATUS_OK },
1796 { NTCREATEX_DISP_OPEN_IF, true, NT_STATUS_OK },
1797 { NTCREATEX_DISP_OPEN_IF, false, NT_STATUS_OK },
1798 { NTCREATEX_DISP_OVERWRITE, true, NT_STATUS_INVALID_PARAMETER },
1799 { NTCREATEX_DISP_OVERWRITE, false, NT_STATUS_INVALID_PARAMETER },
1800 { NTCREATEX_DISP_OVERWRITE_IF, true, NT_STATUS_INVALID_PARAMETER },
1801 { NTCREATEX_DISP_OVERWRITE_IF, false, NT_STATUS_INVALID_PARAMETER },
1802 { 6, true, NT_STATUS_INVALID_PARAMETER },
1803 { 6, false, NT_STATUS_INVALID_PARAMETER },
1806 if (!torture_setup_dir(cli, BASEDIR)) {
1811 .flags = NTCREATEX_FLAGS_EXTENDED,
1812 .access_mask = SEC_FLAG_MAXIMUM_ALLOWED,
1813 .file_attr = FILE_ATTRIBUTE_DIRECTORY,
1814 .share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE,
1815 .create_options = NTCREATEX_OPTIONS_DIRECTORY,
1819 smbcli_rmdir(cli->tree, dname);
1820 smbcli_unlink(cli->tree, dname);
1822 /* test the open disposition for directories */
1823 torture_comment(tctx, "Testing open dispositions for directories...\n");
1825 for (i=0; i<ARRAY_SIZE(open_funcs_dir); i++) {
1826 if (open_funcs_dir[i].dir_exists) {
1827 status = smbcli_mkdir(cli->tree, dname);
1828 if (!NT_STATUS_IS_OK(status)) {
1829 torture_result(tctx, TORTURE_FAIL,
1830 "(%s): Failed to make directory "
1831 "%s - %s\n", __location__, dname,
1832 smbcli_errstr(cli->tree));
1838 io.ntcreatex.in.open_disposition = open_funcs_dir[i].open_disp;
1839 status = smb_raw_open(cli->tree, tctx, &io);
1840 if (!NT_STATUS_EQUAL(status, open_funcs_dir[i].correct_status)) {
1841 torture_result(tctx, TORTURE_FAIL,
1842 "(%s) incorrect status %s should be %s "
1843 "(i=%d dir_exists=%d open_disp=%d)\n",
1844 __location__, nt_errstr(status),
1845 nt_errstr(open_funcs_dir[i].correct_status),
1846 i, (int)open_funcs_dir[i].dir_exists,
1847 (int)open_funcs_dir[i].open_disp);
1850 if (NT_STATUS_IS_OK(status) || open_funcs_dir[i].dir_exists) {
1851 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
1852 smbcli_rmdir(cli->tree, dname);
1857 smbcli_rmdir(cli->tree, dname);
1858 smbcli_deltree(cli->tree, BASEDIR);
1863 /* basic testing of all RAW_OPEN_* calls
1865 bool torture_raw_open(struct torture_context *torture, struct smbcli_state *cli)
1869 if (!torture_setup_dir(cli, BASEDIR)) {
1873 ret &= test_ntcreatex_brlocked(cli, torture);
1874 ret &= test_open(cli, torture);
1875 ret &= test_raw_open_multi(torture);
1876 ret &= test_openx(cli, torture);
1877 ret &= test_ntcreatex(cli, torture);
1878 ret &= test_nttrans_create(cli, torture);
1879 ret &= test_t2open(cli, torture);
1880 ret &= test_mknew(cli, torture);
1881 ret &= test_create(cli, torture);
1882 ret &= test_ctemp(cli, torture);
1883 ret &= test_chained(cli, torture);
1884 ret &= test_chained_ntcreatex_readx(cli, torture);
1885 ret &= test_no_leading_slash(cli, torture);
1886 ret &= test_openx_over_dir(cli, torture);
1887 ret &= test_open_for_delete(cli, torture);
1888 ret &= test_ntcreatex_opendisp_dir(cli, torture);
1890 smb_raw_exit(cli->session);
1891 smbcli_deltree(cli->tree, BASEDIR);