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"
24 /* enum for whether reads/writes are possible on a file */
25 enum rdwr_mode {RDWR_NONE, RDWR_RDONLY, RDWR_WRONLY, RDWR_RDWR};
27 #define BASEDIR "\\rawopen"
30 check if a open file can be read/written
32 static enum rdwr_mode check_rdwr(struct smbcli_tree *tree, int fnum)
35 BOOL can_read = (smbcli_read(tree, fnum, &c, 0, 1) == 1);
36 BOOL can_write = (smbcli_write(tree, fnum, 0, &c, 0, 1) == 1);
37 if ( can_read && can_write) return RDWR_RDWR;
38 if ( can_read && !can_write) return RDWR_RDONLY;
39 if (!can_read && can_write) return RDWR_WRONLY;
44 describe a RDWR mode as a string
46 static const char *rdwr_string(enum rdwr_mode m)
49 case RDWR_NONE: return "NONE";
50 case RDWR_RDONLY: return "RDONLY";
51 case RDWR_WRONLY: return "WRONLY";
52 case RDWR_RDWR: return "RDWR";
57 #define CHECK_STATUS(status, correct) do { \
58 if (!NT_STATUS_EQUAL(status, correct)) { \
59 printf("(%s) Incorrect status %s - should be %s\n", \
60 __location__, nt_errstr(status), nt_errstr(correct)); \
65 #define CREATE_FILE do { \
66 fnum = create_complex_file(cli, mem_ctx, fname); \
68 printf("(%s) Failed to create %s - %s\n", __location__, fname, smbcli_errstr(cli->tree)); \
73 #define CHECK_RDWR(fnum, correct) do { \
74 enum rdwr_mode m = check_rdwr(cli->tree, fnum); \
76 printf("(%s) Incorrect readwrite mode %s - expected %s\n", \
77 __location__, rdwr_string(m), rdwr_string(correct)); \
81 #define CHECK_TIME(t, field) do { \
83 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
84 finfo.all_info.in.fname = fname; \
85 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo); \
86 CHECK_STATUS(status, NT_STATUS_OK); \
88 t2 = nt_time_to_unix(finfo.all_info.out.field) & ~1; \
89 if (ABS(t1-t2) > 2) { \
90 printf("(%s) wrong time for field %s %s - %s\n", \
91 __location__, #field, \
92 timestring(mem_ctx, t1), \
93 timestring(mem_ctx, t2)); \
94 dump_all_info(mem_ctx, &finfo); \
98 #define CHECK_NTTIME(t, field) do { \
100 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
101 finfo.all_info.in.fname = fname; \
102 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo); \
103 CHECK_STATUS(status, NT_STATUS_OK); \
104 t2 = finfo.all_info.out.field; \
106 printf("(%s) wrong time for field %s %s - %s\n", \
107 __location__, #field, \
108 nt_time_string(mem_ctx, t), \
109 nt_time_string(mem_ctx, t2)); \
110 dump_all_info(mem_ctx, &finfo); \
114 #define CHECK_ALL_INFO(v, field) do { \
115 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
116 finfo.all_info.in.fname = fname; \
117 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo); \
118 CHECK_STATUS(status, NT_STATUS_OK); \
119 if ((v) != (finfo.all_info.out.field)) { \
120 printf("(%s) wrong value for field %s 0x%x - 0x%x\n", \
121 __location__, #field, (int)v, (int)(finfo.all_info.out.field)); \
122 dump_all_info(mem_ctx, &finfo); \
126 #define CHECK_VAL(v, correct) do { \
127 if ((v) != (correct)) { \
128 printf("(%s) wrong value for %s 0x%x - 0x%x\n", \
129 __location__, #v, (int)(v), (int)correct); \
133 #define SET_ATTRIB(sattrib) do { \
134 union smb_setfileinfo sfinfo; \
135 sfinfo.generic.level = RAW_SFILEINFO_BASIC_INFORMATION; \
136 sfinfo.generic.file.fname = fname; \
137 ZERO_STRUCT(sfinfo.basic_info.in); \
138 sfinfo.basic_info.in.attrib = sattrib; \
139 status = smb_raw_setpathinfo(cli->tree, &sfinfo); \
140 if (!NT_STATUS_IS_OK(status)) { \
141 printf("(%s) Failed to set attrib 0x%x on %s\n", \
142 __location__, sattrib, fname); \
148 static BOOL test_open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
151 union smb_fileinfo finfo;
152 const char *fname = BASEDIR "\\torture_open.txt";
154 int fnum = -1, fnum2;
157 printf("Checking RAW_OPEN_OPEN\n");
159 io.open.level = RAW_OPEN_OPEN;
160 io.open.in.fname = fname;
161 io.open.in.flags = OPEN_FLAGS_FCB;
162 io.open.in.search_attrs = 0;
163 status = smb_raw_open(cli->tree, mem_ctx, &io);
164 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
165 fnum = io.open.out.fnum;
167 smbcli_unlink(cli->tree, fname);
169 smbcli_close(cli->tree, fnum);
171 status = smb_raw_open(cli->tree, mem_ctx, &io);
172 CHECK_STATUS(status, NT_STATUS_OK);
173 fnum = io.open.out.fnum;
174 CHECK_RDWR(fnum, RDWR_RDWR);
176 status = smb_raw_open(cli->tree, mem_ctx, &io);
177 CHECK_STATUS(status, NT_STATUS_OK);
178 fnum2 = io.open.out.fnum;
179 CHECK_RDWR(fnum2, RDWR_RDWR);
180 smbcli_close(cli->tree, fnum2);
181 smbcli_close(cli->tree, fnum);
183 /* check the read/write modes */
184 io.open.level = RAW_OPEN_OPEN;
185 io.open.in.fname = fname;
186 io.open.in.search_attrs = 0;
188 io.open.in.flags = OPEN_FLAGS_OPEN_READ;
189 status = smb_raw_open(cli->tree, mem_ctx, &io);
190 CHECK_STATUS(status, NT_STATUS_OK);
191 fnum = io.open.out.fnum;
192 CHECK_RDWR(fnum, RDWR_RDONLY);
193 smbcli_close(cli->tree, fnum);
195 io.open.in.flags = OPEN_FLAGS_OPEN_WRITE;
196 status = smb_raw_open(cli->tree, mem_ctx, &io);
197 CHECK_STATUS(status, NT_STATUS_OK);
198 fnum = io.open.out.fnum;
199 CHECK_RDWR(fnum, RDWR_WRONLY);
200 smbcli_close(cli->tree, fnum);
202 io.open.in.flags = OPEN_FLAGS_OPEN_RDWR;
203 status = smb_raw_open(cli->tree, mem_ctx, &io);
204 CHECK_STATUS(status, NT_STATUS_OK);
205 fnum = io.open.out.fnum;
206 CHECK_RDWR(fnum, RDWR_RDWR);
207 smbcli_close(cli->tree, fnum);
209 /* check the share modes roughly - not a complete matrix */
210 io.open.in.flags = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_WRITE;
211 status = smb_raw_open(cli->tree, mem_ctx, &io);
212 CHECK_STATUS(status, NT_STATUS_OK);
213 fnum = io.open.out.fnum;
214 CHECK_RDWR(fnum, RDWR_RDWR);
216 if (io.open.in.flags != io.open.out.rmode) {
217 printf("(%s) rmode should equal flags - 0x%x 0x%x\n",
218 __location__, io.open.out.rmode, io.open.in.flags);
221 io.open.in.flags = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_NONE;
222 status = smb_raw_open(cli->tree, mem_ctx, &io);
223 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
225 io.open.in.flags = OPEN_FLAGS_OPEN_READ | OPEN_FLAGS_DENY_NONE;
226 status = smb_raw_open(cli->tree, mem_ctx, &io);
227 CHECK_STATUS(status, NT_STATUS_OK);
228 fnum2 = io.open.out.fnum;
229 CHECK_RDWR(fnum2, RDWR_RDONLY);
230 smbcli_close(cli->tree, fnum);
231 smbcli_close(cli->tree, fnum2);
234 /* check the returned write time */
235 io.open.level = RAW_OPEN_OPEN;
236 io.open.in.fname = fname;
237 io.open.in.search_attrs = 0;
238 io.open.in.flags = OPEN_FLAGS_OPEN_READ;
239 status = smb_raw_open(cli->tree, mem_ctx, &io);
240 CHECK_STATUS(status, NT_STATUS_OK);
241 fnum = io.open.out.fnum;
243 /* check other reply fields */
244 CHECK_TIME(io.open.out.write_time, write_time);
245 CHECK_ALL_INFO(io.open.out.size, size);
246 CHECK_ALL_INFO(io.open.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
249 smbcli_close(cli->tree, fnum);
250 smbcli_unlink(cli->tree, fname);
259 static BOOL test_openx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
262 union smb_fileinfo finfo;
263 const char *fname = BASEDIR "\\torture_openx.txt";
265 int fnum = -1, fnum2;
271 NTSTATUS correct_status;
273 { OPENX_OPEN_FUNC_OPEN, True, NT_STATUS_OK },
274 { OPENX_OPEN_FUNC_OPEN, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
275 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OK },
276 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
277 { OPENX_OPEN_FUNC_FAIL, True, NT_STATUS_INVALID_LOCK_SEQUENCE },
278 { OPENX_OPEN_FUNC_FAIL, False, NT_STATUS_INVALID_LOCK_SEQUENCE },
279 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OBJECT_NAME_COLLISION },
280 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
281 { OPENX_OPEN_FUNC_TRUNC, True, NT_STATUS_OK },
282 { OPENX_OPEN_FUNC_TRUNC, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
283 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OK },
284 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
287 printf("Checking RAW_OPEN_OPENX\n");
288 smbcli_unlink(cli->tree, fname);
290 io.openx.level = RAW_OPEN_OPENX;
291 io.openx.in.fname = fname;
292 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
293 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
294 io.openx.in.search_attrs = 0;
295 io.openx.in.file_attrs = 0;
296 io.openx.in.write_time = 0;
297 io.openx.in.size = 1024*1024;
298 io.openx.in.timeout = 0;
300 /* check all combinations of open_func */
301 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
302 if (open_funcs[i].with_file) {
303 fnum = create_complex_file(cli, mem_ctx, fname);
305 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
309 smbcli_close(cli->tree, fnum);
311 io.openx.in.open_func = open_funcs[i].open_func;
312 status = smb_raw_open(cli->tree, mem_ctx, &io);
313 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
314 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n",
315 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
316 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_func);
319 if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
320 smbcli_close(cli->tree, io.openx.out.fnum);
321 smbcli_unlink(cli->tree, fname);
325 /* check the basic return fields */
326 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
327 status = smb_raw_open(cli->tree, mem_ctx, &io);
328 CHECK_STATUS(status, NT_STATUS_OK);
329 fnum = io.openx.out.fnum;
331 CHECK_ALL_INFO(io.openx.out.size, size);
332 CHECK_VAL(io.openx.out.size, 1024*1024);
333 CHECK_ALL_INFO(io.openx.in.size, size);
334 CHECK_TIME(io.openx.out.write_time, write_time);
335 CHECK_ALL_INFO(io.openx.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
336 CHECK_VAL(io.openx.out.access, OPENX_MODE_ACCESS_RDWR);
337 CHECK_VAL(io.openx.out.ftype, 0);
338 CHECK_VAL(io.openx.out.devstate, 0);
339 CHECK_VAL(io.openx.out.action, OPENX_ACTION_CREATED);
340 smbcli_close(cli->tree, fnum);
341 smbcli_unlink(cli->tree, fname);
343 /* check the fields when the file already existed */
344 fnum2 = create_complex_file(cli, mem_ctx, fname);
349 smbcli_close(cli->tree, fnum2);
351 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
352 status = smb_raw_open(cli->tree, mem_ctx, &io);
353 CHECK_STATUS(status, NT_STATUS_OK);
354 fnum = io.openx.out.fnum;
356 CHECK_ALL_INFO(io.openx.out.size, size);
357 CHECK_TIME(io.openx.out.write_time, write_time);
358 CHECK_VAL(io.openx.out.action, OPENX_ACTION_EXISTED);
359 CHECK_VAL(io.openx.out.unknown, 0);
360 CHECK_ALL_INFO(io.openx.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
361 smbcli_close(cli->tree, fnum);
363 /* now check the search attrib for hidden files - win2003 ignores this? */
364 SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN);
365 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib);
367 io.openx.in.search_attrs = FILE_ATTRIBUTE_HIDDEN;
368 status = smb_raw_open(cli->tree, mem_ctx, &io);
369 CHECK_STATUS(status, NT_STATUS_OK);
370 smbcli_close(cli->tree, io.openx.out.fnum);
372 io.openx.in.search_attrs = 0;
373 status = smb_raw_open(cli->tree, mem_ctx, &io);
374 CHECK_STATUS(status, NT_STATUS_OK);
375 smbcli_close(cli->tree, io.openx.out.fnum);
377 SET_ATTRIB(FILE_ATTRIBUTE_NORMAL);
378 smbcli_unlink(cli->tree, fname);
380 /* and check attrib on create */
381 io.openx.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE;
382 io.openx.in.search_attrs = 0;
383 io.openx.in.file_attrs = FILE_ATTRIBUTE_SYSTEM;
384 status = smb_raw_open(cli->tree, mem_ctx, &io);
385 CHECK_STATUS(status, NT_STATUS_OK);
386 CHECK_ALL_INFO(FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE,
387 attrib & ~FILE_ATTRIBUTE_NONINDEXED);
388 smbcli_close(cli->tree, io.openx.out.fnum);
389 smbcli_unlink(cli->tree, fname);
391 /* check timeout on create - win2003 ignores the timeout! */
392 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
393 io.openx.in.file_attrs = 0;
394 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL;
395 status = smb_raw_open(cli->tree, mem_ctx, &io);
396 CHECK_STATUS(status, NT_STATUS_OK);
397 fnum = io.openx.out.fnum;
399 io.openx.in.timeout = 20000;
401 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_NONE;
402 status = smb_raw_open(cli->tree, mem_ctx, &io);
403 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
404 if (end_timer() > 3) {
405 printf("(%s) Incorrect timing in openx with timeout - waited %d seconds\n",
406 __location__, (int)end_timer());
409 smbcli_close(cli->tree, fnum);
410 smbcli_unlink(cli->tree, fname);
412 /* now this is a really weird one - open for execute implies create?! */
413 io.openx.in.fname = fname;
414 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
415 io.openx.in.open_mode = OPENX_MODE_ACCESS_EXEC | OPENX_MODE_DENY_NONE;
416 io.openx.in.search_attrs = 0;
417 io.openx.in.open_func = OPENX_OPEN_FUNC_FAIL;
418 io.openx.in.file_attrs = 0;
419 io.openx.in.write_time = 0;
420 io.openx.in.size = 0;
421 io.openx.in.timeout = 0;
422 status = smb_raw_open(cli->tree, mem_ctx, &io);
423 CHECK_STATUS(status, NT_STATUS_OK);
424 smbcli_close(cli->tree, io.openx.out.fnum);
426 /* check the extended return flag */
427 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO | OPENX_FLAGS_EXTENDED_RETURN;
428 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
429 status = smb_raw_open(cli->tree, mem_ctx, &io);
430 CHECK_STATUS(status, NT_STATUS_OK);
431 CHECK_VAL(io.openx.out.access_mask, STD_RIGHT_ALL_ACCESS);
432 smbcli_close(cli->tree, io.openx.out.fnum);
435 smbcli_close(cli->tree, fnum);
436 smbcli_unlink(cli->tree, fname);
445 I can't work out how to get win2003 to accept a create file via TRANS2_OPEN, which
446 is why you see all the ACCESS_DENIED results below. When we finally work this out then this
447 test will make more sense
449 static BOOL test_t2open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
452 union smb_fileinfo finfo;
453 const char *fname = BASEDIR "\\torture_t2open.txt";
461 NTSTATUS correct_status;
463 { OPENX_OPEN_FUNC_OPEN, True, NT_STATUS_OK },
464 { OPENX_OPEN_FUNC_OPEN, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
465 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OK },
466 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_ACCESS_DENIED },
467 { OPENX_OPEN_FUNC_FAIL, True, NT_STATUS_OBJECT_NAME_COLLISION },
468 { OPENX_OPEN_FUNC_FAIL, False, NT_STATUS_ACCESS_DENIED },
469 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OBJECT_NAME_COLLISION },
470 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_ACCESS_DENIED },
471 { OPENX_OPEN_FUNC_TRUNC, True, NT_STATUS_ACCESS_DENIED },
472 { OPENX_OPEN_FUNC_TRUNC, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
473 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_ACCESS_DENIED },
474 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_ACCESS_DENIED },
477 printf("Checking RAW_OPEN_T2OPEN\n");
479 io.t2open.level = RAW_OPEN_T2OPEN;
480 io.t2open.in.fname = fname;
481 io.t2open.in.flags = OPENX_FLAGS_ADDITIONAL_INFO |
482 OPENX_FLAGS_EA_LEN | OPENX_FLAGS_EXTENDED_RETURN;
483 io.t2open.in.open_mode = OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR;
484 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
485 io.t2open.in.file_attrs = 0;
486 io.t2open.in.write_time = 0;
487 io.t2open.in.size = 0;
488 io.t2open.in.timeout = 0;
490 io.t2open.in.eas = talloc(mem_ctx, sizeof(io.t2open.in.eas[0]));
491 io.t2open.in.num_eas = 1;
492 io.t2open.in.eas[0].flags = 0;
493 io.t2open.in.eas[0].name.s = "EAONE";
494 io.t2open.in.eas[0].value = data_blob_talloc(mem_ctx, "1", 1);
496 /* check all combinations of open_func */
497 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
498 if (open_funcs[i].with_file) {
499 fnum = create_complex_file(cli, mem_ctx, fname);
501 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
505 smbcli_close(cli->tree, fnum);
507 io.t2open.in.open_func = open_funcs[i].open_func;
508 status = smb_raw_open(cli->tree, mem_ctx, &io);
509 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
510 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n",
511 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
512 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_func);
515 if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
516 smbcli_close(cli->tree, io.t2open.out.fnum);
517 smbcli_unlink(cli->tree, fname);
521 /* check the basic return fields */
522 fnum = create_complex_file(cli, mem_ctx, fname);
523 smbcli_close(cli->tree, fnum);
524 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
525 status = smb_raw_open(cli->tree, mem_ctx, &io);
526 CHECK_STATUS(status, NT_STATUS_OK);
527 fnum = io.t2open.out.fnum;
529 CHECK_ALL_INFO(io.t2open.out.size, size);
530 CHECK_VAL(io.t2open.out.write_time, 0);
531 CHECK_ALL_INFO(io.t2open.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
532 CHECK_VAL(io.t2open.out.access, OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR);
533 CHECK_VAL(io.t2open.out.ftype, 0);
534 CHECK_VAL(io.t2open.out.devstate, 0);
535 CHECK_VAL(io.t2open.out.action, OPENX_ACTION_EXISTED);
536 smbcli_close(cli->tree, fnum);
538 /* now check the search attrib for hidden files - win2003 ignores this? */
539 SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN);
540 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib);
542 status = smb_raw_open(cli->tree, mem_ctx, &io);
543 CHECK_STATUS(status, NT_STATUS_OK);
544 smbcli_close(cli->tree, io.t2open.out.fnum);
546 status = smb_raw_open(cli->tree, mem_ctx, &io);
547 CHECK_STATUS(status, NT_STATUS_OK);
548 smbcli_close(cli->tree, io.t2open.out.fnum);
550 SET_ATTRIB(FILE_ATTRIBUTE_NORMAL);
551 smbcli_unlink(cli->tree, fname);
553 /* and check attrib on create */
554 io.t2open.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE;
555 io.t2open.in.file_attrs = FILE_ATTRIBUTE_SYSTEM;
556 status = smb_raw_open(cli->tree, mem_ctx, &io);
557 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
559 /* check timeout on create - win2003 ignores the timeout! */
560 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
561 io.t2open.in.file_attrs = 0;
562 io.t2open.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL;
563 status = smb_raw_open(cli->tree, mem_ctx, &io);
564 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
567 smbcli_close(cli->tree, fnum);
568 smbcli_unlink(cli->tree, fname);
575 test RAW_OPEN_NTCREATEX
577 static BOOL test_ntcreatex(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
580 union smb_fileinfo finfo;
581 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
582 const char *dname = BASEDIR "\\torture_ntcreatex.dir";
590 NTSTATUS correct_status;
592 { NTCREATEX_DISP_SUPERSEDE, True, NT_STATUS_OK },
593 { NTCREATEX_DISP_SUPERSEDE, False, NT_STATUS_OK },
594 { NTCREATEX_DISP_OPEN, True, NT_STATUS_OK },
595 { NTCREATEX_DISP_OPEN, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
596 { NTCREATEX_DISP_CREATE, True, NT_STATUS_OBJECT_NAME_COLLISION },
597 { NTCREATEX_DISP_CREATE, False, NT_STATUS_OK },
598 { NTCREATEX_DISP_OPEN_IF, True, NT_STATUS_OK },
599 { NTCREATEX_DISP_OPEN_IF, False, NT_STATUS_OK },
600 { NTCREATEX_DISP_OVERWRITE, True, NT_STATUS_OK },
601 { NTCREATEX_DISP_OVERWRITE, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
602 { NTCREATEX_DISP_OVERWRITE_IF, True, NT_STATUS_OK },
603 { NTCREATEX_DISP_OVERWRITE_IF, False, NT_STATUS_OK },
604 { 6, True, NT_STATUS_INVALID_PARAMETER },
605 { 6, False, NT_STATUS_INVALID_PARAMETER },
608 printf("Checking RAW_OPEN_NTCREATEX\n");
610 /* reasonable default parameters */
611 io.generic.level = RAW_OPEN_NTCREATEX;
612 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
613 io.ntcreatex.in.root_fid = 0;
614 io.ntcreatex.in.access_mask = GENERIC_RIGHTS_FILE_ALL_ACCESS;
615 io.ntcreatex.in.alloc_size = 1024*1024;
616 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
617 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
618 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
619 io.ntcreatex.in.create_options = 0;
620 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
621 io.ntcreatex.in.security_flags = 0;
622 io.ntcreatex.in.fname = fname;
624 /* test the open disposition */
625 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
626 if (open_funcs[i].with_file) {
627 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE);
629 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
633 smbcli_close(cli->tree, fnum);
635 io.ntcreatex.in.open_disposition = open_funcs[i].open_disp;
636 status = smb_raw_open(cli->tree, mem_ctx, &io);
637 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
638 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_disp=%d)\n",
639 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
640 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_disp);
643 if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
644 smbcli_close(cli->tree, io.ntcreatex.out.fnum);
645 smbcli_unlink(cli->tree, fname);
649 /* basic field testing */
650 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
652 status = smb_raw_open(cli->tree, mem_ctx, &io);
653 CHECK_STATUS(status, NT_STATUS_OK);
654 fnum = io.ntcreatex.out.fnum;
656 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
657 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
658 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
659 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
660 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
661 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
662 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
663 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
664 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
665 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
666 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
668 /* check fields when the file already existed */
669 smbcli_close(cli->tree, fnum);
670 smbcli_unlink(cli->tree, fname);
671 fnum = create_complex_file(cli, mem_ctx, fname);
676 smbcli_close(cli->tree, fnum);
678 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
679 status = smb_raw_open(cli->tree, mem_ctx, &io);
680 CHECK_STATUS(status, NT_STATUS_OK);
681 fnum = io.ntcreatex.out.fnum;
683 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
684 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
685 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
686 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
687 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
688 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
689 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
690 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
691 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
692 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
693 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
694 smbcli_close(cli->tree, fnum);
695 smbcli_unlink(cli->tree, fname);
698 /* create a directory */
699 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
700 io.ntcreatex.in.access_mask = GENERIC_RIGHTS_FILE_ALL_ACCESS;
701 io.ntcreatex.in.alloc_size = 0;
702 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
703 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
704 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
705 io.ntcreatex.in.create_options = 0;
706 io.ntcreatex.in.fname = dname;
709 smbcli_rmdir(cli->tree, fname);
710 smbcli_unlink(cli->tree, fname);
712 io.ntcreatex.in.access_mask = SEC_RIGHT_MAXIMUM_ALLOWED;
713 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
714 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
715 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
716 status = smb_raw_open(cli->tree, mem_ctx, &io);
717 CHECK_STATUS(status, NT_STATUS_OK);
718 fnum = io.ntcreatex.out.fnum;
720 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
721 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
722 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
723 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
724 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
725 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
726 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
727 CHECK_VAL(io.ntcreatex.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED,
728 FILE_ATTRIBUTE_DIRECTORY);
729 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
730 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
731 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
732 CHECK_VAL(io.ntcreatex.out.is_directory, 1);
733 CHECK_VAL(io.ntcreatex.out.size, 0);
734 CHECK_VAL(io.ntcreatex.out.alloc_size, 0);
735 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
736 smbcli_unlink(cli->tree, fname);
740 smbcli_close(cli->tree, fnum);
741 smbcli_unlink(cli->tree, fname);
747 test RAW_OPEN_NTCREATEX with an already opened and byte range locked file
749 I've got an application that does a similar sequence of ntcreate&x,
750 locking&x and another ntcreate&x with
751 open_disposition==NTCREATEX_DISP_OVERWRITE_IF. Windows 2003 allows the
754 static BOOL test_ntcreatex_brlocked(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
756 union smb_open io, io1;
758 struct smb_lock_entry lock[1];
759 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
763 /* reasonable default parameters */
764 io.generic.level = RAW_OPEN_NTCREATEX;
765 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
766 io.ntcreatex.in.root_fid = 0;
767 io.ntcreatex.in.access_mask = 0x2019f;
768 io.ntcreatex.in.alloc_size = 0;
769 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
770 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
771 NTCREATEX_SHARE_ACCESS_WRITE;
772 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
773 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
774 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
775 io.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC |
776 NTCREATEX_SECURITY_ALL;
777 io.ntcreatex.in.fname = fname;
779 status = smb_raw_open(cli->tree, mem_ctx, &io);
780 CHECK_STATUS(status, NT_STATUS_OK);
782 io2.lockx.level = RAW_LOCK_LOCKX;
783 io2.lockx.in.fnum = io.ntcreatex.out.fnum;
784 io2.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
785 io2.lockx.in.timeout = 0;
786 io2.lockx.in.ulock_cnt = 0;
787 io2.lockx.in.lock_cnt = 1;
788 lock[0].pid = cli->session->pid;
791 io2.lockx.in.locks = &lock[0];
792 status = smb_raw_lock(cli->tree, &io2);
793 CHECK_STATUS(status, NT_STATUS_OK);
795 io1.generic.level = RAW_OPEN_NTCREATEX;
796 io1.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
797 io1.ntcreatex.in.root_fid = 0;
798 io1.ntcreatex.in.access_mask = 0x20196;
799 io1.ntcreatex.in.alloc_size = 0;
800 io1.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
801 io1.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
802 NTCREATEX_SHARE_ACCESS_WRITE;
803 io1.ntcreatex.in.open_disposition = NTCREATEX_DISP_OVERWRITE_IF;
804 io1.ntcreatex.in.create_options = 0;
805 io1.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
806 io1.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC |
807 NTCREATEX_SECURITY_ALL;
808 io1.ntcreatex.in.fname = fname;
810 status = smb_raw_open(cli->tree, mem_ctx, &io1);
811 CHECK_STATUS(status, NT_STATUS_OK);
814 smbcli_close(cli->tree, io.ntcreatex.out.fnum);
815 smbcli_close(cli->tree, io1.ntcreatex.out.fnum);
816 smbcli_unlink(cli->tree, fname);
823 static BOOL test_mknew(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
826 const char *fname = BASEDIR "\\torture_mknew.txt";
830 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
831 union smb_fileinfo finfo;
833 printf("Checking RAW_OPEN_MKNEW\n");
835 io.mknew.level = RAW_OPEN_MKNEW;
836 io.mknew.in.attrib = 0;
837 io.mknew.in.write_time = 0;
838 io.mknew.in.fname = fname;
839 status = smb_raw_open(cli->tree, mem_ctx, &io);
840 CHECK_STATUS(status, NT_STATUS_OK);
841 fnum = io.mknew.out.fnum;
843 status = smb_raw_open(cli->tree, mem_ctx, &io);
844 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
846 smbcli_close(cli->tree, fnum);
847 smbcli_unlink(cli->tree, fname);
849 /* make sure write_time works */
850 io.mknew.in.write_time = basetime;
851 status = smb_raw_open(cli->tree, mem_ctx, &io);
852 CHECK_STATUS(status, NT_STATUS_OK);
853 fnum = io.mknew.out.fnum;
854 CHECK_TIME(basetime, write_time);
856 smbcli_close(cli->tree, fnum);
857 smbcli_unlink(cli->tree, fname);
859 /* make sure file_attrs works */
860 io.mknew.in.attrib = FILE_ATTRIBUTE_HIDDEN;
861 status = smb_raw_open(cli->tree, mem_ctx, &io);
862 CHECK_STATUS(status, NT_STATUS_OK);
863 fnum = io.mknew.out.fnum;
864 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE,
865 attrib & ~FILE_ATTRIBUTE_NONINDEXED);
868 smbcli_close(cli->tree, fnum);
869 smbcli_unlink(cli->tree, fname);
878 static BOOL test_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
881 const char *fname = BASEDIR "\\torture_create.txt";
885 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
886 union smb_fileinfo finfo;
888 printf("Checking RAW_OPEN_CREATE\n");
890 io.create.level = RAW_OPEN_CREATE;
891 io.create.in.attrib = 0;
892 io.create.in.write_time = 0;
893 io.create.in.fname = fname;
894 status = smb_raw_open(cli->tree, mem_ctx, &io);
895 CHECK_STATUS(status, NT_STATUS_OK);
896 fnum = io.create.out.fnum;
898 status = smb_raw_open(cli->tree, mem_ctx, &io);
899 CHECK_STATUS(status, NT_STATUS_OK);
901 smbcli_close(cli->tree, io.create.out.fnum);
902 smbcli_close(cli->tree, fnum);
903 smbcli_unlink(cli->tree, fname);
905 /* make sure write_time works */
906 io.create.in.write_time = basetime;
907 status = smb_raw_open(cli->tree, mem_ctx, &io);
908 CHECK_STATUS(status, NT_STATUS_OK);
909 fnum = io.create.out.fnum;
910 CHECK_TIME(basetime, write_time);
912 smbcli_close(cli->tree, fnum);
913 smbcli_unlink(cli->tree, fname);
915 /* make sure file_attrs works */
916 io.create.in.attrib = FILE_ATTRIBUTE_HIDDEN;
917 status = smb_raw_open(cli->tree, mem_ctx, &io);
918 CHECK_STATUS(status, NT_STATUS_OK);
919 fnum = io.create.out.fnum;
920 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE,
921 attrib & ~FILE_ATTRIBUTE_NONINDEXED);
924 smbcli_close(cli->tree, fnum);
925 smbcli_unlink(cli->tree, fname);
934 static BOOL test_ctemp(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
940 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
941 union smb_fileinfo finfo;
942 const char *name, *fname = NULL;
944 printf("Checking RAW_OPEN_CTEMP\n");
946 io.ctemp.level = RAW_OPEN_CTEMP;
947 io.ctemp.in.attrib = FILE_ATTRIBUTE_HIDDEN;
948 io.ctemp.in.write_time = basetime;
949 io.ctemp.in.directory = BASEDIR;
950 status = smb_raw_open(cli->tree, mem_ctx, &io);
951 CHECK_STATUS(status, NT_STATUS_OK);
952 fnum = io.ctemp.out.fnum;
954 name = io.ctemp.out.name;
956 finfo.generic.level = RAW_FILEINFO_NAME_INFO;
957 finfo.generic.in.fnum = fnum;
958 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
959 CHECK_STATUS(status, NT_STATUS_OK);
961 fname = finfo.name_info.out.fname.s;
962 d_printf("ctemp name=%s real name=%s\n", name, fname);
964 CHECK_TIME(basetime, write_time);
967 smbcli_close(cli->tree, fnum);
969 smbcli_unlink(cli->tree, fname);
975 /* basic testing of all RAW_OPEN_* calls
977 BOOL torture_raw_open(void)
979 struct smbcli_state *cli;
983 if (!torture_open_connection(&cli)) {
987 mem_ctx = talloc_init("torture_raw_open");
989 if (smbcli_deltree(cli->tree, BASEDIR) == -1) {
990 printf("Failed to clean " BASEDIR "\n");
993 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
994 printf("Failed to create " BASEDIR " - %s\n", smbcli_errstr(cli->tree));
998 if (!test_ntcreatex_brlocked(cli, mem_ctx)) {
1002 if (!test_open(cli, mem_ctx)) {
1006 if (!test_openx(cli, mem_ctx)) {
1010 if (!test_ntcreatex(cli, mem_ctx)) {
1014 if (!test_t2open(cli, mem_ctx)) {
1018 if (!test_mknew(cli, mem_ctx)) {
1022 if (!test_create(cli, mem_ctx)) {
1026 if (!test_ctemp(cli, mem_ctx)) {
1030 smb_raw_exit(cli->session);
1031 smbcli_deltree(cli->tree, BASEDIR);
1033 torture_close_connection(cli);
1034 talloc_destroy(mem_ctx);