2 Unix SMB/CIFS implementation.
3 RAW_OPEN_* individual test suite
4 Copyright (C) Andrew Tridgell 2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "torture/torture.h"
22 #include "libcli/raw/libcliraw.h"
23 #include "libcli/raw/raw_proto.h"
24 #include "system/time.h"
25 #include "system/filesys.h"
26 #include "librpc/gen_ndr/security.h"
27 #include "lib/events/events.h"
28 #include "libcli/libcli.h"
29 #include "torture/util.h"
30 #include "auth/credentials/credentials.h"
31 #include "lib/cmdline/popt_common.h"
32 #include "param/param.h"
34 /* enum for whether reads/writes are possible on a file */
35 enum rdwr_mode {RDWR_NONE, RDWR_RDONLY, RDWR_WRONLY, RDWR_RDWR};
37 #define BASEDIR "\\rawopen"
40 check if a open file can be read/written
42 static enum rdwr_mode check_rdwr(struct smbcli_tree *tree, int fnum)
45 bool can_read = (smbcli_read(tree, fnum, &c, 0, 1) == 1);
46 bool can_write = (smbcli_write(tree, fnum, 0, &c, 0, 1) == 1);
47 if ( can_read && can_write) return RDWR_RDWR;
48 if ( can_read && !can_write) return RDWR_RDONLY;
49 if (!can_read && can_write) return RDWR_WRONLY;
54 describe a RDWR mode as a string
56 static const char *rdwr_string(enum rdwr_mode m)
59 case RDWR_NONE: return "NONE";
60 case RDWR_RDONLY: return "RDONLY";
61 case RDWR_WRONLY: return "WRONLY";
62 case RDWR_RDWR: return "RDWR";
67 #define CHECK_STATUS(status, correct) do { \
68 if (!NT_STATUS_EQUAL(status, correct)) { \
69 printf("(%s) Incorrect status %s - should be %s\n", \
70 __location__, nt_errstr(status), nt_errstr(correct)); \
75 #define CREATE_FILE do { \
76 fnum = create_complex_file(cli, tctx, fname); \
78 printf("(%s) Failed to create %s - %s\n", __location__, fname, smbcli_errstr(cli->tree)); \
83 #define CHECK_RDWR(fnum, correct) do { \
84 enum rdwr_mode m = check_rdwr(cli->tree, fnum); \
86 printf("(%s) Incorrect readwrite mode %s - expected %s\n", \
87 __location__, rdwr_string(m), rdwr_string(correct)); \
91 #define CHECK_TIME(t, field) do { \
93 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
94 finfo.all_info.in.file.path = fname; \
95 status = smb_raw_pathinfo(cli->tree, tctx, &finfo); \
96 CHECK_STATUS(status, NT_STATUS_OK); \
98 t2 = nt_time_to_unix(finfo.all_info.out.field) & ~1; \
99 if (abs(t1-t2) > 2) { \
100 printf("(%s) wrong time for field %s %s - %s\n", \
101 __location__, #field, \
102 timestring(tctx, t1), \
103 timestring(tctx, t2)); \
104 dump_all_info(tctx, &finfo); \
108 #define CHECK_NTTIME(t, field) do { \
110 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
111 finfo.all_info.in.file.path = fname; \
112 status = smb_raw_pathinfo(cli->tree, tctx, &finfo); \
113 CHECK_STATUS(status, NT_STATUS_OK); \
114 t2 = finfo.all_info.out.field; \
116 printf("(%s) wrong time for field %s %s - %s\n", \
117 __location__, #field, \
118 nt_time_string(tctx, t), \
119 nt_time_string(tctx, t2)); \
120 dump_all_info(tctx, &finfo); \
124 #define CHECK_ALL_INFO(v, field) do { \
125 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
126 finfo.all_info.in.file.path = fname; \
127 status = smb_raw_pathinfo(cli->tree, tctx, &finfo); \
128 CHECK_STATUS(status, NT_STATUS_OK); \
129 if ((v) != (finfo.all_info.out.field)) { \
130 printf("(%s) wrong value for field %s 0x%x - 0x%x\n", \
131 __location__, #field, (int)v, (int)(finfo.all_info.out.field)); \
132 dump_all_info(tctx, &finfo); \
136 #define CHECK_VAL(v, correct) do { \
137 if ((v) != (correct)) { \
138 printf("(%s) wrong value for %s 0x%x - should be 0x%x\n", \
139 __location__, #v, (int)(v), (int)correct); \
143 #define SET_ATTRIB(sattrib) do { \
144 union smb_setfileinfo sfinfo; \
145 ZERO_STRUCT(sfinfo.basic_info.in); \
146 sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFORMATION; \
147 sfinfo.basic_info.in.file.path = fname; \
148 sfinfo.basic_info.in.attrib = sattrib; \
149 status = smb_raw_setpathinfo(cli->tree, &sfinfo); \
150 if (!NT_STATUS_IS_OK(status)) { \
151 printf("(%s) Failed to set attrib 0x%x on %s\n", \
152 __location__, sattrib, fname); \
158 static bool test_open(struct smbcli_state *cli, struct torture_context *tctx)
161 union smb_fileinfo finfo;
162 const char *fname = BASEDIR "\\torture_open.txt";
164 int fnum = -1, fnum2;
167 printf("Checking RAW_OPEN_OPEN\n");
169 io.openold.level = RAW_OPEN_OPEN;
170 io.openold.in.fname = fname;
171 io.openold.in.open_mode = OPEN_FLAGS_FCB;
172 io.openold.in.search_attrs = 0;
173 status = smb_raw_open(cli->tree, tctx, &io);
174 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
175 fnum = io.openold.out.file.fnum;
177 smbcli_unlink(cli->tree, fname);
179 smbcli_close(cli->tree, fnum);
181 status = smb_raw_open(cli->tree, tctx, &io);
182 CHECK_STATUS(status, NT_STATUS_OK);
183 fnum = io.openold.out.file.fnum;
184 CHECK_RDWR(fnum, RDWR_RDWR);
186 status = smb_raw_open(cli->tree, tctx, &io);
187 CHECK_STATUS(status, NT_STATUS_OK);
188 fnum2 = io.openold.out.file.fnum;
189 CHECK_RDWR(fnum2, RDWR_RDWR);
190 smbcli_close(cli->tree, fnum2);
191 smbcli_close(cli->tree, fnum);
193 /* check the read/write modes */
194 io.openold.level = RAW_OPEN_OPEN;
195 io.openold.in.fname = fname;
196 io.openold.in.search_attrs = 0;
198 io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ;
199 status = smb_raw_open(cli->tree, tctx, &io);
200 CHECK_STATUS(status, NT_STATUS_OK);
201 fnum = io.openold.out.file.fnum;
202 CHECK_RDWR(fnum, RDWR_RDONLY);
203 smbcli_close(cli->tree, fnum);
205 io.openold.in.open_mode = OPEN_FLAGS_OPEN_WRITE;
206 status = smb_raw_open(cli->tree, tctx, &io);
207 CHECK_STATUS(status, NT_STATUS_OK);
208 fnum = io.openold.out.file.fnum;
209 CHECK_RDWR(fnum, RDWR_WRONLY);
210 smbcli_close(cli->tree, fnum);
212 io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR;
213 status = smb_raw_open(cli->tree, tctx, &io);
214 CHECK_STATUS(status, NT_STATUS_OK);
215 fnum = io.openold.out.file.fnum;
216 CHECK_RDWR(fnum, RDWR_RDWR);
217 smbcli_close(cli->tree, fnum);
219 /* check the share modes roughly - not a complete matrix */
220 io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_WRITE;
221 status = smb_raw_open(cli->tree, tctx, &io);
222 CHECK_STATUS(status, NT_STATUS_OK);
223 fnum = io.openold.out.file.fnum;
224 CHECK_RDWR(fnum, RDWR_RDWR);
226 if (io.openold.in.open_mode != io.openold.out.rmode) {
227 printf("(%s) rmode should equal open_mode - 0x%x 0x%x\n",
228 __location__, io.openold.out.rmode, io.openold.in.open_mode);
231 io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_NONE;
232 status = smb_raw_open(cli->tree, tctx, &io);
233 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
235 io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ | OPEN_FLAGS_DENY_NONE;
236 status = smb_raw_open(cli->tree, tctx, &io);
237 CHECK_STATUS(status, NT_STATUS_OK);
238 fnum2 = io.openold.out.file.fnum;
239 CHECK_RDWR(fnum2, RDWR_RDONLY);
240 smbcli_close(cli->tree, fnum);
241 smbcli_close(cli->tree, fnum2);
244 /* check the returned write time */
245 io.openold.level = RAW_OPEN_OPEN;
246 io.openold.in.fname = fname;
247 io.openold.in.search_attrs = 0;
248 io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ;
249 status = smb_raw_open(cli->tree, tctx, &io);
250 CHECK_STATUS(status, NT_STATUS_OK);
251 fnum = io.openold.out.file.fnum;
253 /* check other reply fields */
254 CHECK_TIME(io.openold.out.write_time, write_time);
255 CHECK_ALL_INFO(io.openold.out.size, size);
256 CHECK_ALL_INFO(io.openold.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
259 smbcli_close(cli->tree, fnum);
260 smbcli_unlink(cli->tree, fname);
269 static bool test_openx(struct smbcli_state *cli, struct torture_context *tctx)
272 union smb_fileinfo finfo;
273 const char *fname = BASEDIR "\\torture_openx.txt";
274 const char *fname_exe = BASEDIR "\\torture_openx.exe";
276 int fnum = -1, fnum2;
283 NTSTATUS correct_status;
285 { OPENX_OPEN_FUNC_OPEN, true, NT_STATUS_OK },
286 { OPENX_OPEN_FUNC_OPEN, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
287 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OK },
288 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
289 { OPENX_OPEN_FUNC_FAIL, true, NT_STATUS_DOS(ERRDOS, ERRbadaccess) },
290 { OPENX_OPEN_FUNC_FAIL, false, NT_STATUS_DOS(ERRDOS, ERRbadaccess) },
291 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OBJECT_NAME_COLLISION },
292 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
293 { OPENX_OPEN_FUNC_TRUNC, true, NT_STATUS_OK },
294 { OPENX_OPEN_FUNC_TRUNC, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
295 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OK },
296 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
299 printf("Checking RAW_OPEN_OPENX\n");
300 smbcli_unlink(cli->tree, fname);
302 io.openx.level = RAW_OPEN_OPENX;
303 io.openx.in.fname = fname;
304 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
305 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
306 io.openx.in.search_attrs = 0;
307 io.openx.in.file_attrs = 0;
308 io.openx.in.write_time = 0;
309 io.openx.in.size = 1024*1024;
310 io.openx.in.timeout = 0;
312 /* check all combinations of open_func */
313 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
314 if (open_funcs[i].with_file) {
315 fnum = create_complex_file(cli, tctx, fname);
317 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
321 smbcli_close(cli->tree, fnum);
323 io.openx.in.open_func = open_funcs[i].open_func;
324 status = smb_raw_open(cli->tree, tctx, &io);
325 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
326 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n",
327 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
328 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_func);
331 if (NT_STATUS_IS_OK(status)) {
332 smbcli_close(cli->tree, io.openx.out.file.fnum);
334 if (open_funcs[i].with_file) {
335 smbcli_unlink(cli->tree, fname);
339 smbcli_unlink(cli->tree, fname);
341 /* check the basic return fields */
342 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
343 status = smb_raw_open(cli->tree, tctx, &io);
344 CHECK_STATUS(status, NT_STATUS_OK);
345 fnum = io.openx.out.file.fnum;
347 CHECK_ALL_INFO(io.openx.out.size, size);
348 CHECK_TIME(io.openx.out.write_time, write_time);
349 CHECK_ALL_INFO(io.openx.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
350 CHECK_VAL(io.openx.out.access, OPENX_MODE_ACCESS_RDWR);
351 CHECK_VAL(io.openx.out.ftype, 0);
352 CHECK_VAL(io.openx.out.devstate, 0);
353 CHECK_VAL(io.openx.out.action, OPENX_ACTION_CREATED);
354 CHECK_VAL(io.openx.out.size, 1024*1024);
355 CHECK_ALL_INFO(io.openx.in.size, size);
356 smbcli_close(cli->tree, fnum);
357 smbcli_unlink(cli->tree, fname);
359 /* check the fields when the file already existed */
360 fnum2 = create_complex_file(cli, tctx, fname);
365 smbcli_close(cli->tree, fnum2);
367 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
368 status = smb_raw_open(cli->tree, tctx, &io);
369 CHECK_STATUS(status, NT_STATUS_OK);
370 fnum = io.openx.out.file.fnum;
372 CHECK_ALL_INFO(io.openx.out.size, size);
373 CHECK_TIME(io.openx.out.write_time, write_time);
374 CHECK_VAL(io.openx.out.action, OPENX_ACTION_EXISTED);
375 CHECK_VAL(io.openx.out.unknown, 0);
376 CHECK_ALL_INFO(io.openx.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
377 smbcli_close(cli->tree, fnum);
379 /* now check the search attrib for hidden files - win2003 ignores this? */
380 SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN);
381 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib);
383 io.openx.in.search_attrs = FILE_ATTRIBUTE_HIDDEN;
384 status = smb_raw_open(cli->tree, tctx, &io);
385 CHECK_STATUS(status, NT_STATUS_OK);
386 smbcli_close(cli->tree, io.openx.out.file.fnum);
388 io.openx.in.search_attrs = 0;
389 status = smb_raw_open(cli->tree, tctx, &io);
390 CHECK_STATUS(status, NT_STATUS_OK);
391 smbcli_close(cli->tree, io.openx.out.file.fnum);
393 SET_ATTRIB(FILE_ATTRIBUTE_NORMAL);
394 smbcli_unlink(cli->tree, fname);
396 /* and check attrib on create */
397 io.openx.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE;
398 io.openx.in.search_attrs = 0;
399 io.openx.in.file_attrs = FILE_ATTRIBUTE_SYSTEM;
400 status = smb_raw_open(cli->tree, tctx, &io);
401 CHECK_STATUS(status, NT_STATUS_OK);
402 if (torture_setting_bool(tctx, "samba3", false)) {
403 CHECK_ALL_INFO(FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE,
404 attrib & ~(FILE_ATTRIBUTE_NONINDEXED|
405 FILE_ATTRIBUTE_SPARSE));
408 CHECK_ALL_INFO(FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE,
409 attrib & ~(FILE_ATTRIBUTE_NONINDEXED));
411 smbcli_close(cli->tree, io.openx.out.file.fnum);
412 smbcli_unlink(cli->tree, fname);
414 /* check timeout on create - win2003 ignores the timeout! */
415 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
416 io.openx.in.file_attrs = 0;
417 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL;
418 status = smb_raw_open(cli->tree, tctx, &io);
419 CHECK_STATUS(status, NT_STATUS_OK);
420 fnum = io.openx.out.file.fnum;
422 io.openx.in.timeout = 20000;
423 tv = timeval_current();
424 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_NONE;
425 status = smb_raw_open(cli->tree, tctx, &io);
426 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
427 if (timeval_elapsed(&tv) > 3.0) {
428 printf("(%s) Incorrect timing in openx with timeout - waited %.2f seconds\n",
429 __location__, timeval_elapsed(&tv));
432 smbcli_close(cli->tree, fnum);
433 smbcli_unlink(cli->tree, fname);
435 /* now this is a really weird one - open for execute implies create?! */
436 io.openx.in.fname = fname;
437 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
438 io.openx.in.open_mode = OPENX_MODE_ACCESS_EXEC | OPENX_MODE_DENY_NONE;
439 io.openx.in.search_attrs = 0;
440 io.openx.in.open_func = OPENX_OPEN_FUNC_FAIL;
441 io.openx.in.file_attrs = 0;
442 io.openx.in.write_time = 0;
443 io.openx.in.size = 0;
444 io.openx.in.timeout = 0;
445 status = smb_raw_open(cli->tree, tctx, &io);
446 CHECK_STATUS(status, NT_STATUS_OK);
447 smbcli_close(cli->tree, io.openx.out.file.fnum);
449 /* check the extended return flag */
450 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO | OPENX_FLAGS_EXTENDED_RETURN;
451 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
452 status = smb_raw_open(cli->tree, tctx, &io);
453 CHECK_STATUS(status, NT_STATUS_OK);
454 CHECK_VAL(io.openx.out.access_mask, SEC_STD_ALL);
455 smbcli_close(cli->tree, io.openx.out.file.fnum);
457 io.openx.in.fname = "\\A.+,;=[].B";
458 status = smb_raw_open(cli->tree, tctx, &io);
459 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
461 /* Check the mapping for open exec. */
463 /* First create an .exe file. */
464 smbcli_unlink(cli->tree, fname_exe);
465 fnum = create_complex_file(cli, tctx, fname_exe);
466 smbcli_close(cli->tree, fnum);
468 io.openx.level = RAW_OPEN_OPENX;
469 io.openx.in.fname = fname_exe;
470 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
471 io.openx.in.open_mode = OPENX_MODE_ACCESS_EXEC | OPENX_MODE_DENY_NONE;
472 io.openx.in.search_attrs = 0;
473 io.openx.in.file_attrs = 0;
474 io.openx.in.write_time = 0;
475 io.openx.in.size = 0;
476 io.openx.in.timeout = 0;
477 status = smb_raw_open(cli->tree, tctx, &io);
478 CHECK_STATUS(status, NT_STATUS_OK);
480 /* Can we read and write ? */
481 CHECK_RDWR(io.openx.out.file.fnum, RDWR_RDONLY);
482 smbcli_close(cli->tree, io.openx.out.file.fnum);
483 smbcli_unlink(cli->tree, fname);
486 smbcli_close(cli->tree, fnum);
487 smbcli_unlink(cli->tree, fname_exe);
488 smbcli_unlink(cli->tree, fname);
497 many thanks to kukks for a sniff showing how this works with os2->w2k
499 static bool test_t2open(struct smbcli_state *cli, struct torture_context *tctx)
502 union smb_fileinfo finfo;
503 const char *fname1 = BASEDIR "\\torture_t2open_yes.txt";
504 const char *fname2 = BASEDIR "\\torture_t2open_no.txt";
505 const char *fname = BASEDIR "\\torture_t2open_3.txt";
513 NTSTATUS correct_status;
515 { OPENX_OPEN_FUNC_OPEN, true, NT_STATUS_OK },
516 { OPENX_OPEN_FUNC_OPEN, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
517 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OK },
518 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
519 { OPENX_OPEN_FUNC_FAIL, true, NT_STATUS_OBJECT_NAME_COLLISION },
520 { OPENX_OPEN_FUNC_FAIL, false, NT_STATUS_OBJECT_NAME_COLLISION },
521 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OBJECT_NAME_COLLISION },
522 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OBJECT_NAME_COLLISION },
523 { OPENX_OPEN_FUNC_TRUNC, true, NT_STATUS_OK },
524 { OPENX_OPEN_FUNC_TRUNC, false, NT_STATUS_OK },
525 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, true, NT_STATUS_OK },
526 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
529 fnum = create_complex_file(cli, tctx, fname1);
531 d_printf("Failed to create file %s - %s\n", fname1, smbcli_errstr(cli->tree));
535 smbcli_close(cli->tree, fnum);
537 printf("Checking RAW_OPEN_T2OPEN\n");
539 io.t2open.level = RAW_OPEN_T2OPEN;
540 io.t2open.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
541 io.t2open.in.open_mode = OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR;
542 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
543 io.t2open.in.search_attrs = 0;
544 io.t2open.in.file_attrs = 0;
545 io.t2open.in.write_time = 0;
546 io.t2open.in.size = 0;
547 io.t2open.in.timeout = 0;
549 io.t2open.in.num_eas = 3;
550 io.t2open.in.eas = talloc_array(tctx, struct ea_struct, io.t2open.in.num_eas);
551 io.t2open.in.eas[0].flags = 0;
552 io.t2open.in.eas[0].name.s = ".CLASSINFO";
553 io.t2open.in.eas[0].value = data_blob_talloc(tctx, "first value", 11);
554 io.t2open.in.eas[1].flags = 0;
555 io.t2open.in.eas[1].name.s = "EA TWO";
556 io.t2open.in.eas[1].value = data_blob_talloc(tctx, "foo", 3);
557 io.t2open.in.eas[2].flags = 0;
558 io.t2open.in.eas[2].name.s = "X THIRD";
559 io.t2open.in.eas[2].value = data_blob_talloc(tctx, "xy", 2);
561 /* check all combinations of open_func */
562 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
564 if (open_funcs[i].with_file) {
565 io.t2open.in.fname = fname1;
567 io.t2open.in.fname = fname2;
569 io.t2open.in.open_func = open_funcs[i].open_func;
570 status = smb_raw_open(cli->tree, tctx, &io);
571 if ((io.t2open.in.num_eas != 0)
572 && NT_STATUS_EQUAL(status, NT_STATUS_EAS_NOT_SUPPORTED)
573 && torture_setting_bool(tctx, "samba3", false)) {
574 printf("(%s) EAs not supported, not treating as fatal "
575 "in Samba3 test\n", __location__);
576 io.t2open.in.num_eas = 0;
580 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
581 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n",
582 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
583 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_func);
586 if (NT_STATUS_IS_OK(status)) {
587 smbcli_close(cli->tree, io.t2open.out.file.fnum);
591 smbcli_unlink(cli->tree, fname1);
592 smbcli_unlink(cli->tree, fname2);
594 /* check the basic return fields */
595 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
596 io.t2open.in.write_time = 0;
597 io.t2open.in.fname = fname;
598 status = smb_raw_open(cli->tree, tctx, &io);
599 CHECK_STATUS(status, NT_STATUS_OK);
600 fnum = io.t2open.out.file.fnum;
602 CHECK_ALL_INFO(io.t2open.out.size, size);
604 /* windows appears to leak uninitialised memory here */
605 CHECK_VAL(io.t2open.out.write_time, 0);
607 CHECK_ALL_INFO(io.t2open.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
608 CHECK_VAL(io.t2open.out.access, OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR);
609 CHECK_VAL(io.t2open.out.ftype, 0);
610 CHECK_VAL(io.t2open.out.devstate, 0);
611 CHECK_VAL(io.t2open.out.action, OPENX_ACTION_CREATED);
612 smbcli_close(cli->tree, fnum);
614 status = torture_check_ea(cli, fname, ".CLASSINFO", "first value");
615 CHECK_STATUS(status, io.t2open.in.num_eas
616 ? NT_STATUS_OK : NT_STATUS_EAS_NOT_SUPPORTED);
617 status = torture_check_ea(cli, fname, "EA TWO", "foo");
618 CHECK_STATUS(status, io.t2open.in.num_eas
619 ? NT_STATUS_OK : NT_STATUS_EAS_NOT_SUPPORTED);
620 status = torture_check_ea(cli, fname, "X THIRD", "xy");
621 CHECK_STATUS(status, io.t2open.in.num_eas
622 ? NT_STATUS_OK : NT_STATUS_EAS_NOT_SUPPORTED);
624 /* now check the search attrib for hidden files - win2003 ignores this? */
625 SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN);
626 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib);
628 status = smb_raw_open(cli->tree, tctx, &io);
629 CHECK_STATUS(status, NT_STATUS_OK);
630 smbcli_close(cli->tree, io.t2open.out.file.fnum);
632 status = smb_raw_open(cli->tree, tctx, &io);
633 CHECK_STATUS(status, NT_STATUS_OK);
634 smbcli_close(cli->tree, io.t2open.out.file.fnum);
636 SET_ATTRIB(FILE_ATTRIBUTE_NORMAL);
637 smbcli_unlink(cli->tree, fname);
639 /* and check attrib on create */
640 io.t2open.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE;
641 io.t2open.in.file_attrs = FILE_ATTRIBUTE_SYSTEM;
642 status = smb_raw_open(cli->tree, tctx, &io);
643 CHECK_STATUS(status, NT_STATUS_OK);
645 /* check timeout on create - win2003 ignores the timeout! */
646 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
647 io.t2open.in.file_attrs = 0;
648 io.t2open.in.timeout = 20000;
649 io.t2open.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL;
650 status = smb_raw_open(cli->tree, tctx, &io);
651 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
654 smbcli_close(cli->tree, fnum);
655 smbcli_unlink(cli->tree, fname);
662 test RAW_OPEN_NTCREATEX
664 static bool test_ntcreatex(struct smbcli_state *cli, struct torture_context *tctx)
667 union smb_fileinfo finfo;
668 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
669 const char *dname = BASEDIR "\\torture_ntcreatex.dir";
677 NTSTATUS correct_status;
679 { NTCREATEX_DISP_SUPERSEDE, true, NT_STATUS_OK },
680 { NTCREATEX_DISP_SUPERSEDE, false, NT_STATUS_OK },
681 { NTCREATEX_DISP_OPEN, true, NT_STATUS_OK },
682 { NTCREATEX_DISP_OPEN, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
683 { NTCREATEX_DISP_CREATE, true, NT_STATUS_OBJECT_NAME_COLLISION },
684 { NTCREATEX_DISP_CREATE, false, NT_STATUS_OK },
685 { NTCREATEX_DISP_OPEN_IF, true, NT_STATUS_OK },
686 { NTCREATEX_DISP_OPEN_IF, false, NT_STATUS_OK },
687 { NTCREATEX_DISP_OVERWRITE, true, NT_STATUS_OK },
688 { NTCREATEX_DISP_OVERWRITE, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
689 { NTCREATEX_DISP_OVERWRITE_IF, true, NT_STATUS_OK },
690 { NTCREATEX_DISP_OVERWRITE_IF, false, NT_STATUS_OK },
691 { 6, true, NT_STATUS_INVALID_PARAMETER },
692 { 6, false, NT_STATUS_INVALID_PARAMETER },
695 printf("Checking RAW_OPEN_NTCREATEX\n");
697 /* reasonable default parameters */
698 io.generic.level = RAW_OPEN_NTCREATEX;
699 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
700 io.ntcreatex.in.root_fid = 0;
701 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
702 io.ntcreatex.in.alloc_size = 1024*1024;
703 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
704 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
705 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
706 io.ntcreatex.in.create_options = 0;
707 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
708 io.ntcreatex.in.security_flags = 0;
709 io.ntcreatex.in.fname = fname;
711 /* test the open disposition */
712 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
713 if (open_funcs[i].with_file) {
714 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE);
716 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
720 smbcli_close(cli->tree, fnum);
722 io.ntcreatex.in.open_disposition = open_funcs[i].open_disp;
723 status = smb_raw_open(cli->tree, tctx, &io);
724 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
725 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_disp=%d)\n",
726 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
727 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_disp);
730 if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
731 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
732 smbcli_unlink(cli->tree, fname);
736 /* basic field testing */
737 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
739 status = smb_raw_open(cli->tree, tctx, &io);
740 CHECK_STATUS(status, NT_STATUS_OK);
741 fnum = io.ntcreatex.out.file.fnum;
743 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
744 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
745 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
746 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
747 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
748 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
749 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
750 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
751 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
752 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
753 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
755 /* check fields when the file already existed */
756 smbcli_close(cli->tree, fnum);
757 smbcli_unlink(cli->tree, fname);
758 fnum = create_complex_file(cli, tctx, fname);
763 smbcli_close(cli->tree, fnum);
765 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
766 status = smb_raw_open(cli->tree, tctx, &io);
767 CHECK_STATUS(status, NT_STATUS_OK);
768 fnum = io.ntcreatex.out.file.fnum;
770 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
771 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
772 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
773 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
774 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
775 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
776 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
777 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
778 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
779 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
780 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
781 smbcli_close(cli->tree, fnum);
782 smbcli_unlink(cli->tree, fname);
785 /* create a directory */
786 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
787 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
788 io.ntcreatex.in.alloc_size = 0;
789 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
790 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
791 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
792 io.ntcreatex.in.create_options = 0;
793 io.ntcreatex.in.fname = dname;
796 smbcli_rmdir(cli->tree, fname);
797 smbcli_unlink(cli->tree, fname);
799 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
800 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
801 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
802 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
803 status = smb_raw_open(cli->tree, tctx, &io);
804 CHECK_STATUS(status, NT_STATUS_OK);
805 fnum = io.ntcreatex.out.file.fnum;
807 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
808 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
809 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
810 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
811 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
812 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
813 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
814 CHECK_VAL(io.ntcreatex.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED,
815 FILE_ATTRIBUTE_DIRECTORY);
816 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
817 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
818 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
819 CHECK_VAL(io.ntcreatex.out.is_directory, 1);
820 CHECK_VAL(io.ntcreatex.out.size, 0);
821 CHECK_VAL(io.ntcreatex.out.alloc_size, 0);
822 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
823 smbcli_unlink(cli->tree, fname);
827 smbcli_close(cli->tree, fnum);
828 smbcli_unlink(cli->tree, fname);
835 test RAW_OPEN_NTTRANS_CREATE
837 static bool test_nttrans_create(struct smbcli_state *cli, struct torture_context *tctx)
840 union smb_fileinfo finfo;
841 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
842 const char *dname = BASEDIR "\\torture_ntcreatex.dir";
850 NTSTATUS correct_status;
852 { NTCREATEX_DISP_SUPERSEDE, true, NT_STATUS_OK },
853 { NTCREATEX_DISP_SUPERSEDE, false, NT_STATUS_OK },
854 { NTCREATEX_DISP_OPEN, true, NT_STATUS_OK },
855 { NTCREATEX_DISP_OPEN, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
856 { NTCREATEX_DISP_CREATE, true, NT_STATUS_OBJECT_NAME_COLLISION },
857 { NTCREATEX_DISP_CREATE, false, NT_STATUS_OK },
858 { NTCREATEX_DISP_OPEN_IF, true, NT_STATUS_OK },
859 { NTCREATEX_DISP_OPEN_IF, false, NT_STATUS_OK },
860 { NTCREATEX_DISP_OVERWRITE, true, NT_STATUS_OK },
861 { NTCREATEX_DISP_OVERWRITE, false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
862 { NTCREATEX_DISP_OVERWRITE_IF, true, NT_STATUS_OK },
863 { NTCREATEX_DISP_OVERWRITE_IF, false, NT_STATUS_OK },
864 { 6, true, NT_STATUS_INVALID_PARAMETER },
865 { 6, false, NT_STATUS_INVALID_PARAMETER },
868 printf("Checking RAW_OPEN_NTTRANS_CREATE\n");
870 /* reasonable default parameters */
871 io.generic.level = RAW_OPEN_NTTRANS_CREATE;
872 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
873 io.ntcreatex.in.root_fid = 0;
874 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
875 io.ntcreatex.in.alloc_size = 1024*1024;
876 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
877 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
878 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
879 io.ntcreatex.in.create_options = 0;
880 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
881 io.ntcreatex.in.security_flags = 0;
882 io.ntcreatex.in.fname = fname;
883 io.ntcreatex.in.sec_desc = NULL;
884 io.ntcreatex.in.ea_list = NULL;
886 /* test the open disposition */
887 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
888 if (open_funcs[i].with_file) {
889 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE);
891 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
895 smbcli_close(cli->tree, fnum);
897 io.ntcreatex.in.open_disposition = open_funcs[i].open_disp;
898 status = smb_raw_open(cli->tree, tctx, &io);
899 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
900 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_disp=%d)\n",
901 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
902 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_disp);
905 if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
906 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
907 smbcli_unlink(cli->tree, fname);
911 /* basic field testing */
912 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
914 status = smb_raw_open(cli->tree, tctx, &io);
915 CHECK_STATUS(status, NT_STATUS_OK);
916 fnum = io.ntcreatex.out.file.fnum;
918 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
919 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
920 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
921 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
922 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
923 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
924 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
925 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
926 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
927 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
928 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
930 /* check fields when the file already existed */
931 smbcli_close(cli->tree, fnum);
932 smbcli_unlink(cli->tree, fname);
933 fnum = create_complex_file(cli, tctx, fname);
938 smbcli_close(cli->tree, fnum);
940 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
941 status = smb_raw_open(cli->tree, tctx, &io);
942 CHECK_STATUS(status, NT_STATUS_OK);
943 fnum = io.ntcreatex.out.file.fnum;
945 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
946 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
947 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
948 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
949 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
950 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
951 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
952 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
953 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
954 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
955 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
956 smbcli_close(cli->tree, fnum);
958 /* check no-recall - don't pull a file from tape on a HSM */
959 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_NO_RECALL;
960 status = smb_raw_open(cli->tree, tctx, &io);
961 CHECK_STATUS(status, NT_STATUS_OK);
962 fnum = io.ntcreatex.out.file.fnum;
964 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
965 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
966 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
967 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
968 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
969 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
970 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
971 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
972 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
973 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
974 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
975 smbcli_close(cli->tree, fnum);
977 /* Check some create options (these all should be ignored) */
978 for (i=0; i < 32; i++) {
979 uint32_t create_option = (1 << i) & NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
980 if (create_option == 0) {
983 io.ntcreatex.in.create_options = create_option;
984 status = smb_raw_open(cli->tree, tctx, &io);
985 CHECK_STATUS(status, NT_STATUS_OK);
987 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
988 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
989 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
990 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
991 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
992 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
993 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
994 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
995 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
996 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
997 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
998 smbcli_close(cli->tree, fnum);
1001 smbcli_unlink(cli->tree, fname);
1004 /* create a directory */
1005 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1006 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
1007 io.ntcreatex.in.alloc_size = 0;
1008 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
1009 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
1010 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1011 io.ntcreatex.in.create_options = 0;
1012 io.ntcreatex.in.fname = dname;
1015 smbcli_rmdir(cli->tree, fname);
1016 smbcli_unlink(cli->tree, fname);
1018 io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1019 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
1020 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1021 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
1022 status = smb_raw_open(cli->tree, tctx, &io);
1023 CHECK_STATUS(status, NT_STATUS_OK);
1024 fnum = io.ntcreatex.out.file.fnum;
1026 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
1027 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
1028 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
1029 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
1030 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
1031 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
1032 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
1033 CHECK_VAL(io.ntcreatex.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED,
1034 FILE_ATTRIBUTE_DIRECTORY);
1035 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
1036 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
1037 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
1038 CHECK_VAL(io.ntcreatex.out.is_directory, 1);
1039 CHECK_VAL(io.ntcreatex.out.size, 0);
1040 CHECK_VAL(io.ntcreatex.out.alloc_size, 0);
1041 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
1042 smbcli_unlink(cli->tree, fname);
1046 smbcli_close(cli->tree, fnum);
1047 smbcli_unlink(cli->tree, fname);
1053 test RAW_OPEN_NTCREATEX with an already opened and byte range locked file
1055 I've got an application that does a similar sequence of ntcreate&x,
1056 locking&x and another ntcreate&x with
1057 open_disposition==NTCREATEX_DISP_OVERWRITE_IF. Windows 2003 allows the
1060 static bool test_ntcreatex_brlocked(struct smbcli_state *cli, struct torture_context *tctx)
1062 union smb_open io, io1;
1064 struct smb_lock_entry lock[1];
1065 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
1069 printf("Testing ntcreatex with a byte range locked file\n");
1071 io.generic.level = RAW_OPEN_NTCREATEX;
1072 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
1073 io.ntcreatex.in.root_fid = 0;
1074 io.ntcreatex.in.access_mask = 0x2019f;
1075 io.ntcreatex.in.alloc_size = 0;
1076 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1077 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1078 NTCREATEX_SHARE_ACCESS_WRITE;
1079 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1080 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
1081 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
1082 io.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC |
1083 NTCREATEX_SECURITY_ALL;
1084 io.ntcreatex.in.fname = fname;
1086 status = smb_raw_open(cli->tree, tctx, &io);
1087 CHECK_STATUS(status, NT_STATUS_OK);
1089 io2.lockx.level = RAW_LOCK_LOCKX;
1090 io2.lockx.in.file.fnum = io.ntcreatex.out.file.fnum;
1091 io2.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
1092 io2.lockx.in.timeout = 0;
1093 io2.lockx.in.ulock_cnt = 0;
1094 io2.lockx.in.lock_cnt = 1;
1095 lock[0].pid = cli->session->pid;
1097 lock[0].count = 0x1;
1098 io2.lockx.in.locks = &lock[0];
1099 status = smb_raw_lock(cli->tree, &io2);
1100 CHECK_STATUS(status, NT_STATUS_OK);
1102 io1.generic.level = RAW_OPEN_NTCREATEX;
1103 io1.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
1104 io1.ntcreatex.in.root_fid = 0;
1105 io1.ntcreatex.in.access_mask = 0x20196;
1106 io1.ntcreatex.in.alloc_size = 0;
1107 io1.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1108 io1.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
1109 NTCREATEX_SHARE_ACCESS_WRITE;
1110 io1.ntcreatex.in.open_disposition = NTCREATEX_DISP_OVERWRITE_IF;
1111 io1.ntcreatex.in.create_options = 0;
1112 io1.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
1113 io1.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC |
1114 NTCREATEX_SECURITY_ALL;
1115 io1.ntcreatex.in.fname = fname;
1117 status = smb_raw_open(cli->tree, tctx, &io1);
1118 CHECK_STATUS(status, NT_STATUS_OK);
1121 smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
1122 smbcli_close(cli->tree, io1.ntcreatex.out.file.fnum);
1123 smbcli_unlink(cli->tree, fname);
1130 static bool test_mknew(struct smbcli_state *cli, struct torture_context *tctx)
1133 const char *fname = BASEDIR "\\torture_mknew.txt";
1137 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1138 union smb_fileinfo finfo;
1140 printf("Checking RAW_OPEN_MKNEW\n");
1142 io.mknew.level = RAW_OPEN_MKNEW;
1143 io.mknew.in.attrib = 0;
1144 io.mknew.in.write_time = 0;
1145 io.mknew.in.fname = fname;
1146 status = smb_raw_open(cli->tree, tctx, &io);
1147 CHECK_STATUS(status, NT_STATUS_OK);
1148 fnum = io.mknew.out.file.fnum;
1150 status = smb_raw_open(cli->tree, tctx, &io);
1151 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
1153 smbcli_close(cli->tree, fnum);
1154 smbcli_unlink(cli->tree, fname);
1156 /* make sure write_time works */
1157 io.mknew.in.write_time = basetime;
1158 status = smb_raw_open(cli->tree, tctx, &io);
1159 CHECK_STATUS(status, NT_STATUS_OK);
1160 fnum = io.mknew.out.file.fnum;
1161 CHECK_TIME(basetime, write_time);
1163 smbcli_close(cli->tree, fnum);
1164 smbcli_unlink(cli->tree, fname);
1166 /* make sure file_attrs works */
1167 io.mknew.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1168 status = smb_raw_open(cli->tree, tctx, &io);
1169 CHECK_STATUS(status, NT_STATUS_OK);
1170 fnum = io.mknew.out.file.fnum;
1171 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE,
1172 attrib & ~FILE_ATTRIBUTE_NONINDEXED);
1175 smbcli_close(cli->tree, fnum);
1176 smbcli_unlink(cli->tree, fname);
1183 test RAW_OPEN_CREATE
1185 static bool test_create(struct smbcli_state *cli, struct torture_context *tctx)
1188 const char *fname = BASEDIR "\\torture_create.txt";
1192 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1193 union smb_fileinfo finfo;
1195 printf("Checking RAW_OPEN_CREATE\n");
1197 io.create.level = RAW_OPEN_CREATE;
1198 io.create.in.attrib = 0;
1199 io.create.in.write_time = 0;
1200 io.create.in.fname = fname;
1201 status = smb_raw_open(cli->tree, tctx, &io);
1202 CHECK_STATUS(status, NT_STATUS_OK);
1203 fnum = io.create.out.file.fnum;
1205 status = smb_raw_open(cli->tree, tctx, &io);
1206 CHECK_STATUS(status, NT_STATUS_OK);
1208 smbcli_close(cli->tree, io.create.out.file.fnum);
1209 smbcli_close(cli->tree, fnum);
1210 smbcli_unlink(cli->tree, fname);
1212 /* make sure write_time works */
1213 io.create.in.write_time = basetime;
1214 status = smb_raw_open(cli->tree, tctx, &io);
1215 CHECK_STATUS(status, NT_STATUS_OK);
1216 fnum = io.create.out.file.fnum;
1217 CHECK_TIME(basetime, write_time);
1219 smbcli_close(cli->tree, fnum);
1220 smbcli_unlink(cli->tree, fname);
1222 /* make sure file_attrs works */
1223 io.create.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1224 status = smb_raw_open(cli->tree, tctx, &io);
1225 CHECK_STATUS(status, NT_STATUS_OK);
1226 fnum = io.create.out.file.fnum;
1227 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE,
1228 attrib & ~FILE_ATTRIBUTE_NONINDEXED);
1231 smbcli_close(cli->tree, fnum);
1232 smbcli_unlink(cli->tree, fname);
1241 static bool test_ctemp(struct smbcli_state *cli, TALLOC_CTX *tctx)
1247 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1248 union smb_fileinfo finfo;
1249 const char *name, *fname = NULL;
1251 printf("Checking RAW_OPEN_CTEMP\n");
1253 io.ctemp.level = RAW_OPEN_CTEMP;
1254 io.ctemp.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1255 io.ctemp.in.write_time = basetime;
1256 io.ctemp.in.directory = BASEDIR;
1257 status = smb_raw_open(cli->tree, tctx, &io);
1258 CHECK_STATUS(status, NT_STATUS_OK);
1259 fnum = io.ctemp.out.file.fnum;
1261 name = io.ctemp.out.name;
1263 finfo.generic.level = RAW_FILEINFO_NAME_INFO;
1264 finfo.generic.in.file.fnum = fnum;
1265 status = smb_raw_fileinfo(cli->tree, tctx, &finfo);
1266 CHECK_STATUS(status, NT_STATUS_OK);
1268 fname = finfo.name_info.out.fname.s;
1269 d_printf("ctemp name=%s real name=%s\n", name, fname);
1272 smbcli_close(cli->tree, fnum);
1274 smbcli_unlink(cli->tree, fname);
1282 test chained RAW_OPEN_OPENX_READX
1284 static bool test_chained(struct smbcli_state *cli, TALLOC_CTX *tctx)
1287 const char *fname = BASEDIR "\\torture_chained.txt";
1291 const char *buf = "test";
1294 printf("Checking RAW_OPEN_OPENX chained with READX\n");
1295 smbcli_unlink(cli->tree, fname);
1297 fnum = create_complex_file(cli, tctx, fname);
1299 smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf));
1301 smbcli_close(cli->tree, fnum);
1303 io.openxreadx.level = RAW_OPEN_OPENX_READX;
1304 io.openxreadx.in.fname = fname;
1305 io.openxreadx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
1306 io.openxreadx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
1307 io.openxreadx.in.open_func = OPENX_OPEN_FUNC_OPEN;
1308 io.openxreadx.in.search_attrs = 0;
1309 io.openxreadx.in.file_attrs = 0;
1310 io.openxreadx.in.write_time = 0;
1311 io.openxreadx.in.size = 1024*1024;
1312 io.openxreadx.in.timeout = 0;
1314 io.openxreadx.in.offset = 0;
1315 io.openxreadx.in.mincnt = sizeof(buf);
1316 io.openxreadx.in.maxcnt = sizeof(buf);
1317 io.openxreadx.in.remaining = 0;
1318 io.openxreadx.out.data = (uint8_t *)buf2;
1320 status = smb_raw_open(cli->tree, tctx, &io);
1321 CHECK_STATUS(status, NT_STATUS_OK);
1322 fnum = io.openxreadx.out.file.fnum;
1324 if (memcmp(buf, buf2, sizeof(buf)) != 0) {
1325 d_printf("wrong data in reply buffer\n");
1330 smbcli_close(cli->tree, fnum);
1331 smbcli_unlink(cli->tree, fname);
1337 test RAW_OPEN_OPENX without a leading slash on the path.
1338 NetApp filers are known to fail on this.
1341 static bool test_no_leading_slash(struct smbcli_state *cli, TALLOC_CTX *tctx)
1344 const char *fname = BASEDIR "\\torture_no_leading_slash.txt";
1348 const char *buf = "test";
1350 printf("Checking RAW_OPEN_OPENX without leading slash on path\n");
1351 smbcli_unlink(cli->tree, fname);
1353 /* Create the file */
1354 fnum = create_complex_file(cli, tctx, fname);
1355 smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf));
1356 smbcli_close(cli->tree, fnum);
1358 /* Prepare to open the file using path without leading slash */
1359 io.openx.level = RAW_OPEN_OPENX;
1360 io.openx.in.fname = fname + 1;
1361 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
1362 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
1363 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
1364 io.openx.in.search_attrs = 0;
1365 io.openx.in.file_attrs = 0;
1366 io.openx.in.write_time = 0;
1367 io.openx.in.size = 1024*1024;
1368 io.openx.in.timeout = 0;
1370 status = smb_raw_open(cli->tree, tctx, &io);
1371 CHECK_STATUS(status, NT_STATUS_OK);
1372 fnum = io.openx.out.file.fnum;
1375 smbcli_close(cli->tree, fnum);
1376 smbcli_unlink(cli->tree, fname);
1381 /* A little torture test to expose a race condition in Samba 3.0.20 ... :-) */
1383 static bool test_raw_open_multi(struct torture_context *tctx)
1385 struct smbcli_state *cli;
1386 TALLOC_CTX *mem_ctx = talloc_init("torture_test_oplock_multi");
1387 const char *fname = "\\test_oplock.dat";
1391 struct smbcli_state **clients;
1392 struct smbcli_request **requests;
1393 union smb_open *ios;
1394 const char *host = torture_setting_string(tctx, "host", NULL);
1395 const char *share = torture_setting_string(tctx, "share", NULL);
1396 int i, num_files = 3;
1398 int num_collision = 0;
1400 clients = talloc_array(mem_ctx, struct smbcli_state *, num_files);
1401 requests = talloc_array(mem_ctx, struct smbcli_request *, num_files);
1402 ios = talloc_array(mem_ctx, union smb_open, num_files);
1403 if ((tctx->ev == NULL) || (clients == NULL) || (requests == NULL) ||
1405 DEBUG(0, ("talloc failed\n"));
1409 if (!torture_open_connection_share(mem_ctx, &cli, tctx, host, share, tctx->ev)) {
1413 cli->tree->session->transport->options.request_timeout = 60;
1415 for (i=0; i<num_files; i++) {
1416 if (!torture_open_connection_share(mem_ctx, &(clients[i]),
1417 tctx, host, share, tctx->ev)) {
1418 DEBUG(0, ("Could not open %d'th connection\n", i));
1421 clients[i]->tree->session->transport->options.request_timeout = 60;
1425 smbcli_unlink(cli->tree, fname);
1428 base ntcreatex parms
1430 io.generic.level = RAW_OPEN_NTCREATEX;
1431 io.ntcreatex.in.root_fid = 0;
1432 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
1433 io.ntcreatex.in.alloc_size = 0;
1434 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
1435 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ|
1436 NTCREATEX_SHARE_ACCESS_WRITE|
1437 NTCREATEX_SHARE_ACCESS_DELETE;
1438 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1439 io.ntcreatex.in.create_options = 0;
1440 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1441 io.ntcreatex.in.security_flags = 0;
1442 io.ntcreatex.in.fname = fname;
1443 io.ntcreatex.in.flags = 0;
1445 for (i=0; i<num_files; i++) {
1447 requests[i] = smb_raw_open_send(clients[i]->tree, &ios[i]);
1448 if (requests[i] == NULL) {
1449 DEBUG(0, ("could not send %d'th request\n", i));
1454 DEBUG(10, ("waiting for replies\n"));
1456 bool unreplied = false;
1457 for (i=0; i<num_files; i++) {
1458 if (requests[i] == NULL) {
1461 if (requests[i]->state < SMBCLI_REQUEST_DONE) {
1465 status = smb_raw_open_recv(requests[i], mem_ctx,
1468 DEBUG(0, ("File %d returned status %s\n", i,
1469 nt_errstr(status)));
1471 if (NT_STATUS_IS_OK(status)) {
1475 if (NT_STATUS_EQUAL(status,
1476 NT_STATUS_OBJECT_NAME_COLLISION)) {
1486 if (event_loop_once(tctx->ev) != 0) {
1487 DEBUG(0, ("event_loop_once failed\n"));
1492 if ((num_ok != 1) || (num_ok + num_collision != num_files)) {
1496 for (i=0; i<num_files; i++) {
1497 torture_close_connection(clients[i]);
1499 talloc_free(mem_ctx);
1503 /* basic testing of all RAW_OPEN_* calls
1505 bool torture_raw_open(struct torture_context *torture, struct smbcli_state *cli)
1509 if (!torture_setup_dir(cli, BASEDIR)) {
1513 ret &= test_ntcreatex_brlocked(cli, torture);
1514 ret &= test_open(cli, torture);
1515 ret &= test_raw_open_multi(torture);
1516 ret &= test_openx(cli, torture);
1517 ret &= test_ntcreatex(cli, torture);
1518 ret &= test_nttrans_create(cli, torture);
1519 ret &= test_t2open(cli, torture);
1520 ret &= test_mknew(cli, torture);
1521 ret &= test_create(cli, torture);
1522 ret &= test_ctemp(cli, torture);
1523 ret &= test_chained(cli, torture);
1524 ret &= test_no_leading_slash(cli, torture);
1526 smb_raw_exit(cli->session);
1527 smbcli_deltree(cli->tree, BASEDIR);