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"
32 /* enum for whether reads/writes are possible on a file */
33 enum rdwr_mode {RDWR_NONE, RDWR_RDONLY, RDWR_WRONLY, RDWR_RDWR};
35 #define BASEDIR "\\rawopen"
38 check if a open file can be read/written
40 static enum rdwr_mode check_rdwr(struct smbcli_tree *tree, int fnum)
43 BOOL can_read = (smbcli_read(tree, fnum, &c, 0, 1) == 1);
44 BOOL can_write = (smbcli_write(tree, fnum, 0, &c, 0, 1) == 1);
45 if ( can_read && can_write) return RDWR_RDWR;
46 if ( can_read && !can_write) return RDWR_RDONLY;
47 if (!can_read && can_write) return RDWR_WRONLY;
52 describe a RDWR mode as a string
54 static const char *rdwr_string(enum rdwr_mode m)
57 case RDWR_NONE: return "NONE";
58 case RDWR_RDONLY: return "RDONLY";
59 case RDWR_WRONLY: return "WRONLY";
60 case RDWR_RDWR: return "RDWR";
65 #define CHECK_STATUS(status, correct) do { \
66 if (!NT_STATUS_EQUAL(status, correct)) { \
67 printf("(%s) Incorrect status %s - should be %s\n", \
68 __location__, nt_errstr(status), nt_errstr(correct)); \
73 #define CREATE_FILE do { \
74 fnum = create_complex_file(cli, mem_ctx, fname); \
76 printf("(%s) Failed to create %s - %s\n", __location__, fname, smbcli_errstr(cli->tree)); \
81 #define CHECK_RDWR(fnum, correct) do { \
82 enum rdwr_mode m = check_rdwr(cli->tree, fnum); \
84 printf("(%s) Incorrect readwrite mode %s - expected %s\n", \
85 __location__, rdwr_string(m), rdwr_string(correct)); \
89 #define CHECK_TIME(t, field) do { \
91 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
92 finfo.all_info.in.file.path = fname; \
93 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo); \
94 CHECK_STATUS(status, NT_STATUS_OK); \
96 t2 = nt_time_to_unix(finfo.all_info.out.field) & ~1; \
97 if (abs(t1-t2) > 2) { \
98 printf("(%s) wrong time for field %s %s - %s\n", \
99 __location__, #field, \
100 timestring(mem_ctx, t1), \
101 timestring(mem_ctx, t2)); \
102 dump_all_info(mem_ctx, &finfo); \
106 #define CHECK_NTTIME(t, field) do { \
108 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
109 finfo.all_info.in.file.path = fname; \
110 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo); \
111 CHECK_STATUS(status, NT_STATUS_OK); \
112 t2 = finfo.all_info.out.field; \
114 printf("(%s) wrong time for field %s %s - %s\n", \
115 __location__, #field, \
116 nt_time_string(mem_ctx, t), \
117 nt_time_string(mem_ctx, t2)); \
118 dump_all_info(mem_ctx, &finfo); \
122 #define CHECK_ALL_INFO(v, field) do { \
123 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
124 finfo.all_info.in.file.path = fname; \
125 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo); \
126 CHECK_STATUS(status, NT_STATUS_OK); \
127 if ((v) != (finfo.all_info.out.field)) { \
128 printf("(%s) wrong value for field %s 0x%x - 0x%x\n", \
129 __location__, #field, (int)v, (int)(finfo.all_info.out.field)); \
130 dump_all_info(mem_ctx, &finfo); \
134 #define CHECK_VAL(v, correct) do { \
135 if ((v) != (correct)) { \
136 printf("(%s) wrong value for %s 0x%x - should be 0x%x\n", \
137 __location__, #v, (int)(v), (int)correct); \
141 #define SET_ATTRIB(sattrib) do { \
142 union smb_setfileinfo sfinfo; \
143 ZERO_STRUCT(sfinfo.basic_info.in); \
144 sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFORMATION; \
145 sfinfo.basic_info.in.file.path = fname; \
146 sfinfo.basic_info.in.attrib = sattrib; \
147 status = smb_raw_setpathinfo(cli->tree, &sfinfo); \
148 if (!NT_STATUS_IS_OK(status)) { \
149 printf("(%s) Failed to set attrib 0x%x on %s\n", \
150 __location__, sattrib, fname); \
156 static BOOL test_open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
159 union smb_fileinfo finfo;
160 const char *fname = BASEDIR "\\torture_open.txt";
162 int fnum = -1, fnum2;
165 printf("Checking RAW_OPEN_OPEN\n");
167 io.openold.level = RAW_OPEN_OPEN;
168 io.openold.in.fname = fname;
169 io.openold.in.open_mode = OPEN_FLAGS_FCB;
170 io.openold.in.search_attrs = 0;
171 status = smb_raw_open(cli->tree, mem_ctx, &io);
172 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
173 fnum = io.openold.out.file.fnum;
175 smbcli_unlink(cli->tree, fname);
177 smbcli_close(cli->tree, fnum);
179 status = smb_raw_open(cli->tree, mem_ctx, &io);
180 CHECK_STATUS(status, NT_STATUS_OK);
181 fnum = io.openold.out.file.fnum;
182 CHECK_RDWR(fnum, RDWR_RDWR);
184 status = smb_raw_open(cli->tree, mem_ctx, &io);
185 CHECK_STATUS(status, NT_STATUS_OK);
186 fnum2 = io.openold.out.file.fnum;
187 CHECK_RDWR(fnum2, RDWR_RDWR);
188 smbcli_close(cli->tree, fnum2);
189 smbcli_close(cli->tree, fnum);
191 /* check the read/write modes */
192 io.openold.level = RAW_OPEN_OPEN;
193 io.openold.in.fname = fname;
194 io.openold.in.search_attrs = 0;
196 io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ;
197 status = smb_raw_open(cli->tree, mem_ctx, &io);
198 CHECK_STATUS(status, NT_STATUS_OK);
199 fnum = io.openold.out.file.fnum;
200 CHECK_RDWR(fnum, RDWR_RDONLY);
201 smbcli_close(cli->tree, fnum);
203 io.openold.in.open_mode = OPEN_FLAGS_OPEN_WRITE;
204 status = smb_raw_open(cli->tree, mem_ctx, &io);
205 CHECK_STATUS(status, NT_STATUS_OK);
206 fnum = io.openold.out.file.fnum;
207 CHECK_RDWR(fnum, RDWR_WRONLY);
208 smbcli_close(cli->tree, fnum);
210 io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR;
211 status = smb_raw_open(cli->tree, mem_ctx, &io);
212 CHECK_STATUS(status, NT_STATUS_OK);
213 fnum = io.openold.out.file.fnum;
214 CHECK_RDWR(fnum, RDWR_RDWR);
215 smbcli_close(cli->tree, fnum);
217 /* check the share modes roughly - not a complete matrix */
218 io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_WRITE;
219 status = smb_raw_open(cli->tree, mem_ctx, &io);
220 CHECK_STATUS(status, NT_STATUS_OK);
221 fnum = io.openold.out.file.fnum;
222 CHECK_RDWR(fnum, RDWR_RDWR);
224 if (io.openold.in.open_mode != io.openold.out.rmode) {
225 printf("(%s) rmode should equal open_mode - 0x%x 0x%x\n",
226 __location__, io.openold.out.rmode, io.openold.in.open_mode);
229 io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_NONE;
230 status = smb_raw_open(cli->tree, mem_ctx, &io);
231 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
233 io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ | OPEN_FLAGS_DENY_NONE;
234 status = smb_raw_open(cli->tree, mem_ctx, &io);
235 CHECK_STATUS(status, NT_STATUS_OK);
236 fnum2 = io.openold.out.file.fnum;
237 CHECK_RDWR(fnum2, RDWR_RDONLY);
238 smbcli_close(cli->tree, fnum);
239 smbcli_close(cli->tree, fnum2);
242 /* check the returned write time */
243 io.openold.level = RAW_OPEN_OPEN;
244 io.openold.in.fname = fname;
245 io.openold.in.search_attrs = 0;
246 io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ;
247 status = smb_raw_open(cli->tree, mem_ctx, &io);
248 CHECK_STATUS(status, NT_STATUS_OK);
249 fnum = io.openold.out.file.fnum;
251 /* check other reply fields */
252 CHECK_TIME(io.openold.out.write_time, write_time);
253 CHECK_ALL_INFO(io.openold.out.size, size);
254 CHECK_ALL_INFO(io.openold.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
257 smbcli_close(cli->tree, fnum);
258 smbcli_unlink(cli->tree, fname);
267 static BOOL test_openx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
270 union smb_fileinfo finfo;
271 const char *fname = BASEDIR "\\torture_openx.txt";
272 const char *fname_exe = BASEDIR "\\torture_openx.exe";
274 int fnum = -1, fnum2;
281 NTSTATUS correct_status;
283 { OPENX_OPEN_FUNC_OPEN, True, NT_STATUS_OK },
284 { OPENX_OPEN_FUNC_OPEN, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
285 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OK },
286 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
287 { OPENX_OPEN_FUNC_FAIL, True, NT_STATUS_DOS(ERRDOS, ERRbadaccess) },
288 { OPENX_OPEN_FUNC_FAIL, False, NT_STATUS_DOS(ERRDOS, ERRbadaccess) },
289 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OBJECT_NAME_COLLISION },
290 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
291 { OPENX_OPEN_FUNC_TRUNC, True, NT_STATUS_OK },
292 { OPENX_OPEN_FUNC_TRUNC, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
293 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OK },
294 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
297 printf("Checking RAW_OPEN_OPENX\n");
298 smbcli_unlink(cli->tree, fname);
300 io.openx.level = RAW_OPEN_OPENX;
301 io.openx.in.fname = fname;
302 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
303 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
304 io.openx.in.search_attrs = 0;
305 io.openx.in.file_attrs = 0;
306 io.openx.in.write_time = 0;
307 io.openx.in.size = 1024*1024;
308 io.openx.in.timeout = 0;
310 /* check all combinations of open_func */
311 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
312 if (open_funcs[i].with_file) {
313 fnum = create_complex_file(cli, mem_ctx, fname);
315 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
319 smbcli_close(cli->tree, fnum);
321 io.openx.in.open_func = open_funcs[i].open_func;
322 status = smb_raw_open(cli->tree, mem_ctx, &io);
323 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
324 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n",
325 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
326 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_func);
329 if (NT_STATUS_IS_OK(status)) {
330 smbcli_close(cli->tree, io.openx.out.file.fnum);
332 if (open_funcs[i].with_file) {
333 smbcli_unlink(cli->tree, fname);
337 smbcli_unlink(cli->tree, fname);
339 /* check the basic return fields */
340 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
341 status = smb_raw_open(cli->tree, mem_ctx, &io);
342 CHECK_STATUS(status, NT_STATUS_OK);
343 fnum = io.openx.out.file.fnum;
345 CHECK_ALL_INFO(io.openx.out.size, size);
346 CHECK_TIME(io.openx.out.write_time, write_time);
347 CHECK_ALL_INFO(io.openx.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
348 CHECK_VAL(io.openx.out.access, OPENX_MODE_ACCESS_RDWR);
349 CHECK_VAL(io.openx.out.ftype, 0);
350 CHECK_VAL(io.openx.out.devstate, 0);
351 CHECK_VAL(io.openx.out.action, OPENX_ACTION_CREATED);
352 CHECK_VAL(io.openx.out.size, 1024*1024);
353 CHECK_ALL_INFO(io.openx.in.size, size);
354 smbcli_close(cli->tree, fnum);
355 smbcli_unlink(cli->tree, fname);
357 /* check the fields when the file already existed */
358 fnum2 = create_complex_file(cli, mem_ctx, fname);
363 smbcli_close(cli->tree, fnum2);
365 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
366 status = smb_raw_open(cli->tree, mem_ctx, &io);
367 CHECK_STATUS(status, NT_STATUS_OK);
368 fnum = io.openx.out.file.fnum;
370 CHECK_ALL_INFO(io.openx.out.size, size);
371 CHECK_TIME(io.openx.out.write_time, write_time);
372 CHECK_VAL(io.openx.out.action, OPENX_ACTION_EXISTED);
373 CHECK_VAL(io.openx.out.unknown, 0);
374 CHECK_ALL_INFO(io.openx.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
375 smbcli_close(cli->tree, fnum);
377 /* now check the search attrib for hidden files - win2003 ignores this? */
378 SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN);
379 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib);
381 io.openx.in.search_attrs = FILE_ATTRIBUTE_HIDDEN;
382 status = smb_raw_open(cli->tree, mem_ctx, &io);
383 CHECK_STATUS(status, NT_STATUS_OK);
384 smbcli_close(cli->tree, io.openx.out.file.fnum);
386 io.openx.in.search_attrs = 0;
387 status = smb_raw_open(cli->tree, mem_ctx, &io);
388 CHECK_STATUS(status, NT_STATUS_OK);
389 smbcli_close(cli->tree, io.openx.out.file.fnum);
391 SET_ATTRIB(FILE_ATTRIBUTE_NORMAL);
392 smbcli_unlink(cli->tree, fname);
394 /* and check attrib on create */
395 io.openx.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE;
396 io.openx.in.search_attrs = 0;
397 io.openx.in.file_attrs = FILE_ATTRIBUTE_SYSTEM;
398 status = smb_raw_open(cli->tree, mem_ctx, &io);
399 CHECK_STATUS(status, NT_STATUS_OK);
400 if (lp_parm_bool(-1, "torture", "samba3", False)) {
401 CHECK_ALL_INFO(FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE,
402 attrib & ~(FILE_ATTRIBUTE_NONINDEXED|
403 FILE_ATTRIBUTE_SPARSE));
406 CHECK_ALL_INFO(FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE,
407 attrib & ~(FILE_ATTRIBUTE_NONINDEXED));
409 smbcli_close(cli->tree, io.openx.out.file.fnum);
410 smbcli_unlink(cli->tree, fname);
412 /* check timeout on create - win2003 ignores the timeout! */
413 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
414 io.openx.in.file_attrs = 0;
415 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL;
416 status = smb_raw_open(cli->tree, mem_ctx, &io);
417 CHECK_STATUS(status, NT_STATUS_OK);
418 fnum = io.openx.out.file.fnum;
420 io.openx.in.timeout = 20000;
421 tv = timeval_current();
422 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_NONE;
423 status = smb_raw_open(cli->tree, mem_ctx, &io);
424 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
425 if (timeval_elapsed(&tv) > 3.0) {
426 printf("(%s) Incorrect timing in openx with timeout - waited %.2f seconds\n",
427 __location__, timeval_elapsed(&tv));
430 smbcli_close(cli->tree, fnum);
431 smbcli_unlink(cli->tree, fname);
433 /* now this is a really weird one - open for execute implies create?! */
434 io.openx.in.fname = fname;
435 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
436 io.openx.in.open_mode = OPENX_MODE_ACCESS_EXEC | OPENX_MODE_DENY_NONE;
437 io.openx.in.search_attrs = 0;
438 io.openx.in.open_func = OPENX_OPEN_FUNC_FAIL;
439 io.openx.in.file_attrs = 0;
440 io.openx.in.write_time = 0;
441 io.openx.in.size = 0;
442 io.openx.in.timeout = 0;
443 status = smb_raw_open(cli->tree, mem_ctx, &io);
444 CHECK_STATUS(status, NT_STATUS_OK);
445 smbcli_close(cli->tree, io.openx.out.file.fnum);
447 /* check the extended return flag */
448 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO | OPENX_FLAGS_EXTENDED_RETURN;
449 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
450 status = smb_raw_open(cli->tree, mem_ctx, &io);
451 CHECK_STATUS(status, NT_STATUS_OK);
452 CHECK_VAL(io.openx.out.access_mask, SEC_STD_ALL);
453 smbcli_close(cli->tree, io.openx.out.file.fnum);
455 io.openx.in.fname = "\\A.+,;=[].B";
456 status = smb_raw_open(cli->tree, mem_ctx, &io);
457 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
459 /* Check the mapping for open exec. */
461 /* First create an .exe file. */
462 smbcli_unlink(cli->tree, fname_exe);
463 fnum = create_complex_file(cli, mem_ctx, fname_exe);
464 smbcli_close(cli->tree, fnum);
466 io.openx.level = RAW_OPEN_OPENX;
467 io.openx.in.fname = fname_exe;
468 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
469 io.openx.in.open_mode = OPENX_MODE_ACCESS_EXEC | OPENX_MODE_DENY_NONE;
470 io.openx.in.search_attrs = 0;
471 io.openx.in.file_attrs = 0;
472 io.openx.in.write_time = 0;
473 io.openx.in.size = 0;
474 io.openx.in.timeout = 0;
475 status = smb_raw_open(cli->tree, mem_ctx, &io);
476 CHECK_STATUS(status, NT_STATUS_OK);
478 /* Can we read and write ? */
479 CHECK_RDWR(io.openx.out.file.fnum, RDWR_RDONLY);
480 smbcli_close(cli->tree, io.openx.out.file.fnum);
481 smbcli_unlink(cli->tree, fname);
484 smbcli_close(cli->tree, fnum);
485 smbcli_unlink(cli->tree, fname_exe);
486 smbcli_unlink(cli->tree, fname);
495 many thanks to kukks for a sniff showing how this works with os2->w2k
497 static BOOL test_t2open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
500 union smb_fileinfo finfo;
501 const char *fname1 = BASEDIR "\\torture_t2open_yes.txt";
502 const char *fname2 = BASEDIR "\\torture_t2open_no.txt";
503 const char *fname = BASEDIR "\\torture_t2open_3.txt";
511 NTSTATUS correct_status;
513 { OPENX_OPEN_FUNC_OPEN, True, NT_STATUS_OK },
514 { OPENX_OPEN_FUNC_OPEN, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
515 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OK },
516 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
517 { OPENX_OPEN_FUNC_FAIL, True, NT_STATUS_OBJECT_NAME_COLLISION },
518 { OPENX_OPEN_FUNC_FAIL, False, NT_STATUS_OBJECT_NAME_COLLISION },
519 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OBJECT_NAME_COLLISION },
520 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OBJECT_NAME_COLLISION },
521 { OPENX_OPEN_FUNC_TRUNC, True, NT_STATUS_OK },
522 { OPENX_OPEN_FUNC_TRUNC, False, NT_STATUS_OK },
523 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OK },
524 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
527 fnum = create_complex_file(cli, mem_ctx, fname1);
529 d_printf("Failed to create file %s - %s\n", fname1, smbcli_errstr(cli->tree));
533 smbcli_close(cli->tree, fnum);
535 printf("Checking RAW_OPEN_T2OPEN\n");
537 io.t2open.level = RAW_OPEN_T2OPEN;
538 io.t2open.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
539 io.t2open.in.open_mode = OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR;
540 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
541 io.t2open.in.search_attrs = 0;
542 io.t2open.in.file_attrs = 0;
543 io.t2open.in.write_time = 0;
544 io.t2open.in.size = 0;
545 io.t2open.in.timeout = 0;
547 io.t2open.in.num_eas = 3;
548 io.t2open.in.eas = talloc_array(mem_ctx, struct ea_struct, io.t2open.in.num_eas);
549 io.t2open.in.eas[0].flags = 0;
550 io.t2open.in.eas[0].name.s = ".CLASSINFO";
551 io.t2open.in.eas[0].value = data_blob_talloc(mem_ctx, "first value", 11);
552 io.t2open.in.eas[1].flags = 0;
553 io.t2open.in.eas[1].name.s = "EA TWO";
554 io.t2open.in.eas[1].value = data_blob_talloc(mem_ctx, "foo", 3);
555 io.t2open.in.eas[2].flags = 0;
556 io.t2open.in.eas[2].name.s = "X THIRD";
557 io.t2open.in.eas[2].value = data_blob_talloc(mem_ctx, "xy", 2);
559 /* check all combinations of open_func */
560 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
562 if (open_funcs[i].with_file) {
563 io.t2open.in.fname = fname1;
565 io.t2open.in.fname = fname2;
567 io.t2open.in.open_func = open_funcs[i].open_func;
568 status = smb_raw_open(cli->tree, mem_ctx, &io);
569 if ((io.t2open.in.num_eas != 0)
570 && NT_STATUS_EQUAL(status, NT_STATUS_EAS_NOT_SUPPORTED)
571 && lp_parm_bool(-1, "torture", "samba3", False)) {
572 printf("(%s) EAs not supported, not treating as fatal "
573 "in Samba3 test\n", __location__);
574 io.t2open.in.num_eas = 0;
578 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
579 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n",
580 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
581 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_func);
584 if (NT_STATUS_IS_OK(status)) {
585 smbcli_close(cli->tree, io.t2open.out.file.fnum);
589 smbcli_unlink(cli->tree, fname1);
590 smbcli_unlink(cli->tree, fname2);
592 /* check the basic return fields */
593 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
594 io.t2open.in.write_time = 0;
595 io.t2open.in.fname = fname;
596 status = smb_raw_open(cli->tree, mem_ctx, &io);
597 CHECK_STATUS(status, NT_STATUS_OK);
598 fnum = io.t2open.out.file.fnum;
600 CHECK_ALL_INFO(io.t2open.out.size, size);
602 /* windows appears to leak uninitialised memory here */
603 CHECK_VAL(io.t2open.out.write_time, 0);
605 CHECK_ALL_INFO(io.t2open.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
606 CHECK_VAL(io.t2open.out.access, OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR);
607 CHECK_VAL(io.t2open.out.ftype, 0);
608 CHECK_VAL(io.t2open.out.devstate, 0);
609 CHECK_VAL(io.t2open.out.action, OPENX_ACTION_CREATED);
610 smbcli_close(cli->tree, fnum);
612 status = torture_check_ea(cli, fname, ".CLASSINFO", "first value");
613 CHECK_STATUS(status, io.t2open.in.num_eas
614 ? NT_STATUS_OK : NT_STATUS_EAS_NOT_SUPPORTED);
615 status = torture_check_ea(cli, fname, "EA TWO", "foo");
616 CHECK_STATUS(status, io.t2open.in.num_eas
617 ? NT_STATUS_OK : NT_STATUS_EAS_NOT_SUPPORTED);
618 status = torture_check_ea(cli, fname, "X THIRD", "xy");
619 CHECK_STATUS(status, io.t2open.in.num_eas
620 ? NT_STATUS_OK : NT_STATUS_EAS_NOT_SUPPORTED);
622 /* now check the search attrib for hidden files - win2003 ignores this? */
623 SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN);
624 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib);
626 status = smb_raw_open(cli->tree, mem_ctx, &io);
627 CHECK_STATUS(status, NT_STATUS_OK);
628 smbcli_close(cli->tree, io.t2open.out.file.fnum);
630 status = smb_raw_open(cli->tree, mem_ctx, &io);
631 CHECK_STATUS(status, NT_STATUS_OK);
632 smbcli_close(cli->tree, io.t2open.out.file.fnum);
634 SET_ATTRIB(FILE_ATTRIBUTE_NORMAL);
635 smbcli_unlink(cli->tree, fname);
637 /* and check attrib on create */
638 io.t2open.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE;
639 io.t2open.in.file_attrs = FILE_ATTRIBUTE_SYSTEM;
640 status = smb_raw_open(cli->tree, mem_ctx, &io);
641 CHECK_STATUS(status, NT_STATUS_OK);
643 /* check timeout on create - win2003 ignores the timeout! */
644 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
645 io.t2open.in.file_attrs = 0;
646 io.t2open.in.timeout = 20000;
647 io.t2open.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL;
648 status = smb_raw_open(cli->tree, mem_ctx, &io);
649 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
652 smbcli_close(cli->tree, fnum);
653 smbcli_unlink(cli->tree, fname);
660 test RAW_OPEN_NTCREATEX
662 static BOOL test_ntcreatex(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
665 union smb_fileinfo finfo;
666 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
667 const char *dname = BASEDIR "\\torture_ntcreatex.dir";
675 NTSTATUS correct_status;
677 { NTCREATEX_DISP_SUPERSEDE, True, NT_STATUS_OK },
678 { NTCREATEX_DISP_SUPERSEDE, False, NT_STATUS_OK },
679 { NTCREATEX_DISP_OPEN, True, NT_STATUS_OK },
680 { NTCREATEX_DISP_OPEN, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
681 { NTCREATEX_DISP_CREATE, True, NT_STATUS_OBJECT_NAME_COLLISION },
682 { NTCREATEX_DISP_CREATE, False, NT_STATUS_OK },
683 { NTCREATEX_DISP_OPEN_IF, True, NT_STATUS_OK },
684 { NTCREATEX_DISP_OPEN_IF, False, NT_STATUS_OK },
685 { NTCREATEX_DISP_OVERWRITE, True, NT_STATUS_OK },
686 { NTCREATEX_DISP_OVERWRITE, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
687 { NTCREATEX_DISP_OVERWRITE_IF, True, NT_STATUS_OK },
688 { NTCREATEX_DISP_OVERWRITE_IF, False, NT_STATUS_OK },
689 { 6, True, NT_STATUS_INVALID_PARAMETER },
690 { 6, False, NT_STATUS_INVALID_PARAMETER },
693 printf("Checking RAW_OPEN_NTCREATEX\n");
695 /* reasonable default parameters */
696 io.generic.level = RAW_OPEN_NTCREATEX;
697 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
698 io.ntcreatex.in.root_fid = 0;
699 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
700 io.ntcreatex.in.alloc_size = 1024*1024;
701 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
702 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
703 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
704 io.ntcreatex.in.create_options = 0;
705 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
706 io.ntcreatex.in.security_flags = 0;
707 io.ntcreatex.in.fname = fname;
709 /* test the open disposition */
710 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
711 if (open_funcs[i].with_file) {
712 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE);
714 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
718 smbcli_close(cli->tree, fnum);
720 io.ntcreatex.in.open_disposition = open_funcs[i].open_disp;
721 status = smb_raw_open(cli->tree, mem_ctx, &io);
722 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
723 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_disp=%d)\n",
724 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
725 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_disp);
728 if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
729 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
730 smbcli_unlink(cli->tree, fname);
734 /* basic field testing */
735 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
737 status = smb_raw_open(cli->tree, mem_ctx, &io);
738 CHECK_STATUS(status, NT_STATUS_OK);
739 fnum = io.ntcreatex.out.file.fnum;
741 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
742 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
743 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
744 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
745 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
746 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
747 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
748 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
749 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
750 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
751 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
753 /* check fields when the file already existed */
754 smbcli_close(cli->tree, fnum);
755 smbcli_unlink(cli->tree, fname);
756 fnum = create_complex_file(cli, mem_ctx, fname);
761 smbcli_close(cli->tree, fnum);
763 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
764 status = smb_raw_open(cli->tree, mem_ctx, &io);
765 CHECK_STATUS(status, NT_STATUS_OK);
766 fnum = io.ntcreatex.out.file.fnum;
768 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
769 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
770 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
771 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
772 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
773 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
774 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
775 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
776 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
777 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
778 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
779 smbcli_close(cli->tree, fnum);
780 smbcli_unlink(cli->tree, fname);
783 /* create a directory */
784 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
785 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
786 io.ntcreatex.in.alloc_size = 0;
787 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
788 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
789 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
790 io.ntcreatex.in.create_options = 0;
791 io.ntcreatex.in.fname = dname;
794 smbcli_rmdir(cli->tree, fname);
795 smbcli_unlink(cli->tree, fname);
797 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
798 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
799 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
800 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
801 status = smb_raw_open(cli->tree, mem_ctx, &io);
802 CHECK_STATUS(status, NT_STATUS_OK);
803 fnum = io.ntcreatex.out.file.fnum;
805 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
806 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
807 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
808 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
809 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
810 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
811 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
812 CHECK_VAL(io.ntcreatex.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED,
813 FILE_ATTRIBUTE_DIRECTORY);
814 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
815 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
816 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
817 CHECK_VAL(io.ntcreatex.out.is_directory, 1);
818 CHECK_VAL(io.ntcreatex.out.size, 0);
819 CHECK_VAL(io.ntcreatex.out.alloc_size, 0);
820 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
821 smbcli_unlink(cli->tree, fname);
825 smbcli_close(cli->tree, fnum);
826 smbcli_unlink(cli->tree, fname);
833 test RAW_OPEN_NTTRANS_CREATE
835 static BOOL test_nttrans_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
838 union smb_fileinfo finfo;
839 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
840 const char *dname = BASEDIR "\\torture_ntcreatex.dir";
848 NTSTATUS correct_status;
850 { NTCREATEX_DISP_SUPERSEDE, True, NT_STATUS_OK },
851 { NTCREATEX_DISP_SUPERSEDE, False, NT_STATUS_OK },
852 { NTCREATEX_DISP_OPEN, True, NT_STATUS_OK },
853 { NTCREATEX_DISP_OPEN, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
854 { NTCREATEX_DISP_CREATE, True, NT_STATUS_OBJECT_NAME_COLLISION },
855 { NTCREATEX_DISP_CREATE, False, NT_STATUS_OK },
856 { NTCREATEX_DISP_OPEN_IF, True, NT_STATUS_OK },
857 { NTCREATEX_DISP_OPEN_IF, False, NT_STATUS_OK },
858 { NTCREATEX_DISP_OVERWRITE, True, NT_STATUS_OK },
859 { NTCREATEX_DISP_OVERWRITE, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
860 { NTCREATEX_DISP_OVERWRITE_IF, True, NT_STATUS_OK },
861 { NTCREATEX_DISP_OVERWRITE_IF, False, NT_STATUS_OK },
862 { 6, True, NT_STATUS_INVALID_PARAMETER },
863 { 6, False, NT_STATUS_INVALID_PARAMETER },
866 printf("Checking RAW_OPEN_NTTRANS_CREATE\n");
868 /* reasonable default parameters */
869 io.generic.level = RAW_OPEN_NTTRANS_CREATE;
870 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
871 io.ntcreatex.in.root_fid = 0;
872 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
873 io.ntcreatex.in.alloc_size = 1024*1024;
874 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
875 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
876 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
877 io.ntcreatex.in.create_options = 0;
878 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
879 io.ntcreatex.in.security_flags = 0;
880 io.ntcreatex.in.fname = fname;
881 io.ntcreatex.in.sec_desc = NULL;
882 io.ntcreatex.in.ea_list = NULL;
884 /* test the open disposition */
885 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
886 if (open_funcs[i].with_file) {
887 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE);
889 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
893 smbcli_close(cli->tree, fnum);
895 io.ntcreatex.in.open_disposition = open_funcs[i].open_disp;
896 status = smb_raw_open(cli->tree, mem_ctx, &io);
897 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
898 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_disp=%d)\n",
899 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
900 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_disp);
903 if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
904 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
905 smbcli_unlink(cli->tree, fname);
909 /* basic field testing */
910 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
912 status = smb_raw_open(cli->tree, mem_ctx, &io);
913 CHECK_STATUS(status, NT_STATUS_OK);
914 fnum = io.ntcreatex.out.file.fnum;
916 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
917 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
918 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
919 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
920 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
921 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
922 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
923 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
924 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
925 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
926 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
928 /* check fields when the file already existed */
929 smbcli_close(cli->tree, fnum);
930 smbcli_unlink(cli->tree, fname);
931 fnum = create_complex_file(cli, mem_ctx, fname);
936 smbcli_close(cli->tree, fnum);
938 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
939 status = smb_raw_open(cli->tree, mem_ctx, &io);
940 CHECK_STATUS(status, NT_STATUS_OK);
941 fnum = io.ntcreatex.out.file.fnum;
943 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
944 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
945 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
946 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
947 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
948 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
949 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
950 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
951 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
952 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
953 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
954 smbcli_close(cli->tree, fnum);
955 smbcli_unlink(cli->tree, fname);
958 /* create a directory */
959 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
960 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
961 io.ntcreatex.in.alloc_size = 0;
962 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
963 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
964 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
965 io.ntcreatex.in.create_options = 0;
966 io.ntcreatex.in.fname = dname;
969 smbcli_rmdir(cli->tree, fname);
970 smbcli_unlink(cli->tree, fname);
972 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
973 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
974 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
975 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
976 status = smb_raw_open(cli->tree, mem_ctx, &io);
977 CHECK_STATUS(status, NT_STATUS_OK);
978 fnum = io.ntcreatex.out.file.fnum;
980 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
981 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
982 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
983 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
984 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
985 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
986 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
987 CHECK_VAL(io.ntcreatex.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED,
988 FILE_ATTRIBUTE_DIRECTORY);
989 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
990 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
991 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
992 CHECK_VAL(io.ntcreatex.out.is_directory, 1);
993 CHECK_VAL(io.ntcreatex.out.size, 0);
994 CHECK_VAL(io.ntcreatex.out.alloc_size, 0);
995 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
996 smbcli_unlink(cli->tree, fname);
1000 smbcli_close(cli->tree, fnum);
1001 smbcli_unlink(cli->tree, fname);
1007 test RAW_OPEN_NTCREATEX with an already opened and byte range locked file
1009 I've got an application that does a similar sequence of ntcreate&x,
1010 locking&x and another ntcreate&x with
1011 open_disposition==NTCREATEX_DISP_OVERWRITE_IF. Windows 2003 allows the
1014 static BOOL test_ntcreatex_brlocked(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1016 union smb_open io, io1;
1018 struct smb_lock_entry lock[1];
1019 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
1023 printf("Testing ntcreatex with a byte range locked file\n");
1025 io.generic.level = RAW_OPEN_NTCREATEX;
1026 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
1027 io.ntcreatex.in.root_fid = 0;
1028 io.ntcreatex.in.access_mask = 0x2019f;
1029 io.ntcreatex.in.alloc_size = 0;
1030 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1031 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1032 NTCREATEX_SHARE_ACCESS_WRITE;
1033 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1034 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
1035 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
1036 io.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC |
1037 NTCREATEX_SECURITY_ALL;
1038 io.ntcreatex.in.fname = fname;
1040 status = smb_raw_open(cli->tree, mem_ctx, &io);
1041 CHECK_STATUS(status, NT_STATUS_OK);
1043 io2.lockx.level = RAW_LOCK_LOCKX;
1044 io2.lockx.in.file.fnum = io.ntcreatex.out.file.fnum;
1045 io2.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
1046 io2.lockx.in.timeout = 0;
1047 io2.lockx.in.ulock_cnt = 0;
1048 io2.lockx.in.lock_cnt = 1;
1049 lock[0].pid = cli->session->pid;
1051 lock[0].count = 0x1;
1052 io2.lockx.in.locks = &lock[0];
1053 status = smb_raw_lock(cli->tree, &io2);
1054 CHECK_STATUS(status, NT_STATUS_OK);
1056 io1.generic.level = RAW_OPEN_NTCREATEX;
1057 io1.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
1058 io1.ntcreatex.in.root_fid = 0;
1059 io1.ntcreatex.in.access_mask = 0x20196;
1060 io1.ntcreatex.in.alloc_size = 0;
1061 io1.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1062 io1.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1063 NTCREATEX_SHARE_ACCESS_WRITE;
1064 io1.ntcreatex.in.open_disposition = NTCREATEX_DISP_OVERWRITE_IF;
1065 io1.ntcreatex.in.create_options = 0;
1066 io1.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
1067 io1.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC |
1068 NTCREATEX_SECURITY_ALL;
1069 io1.ntcreatex.in.fname = fname;
1071 status = smb_raw_open(cli->tree, mem_ctx, &io1);
1072 CHECK_STATUS(status, NT_STATUS_OK);
1075 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
1076 smbcli_close(cli->tree, io1.ntcreatex.out.file.fnum);
1077 smbcli_unlink(cli->tree, fname);
1084 static BOOL test_mknew(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1087 const char *fname = BASEDIR "\\torture_mknew.txt";
1091 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1092 union smb_fileinfo finfo;
1094 printf("Checking RAW_OPEN_MKNEW\n");
1096 io.mknew.level = RAW_OPEN_MKNEW;
1097 io.mknew.in.attrib = 0;
1098 io.mknew.in.write_time = 0;
1099 io.mknew.in.fname = fname;
1100 status = smb_raw_open(cli->tree, mem_ctx, &io);
1101 CHECK_STATUS(status, NT_STATUS_OK);
1102 fnum = io.mknew.out.file.fnum;
1104 status = smb_raw_open(cli->tree, mem_ctx, &io);
1105 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
1107 smbcli_close(cli->tree, fnum);
1108 smbcli_unlink(cli->tree, fname);
1110 /* make sure write_time works */
1111 io.mknew.in.write_time = basetime;
1112 status = smb_raw_open(cli->tree, mem_ctx, &io);
1113 CHECK_STATUS(status, NT_STATUS_OK);
1114 fnum = io.mknew.out.file.fnum;
1115 CHECK_TIME(basetime, write_time);
1117 smbcli_close(cli->tree, fnum);
1118 smbcli_unlink(cli->tree, fname);
1120 /* make sure file_attrs works */
1121 io.mknew.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1122 status = smb_raw_open(cli->tree, mem_ctx, &io);
1123 CHECK_STATUS(status, NT_STATUS_OK);
1124 fnum = io.mknew.out.file.fnum;
1125 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE,
1126 attrib & ~FILE_ATTRIBUTE_NONINDEXED);
1129 smbcli_close(cli->tree, fnum);
1130 smbcli_unlink(cli->tree, fname);
1137 test RAW_OPEN_CREATE
1139 static BOOL test_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1142 const char *fname = BASEDIR "\\torture_create.txt";
1146 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1147 union smb_fileinfo finfo;
1149 printf("Checking RAW_OPEN_CREATE\n");
1151 io.create.level = RAW_OPEN_CREATE;
1152 io.create.in.attrib = 0;
1153 io.create.in.write_time = 0;
1154 io.create.in.fname = fname;
1155 status = smb_raw_open(cli->tree, mem_ctx, &io);
1156 CHECK_STATUS(status, NT_STATUS_OK);
1157 fnum = io.create.out.file.fnum;
1159 status = smb_raw_open(cli->tree, mem_ctx, &io);
1160 CHECK_STATUS(status, NT_STATUS_OK);
1162 smbcli_close(cli->tree, io.create.out.file.fnum);
1163 smbcli_close(cli->tree, fnum);
1164 smbcli_unlink(cli->tree, fname);
1166 /* make sure write_time works */
1167 io.create.in.write_time = basetime;
1168 status = smb_raw_open(cli->tree, mem_ctx, &io);
1169 CHECK_STATUS(status, NT_STATUS_OK);
1170 fnum = io.create.out.file.fnum;
1171 CHECK_TIME(basetime, write_time);
1173 smbcli_close(cli->tree, fnum);
1174 smbcli_unlink(cli->tree, fname);
1176 /* make sure file_attrs works */
1177 io.create.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1178 status = smb_raw_open(cli->tree, mem_ctx, &io);
1179 CHECK_STATUS(status, NT_STATUS_OK);
1180 fnum = io.create.out.file.fnum;
1181 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE,
1182 attrib & ~FILE_ATTRIBUTE_NONINDEXED);
1185 smbcli_close(cli->tree, fnum);
1186 smbcli_unlink(cli->tree, fname);
1195 static BOOL test_ctemp(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1201 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1202 union smb_fileinfo finfo;
1203 const char *name, *fname = NULL;
1205 printf("Checking RAW_OPEN_CTEMP\n");
1207 io.ctemp.level = RAW_OPEN_CTEMP;
1208 io.ctemp.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1209 io.ctemp.in.write_time = basetime;
1210 io.ctemp.in.directory = BASEDIR;
1211 status = smb_raw_open(cli->tree, mem_ctx, &io);
1212 CHECK_STATUS(status, NT_STATUS_OK);
1213 fnum = io.ctemp.out.file.fnum;
1215 name = io.ctemp.out.name;
1217 finfo.generic.level = RAW_FILEINFO_NAME_INFO;
1218 finfo.generic.in.file.fnum = fnum;
1219 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
1220 CHECK_STATUS(status, NT_STATUS_OK);
1222 fname = finfo.name_info.out.fname.s;
1223 d_printf("ctemp name=%s real name=%s\n", name, fname);
1226 smbcli_close(cli->tree, fnum);
1228 smbcli_unlink(cli->tree, fname);
1236 test chained RAW_OPEN_OPENX_READX
1238 static BOOL test_chained(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1241 const char *fname = BASEDIR "\\torture_chained.txt";
1245 const char *buf = "test";
1248 printf("Checking RAW_OPEN_OPENX chained with READX\n");
1249 smbcli_unlink(cli->tree, fname);
1251 fnum = create_complex_file(cli, mem_ctx, fname);
1253 smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf));
1255 smbcli_close(cli->tree, fnum);
1257 io.openxreadx.level = RAW_OPEN_OPENX_READX;
1258 io.openxreadx.in.fname = fname;
1259 io.openxreadx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
1260 io.openxreadx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
1261 io.openxreadx.in.open_func = OPENX_OPEN_FUNC_OPEN;
1262 io.openxreadx.in.search_attrs = 0;
1263 io.openxreadx.in.file_attrs = 0;
1264 io.openxreadx.in.write_time = 0;
1265 io.openxreadx.in.size = 1024*1024;
1266 io.openxreadx.in.timeout = 0;
1268 io.openxreadx.in.offset = 0;
1269 io.openxreadx.in.mincnt = sizeof(buf);
1270 io.openxreadx.in.maxcnt = sizeof(buf);
1271 io.openxreadx.in.remaining = 0;
1272 io.openxreadx.out.data = (uint8_t *)buf2;
1274 status = smb_raw_open(cli->tree, mem_ctx, &io);
1275 CHECK_STATUS(status, NT_STATUS_OK);
1276 fnum = io.openxreadx.out.file.fnum;
1278 if (memcmp(buf, buf2, sizeof(buf)) != 0) {
1279 d_printf("wrong data in reply buffer\n");
1284 smbcli_close(cli->tree, fnum);
1285 smbcli_unlink(cli->tree, fname);
1291 test RAW_OPEN_OPENX without a leading slash on the path.
1292 NetApp filers are known to fail on this.
1295 static BOOL test_no_leading_slash(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1298 const char *fname = BASEDIR "\\torture_no_leading_slash.txt";
1302 const char *buf = "test";
1304 printf("Checking RAW_OPEN_OPENX without leading slash on path\n");
1305 smbcli_unlink(cli->tree, fname);
1307 /* Create the file */
1308 fnum = create_complex_file(cli, mem_ctx, fname);
1309 smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf));
1310 smbcli_close(cli->tree, fnum);
1312 /* Prepare to open the file using path without leading slash */
1313 io.openx.level = RAW_OPEN_OPENX;
1314 io.openx.in.fname = fname + 1;
1315 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
1316 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
1317 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
1318 io.openx.in.search_attrs = 0;
1319 io.openx.in.file_attrs = 0;
1320 io.openx.in.write_time = 0;
1321 io.openx.in.size = 1024*1024;
1322 io.openx.in.timeout = 0;
1324 status = smb_raw_open(cli->tree, mem_ctx, &io);
1325 CHECK_STATUS(status, NT_STATUS_OK);
1326 fnum = io.openx.out.file.fnum;
1329 smbcli_close(cli->tree, fnum);
1330 smbcli_unlink(cli->tree, fname);
1335 /* A little torture test to expose a race condition in Samba 3.0.20 ... :-) */
1337 static BOOL test_raw_open_multi(void)
1339 struct smbcli_state *cli;
1340 TALLOC_CTX *mem_ctx = talloc_init("torture_test_oplock_multi");
1341 const char *fname = "\\test_oplock.dat";
1345 struct smbcli_state **clients;
1346 struct smbcli_request **requests;
1347 union smb_open *ios;
1348 const char *host = lp_parm_string(-1, "torture", "host");
1349 const char *share = lp_parm_string(-1, "torture", "share");
1350 int i, num_files = 3;
1351 struct event_context *ev;
1353 int num_collision = 0;
1355 ev = cli_credentials_get_event_context(cmdline_credentials);
1356 clients = talloc_array(mem_ctx, struct smbcli_state *, num_files);
1357 requests = talloc_array(mem_ctx, struct smbcli_request *, num_files);
1358 ios = talloc_array(mem_ctx, union smb_open, num_files);
1359 if ((ev == NULL) || (clients == NULL) || (requests == NULL) ||
1361 DEBUG(0, ("talloc failed\n"));
1365 if (!torture_open_connection_share(mem_ctx, &cli, host, share, ev)) {
1369 cli->tree->session->transport->options.request_timeout = 60000;
1371 for (i=0; i<num_files; i++) {
1372 if (!torture_open_connection_share(mem_ctx, &(clients[i]),
1374 DEBUG(0, ("Could not open %d'th connection\n", i));
1377 clients[i]->tree->session->transport->
1378 options.request_timeout = 60000;
1382 smbcli_unlink(cli->tree, fname);
1385 base ntcreatex parms
1387 io.generic.level = RAW_OPEN_NTCREATEX;
1388 io.ntcreatex.in.root_fid = 0;
1389 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
1390 io.ntcreatex.in.alloc_size = 0;
1391 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1392 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ|
1393 NTCREATEX_SHARE_ACCESS_WRITE|
1394 NTCREATEX_SHARE_ACCESS_DELETE;
1395 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1396 io.ntcreatex.in.create_options = 0;
1397 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1398 io.ntcreatex.in.security_flags = 0;
1399 io.ntcreatex.in.fname = fname;
1400 io.ntcreatex.in.flags = 0;
1402 for (i=0; i<num_files; i++) {
1404 requests[i] = smb_raw_open_send(clients[i]->tree, &ios[i]);
1405 if (requests[i] == NULL) {
1406 DEBUG(0, ("could not send %d'th request\n", i));
1411 DEBUG(10, ("waiting for replies\n"));
1413 BOOL unreplied = False;
1414 for (i=0; i<num_files; i++) {
1415 if (requests[i] == NULL) {
1418 if (requests[i]->state < SMBCLI_REQUEST_DONE) {
1422 status = smb_raw_open_recv(requests[i], mem_ctx,
1425 DEBUG(0, ("File %d returned status %s\n", i,
1426 nt_errstr(status)));
1428 if (NT_STATUS_IS_OK(status)) {
1432 if (NT_STATUS_EQUAL(status,
1433 NT_STATUS_OBJECT_NAME_COLLISION)) {
1443 if (event_loop_once(ev) != 0) {
1444 DEBUG(0, ("event_loop_once failed\n"));
1449 if ((num_ok != 1) || (num_ok + num_collision != num_files)) {
1453 for (i=0; i<num_files; i++) {
1454 torture_close_connection(clients[i]);
1456 talloc_free(mem_ctx);
1460 /* basic testing of all RAW_OPEN_* calls
1462 bool torture_raw_open(struct torture_context *torture, struct smbcli_state *cli)
1466 if (!torture_setup_dir(cli, BASEDIR)) {
1470 ret &= test_ntcreatex_brlocked(cli, torture);
1471 ret &= test_open(cli, torture);
1472 ret &= test_raw_open_multi();
1473 ret &= test_openx(cli, torture);
1474 ret &= test_ntcreatex(cli, torture);
1475 ret &= test_nttrans_create(cli, torture);
1476 ret &= test_t2open(cli, torture);
1477 ret &= test_mknew(cli, torture);
1478 ret &= test_create(cli, torture);
1479 ret &= test_ctemp(cli, torture);
1480 ret &= test_chained(cli, torture);
1481 ret &= test_no_leading_slash(cli, torture);
1483 smb_raw_exit(cli->session);
1484 smbcli_deltree(cli->tree, BASEDIR);