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 "system/time.h"
24 #include "system/filesys.h"
25 #include "librpc/gen_ndr/security.h"
26 #include "lib/events/events.h"
27 #include "libcli/libcli.h"
28 #include "torture/util.h"
29 #include "auth/credentials/credentials.h"
30 #include "lib/cmdline/popt_common.h"
31 #include "param/param.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 printf("(%s) Incorrect status %s - should be %s\n", \
69 __location__, nt_errstr(status), nt_errstr(correct)); \
74 #define CREATE_FILE do { \
75 fnum = create_complex_file(cli, tctx, fname); \
77 printf("(%s) Failed to create %s - %s\n", __location__, fname, smbcli_errstr(cli->tree)); \
82 #define CHECK_RDWR(fnum, correct) do { \
83 enum rdwr_mode m = check_rdwr(cli->tree, fnum); \
85 printf("(%s) Incorrect readwrite mode %s - expected %s\n", \
86 __location__, rdwr_string(m), rdwr_string(correct)); \
90 #define CHECK_TIME(t, field) do { \
92 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
93 finfo.all_info.in.file.path = fname; \
94 status = smb_raw_pathinfo(cli->tree, tctx, &finfo); \
95 CHECK_STATUS(status, NT_STATUS_OK); \
97 t2 = nt_time_to_unix(finfo.all_info.out.field) & ~1; \
98 if (abs(t1-t2) > 2) { \
99 printf("(%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 printf("(%s) wrong time for field %s %s - %s\n", \
116 __location__, #field, \
117 nt_time_string(tctx, t), \
118 nt_time_string(tctx, t2)); \
119 dump_all_info(tctx, &finfo); \
123 #define CHECK_ALL_INFO(v, field) do { \
124 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
125 finfo.all_info.in.file.path = fname; \
126 status = smb_raw_pathinfo(cli->tree, tctx, &finfo); \
127 CHECK_STATUS(status, NT_STATUS_OK); \
128 if ((v) != (finfo.all_info.out.field)) { \
129 printf("(%s) wrong value for field %s 0x%x - 0x%x\n", \
130 __location__, #field, (int)v, (int)(finfo.all_info.out.field)); \
131 dump_all_info(tctx, &finfo); \
135 #define CHECK_VAL(v, correct) do { \
136 if ((v) != (correct)) { \
137 printf("(%s) wrong value for %s 0x%x - should be 0x%x\n", \
138 __location__, #v, (int)(v), (int)correct); \
142 #define SET_ATTRIB(sattrib) do { \
143 union smb_setfileinfo sfinfo; \
144 ZERO_STRUCT(sfinfo.basic_info.in); \
145 sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFORMATION; \
146 sfinfo.basic_info.in.file.path = fname; \
147 sfinfo.basic_info.in.attrib = sattrib; \
148 status = smb_raw_setpathinfo(cli->tree, &sfinfo); \
149 if (!NT_STATUS_IS_OK(status)) { \
150 printf("(%s) Failed to set attrib 0x%x on %s\n", \
151 __location__, sattrib, fname); \
157 static bool test_open(struct smbcli_state *cli, struct torture_context *tctx)
160 union smb_fileinfo finfo;
161 const char *fname = BASEDIR "\\torture_open.txt";
163 int fnum = -1, fnum2;
166 printf("Checking RAW_OPEN_OPEN\n");
168 io.openold.level = RAW_OPEN_OPEN;
169 io.openold.in.fname = fname;
170 io.openold.in.open_mode = OPEN_FLAGS_FCB;
171 io.openold.in.search_attrs = 0;
172 status = smb_raw_open(cli->tree, tctx, &io);
173 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
174 fnum = io.openold.out.file.fnum;
176 smbcli_unlink(cli->tree, fname);
178 smbcli_close(cli->tree, fnum);
180 status = smb_raw_open(cli->tree, tctx, &io);
181 CHECK_STATUS(status, NT_STATUS_OK);
182 fnum = io.openold.out.file.fnum;
183 CHECK_RDWR(fnum, RDWR_RDWR);
185 status = smb_raw_open(cli->tree, tctx, &io);
186 CHECK_STATUS(status, NT_STATUS_OK);
187 fnum2 = io.openold.out.file.fnum;
188 CHECK_RDWR(fnum2, RDWR_RDWR);
189 smbcli_close(cli->tree, fnum2);
190 smbcli_close(cli->tree, fnum);
192 /* check the read/write modes */
193 io.openold.level = RAW_OPEN_OPEN;
194 io.openold.in.fname = fname;
195 io.openold.in.search_attrs = 0;
197 io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ;
198 status = smb_raw_open(cli->tree, tctx, &io);
199 CHECK_STATUS(status, NT_STATUS_OK);
200 fnum = io.openold.out.file.fnum;
201 CHECK_RDWR(fnum, RDWR_RDONLY);
202 smbcli_close(cli->tree, fnum);
204 io.openold.in.open_mode = OPEN_FLAGS_OPEN_WRITE;
205 status = smb_raw_open(cli->tree, tctx, &io);
206 CHECK_STATUS(status, NT_STATUS_OK);
207 fnum = io.openold.out.file.fnum;
208 CHECK_RDWR(fnum, RDWR_WRONLY);
209 smbcli_close(cli->tree, fnum);
211 io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR;
212 status = smb_raw_open(cli->tree, tctx, &io);
213 CHECK_STATUS(status, NT_STATUS_OK);
214 fnum = io.openold.out.file.fnum;
215 CHECK_RDWR(fnum, RDWR_RDWR);
216 smbcli_close(cli->tree, fnum);
218 /* check the share modes roughly - not a complete matrix */
219 io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_WRITE;
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);
225 if (io.openold.in.open_mode != io.openold.out.rmode) {
226 printf("(%s) rmode should equal open_mode - 0x%x 0x%x\n",
227 __location__, io.openold.out.rmode, io.openold.in.open_mode);
230 io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_NONE;
231 status = smb_raw_open(cli->tree, tctx, &io);
232 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
234 io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ | OPEN_FLAGS_DENY_NONE;
235 status = smb_raw_open(cli->tree, tctx, &io);
236 CHECK_STATUS(status, NT_STATUS_OK);
237 fnum2 = io.openold.out.file.fnum;
238 CHECK_RDWR(fnum2, RDWR_RDONLY);
239 smbcli_close(cli->tree, fnum);
240 smbcli_close(cli->tree, fnum2);
243 /* check the returned write time */
244 io.openold.level = RAW_OPEN_OPEN;
245 io.openold.in.fname = fname;
246 io.openold.in.search_attrs = 0;
247 io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ;
248 status = smb_raw_open(cli->tree, tctx, &io);
249 CHECK_STATUS(status, NT_STATUS_OK);
250 fnum = io.openold.out.file.fnum;
252 /* check other reply fields */
253 CHECK_TIME(io.openold.out.write_time, write_time);
254 CHECK_ALL_INFO(io.openold.out.size, size);
255 CHECK_ALL_INFO(io.openold.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
258 smbcli_close(cli->tree, fnum);
259 smbcli_unlink(cli->tree, fname);
268 static bool test_openx(struct smbcli_state *cli, struct torture_context *tctx)
271 union smb_fileinfo finfo;
272 const char *fname = BASEDIR "\\torture_openx.txt";
273 const char *fname_exe = BASEDIR "\\torture_openx.exe";
275 int fnum = -1, fnum2;
282 NTSTATUS correct_status;
284 { OPENX_OPEN_FUNC_OPEN, true, NT_STATUS_OK },
285 { OPENX_OPEN_FUNC_OPEN, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
286 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OK },
287 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
288 { OPENX_OPEN_FUNC_FAIL, true, NT_STATUS_DOS(ERRDOS, ERRbadaccess) },
289 { OPENX_OPEN_FUNC_FAIL, false, NT_STATUS_DOS(ERRDOS, ERRbadaccess) },
290 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OBJECT_NAME_COLLISION },
291 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
292 { OPENX_OPEN_FUNC_TRUNC, true, NT_STATUS_OK },
293 { OPENX_OPEN_FUNC_TRUNC, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
294 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OK },
295 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
298 printf("Checking RAW_OPEN_OPENX\n");
299 smbcli_unlink(cli->tree, fname);
301 io.openx.level = RAW_OPEN_OPENX;
302 io.openx.in.fname = fname;
303 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
304 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
305 io.openx.in.search_attrs = 0;
306 io.openx.in.file_attrs = 0;
307 io.openx.in.write_time = 0;
308 io.openx.in.size = 1024*1024;
309 io.openx.in.timeout = 0;
311 /* check all combinations of open_func */
312 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
313 if (open_funcs[i].with_file) {
314 fnum = create_complex_file(cli, tctx, fname);
316 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
320 smbcli_close(cli->tree, fnum);
322 io.openx.in.open_func = open_funcs[i].open_func;
323 status = smb_raw_open(cli->tree, tctx, &io);
324 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
325 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n",
326 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
327 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_func);
330 if (NT_STATUS_IS_OK(status)) {
331 smbcli_close(cli->tree, io.openx.out.file.fnum);
333 if (open_funcs[i].with_file) {
334 smbcli_unlink(cli->tree, fname);
338 smbcli_unlink(cli->tree, fname);
340 /* check the basic return fields */
341 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
342 status = smb_raw_open(cli->tree, tctx, &io);
343 CHECK_STATUS(status, NT_STATUS_OK);
344 fnum = io.openx.out.file.fnum;
346 CHECK_ALL_INFO(io.openx.out.size, size);
347 CHECK_TIME(io.openx.out.write_time, write_time);
348 CHECK_ALL_INFO(io.openx.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
349 CHECK_VAL(io.openx.out.access, OPENX_MODE_ACCESS_RDWR);
350 CHECK_VAL(io.openx.out.ftype, 0);
351 CHECK_VAL(io.openx.out.devstate, 0);
352 CHECK_VAL(io.openx.out.action, OPENX_ACTION_CREATED);
353 CHECK_VAL(io.openx.out.size, 1024*1024);
354 CHECK_ALL_INFO(io.openx.in.size, size);
355 smbcli_close(cli->tree, fnum);
356 smbcli_unlink(cli->tree, fname);
358 /* check the fields when the file already existed */
359 fnum2 = create_complex_file(cli, tctx, fname);
364 smbcli_close(cli->tree, fnum2);
366 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
367 status = smb_raw_open(cli->tree, tctx, &io);
368 CHECK_STATUS(status, NT_STATUS_OK);
369 fnum = io.openx.out.file.fnum;
371 CHECK_ALL_INFO(io.openx.out.size, size);
372 CHECK_TIME(io.openx.out.write_time, write_time);
373 CHECK_VAL(io.openx.out.action, OPENX_ACTION_EXISTED);
374 CHECK_VAL(io.openx.out.unknown, 0);
375 CHECK_ALL_INFO(io.openx.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
376 smbcli_close(cli->tree, fnum);
378 /* now check the search attrib for hidden files - win2003 ignores this? */
379 SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN);
380 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib);
382 io.openx.in.search_attrs = FILE_ATTRIBUTE_HIDDEN;
383 status = smb_raw_open(cli->tree, tctx, &io);
384 CHECK_STATUS(status, NT_STATUS_OK);
385 smbcli_close(cli->tree, io.openx.out.file.fnum);
387 io.openx.in.search_attrs = 0;
388 status = smb_raw_open(cli->tree, tctx, &io);
389 CHECK_STATUS(status, NT_STATUS_OK);
390 smbcli_close(cli->tree, io.openx.out.file.fnum);
392 SET_ATTRIB(FILE_ATTRIBUTE_NORMAL);
393 smbcli_unlink(cli->tree, fname);
395 /* and check attrib on create */
396 io.openx.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE;
397 io.openx.in.search_attrs = 0;
398 io.openx.in.file_attrs = FILE_ATTRIBUTE_SYSTEM;
399 status = smb_raw_open(cli->tree, tctx, &io);
400 CHECK_STATUS(status, NT_STATUS_OK);
401 if (torture_setting_bool(tctx, "samba3", false)) {
402 CHECK_ALL_INFO(FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE,
403 attrib & ~(FILE_ATTRIBUTE_NONINDEXED|
404 FILE_ATTRIBUTE_SPARSE));
407 CHECK_ALL_INFO(FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE,
408 attrib & ~(FILE_ATTRIBUTE_NONINDEXED));
410 smbcli_close(cli->tree, io.openx.out.file.fnum);
411 smbcli_unlink(cli->tree, fname);
413 /* check timeout on create - win2003 ignores the timeout! */
414 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
415 io.openx.in.file_attrs = 0;
416 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL;
417 status = smb_raw_open(cli->tree, tctx, &io);
418 CHECK_STATUS(status, NT_STATUS_OK);
419 fnum = io.openx.out.file.fnum;
421 io.openx.in.timeout = 20000;
422 tv = timeval_current();
423 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_NONE;
424 status = smb_raw_open(cli->tree, tctx, &io);
425 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
426 if (timeval_elapsed(&tv) > 3.0) {
427 printf("(%s) Incorrect timing in openx with timeout - waited %.2f seconds\n",
428 __location__, timeval_elapsed(&tv));
431 smbcli_close(cli->tree, fnum);
432 smbcli_unlink(cli->tree, fname);
434 /* now this is a really weird one - open for execute implies create?! */
435 io.openx.in.fname = fname;
436 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
437 io.openx.in.open_mode = OPENX_MODE_ACCESS_EXEC | OPENX_MODE_DENY_NONE;
438 io.openx.in.search_attrs = 0;
439 io.openx.in.open_func = OPENX_OPEN_FUNC_FAIL;
440 io.openx.in.file_attrs = 0;
441 io.openx.in.write_time = 0;
442 io.openx.in.size = 0;
443 io.openx.in.timeout = 0;
444 status = smb_raw_open(cli->tree, tctx, &io);
445 CHECK_STATUS(status, NT_STATUS_OK);
446 smbcli_close(cli->tree, io.openx.out.file.fnum);
448 /* check the extended return flag */
449 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO | OPENX_FLAGS_EXTENDED_RETURN;
450 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
451 status = smb_raw_open(cli->tree, tctx, &io);
452 CHECK_STATUS(status, NT_STATUS_OK);
453 CHECK_VAL(io.openx.out.access_mask, SEC_STD_ALL);
454 smbcli_close(cli->tree, io.openx.out.file.fnum);
456 io.openx.in.fname = "\\A.+,;=[].B";
457 status = smb_raw_open(cli->tree, tctx, &io);
458 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
460 /* Check the mapping for open exec. */
462 /* First create an .exe file. */
463 smbcli_unlink(cli->tree, fname_exe);
464 fnum = create_complex_file(cli, tctx, fname_exe);
465 smbcli_close(cli->tree, fnum);
467 io.openx.level = RAW_OPEN_OPENX;
468 io.openx.in.fname = fname_exe;
469 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
470 io.openx.in.open_mode = OPENX_MODE_ACCESS_EXEC | OPENX_MODE_DENY_NONE;
471 io.openx.in.search_attrs = 0;
472 io.openx.in.file_attrs = 0;
473 io.openx.in.write_time = 0;
474 io.openx.in.size = 0;
475 io.openx.in.timeout = 0;
476 status = smb_raw_open(cli->tree, tctx, &io);
477 CHECK_STATUS(status, NT_STATUS_OK);
479 /* Can we read and write ? */
480 CHECK_RDWR(io.openx.out.file.fnum, RDWR_RDONLY);
481 smbcli_close(cli->tree, io.openx.out.file.fnum);
482 smbcli_unlink(cli->tree, fname);
485 smbcli_close(cli->tree, fnum);
486 smbcli_unlink(cli->tree, fname_exe);
487 smbcli_unlink(cli->tree, fname);
496 many thanks to kukks for a sniff showing how this works with os2->w2k
498 static bool test_t2open(struct smbcli_state *cli, struct torture_context *tctx)
501 union smb_fileinfo finfo;
502 const char *fname1 = BASEDIR "\\torture_t2open_yes.txt";
503 const char *fname2 = BASEDIR "\\torture_t2open_no.txt";
504 const char *fname = BASEDIR "\\torture_t2open_3.txt";
512 NTSTATUS correct_status;
514 { OPENX_OPEN_FUNC_OPEN, true, NT_STATUS_OK },
515 { OPENX_OPEN_FUNC_OPEN, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
516 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OK },
517 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
518 { OPENX_OPEN_FUNC_FAIL, true, NT_STATUS_OBJECT_NAME_COLLISION },
519 { OPENX_OPEN_FUNC_FAIL, false, NT_STATUS_OBJECT_NAME_COLLISION },
520 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OBJECT_NAME_COLLISION },
521 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OBJECT_NAME_COLLISION },
522 { OPENX_OPEN_FUNC_TRUNC, true, NT_STATUS_OK },
523 { OPENX_OPEN_FUNC_TRUNC, false, NT_STATUS_OK },
524 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OK },
525 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
528 fnum = create_complex_file(cli, tctx, fname1);
530 d_printf("Failed to create file %s - %s\n", fname1, smbcli_errstr(cli->tree));
534 smbcli_close(cli->tree, fnum);
536 printf("Checking RAW_OPEN_T2OPEN\n");
538 io.t2open.level = RAW_OPEN_T2OPEN;
539 io.t2open.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
540 io.t2open.in.open_mode = OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR;
541 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
542 io.t2open.in.search_attrs = 0;
543 io.t2open.in.file_attrs = 0;
544 io.t2open.in.write_time = 0;
545 io.t2open.in.size = 0;
546 io.t2open.in.timeout = 0;
548 io.t2open.in.num_eas = 3;
549 io.t2open.in.eas = talloc_array(tctx, struct ea_struct, io.t2open.in.num_eas);
550 io.t2open.in.eas[0].flags = 0;
551 io.t2open.in.eas[0].name.s = ".CLASSINFO";
552 io.t2open.in.eas[0].value = data_blob_talloc(tctx, "first value", 11);
553 io.t2open.in.eas[1].flags = 0;
554 io.t2open.in.eas[1].name.s = "EA TWO";
555 io.t2open.in.eas[1].value = data_blob_talloc(tctx, "foo", 3);
556 io.t2open.in.eas[2].flags = 0;
557 io.t2open.in.eas[2].name.s = "X THIRD";
558 io.t2open.in.eas[2].value = data_blob_talloc(tctx, "xy", 2);
560 /* check all combinations of open_func */
561 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
563 if (open_funcs[i].with_file) {
564 io.t2open.in.fname = fname1;
566 io.t2open.in.fname = fname2;
568 io.t2open.in.open_func = open_funcs[i].open_func;
569 status = smb_raw_open(cli->tree, tctx, &io);
570 if ((io.t2open.in.num_eas != 0)
571 && NT_STATUS_EQUAL(status, NT_STATUS_EAS_NOT_SUPPORTED)
572 && torture_setting_bool(tctx, "samba3", false)) {
573 printf("(%s) EAs not supported, not treating as fatal "
574 "in Samba3 test\n", __location__);
575 io.t2open.in.num_eas = 0;
579 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
580 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n",
581 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
582 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_func);
585 if (NT_STATUS_IS_OK(status)) {
586 smbcli_close(cli->tree, io.t2open.out.file.fnum);
590 smbcli_unlink(cli->tree, fname1);
591 smbcli_unlink(cli->tree, fname2);
593 /* check the basic return fields */
594 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
595 io.t2open.in.write_time = 0;
596 io.t2open.in.fname = fname;
597 status = smb_raw_open(cli->tree, tctx, &io);
598 CHECK_STATUS(status, NT_STATUS_OK);
599 fnum = io.t2open.out.file.fnum;
601 CHECK_ALL_INFO(io.t2open.out.size, size);
603 /* windows appears to leak uninitialised memory here */
604 CHECK_VAL(io.t2open.out.write_time, 0);
606 CHECK_ALL_INFO(io.t2open.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
607 CHECK_VAL(io.t2open.out.access, OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR);
608 CHECK_VAL(io.t2open.out.ftype, 0);
609 CHECK_VAL(io.t2open.out.devstate, 0);
610 CHECK_VAL(io.t2open.out.action, OPENX_ACTION_CREATED);
611 smbcli_close(cli->tree, fnum);
613 status = torture_check_ea(cli, fname, ".CLASSINFO", "first value");
614 CHECK_STATUS(status, io.t2open.in.num_eas
615 ? NT_STATUS_OK : NT_STATUS_EAS_NOT_SUPPORTED);
616 status = torture_check_ea(cli, fname, "EA TWO", "foo");
617 CHECK_STATUS(status, io.t2open.in.num_eas
618 ? NT_STATUS_OK : NT_STATUS_EAS_NOT_SUPPORTED);
619 status = torture_check_ea(cli, fname, "X THIRD", "xy");
620 CHECK_STATUS(status, io.t2open.in.num_eas
621 ? NT_STATUS_OK : NT_STATUS_EAS_NOT_SUPPORTED);
623 /* now check the search attrib for hidden files - win2003 ignores this? */
624 SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN);
625 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib);
627 status = smb_raw_open(cli->tree, tctx, &io);
628 CHECK_STATUS(status, NT_STATUS_OK);
629 smbcli_close(cli->tree, io.t2open.out.file.fnum);
631 status = smb_raw_open(cli->tree, tctx, &io);
632 CHECK_STATUS(status, NT_STATUS_OK);
633 smbcli_close(cli->tree, io.t2open.out.file.fnum);
635 SET_ATTRIB(FILE_ATTRIBUTE_NORMAL);
636 smbcli_unlink(cli->tree, fname);
638 /* and check attrib on create */
639 io.t2open.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE;
640 io.t2open.in.file_attrs = FILE_ATTRIBUTE_SYSTEM;
641 status = smb_raw_open(cli->tree, tctx, &io);
642 CHECK_STATUS(status, NT_STATUS_OK);
644 /* check timeout on create - win2003 ignores the timeout! */
645 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
646 io.t2open.in.file_attrs = 0;
647 io.t2open.in.timeout = 20000;
648 io.t2open.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL;
649 status = smb_raw_open(cli->tree, tctx, &io);
650 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
653 smbcli_close(cli->tree, fnum);
654 smbcli_unlink(cli->tree, fname);
661 test RAW_OPEN_NTCREATEX
663 static bool test_ntcreatex(struct smbcli_state *cli, struct torture_context *tctx)
666 union smb_fileinfo finfo;
667 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
668 const char *dname = BASEDIR "\\torture_ntcreatex.dir";
676 NTSTATUS correct_status;
678 { NTCREATEX_DISP_SUPERSEDE, true, NT_STATUS_OK },
679 { NTCREATEX_DISP_SUPERSEDE, false, NT_STATUS_OK },
680 { NTCREATEX_DISP_OPEN, true, NT_STATUS_OK },
681 { NTCREATEX_DISP_OPEN, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
682 { NTCREATEX_DISP_CREATE, true, NT_STATUS_OBJECT_NAME_COLLISION },
683 { NTCREATEX_DISP_CREATE, false, NT_STATUS_OK },
684 { NTCREATEX_DISP_OPEN_IF, true, NT_STATUS_OK },
685 { NTCREATEX_DISP_OPEN_IF, false, NT_STATUS_OK },
686 { NTCREATEX_DISP_OVERWRITE, true, NT_STATUS_OK },
687 { NTCREATEX_DISP_OVERWRITE, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
688 { NTCREATEX_DISP_OVERWRITE_IF, true, NT_STATUS_OK },
689 { NTCREATEX_DISP_OVERWRITE_IF, false, NT_STATUS_OK },
690 { 6, true, NT_STATUS_INVALID_PARAMETER },
691 { 6, false, NT_STATUS_INVALID_PARAMETER },
694 printf("Checking RAW_OPEN_NTCREATEX\n");
696 /* reasonable default parameters */
697 io.generic.level = RAW_OPEN_NTCREATEX;
698 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
699 io.ntcreatex.in.root_fid = 0;
700 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
701 io.ntcreatex.in.alloc_size = 1024*1024;
702 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
703 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
704 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
705 io.ntcreatex.in.create_options = 0;
706 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
707 io.ntcreatex.in.security_flags = 0;
708 io.ntcreatex.in.fname = fname;
710 /* test the open disposition */
711 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
712 if (open_funcs[i].with_file) {
713 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE);
715 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
719 smbcli_close(cli->tree, fnum);
721 io.ntcreatex.in.open_disposition = open_funcs[i].open_disp;
722 status = smb_raw_open(cli->tree, tctx, &io);
723 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
724 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_disp=%d)\n",
725 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
726 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_disp);
729 if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
730 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
731 smbcli_unlink(cli->tree, fname);
735 /* basic field testing */
736 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
738 status = smb_raw_open(cli->tree, tctx, &io);
739 CHECK_STATUS(status, NT_STATUS_OK);
740 fnum = io.ntcreatex.out.file.fnum;
742 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
743 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
744 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
745 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
746 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
747 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
748 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
749 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
750 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
751 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
752 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
754 /* check fields when the file already existed */
755 smbcli_close(cli->tree, fnum);
756 smbcli_unlink(cli->tree, fname);
757 fnum = create_complex_file(cli, tctx, fname);
762 smbcli_close(cli->tree, fnum);
764 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
765 status = smb_raw_open(cli->tree, tctx, &io);
766 CHECK_STATUS(status, NT_STATUS_OK);
767 fnum = io.ntcreatex.out.file.fnum;
769 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
770 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
771 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
772 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
773 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
774 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
775 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
776 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
777 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
778 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
779 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
780 smbcli_close(cli->tree, fnum);
781 smbcli_unlink(cli->tree, fname);
784 /* create a directory */
785 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
786 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
787 io.ntcreatex.in.alloc_size = 0;
788 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
789 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
790 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
791 io.ntcreatex.in.create_options = 0;
792 io.ntcreatex.in.fname = dname;
795 smbcli_rmdir(cli->tree, fname);
796 smbcli_unlink(cli->tree, fname);
798 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
799 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
800 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
801 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
802 status = smb_raw_open(cli->tree, tctx, &io);
803 CHECK_STATUS(status, NT_STATUS_OK);
804 fnum = io.ntcreatex.out.file.fnum;
806 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
807 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
808 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
809 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
810 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
811 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
812 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
813 CHECK_VAL(io.ntcreatex.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED,
814 FILE_ATTRIBUTE_DIRECTORY);
815 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
816 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
817 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
818 CHECK_VAL(io.ntcreatex.out.is_directory, 1);
819 CHECK_VAL(io.ntcreatex.out.size, 0);
820 CHECK_VAL(io.ntcreatex.out.alloc_size, 0);
821 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
822 smbcli_unlink(cli->tree, fname);
826 smbcli_close(cli->tree, fnum);
827 smbcli_unlink(cli->tree, fname);
834 test RAW_OPEN_NTTRANS_CREATE
836 static bool test_nttrans_create(struct smbcli_state *cli, struct torture_context *tctx)
839 union smb_fileinfo finfo;
840 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
841 const char *dname = BASEDIR "\\torture_ntcreatex.dir";
849 NTSTATUS correct_status;
851 { NTCREATEX_DISP_SUPERSEDE, true, NT_STATUS_OK },
852 { NTCREATEX_DISP_SUPERSEDE, false, NT_STATUS_OK },
853 { NTCREATEX_DISP_OPEN, true, NT_STATUS_OK },
854 { NTCREATEX_DISP_OPEN, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
855 { NTCREATEX_DISP_CREATE, true, NT_STATUS_OBJECT_NAME_COLLISION },
856 { NTCREATEX_DISP_CREATE, false, NT_STATUS_OK },
857 { NTCREATEX_DISP_OPEN_IF, true, NT_STATUS_OK },
858 { NTCREATEX_DISP_OPEN_IF, false, NT_STATUS_OK },
859 { NTCREATEX_DISP_OVERWRITE, true, NT_STATUS_OK },
860 { NTCREATEX_DISP_OVERWRITE, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
861 { NTCREATEX_DISP_OVERWRITE_IF, true, NT_STATUS_OK },
862 { NTCREATEX_DISP_OVERWRITE_IF, false, NT_STATUS_OK },
863 { 6, true, NT_STATUS_INVALID_PARAMETER },
864 { 6, false, NT_STATUS_INVALID_PARAMETER },
867 printf("Checking RAW_OPEN_NTTRANS_CREATE\n");
869 /* reasonable default parameters */
870 io.generic.level = RAW_OPEN_NTTRANS_CREATE;
871 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
872 io.ntcreatex.in.root_fid = 0;
873 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
874 io.ntcreatex.in.alloc_size = 1024*1024;
875 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
876 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
877 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
878 io.ntcreatex.in.create_options = 0;
879 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
880 io.ntcreatex.in.security_flags = 0;
881 io.ntcreatex.in.fname = fname;
882 io.ntcreatex.in.sec_desc = NULL;
883 io.ntcreatex.in.ea_list = NULL;
885 /* test the open disposition */
886 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
887 if (open_funcs[i].with_file) {
888 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE);
890 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
894 smbcli_close(cli->tree, fnum);
896 io.ntcreatex.in.open_disposition = open_funcs[i].open_disp;
897 status = smb_raw_open(cli->tree, tctx, &io);
898 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
899 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_disp=%d)\n",
900 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
901 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_disp);
904 if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
905 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
906 smbcli_unlink(cli->tree, fname);
910 /* basic field testing */
911 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
913 status = smb_raw_open(cli->tree, tctx, &io);
914 CHECK_STATUS(status, NT_STATUS_OK);
915 fnum = io.ntcreatex.out.file.fnum;
917 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
918 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
919 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
920 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
921 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
922 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
923 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
924 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
925 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
926 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
927 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
929 /* check fields when the file already existed */
930 smbcli_close(cli->tree, fnum);
931 smbcli_unlink(cli->tree, fname);
932 fnum = create_complex_file(cli, tctx, fname);
937 smbcli_close(cli->tree, fnum);
939 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
940 status = smb_raw_open(cli->tree, tctx, &io);
941 CHECK_STATUS(status, NT_STATUS_OK);
942 fnum = io.ntcreatex.out.file.fnum;
944 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
945 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
946 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
947 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
948 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
949 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
950 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
951 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
952 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
953 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
954 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
955 smbcli_close(cli->tree, fnum);
956 smbcli_unlink(cli->tree, fname);
959 /* create a directory */
960 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
961 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
962 io.ntcreatex.in.alloc_size = 0;
963 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
964 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
965 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
966 io.ntcreatex.in.create_options = 0;
967 io.ntcreatex.in.fname = dname;
970 smbcli_rmdir(cli->tree, fname);
971 smbcli_unlink(cli->tree, fname);
973 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
974 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
975 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
976 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
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_CREATED);
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_VAL(io.ntcreatex.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED,
989 FILE_ATTRIBUTE_DIRECTORY);
990 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
991 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
992 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
993 CHECK_VAL(io.ntcreatex.out.is_directory, 1);
994 CHECK_VAL(io.ntcreatex.out.size, 0);
995 CHECK_VAL(io.ntcreatex.out.alloc_size, 0);
996 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
997 smbcli_unlink(cli->tree, fname);
1001 smbcli_close(cli->tree, fnum);
1002 smbcli_unlink(cli->tree, fname);
1008 test RAW_OPEN_NTCREATEX with an already opened and byte range locked file
1010 I've got an application that does a similar sequence of ntcreate&x,
1011 locking&x and another ntcreate&x with
1012 open_disposition==NTCREATEX_DISP_OVERWRITE_IF. Windows 2003 allows the
1015 static bool test_ntcreatex_brlocked(struct smbcli_state *cli, struct torture_context *tctx)
1017 union smb_open io, io1;
1019 struct smb_lock_entry lock[1];
1020 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
1024 printf("Testing ntcreatex with a byte range locked file\n");
1026 io.generic.level = RAW_OPEN_NTCREATEX;
1027 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
1028 io.ntcreatex.in.root_fid = 0;
1029 io.ntcreatex.in.access_mask = 0x2019f;
1030 io.ntcreatex.in.alloc_size = 0;
1031 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1032 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1033 NTCREATEX_SHARE_ACCESS_WRITE;
1034 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1035 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
1036 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
1037 io.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC |
1038 NTCREATEX_SECURITY_ALL;
1039 io.ntcreatex.in.fname = fname;
1041 status = smb_raw_open(cli->tree, tctx, &io);
1042 CHECK_STATUS(status, NT_STATUS_OK);
1044 io2.lockx.level = RAW_LOCK_LOCKX;
1045 io2.lockx.in.file.fnum = io.ntcreatex.out.file.fnum;
1046 io2.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
1047 io2.lockx.in.timeout = 0;
1048 io2.lockx.in.ulock_cnt = 0;
1049 io2.lockx.in.lock_cnt = 1;
1050 lock[0].pid = cli->session->pid;
1052 lock[0].count = 0x1;
1053 io2.lockx.in.locks = &lock[0];
1054 status = smb_raw_lock(cli->tree, &io2);
1055 CHECK_STATUS(status, NT_STATUS_OK);
1057 io1.generic.level = RAW_OPEN_NTCREATEX;
1058 io1.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
1059 io1.ntcreatex.in.root_fid = 0;
1060 io1.ntcreatex.in.access_mask = 0x20196;
1061 io1.ntcreatex.in.alloc_size = 0;
1062 io1.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1063 io1.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1064 NTCREATEX_SHARE_ACCESS_WRITE;
1065 io1.ntcreatex.in.open_disposition = NTCREATEX_DISP_OVERWRITE_IF;
1066 io1.ntcreatex.in.create_options = 0;
1067 io1.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
1068 io1.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC |
1069 NTCREATEX_SECURITY_ALL;
1070 io1.ntcreatex.in.fname = fname;
1072 status = smb_raw_open(cli->tree, tctx, &io1);
1073 CHECK_STATUS(status, NT_STATUS_OK);
1076 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
1077 smbcli_close(cli->tree, io1.ntcreatex.out.file.fnum);
1078 smbcli_unlink(cli->tree, fname);
1085 static bool test_mknew(struct smbcli_state *cli, struct torture_context *tctx)
1088 const char *fname = BASEDIR "\\torture_mknew.txt";
1092 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1093 union smb_fileinfo finfo;
1095 printf("Checking RAW_OPEN_MKNEW\n");
1097 io.mknew.level = RAW_OPEN_MKNEW;
1098 io.mknew.in.attrib = 0;
1099 io.mknew.in.write_time = 0;
1100 io.mknew.in.fname = fname;
1101 status = smb_raw_open(cli->tree, tctx, &io);
1102 CHECK_STATUS(status, NT_STATUS_OK);
1103 fnum = io.mknew.out.file.fnum;
1105 status = smb_raw_open(cli->tree, tctx, &io);
1106 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
1108 smbcli_close(cli->tree, fnum);
1109 smbcli_unlink(cli->tree, fname);
1111 /* make sure write_time works */
1112 io.mknew.in.write_time = basetime;
1113 status = smb_raw_open(cli->tree, tctx, &io);
1114 CHECK_STATUS(status, NT_STATUS_OK);
1115 fnum = io.mknew.out.file.fnum;
1116 CHECK_TIME(basetime, write_time);
1118 smbcli_close(cli->tree, fnum);
1119 smbcli_unlink(cli->tree, fname);
1121 /* make sure file_attrs works */
1122 io.mknew.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1123 status = smb_raw_open(cli->tree, tctx, &io);
1124 CHECK_STATUS(status, NT_STATUS_OK);
1125 fnum = io.mknew.out.file.fnum;
1126 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE,
1127 attrib & ~FILE_ATTRIBUTE_NONINDEXED);
1130 smbcli_close(cli->tree, fnum);
1131 smbcli_unlink(cli->tree, fname);
1138 test RAW_OPEN_CREATE
1140 static bool test_create(struct smbcli_state *cli, struct torture_context *tctx)
1143 const char *fname = BASEDIR "\\torture_create.txt";
1147 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1148 union smb_fileinfo finfo;
1150 printf("Checking RAW_OPEN_CREATE\n");
1152 io.create.level = RAW_OPEN_CREATE;
1153 io.create.in.attrib = 0;
1154 io.create.in.write_time = 0;
1155 io.create.in.fname = fname;
1156 status = smb_raw_open(cli->tree, tctx, &io);
1157 CHECK_STATUS(status, NT_STATUS_OK);
1158 fnum = io.create.out.file.fnum;
1160 status = smb_raw_open(cli->tree, tctx, &io);
1161 CHECK_STATUS(status, NT_STATUS_OK);
1163 smbcli_close(cli->tree, io.create.out.file.fnum);
1164 smbcli_close(cli->tree, fnum);
1165 smbcli_unlink(cli->tree, fname);
1167 /* make sure write_time works */
1168 io.create.in.write_time = basetime;
1169 status = smb_raw_open(cli->tree, tctx, &io);
1170 CHECK_STATUS(status, NT_STATUS_OK);
1171 fnum = io.create.out.file.fnum;
1172 CHECK_TIME(basetime, write_time);
1174 smbcli_close(cli->tree, fnum);
1175 smbcli_unlink(cli->tree, fname);
1177 /* make sure file_attrs works */
1178 io.create.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1179 status = smb_raw_open(cli->tree, tctx, &io);
1180 CHECK_STATUS(status, NT_STATUS_OK);
1181 fnum = io.create.out.file.fnum;
1182 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE,
1183 attrib & ~FILE_ATTRIBUTE_NONINDEXED);
1186 smbcli_close(cli->tree, fnum);
1187 smbcli_unlink(cli->tree, fname);
1196 static bool test_ctemp(struct smbcli_state *cli, TALLOC_CTX *tctx)
1202 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1203 union smb_fileinfo finfo;
1204 const char *name, *fname = NULL;
1206 printf("Checking RAW_OPEN_CTEMP\n");
1208 io.ctemp.level = RAW_OPEN_CTEMP;
1209 io.ctemp.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1210 io.ctemp.in.write_time = basetime;
1211 io.ctemp.in.directory = BASEDIR;
1212 status = smb_raw_open(cli->tree, tctx, &io);
1213 CHECK_STATUS(status, NT_STATUS_OK);
1214 fnum = io.ctemp.out.file.fnum;
1216 name = io.ctemp.out.name;
1218 finfo.generic.level = RAW_FILEINFO_NAME_INFO;
1219 finfo.generic.in.file.fnum = fnum;
1220 status = smb_raw_fileinfo(cli->tree, tctx, &finfo);
1221 CHECK_STATUS(status, NT_STATUS_OK);
1223 fname = finfo.name_info.out.fname.s;
1224 d_printf("ctemp name=%s real name=%s\n", name, fname);
1227 smbcli_close(cli->tree, fnum);
1229 smbcli_unlink(cli->tree, fname);
1237 test chained RAW_OPEN_OPENX_READX
1239 static bool test_chained(struct smbcli_state *cli, TALLOC_CTX *tctx)
1242 const char *fname = BASEDIR "\\torture_chained.txt";
1246 const char *buf = "test";
1249 printf("Checking RAW_OPEN_OPENX chained with READX\n");
1250 smbcli_unlink(cli->tree, fname);
1252 fnum = create_complex_file(cli, tctx, fname);
1254 smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf));
1256 smbcli_close(cli->tree, fnum);
1258 io.openxreadx.level = RAW_OPEN_OPENX_READX;
1259 io.openxreadx.in.fname = fname;
1260 io.openxreadx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
1261 io.openxreadx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
1262 io.openxreadx.in.open_func = OPENX_OPEN_FUNC_OPEN;
1263 io.openxreadx.in.search_attrs = 0;
1264 io.openxreadx.in.file_attrs = 0;
1265 io.openxreadx.in.write_time = 0;
1266 io.openxreadx.in.size = 1024*1024;
1267 io.openxreadx.in.timeout = 0;
1269 io.openxreadx.in.offset = 0;
1270 io.openxreadx.in.mincnt = sizeof(buf);
1271 io.openxreadx.in.maxcnt = sizeof(buf);
1272 io.openxreadx.in.remaining = 0;
1273 io.openxreadx.out.data = (uint8_t *)buf2;
1275 status = smb_raw_open(cli->tree, tctx, &io);
1276 CHECK_STATUS(status, NT_STATUS_OK);
1277 fnum = io.openxreadx.out.file.fnum;
1279 if (memcmp(buf, buf2, sizeof(buf)) != 0) {
1280 d_printf("wrong data in reply buffer\n");
1285 smbcli_close(cli->tree, fnum);
1286 smbcli_unlink(cli->tree, fname);
1292 test RAW_OPEN_OPENX without a leading slash on the path.
1293 NetApp filers are known to fail on this.
1296 static bool test_no_leading_slash(struct smbcli_state *cli, TALLOC_CTX *tctx)
1299 const char *fname = BASEDIR "\\torture_no_leading_slash.txt";
1303 const char *buf = "test";
1305 printf("Checking RAW_OPEN_OPENX without leading slash on path\n");
1306 smbcli_unlink(cli->tree, fname);
1308 /* Create the file */
1309 fnum = create_complex_file(cli, tctx, fname);
1310 smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf));
1311 smbcli_close(cli->tree, fnum);
1313 /* Prepare to open the file using path without leading slash */
1314 io.openx.level = RAW_OPEN_OPENX;
1315 io.openx.in.fname = fname + 1;
1316 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
1317 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
1318 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
1319 io.openx.in.search_attrs = 0;
1320 io.openx.in.file_attrs = 0;
1321 io.openx.in.write_time = 0;
1322 io.openx.in.size = 1024*1024;
1323 io.openx.in.timeout = 0;
1325 status = smb_raw_open(cli->tree, tctx, &io);
1326 CHECK_STATUS(status, NT_STATUS_OK);
1327 fnum = io.openx.out.file.fnum;
1330 smbcli_close(cli->tree, fnum);
1331 smbcli_unlink(cli->tree, fname);
1336 /* A little torture test to expose a race condition in Samba 3.0.20 ... :-) */
1338 static bool test_raw_open_multi(struct torture_context *tctx)
1340 struct smbcli_state *cli;
1341 TALLOC_CTX *mem_ctx = talloc_init("torture_test_oplock_multi");
1342 const char *fname = "\\test_oplock.dat";
1346 struct smbcli_state **clients;
1347 struct smbcli_request **requests;
1348 union smb_open *ios;
1349 const char *host = torture_setting_string(tctx, "host", NULL);
1350 const char *share = torture_setting_string(tctx, "share", NULL);
1351 int i, num_files = 3;
1352 struct event_context *ev;
1354 int num_collision = 0;
1356 ev = cli_credentials_get_event_context(cmdline_credentials);
1357 clients = talloc_array(mem_ctx, struct smbcli_state *, num_files);
1358 requests = talloc_array(mem_ctx, struct smbcli_request *, num_files);
1359 ios = talloc_array(mem_ctx, union smb_open, num_files);
1360 if ((ev == NULL) || (clients == NULL) || (requests == NULL) ||
1362 DEBUG(0, ("talloc failed\n"));
1366 if (!torture_open_connection_share(mem_ctx, &cli, host, share, ev)) {
1370 cli->tree->session->transport->options.request_timeout = 60000;
1372 for (i=0; i<num_files; i++) {
1373 if (!torture_open_connection_share(mem_ctx, &(clients[i]),
1375 DEBUG(0, ("Could not open %d'th connection\n", i));
1378 clients[i]->tree->session->transport->
1379 options.request_timeout = 60000;
1383 smbcli_unlink(cli->tree, fname);
1386 base ntcreatex parms
1388 io.generic.level = RAW_OPEN_NTCREATEX;
1389 io.ntcreatex.in.root_fid = 0;
1390 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
1391 io.ntcreatex.in.alloc_size = 0;
1392 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1393 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ|
1394 NTCREATEX_SHARE_ACCESS_WRITE|
1395 NTCREATEX_SHARE_ACCESS_DELETE;
1396 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1397 io.ntcreatex.in.create_options = 0;
1398 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1399 io.ntcreatex.in.security_flags = 0;
1400 io.ntcreatex.in.fname = fname;
1401 io.ntcreatex.in.flags = 0;
1403 for (i=0; i<num_files; i++) {
1405 requests[i] = smb_raw_open_send(clients[i]->tree, &ios[i]);
1406 if (requests[i] == NULL) {
1407 DEBUG(0, ("could not send %d'th request\n", i));
1412 DEBUG(10, ("waiting for replies\n"));
1414 bool unreplied = false;
1415 for (i=0; i<num_files; i++) {
1416 if (requests[i] == NULL) {
1419 if (requests[i]->state < SMBCLI_REQUEST_DONE) {
1423 status = smb_raw_open_recv(requests[i], mem_ctx,
1426 DEBUG(0, ("File %d returned status %s\n", i,
1427 nt_errstr(status)));
1429 if (NT_STATUS_IS_OK(status)) {
1433 if (NT_STATUS_EQUAL(status,
1434 NT_STATUS_OBJECT_NAME_COLLISION)) {
1444 if (event_loop_once(ev) != 0) {
1445 DEBUG(0, ("event_loop_once failed\n"));
1450 if ((num_ok != 1) || (num_ok + num_collision != num_files)) {
1454 for (i=0; i<num_files; i++) {
1455 torture_close_connection(clients[i]);
1457 talloc_free(mem_ctx);
1461 /* basic testing of all RAW_OPEN_* calls
1463 bool torture_raw_open(struct torture_context *torture, struct smbcli_state *cli)
1467 if (!torture_setup_dir(cli, BASEDIR)) {
1471 ret &= test_ntcreatex_brlocked(cli, torture);
1472 ret &= test_open(cli, torture);
1473 ret &= test_raw_open_multi(torture);
1474 ret &= test_openx(cli, torture);
1475 ret &= test_ntcreatex(cli, torture);
1476 ret &= test_nttrans_create(cli, torture);
1477 ret &= test_t2open(cli, torture);
1478 ret &= test_mknew(cli, torture);
1479 ret &= test_create(cli, torture);
1480 ret &= test_ctemp(cli, torture);
1481 ret &= test_chained(cli, torture);
1482 ret &= test_no_leading_slash(cli, torture);
1484 smb_raw_exit(cli->session);
1485 smbcli_deltree(cli->tree, BASEDIR);