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 "libcli/raw/libcliraw.h"
23 #include "system/time.h"
24 #include "system/filesys.h"
25 #include "librpc/gen_ndr/ndr_security.h"
26 #include "lib/events/events.h"
28 /* enum for whether reads/writes are possible on a file */
29 enum rdwr_mode {RDWR_NONE, RDWR_RDONLY, RDWR_WRONLY, RDWR_RDWR};
31 #define BASEDIR "\\rawopen"
34 check if a open file can be read/written
36 static enum rdwr_mode check_rdwr(struct smbcli_tree *tree, int fnum)
39 BOOL can_read = (smbcli_read(tree, fnum, &c, 0, 1) == 1);
40 BOOL can_write = (smbcli_write(tree, fnum, 0, &c, 0, 1) == 1);
41 if ( can_read && can_write) return RDWR_RDWR;
42 if ( can_read && !can_write) return RDWR_RDONLY;
43 if (!can_read && can_write) return RDWR_WRONLY;
48 describe a RDWR mode as a string
50 static const char *rdwr_string(enum rdwr_mode m)
53 case RDWR_NONE: return "NONE";
54 case RDWR_RDONLY: return "RDONLY";
55 case RDWR_WRONLY: return "WRONLY";
56 case RDWR_RDWR: return "RDWR";
61 #define CHECK_STATUS(status, correct) do { \
62 if (!NT_STATUS_EQUAL(status, correct)) { \
63 printf("(%s) Incorrect status %s - should be %s\n", \
64 __location__, nt_errstr(status), nt_errstr(correct)); \
69 #define CREATE_FILE do { \
70 fnum = create_complex_file(cli, mem_ctx, fname); \
72 printf("(%s) Failed to create %s - %s\n", __location__, fname, smbcli_errstr(cli->tree)); \
77 #define CHECK_RDWR(fnum, correct) do { \
78 enum rdwr_mode m = check_rdwr(cli->tree, fnum); \
80 printf("(%s) Incorrect readwrite mode %s - expected %s\n", \
81 __location__, rdwr_string(m), rdwr_string(correct)); \
85 #define CHECK_TIME(t, field) do { \
87 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
88 finfo.all_info.in.fname = fname; \
89 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo); \
90 CHECK_STATUS(status, NT_STATUS_OK); \
92 t2 = nt_time_to_unix(finfo.all_info.out.field) & ~1; \
93 if (ABS(t1-t2) > 2) { \
94 printf("(%s) wrong time for field %s %s - %s\n", \
95 __location__, #field, \
96 timestring(mem_ctx, t1), \
97 timestring(mem_ctx, t2)); \
98 dump_all_info(mem_ctx, &finfo); \
102 #define CHECK_NTTIME(t, field) do { \
104 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
105 finfo.all_info.in.fname = fname; \
106 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo); \
107 CHECK_STATUS(status, NT_STATUS_OK); \
108 t2 = finfo.all_info.out.field; \
110 printf("(%s) wrong time for field %s %s - %s\n", \
111 __location__, #field, \
112 nt_time_string(mem_ctx, t), \
113 nt_time_string(mem_ctx, t2)); \
114 dump_all_info(mem_ctx, &finfo); \
118 #define CHECK_ALL_INFO(v, field) do { \
119 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
120 finfo.all_info.in.fname = fname; \
121 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo); \
122 CHECK_STATUS(status, NT_STATUS_OK); \
123 if ((v) != (finfo.all_info.out.field)) { \
124 printf("(%s) wrong value for field %s 0x%x - 0x%x\n", \
125 __location__, #field, (int)v, (int)(finfo.all_info.out.field)); \
126 dump_all_info(mem_ctx, &finfo); \
130 #define CHECK_VAL(v, correct) do { \
131 if ((v) != (correct)) { \
132 printf("(%s) wrong value for %s 0x%x - should be 0x%x\n", \
133 __location__, #v, (int)(v), (int)correct); \
137 #define SET_ATTRIB(sattrib) do { \
138 union smb_setfileinfo sfinfo; \
139 sfinfo.generic.level = RAW_SFILEINFO_BASIC_INFORMATION; \
140 sfinfo.generic.file.fname = fname; \
141 ZERO_STRUCT(sfinfo.basic_info.in); \
142 sfinfo.basic_info.in.attrib = sattrib; \
143 status = smb_raw_setpathinfo(cli->tree, &sfinfo); \
144 if (!NT_STATUS_IS_OK(status)) { \
145 printf("(%s) Failed to set attrib 0x%x on %s\n", \
146 __location__, sattrib, fname); \
152 static BOOL test_open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
155 union smb_fileinfo finfo;
156 const char *fname = BASEDIR "\\torture_open.txt";
158 int fnum = -1, fnum2;
161 printf("Checking RAW_OPEN_OPEN\n");
163 io.openold.level = RAW_OPEN_OPEN;
164 io.openold.in.fname = fname;
165 io.openold.in.open_mode = OPEN_FLAGS_FCB;
166 io.openold.in.search_attrs = 0;
167 status = smb_raw_open(cli->tree, mem_ctx, &io);
168 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
169 fnum = io.openold.out.fnum;
171 smbcli_unlink(cli->tree, fname);
173 smbcli_close(cli->tree, fnum);
175 status = smb_raw_open(cli->tree, mem_ctx, &io);
176 CHECK_STATUS(status, NT_STATUS_OK);
177 fnum = io.openold.out.fnum;
178 CHECK_RDWR(fnum, RDWR_RDWR);
180 status = smb_raw_open(cli->tree, mem_ctx, &io);
181 CHECK_STATUS(status, NT_STATUS_OK);
182 fnum2 = io.openold.out.fnum;
183 CHECK_RDWR(fnum2, RDWR_RDWR);
184 smbcli_close(cli->tree, fnum2);
185 smbcli_close(cli->tree, fnum);
187 /* check the read/write modes */
188 io.openold.level = RAW_OPEN_OPEN;
189 io.openold.in.fname = fname;
190 io.openold.in.search_attrs = 0;
192 io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ;
193 status = smb_raw_open(cli->tree, mem_ctx, &io);
194 CHECK_STATUS(status, NT_STATUS_OK);
195 fnum = io.openold.out.fnum;
196 CHECK_RDWR(fnum, RDWR_RDONLY);
197 smbcli_close(cli->tree, fnum);
199 io.openold.in.open_mode = OPEN_FLAGS_OPEN_WRITE;
200 status = smb_raw_open(cli->tree, mem_ctx, &io);
201 CHECK_STATUS(status, NT_STATUS_OK);
202 fnum = io.openold.out.fnum;
203 CHECK_RDWR(fnum, RDWR_WRONLY);
204 smbcli_close(cli->tree, fnum);
206 io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR;
207 status = smb_raw_open(cli->tree, mem_ctx, &io);
208 CHECK_STATUS(status, NT_STATUS_OK);
209 fnum = io.openold.out.fnum;
210 CHECK_RDWR(fnum, RDWR_RDWR);
211 smbcli_close(cli->tree, fnum);
213 /* check the share modes roughly - not a complete matrix */
214 io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_WRITE;
215 status = smb_raw_open(cli->tree, mem_ctx, &io);
216 CHECK_STATUS(status, NT_STATUS_OK);
217 fnum = io.openold.out.fnum;
218 CHECK_RDWR(fnum, RDWR_RDWR);
220 if (io.openold.in.open_mode != io.openold.out.rmode) {
221 printf("(%s) rmode should equal open_mode - 0x%x 0x%x\n",
222 __location__, io.openold.out.rmode, io.openold.in.open_mode);
225 io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_NONE;
226 status = smb_raw_open(cli->tree, mem_ctx, &io);
227 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
229 io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ | OPEN_FLAGS_DENY_NONE;
230 status = smb_raw_open(cli->tree, mem_ctx, &io);
231 CHECK_STATUS(status, NT_STATUS_OK);
232 fnum2 = io.openold.out.fnum;
233 CHECK_RDWR(fnum2, RDWR_RDONLY);
234 smbcli_close(cli->tree, fnum);
235 smbcli_close(cli->tree, fnum2);
238 /* check the returned write time */
239 io.openold.level = RAW_OPEN_OPEN;
240 io.openold.in.fname = fname;
241 io.openold.in.search_attrs = 0;
242 io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ;
243 status = smb_raw_open(cli->tree, mem_ctx, &io);
244 CHECK_STATUS(status, NT_STATUS_OK);
245 fnum = io.openold.out.fnum;
247 /* check other reply fields */
248 CHECK_TIME(io.openold.out.write_time, write_time);
249 CHECK_ALL_INFO(io.openold.out.size, size);
250 CHECK_ALL_INFO(io.openold.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
253 smbcli_close(cli->tree, fnum);
254 smbcli_unlink(cli->tree, fname);
263 static BOOL test_openx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
266 union smb_fileinfo finfo;
267 const char *fname = BASEDIR "\\torture_openx.txt";
269 int fnum = -1, fnum2;
276 NTSTATUS correct_status;
278 { OPENX_OPEN_FUNC_OPEN, True, NT_STATUS_OK },
279 { OPENX_OPEN_FUNC_OPEN, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
280 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OK },
281 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
282 { OPENX_OPEN_FUNC_FAIL, True, NT_STATUS_DOS(ERRDOS, ERRbadaccess) },
283 { OPENX_OPEN_FUNC_FAIL, False, NT_STATUS_DOS(ERRDOS, ERRbadaccess) },
284 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OBJECT_NAME_COLLISION },
285 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
286 { OPENX_OPEN_FUNC_TRUNC, True, NT_STATUS_OK },
287 { OPENX_OPEN_FUNC_TRUNC, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
288 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OK },
289 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
292 printf("Checking RAW_OPEN_OPENX\n");
293 smbcli_unlink(cli->tree, fname);
295 io.openx.level = RAW_OPEN_OPENX;
296 io.openx.in.fname = fname;
297 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
298 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
299 io.openx.in.search_attrs = 0;
300 io.openx.in.file_attrs = 0;
301 io.openx.in.write_time = 0;
302 io.openx.in.size = 1024*1024;
303 io.openx.in.timeout = 0;
305 /* check all combinations of open_func */
306 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
307 if (open_funcs[i].with_file) {
308 fnum = create_complex_file(cli, mem_ctx, fname);
310 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
314 smbcli_close(cli->tree, fnum);
316 io.openx.in.open_func = open_funcs[i].open_func;
317 status = smb_raw_open(cli->tree, mem_ctx, &io);
318 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
319 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n",
320 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
321 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_func);
324 if (NT_STATUS_IS_OK(status)) {
325 smbcli_close(cli->tree, io.openx.out.fnum);
327 if (open_funcs[i].with_file) {
328 smbcli_unlink(cli->tree, fname);
332 smbcli_unlink(cli->tree, fname);
334 /* check the basic return fields */
335 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
336 status = smb_raw_open(cli->tree, mem_ctx, &io);
337 CHECK_STATUS(status, NT_STATUS_OK);
338 fnum = io.openx.out.fnum;
340 CHECK_ALL_INFO(io.openx.out.size, size);
341 CHECK_TIME(io.openx.out.write_time, write_time);
342 CHECK_ALL_INFO(io.openx.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
343 CHECK_VAL(io.openx.out.access, OPENX_MODE_ACCESS_RDWR);
344 CHECK_VAL(io.openx.out.ftype, 0);
345 CHECK_VAL(io.openx.out.devstate, 0);
346 CHECK_VAL(io.openx.out.action, OPENX_ACTION_CREATED);
347 CHECK_VAL(io.openx.out.size, 1024*1024);
348 CHECK_ALL_INFO(io.openx.in.size, size);
349 smbcli_close(cli->tree, fnum);
350 smbcli_unlink(cli->tree, fname);
352 /* check the fields when the file already existed */
353 fnum2 = create_complex_file(cli, mem_ctx, fname);
358 smbcli_close(cli->tree, fnum2);
360 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
361 status = smb_raw_open(cli->tree, mem_ctx, &io);
362 CHECK_STATUS(status, NT_STATUS_OK);
363 fnum = io.openx.out.fnum;
365 CHECK_ALL_INFO(io.openx.out.size, size);
366 CHECK_TIME(io.openx.out.write_time, write_time);
367 CHECK_VAL(io.openx.out.action, OPENX_ACTION_EXISTED);
368 CHECK_VAL(io.openx.out.unknown, 0);
369 CHECK_ALL_INFO(io.openx.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
370 smbcli_close(cli->tree, fnum);
372 /* now check the search attrib for hidden files - win2003 ignores this? */
373 SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN);
374 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib);
376 io.openx.in.search_attrs = FILE_ATTRIBUTE_HIDDEN;
377 status = smb_raw_open(cli->tree, mem_ctx, &io);
378 CHECK_STATUS(status, NT_STATUS_OK);
379 smbcli_close(cli->tree, io.openx.out.fnum);
381 io.openx.in.search_attrs = 0;
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.fnum);
386 SET_ATTRIB(FILE_ATTRIBUTE_NORMAL);
387 smbcli_unlink(cli->tree, fname);
389 /* and check attrib on create */
390 io.openx.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE;
391 io.openx.in.search_attrs = 0;
392 io.openx.in.file_attrs = FILE_ATTRIBUTE_SYSTEM;
393 status = smb_raw_open(cli->tree, mem_ctx, &io);
394 CHECK_STATUS(status, NT_STATUS_OK);
395 CHECK_ALL_INFO(FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE,
396 attrib & ~FILE_ATTRIBUTE_NONINDEXED);
397 smbcli_close(cli->tree, io.openx.out.fnum);
398 smbcli_unlink(cli->tree, fname);
400 /* check timeout on create - win2003 ignores the timeout! */
401 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
402 io.openx.in.file_attrs = 0;
403 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL;
404 status = smb_raw_open(cli->tree, mem_ctx, &io);
405 CHECK_STATUS(status, NT_STATUS_OK);
406 fnum = io.openx.out.fnum;
408 io.openx.in.timeout = 20000;
409 tv = timeval_current();
410 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_NONE;
411 status = smb_raw_open(cli->tree, mem_ctx, &io);
412 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
413 if (timeval_elapsed(&tv) > 3.0) {
414 printf("(%s) Incorrect timing in openx with timeout - waited %.2f seconds\n",
415 __location__, timeval_elapsed(&tv));
418 smbcli_close(cli->tree, fnum);
419 smbcli_unlink(cli->tree, fname);
421 /* now this is a really weird one - open for execute implies create?! */
422 io.openx.in.fname = fname;
423 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
424 io.openx.in.open_mode = OPENX_MODE_ACCESS_EXEC | OPENX_MODE_DENY_NONE;
425 io.openx.in.search_attrs = 0;
426 io.openx.in.open_func = OPENX_OPEN_FUNC_FAIL;
427 io.openx.in.file_attrs = 0;
428 io.openx.in.write_time = 0;
429 io.openx.in.size = 0;
430 io.openx.in.timeout = 0;
431 status = smb_raw_open(cli->tree, mem_ctx, &io);
432 CHECK_STATUS(status, NT_STATUS_OK);
433 smbcli_close(cli->tree, io.openx.out.fnum);
435 /* check the extended return flag */
436 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO | OPENX_FLAGS_EXTENDED_RETURN;
437 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
438 status = smb_raw_open(cli->tree, mem_ctx, &io);
439 CHECK_STATUS(status, NT_STATUS_OK);
440 CHECK_VAL(io.openx.out.access_mask, SEC_STD_ALL);
441 smbcli_close(cli->tree, io.openx.out.fnum);
443 io.openx.in.fname = "\\A.+,;=[].B";
444 status = smb_raw_open(cli->tree, mem_ctx, &io);
445 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
448 smbcli_close(cli->tree, fnum);
449 smbcli_unlink(cli->tree, fname);
458 many thanks to kukks for a sniff showing how this works with os2->w2k
460 static BOOL test_t2open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
463 union smb_fileinfo finfo;
464 const char *fname1 = BASEDIR "\\torture_t2open_yes.txt";
465 const char *fname2 = BASEDIR "\\torture_t2open_no.txt";
466 const char *fname = BASEDIR "\\torture_t2open_3.txt";
474 NTSTATUS correct_status;
476 { OPENX_OPEN_FUNC_OPEN, True, NT_STATUS_OK },
477 { OPENX_OPEN_FUNC_OPEN, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
478 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OK },
479 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
480 { OPENX_OPEN_FUNC_FAIL, True, NT_STATUS_OBJECT_NAME_COLLISION },
481 { OPENX_OPEN_FUNC_FAIL, False, NT_STATUS_OBJECT_NAME_COLLISION },
482 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OBJECT_NAME_COLLISION },
483 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OBJECT_NAME_COLLISION },
484 { OPENX_OPEN_FUNC_TRUNC, True, NT_STATUS_OK },
485 { OPENX_OPEN_FUNC_TRUNC, False, NT_STATUS_OK },
486 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OK },
487 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
490 fnum = create_complex_file(cli, mem_ctx, fname1);
492 d_printf("Failed to create file %s - %s\n", fname1, smbcli_errstr(cli->tree));
496 smbcli_close(cli->tree, fnum);
498 printf("Checking RAW_OPEN_T2OPEN\n");
500 io.t2open.level = RAW_OPEN_T2OPEN;
501 io.t2open.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
502 io.t2open.in.open_mode = OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR;
503 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
504 io.t2open.in.search_attrs = 0;
505 io.t2open.in.file_attrs = 0;
506 io.t2open.in.write_time = 0;
507 io.t2open.in.size = 0;
508 io.t2open.in.timeout = 0;
510 io.t2open.in.num_eas = 3;
511 io.t2open.in.eas = talloc_array(mem_ctx, struct ea_struct, io.t2open.in.num_eas);
512 io.t2open.in.eas[0].flags = 0;
513 io.t2open.in.eas[0].name.s = ".CLASSINFO";
514 io.t2open.in.eas[0].value = data_blob_talloc(mem_ctx, "first value", 11);
515 io.t2open.in.eas[1].flags = 0;
516 io.t2open.in.eas[1].name.s = "EA TWO";
517 io.t2open.in.eas[1].value = data_blob_talloc(mem_ctx, "foo", 3);
518 io.t2open.in.eas[2].flags = 0;
519 io.t2open.in.eas[2].name.s = "X THIRD";
520 io.t2open.in.eas[2].value = data_blob_talloc(mem_ctx, "xy", 2);
522 /* check all combinations of open_func */
523 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
524 if (open_funcs[i].with_file) {
525 io.t2open.in.fname = fname1;
527 io.t2open.in.fname = fname2;
529 io.t2open.in.open_func = open_funcs[i].open_func;
530 status = smb_raw_open(cli->tree, mem_ctx, &io);
531 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
532 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n",
533 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
534 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_func);
537 if (NT_STATUS_IS_OK(status)) {
538 smbcli_close(cli->tree, io.t2open.out.fnum);
542 smbcli_unlink(cli->tree, fname1);
543 smbcli_unlink(cli->tree, fname2);
545 /* check the basic return fields */
546 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
547 io.t2open.in.write_time = 0;
548 io.t2open.in.fname = fname;
549 status = smb_raw_open(cli->tree, mem_ctx, &io);
550 CHECK_STATUS(status, NT_STATUS_OK);
551 fnum = io.t2open.out.fnum;
553 CHECK_ALL_INFO(io.t2open.out.size, size);
555 /* windows appears to leak uninitialised memory here */
556 CHECK_VAL(io.t2open.out.write_time, 0);
558 CHECK_ALL_INFO(io.t2open.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
559 CHECK_VAL(io.t2open.out.access, OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR);
560 CHECK_VAL(io.t2open.out.ftype, 0);
561 CHECK_VAL(io.t2open.out.devstate, 0);
562 CHECK_VAL(io.t2open.out.action, OPENX_ACTION_CREATED);
563 smbcli_close(cli->tree, fnum);
565 status = torture_check_ea(cli, fname, ".CLASSINFO", "first value");
566 CHECK_STATUS(status, NT_STATUS_OK);
567 status = torture_check_ea(cli, fname, "EA TWO", "foo");
568 CHECK_STATUS(status, NT_STATUS_OK);
569 status = torture_check_ea(cli, fname, "X THIRD", "xy");
570 CHECK_STATUS(status, NT_STATUS_OK);
572 /* now check the search attrib for hidden files - win2003 ignores this? */
573 SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN);
574 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib);
576 status = smb_raw_open(cli->tree, mem_ctx, &io);
577 CHECK_STATUS(status, NT_STATUS_OK);
578 smbcli_close(cli->tree, io.t2open.out.fnum);
580 status = smb_raw_open(cli->tree, mem_ctx, &io);
581 CHECK_STATUS(status, NT_STATUS_OK);
582 smbcli_close(cli->tree, io.t2open.out.fnum);
584 SET_ATTRIB(FILE_ATTRIBUTE_NORMAL);
585 smbcli_unlink(cli->tree, fname);
587 /* and check attrib on create */
588 io.t2open.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE;
589 io.t2open.in.file_attrs = FILE_ATTRIBUTE_SYSTEM;
590 status = smb_raw_open(cli->tree, mem_ctx, &io);
591 CHECK_STATUS(status, NT_STATUS_OK);
593 /* check timeout on create - win2003 ignores the timeout! */
594 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
595 io.t2open.in.file_attrs = 0;
596 io.t2open.in.timeout = 20000;
597 io.t2open.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL;
598 status = smb_raw_open(cli->tree, mem_ctx, &io);
599 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
602 smbcli_close(cli->tree, fnum);
603 smbcli_unlink(cli->tree, fname);
610 test RAW_OPEN_NTCREATEX
612 static BOOL test_ntcreatex(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
615 union smb_fileinfo finfo;
616 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
617 const char *dname = BASEDIR "\\torture_ntcreatex.dir";
625 NTSTATUS correct_status;
627 { NTCREATEX_DISP_SUPERSEDE, True, NT_STATUS_OK },
628 { NTCREATEX_DISP_SUPERSEDE, False, NT_STATUS_OK },
629 { NTCREATEX_DISP_OPEN, True, NT_STATUS_OK },
630 { NTCREATEX_DISP_OPEN, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
631 { NTCREATEX_DISP_CREATE, True, NT_STATUS_OBJECT_NAME_COLLISION },
632 { NTCREATEX_DISP_CREATE, False, NT_STATUS_OK },
633 { NTCREATEX_DISP_OPEN_IF, True, NT_STATUS_OK },
634 { NTCREATEX_DISP_OPEN_IF, False, NT_STATUS_OK },
635 { NTCREATEX_DISP_OVERWRITE, True, NT_STATUS_OK },
636 { NTCREATEX_DISP_OVERWRITE, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
637 { NTCREATEX_DISP_OVERWRITE_IF, True, NT_STATUS_OK },
638 { NTCREATEX_DISP_OVERWRITE_IF, False, NT_STATUS_OK },
639 { 6, True, NT_STATUS_INVALID_PARAMETER },
640 { 6, False, NT_STATUS_INVALID_PARAMETER },
643 printf("Checking RAW_OPEN_NTCREATEX\n");
645 /* reasonable default parameters */
646 io.generic.level = RAW_OPEN_NTCREATEX;
647 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
648 io.ntcreatex.in.root_fid = 0;
649 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
650 io.ntcreatex.in.alloc_size = 1024*1024;
651 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
652 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
653 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
654 io.ntcreatex.in.create_options = 0;
655 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
656 io.ntcreatex.in.security_flags = 0;
657 io.ntcreatex.in.fname = fname;
659 /* test the open disposition */
660 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
661 if (open_funcs[i].with_file) {
662 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE);
664 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
668 smbcli_close(cli->tree, fnum);
670 io.ntcreatex.in.open_disposition = open_funcs[i].open_disp;
671 status = smb_raw_open(cli->tree, mem_ctx, &io);
672 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
673 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_disp=%d)\n",
674 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
675 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_disp);
678 if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
679 smbcli_close(cli->tree, io.ntcreatex.out.fnum);
680 smbcli_unlink(cli->tree, fname);
684 /* basic field testing */
685 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
687 status = smb_raw_open(cli->tree, mem_ctx, &io);
688 CHECK_STATUS(status, NT_STATUS_OK);
689 fnum = io.ntcreatex.out.fnum;
691 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
692 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
693 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
694 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
695 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
696 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
697 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
698 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
699 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
700 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
701 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
703 /* check fields when the file already existed */
704 smbcli_close(cli->tree, fnum);
705 smbcli_unlink(cli->tree, fname);
706 fnum = create_complex_file(cli, mem_ctx, fname);
711 smbcli_close(cli->tree, fnum);
713 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
714 status = smb_raw_open(cli->tree, mem_ctx, &io);
715 CHECK_STATUS(status, NT_STATUS_OK);
716 fnum = io.ntcreatex.out.fnum;
718 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
719 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
720 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
721 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
722 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
723 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
724 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
725 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
726 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
727 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
728 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
729 smbcli_close(cli->tree, fnum);
730 smbcli_unlink(cli->tree, fname);
733 /* create a directory */
734 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
735 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
736 io.ntcreatex.in.alloc_size = 0;
737 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
738 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
739 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
740 io.ntcreatex.in.create_options = 0;
741 io.ntcreatex.in.fname = dname;
744 smbcli_rmdir(cli->tree, fname);
745 smbcli_unlink(cli->tree, fname);
747 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
748 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
749 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
750 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
751 status = smb_raw_open(cli->tree, mem_ctx, &io);
752 CHECK_STATUS(status, NT_STATUS_OK);
753 fnum = io.ntcreatex.out.fnum;
755 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
756 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
757 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
758 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
759 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
760 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
761 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
762 CHECK_VAL(io.ntcreatex.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED,
763 FILE_ATTRIBUTE_DIRECTORY);
764 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
765 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
766 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
767 CHECK_VAL(io.ntcreatex.out.is_directory, 1);
768 CHECK_VAL(io.ntcreatex.out.size, 0);
769 CHECK_VAL(io.ntcreatex.out.alloc_size, 0);
770 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
771 smbcli_unlink(cli->tree, fname);
775 smbcli_close(cli->tree, fnum);
776 smbcli_unlink(cli->tree, fname);
783 test RAW_OPEN_NTTRANS_CREATE
785 static BOOL test_nttrans_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
788 union smb_fileinfo finfo;
789 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
790 const char *dname = BASEDIR "\\torture_ntcreatex.dir";
798 NTSTATUS correct_status;
800 { NTCREATEX_DISP_SUPERSEDE, True, NT_STATUS_OK },
801 { NTCREATEX_DISP_SUPERSEDE, False, NT_STATUS_OK },
802 { NTCREATEX_DISP_OPEN, True, NT_STATUS_OK },
803 { NTCREATEX_DISP_OPEN, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
804 { NTCREATEX_DISP_CREATE, True, NT_STATUS_OBJECT_NAME_COLLISION },
805 { NTCREATEX_DISP_CREATE, False, NT_STATUS_OK },
806 { NTCREATEX_DISP_OPEN_IF, True, NT_STATUS_OK },
807 { NTCREATEX_DISP_OPEN_IF, False, NT_STATUS_OK },
808 { NTCREATEX_DISP_OVERWRITE, True, NT_STATUS_OK },
809 { NTCREATEX_DISP_OVERWRITE, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
810 { NTCREATEX_DISP_OVERWRITE_IF, True, NT_STATUS_OK },
811 { NTCREATEX_DISP_OVERWRITE_IF, False, NT_STATUS_OK },
812 { 6, True, NT_STATUS_INVALID_PARAMETER },
813 { 6, False, NT_STATUS_INVALID_PARAMETER },
816 printf("Checking RAW_OPEN_NTTRANS_CREATE\n");
818 /* reasonable default parameters */
819 io.generic.level = RAW_OPEN_NTTRANS_CREATE;
820 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
821 io.ntcreatex.in.root_fid = 0;
822 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
823 io.ntcreatex.in.alloc_size = 1024*1024;
824 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
825 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
826 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
827 io.ntcreatex.in.create_options = 0;
828 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
829 io.ntcreatex.in.security_flags = 0;
830 io.ntcreatex.in.fname = fname;
831 io.ntcreatex.in.sec_desc = NULL;
832 io.ntcreatex.in.ea_list = NULL;
834 /* test the open disposition */
835 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
836 if (open_funcs[i].with_file) {
837 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE);
839 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
843 smbcli_close(cli->tree, fnum);
845 io.ntcreatex.in.open_disposition = open_funcs[i].open_disp;
846 status = smb_raw_open(cli->tree, mem_ctx, &io);
847 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
848 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_disp=%d)\n",
849 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
850 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_disp);
853 if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
854 smbcli_close(cli->tree, io.ntcreatex.out.fnum);
855 smbcli_unlink(cli->tree, fname);
859 /* basic field testing */
860 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
862 status = smb_raw_open(cli->tree, mem_ctx, &io);
863 CHECK_STATUS(status, NT_STATUS_OK);
864 fnum = io.ntcreatex.out.fnum;
866 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
867 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
868 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
869 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
870 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
871 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
872 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
873 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
874 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
875 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
876 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
878 /* check fields when the file already existed */
879 smbcli_close(cli->tree, fnum);
880 smbcli_unlink(cli->tree, fname);
881 fnum = create_complex_file(cli, mem_ctx, fname);
886 smbcli_close(cli->tree, fnum);
888 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
889 status = smb_raw_open(cli->tree, mem_ctx, &io);
890 CHECK_STATUS(status, NT_STATUS_OK);
891 fnum = io.ntcreatex.out.fnum;
893 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
894 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
895 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
896 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
897 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
898 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
899 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
900 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
901 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
902 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
903 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
904 smbcli_close(cli->tree, fnum);
905 smbcli_unlink(cli->tree, fname);
908 /* create a directory */
909 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
910 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
911 io.ntcreatex.in.alloc_size = 0;
912 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
913 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
914 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
915 io.ntcreatex.in.create_options = 0;
916 io.ntcreatex.in.fname = dname;
919 smbcli_rmdir(cli->tree, fname);
920 smbcli_unlink(cli->tree, fname);
922 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
923 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
924 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
925 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
926 status = smb_raw_open(cli->tree, mem_ctx, &io);
927 CHECK_STATUS(status, NT_STATUS_OK);
928 fnum = io.ntcreatex.out.fnum;
930 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
931 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
932 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
933 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
934 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
935 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
936 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
937 CHECK_VAL(io.ntcreatex.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED,
938 FILE_ATTRIBUTE_DIRECTORY);
939 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
940 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
941 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
942 CHECK_VAL(io.ntcreatex.out.is_directory, 1);
943 CHECK_VAL(io.ntcreatex.out.size, 0);
944 CHECK_VAL(io.ntcreatex.out.alloc_size, 0);
945 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
946 smbcli_unlink(cli->tree, fname);
950 smbcli_close(cli->tree, fnum);
951 smbcli_unlink(cli->tree, fname);
957 test RAW_OPEN_NTCREATEX with an already opened and byte range locked file
959 I've got an application that does a similar sequence of ntcreate&x,
960 locking&x and another ntcreate&x with
961 open_disposition==NTCREATEX_DISP_OVERWRITE_IF. Windows 2003 allows the
964 static BOOL test_ntcreatex_brlocked(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
966 union smb_open io, io1;
968 struct smb_lock_entry lock[1];
969 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
973 printf("Testing ntcreatex with a byte range locked file\n");
975 io.generic.level = RAW_OPEN_NTCREATEX;
976 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
977 io.ntcreatex.in.root_fid = 0;
978 io.ntcreatex.in.access_mask = 0x2019f;
979 io.ntcreatex.in.alloc_size = 0;
980 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
981 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
982 NTCREATEX_SHARE_ACCESS_WRITE;
983 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
984 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
985 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
986 io.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC |
987 NTCREATEX_SECURITY_ALL;
988 io.ntcreatex.in.fname = fname;
990 status = smb_raw_open(cli->tree, mem_ctx, &io);
991 CHECK_STATUS(status, NT_STATUS_OK);
993 io2.lockx.level = RAW_LOCK_LOCKX;
994 io2.lockx.in.fnum = io.ntcreatex.out.fnum;
995 io2.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
996 io2.lockx.in.timeout = 0;
997 io2.lockx.in.ulock_cnt = 0;
998 io2.lockx.in.lock_cnt = 1;
999 lock[0].pid = cli->session->pid;
1001 lock[0].count = 0x1;
1002 io2.lockx.in.locks = &lock[0];
1003 status = smb_raw_lock(cli->tree, &io2);
1004 CHECK_STATUS(status, NT_STATUS_OK);
1006 io1.generic.level = RAW_OPEN_NTCREATEX;
1007 io1.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
1008 io1.ntcreatex.in.root_fid = 0;
1009 io1.ntcreatex.in.access_mask = 0x20196;
1010 io1.ntcreatex.in.alloc_size = 0;
1011 io1.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1012 io1.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1013 NTCREATEX_SHARE_ACCESS_WRITE;
1014 io1.ntcreatex.in.open_disposition = NTCREATEX_DISP_OVERWRITE_IF;
1015 io1.ntcreatex.in.create_options = 0;
1016 io1.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
1017 io1.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC |
1018 NTCREATEX_SECURITY_ALL;
1019 io1.ntcreatex.in.fname = fname;
1021 status = smb_raw_open(cli->tree, mem_ctx, &io1);
1022 CHECK_STATUS(status, NT_STATUS_OK);
1025 smbcli_close(cli->tree, io.ntcreatex.out.fnum);
1026 smbcli_close(cli->tree, io1.ntcreatex.out.fnum);
1027 smbcli_unlink(cli->tree, fname);
1034 static BOOL test_mknew(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1037 const char *fname = BASEDIR "\\torture_mknew.txt";
1041 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1042 union smb_fileinfo finfo;
1044 printf("Checking RAW_OPEN_MKNEW\n");
1046 io.mknew.level = RAW_OPEN_MKNEW;
1047 io.mknew.in.attrib = 0;
1048 io.mknew.in.write_time = 0;
1049 io.mknew.in.fname = fname;
1050 status = smb_raw_open(cli->tree, mem_ctx, &io);
1051 CHECK_STATUS(status, NT_STATUS_OK);
1052 fnum = io.mknew.out.fnum;
1054 status = smb_raw_open(cli->tree, mem_ctx, &io);
1055 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
1057 smbcli_close(cli->tree, fnum);
1058 smbcli_unlink(cli->tree, fname);
1060 /* make sure write_time works */
1061 io.mknew.in.write_time = basetime;
1062 status = smb_raw_open(cli->tree, mem_ctx, &io);
1063 CHECK_STATUS(status, NT_STATUS_OK);
1064 fnum = io.mknew.out.fnum;
1065 CHECK_TIME(basetime, write_time);
1067 smbcli_close(cli->tree, fnum);
1068 smbcli_unlink(cli->tree, fname);
1070 /* make sure file_attrs works */
1071 io.mknew.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1072 status = smb_raw_open(cli->tree, mem_ctx, &io);
1073 CHECK_STATUS(status, NT_STATUS_OK);
1074 fnum = io.mknew.out.fnum;
1075 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE,
1076 attrib & ~FILE_ATTRIBUTE_NONINDEXED);
1079 smbcli_close(cli->tree, fnum);
1080 smbcli_unlink(cli->tree, fname);
1087 test RAW_OPEN_CREATE
1089 static BOOL test_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1092 const char *fname = BASEDIR "\\torture_create.txt";
1096 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1097 union smb_fileinfo finfo;
1099 printf("Checking RAW_OPEN_CREATE\n");
1101 io.create.level = RAW_OPEN_CREATE;
1102 io.create.in.attrib = 0;
1103 io.create.in.write_time = 0;
1104 io.create.in.fname = fname;
1105 status = smb_raw_open(cli->tree, mem_ctx, &io);
1106 CHECK_STATUS(status, NT_STATUS_OK);
1107 fnum = io.create.out.fnum;
1109 status = smb_raw_open(cli->tree, mem_ctx, &io);
1110 CHECK_STATUS(status, NT_STATUS_OK);
1112 smbcli_close(cli->tree, io.create.out.fnum);
1113 smbcli_close(cli->tree, fnum);
1114 smbcli_unlink(cli->tree, fname);
1116 /* make sure write_time works */
1117 io.create.in.write_time = basetime;
1118 status = smb_raw_open(cli->tree, mem_ctx, &io);
1119 CHECK_STATUS(status, NT_STATUS_OK);
1120 fnum = io.create.out.fnum;
1121 CHECK_TIME(basetime, write_time);
1123 smbcli_close(cli->tree, fnum);
1124 smbcli_unlink(cli->tree, fname);
1126 /* make sure file_attrs works */
1127 io.create.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1128 status = smb_raw_open(cli->tree, mem_ctx, &io);
1129 CHECK_STATUS(status, NT_STATUS_OK);
1130 fnum = io.create.out.fnum;
1131 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE,
1132 attrib & ~FILE_ATTRIBUTE_NONINDEXED);
1135 smbcli_close(cli->tree, fnum);
1136 smbcli_unlink(cli->tree, fname);
1145 static BOOL test_ctemp(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1151 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1152 union smb_fileinfo finfo;
1153 const char *name, *fname = NULL;
1155 printf("Checking RAW_OPEN_CTEMP\n");
1157 io.ctemp.level = RAW_OPEN_CTEMP;
1158 io.ctemp.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1159 io.ctemp.in.write_time = basetime;
1160 io.ctemp.in.directory = BASEDIR;
1161 status = smb_raw_open(cli->tree, mem_ctx, &io);
1162 CHECK_STATUS(status, NT_STATUS_OK);
1163 fnum = io.ctemp.out.fnum;
1165 name = io.ctemp.out.name;
1167 finfo.generic.level = RAW_FILEINFO_NAME_INFO;
1168 finfo.generic.in.fnum = fnum;
1169 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
1170 CHECK_STATUS(status, NT_STATUS_OK);
1172 fname = finfo.name_info.out.fname.s;
1173 d_printf("ctemp name=%s real name=%s\n", name, fname);
1176 smbcli_close(cli->tree, fnum);
1178 smbcli_unlink(cli->tree, fname);
1186 test chained RAW_OPEN_OPENX_READX
1188 static BOOL test_chained(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1191 const char *fname = BASEDIR "\\torture_chained.txt";
1195 const char *buf = "test";
1198 printf("Checking RAW_OPEN_OPENX chained with READX\n");
1199 smbcli_unlink(cli->tree, fname);
1201 fnum = create_complex_file(cli, mem_ctx, fname);
1203 smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf));
1205 smbcli_close(cli->tree, fnum);
1207 io.openxreadx.level = RAW_OPEN_OPENX_READX;
1208 io.openxreadx.in.fname = fname;
1209 io.openxreadx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
1210 io.openxreadx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
1211 io.openxreadx.in.open_func = OPENX_OPEN_FUNC_OPEN;
1212 io.openxreadx.in.search_attrs = 0;
1213 io.openxreadx.in.file_attrs = 0;
1214 io.openxreadx.in.write_time = 0;
1215 io.openxreadx.in.size = 1024*1024;
1216 io.openxreadx.in.timeout = 0;
1218 io.openxreadx.in.offset = 0;
1219 io.openxreadx.in.mincnt = sizeof(buf);
1220 io.openxreadx.in.maxcnt = sizeof(buf);
1221 io.openxreadx.in.remaining = 0;
1222 io.openxreadx.out.data = buf2;
1224 status = smb_raw_open(cli->tree, mem_ctx, &io);
1225 CHECK_STATUS(status, NT_STATUS_OK);
1226 fnum = io.openxreadx.out.fnum;
1228 if (memcmp(buf, buf2, sizeof(buf)) != 0) {
1229 d_printf("wrong data in reply buffer\n");
1234 smbcli_close(cli->tree, fnum);
1235 smbcli_unlink(cli->tree, fname);
1240 /* A little torture test to expose a race condition in Samba 3.0.20 ... :-) */
1242 static BOOL test_raw_open_multi(void)
1244 struct smbcli_state *cli;
1245 TALLOC_CTX *mem_ctx = talloc_init("torture_test_oplock_multi");
1246 const char *fname = "\\test_oplock.dat";
1250 struct smbcli_state **clients;
1251 struct smbcli_request **requests;
1252 union smb_open *ios;
1253 const char *host = lp_parm_string(-1, "torture", "host");
1254 const char *share = lp_parm_string(-1, "torture", "share");
1255 int i, num_files = 3;
1256 struct event_context *ev;
1258 int num_collision = 0;
1260 ev = event_context_init(mem_ctx);
1261 clients = talloc_array(mem_ctx, struct smbcli_state *, num_files);
1262 requests = talloc_array(mem_ctx, struct smbcli_request *, num_files);
1263 ios = talloc_array(mem_ctx, union smb_open, num_files);
1264 if ((ev == NULL) || (clients == NULL) || (requests == NULL) ||
1266 DEBUG(0, ("talloc failed\n"));
1270 if (!torture_open_connection_share(mem_ctx, &cli, host, share, ev)) {
1274 cli->tree->session->transport->options.request_timeout = 60000;
1276 for (i=0; i<num_files; i++) {
1277 if (!torture_open_connection_share(mem_ctx, &(clients[i]),
1279 DEBUG(0, ("Could not open %d'th connection\n", i));
1282 clients[i]->tree->session->transport->
1283 options.request_timeout = 60000;
1287 smbcli_unlink(cli->tree, fname);
1290 base ntcreatex parms
1292 io.generic.level = RAW_OPEN_NTCREATEX;
1293 io.ntcreatex.in.root_fid = 0;
1294 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
1295 io.ntcreatex.in.alloc_size = 0;
1296 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1297 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ|
1298 NTCREATEX_SHARE_ACCESS_WRITE|
1299 NTCREATEX_SHARE_ACCESS_DELETE;
1300 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1301 io.ntcreatex.in.create_options = 0;
1302 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1303 io.ntcreatex.in.security_flags = 0;
1304 io.ntcreatex.in.fname = fname;
1305 io.ntcreatex.in.flags = 0;
1307 for (i=0; i<num_files; i++) {
1309 requests[i] = smb_raw_open_send(clients[i]->tree, &ios[i]);
1310 if (requests[i] == NULL) {
1311 DEBUG(0, ("could not send %d'th request\n", i));
1316 DEBUG(10, ("waiting for replies\n"));
1318 BOOL unreplied = False;
1319 for (i=0; i<num_files; i++) {
1320 if (requests[i] == NULL) {
1323 if (requests[i]->state < SMBCLI_REQUEST_DONE) {
1327 status = smb_raw_open_recv(requests[i], mem_ctx,
1330 DEBUG(0, ("File %d returned status %s\n", i,
1331 nt_errstr(status)));
1333 if (NT_STATUS_IS_OK(status)) {
1337 if (NT_STATUS_EQUAL(status,
1338 NT_STATUS_OBJECT_NAME_COLLISION)) {
1348 if (event_loop_once(ev) != 0) {
1349 DEBUG(0, ("event_loop_once failed\n"));
1354 if ((num_ok != 1) || (num_ok + num_collision != num_files)) {
1358 for (i=0; i<num_files; i++) {
1359 torture_close_connection(clients[i]);
1361 talloc_free(mem_ctx);
1365 /* basic testing of all RAW_OPEN_* calls
1367 BOOL torture_raw_open(void)
1369 struct smbcli_state *cli;
1371 TALLOC_CTX *mem_ctx;
1373 if (!torture_open_connection(&cli)) {
1377 mem_ctx = talloc_init("torture_raw_open");
1379 if (!torture_setup_dir(cli, BASEDIR)) {
1383 ret &= test_ntcreatex_brlocked(cli, mem_ctx);
1384 ret &= test_open(cli, mem_ctx);
1385 ret &= test_raw_open_multi();
1386 ret &= test_openx(cli, mem_ctx);
1387 ret &= test_ntcreatex(cli, mem_ctx);
1388 ret &= test_nttrans_create(cli, mem_ctx);
1389 ret &= test_t2open(cli, mem_ctx);
1390 ret &= test_mknew(cli, mem_ctx);
1391 ret &= test_create(cli, mem_ctx);
1392 ret &= test_ctemp(cli, mem_ctx);
1393 ret &= test_chained(cli, mem_ctx);
1395 smb_raw_exit(cli->session);
1396 smbcli_deltree(cli->tree, BASEDIR);
1398 torture_close_connection(cli);
1399 talloc_free(mem_ctx);