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 - should be 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;
273 NTSTATUS correct_status;
275 { OPENX_OPEN_FUNC_OPEN, True, NT_STATUS_OK },
276 { OPENX_OPEN_FUNC_OPEN, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
277 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OK },
278 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
279 { OPENX_OPEN_FUNC_FAIL, True, NT_STATUS_INVALID_LOCK_SEQUENCE },
280 { OPENX_OPEN_FUNC_FAIL, False, NT_STATUS_INVALID_LOCK_SEQUENCE },
281 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OBJECT_NAME_COLLISION },
282 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
283 { OPENX_OPEN_FUNC_TRUNC, True, NT_STATUS_OK },
284 { OPENX_OPEN_FUNC_TRUNC, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
285 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OK },
286 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
289 printf("Checking RAW_OPEN_OPENX\n");
290 smbcli_unlink(cli->tree, fname);
292 io.openx.level = RAW_OPEN_OPENX;
293 io.openx.in.fname = fname;
294 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
295 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
296 io.openx.in.search_attrs = 0;
297 io.openx.in.file_attrs = 0;
298 io.openx.in.write_time = 0;
299 io.openx.in.size = 1024*1024;
300 io.openx.in.timeout = 0;
302 /* check all combinations of open_func */
303 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
304 if (open_funcs[i].with_file) {
305 fnum = create_complex_file(cli, mem_ctx, fname);
307 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
311 smbcli_close(cli->tree, fnum);
313 io.openx.in.open_func = open_funcs[i].open_func;
314 status = smb_raw_open(cli->tree, mem_ctx, &io);
315 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
316 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n",
317 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
318 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_func);
321 if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
322 smbcli_close(cli->tree, io.openx.out.fnum);
323 smbcli_unlink(cli->tree, fname);
327 /* check the basic return fields */
328 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
329 status = smb_raw_open(cli->tree, mem_ctx, &io);
330 CHECK_STATUS(status, NT_STATUS_OK);
331 fnum = io.openx.out.fnum;
333 CHECK_ALL_INFO(io.openx.out.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 CHECK_VAL(io.openx.out.size, 1024*1024);
341 CHECK_ALL_INFO(io.openx.in.size, size);
342 smbcli_close(cli->tree, fnum);
343 smbcli_unlink(cli->tree, fname);
345 /* check the fields when the file already existed */
346 fnum2 = create_complex_file(cli, mem_ctx, fname);
351 smbcli_close(cli->tree, fnum2);
353 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
354 status = smb_raw_open(cli->tree, mem_ctx, &io);
355 CHECK_STATUS(status, NT_STATUS_OK);
356 fnum = io.openx.out.fnum;
358 CHECK_ALL_INFO(io.openx.out.size, size);
359 CHECK_TIME(io.openx.out.write_time, write_time);
360 CHECK_VAL(io.openx.out.action, OPENX_ACTION_EXISTED);
361 CHECK_VAL(io.openx.out.unknown, 0);
362 CHECK_ALL_INFO(io.openx.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
363 smbcli_close(cli->tree, fnum);
365 /* now check the search attrib for hidden files - win2003 ignores this? */
366 SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN);
367 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib);
369 io.openx.in.search_attrs = FILE_ATTRIBUTE_HIDDEN;
370 status = smb_raw_open(cli->tree, mem_ctx, &io);
371 CHECK_STATUS(status, NT_STATUS_OK);
372 smbcli_close(cli->tree, io.openx.out.fnum);
374 io.openx.in.search_attrs = 0;
375 status = smb_raw_open(cli->tree, mem_ctx, &io);
376 CHECK_STATUS(status, NT_STATUS_OK);
377 smbcli_close(cli->tree, io.openx.out.fnum);
379 SET_ATTRIB(FILE_ATTRIBUTE_NORMAL);
380 smbcli_unlink(cli->tree, fname);
382 /* and check attrib on create */
383 io.openx.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE;
384 io.openx.in.search_attrs = 0;
385 io.openx.in.file_attrs = FILE_ATTRIBUTE_SYSTEM;
386 status = smb_raw_open(cli->tree, mem_ctx, &io);
387 CHECK_STATUS(status, NT_STATUS_OK);
388 CHECK_ALL_INFO(FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE,
389 attrib & ~FILE_ATTRIBUTE_NONINDEXED);
390 smbcli_close(cli->tree, io.openx.out.fnum);
391 smbcli_unlink(cli->tree, fname);
393 /* check timeout on create - win2003 ignores the timeout! */
394 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
395 io.openx.in.file_attrs = 0;
396 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL;
397 status = smb_raw_open(cli->tree, mem_ctx, &io);
398 CHECK_STATUS(status, NT_STATUS_OK);
399 fnum = io.openx.out.fnum;
401 io.openx.in.timeout = 20000;
402 tv = timeval_current();
403 io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_NONE;
404 status = smb_raw_open(cli->tree, mem_ctx, &io);
405 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
406 if (timeval_elapsed(&tv) > 3.0) {
407 printf("(%s) Incorrect timing in openx with timeout - waited %.2f seconds\n",
408 __location__, timeval_elapsed(&tv));
411 smbcli_close(cli->tree, fnum);
412 smbcli_unlink(cli->tree, fname);
414 /* now this is a really weird one - open for execute implies create?! */
415 io.openx.in.fname = fname;
416 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
417 io.openx.in.open_mode = OPENX_MODE_ACCESS_EXEC | OPENX_MODE_DENY_NONE;
418 io.openx.in.search_attrs = 0;
419 io.openx.in.open_func = OPENX_OPEN_FUNC_FAIL;
420 io.openx.in.file_attrs = 0;
421 io.openx.in.write_time = 0;
422 io.openx.in.size = 0;
423 io.openx.in.timeout = 0;
424 status = smb_raw_open(cli->tree, mem_ctx, &io);
425 CHECK_STATUS(status, NT_STATUS_OK);
426 smbcli_close(cli->tree, io.openx.out.fnum);
428 /* check the extended return flag */
429 io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO | OPENX_FLAGS_EXTENDED_RETURN;
430 io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
431 status = smb_raw_open(cli->tree, mem_ctx, &io);
432 CHECK_STATUS(status, NT_STATUS_OK);
433 CHECK_VAL(io.openx.out.access_mask, STD_RIGHT_ALL_ACCESS);
434 smbcli_close(cli->tree, io.openx.out.fnum);
437 smbcli_close(cli->tree, fnum);
438 smbcli_unlink(cli->tree, fname);
447 I can't work out how to get win2003 to accept a create file via TRANS2_OPEN, which
448 is why you see all the ACCESS_DENIED results below. When we finally work this out then this
449 test will make more sense
451 static BOOL test_t2open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
454 union smb_fileinfo finfo;
455 const char *fname1 = BASEDIR "\\torture_t2open_yes.txt";
456 const char *fname2 = BASEDIR "\\torture_t2open_no.txt";
457 const char *fname = BASEDIR "\\torture_t2open_3.txt";
465 NTSTATUS correct_status;
467 { OPENX_OPEN_FUNC_OPEN, True, NT_STATUS_OK },
468 { OPENX_OPEN_FUNC_OPEN, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
469 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OK },
470 { OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_ACCESS_DENIED },
471 { OPENX_OPEN_FUNC_FAIL, True, NT_STATUS_OBJECT_NAME_COLLISION },
472 { OPENX_OPEN_FUNC_FAIL, False, NT_STATUS_ACCESS_DENIED },
473 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_OBJECT_NAME_COLLISION },
474 { OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_ACCESS_DENIED },
475 { OPENX_OPEN_FUNC_TRUNC, True, NT_STATUS_ACCESS_DENIED },
476 { OPENX_OPEN_FUNC_TRUNC, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
477 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, True, NT_STATUS_ACCESS_DENIED },
478 { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_ACCESS_DENIED },
481 fnum = create_complex_file(cli, mem_ctx, fname1);
483 d_printf("Failed to create file %s - %s\n", fname1, smbcli_errstr(cli->tree));
487 smbcli_close(cli->tree, fnum);
489 printf("Checking RAW_OPEN_T2OPEN\n");
491 io.t2open.level = RAW_OPEN_T2OPEN;
492 io.t2open.in.flags = OPENX_FLAGS_ADDITIONAL_INFO |
493 OPENX_FLAGS_EA_LEN | OPENX_FLAGS_EXTENDED_RETURN;
494 io.t2open.in.open_mode = OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR;
495 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
496 io.t2open.in.file_attrs = 0;
497 io.t2open.in.write_time = 0;
498 io.t2open.in.size = 0;
499 io.t2open.in.timeout = 0;
501 io.t2open.in.eas = talloc(mem_ctx, sizeof(io.t2open.in.eas[0]));
502 io.t2open.in.num_eas = 1;
503 io.t2open.in.eas[0].flags = 0;
504 io.t2open.in.eas[0].name.s = "EAONE";
505 io.t2open.in.eas[0].value = data_blob_talloc(mem_ctx, "1", 1);
507 /* check all combinations of open_func */
508 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
509 if (open_funcs[i].with_file) {
510 io.t2open.in.fname = fname1;
512 io.t2open.in.fname = fname2;
514 io.t2open.in.open_func = open_funcs[i].open_func;
515 status = smb_raw_open(cli->tree, mem_ctx, &io);
516 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
517 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n",
518 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
519 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_func);
522 if (NT_STATUS_IS_OK(status)) {
523 smbcli_close(cli->tree, io.t2open.out.fnum);
527 smbcli_unlink(cli->tree, fname1);
529 /* check the basic return fields */
530 fnum = create_complex_file(cli, mem_ctx, fname);
531 smbcli_close(cli->tree, fnum);
532 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
533 io.t2open.in.fname = fname;
534 status = smb_raw_open(cli->tree, mem_ctx, &io);
535 CHECK_STATUS(status, NT_STATUS_OK);
536 fnum = io.t2open.out.fnum;
538 CHECK_ALL_INFO(io.t2open.out.size, size);
539 CHECK_VAL(io.t2open.out.write_time, 0);
540 CHECK_ALL_INFO(io.t2open.out.attrib, attrib & ~FILE_ATTRIBUTE_NONINDEXED);
541 CHECK_VAL(io.t2open.out.access, OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR);
542 CHECK_VAL(io.t2open.out.ftype, 0);
543 CHECK_VAL(io.t2open.out.devstate, 0);
544 CHECK_VAL(io.t2open.out.action, OPENX_ACTION_EXISTED);
545 smbcli_close(cli->tree, fnum);
547 /* now check the search attrib for hidden files - win2003 ignores this? */
548 SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN);
549 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib);
551 status = smb_raw_open(cli->tree, mem_ctx, &io);
552 CHECK_STATUS(status, NT_STATUS_OK);
553 smbcli_close(cli->tree, io.t2open.out.fnum);
555 status = smb_raw_open(cli->tree, mem_ctx, &io);
556 CHECK_STATUS(status, NT_STATUS_OK);
557 smbcli_close(cli->tree, io.t2open.out.fnum);
559 SET_ATTRIB(FILE_ATTRIBUTE_NORMAL);
560 smbcli_unlink(cli->tree, fname);
562 /* and check attrib on create */
563 io.t2open.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE;
564 io.t2open.in.file_attrs = FILE_ATTRIBUTE_SYSTEM;
565 status = smb_raw_open(cli->tree, mem_ctx, &io);
566 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
568 /* check timeout on create - win2003 ignores the timeout! */
569 io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
570 io.t2open.in.file_attrs = 0;
571 io.t2open.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL;
572 status = smb_raw_open(cli->tree, mem_ctx, &io);
573 CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
576 smbcli_close(cli->tree, fnum);
577 smbcli_unlink(cli->tree, fname);
584 test RAW_OPEN_NTCREATEX
586 static BOOL test_ntcreatex(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
589 union smb_fileinfo finfo;
590 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
591 const char *dname = BASEDIR "\\torture_ntcreatex.dir";
599 NTSTATUS correct_status;
601 { NTCREATEX_DISP_SUPERSEDE, True, NT_STATUS_OK },
602 { NTCREATEX_DISP_SUPERSEDE, False, NT_STATUS_OK },
603 { NTCREATEX_DISP_OPEN, True, NT_STATUS_OK },
604 { NTCREATEX_DISP_OPEN, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
605 { NTCREATEX_DISP_CREATE, True, NT_STATUS_OBJECT_NAME_COLLISION },
606 { NTCREATEX_DISP_CREATE, False, NT_STATUS_OK },
607 { NTCREATEX_DISP_OPEN_IF, True, NT_STATUS_OK },
608 { NTCREATEX_DISP_OPEN_IF, False, NT_STATUS_OK },
609 { NTCREATEX_DISP_OVERWRITE, True, NT_STATUS_OK },
610 { NTCREATEX_DISP_OVERWRITE, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
611 { NTCREATEX_DISP_OVERWRITE_IF, True, NT_STATUS_OK },
612 { NTCREATEX_DISP_OVERWRITE_IF, False, NT_STATUS_OK },
613 { 6, True, NT_STATUS_INVALID_PARAMETER },
614 { 6, False, NT_STATUS_INVALID_PARAMETER },
617 printf("Checking RAW_OPEN_NTCREATEX\n");
619 /* reasonable default parameters */
620 io.generic.level = RAW_OPEN_NTCREATEX;
621 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
622 io.ntcreatex.in.root_fid = 0;
623 io.ntcreatex.in.access_mask = GENERIC_RIGHTS_FILE_ALL_ACCESS;
624 io.ntcreatex.in.alloc_size = 1024*1024;
625 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
626 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
627 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
628 io.ntcreatex.in.create_options = 0;
629 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
630 io.ntcreatex.in.security_flags = 0;
631 io.ntcreatex.in.fname = fname;
633 /* test the open disposition */
634 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
635 if (open_funcs[i].with_file) {
636 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE);
638 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
642 smbcli_close(cli->tree, fnum);
644 io.ntcreatex.in.open_disposition = open_funcs[i].open_disp;
645 status = smb_raw_open(cli->tree, mem_ctx, &io);
646 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
647 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_disp=%d)\n",
648 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
649 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_disp);
652 if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
653 smbcli_close(cli->tree, io.ntcreatex.out.fnum);
654 smbcli_unlink(cli->tree, fname);
658 /* basic field testing */
659 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
661 status = smb_raw_open(cli->tree, mem_ctx, &io);
662 CHECK_STATUS(status, NT_STATUS_OK);
663 fnum = io.ntcreatex.out.fnum;
665 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
666 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
667 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
668 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
669 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
670 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
671 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
672 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
673 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
674 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
675 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
677 /* check fields when the file already existed */
678 smbcli_close(cli->tree, fnum);
679 smbcli_unlink(cli->tree, fname);
680 fnum = create_complex_file(cli, mem_ctx, fname);
685 smbcli_close(cli->tree, fnum);
687 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
688 status = smb_raw_open(cli->tree, mem_ctx, &io);
689 CHECK_STATUS(status, NT_STATUS_OK);
690 fnum = io.ntcreatex.out.fnum;
692 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
693 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
694 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
695 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
696 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
697 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
698 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
699 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
700 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
701 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
702 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
703 smbcli_close(cli->tree, fnum);
704 smbcli_unlink(cli->tree, fname);
707 /* create a directory */
708 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
709 io.ntcreatex.in.access_mask = GENERIC_RIGHTS_FILE_ALL_ACCESS;
710 io.ntcreatex.in.alloc_size = 0;
711 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
712 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
713 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
714 io.ntcreatex.in.create_options = 0;
715 io.ntcreatex.in.fname = dname;
718 smbcli_rmdir(cli->tree, fname);
719 smbcli_unlink(cli->tree, fname);
721 io.ntcreatex.in.access_mask = SEC_RIGHT_MAXIMUM_ALLOWED;
722 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
723 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
724 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
725 status = smb_raw_open(cli->tree, mem_ctx, &io);
726 CHECK_STATUS(status, NT_STATUS_OK);
727 fnum = io.ntcreatex.out.fnum;
729 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
730 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
731 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
732 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
733 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
734 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
735 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
736 CHECK_VAL(io.ntcreatex.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED,
737 FILE_ATTRIBUTE_DIRECTORY);
738 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
739 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
740 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
741 CHECK_VAL(io.ntcreatex.out.is_directory, 1);
742 CHECK_VAL(io.ntcreatex.out.size, 0);
743 CHECK_VAL(io.ntcreatex.out.alloc_size, 0);
744 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
745 smbcli_unlink(cli->tree, fname);
749 smbcli_close(cli->tree, fnum);
750 smbcli_unlink(cli->tree, fname);
757 test RAW_OPEN_NTTRANS_CREATE
759 static BOOL test_nttrans_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
762 union smb_fileinfo finfo;
763 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
764 const char *dname = BASEDIR "\\torture_ntcreatex.dir";
772 NTSTATUS correct_status;
774 { NTCREATEX_DISP_SUPERSEDE, True, NT_STATUS_OK },
775 { NTCREATEX_DISP_SUPERSEDE, False, NT_STATUS_OK },
776 { NTCREATEX_DISP_OPEN, True, NT_STATUS_OK },
777 { NTCREATEX_DISP_OPEN, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
778 { NTCREATEX_DISP_CREATE, True, NT_STATUS_OBJECT_NAME_COLLISION },
779 { NTCREATEX_DISP_CREATE, False, NT_STATUS_OK },
780 { NTCREATEX_DISP_OPEN_IF, True, NT_STATUS_OK },
781 { NTCREATEX_DISP_OPEN_IF, False, NT_STATUS_OK },
782 { NTCREATEX_DISP_OVERWRITE, True, NT_STATUS_OK },
783 { NTCREATEX_DISP_OVERWRITE, False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
784 { NTCREATEX_DISP_OVERWRITE_IF, True, NT_STATUS_OK },
785 { NTCREATEX_DISP_OVERWRITE_IF, False, NT_STATUS_OK },
786 { 6, True, NT_STATUS_INVALID_PARAMETER },
787 { 6, False, NT_STATUS_INVALID_PARAMETER },
790 printf("Checking RAW_OPEN_NTTRANS_CREATE\n");
792 /* reasonable default parameters */
793 io.generic.level = RAW_OPEN_NTTRANS_CREATE;
794 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
795 io.ntcreatex.in.root_fid = 0;
796 io.ntcreatex.in.access_mask = GENERIC_RIGHTS_FILE_ALL_ACCESS;
797 io.ntcreatex.in.alloc_size = 1024*1024;
798 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
799 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
800 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
801 io.ntcreatex.in.create_options = 0;
802 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
803 io.ntcreatex.in.security_flags = 0;
804 io.ntcreatex.in.fname = fname;
805 io.ntcreatex.in.sec_desc = NULL;
806 io.ntcreatex.in.ea_list = NULL;
808 /* test the open disposition */
809 for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
810 if (open_funcs[i].with_file) {
811 fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE);
813 d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
817 smbcli_close(cli->tree, fnum);
819 io.ntcreatex.in.open_disposition = open_funcs[i].open_disp;
820 status = smb_raw_open(cli->tree, mem_ctx, &io);
821 if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
822 printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_disp=%d)\n",
823 __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
824 i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_disp);
827 if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
828 smbcli_close(cli->tree, io.ntcreatex.out.fnum);
829 smbcli_unlink(cli->tree, fname);
833 /* basic field testing */
834 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
836 status = smb_raw_open(cli->tree, mem_ctx, &io);
837 CHECK_STATUS(status, NT_STATUS_OK);
838 fnum = io.ntcreatex.out.fnum;
840 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
841 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
842 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
843 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
844 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
845 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
846 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
847 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
848 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
849 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
850 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
852 /* check fields when the file already existed */
853 smbcli_close(cli->tree, fnum);
854 smbcli_unlink(cli->tree, fname);
855 fnum = create_complex_file(cli, mem_ctx, fname);
860 smbcli_close(cli->tree, fnum);
862 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
863 status = smb_raw_open(cli->tree, mem_ctx, &io);
864 CHECK_STATUS(status, NT_STATUS_OK);
865 fnum = io.ntcreatex.out.fnum;
867 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
868 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
869 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
870 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
871 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
872 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
873 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
874 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
875 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
876 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
877 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
878 smbcli_close(cli->tree, fnum);
879 smbcli_unlink(cli->tree, fname);
882 /* create a directory */
883 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
884 io.ntcreatex.in.access_mask = GENERIC_RIGHTS_FILE_ALL_ACCESS;
885 io.ntcreatex.in.alloc_size = 0;
886 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
887 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
888 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
889 io.ntcreatex.in.create_options = 0;
890 io.ntcreatex.in.fname = dname;
893 smbcli_rmdir(cli->tree, fname);
894 smbcli_unlink(cli->tree, fname);
896 io.ntcreatex.in.access_mask = SEC_RIGHT_MAXIMUM_ALLOWED;
897 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
898 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
899 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
900 status = smb_raw_open(cli->tree, mem_ctx, &io);
901 CHECK_STATUS(status, NT_STATUS_OK);
902 fnum = io.ntcreatex.out.fnum;
904 CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
905 CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
906 CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
907 CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
908 CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
909 CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
910 CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
911 CHECK_VAL(io.ntcreatex.out.attrib & ~FILE_ATTRIBUTE_NONINDEXED,
912 FILE_ATTRIBUTE_DIRECTORY);
913 CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
914 CHECK_ALL_INFO(io.ntcreatex.out.size, size);
915 CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
916 CHECK_VAL(io.ntcreatex.out.is_directory, 1);
917 CHECK_VAL(io.ntcreatex.out.size, 0);
918 CHECK_VAL(io.ntcreatex.out.alloc_size, 0);
919 CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
920 smbcli_unlink(cli->tree, fname);
924 smbcli_close(cli->tree, fnum);
925 smbcli_unlink(cli->tree, fname);
931 test RAW_OPEN_NTCREATEX with an already opened and byte range locked file
933 I've got an application that does a similar sequence of ntcreate&x,
934 locking&x and another ntcreate&x with
935 open_disposition==NTCREATEX_DISP_OVERWRITE_IF. Windows 2003 allows the
938 static BOOL test_ntcreatex_brlocked(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
940 union smb_open io, io1;
942 struct smb_lock_entry lock[1];
943 const char *fname = BASEDIR "\\torture_ntcreatex.txt";
947 /* reasonable default parameters */
948 io.generic.level = RAW_OPEN_NTCREATEX;
949 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
950 io.ntcreatex.in.root_fid = 0;
951 io.ntcreatex.in.access_mask = 0x2019f;
952 io.ntcreatex.in.alloc_size = 0;
953 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
954 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
955 NTCREATEX_SHARE_ACCESS_WRITE;
956 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
957 io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
958 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
959 io.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC |
960 NTCREATEX_SECURITY_ALL;
961 io.ntcreatex.in.fname = fname;
963 status = smb_raw_open(cli->tree, mem_ctx, &io);
964 CHECK_STATUS(status, NT_STATUS_OK);
966 io2.lockx.level = RAW_LOCK_LOCKX;
967 io2.lockx.in.fnum = io.ntcreatex.out.fnum;
968 io2.lockx.in.mode = LOCKING_ANDX_LARGE_FILES;
969 io2.lockx.in.timeout = 0;
970 io2.lockx.in.ulock_cnt = 0;
971 io2.lockx.in.lock_cnt = 1;
972 lock[0].pid = cli->session->pid;
975 io2.lockx.in.locks = &lock[0];
976 status = smb_raw_lock(cli->tree, &io2);
977 CHECK_STATUS(status, NT_STATUS_OK);
979 io1.generic.level = RAW_OPEN_NTCREATEX;
980 io1.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
981 io1.ntcreatex.in.root_fid = 0;
982 io1.ntcreatex.in.access_mask = 0x20196;
983 io1.ntcreatex.in.alloc_size = 0;
984 io1.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
985 io1.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
986 NTCREATEX_SHARE_ACCESS_WRITE;
987 io1.ntcreatex.in.open_disposition = NTCREATEX_DISP_OVERWRITE_IF;
988 io1.ntcreatex.in.create_options = 0;
989 io1.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
990 io1.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC |
991 NTCREATEX_SECURITY_ALL;
992 io1.ntcreatex.in.fname = fname;
994 status = smb_raw_open(cli->tree, mem_ctx, &io1);
995 CHECK_STATUS(status, NT_STATUS_OK);
998 smbcli_close(cli->tree, io.ntcreatex.out.fnum);
999 smbcli_close(cli->tree, io1.ntcreatex.out.fnum);
1000 smbcli_unlink(cli->tree, fname);
1007 static BOOL test_mknew(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1010 const char *fname = BASEDIR "\\torture_mknew.txt";
1014 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1015 union smb_fileinfo finfo;
1017 printf("Checking RAW_OPEN_MKNEW\n");
1019 io.mknew.level = RAW_OPEN_MKNEW;
1020 io.mknew.in.attrib = 0;
1021 io.mknew.in.write_time = 0;
1022 io.mknew.in.fname = fname;
1023 status = smb_raw_open(cli->tree, mem_ctx, &io);
1024 CHECK_STATUS(status, NT_STATUS_OK);
1025 fnum = io.mknew.out.fnum;
1027 status = smb_raw_open(cli->tree, mem_ctx, &io);
1028 CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
1030 smbcli_close(cli->tree, fnum);
1031 smbcli_unlink(cli->tree, fname);
1033 /* make sure write_time works */
1034 io.mknew.in.write_time = basetime;
1035 status = smb_raw_open(cli->tree, mem_ctx, &io);
1036 CHECK_STATUS(status, NT_STATUS_OK);
1037 fnum = io.mknew.out.fnum;
1038 CHECK_TIME(basetime, write_time);
1040 smbcli_close(cli->tree, fnum);
1041 smbcli_unlink(cli->tree, fname);
1043 /* make sure file_attrs works */
1044 io.mknew.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1045 status = smb_raw_open(cli->tree, mem_ctx, &io);
1046 CHECK_STATUS(status, NT_STATUS_OK);
1047 fnum = io.mknew.out.fnum;
1048 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE,
1049 attrib & ~FILE_ATTRIBUTE_NONINDEXED);
1052 smbcli_close(cli->tree, fnum);
1053 smbcli_unlink(cli->tree, fname);
1060 test RAW_OPEN_CREATE
1062 static BOOL test_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1065 const char *fname = BASEDIR "\\torture_create.txt";
1069 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1070 union smb_fileinfo finfo;
1072 printf("Checking RAW_OPEN_CREATE\n");
1074 io.create.level = RAW_OPEN_CREATE;
1075 io.create.in.attrib = 0;
1076 io.create.in.write_time = 0;
1077 io.create.in.fname = fname;
1078 status = smb_raw_open(cli->tree, mem_ctx, &io);
1079 CHECK_STATUS(status, NT_STATUS_OK);
1080 fnum = io.create.out.fnum;
1082 status = smb_raw_open(cli->tree, mem_ctx, &io);
1083 CHECK_STATUS(status, NT_STATUS_OK);
1085 smbcli_close(cli->tree, io.create.out.fnum);
1086 smbcli_close(cli->tree, fnum);
1087 smbcli_unlink(cli->tree, fname);
1089 /* make sure write_time works */
1090 io.create.in.write_time = basetime;
1091 status = smb_raw_open(cli->tree, mem_ctx, &io);
1092 CHECK_STATUS(status, NT_STATUS_OK);
1093 fnum = io.create.out.fnum;
1094 CHECK_TIME(basetime, write_time);
1096 smbcli_close(cli->tree, fnum);
1097 smbcli_unlink(cli->tree, fname);
1099 /* make sure file_attrs works */
1100 io.create.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1101 status = smb_raw_open(cli->tree, mem_ctx, &io);
1102 CHECK_STATUS(status, NT_STATUS_OK);
1103 fnum = io.create.out.fnum;
1104 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE,
1105 attrib & ~FILE_ATTRIBUTE_NONINDEXED);
1108 smbcli_close(cli->tree, fnum);
1109 smbcli_unlink(cli->tree, fname);
1118 static BOOL test_ctemp(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
1124 time_t basetime = (time(NULL) + 3600*24*3) & ~1;
1125 union smb_fileinfo finfo;
1126 const char *name, *fname = NULL;
1128 printf("Checking RAW_OPEN_CTEMP\n");
1130 io.ctemp.level = RAW_OPEN_CTEMP;
1131 io.ctemp.in.attrib = FILE_ATTRIBUTE_HIDDEN;
1132 io.ctemp.in.write_time = basetime;
1133 io.ctemp.in.directory = BASEDIR;
1134 status = smb_raw_open(cli->tree, mem_ctx, &io);
1135 CHECK_STATUS(status, NT_STATUS_OK);
1136 fnum = io.ctemp.out.fnum;
1138 name = io.ctemp.out.name;
1140 finfo.generic.level = RAW_FILEINFO_NAME_INFO;
1141 finfo.generic.in.fnum = fnum;
1142 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
1143 CHECK_STATUS(status, NT_STATUS_OK);
1145 fname = finfo.name_info.out.fname.s;
1146 d_printf("ctemp name=%s real name=%s\n", name, fname);
1149 smbcli_close(cli->tree, fnum);
1151 smbcli_unlink(cli->tree, fname);
1157 /* basic testing of all RAW_OPEN_* calls
1159 BOOL torture_raw_open(void)
1161 struct smbcli_state *cli;
1163 TALLOC_CTX *mem_ctx;
1165 if (!torture_open_connection(&cli)) {
1169 mem_ctx = talloc_init("torture_raw_open");
1171 if (!torture_setup_dir(cli, BASEDIR)) {
1175 ret &= test_ntcreatex_brlocked(cli, mem_ctx);
1176 ret &= test_open(cli, mem_ctx);
1177 ret &= test_openx(cli, mem_ctx);
1178 ret &= test_ntcreatex(cli, mem_ctx);
1179 ret &= test_nttrans_create(cli, mem_ctx);
1180 ret &= test_t2open(cli, mem_ctx);
1181 ret &= test_mknew(cli, mem_ctx);
1182 ret &= test_create(cli, mem_ctx);
1183 ret &= test_ctemp(cli, mem_ctx);
1185 smb_raw_exit(cli->session);
1186 smbcli_deltree(cli->tree, BASEDIR);
1188 torture_close_connection(cli);
1189 talloc_destroy(mem_ctx);