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"
25 /* enum for whether reads/writes are possible on a file */
26 enum rdwr_mode {RDWR_NONE, RDWR_RDONLY, RDWR_WRONLY, RDWR_RDWR};
28 #define BASEDIR "\\rawopen"
31 check if a open file can be read/written
33 static enum rdwr_mode check_rdwr(struct smbcli_tree *tree, int fnum)
36 BOOL can_read = (smbcli_read(tree, fnum, &c, 0, 1) == 1);
37 BOOL can_write = (smbcli_write(tree, fnum, 0, &c, 0, 1) == 1);
38 if ( can_read && can_write) return RDWR_RDWR;
39 if ( can_read && !can_write) return RDWR_RDONLY;
40 if (!can_read && can_write) return RDWR_WRONLY;
45 describe a RDWR mode as a string
47 static const char *rdwr_string(enum rdwr_mode m)
50 case RDWR_NONE: return "NONE";
51 case RDWR_RDONLY: return "RDONLY";
52 case RDWR_WRONLY: return "WRONLY";
53 case RDWR_RDWR: return "RDWR";
58 #define CHECK_STATUS(status, correct) do { \
59 if (!NT_STATUS_EQUAL(status, correct)) { \
60 printf("(%s) Incorrect status %s - should be %s\n", \
61 __location__, nt_errstr(status), nt_errstr(correct)); \
66 #define CREATE_FILE do { \
67 fnum = create_complex_file(cli, mem_ctx, fname); \
69 printf("(%s) Failed to create %s - %s\n", __location__, fname, smbcli_errstr(cli->tree)); \
74 #define CHECK_RDWR(fnum, correct) do { \
75 enum rdwr_mode m = check_rdwr(cli->tree, fnum); \
77 printf("(%s) Incorrect readwrite mode %s - expected %s\n", \
78 __location__, rdwr_string(m), rdwr_string(correct)); \
82 #define CHECK_TIME(t, field) do { \
84 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
85 finfo.all_info.in.fname = fname; \
86 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo); \
87 CHECK_STATUS(status, NT_STATUS_OK); \
89 t2 = nt_time_to_unix(finfo.all_info.out.field) & ~1; \
90 if (ABS(t1-t2) > 2) { \
91 printf("(%s) wrong time for field %s %s - %s\n", \
92 __location__, #field, \
93 timestring(mem_ctx, t1), \
94 timestring(mem_ctx, t2)); \
95 dump_all_info(mem_ctx, &finfo); \
99 #define CHECK_NTTIME(t, field) do { \
101 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
102 finfo.all_info.in.fname = fname; \
103 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo); \
104 CHECK_STATUS(status, NT_STATUS_OK); \
105 t2 = finfo.all_info.out.field; \
107 printf("(%s) wrong time for field %s %s - %s\n", \
108 __location__, #field, \
109 nt_time_string(mem_ctx, t), \
110 nt_time_string(mem_ctx, t2)); \
111 dump_all_info(mem_ctx, &finfo); \
115 #define CHECK_ALL_INFO(v, field) do { \
116 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
117 finfo.all_info.in.fname = fname; \
118 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo); \
119 CHECK_STATUS(status, NT_STATUS_OK); \
120 if ((v) != (finfo.all_info.out.field)) { \
121 printf("(%s) wrong value for field %s 0x%x - 0x%x\n", \
122 __location__, #field, (int)v, (int)(finfo.all_info.out.field)); \
123 dump_all_info(mem_ctx, &finfo); \
127 #define CHECK_VAL(v, correct) do { \
128 if ((v) != (correct)) { \
129 printf("(%s) wrong value for %s 0x%x - 0x%x\n", \
130 __location__, #v, (int)(v), (int)correct); \
134 #define SET_ATTRIB(sattrib) do { \
135 union smb_setfileinfo sfinfo; \
136 sfinfo.generic.level = RAW_SFILEINFO_BASIC_INFORMATION; \
137 sfinfo.generic.file.fname = fname; \
138 ZERO_STRUCT(sfinfo.basic_info.in); \
139 sfinfo.basic_info.in.attrib = sattrib; \
140 status = smb_raw_setpathinfo(cli->tree, &sfinfo); \
141 if (!NT_STATUS_IS_OK(status)) { \
142 printf("(%s) Failed to set attrib 0x%x on %s\n", \
143 __location__, sattrib, fname); \
149 static BOOL test_open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
152 union smb_fileinfo finfo;
153 const char *fname = BASEDIR "\\torture_open.txt";
155 int fnum = -1, fnum2;
158 printf("Checking RAW_OPEN_OPEN\n");
160 io.openold.level = RAW_OPEN_OPEN;
161 io.openold.in.fname = fname;
162 io.openold.in.flags = OPEN_FLAGS_FCB;
163 io.openold.in.search_attrs = 0;
164 status = smb_raw_open(cli->tree, mem_ctx, &io);
165 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
166 fnum = io.openold.out.fnum;
168 smbcli_unlink(cli->tree, fname);
170 smbcli_close(cli->tree, fnum);
172 status = smb_raw_open(cli->tree, mem_ctx, &io);
173 CHECK_STATUS(status, NT_STATUS_OK);
174 fnum = io.openold.out.fnum;
175 CHECK_RDWR(fnum, RDWR_RDWR);
177 status = smb_raw_open(cli->tree, mem_ctx, &io);
178 CHECK_STATUS(status, NT_STATUS_OK);
179 fnum2 = io.openold.out.fnum;
180 CHECK_RDWR(fnum2, RDWR_RDWR);
181 smbcli_close(cli->tree, fnum2);
182 smbcli_close(cli->tree, fnum);
184 /* check the read/write modes */
185 io.openold.level = RAW_OPEN_OPEN;
186 io.openold.in.fname = fname;
187 io.openold.in.search_attrs = 0;
189 io.openold.in.flags = OPEN_FLAGS_OPEN_READ;
190 status = smb_raw_open(cli->tree, mem_ctx, &io);
191 CHECK_STATUS(status, NT_STATUS_OK);
192 fnum = io.openold.out.fnum;
193 CHECK_RDWR(fnum, RDWR_RDONLY);
194 smbcli_close(cli->tree, fnum);
196 io.openold.in.flags = OPEN_FLAGS_OPEN_WRITE;
197 status = smb_raw_open(cli->tree, mem_ctx, &io);
198 CHECK_STATUS(status, NT_STATUS_OK);
199 fnum = io.openold.out.fnum;
200 CHECK_RDWR(fnum, RDWR_WRONLY);
201 smbcli_close(cli->tree, fnum);
203 io.openold.in.flags = OPEN_FLAGS_OPEN_RDWR;
204 status = smb_raw_open(cli->tree, mem_ctx, &io);
205 CHECK_STATUS(status, NT_STATUS_OK);
206 fnum = io.openold.out.fnum;
207 CHECK_RDWR(fnum, RDWR_RDWR);
208 smbcli_close(cli->tree, fnum);
210 /* check the share modes roughly - not a complete matrix */
211 io.openold.in.flags = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_WRITE;
212 status = smb_raw_open(cli->tree, mem_ctx, &io);
213 CHECK_STATUS(status, NT_STATUS_OK);
214 fnum = io.openold.out.fnum;
215 CHECK_RDWR(fnum, RDWR_RDWR);
217 if (io.openold.in.flags != io.openold.out.rmode) {
218 printf("(%s) rmode should equal flags - 0x%x 0x%x\n",
219 __location__, io.openold.out.rmode, io.openold.in.flags);
222 io.openold.in.flags = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_NONE;
223 status = smb_raw_open(cli->tree, mem_ctx, &io);
224 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
226 io.openold.in.flags = OPEN_FLAGS_OPEN_READ | OPEN_FLAGS_DENY_NONE;
227 status = smb_raw_open(cli->tree, mem_ctx, &io);
228 CHECK_STATUS(status, NT_STATUS_OK);
229 fnum2 = io.openold.out.fnum;
230 CHECK_RDWR(fnum2, RDWR_RDONLY);
231 smbcli_close(cli->tree, fnum);
232 smbcli_close(cli->tree, fnum2);
235 /* check the returned write time */
236 io.openold.level = RAW_OPEN_OPEN;
237 io.openold.in.fname = fname;
238 io.openold.in.search_attrs = 0;
239 io.openold.in.flags = OPEN_FLAGS_OPEN_READ;
240 status = smb_raw_open(cli->tree, mem_ctx, &io);
241 CHECK_STATUS(status, NT_STATUS_OK);
242 fnum = io.openold.out.fnum;
244 /* check other reply fields */
245 CHECK_TIME(io.openold.out.write_time, write_time);
246 CHECK_ALL_INFO(io.openold.out.size, size);
247 CHECK_ALL_INFO(io.openold.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
250 smbcli_close(cli->tree, fnum);
251 smbcli_unlink(cli->tree, fname);
260 static BOOL test_openx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
263 union smb_fileinfo finfo;
264 const char *fname = BASEDIR "\\torture_openx.txt";
266 int fnum = -1, fnum2;
272 NTSTATUS correct_status;
274 { OPENX_OPEN_FUNC_OPEN, True, NT_STATUS_OK },
275 { OPENX_OPEN_FUNC_OPEN, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
276 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OK },
277 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
278 { OPENX_OPEN_FUNC_FAIL, True, NT_STATUS_INVALID_LOCK_SEQUENCE },
279 { OPENX_OPEN_FUNC_FAIL, False, NT_STATUS_INVALID_LOCK_SEQUENCE },
280 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OBJECT_NAME_COLLISION },
281 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
282 { OPENX_OPEN_FUNC_TRUNC, True, NT_STATUS_OK },
283 { OPENX_OPEN_FUNC_TRUNC, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
284 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OK },
285 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
288 printf("Checking RAW_OPEN_OPENX\n");
289 smbcli_unlink(cli->tree, fname);
291 io.openx.level = RAW_OPEN_OPENX;
292 io.openx.in.fname = fname;
293 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
294 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
295 io.openx.in.search_attrs = 0;
296 io.openx.in.file_attrs = 0;
297 io.openx.in.write_time = 0;
298 io.openx.in.size = 1024*1024;
299 io.openx.in.timeout = 0;
301 /* check all combinations of open_func */
302 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
303 if (open_funcs[i].with_file) {
304 fnum = create_complex_file(cli, mem_ctx, fname);
306 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
310 smbcli_close(cli->tree, fnum);
312 io.openx.in.open_func = open_funcs[i].open_func;
313 status = smb_raw_open(cli->tree, mem_ctx, &io);
314 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
315 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n",
316 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
317 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_func);
320 if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
321 smbcli_close(cli->tree, io.openx.out.fnum);
322 smbcli_unlink(cli->tree, fname);
326 /* check the basic return fields */
327 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
328 status = smb_raw_open(cli->tree, mem_ctx, &io);
329 CHECK_STATUS(status, NT_STATUS_OK);
330 fnum = io.openx.out.fnum;
332 CHECK_ALL_INFO(io.openx.out.size, size);
333 CHECK_VAL(io.openx.out.size, 1024*1024);
334 CHECK_ALL_INFO(io.openx.in.size, size);
335 CHECK_TIME(io.openx.out.write_time, write_time);
336 CHECK_ALL_INFO(io.openx.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
337 CHECK_VAL(io.openx.out.access, OPENX_MODE_ACCESS_RDWR);
338 CHECK_VAL(io.openx.out.ftype, 0);
339 CHECK_VAL(io.openx.out.devstate, 0);
340 CHECK_VAL(io.openx.out.action, OPENX_ACTION_CREATED);
341 smbcli_close(cli->tree, fnum);
342 smbcli_unlink(cli->tree, fname);
344 /* check the fields when the file already existed */
345 fnum2 = create_complex_file(cli, mem_ctx, fname);
350 smbcli_close(cli->tree, fnum2);
352 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
353 status = smb_raw_open(cli->tree, mem_ctx, &io);
354 CHECK_STATUS(status, NT_STATUS_OK);
355 fnum = io.openx.out.fnum;
357 CHECK_ALL_INFO(io.openx.out.size, size);
358 CHECK_TIME(io.openx.out.write_time, write_time);
359 CHECK_VAL(io.openx.out.action, OPENX_ACTION_EXISTED);
360 CHECK_VAL(io.openx.out.unknown, 0);
361 CHECK_ALL_INFO(io.openx.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
362 smbcli_close(cli->tree, fnum);
364 /* now check the search attrib for hidden files - win2003 ignores this? */
365 SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN);
366 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib);
368 io.openx.in.search_attrs = FILE_ATTRIBUTE_HIDDEN;
369 status = smb_raw_open(cli->tree, mem_ctx, &io);
370 CHECK_STATUS(status, NT_STATUS_OK);
371 smbcli_close(cli->tree, io.openx.out.fnum);
373 io.openx.in.search_attrs = 0;
374 status = smb_raw_open(cli->tree, mem_ctx, &io);
375 CHECK_STATUS(status, NT_STATUS_OK);
376 smbcli_close(cli->tree, io.openx.out.fnum);
378 SET_ATTRIB(FILE_ATTRIBUTE_NORMAL);
379 smbcli_unlink(cli->tree, fname);
381 /* and check attrib on create */
382 io.openx.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE;
383 io.openx.in.search_attrs = 0;
384 io.openx.in.file_attrs = FILE_ATTRIBUTE_SYSTEM;
385 status = smb_raw_open(cli->tree, mem_ctx, &io);
386 CHECK_STATUS(status, NT_STATUS_OK);
387 CHECK_ALL_INFO(FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE,
388 attrib & ~FILE_ATTRIBUTE_NONINDEXED);
389 smbcli_close(cli->tree, io.openx.out.fnum);
390 smbcli_unlink(cli->tree, fname);
392 /* check timeout on create - win2003 ignores the timeout! */
393 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
394 io.openx.in.file_attrs = 0;
395 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL;
396 status = smb_raw_open(cli->tree, mem_ctx, &io);
397 CHECK_STATUS(status, NT_STATUS_OK);
398 fnum = io.openx.out.fnum;
400 io.openx.in.timeout = 20000;
402 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_NONE;
403 status = smb_raw_open(cli->tree, mem_ctx, &io);
404 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
405 if (end_timer() > 3) {
406 printf("(%s) Incorrect timing in openx with timeout - waited %d seconds\n",
407 __location__, (int)end_timer());
410 smbcli_close(cli->tree, fnum);
411 smbcli_unlink(cli->tree, fname);
413 /* now this is a really weird one - open for execute implies create?! */
414 io.openx.in.fname = fname;
415 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
416 io.openx.in.open_mode = OPENX_MODE_ACCESS_EXEC | OPENX_MODE_DENY_NONE;
417 io.openx.in.search_attrs = 0;
418 io.openx.in.open_func = OPENX_OPEN_FUNC_FAIL;
419 io.openx.in.file_attrs = 0;
420 io.openx.in.write_time = 0;
421 io.openx.in.size = 0;
422 io.openx.in.timeout = 0;
423 status = smb_raw_open(cli->tree, mem_ctx, &io);
424 CHECK_STATUS(status, NT_STATUS_OK);
425 smbcli_close(cli->tree, io.openx.out.fnum);
427 /* check the extended return flag */
428 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO | OPENX_FLAGS_EXTENDED_RETURN;
429 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
430 status = smb_raw_open(cli->tree, mem_ctx, &io);
431 CHECK_STATUS(status, NT_STATUS_OK);
432 CHECK_VAL(io.openx.out.access_mask, STD_RIGHT_ALL_ACCESS);
433 smbcli_close(cli->tree, io.openx.out.fnum);
436 smbcli_close(cli->tree, fnum);
437 smbcli_unlink(cli->tree, fname);
446 I can't work out how to get win2003 to accept a create file via TRANS2_OPEN, which
447 is why you see all the ACCESS_DENIED results below. When we finally work this out then this
448 test will make more sense
450 static BOOL test_t2open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
453 union smb_fileinfo finfo;
454 const char *fname = BASEDIR "\\torture_t2open.txt";
462 NTSTATUS correct_status;
464 { OPENX_OPEN_FUNC_OPEN, True, NT_STATUS_OK },
465 { OPENX_OPEN_FUNC_OPEN, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
466 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OK },
467 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_ACCESS_DENIED },
468 { OPENX_OPEN_FUNC_FAIL, True, NT_STATUS_OBJECT_NAME_COLLISION },
469 { OPENX_OPEN_FUNC_FAIL, False, NT_STATUS_ACCESS_DENIED },
470 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OBJECT_NAME_COLLISION },
471 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_ACCESS_DENIED },
472 { OPENX_OPEN_FUNC_TRUNC, True, NT_STATUS_ACCESS_DENIED },
473 { OPENX_OPEN_FUNC_TRUNC, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
474 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_ACCESS_DENIED },
475 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_ACCESS_DENIED },
478 printf("Checking RAW_OPEN_T2OPEN\n");
480 io.t2open.level = RAW_OPEN_T2OPEN;
481 io.t2open.in.fname = fname;
482 io.t2open.in.flags = OPENX_FLAGS_ADDITIONAL_INFO |
483 OPENX_FLAGS_EA_LEN | OPENX_FLAGS_EXTENDED_RETURN;
484 io.t2open.in.open_mode = OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR;
485 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
486 io.t2open.in.file_attrs = 0;
487 io.t2open.in.write_time = 0;
488 io.t2open.in.size = 0;
489 io.t2open.in.timeout = 0;
491 io.t2open.in.eas = talloc(mem_ctx, sizeof(io.t2open.in.eas[0]));
492 io.t2open.in.num_eas = 1;
493 io.t2open.in.eas[0].flags = 0;
494 io.t2open.in.eas[0].name.s = "EAONE";
495 io.t2open.in.eas[0].value = data_blob_talloc(mem_ctx, "1", 1);
497 /* check all combinations of open_func */
498 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
499 if (open_funcs[i].with_file) {
500 fnum = create_complex_file(cli, mem_ctx, fname);
502 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
506 smbcli_close(cli->tree, fnum);
508 io.t2open.in.open_func = open_funcs[i].open_func;
509 status = smb_raw_open(cli->tree, mem_ctx, &io);
510 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
511 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n",
512 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
513 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_func);
516 if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
517 smbcli_close(cli->tree, io.t2open.out.fnum);
518 smbcli_unlink(cli->tree, fname);
522 /* check the basic return fields */
523 fnum = create_complex_file(cli, mem_ctx, fname);
524 smbcli_close(cli->tree, fnum);
525 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
526 status = smb_raw_open(cli->tree, mem_ctx, &io);
527 CHECK_STATUS(status, NT_STATUS_OK);
528 fnum = io.t2open.out.fnum;
530 CHECK_ALL_INFO(io.t2open.out.size, size);
531 CHECK_VAL(io.t2open.out.write_time, 0);
532 CHECK_ALL_INFO(io.t2open.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
533 CHECK_VAL(io.t2open.out.access, OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR);
534 CHECK_VAL(io.t2open.out.ftype, 0);
535 CHECK_VAL(io.t2open.out.devstate, 0);
536 CHECK_VAL(io.t2open.out.action, OPENX_ACTION_EXISTED);
537 smbcli_close(cli->tree, fnum);
539 /* now check the search attrib for hidden files - win2003 ignores this? */
540 SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN);
541 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib);
543 status = smb_raw_open(cli->tree, mem_ctx, &io);
544 CHECK_STATUS(status, NT_STATUS_OK);
545 smbcli_close(cli->tree, io.t2open.out.fnum);
547 status = smb_raw_open(cli->tree, mem_ctx, &io);
548 CHECK_STATUS(status, NT_STATUS_OK);
549 smbcli_close(cli->tree, io.t2open.out.fnum);
551 SET_ATTRIB(FILE_ATTRIBUTE_NORMAL);
552 smbcli_unlink(cli->tree, fname);
554 /* and check attrib on create */
555 io.t2open.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE;
556 io.t2open.in.file_attrs = FILE_ATTRIBUTE_SYSTEM;
557 status = smb_raw_open(cli->tree, mem_ctx, &io);
558 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
560 /* check timeout on create - win2003 ignores the timeout! */
561 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
562 io.t2open.in.file_attrs = 0;
563 io.t2open.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL;
564 status = smb_raw_open(cli->tree, mem_ctx, &io);
565 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
568 smbcli_close(cli->tree, fnum);
569 smbcli_unlink(cli->tree, fname);
576 test RAW_OPEN_NTCREATEX
578 static BOOL test_ntcreatex(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
581 union smb_fileinfo finfo;
582 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
583 const char *dname = BASEDIR "\\torture_ntcreatex.dir";
591 NTSTATUS correct_status;
593 { NTCREATEX_DISP_SUPERSEDE, True, NT_STATUS_OK },
594 { NTCREATEX_DISP_SUPERSEDE, False, NT_STATUS_OK },
595 { NTCREATEX_DISP_OPEN, True, NT_STATUS_OK },
596 { NTCREATEX_DISP_OPEN, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
597 { NTCREATEX_DISP_CREATE, True, NT_STATUS_OBJECT_NAME_COLLISION },
598 { NTCREATEX_DISP_CREATE, False, NT_STATUS_OK },
599 { NTCREATEX_DISP_OPEN_IF, True, NT_STATUS_OK },
600 { NTCREATEX_DISP_OPEN_IF, False, NT_STATUS_OK },
601 { NTCREATEX_DISP_OVERWRITE, True, NT_STATUS_OK },
602 { NTCREATEX_DISP_OVERWRITE, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
603 { NTCREATEX_DISP_OVERWRITE_IF, True, NT_STATUS_OK },
604 { NTCREATEX_DISP_OVERWRITE_IF, False, NT_STATUS_OK },
605 { 6, True, NT_STATUS_INVALID_PARAMETER },
606 { 6, False, NT_STATUS_INVALID_PARAMETER },
609 printf("Checking RAW_OPEN_NTCREATEX\n");
611 /* reasonable default parameters */
612 io.generic.level = RAW_OPEN_NTCREATEX;
613 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
614 io.ntcreatex.in.root_fid = 0;
615 io.ntcreatex.in.access_mask = GENERIC_RIGHTS_FILE_ALL_ACCESS;
616 io.ntcreatex.in.alloc_size = 1024*1024;
617 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
618 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
619 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
620 io.ntcreatex.in.create_options = 0;
621 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
622 io.ntcreatex.in.security_flags = 0;
623 io.ntcreatex.in.fname = fname;
625 /* test the open disposition */
626 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
627 if (open_funcs[i].with_file) {
628 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE);
630 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
634 smbcli_close(cli->tree, fnum);
636 io.ntcreatex.in.open_disposition = open_funcs[i].open_disp;
637 status = smb_raw_open(cli->tree, mem_ctx, &io);
638 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
639 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_disp=%d)\n",
640 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
641 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_disp);
644 if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
645 smbcli_close(cli->tree, io.ntcreatex.out.fnum);
646 smbcli_unlink(cli->tree, fname);
650 /* basic field testing */
651 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
653 status = smb_raw_open(cli->tree, mem_ctx, &io);
654 CHECK_STATUS(status, NT_STATUS_OK);
655 fnum = io.ntcreatex.out.fnum;
657 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
658 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
659 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
660 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
661 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
662 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
663 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
664 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
665 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
666 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
667 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
669 /* check fields when the file already existed */
670 smbcli_close(cli->tree, fnum);
671 smbcli_unlink(cli->tree, fname);
672 fnum = create_complex_file(cli, mem_ctx, fname);
677 smbcli_close(cli->tree, fnum);
679 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
680 status = smb_raw_open(cli->tree, mem_ctx, &io);
681 CHECK_STATUS(status, NT_STATUS_OK);
682 fnum = io.ntcreatex.out.fnum;
684 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
685 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
686 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
687 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
688 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
689 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
690 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
691 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
692 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
693 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
694 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
695 smbcli_close(cli->tree, fnum);
696 smbcli_unlink(cli->tree, fname);
699 /* create a directory */
700 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
701 io.ntcreatex.in.access_mask = GENERIC_RIGHTS_FILE_ALL_ACCESS;
702 io.ntcreatex.in.alloc_size = 0;
703 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
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.fname = dname;
710 smbcli_rmdir(cli->tree, fname);
711 smbcli_unlink(cli->tree, fname);
713 io.ntcreatex.in.access_mask = SEC_RIGHT_MAXIMUM_ALLOWED;
714 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
715 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
716 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
717 status = smb_raw_open(cli->tree, mem_ctx, &io);
718 CHECK_STATUS(status, NT_STATUS_OK);
719 fnum = io.ntcreatex.out.fnum;
721 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
722 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
723 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
724 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
725 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
726 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
727 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
728 CHECK_VAL(io.ntcreatex.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED,
729 FILE_ATTRIBUTE_DIRECTORY);
730 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
731 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
732 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
733 CHECK_VAL(io.ntcreatex.out.is_directory, 1);
734 CHECK_VAL(io.ntcreatex.out.size, 0);
735 CHECK_VAL(io.ntcreatex.out.alloc_size, 0);
736 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
737 smbcli_unlink(cli->tree, fname);
741 smbcli_close(cli->tree, fnum);
742 smbcli_unlink(cli->tree, fname);
748 test RAW_OPEN_NTCREATEX with an already opened and byte range locked file
750 I've got an application that does a similar sequence of ntcreate&x,
751 locking&x and another ntcreate&x with
752 open_disposition==NTCREATEX_DISP_OVERWRITE_IF. Windows 2003 allows the
755 static BOOL test_ntcreatex_brlocked(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
757 union smb_open io, io1;
759 struct smb_lock_entry lock[1];
760 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
764 /* reasonable default parameters */
765 io.generic.level = RAW_OPEN_NTCREATEX;
766 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
767 io.ntcreatex.in.root_fid = 0;
768 io.ntcreatex.in.access_mask = 0x2019f;
769 io.ntcreatex.in.alloc_size = 0;
770 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
771 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
772 NTCREATEX_SHARE_ACCESS_WRITE;
773 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
774 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
775 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
776 io.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC |
777 NTCREATEX_SECURITY_ALL;
778 io.ntcreatex.in.fname = fname;
780 status = smb_raw_open(cli->tree, mem_ctx, &io);
781 CHECK_STATUS(status, NT_STATUS_OK);
783 io2.lockx.level = RAW_LOCK_LOCKX;
784 io2.lockx.in.fnum = io.ntcreatex.out.fnum;
785 io2.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
786 io2.lockx.in.timeout = 0;
787 io2.lockx.in.ulock_cnt = 0;
788 io2.lockx.in.lock_cnt = 1;
789 lock[0].pid = cli->session->pid;
792 io2.lockx.in.locks = &lock[0];
793 status = smb_raw_lock(cli->tree, &io2);
794 CHECK_STATUS(status, NT_STATUS_OK);
796 io1.generic.level = RAW_OPEN_NTCREATEX;
797 io1.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
798 io1.ntcreatex.in.root_fid = 0;
799 io1.ntcreatex.in.access_mask = 0x20196;
800 io1.ntcreatex.in.alloc_size = 0;
801 io1.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
802 io1.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
803 NTCREATEX_SHARE_ACCESS_WRITE;
804 io1.ntcreatex.in.open_disposition = NTCREATEX_DISP_OVERWRITE_IF;
805 io1.ntcreatex.in.create_options = 0;
806 io1.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
807 io1.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC |
808 NTCREATEX_SECURITY_ALL;
809 io1.ntcreatex.in.fname = fname;
811 status = smb_raw_open(cli->tree, mem_ctx, &io1);
812 CHECK_STATUS(status, NT_STATUS_OK);
815 smbcli_close(cli->tree, io.ntcreatex.out.fnum);
816 smbcli_close(cli->tree, io1.ntcreatex.out.fnum);
817 smbcli_unlink(cli->tree, fname);
824 static BOOL test_mknew(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
827 const char *fname = BASEDIR "\\torture_mknew.txt";
831 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
832 union smb_fileinfo finfo;
834 printf("Checking RAW_OPEN_MKNEW\n");
836 io.mknew.level = RAW_OPEN_MKNEW;
837 io.mknew.in.attrib = 0;
838 io.mknew.in.write_time = 0;
839 io.mknew.in.fname = fname;
840 status = smb_raw_open(cli->tree, mem_ctx, &io);
841 CHECK_STATUS(status, NT_STATUS_OK);
842 fnum = io.mknew.out.fnum;
844 status = smb_raw_open(cli->tree, mem_ctx, &io);
845 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
847 smbcli_close(cli->tree, fnum);
848 smbcli_unlink(cli->tree, fname);
850 /* make sure write_time works */
851 io.mknew.in.write_time = basetime;
852 status = smb_raw_open(cli->tree, mem_ctx, &io);
853 CHECK_STATUS(status, NT_STATUS_OK);
854 fnum = io.mknew.out.fnum;
855 CHECK_TIME(basetime, write_time);
857 smbcli_close(cli->tree, fnum);
858 smbcli_unlink(cli->tree, fname);
860 /* make sure file_attrs works */
861 io.mknew.in.attrib = FILE_ATTRIBUTE_HIDDEN;
862 status = smb_raw_open(cli->tree, mem_ctx, &io);
863 CHECK_STATUS(status, NT_STATUS_OK);
864 fnum = io.mknew.out.fnum;
865 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE,
866 attrib & ~FILE_ATTRIBUTE_NONINDEXED);
869 smbcli_close(cli->tree, fnum);
870 smbcli_unlink(cli->tree, fname);
879 static BOOL test_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
882 const char *fname = BASEDIR "\\torture_create.txt";
886 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
887 union smb_fileinfo finfo;
889 printf("Checking RAW_OPEN_CREATE\n");
891 io.create.level = RAW_OPEN_CREATE;
892 io.create.in.attrib = 0;
893 io.create.in.write_time = 0;
894 io.create.in.fname = fname;
895 status = smb_raw_open(cli->tree, mem_ctx, &io);
896 CHECK_STATUS(status, NT_STATUS_OK);
897 fnum = io.create.out.fnum;
899 status = smb_raw_open(cli->tree, mem_ctx, &io);
900 CHECK_STATUS(status, NT_STATUS_OK);
902 smbcli_close(cli->tree, io.create.out.fnum);
903 smbcli_close(cli->tree, fnum);
904 smbcli_unlink(cli->tree, fname);
906 /* make sure write_time works */
907 io.create.in.write_time = basetime;
908 status = smb_raw_open(cli->tree, mem_ctx, &io);
909 CHECK_STATUS(status, NT_STATUS_OK);
910 fnum = io.create.out.fnum;
911 CHECK_TIME(basetime, write_time);
913 smbcli_close(cli->tree, fnum);
914 smbcli_unlink(cli->tree, fname);
916 /* make sure file_attrs works */
917 io.create.in.attrib = FILE_ATTRIBUTE_HIDDEN;
918 status = smb_raw_open(cli->tree, mem_ctx, &io);
919 CHECK_STATUS(status, NT_STATUS_OK);
920 fnum = io.create.out.fnum;
921 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE,
922 attrib & ~FILE_ATTRIBUTE_NONINDEXED);
925 smbcli_close(cli->tree, fnum);
926 smbcli_unlink(cli->tree, fname);
935 static BOOL test_ctemp(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
941 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
942 union smb_fileinfo finfo;
943 const char *name, *fname = NULL;
945 printf("Checking RAW_OPEN_CTEMP\n");
947 io.ctemp.level = RAW_OPEN_CTEMP;
948 io.ctemp.in.attrib = FILE_ATTRIBUTE_HIDDEN;
949 io.ctemp.in.write_time = basetime;
950 io.ctemp.in.directory = BASEDIR;
951 status = smb_raw_open(cli->tree, mem_ctx, &io);
952 CHECK_STATUS(status, NT_STATUS_OK);
953 fnum = io.ctemp.out.fnum;
955 name = io.ctemp.out.name;
957 finfo.generic.level = RAW_FILEINFO_NAME_INFO;
958 finfo.generic.in.fnum = fnum;
959 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
960 CHECK_STATUS(status, NT_STATUS_OK);
962 fname = finfo.name_info.out.fname.s;
963 d_printf("ctemp name=%s real name=%s\n", name, fname);
965 CHECK_TIME(basetime, write_time);
968 smbcli_close(cli->tree, fnum);
970 smbcli_unlink(cli->tree, fname);
976 /* basic testing of all RAW_OPEN_* calls
978 BOOL torture_raw_open(void)
980 struct smbcli_state *cli;
984 if (!torture_open_connection(&cli)) {
988 mem_ctx = talloc_init("torture_raw_open");
990 if (smbcli_deltree(cli->tree, BASEDIR) == -1) {
991 printf("Failed to clean " BASEDIR "\n");
994 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
995 printf("Failed to create " BASEDIR " - %s\n", smbcli_errstr(cli->tree));
999 if (!test_ntcreatex_brlocked(cli, mem_ctx)) {
1003 if (!test_open(cli, mem_ctx)) {
1007 if (!test_openx(cli, mem_ctx)) {
1011 if (!test_ntcreatex(cli, mem_ctx)) {
1015 if (!test_t2open(cli, mem_ctx)) {
1019 if (!test_mknew(cli, mem_ctx)) {
1023 if (!test_create(cli, mem_ctx)) {
1027 if (!test_ctemp(cli, mem_ctx)) {
1031 smb_raw_exit(cli->session);
1032 smbcli_deltree(cli->tree, BASEDIR);
1034 torture_close_connection(cli);
1035 talloc_destroy(mem_ctx);