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 2 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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "torture/torture.h"
23 #include "libcli/raw/libcliraw.h"
24 #include "system/time.h"
25 #include "system/filesys.h"
26 #include "librpc/gen_ndr/ndr_security.h"
27 #include "lib/events/events.h"
28 #include "libcli/libcli.h"
30 /* enum for whether reads/writes are possible on a file */
31 enum rdwr_mode {RDWR_NONE, RDWR_RDONLY, RDWR_WRONLY, RDWR_RDWR};
33 #define BASEDIR "\\rawopen"
36 check if a open file can be read/written
38 static enum rdwr_mode check_rdwr(struct smbcli_tree *tree, int fnum)
41 BOOL can_read = (smbcli_read(tree, fnum, &c, 0, 1) == 1);
42 BOOL can_write = (smbcli_write(tree, fnum, 0, &c, 0, 1) == 1);
43 if ( can_read && can_write) return RDWR_RDWR;
44 if ( can_read && !can_write) return RDWR_RDONLY;
45 if (!can_read && can_write) return RDWR_WRONLY;
50 describe a RDWR mode as a string
52 static const char *rdwr_string(enum rdwr_mode m)
55 case RDWR_NONE: return "NONE";
56 case RDWR_RDONLY: return "RDONLY";
57 case RDWR_WRONLY: return "WRONLY";
58 case RDWR_RDWR: return "RDWR";
63 #define CHECK_STATUS(status, correct) do { \
64 if (!NT_STATUS_EQUAL(status, correct)) { \
65 printf("(%s) Incorrect status %s - should be %s\n", \
66 __location__, nt_errstr(status), nt_errstr(correct)); \
71 #define CREATE_FILE do { \
72 fnum = create_complex_file(cli, mem_ctx, fname); \
74 printf("(%s) Failed to create %s - %s\n", __location__, fname, smbcli_errstr(cli->tree)); \
79 #define CHECK_RDWR(fnum, correct) do { \
80 enum rdwr_mode m = check_rdwr(cli->tree, fnum); \
82 printf("(%s) Incorrect readwrite mode %s - expected %s\n", \
83 __location__, rdwr_string(m), rdwr_string(correct)); \
87 #define CHECK_TIME(t, field) do { \
89 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
90 finfo.all_info.in.fname = fname; \
91 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo); \
92 CHECK_STATUS(status, NT_STATUS_OK); \
94 t2 = nt_time_to_unix(finfo.all_info.out.field) & ~1; \
95 if (ABS(t1-t2) > 2) { \
96 printf("(%s) wrong time for field %s %s - %s\n", \
97 __location__, #field, \
98 timestring(mem_ctx, t1), \
99 timestring(mem_ctx, t2)); \
100 dump_all_info(mem_ctx, &finfo); \
104 #define CHECK_NTTIME(t, field) do { \
106 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
107 finfo.all_info.in.fname = fname; \
108 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo); \
109 CHECK_STATUS(status, NT_STATUS_OK); \
110 t2 = finfo.all_info.out.field; \
112 printf("(%s) wrong time for field %s %s - %s\n", \
113 __location__, #field, \
114 nt_time_string(mem_ctx, t), \
115 nt_time_string(mem_ctx, t2)); \
116 dump_all_info(mem_ctx, &finfo); \
120 #define CHECK_ALL_INFO(v, field) do { \
121 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
122 finfo.all_info.in.fname = fname; \
123 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo); \
124 CHECK_STATUS(status, NT_STATUS_OK); \
125 if ((v) != (finfo.all_info.out.field)) { \
126 printf("(%s) wrong value for field %s 0x%x - 0x%x\n", \
127 __location__, #field, (int)v, (int)(finfo.all_info.out.field)); \
128 dump_all_info(mem_ctx, &finfo); \
132 #define CHECK_VAL(v, correct) do { \
133 if ((v) != (correct)) { \
134 printf("(%s) wrong value for %s 0x%x - should be 0x%x\n", \
135 __location__, #v, (int)(v), (int)correct); \
139 #define SET_ATTRIB(sattrib) do { \
140 union smb_setfileinfo sfinfo; \
141 sfinfo.generic.level = RAW_SFILEINFO_BASIC_INFORMATION; \
142 sfinfo.generic.file.fname = fname; \
143 ZERO_STRUCT(sfinfo.basic_info.in); \
144 sfinfo.basic_info.in.attrib = sattrib; \
145 status = smb_raw_setpathinfo(cli->tree, &sfinfo); \
146 if (!NT_STATUS_IS_OK(status)) { \
147 printf("(%s) Failed to set attrib 0x%x on %s\n", \
148 __location__, sattrib, fname); \
154 static BOOL test_open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
157 union smb_fileinfo finfo;
158 const char *fname = BASEDIR "\\torture_open.txt";
160 int fnum = -1, fnum2;
163 printf("Checking RAW_OPEN_OPEN\n");
165 io.openold.level = RAW_OPEN_OPEN;
166 io.openold.in.fname = fname;
167 io.openold.in.open_mode = OPEN_FLAGS_FCB;
168 io.openold.in.search_attrs = 0;
169 status = smb_raw_open(cli->tree, mem_ctx, &io);
170 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
171 fnum = io.openold.out.fnum;
173 smbcli_unlink(cli->tree, fname);
175 smbcli_close(cli->tree, fnum);
177 status = smb_raw_open(cli->tree, mem_ctx, &io);
178 CHECK_STATUS(status, NT_STATUS_OK);
179 fnum = io.openold.out.fnum;
180 CHECK_RDWR(fnum, RDWR_RDWR);
182 status = smb_raw_open(cli->tree, mem_ctx, &io);
183 CHECK_STATUS(status, NT_STATUS_OK);
184 fnum2 = io.openold.out.fnum;
185 CHECK_RDWR(fnum2, RDWR_RDWR);
186 smbcli_close(cli->tree, fnum2);
187 smbcli_close(cli->tree, fnum);
189 /* check the read/write modes */
190 io.openold.level = RAW_OPEN_OPEN;
191 io.openold.in.fname = fname;
192 io.openold.in.search_attrs = 0;
194 io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ;
195 status = smb_raw_open(cli->tree, mem_ctx, &io);
196 CHECK_STATUS(status, NT_STATUS_OK);
197 fnum = io.openold.out.fnum;
198 CHECK_RDWR(fnum, RDWR_RDONLY);
199 smbcli_close(cli->tree, fnum);
201 io.openold.in.open_mode = OPEN_FLAGS_OPEN_WRITE;
202 status = smb_raw_open(cli->tree, mem_ctx, &io);
203 CHECK_STATUS(status, NT_STATUS_OK);
204 fnum = io.openold.out.fnum;
205 CHECK_RDWR(fnum, RDWR_WRONLY);
206 smbcli_close(cli->tree, fnum);
208 io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR;
209 status = smb_raw_open(cli->tree, mem_ctx, &io);
210 CHECK_STATUS(status, NT_STATUS_OK);
211 fnum = io.openold.out.fnum;
212 CHECK_RDWR(fnum, RDWR_RDWR);
213 smbcli_close(cli->tree, fnum);
215 /* check the share modes roughly - not a complete matrix */
216 io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_WRITE;
217 status = smb_raw_open(cli->tree, mem_ctx, &io);
218 CHECK_STATUS(status, NT_STATUS_OK);
219 fnum = io.openold.out.fnum;
220 CHECK_RDWR(fnum, RDWR_RDWR);
222 if (io.openold.in.open_mode != io.openold.out.rmode) {
223 printf("(%s) rmode should equal open_mode - 0x%x 0x%x\n",
224 __location__, io.openold.out.rmode, io.openold.in.open_mode);
227 io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_NONE;
228 status = smb_raw_open(cli->tree, mem_ctx, &io);
229 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
231 io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ | OPEN_FLAGS_DENY_NONE;
232 status = smb_raw_open(cli->tree, mem_ctx, &io);
233 CHECK_STATUS(status, NT_STATUS_OK);
234 fnum2 = io.openold.out.fnum;
235 CHECK_RDWR(fnum2, RDWR_RDONLY);
236 smbcli_close(cli->tree, fnum);
237 smbcli_close(cli->tree, fnum2);
240 /* check the returned write time */
241 io.openold.level = RAW_OPEN_OPEN;
242 io.openold.in.fname = fname;
243 io.openold.in.search_attrs = 0;
244 io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ;
245 status = smb_raw_open(cli->tree, mem_ctx, &io);
246 CHECK_STATUS(status, NT_STATUS_OK);
247 fnum = io.openold.out.fnum;
249 /* check other reply fields */
250 CHECK_TIME(io.openold.out.write_time, write_time);
251 CHECK_ALL_INFO(io.openold.out.size, size);
252 CHECK_ALL_INFO(io.openold.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
255 smbcli_close(cli->tree, fnum);
256 smbcli_unlink(cli->tree, fname);
265 static BOOL test_openx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
268 union smb_fileinfo finfo;
269 const char *fname = BASEDIR "\\torture_openx.txt";
270 const char *fname_exe = BASEDIR "\\torture_openx.exe";
272 int fnum = -1, fnum2;
279 NTSTATUS correct_status;
281 { OPENX_OPEN_FUNC_OPEN, True, NT_STATUS_OK },
282 { OPENX_OPEN_FUNC_OPEN, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
283 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OK },
284 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
285 { OPENX_OPEN_FUNC_FAIL, True, NT_STATUS_DOS(ERRDOS, ERRbadaccess) },
286 { OPENX_OPEN_FUNC_FAIL, False, NT_STATUS_DOS(ERRDOS, ERRbadaccess) },
287 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OBJECT_NAME_COLLISION },
288 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
289 { OPENX_OPEN_FUNC_TRUNC, True, NT_STATUS_OK },
290 { OPENX_OPEN_FUNC_TRUNC, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
291 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OK },
292 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
295 printf("Checking RAW_OPEN_OPENX\n");
296 smbcli_unlink(cli->tree, fname);
298 io.openx.level = RAW_OPEN_OPENX;
299 io.openx.in.fname = fname;
300 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
301 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
302 io.openx.in.search_attrs = 0;
303 io.openx.in.file_attrs = 0;
304 io.openx.in.write_time = 0;
305 io.openx.in.size = 1024*1024;
306 io.openx.in.timeout = 0;
308 /* check all combinations of open_func */
309 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
310 if (open_funcs[i].with_file) {
311 fnum = create_complex_file(cli, mem_ctx, fname);
313 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
317 smbcli_close(cli->tree, fnum);
319 io.openx.in.open_func = open_funcs[i].open_func;
320 status = smb_raw_open(cli->tree, mem_ctx, &io);
321 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
322 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n",
323 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
324 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_func);
327 if (NT_STATUS_IS_OK(status)) {
328 smbcli_close(cli->tree, io.openx.out.fnum);
330 if (open_funcs[i].with_file) {
331 smbcli_unlink(cli->tree, fname);
335 smbcli_unlink(cli->tree, fname);
337 /* check the basic return fields */
338 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
339 status = smb_raw_open(cli->tree, mem_ctx, &io);
340 CHECK_STATUS(status, NT_STATUS_OK);
341 fnum = io.openx.out.fnum;
343 CHECK_ALL_INFO(io.openx.out.size, size);
344 CHECK_TIME(io.openx.out.write_time, write_time);
345 CHECK_ALL_INFO(io.openx.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
346 CHECK_VAL(io.openx.out.access, OPENX_MODE_ACCESS_RDWR);
347 CHECK_VAL(io.openx.out.ftype, 0);
348 CHECK_VAL(io.openx.out.devstate, 0);
349 CHECK_VAL(io.openx.out.action, OPENX_ACTION_CREATED);
350 CHECK_VAL(io.openx.out.size, 1024*1024);
351 CHECK_ALL_INFO(io.openx.in.size, size);
352 smbcli_close(cli->tree, fnum);
353 smbcli_unlink(cli->tree, fname);
355 /* check the fields when the file already existed */
356 fnum2 = create_complex_file(cli, mem_ctx, fname);
361 smbcli_close(cli->tree, fnum2);
363 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
364 status = smb_raw_open(cli->tree, mem_ctx, &io);
365 CHECK_STATUS(status, NT_STATUS_OK);
366 fnum = io.openx.out.fnum;
368 CHECK_ALL_INFO(io.openx.out.size, size);
369 CHECK_TIME(io.openx.out.write_time, write_time);
370 CHECK_VAL(io.openx.out.action, OPENX_ACTION_EXISTED);
371 CHECK_VAL(io.openx.out.unknown, 0);
372 CHECK_ALL_INFO(io.openx.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
373 smbcli_close(cli->tree, fnum);
375 /* now check the search attrib for hidden files - win2003 ignores this? */
376 SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN);
377 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib);
379 io.openx.in.search_attrs = FILE_ATTRIBUTE_HIDDEN;
380 status = smb_raw_open(cli->tree, mem_ctx, &io);
381 CHECK_STATUS(status, NT_STATUS_OK);
382 smbcli_close(cli->tree, io.openx.out.fnum);
384 io.openx.in.search_attrs = 0;
385 status = smb_raw_open(cli->tree, mem_ctx, &io);
386 CHECK_STATUS(status, NT_STATUS_OK);
387 smbcli_close(cli->tree, io.openx.out.fnum);
389 SET_ATTRIB(FILE_ATTRIBUTE_NORMAL);
390 smbcli_unlink(cli->tree, fname);
392 /* and check attrib on create */
393 io.openx.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE;
394 io.openx.in.search_attrs = 0;
395 io.openx.in.file_attrs = FILE_ATTRIBUTE_SYSTEM;
396 status = smb_raw_open(cli->tree, mem_ctx, &io);
397 CHECK_STATUS(status, NT_STATUS_OK);
398 CHECK_ALL_INFO(FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE,
399 attrib & ~FILE_ATTRIBUTE_NONINDEXED);
400 smbcli_close(cli->tree, io.openx.out.fnum);
401 smbcli_unlink(cli->tree, fname);
403 /* check timeout on create - win2003 ignores the timeout! */
404 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
405 io.openx.in.file_attrs = 0;
406 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL;
407 status = smb_raw_open(cli->tree, mem_ctx, &io);
408 CHECK_STATUS(status, NT_STATUS_OK);
409 fnum = io.openx.out.fnum;
411 io.openx.in.timeout = 20000;
412 tv = timeval_current();
413 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_NONE;
414 status = smb_raw_open(cli->tree, mem_ctx, &io);
415 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
416 if (timeval_elapsed(&tv) > 3.0) {
417 printf("(%s) Incorrect timing in openx with timeout - waited %.2f seconds\n",
418 __location__, timeval_elapsed(&tv));
421 smbcli_close(cli->tree, fnum);
422 smbcli_unlink(cli->tree, fname);
424 /* now this is a really weird one - open for execute implies create?! */
425 io.openx.in.fname = fname;
426 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
427 io.openx.in.open_mode = OPENX_MODE_ACCESS_EXEC | OPENX_MODE_DENY_NONE;
428 io.openx.in.search_attrs = 0;
429 io.openx.in.open_func = OPENX_OPEN_FUNC_FAIL;
430 io.openx.in.file_attrs = 0;
431 io.openx.in.write_time = 0;
432 io.openx.in.size = 0;
433 io.openx.in.timeout = 0;
434 status = smb_raw_open(cli->tree, mem_ctx, &io);
435 CHECK_STATUS(status, NT_STATUS_OK);
436 smbcli_close(cli->tree, io.openx.out.fnum);
438 /* check the extended return flag */
439 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO | OPENX_FLAGS_EXTENDED_RETURN;
440 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
441 status = smb_raw_open(cli->tree, mem_ctx, &io);
442 CHECK_STATUS(status, NT_STATUS_OK);
443 CHECK_VAL(io.openx.out.access_mask, SEC_STD_ALL);
444 smbcli_close(cli->tree, io.openx.out.fnum);
446 io.openx.in.fname = "\\A.+,;=[].B";
447 status = smb_raw_open(cli->tree, mem_ctx, &io);
448 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
450 /* Check the mapping for open exec. */
452 /* First create an .exe file. */
453 smbcli_unlink(cli->tree, fname_exe);
454 fnum = create_complex_file(cli, mem_ctx, fname_exe);
455 smbcli_close(cli->tree, fnum);
457 io.openx.level = RAW_OPEN_OPENX;
458 io.openx.in.fname = fname_exe;
459 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
460 io.openx.in.open_mode = OPENX_MODE_ACCESS_EXEC | OPENX_MODE_DENY_NONE;
461 io.openx.in.search_attrs = 0;
462 io.openx.in.file_attrs = 0;
463 io.openx.in.write_time = 0;
464 io.openx.in.size = 0;
465 io.openx.in.timeout = 0;
466 status = smb_raw_open(cli->tree, mem_ctx, &io);
467 CHECK_STATUS(status, NT_STATUS_OK);
469 /* Can we read and write ? */
470 CHECK_RDWR(io.openx.out.fnum, RDWR_RDONLY);
471 smbcli_close(cli->tree, io.openx.out.fnum);
472 smbcli_unlink(cli->tree, fname);
475 smbcli_close(cli->tree, fnum);
476 smbcli_unlink(cli->tree, fname_exe);
477 smbcli_unlink(cli->tree, fname);
486 many thanks to kukks for a sniff showing how this works with os2->w2k
488 static BOOL test_t2open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
491 union smb_fileinfo finfo;
492 const char *fname1 = BASEDIR "\\torture_t2open_yes.txt";
493 const char *fname2 = BASEDIR "\\torture_t2open_no.txt";
494 const char *fname = BASEDIR "\\torture_t2open_3.txt";
502 NTSTATUS correct_status;
504 { OPENX_OPEN_FUNC_OPEN, True, NT_STATUS_OK },
505 { OPENX_OPEN_FUNC_OPEN, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
506 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OK },
507 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
508 { OPENX_OPEN_FUNC_FAIL, True, NT_STATUS_OBJECT_NAME_COLLISION },
509 { OPENX_OPEN_FUNC_FAIL, False, NT_STATUS_OBJECT_NAME_COLLISION },
510 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OBJECT_NAME_COLLISION },
511 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OBJECT_NAME_COLLISION },
512 { OPENX_OPEN_FUNC_TRUNC, True, NT_STATUS_OK },
513 { OPENX_OPEN_FUNC_TRUNC, False, NT_STATUS_OK },
514 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OK },
515 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
518 fnum = create_complex_file(cli, mem_ctx, fname1);
520 d_printf("Failed to create file %s - %s\n", fname1, smbcli_errstr(cli->tree));
524 smbcli_close(cli->tree, fnum);
526 printf("Checking RAW_OPEN_T2OPEN\n");
528 io.t2open.level = RAW_OPEN_T2OPEN;
529 io.t2open.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
530 io.t2open.in.open_mode = OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR;
531 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
532 io.t2open.in.search_attrs = 0;
533 io.t2open.in.file_attrs = 0;
534 io.t2open.in.write_time = 0;
535 io.t2open.in.size = 0;
536 io.t2open.in.timeout = 0;
538 io.t2open.in.num_eas = 3;
539 io.t2open.in.eas = talloc_array(mem_ctx, struct ea_struct, io.t2open.in.num_eas);
540 io.t2open.in.eas[0].flags = 0;
541 io.t2open.in.eas[0].name.s = ".CLASSINFO";
542 io.t2open.in.eas[0].value = data_blob_talloc(mem_ctx, "first value", 11);
543 io.t2open.in.eas[1].flags = 0;
544 io.t2open.in.eas[1].name.s = "EA TWO";
545 io.t2open.in.eas[1].value = data_blob_talloc(mem_ctx, "foo", 3);
546 io.t2open.in.eas[2].flags = 0;
547 io.t2open.in.eas[2].name.s = "X THIRD";
548 io.t2open.in.eas[2].value = data_blob_talloc(mem_ctx, "xy", 2);
550 /* check all combinations of open_func */
551 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
552 if (open_funcs[i].with_file) {
553 io.t2open.in.fname = fname1;
555 io.t2open.in.fname = fname2;
557 io.t2open.in.open_func = open_funcs[i].open_func;
558 status = smb_raw_open(cli->tree, mem_ctx, &io);
559 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
560 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n",
561 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
562 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_func);
565 if (NT_STATUS_IS_OK(status)) {
566 smbcli_close(cli->tree, io.t2open.out.fnum);
570 smbcli_unlink(cli->tree, fname1);
571 smbcli_unlink(cli->tree, fname2);
573 /* check the basic return fields */
574 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
575 io.t2open.in.write_time = 0;
576 io.t2open.in.fname = fname;
577 status = smb_raw_open(cli->tree, mem_ctx, &io);
578 CHECK_STATUS(status, NT_STATUS_OK);
579 fnum = io.t2open.out.fnum;
581 CHECK_ALL_INFO(io.t2open.out.size, size);
583 /* windows appears to leak uninitialised memory here */
584 CHECK_VAL(io.t2open.out.write_time, 0);
586 CHECK_ALL_INFO(io.t2open.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
587 CHECK_VAL(io.t2open.out.access, OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR);
588 CHECK_VAL(io.t2open.out.ftype, 0);
589 CHECK_VAL(io.t2open.out.devstate, 0);
590 CHECK_VAL(io.t2open.out.action, OPENX_ACTION_CREATED);
591 smbcli_close(cli->tree, fnum);
593 status = torture_check_ea(cli, fname, ".CLASSINFO", "first value");
594 CHECK_STATUS(status, NT_STATUS_OK);
595 status = torture_check_ea(cli, fname, "EA TWO", "foo");
596 CHECK_STATUS(status, NT_STATUS_OK);
597 status = torture_check_ea(cli, fname, "X THIRD", "xy");
598 CHECK_STATUS(status, NT_STATUS_OK);
600 /* now check the search attrib for hidden files - win2003 ignores this? */
601 SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN);
602 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib);
604 status = smb_raw_open(cli->tree, mem_ctx, &io);
605 CHECK_STATUS(status, NT_STATUS_OK);
606 smbcli_close(cli->tree, io.t2open.out.fnum);
608 status = smb_raw_open(cli->tree, mem_ctx, &io);
609 CHECK_STATUS(status, NT_STATUS_OK);
610 smbcli_close(cli->tree, io.t2open.out.fnum);
612 SET_ATTRIB(FILE_ATTRIBUTE_NORMAL);
613 smbcli_unlink(cli->tree, fname);
615 /* and check attrib on create */
616 io.t2open.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE;
617 io.t2open.in.file_attrs = FILE_ATTRIBUTE_SYSTEM;
618 status = smb_raw_open(cli->tree, mem_ctx, &io);
619 CHECK_STATUS(status, NT_STATUS_OK);
621 /* check timeout on create - win2003 ignores the timeout! */
622 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
623 io.t2open.in.file_attrs = 0;
624 io.t2open.in.timeout = 20000;
625 io.t2open.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL;
626 status = smb_raw_open(cli->tree, mem_ctx, &io);
627 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
630 smbcli_close(cli->tree, fnum);
631 smbcli_unlink(cli->tree, fname);
638 test RAW_OPEN_NTCREATEX
640 static BOOL test_ntcreatex(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
643 union smb_fileinfo finfo;
644 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
645 const char *dname = BASEDIR "\\torture_ntcreatex.dir";
653 NTSTATUS correct_status;
655 { NTCREATEX_DISP_SUPERSEDE, True, NT_STATUS_OK },
656 { NTCREATEX_DISP_SUPERSEDE, False, NT_STATUS_OK },
657 { NTCREATEX_DISP_OPEN, True, NT_STATUS_OK },
658 { NTCREATEX_DISP_OPEN, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
659 { NTCREATEX_DISP_CREATE, True, NT_STATUS_OBJECT_NAME_COLLISION },
660 { NTCREATEX_DISP_CREATE, False, NT_STATUS_OK },
661 { NTCREATEX_DISP_OPEN_IF, True, NT_STATUS_OK },
662 { NTCREATEX_DISP_OPEN_IF, False, NT_STATUS_OK },
663 { NTCREATEX_DISP_OVERWRITE, True, NT_STATUS_OK },
664 { NTCREATEX_DISP_OVERWRITE, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
665 { NTCREATEX_DISP_OVERWRITE_IF, True, NT_STATUS_OK },
666 { NTCREATEX_DISP_OVERWRITE_IF, False, NT_STATUS_OK },
667 { 6, True, NT_STATUS_INVALID_PARAMETER },
668 { 6, False, NT_STATUS_INVALID_PARAMETER },
671 printf("Checking RAW_OPEN_NTCREATEX\n");
673 /* reasonable default parameters */
674 io.generic.level = RAW_OPEN_NTCREATEX;
675 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
676 io.ntcreatex.in.root_fid = 0;
677 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
678 io.ntcreatex.in.alloc_size = 1024*1024;
679 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
680 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
681 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
682 io.ntcreatex.in.create_options = 0;
683 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
684 io.ntcreatex.in.security_flags = 0;
685 io.ntcreatex.in.fname = fname;
687 /* test the open disposition */
688 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
689 if (open_funcs[i].with_file) {
690 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE);
692 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
696 smbcli_close(cli->tree, fnum);
698 io.ntcreatex.in.open_disposition = open_funcs[i].open_disp;
699 status = smb_raw_open(cli->tree, mem_ctx, &io);
700 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
701 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_disp=%d)\n",
702 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
703 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_disp);
706 if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
707 smbcli_close(cli->tree, io.ntcreatex.out.fnum);
708 smbcli_unlink(cli->tree, fname);
712 /* basic field testing */
713 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
715 status = smb_raw_open(cli->tree, mem_ctx, &io);
716 CHECK_STATUS(status, NT_STATUS_OK);
717 fnum = io.ntcreatex.out.fnum;
719 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
720 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
721 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
722 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
723 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
724 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
725 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
726 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
727 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
728 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
729 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
731 /* check fields when the file already existed */
732 smbcli_close(cli->tree, fnum);
733 smbcli_unlink(cli->tree, fname);
734 fnum = create_complex_file(cli, mem_ctx, fname);
739 smbcli_close(cli->tree, fnum);
741 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
742 status = smb_raw_open(cli->tree, mem_ctx, &io);
743 CHECK_STATUS(status, NT_STATUS_OK);
744 fnum = io.ntcreatex.out.fnum;
746 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
747 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
748 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
749 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
750 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
751 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
752 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
753 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
754 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
755 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
756 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
757 smbcli_close(cli->tree, fnum);
758 smbcli_unlink(cli->tree, fname);
761 /* create a directory */
762 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
763 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
764 io.ntcreatex.in.alloc_size = 0;
765 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
766 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
767 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
768 io.ntcreatex.in.create_options = 0;
769 io.ntcreatex.in.fname = dname;
772 smbcli_rmdir(cli->tree, fname);
773 smbcli_unlink(cli->tree, fname);
775 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
776 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
777 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
778 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
779 status = smb_raw_open(cli->tree, mem_ctx, &io);
780 CHECK_STATUS(status, NT_STATUS_OK);
781 fnum = io.ntcreatex.out.fnum;
783 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
784 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
785 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
786 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
787 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
788 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
789 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
790 CHECK_VAL(io.ntcreatex.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED,
791 FILE_ATTRIBUTE_DIRECTORY);
792 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
793 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
794 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
795 CHECK_VAL(io.ntcreatex.out.is_directory, 1);
796 CHECK_VAL(io.ntcreatex.out.size, 0);
797 CHECK_VAL(io.ntcreatex.out.alloc_size, 0);
798 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
799 smbcli_unlink(cli->tree, fname);
803 smbcli_close(cli->tree, fnum);
804 smbcli_unlink(cli->tree, fname);
811 test RAW_OPEN_NTTRANS_CREATE
813 static BOOL test_nttrans_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
816 union smb_fileinfo finfo;
817 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
818 const char *dname = BASEDIR "\\torture_ntcreatex.dir";
826 NTSTATUS correct_status;
828 { NTCREATEX_DISP_SUPERSEDE, True, NT_STATUS_OK },
829 { NTCREATEX_DISP_SUPERSEDE, False, NT_STATUS_OK },
830 { NTCREATEX_DISP_OPEN, True, NT_STATUS_OK },
831 { NTCREATEX_DISP_OPEN, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
832 { NTCREATEX_DISP_CREATE, True, NT_STATUS_OBJECT_NAME_COLLISION },
833 { NTCREATEX_DISP_CREATE, False, NT_STATUS_OK },
834 { NTCREATEX_DISP_OPEN_IF, True, NT_STATUS_OK },
835 { NTCREATEX_DISP_OPEN_IF, False, NT_STATUS_OK },
836 { NTCREATEX_DISP_OVERWRITE, True, NT_STATUS_OK },
837 { NTCREATEX_DISP_OVERWRITE, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
838 { NTCREATEX_DISP_OVERWRITE_IF, True, NT_STATUS_OK },
839 { NTCREATEX_DISP_OVERWRITE_IF, False, NT_STATUS_OK },
840 { 6, True, NT_STATUS_INVALID_PARAMETER },
841 { 6, False, NT_STATUS_INVALID_PARAMETER },
844 printf("Checking RAW_OPEN_NTTRANS_CREATE\n");
846 /* reasonable default parameters */
847 io.generic.level = RAW_OPEN_NTTRANS_CREATE;
848 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
849 io.ntcreatex.in.root_fid = 0;
850 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
851 io.ntcreatex.in.alloc_size = 1024*1024;
852 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
853 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
854 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
855 io.ntcreatex.in.create_options = 0;
856 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
857 io.ntcreatex.in.security_flags = 0;
858 io.ntcreatex.in.fname = fname;
859 io.ntcreatex.in.sec_desc = NULL;
860 io.ntcreatex.in.ea_list = NULL;
862 /* test the open disposition */
863 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
864 if (open_funcs[i].with_file) {
865 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE);
867 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
871 smbcli_close(cli->tree, fnum);
873 io.ntcreatex.in.open_disposition = open_funcs[i].open_disp;
874 status = smb_raw_open(cli->tree, mem_ctx, &io);
875 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
876 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_disp=%d)\n",
877 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
878 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_disp);
881 if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
882 smbcli_close(cli->tree, io.ntcreatex.out.fnum);
883 smbcli_unlink(cli->tree, fname);
887 /* basic field testing */
888 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
890 status = smb_raw_open(cli->tree, mem_ctx, &io);
891 CHECK_STATUS(status, NT_STATUS_OK);
892 fnum = io.ntcreatex.out.fnum;
894 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
895 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
896 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
897 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
898 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
899 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
900 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
901 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
902 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
903 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
904 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
906 /* check fields when the file already existed */
907 smbcli_close(cli->tree, fnum);
908 smbcli_unlink(cli->tree, fname);
909 fnum = create_complex_file(cli, mem_ctx, fname);
914 smbcli_close(cli->tree, fnum);
916 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
917 status = smb_raw_open(cli->tree, mem_ctx, &io);
918 CHECK_STATUS(status, NT_STATUS_OK);
919 fnum = io.ntcreatex.out.fnum;
921 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
922 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
923 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
924 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
925 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
926 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
927 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
928 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
929 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
930 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
931 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
932 smbcli_close(cli->tree, fnum);
933 smbcli_unlink(cli->tree, fname);
936 /* create a directory */
937 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
938 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
939 io.ntcreatex.in.alloc_size = 0;
940 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
941 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
942 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
943 io.ntcreatex.in.create_options = 0;
944 io.ntcreatex.in.fname = dname;
947 smbcli_rmdir(cli->tree, fname);
948 smbcli_unlink(cli->tree, fname);
950 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
951 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
952 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
953 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
954 status = smb_raw_open(cli->tree, mem_ctx, &io);
955 CHECK_STATUS(status, NT_STATUS_OK);
956 fnum = io.ntcreatex.out.fnum;
958 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
959 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
960 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
961 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
962 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
963 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
964 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
965 CHECK_VAL(io.ntcreatex.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED,
966 FILE_ATTRIBUTE_DIRECTORY);
967 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
968 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
969 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
970 CHECK_VAL(io.ntcreatex.out.is_directory, 1);
971 CHECK_VAL(io.ntcreatex.out.size, 0);
972 CHECK_VAL(io.ntcreatex.out.alloc_size, 0);
973 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
974 smbcli_unlink(cli->tree, fname);
978 smbcli_close(cli->tree, fnum);
979 smbcli_unlink(cli->tree, fname);
985 test RAW_OPEN_NTCREATEX with an already opened and byte range locked file
987 I've got an application that does a similar sequence of ntcreate&x,
988 locking&x and another ntcreate&x with
989 open_disposition==NTCREATEX_DISP_OVERWRITE_IF. Windows 2003 allows the
992 static BOOL test_ntcreatex_brlocked(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
994 union smb_open io, io1;
996 struct smb_lock_entry lock[1];
997 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
1001 printf("Testing ntcreatex with a byte range locked file\n");
1003 io.generic.level = RAW_OPEN_NTCREATEX;
1004 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
1005 io.ntcreatex.in.root_fid = 0;
1006 io.ntcreatex.in.access_mask = 0x2019f;
1007 io.ntcreatex.in.alloc_size = 0;
1008 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1009 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1010 NTCREATEX_SHARE_ACCESS_WRITE;
1011 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1012 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
1013 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
1014 io.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC |
1015 NTCREATEX_SECURITY_ALL;
1016 io.ntcreatex.in.fname = fname;
1018 status = smb_raw_open(cli->tree, mem_ctx, &io);
1019 CHECK_STATUS(status, NT_STATUS_OK);
1021 io2.lockx.level = RAW_LOCK_LOCKX;
1022 io2.lockx.in.fnum = io.ntcreatex.out.fnum;
1023 io2.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
1024 io2.lockx.in.timeout = 0;
1025 io2.lockx.in.ulock_cnt = 0;
1026 io2.lockx.in.lock_cnt = 1;
1027 lock[0].pid = cli->session->pid;
1029 lock[0].count = 0x1;
1030 io2.lockx.in.locks = &lock[0];
1031 status = smb_raw_lock(cli->tree, &io2);
1032 CHECK_STATUS(status, NT_STATUS_OK);
1034 io1.generic.level = RAW_OPEN_NTCREATEX;
1035 io1.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
1036 io1.ntcreatex.in.root_fid = 0;
1037 io1.ntcreatex.in.access_mask = 0x20196;
1038 io1.ntcreatex.in.alloc_size = 0;
1039 io1.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1040 io1.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1041 NTCREATEX_SHARE_ACCESS_WRITE;
1042 io1.ntcreatex.in.open_disposition = NTCREATEX_DISP_OVERWRITE_IF;
1043 io1.ntcreatex.in.create_options = 0;
1044 io1.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
1045 io1.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC |
1046 NTCREATEX_SECURITY_ALL;
1047 io1.ntcreatex.in.fname = fname;
1049 status = smb_raw_open(cli->tree, mem_ctx, &io1);
1050 CHECK_STATUS(status, NT_STATUS_OK);
1053 smbcli_close(cli->tree, io.ntcreatex.out.fnum);
1054 smbcli_close(cli->tree, io1.ntcreatex.out.fnum);
1055 smbcli_unlink(cli->tree, fname);
1062 static BOOL test_mknew(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1065 const char *fname = BASEDIR "\\torture_mknew.txt";
1069 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1070 union smb_fileinfo finfo;
1072 printf("Checking RAW_OPEN_MKNEW\n");
1074 io.mknew.level = RAW_OPEN_MKNEW;
1075 io.mknew.in.attrib = 0;
1076 io.mknew.in.write_time = 0;
1077 io.mknew.in.fname = fname;
1078 status = smb_raw_open(cli->tree, mem_ctx, &io);
1079 CHECK_STATUS(status, NT_STATUS_OK);
1080 fnum = io.mknew.out.fnum;
1082 status = smb_raw_open(cli->tree, mem_ctx, &io);
1083 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
1085 smbcli_close(cli->tree, fnum);
1086 smbcli_unlink(cli->tree, fname);
1088 /* make sure write_time works */
1089 io.mknew.in.write_time = basetime;
1090 status = smb_raw_open(cli->tree, mem_ctx, &io);
1091 CHECK_STATUS(status, NT_STATUS_OK);
1092 fnum = io.mknew.out.fnum;
1093 CHECK_TIME(basetime, write_time);
1095 smbcli_close(cli->tree, fnum);
1096 smbcli_unlink(cli->tree, fname);
1098 /* make sure file_attrs works */
1099 io.mknew.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1100 status = smb_raw_open(cli->tree, mem_ctx, &io);
1101 CHECK_STATUS(status, NT_STATUS_OK);
1102 fnum = io.mknew.out.fnum;
1103 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE,
1104 attrib & ~FILE_ATTRIBUTE_NONINDEXED);
1107 smbcli_close(cli->tree, fnum);
1108 smbcli_unlink(cli->tree, fname);
1115 test RAW_OPEN_CREATE
1117 static BOOL test_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1120 const char *fname = BASEDIR "\\torture_create.txt";
1124 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1125 union smb_fileinfo finfo;
1127 printf("Checking RAW_OPEN_CREATE\n");
1129 io.create.level = RAW_OPEN_CREATE;
1130 io.create.in.attrib = 0;
1131 io.create.in.write_time = 0;
1132 io.create.in.fname = fname;
1133 status = smb_raw_open(cli->tree, mem_ctx, &io);
1134 CHECK_STATUS(status, NT_STATUS_OK);
1135 fnum = io.create.out.fnum;
1137 status = smb_raw_open(cli->tree, mem_ctx, &io);
1138 CHECK_STATUS(status, NT_STATUS_OK);
1140 smbcli_close(cli->tree, io.create.out.fnum);
1141 smbcli_close(cli->tree, fnum);
1142 smbcli_unlink(cli->tree, fname);
1144 /* make sure write_time works */
1145 io.create.in.write_time = basetime;
1146 status = smb_raw_open(cli->tree, mem_ctx, &io);
1147 CHECK_STATUS(status, NT_STATUS_OK);
1148 fnum = io.create.out.fnum;
1149 CHECK_TIME(basetime, write_time);
1151 smbcli_close(cli->tree, fnum);
1152 smbcli_unlink(cli->tree, fname);
1154 /* make sure file_attrs works */
1155 io.create.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1156 status = smb_raw_open(cli->tree, mem_ctx, &io);
1157 CHECK_STATUS(status, NT_STATUS_OK);
1158 fnum = io.create.out.fnum;
1159 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE,
1160 attrib & ~FILE_ATTRIBUTE_NONINDEXED);
1163 smbcli_close(cli->tree, fnum);
1164 smbcli_unlink(cli->tree, fname);
1173 static BOOL test_ctemp(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1179 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1180 union smb_fileinfo finfo;
1181 const char *name, *fname = NULL;
1183 printf("Checking RAW_OPEN_CTEMP\n");
1185 io.ctemp.level = RAW_OPEN_CTEMP;
1186 io.ctemp.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1187 io.ctemp.in.write_time = basetime;
1188 io.ctemp.in.directory = BASEDIR;
1189 status = smb_raw_open(cli->tree, mem_ctx, &io);
1190 CHECK_STATUS(status, NT_STATUS_OK);
1191 fnum = io.ctemp.out.fnum;
1193 name = io.ctemp.out.name;
1195 finfo.generic.level = RAW_FILEINFO_NAME_INFO;
1196 finfo.generic.in.fnum = fnum;
1197 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
1198 CHECK_STATUS(status, NT_STATUS_OK);
1200 fname = finfo.name_info.out.fname.s;
1201 d_printf("ctemp name=%s real name=%s\n", name, fname);
1204 smbcli_close(cli->tree, fnum);
1206 smbcli_unlink(cli->tree, fname);
1214 test chained RAW_OPEN_OPENX_READX
1216 static BOOL test_chained(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1219 const char *fname = BASEDIR "\\torture_chained.txt";
1223 const char *buf = "test";
1226 printf("Checking RAW_OPEN_OPENX chained with READX\n");
1227 smbcli_unlink(cli->tree, fname);
1229 fnum = create_complex_file(cli, mem_ctx, fname);
1231 smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf));
1233 smbcli_close(cli->tree, fnum);
1235 io.openxreadx.level = RAW_OPEN_OPENX_READX;
1236 io.openxreadx.in.fname = fname;
1237 io.openxreadx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
1238 io.openxreadx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
1239 io.openxreadx.in.open_func = OPENX_OPEN_FUNC_OPEN;
1240 io.openxreadx.in.search_attrs = 0;
1241 io.openxreadx.in.file_attrs = 0;
1242 io.openxreadx.in.write_time = 0;
1243 io.openxreadx.in.size = 1024*1024;
1244 io.openxreadx.in.timeout = 0;
1246 io.openxreadx.in.offset = 0;
1247 io.openxreadx.in.mincnt = sizeof(buf);
1248 io.openxreadx.in.maxcnt = sizeof(buf);
1249 io.openxreadx.in.remaining = 0;
1250 io.openxreadx.out.data = buf2;
1252 status = smb_raw_open(cli->tree, mem_ctx, &io);
1253 CHECK_STATUS(status, NT_STATUS_OK);
1254 fnum = io.openxreadx.out.fnum;
1256 if (memcmp(buf, buf2, sizeof(buf)) != 0) {
1257 d_printf("wrong data in reply buffer\n");
1262 smbcli_close(cli->tree, fnum);
1263 smbcli_unlink(cli->tree, fname);
1268 /* A little torture test to expose a race condition in Samba 3.0.20 ... :-) */
1270 static BOOL test_raw_open_multi(void)
1272 struct smbcli_state *cli;
1273 TALLOC_CTX *mem_ctx = talloc_init("torture_test_oplock_multi");
1274 const char *fname = "\\test_oplock.dat";
1278 struct smbcli_state **clients;
1279 struct smbcli_request **requests;
1280 union smb_open *ios;
1281 const char *host = lp_parm_string(-1, "torture", "host");
1282 const char *share = lp_parm_string(-1, "torture", "share");
1283 int i, num_files = 3;
1284 struct event_context *ev;
1286 int num_collision = 0;
1288 ev = event_context_init(mem_ctx);
1289 clients = talloc_array(mem_ctx, struct smbcli_state *, num_files);
1290 requests = talloc_array(mem_ctx, struct smbcli_request *, num_files);
1291 ios = talloc_array(mem_ctx, union smb_open, num_files);
1292 if ((ev == NULL) || (clients == NULL) || (requests == NULL) ||
1294 DEBUG(0, ("talloc failed\n"));
1298 if (!torture_open_connection_share(mem_ctx, &cli, host, share, ev)) {
1302 cli->tree->session->transport->options.request_timeout = 60000;
1304 for (i=0; i<num_files; i++) {
1305 if (!torture_open_connection_share(mem_ctx, &(clients[i]),
1307 DEBUG(0, ("Could not open %d'th connection\n", i));
1310 clients[i]->tree->session->transport->
1311 options.request_timeout = 60000;
1315 smbcli_unlink(cli->tree, fname);
1318 base ntcreatex parms
1320 io.generic.level = RAW_OPEN_NTCREATEX;
1321 io.ntcreatex.in.root_fid = 0;
1322 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
1323 io.ntcreatex.in.alloc_size = 0;
1324 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1325 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ|
1326 NTCREATEX_SHARE_ACCESS_WRITE|
1327 NTCREATEX_SHARE_ACCESS_DELETE;
1328 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1329 io.ntcreatex.in.create_options = 0;
1330 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1331 io.ntcreatex.in.security_flags = 0;
1332 io.ntcreatex.in.fname = fname;
1333 io.ntcreatex.in.flags = 0;
1335 for (i=0; i<num_files; i++) {
1337 requests[i] = smb_raw_open_send(clients[i]->tree, &ios[i]);
1338 if (requests[i] == NULL) {
1339 DEBUG(0, ("could not send %d'th request\n", i));
1344 DEBUG(10, ("waiting for replies\n"));
1346 BOOL unreplied = False;
1347 for (i=0; i<num_files; i++) {
1348 if (requests[i] == NULL) {
1351 if (requests[i]->state < SMBCLI_REQUEST_DONE) {
1355 status = smb_raw_open_recv(requests[i], mem_ctx,
1358 DEBUG(0, ("File %d returned status %s\n", i,
1359 nt_errstr(status)));
1361 if (NT_STATUS_IS_OK(status)) {
1365 if (NT_STATUS_EQUAL(status,
1366 NT_STATUS_OBJECT_NAME_COLLISION)) {
1376 if (event_loop_once(ev) != 0) {
1377 DEBUG(0, ("event_loop_once failed\n"));
1382 if ((num_ok != 1) || (num_ok + num_collision != num_files)) {
1386 for (i=0; i<num_files; i++) {
1387 torture_close_connection(clients[i]);
1389 talloc_free(mem_ctx);
1393 /* basic testing of all RAW_OPEN_* calls
1395 BOOL torture_raw_open(void)
1397 struct smbcli_state *cli;
1399 TALLOC_CTX *mem_ctx;
1401 if (!torture_open_connection(&cli)) {
1405 mem_ctx = talloc_init("torture_raw_open");
1407 if (!torture_setup_dir(cli, BASEDIR)) {
1411 ret &= test_ntcreatex_brlocked(cli, mem_ctx);
1412 ret &= test_open(cli, mem_ctx);
1413 ret &= test_raw_open_multi();
1414 ret &= test_openx(cli, mem_ctx);
1415 ret &= test_ntcreatex(cli, mem_ctx);
1416 ret &= test_nttrans_create(cli, mem_ctx);
1417 ret &= test_t2open(cli, mem_ctx);
1418 ret &= test_mknew(cli, mem_ctx);
1419 ret &= test_create(cli, mem_ctx);
1420 ret &= test_ctemp(cli, mem_ctx);
1421 ret &= test_chained(cli, mem_ctx);
1423 smb_raw_exit(cli->session);
1424 smbcli_deltree(cli->tree, BASEDIR);
1426 torture_close_connection(cli);
1427 talloc_free(mem_ctx);