2 Unix SMB/CIFS implementation.
3 RAW_OPEN_* individual test suite
4 Copyright (C) Andrew Tridgell 2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "libcli/raw/libcliraw.h"
22 #include "system/time.h"
23 #include "system/filesys.h"
24 #include "lib/events/events.h"
25 #include "libcli/libcli.h"
26 #include "torture/util.h"
27 #include "torture/raw/proto.h"
29 /* enum for whether reads/writes are possible on a file */
30 enum rdwr_mode
{RDWR_NONE
, RDWR_RDONLY
, RDWR_WRONLY
, RDWR_RDWR
};
32 #define BASEDIR "\\rawopen"
35 check if a open file can be read/written
37 static enum rdwr_mode
check_rdwr(struct smbcli_tree
*tree
, int fnum
)
40 bool can_read
= (smbcli_read(tree
, fnum
, &c
, 0, 1) == 1);
41 bool can_write
= (smbcli_write(tree
, fnum
, 0, &c
, 0, 1) == 1);
42 if ( can_read
&& can_write
) return RDWR_RDWR
;
43 if ( can_read
&& !can_write
) return RDWR_RDONLY
;
44 if (!can_read
&& can_write
) return RDWR_WRONLY
;
49 describe a RDWR mode as a string
51 static const char *rdwr_string(enum rdwr_mode m
)
54 case RDWR_NONE
: return "NONE";
55 case RDWR_RDONLY
: return "RDONLY";
56 case RDWR_WRONLY
: return "WRONLY";
57 case RDWR_RDWR
: return "RDWR";
62 #define CHECK_STATUS(status, correct) do { \
63 if (!NT_STATUS_EQUAL(status, correct)) { \
64 torture_result(tctx, TORTURE_FAIL, \
65 "(%s) Incorrect status %s - should be %s\n", \
66 __location__, nt_errstr(status), nt_errstr(correct)); \
71 #define CREATE_FILE do { \
72 fnum = create_complex_file(cli, tctx, fname); \
74 torture_result(tctx, TORTURE_FAIL, \
75 "(%s) Failed to create %s - %s\n", \
76 __location__, fname, smbcli_errstr(cli->tree)); \
81 #define CHECK_RDWR(fnum, correct) do { \
82 enum rdwr_mode m = check_rdwr(cli->tree, fnum); \
84 torture_result(tctx, TORTURE_FAIL, \
85 "(%s) Incorrect readwrite mode %s - expected %s\n", \
86 __location__, rdwr_string(m), rdwr_string(correct)); \
90 #define CHECK_TIME(t, field) do { \
92 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
93 finfo.all_info.in.file.path = fname; \
94 status = smb_raw_pathinfo(cli->tree, tctx, &finfo); \
95 CHECK_STATUS(status, NT_STATUS_OK); \
97 t2 = nt_time_to_unix(finfo.all_info.out.field) & ~1; \
98 if (abs(t1-t2) > 2) { \
99 torture_result(tctx, TORTURE_FAIL, \
100 "(%s) wrong time for field %s %s - %s\n", \
101 __location__, #field, \
102 timestring(tctx, t1), \
103 timestring(tctx, t2)); \
104 dump_all_info(tctx, &finfo); \
108 #define CHECK_NTTIME(t, field) do { \
110 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
111 finfo.all_info.in.file.path = fname; \
112 status = smb_raw_pathinfo(cli->tree, tctx, &finfo); \
113 CHECK_STATUS(status, NT_STATUS_OK); \
114 t2 = finfo.all_info.out.field; \
116 torture_result(tctx, TORTURE_FAIL, \
117 "(%s) wrong time for field %s %s - %s\n", \
118 __location__, #field, \
119 nt_time_string(tctx, t), \
120 nt_time_string(tctx, t2)); \
121 dump_all_info(tctx, &finfo); \
125 #define CHECK_ALL_INFO(v, field) do { \
126 finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
127 finfo.all_info.in.file.path = fname; \
128 status = smb_raw_pathinfo(cli->tree, tctx, &finfo); \
129 CHECK_STATUS(status, NT_STATUS_OK); \
130 if ((v) != (finfo.all_info.out.field)) { \
131 torture_result(tctx, TORTURE_FAIL, \
132 "(%s) wrong value for field %s 0x%x - 0x%x\n", \
133 __location__, #field, (unsigned int)(v), (unsigned int)(finfo.all_info.out.field)); \
134 dump_all_info(tctx, &finfo); \
138 #define CHECK_VAL(v, correct) do { \
139 if ((v) != (correct)) { \
140 torture_result(tctx, TORTURE_FAIL, \
141 "(%s) wrong value for %s 0x%x - should be 0x%x\n", \
142 __location__, #v, (unsigned int)(v), (unsigned int)(correct)); \
146 #define SET_ATTRIB(sattrib) do { \
147 union smb_setfileinfo sfinfo; \
148 ZERO_STRUCT(sfinfo.basic_info.in); \
149 sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFORMATION; \
150 sfinfo.basic_info.in.file.path = fname; \
151 sfinfo.basic_info.in.attrib = sattrib; \
152 status = smb_raw_setpathinfo(cli->tree, &sfinfo); \
153 if (!NT_STATUS_IS_OK(status)) { \
154 torture_warning(tctx, "(%s) Failed to set attrib 0x%x on %s\n", \
155 __location__, (unsigned int)(sattrib), fname); \
161 static bool test_open(struct torture_context
*tctx
, struct smbcli_state
*cli
)
164 union smb_fileinfo finfo
;
165 const char *fname
= BASEDIR
"\\torture_open.txt";
167 int fnum
= -1, fnum2
;
170 if (!torture_setup_dir(cli
, BASEDIR
)) {
174 io
.openold
.level
= RAW_OPEN_OPEN
;
175 io
.openold
.in
.fname
= fname
;
176 io
.openold
.in
.open_mode
= OPEN_FLAGS_FCB
;
177 io
.openold
.in
.search_attrs
= 0;
178 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
179 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
180 fnum
= io
.openold
.out
.file
.fnum
;
182 smbcli_unlink(cli
->tree
, fname
);
184 smbcli_close(cli
->tree
, fnum
);
186 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
187 CHECK_STATUS(status
, NT_STATUS_OK
);
188 fnum
= io
.openold
.out
.file
.fnum
;
189 CHECK_RDWR(fnum
, RDWR_RDWR
);
191 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
192 CHECK_STATUS(status
, NT_STATUS_OK
);
193 fnum2
= io
.openold
.out
.file
.fnum
;
194 CHECK_RDWR(fnum2
, RDWR_RDWR
);
195 smbcli_close(cli
->tree
, fnum2
);
196 smbcli_close(cli
->tree
, fnum
);
198 /* check the read/write modes */
199 io
.openold
.level
= RAW_OPEN_OPEN
;
200 io
.openold
.in
.fname
= fname
;
201 io
.openold
.in
.search_attrs
= 0;
203 io
.openold
.in
.open_mode
= OPEN_FLAGS_OPEN_READ
;
204 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
205 CHECK_STATUS(status
, NT_STATUS_OK
);
206 fnum
= io
.openold
.out
.file
.fnum
;
207 CHECK_RDWR(fnum
, RDWR_RDONLY
);
208 smbcli_close(cli
->tree
, fnum
);
210 io
.openold
.in
.open_mode
= OPEN_FLAGS_OPEN_WRITE
;
211 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
212 CHECK_STATUS(status
, NT_STATUS_OK
);
213 fnum
= io
.openold
.out
.file
.fnum
;
214 CHECK_RDWR(fnum
, RDWR_WRONLY
);
215 smbcli_close(cli
->tree
, fnum
);
217 io
.openold
.in
.open_mode
= OPEN_FLAGS_OPEN_RDWR
;
218 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
219 CHECK_STATUS(status
, NT_STATUS_OK
);
220 fnum
= io
.openold
.out
.file
.fnum
;
221 CHECK_RDWR(fnum
, RDWR_RDWR
);
222 smbcli_close(cli
->tree
, fnum
);
224 /* check the share modes roughly - not a complete matrix */
225 io
.openold
.in
.open_mode
= OPEN_FLAGS_OPEN_RDWR
| OPEN_FLAGS_DENY_WRITE
;
226 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
227 CHECK_STATUS(status
, NT_STATUS_OK
);
228 fnum
= io
.openold
.out
.file
.fnum
;
229 CHECK_RDWR(fnum
, RDWR_RDWR
);
231 if (io
.openold
.in
.open_mode
!= io
.openold
.out
.rmode
) {
232 torture_warning(tctx
, "(%s) rmode should equal open_mode - 0x%x 0x%x\n",
233 __location__
, io
.openold
.out
.rmode
, io
.openold
.in
.open_mode
);
236 io
.openold
.in
.open_mode
= OPEN_FLAGS_OPEN_RDWR
| OPEN_FLAGS_DENY_NONE
;
237 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
238 CHECK_STATUS(status
, NT_STATUS_SHARING_VIOLATION
);
240 io
.openold
.in
.open_mode
= OPEN_FLAGS_OPEN_READ
| OPEN_FLAGS_DENY_NONE
;
241 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
242 CHECK_STATUS(status
, NT_STATUS_OK
);
243 fnum2
= io
.openold
.out
.file
.fnum
;
244 CHECK_RDWR(fnum2
, RDWR_RDONLY
);
245 smbcli_close(cli
->tree
, fnum
);
246 smbcli_close(cli
->tree
, fnum2
);
249 /* check the returned write time */
250 io
.openold
.level
= RAW_OPEN_OPEN
;
251 io
.openold
.in
.fname
= fname
;
252 io
.openold
.in
.search_attrs
= 0;
253 io
.openold
.in
.open_mode
= OPEN_FLAGS_OPEN_READ
;
254 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
255 CHECK_STATUS(status
, NT_STATUS_OK
);
256 fnum
= io
.openold
.out
.file
.fnum
;
258 /* check other reply fields */
259 CHECK_TIME(io
.openold
.out
.write_time
, write_time
);
260 CHECK_ALL_INFO(io
.openold
.out
.size
, size
);
261 CHECK_ALL_INFO(io
.openold
.out
.attrib
, attrib
& ~FILE_ATTRIBUTE_NONINDEXED
);
264 smbcli_close(cli
->tree
, fnum
);
265 smbcli_deltree(cli
->tree
, BASEDIR
);
274 static bool test_openx(struct torture_context
*tctx
, struct smbcli_state
*cli
)
277 union smb_fileinfo finfo
;
278 const char *fname
= BASEDIR
"\\torture_openx.txt";
279 const char *fname_exe
= BASEDIR
"\\torture_openx.exe";
281 int fnum
= -1, fnum2
;
288 NTSTATUS correct_status
;
290 { OPENX_OPEN_FUNC_OPEN
, true, NT_STATUS_OK
},
291 { OPENX_OPEN_FUNC_OPEN
, false, NT_STATUS_OBJECT_NAME_NOT_FOUND
},
292 { OPENX_OPEN_FUNC_OPEN
| OPENX_OPEN_FUNC_CREATE
, true, NT_STATUS_OK
},
293 { OPENX_OPEN_FUNC_OPEN
| OPENX_OPEN_FUNC_CREATE
, false, NT_STATUS_OK
},
294 { OPENX_OPEN_FUNC_FAIL
, true, NT_STATUS_DOS(ERRDOS
, ERRbadaccess
) },
295 { OPENX_OPEN_FUNC_FAIL
, false, NT_STATUS_DOS(ERRDOS
, ERRbadaccess
) },
296 { OPENX_OPEN_FUNC_FAIL
| OPENX_OPEN_FUNC_CREATE
, true, NT_STATUS_OBJECT_NAME_COLLISION
},
297 { OPENX_OPEN_FUNC_FAIL
| OPENX_OPEN_FUNC_CREATE
, false, NT_STATUS_OK
},
298 { OPENX_OPEN_FUNC_TRUNC
, true, NT_STATUS_OK
},
299 { OPENX_OPEN_FUNC_TRUNC
, false, NT_STATUS_OBJECT_NAME_NOT_FOUND
},
300 { OPENX_OPEN_FUNC_TRUNC
| OPENX_OPEN_FUNC_CREATE
, true, NT_STATUS_OK
},
301 { OPENX_OPEN_FUNC_TRUNC
| OPENX_OPEN_FUNC_CREATE
, false, NT_STATUS_OK
},
304 if (!torture_setup_dir(cli
, BASEDIR
)) {
308 io
.openx
.level
= RAW_OPEN_OPENX
;
309 io
.openx
.in
.fname
= fname
;
310 io
.openx
.in
.flags
= OPENX_FLAGS_ADDITIONAL_INFO
;
311 io
.openx
.in
.open_mode
= OPENX_MODE_ACCESS_RDWR
;
312 io
.openx
.in
.search_attrs
= 0;
313 io
.openx
.in
.file_attrs
= 0;
314 io
.openx
.in
.write_time
= 0;
315 io
.openx
.in
.size
= 1024*1024;
316 io
.openx
.in
.timeout
= 0;
318 /* check all combinations of open_func */
319 for (i
=0; i
<ARRAY_SIZE(open_funcs
); i
++) {
320 if (open_funcs
[i
].with_file
) {
321 fnum
= create_complex_file(cli
, tctx
, fname
);
323 torture_result(tctx
, TORTURE_FAIL
,
324 "Failed to create file %s - %s\n",
325 fname
, smbcli_errstr(cli
->tree
));
329 smbcli_close(cli
->tree
, fnum
);
331 io
.openx
.in
.open_func
= open_funcs
[i
].open_func
;
332 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
333 if (!NT_STATUS_EQUAL(status
, open_funcs
[i
].correct_status
)) {
334 torture_result(tctx
, TORTURE_FAIL
,
335 "(%s) incorrect status %s should be %s "
336 "(i=%d with_file=%d open_func=0x%x)\n",
337 __location__
, nt_errstr(status
),
338 nt_errstr(open_funcs
[i
].correct_status
),
339 i
, (int)open_funcs
[i
].with_file
,
340 open_funcs
[i
].open_func
);
343 if (NT_STATUS_IS_OK(status
)) {
344 smbcli_close(cli
->tree
, io
.openx
.out
.file
.fnum
);
346 if (open_funcs
[i
].with_file
) {
347 smbcli_unlink(cli
->tree
, fname
);
351 smbcli_unlink(cli
->tree
, fname
);
353 /* check the basic return fields */
354 io
.openx
.in
.open_func
= OPENX_OPEN_FUNC_OPEN
| OPENX_OPEN_FUNC_CREATE
;
355 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
356 CHECK_STATUS(status
, NT_STATUS_OK
);
357 fnum
= io
.openx
.out
.file
.fnum
;
359 CHECK_ALL_INFO(io
.openx
.out
.size
, size
);
360 CHECK_TIME(io
.openx
.out
.write_time
, write_time
);
361 CHECK_ALL_INFO(io
.openx
.out
.attrib
, attrib
& ~FILE_ATTRIBUTE_NONINDEXED
);
362 CHECK_VAL(io
.openx
.out
.access
, OPENX_MODE_ACCESS_RDWR
);
363 CHECK_VAL(io
.openx
.out
.ftype
, 0);
364 CHECK_VAL(io
.openx
.out
.devstate
, 0);
365 CHECK_VAL(io
.openx
.out
.action
, OPENX_ACTION_CREATED
);
366 CHECK_VAL(io
.openx
.out
.size
, 1024*1024);
367 CHECK_ALL_INFO(io
.openx
.in
.size
, size
);
368 smbcli_close(cli
->tree
, fnum
);
369 smbcli_unlink(cli
->tree
, fname
);
371 /* check the fields when the file already existed */
372 fnum2
= create_complex_file(cli
, tctx
, fname
);
377 smbcli_close(cli
->tree
, fnum2
);
379 io
.openx
.in
.open_func
= OPENX_OPEN_FUNC_OPEN
;
380 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
381 CHECK_STATUS(status
, NT_STATUS_OK
);
382 fnum
= io
.openx
.out
.file
.fnum
;
384 CHECK_ALL_INFO(io
.openx
.out
.size
, size
);
385 CHECK_TIME(io
.openx
.out
.write_time
, write_time
);
386 CHECK_VAL(io
.openx
.out
.action
, OPENX_ACTION_EXISTED
);
387 CHECK_VAL(io
.openx
.out
.unknown
, 0);
388 CHECK_ALL_INFO(io
.openx
.out
.attrib
, attrib
& ~FILE_ATTRIBUTE_NONINDEXED
);
389 smbcli_close(cli
->tree
, fnum
);
391 /* now check the search attrib for hidden files - win2003 ignores this? */
392 SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN
);
393 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN
, attrib
);
395 io
.openx
.in
.search_attrs
= FILE_ATTRIBUTE_HIDDEN
;
396 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
397 CHECK_STATUS(status
, NT_STATUS_OK
);
398 smbcli_close(cli
->tree
, io
.openx
.out
.file
.fnum
);
400 io
.openx
.in
.search_attrs
= 0;
401 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
402 CHECK_STATUS(status
, NT_STATUS_OK
);
403 smbcli_close(cli
->tree
, io
.openx
.out
.file
.fnum
);
405 SET_ATTRIB(FILE_ATTRIBUTE_NORMAL
);
406 smbcli_unlink(cli
->tree
, fname
);
408 /* and check attrib on create */
409 io
.openx
.in
.open_func
= OPENX_OPEN_FUNC_FAIL
| OPENX_OPEN_FUNC_CREATE
;
410 io
.openx
.in
.search_attrs
= 0;
411 io
.openx
.in
.file_attrs
= FILE_ATTRIBUTE_SYSTEM
;
412 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
413 CHECK_STATUS(status
, NT_STATUS_OK
);
414 if (torture_setting_bool(tctx
, "samba3", false)) {
415 CHECK_ALL_INFO(FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_ARCHIVE
,
416 attrib
& ~(FILE_ATTRIBUTE_NONINDEXED
|
417 FILE_ATTRIBUTE_SPARSE
));
420 CHECK_ALL_INFO(FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_ARCHIVE
,
421 attrib
& ~(FILE_ATTRIBUTE_NONINDEXED
));
423 smbcli_close(cli
->tree
, io
.openx
.out
.file
.fnum
);
424 smbcli_unlink(cli
->tree
, fname
);
426 /* check timeout on create - win2003 ignores the timeout! */
427 io
.openx
.in
.open_func
= OPENX_OPEN_FUNC_OPEN
| OPENX_OPEN_FUNC_CREATE
;
428 io
.openx
.in
.file_attrs
= 0;
429 io
.openx
.in
.open_mode
= OPENX_MODE_ACCESS_RDWR
| OPENX_MODE_DENY_ALL
;
430 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
431 CHECK_STATUS(status
, NT_STATUS_OK
);
432 fnum
= io
.openx
.out
.file
.fnum
;
434 io
.openx
.in
.timeout
= 20000;
435 tv
= timeval_current();
436 io
.openx
.in
.open_mode
= OPENX_MODE_ACCESS_RDWR
| OPENX_MODE_DENY_NONE
;
437 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
438 CHECK_STATUS(status
, NT_STATUS_SHARING_VIOLATION
);
439 if (timeval_elapsed(&tv
) > 3.0) {
440 torture_result(tctx
, TORTURE_FAIL
,
441 "(%s) Incorrect timing in openx with timeout "
442 "- waited %.2f seconds\n",
443 __location__
, timeval_elapsed(&tv
));
446 smbcli_close(cli
->tree
, fnum
);
447 smbcli_unlink(cli
->tree
, fname
);
449 /* now this is a really weird one - open for execute implies create?! */
450 io
.openx
.in
.fname
= fname
;
451 io
.openx
.in
.flags
= OPENX_FLAGS_ADDITIONAL_INFO
;
452 io
.openx
.in
.open_mode
= OPENX_MODE_ACCESS_EXEC
| OPENX_MODE_DENY_NONE
;
453 io
.openx
.in
.search_attrs
= 0;
454 io
.openx
.in
.open_func
= OPENX_OPEN_FUNC_FAIL
;
455 io
.openx
.in
.file_attrs
= 0;
456 io
.openx
.in
.write_time
= 0;
457 io
.openx
.in
.size
= 0;
458 io
.openx
.in
.timeout
= 0;
459 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
460 CHECK_STATUS(status
, NT_STATUS_OK
);
461 smbcli_close(cli
->tree
, io
.openx
.out
.file
.fnum
);
463 /* check the extended return flag */
464 io
.openx
.in
.flags
= OPENX_FLAGS_ADDITIONAL_INFO
| OPENX_FLAGS_EXTENDED_RETURN
;
465 io
.openx
.in
.open_func
= OPENX_OPEN_FUNC_OPEN
;
466 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
467 CHECK_STATUS(status
, NT_STATUS_OK
);
468 CHECK_VAL(io
.openx
.out
.access_mask
, SEC_STD_ALL
);
469 smbcli_close(cli
->tree
, io
.openx
.out
.file
.fnum
);
471 io
.openx
.in
.fname
= "\\A.+,;=[].B";
472 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
473 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
475 /* Check the mapping for open exec. */
477 /* First create an .exe file. */
478 smbcli_unlink(cli
->tree
, fname_exe
);
479 fnum
= create_complex_file(cli
, tctx
, fname_exe
);
480 smbcli_close(cli
->tree
, fnum
);
482 io
.openx
.level
= RAW_OPEN_OPENX
;
483 io
.openx
.in
.fname
= fname_exe
;
484 io
.openx
.in
.flags
= OPENX_FLAGS_ADDITIONAL_INFO
;
485 io
.openx
.in
.open_mode
= OPENX_MODE_ACCESS_EXEC
| OPENX_MODE_DENY_NONE
;
486 io
.openx
.in
.search_attrs
= 0;
487 io
.openx
.in
.file_attrs
= 0;
488 io
.openx
.in
.write_time
= 0;
489 io
.openx
.in
.size
= 0;
490 io
.openx
.in
.timeout
= 0;
491 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
492 CHECK_STATUS(status
, NT_STATUS_OK
);
494 /* Can we read and write ? */
495 CHECK_RDWR(io
.openx
.out
.file
.fnum
, RDWR_RDONLY
);
496 smbcli_close(cli
->tree
, io
.openx
.out
.file
.fnum
);
497 smbcli_unlink(cli
->tree
, fname
);
500 smbcli_close(cli
->tree
, fnum
);
501 smbcli_deltree(cli
->tree
, BASEDIR
);
510 many thanks to kukks for a sniff showing how this works with os2->w2k
512 static bool test_t2open(struct torture_context
*tctx
, struct smbcli_state
*cli
)
515 union smb_fileinfo finfo
;
516 const char *fname1
= BASEDIR
"\\torture_t2open_yes.txt";
517 const char *fname2
= BASEDIR
"\\torture_t2open_no.txt";
518 const char *fname
= BASEDIR
"\\torture_t2open_3.txt";
526 NTSTATUS correct_status
;
528 { OPENX_OPEN_FUNC_OPEN
, true, NT_STATUS_OK
},
529 { OPENX_OPEN_FUNC_OPEN
, false, NT_STATUS_OBJECT_NAME_NOT_FOUND
},
530 { OPENX_OPEN_FUNC_OPEN
| OPENX_OPEN_FUNC_CREATE
, true, NT_STATUS_OK
},
531 { OPENX_OPEN_FUNC_OPEN
| OPENX_OPEN_FUNC_CREATE
, false, NT_STATUS_OK
},
532 { OPENX_OPEN_FUNC_FAIL
, true, NT_STATUS_OBJECT_NAME_COLLISION
},
533 { OPENX_OPEN_FUNC_FAIL
, false, NT_STATUS_OBJECT_NAME_COLLISION
},
534 { OPENX_OPEN_FUNC_FAIL
| OPENX_OPEN_FUNC_CREATE
, true, NT_STATUS_OBJECT_NAME_COLLISION
},
535 { OPENX_OPEN_FUNC_FAIL
| OPENX_OPEN_FUNC_CREATE
, false, NT_STATUS_OBJECT_NAME_COLLISION
},
536 { OPENX_OPEN_FUNC_TRUNC
, true, NT_STATUS_OK
},
537 { OPENX_OPEN_FUNC_TRUNC
, false, NT_STATUS_OK
},
538 { OPENX_OPEN_FUNC_TRUNC
| OPENX_OPEN_FUNC_CREATE
, true, NT_STATUS_OK
},
539 { OPENX_OPEN_FUNC_TRUNC
| OPENX_OPEN_FUNC_CREATE
, false, NT_STATUS_OK
},
542 if (!torture_setup_dir(cli
, BASEDIR
)) {
546 fnum
= create_complex_file(cli
, tctx
, fname1
);
548 torture_result(tctx
, TORTURE_FAIL
,
549 "(%s): Failed to create file %s - %s\n",
550 __location__
, fname1
, smbcli_errstr(cli
->tree
));
554 smbcli_close(cli
->tree
, fnum
);
556 io
.t2open
.level
= RAW_OPEN_T2OPEN
;
557 io
.t2open
.in
.flags
= OPENX_FLAGS_ADDITIONAL_INFO
;
558 io
.t2open
.in
.open_mode
= OPENX_MODE_DENY_NONE
| OPENX_MODE_ACCESS_RDWR
;
559 io
.t2open
.in
.open_func
= OPENX_OPEN_FUNC_OPEN
| OPENX_OPEN_FUNC_CREATE
;
560 io
.t2open
.in
.search_attrs
= 0;
561 io
.t2open
.in
.file_attrs
= 0;
562 io
.t2open
.in
.write_time
= 0;
563 io
.t2open
.in
.size
= 0;
564 io
.t2open
.in
.timeout
= 0;
566 io
.t2open
.in
.num_eas
= 3;
567 io
.t2open
.in
.eas
= talloc_array(tctx
, struct ea_struct
, io
.t2open
.in
.num_eas
);
568 io
.t2open
.in
.eas
[0].flags
= 0;
569 io
.t2open
.in
.eas
[0].name
.s
= ".CLASSINFO";
570 io
.t2open
.in
.eas
[0].value
= data_blob_talloc(tctx
, "first value", 11);
571 io
.t2open
.in
.eas
[1].flags
= 0;
572 io
.t2open
.in
.eas
[1].name
.s
= "EA TWO";
573 io
.t2open
.in
.eas
[1].value
= data_blob_talloc(tctx
, "foo", 3);
574 io
.t2open
.in
.eas
[2].flags
= 0;
575 io
.t2open
.in
.eas
[2].name
.s
= "X THIRD";
576 io
.t2open
.in
.eas
[2].value
= data_blob_talloc(tctx
, "xy", 2);
578 /* check all combinations of open_func */
579 for (i
=0; i
<ARRAY_SIZE(open_funcs
); i
++) {
581 if (open_funcs
[i
].with_file
) {
582 io
.t2open
.in
.fname
= fname1
;
584 io
.t2open
.in
.fname
= fname2
;
586 io
.t2open
.in
.open_func
= open_funcs
[i
].open_func
;
587 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
588 if ((io
.t2open
.in
.num_eas
!= 0)
589 && NT_STATUS_EQUAL(status
, NT_STATUS_EAS_NOT_SUPPORTED
)
590 && torture_setting_bool(tctx
, "samba3", false)) {
591 torture_warning(tctx
, "(%s) EAs not supported, not "
592 "treating as fatal in Samba3 test\n",
594 io
.t2open
.in
.num_eas
= 0;
598 if (!NT_STATUS_EQUAL(status
, open_funcs
[i
].correct_status
)) {
599 torture_result(tctx
, TORTURE_FAIL
,
600 "(%s) incorrect status %s should be %s "
601 "(i=%d with_file=%d open_func=0x%x)\n",
602 __location__
, nt_errstr(status
),
603 nt_errstr(open_funcs
[i
].correct_status
),
604 i
, (int)open_funcs
[i
].with_file
,
605 open_funcs
[i
].open_func
);
608 if (NT_STATUS_IS_OK(status
)) {
609 smbcli_close(cli
->tree
, io
.t2open
.out
.file
.fnum
);
613 smbcli_unlink(cli
->tree
, fname1
);
614 smbcli_unlink(cli
->tree
, fname2
);
616 /* check the basic return fields */
617 io
.t2open
.in
.open_func
= OPENX_OPEN_FUNC_OPEN
| OPENX_OPEN_FUNC_CREATE
;
618 io
.t2open
.in
.write_time
= 0;
619 io
.t2open
.in
.fname
= fname
;
620 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
621 CHECK_STATUS(status
, NT_STATUS_OK
);
622 fnum
= io
.t2open
.out
.file
.fnum
;
624 CHECK_ALL_INFO(io
.t2open
.out
.size
, size
);
626 /* windows appears to leak uninitialised memory here */
627 CHECK_VAL(io
.t2open
.out
.write_time
, 0);
629 CHECK_ALL_INFO(io
.t2open
.out
.attrib
, attrib
& ~FILE_ATTRIBUTE_NONINDEXED
);
630 CHECK_VAL(io
.t2open
.out
.access
, OPENX_MODE_DENY_NONE
| OPENX_MODE_ACCESS_RDWR
);
631 CHECK_VAL(io
.t2open
.out
.ftype
, 0);
632 CHECK_VAL(io
.t2open
.out
.devstate
, 0);
633 CHECK_VAL(io
.t2open
.out
.action
, OPENX_ACTION_CREATED
);
634 smbcli_close(cli
->tree
, fnum
);
636 status
= torture_check_ea(cli
, fname
, ".CLASSINFO", "first value");
637 CHECK_STATUS(status
, io
.t2open
.in
.num_eas
638 ? NT_STATUS_OK
: NT_STATUS_EAS_NOT_SUPPORTED
);
639 status
= torture_check_ea(cli
, fname
, "EA TWO", "foo");
640 CHECK_STATUS(status
, io
.t2open
.in
.num_eas
641 ? NT_STATUS_OK
: NT_STATUS_EAS_NOT_SUPPORTED
);
642 status
= torture_check_ea(cli
, fname
, "X THIRD", "xy");
643 CHECK_STATUS(status
, io
.t2open
.in
.num_eas
644 ? NT_STATUS_OK
: NT_STATUS_EAS_NOT_SUPPORTED
);
646 /* now check the search attrib for hidden files - win2003 ignores this? */
647 SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN
);
648 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN
, attrib
);
650 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
651 CHECK_STATUS(status
, NT_STATUS_OK
);
652 smbcli_close(cli
->tree
, io
.t2open
.out
.file
.fnum
);
654 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
655 CHECK_STATUS(status
, NT_STATUS_OK
);
656 smbcli_close(cli
->tree
, io
.t2open
.out
.file
.fnum
);
658 SET_ATTRIB(FILE_ATTRIBUTE_NORMAL
);
659 smbcli_unlink(cli
->tree
, fname
);
661 /* and check attrib on create */
662 io
.t2open
.in
.open_func
= OPENX_OPEN_FUNC_FAIL
| OPENX_OPEN_FUNC_CREATE
;
663 io
.t2open
.in
.file_attrs
= FILE_ATTRIBUTE_SYSTEM
;
664 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
665 CHECK_STATUS(status
, NT_STATUS_OK
);
667 /* check timeout on create - win2003 ignores the timeout! */
668 io
.t2open
.in
.open_func
= OPENX_OPEN_FUNC_OPEN
| OPENX_OPEN_FUNC_CREATE
;
669 io
.t2open
.in
.file_attrs
= 0;
670 io
.t2open
.in
.timeout
= 20000;
671 io
.t2open
.in
.open_mode
= OPENX_MODE_ACCESS_RDWR
| OPENX_MODE_DENY_ALL
;
672 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
673 CHECK_STATUS(status
, NT_STATUS_SHARING_VIOLATION
);
676 smbcli_close(cli
->tree
, fnum
);
677 smbcli_deltree(cli
->tree
, BASEDIR
);
684 test RAW_OPEN_NTCREATEX
686 static bool test_ntcreatex(struct torture_context
*tctx
, struct smbcli_state
*cli
)
689 union smb_fileinfo finfo
;
690 const char *fname
= BASEDIR
"\\torture_ntcreatex.txt";
691 const char *dname
= BASEDIR
"\\torture_ntcreatex.dir";
699 NTSTATUS correct_status
;
701 { NTCREATEX_DISP_SUPERSEDE
, true, NT_STATUS_OK
},
702 { NTCREATEX_DISP_SUPERSEDE
, false, NT_STATUS_OK
},
703 { NTCREATEX_DISP_OPEN
, true, NT_STATUS_OK
},
704 { NTCREATEX_DISP_OPEN
, false, NT_STATUS_OBJECT_NAME_NOT_FOUND
},
705 { NTCREATEX_DISP_CREATE
, true, NT_STATUS_OBJECT_NAME_COLLISION
},
706 { NTCREATEX_DISP_CREATE
, false, NT_STATUS_OK
},
707 { NTCREATEX_DISP_OPEN_IF
, true, NT_STATUS_OK
},
708 { NTCREATEX_DISP_OPEN_IF
, false, NT_STATUS_OK
},
709 { NTCREATEX_DISP_OVERWRITE
, true, NT_STATUS_OK
},
710 { NTCREATEX_DISP_OVERWRITE
, false, NT_STATUS_OBJECT_NAME_NOT_FOUND
},
711 { NTCREATEX_DISP_OVERWRITE_IF
, true, NT_STATUS_OK
},
712 { NTCREATEX_DISP_OVERWRITE_IF
, false, NT_STATUS_OK
},
713 { 6, true, NT_STATUS_INVALID_PARAMETER
},
714 { 6, false, NT_STATUS_INVALID_PARAMETER
},
717 if (!torture_setup_dir(cli
, BASEDIR
)) {
721 /* reasonable default parameters */
722 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
723 io
.ntcreatex
.in
.flags
= NTCREATEX_FLAGS_EXTENDED
;
724 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
725 io
.ntcreatex
.in
.access_mask
= SEC_RIGHTS_FILE_ALL
;
726 io
.ntcreatex
.in
.alloc_size
= 1024*1024;
727 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
728 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
729 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
730 io
.ntcreatex
.in
.create_options
= 0;
731 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
732 io
.ntcreatex
.in
.security_flags
= 0;
733 io
.ntcreatex
.in
.fname
= fname
;
735 /* test the open disposition */
736 for (i
=0; i
<ARRAY_SIZE(open_funcs
); i
++) {
737 if (open_funcs
[i
].with_file
) {
738 fnum
= smbcli_open(cli
->tree
, fname
, O_CREAT
|O_RDWR
|O_TRUNC
, DENY_NONE
);
740 torture_result(tctx
, TORTURE_FAIL
,
741 "Failed to create file %s - %s\n",
742 fname
, smbcli_errstr(cli
->tree
));
746 smbcli_close(cli
->tree
, fnum
);
748 io
.ntcreatex
.in
.open_disposition
= open_funcs
[i
].open_disp
;
749 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
750 if (!NT_STATUS_EQUAL(status
, open_funcs
[i
].correct_status
)) {
751 torture_result(tctx
, TORTURE_FAIL
,
752 "(%s) incorrect status %s should be %s "
753 "(i=%d with_file=%d open_disp=%d)\n",
754 __location__
, nt_errstr(status
),
755 nt_errstr(open_funcs
[i
].correct_status
),
756 i
, (int)open_funcs
[i
].with_file
,
757 (int)open_funcs
[i
].open_disp
);
760 if (NT_STATUS_IS_OK(status
) || open_funcs
[i
].with_file
) {
761 smbcli_close(cli
->tree
, io
.ntcreatex
.out
.file
.fnum
);
762 smbcli_unlink(cli
->tree
, fname
);
766 /* basic field testing */
767 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
769 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
770 CHECK_STATUS(status
, NT_STATUS_OK
);
771 fnum
= io
.ntcreatex
.out
.file
.fnum
;
773 CHECK_VAL(io
.ntcreatex
.out
.oplock_level
, 0);
774 CHECK_VAL(io
.ntcreatex
.out
.create_action
, NTCREATEX_ACTION_CREATED
);
775 CHECK_NTTIME(io
.ntcreatex
.out
.create_time
, create_time
);
776 CHECK_NTTIME(io
.ntcreatex
.out
.access_time
, access_time
);
777 CHECK_NTTIME(io
.ntcreatex
.out
.write_time
, write_time
);
778 CHECK_NTTIME(io
.ntcreatex
.out
.change_time
, change_time
);
779 CHECK_ALL_INFO(io
.ntcreatex
.out
.attrib
, attrib
);
780 CHECK_ALL_INFO(io
.ntcreatex
.out
.alloc_size
, alloc_size
);
781 CHECK_ALL_INFO(io
.ntcreatex
.out
.size
, size
);
782 CHECK_ALL_INFO(io
.ntcreatex
.out
.is_directory
, directory
);
783 CHECK_VAL(io
.ntcreatex
.out
.file_type
, FILE_TYPE_DISK
);
785 /* check fields when the file already existed */
786 smbcli_close(cli
->tree
, fnum
);
787 smbcli_unlink(cli
->tree
, fname
);
788 fnum
= create_complex_file(cli
, tctx
, fname
);
793 smbcli_close(cli
->tree
, fnum
);
795 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
796 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
797 CHECK_STATUS(status
, NT_STATUS_OK
);
798 fnum
= io
.ntcreatex
.out
.file
.fnum
;
800 CHECK_VAL(io
.ntcreatex
.out
.oplock_level
, 0);
801 CHECK_VAL(io
.ntcreatex
.out
.create_action
, NTCREATEX_ACTION_EXISTED
);
802 CHECK_NTTIME(io
.ntcreatex
.out
.create_time
, create_time
);
803 CHECK_NTTIME(io
.ntcreatex
.out
.access_time
, access_time
);
804 CHECK_NTTIME(io
.ntcreatex
.out
.write_time
, write_time
);
805 CHECK_NTTIME(io
.ntcreatex
.out
.change_time
, change_time
);
806 CHECK_ALL_INFO(io
.ntcreatex
.out
.attrib
, attrib
);
807 CHECK_ALL_INFO(io
.ntcreatex
.out
.alloc_size
, alloc_size
);
808 CHECK_ALL_INFO(io
.ntcreatex
.out
.size
, size
);
809 CHECK_ALL_INFO(io
.ntcreatex
.out
.is_directory
, directory
);
810 CHECK_VAL(io
.ntcreatex
.out
.file_type
, FILE_TYPE_DISK
);
811 smbcli_close(cli
->tree
, fnum
);
812 smbcli_unlink(cli
->tree
, fname
);
815 /* create a directory */
816 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
817 io
.ntcreatex
.in
.access_mask
= SEC_RIGHTS_FILE_ALL
;
818 io
.ntcreatex
.in
.alloc_size
= 0;
819 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_DIRECTORY
;
820 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
821 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
822 io
.ntcreatex
.in
.create_options
= 0;
823 io
.ntcreatex
.in
.fname
= dname
;
826 smbcli_rmdir(cli
->tree
, fname
);
827 smbcli_unlink(cli
->tree
, fname
);
829 io
.ntcreatex
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
830 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
831 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
832 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
833 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
834 CHECK_STATUS(status
, NT_STATUS_OK
);
835 fnum
= io
.ntcreatex
.out
.file
.fnum
;
837 CHECK_VAL(io
.ntcreatex
.out
.oplock_level
, 0);
838 CHECK_VAL(io
.ntcreatex
.out
.create_action
, NTCREATEX_ACTION_CREATED
);
839 CHECK_NTTIME(io
.ntcreatex
.out
.create_time
, create_time
);
840 CHECK_NTTIME(io
.ntcreatex
.out
.access_time
, access_time
);
841 CHECK_NTTIME(io
.ntcreatex
.out
.write_time
, write_time
);
842 CHECK_NTTIME(io
.ntcreatex
.out
.change_time
, change_time
);
843 CHECK_ALL_INFO(io
.ntcreatex
.out
.attrib
, attrib
);
844 CHECK_VAL(io
.ntcreatex
.out
.attrib
& ~FILE_ATTRIBUTE_NONINDEXED
,
845 FILE_ATTRIBUTE_DIRECTORY
);
846 CHECK_ALL_INFO(io
.ntcreatex
.out
.alloc_size
, alloc_size
);
847 CHECK_ALL_INFO(io
.ntcreatex
.out
.size
, size
);
848 CHECK_ALL_INFO(io
.ntcreatex
.out
.is_directory
, directory
);
849 CHECK_VAL(io
.ntcreatex
.out
.is_directory
, 1);
850 CHECK_VAL(io
.ntcreatex
.out
.size
, 0);
851 CHECK_VAL(io
.ntcreatex
.out
.alloc_size
, 0);
852 CHECK_VAL(io
.ntcreatex
.out
.file_type
, FILE_TYPE_DISK
);
853 smbcli_unlink(cli
->tree
, fname
);
857 smbcli_close(cli
->tree
, fnum
);
858 smbcli_deltree(cli
->tree
, BASEDIR
);
865 test RAW_OPEN_NTTRANS_CREATE
867 static bool test_nttrans_create(struct torture_context
*tctx
, struct smbcli_state
*cli
)
870 union smb_fileinfo finfo
;
871 const char *fname
= BASEDIR
"\\torture_ntcreatex.txt";
872 const char *dname
= BASEDIR
"\\torture_ntcreatex.dir";
877 uint32_t ok_mask
, not_supported_mask
, invalid_parameter_mask
;
878 uint32_t not_a_directory_mask
, unexpected_mask
;
882 NTSTATUS correct_status
;
884 { NTCREATEX_DISP_SUPERSEDE
, true, NT_STATUS_OK
},
885 { NTCREATEX_DISP_SUPERSEDE
, false, NT_STATUS_OK
},
886 { NTCREATEX_DISP_OPEN
, true, NT_STATUS_OK
},
887 { NTCREATEX_DISP_OPEN
, false, NT_STATUS_OBJECT_NAME_NOT_FOUND
},
888 { NTCREATEX_DISP_CREATE
, true, NT_STATUS_OBJECT_NAME_COLLISION
},
889 { NTCREATEX_DISP_CREATE
, false, NT_STATUS_OK
},
890 { NTCREATEX_DISP_OPEN_IF
, true, NT_STATUS_OK
},
891 { NTCREATEX_DISP_OPEN_IF
, false, NT_STATUS_OK
},
892 { NTCREATEX_DISP_OVERWRITE
, true, NT_STATUS_OK
},
893 { NTCREATEX_DISP_OVERWRITE
, false, NT_STATUS_OBJECT_NAME_NOT_FOUND
},
894 { NTCREATEX_DISP_OVERWRITE_IF
, true, NT_STATUS_OK
},
895 { NTCREATEX_DISP_OVERWRITE_IF
, false, NT_STATUS_OK
},
896 { 6, true, NT_STATUS_INVALID_PARAMETER
},
897 { 6, false, NT_STATUS_INVALID_PARAMETER
},
900 if (!torture_setup_dir(cli
, BASEDIR
)) {
904 /* reasonable default parameters */
905 io
.generic
.level
= RAW_OPEN_NTTRANS_CREATE
;
906 io
.ntcreatex
.in
.flags
= NTCREATEX_FLAGS_EXTENDED
;
907 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
908 io
.ntcreatex
.in
.access_mask
= SEC_RIGHTS_FILE_ALL
;
909 io
.ntcreatex
.in
.alloc_size
= 1024*1024;
910 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
911 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
912 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
913 io
.ntcreatex
.in
.create_options
= 0;
914 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
915 io
.ntcreatex
.in
.security_flags
= 0;
916 io
.ntcreatex
.in
.fname
= fname
;
917 io
.ntcreatex
.in
.sec_desc
= NULL
;
918 io
.ntcreatex
.in
.ea_list
= NULL
;
920 /* test the open disposition */
921 for (i
=0; i
<ARRAY_SIZE(open_funcs
); i
++) {
922 if (open_funcs
[i
].with_file
) {
923 fnum
= smbcli_open(cli
->tree
, fname
, O_CREAT
|O_RDWR
|O_TRUNC
, DENY_NONE
);
925 torture_result(tctx
, TORTURE_FAIL
,
926 "Failed to create file %s - %s\n",
927 fname
, smbcli_errstr(cli
->tree
));
931 smbcli_close(cli
->tree
, fnum
);
933 io
.ntcreatex
.in
.open_disposition
= open_funcs
[i
].open_disp
;
934 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
935 if (!NT_STATUS_EQUAL(status
, open_funcs
[i
].correct_status
)) {
936 torture_result(tctx
, TORTURE_FAIL
,
937 "(%s) incorrect status %s should be %s "
938 "(i=%d with_file=%d open_disp=%d)\n",
939 __location__
, nt_errstr(status
),
940 nt_errstr(open_funcs
[i
].correct_status
),
941 i
, (int)open_funcs
[i
].with_file
,
942 (int)open_funcs
[i
].open_disp
);
945 if (NT_STATUS_IS_OK(status
) || open_funcs
[i
].with_file
) {
946 smbcli_close(cli
->tree
, io
.ntcreatex
.out
.file
.fnum
);
947 smbcli_unlink(cli
->tree
, fname
);
951 /* basic field testing */
952 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
954 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
955 CHECK_STATUS(status
, NT_STATUS_OK
);
956 fnum
= io
.ntcreatex
.out
.file
.fnum
;
958 CHECK_VAL(io
.ntcreatex
.out
.oplock_level
, 0);
959 CHECK_VAL(io
.ntcreatex
.out
.create_action
, NTCREATEX_ACTION_CREATED
);
960 CHECK_NTTIME(io
.ntcreatex
.out
.create_time
, create_time
);
961 CHECK_NTTIME(io
.ntcreatex
.out
.access_time
, access_time
);
962 CHECK_NTTIME(io
.ntcreatex
.out
.write_time
, write_time
);
963 CHECK_NTTIME(io
.ntcreatex
.out
.change_time
, change_time
);
964 CHECK_ALL_INFO(io
.ntcreatex
.out
.attrib
, attrib
);
965 CHECK_ALL_INFO(io
.ntcreatex
.out
.alloc_size
, alloc_size
);
966 CHECK_ALL_INFO(io
.ntcreatex
.out
.size
, size
);
967 CHECK_ALL_INFO(io
.ntcreatex
.out
.is_directory
, directory
);
968 CHECK_VAL(io
.ntcreatex
.out
.file_type
, FILE_TYPE_DISK
);
970 /* check fields when the file already existed */
971 smbcli_close(cli
->tree
, fnum
);
972 smbcli_unlink(cli
->tree
, fname
);
973 fnum
= create_complex_file(cli
, tctx
, fname
);
978 smbcli_close(cli
->tree
, fnum
);
980 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
981 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
982 CHECK_STATUS(status
, NT_STATUS_OK
);
983 fnum
= io
.ntcreatex
.out
.file
.fnum
;
985 CHECK_VAL(io
.ntcreatex
.out
.oplock_level
, 0);
986 CHECK_VAL(io
.ntcreatex
.out
.create_action
, NTCREATEX_ACTION_EXISTED
);
987 CHECK_NTTIME(io
.ntcreatex
.out
.create_time
, create_time
);
988 CHECK_NTTIME(io
.ntcreatex
.out
.access_time
, access_time
);
989 CHECK_NTTIME(io
.ntcreatex
.out
.write_time
, write_time
);
990 CHECK_NTTIME(io
.ntcreatex
.out
.change_time
, change_time
);
991 CHECK_ALL_INFO(io
.ntcreatex
.out
.attrib
, attrib
);
992 CHECK_ALL_INFO(io
.ntcreatex
.out
.alloc_size
, alloc_size
);
993 CHECK_ALL_INFO(io
.ntcreatex
.out
.size
, size
);
994 CHECK_ALL_INFO(io
.ntcreatex
.out
.is_directory
, directory
);
995 CHECK_VAL(io
.ntcreatex
.out
.file_type
, FILE_TYPE_DISK
);
996 smbcli_close(cli
->tree
, fnum
);
998 /* check no-recall - don't pull a file from tape on a HSM */
999 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_NO_RECALL
;
1000 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1001 CHECK_STATUS(status
, NT_STATUS_OK
);
1002 fnum
= io
.ntcreatex
.out
.file
.fnum
;
1004 CHECK_VAL(io
.ntcreatex
.out
.oplock_level
, 0);
1005 CHECK_VAL(io
.ntcreatex
.out
.create_action
, NTCREATEX_ACTION_EXISTED
);
1006 CHECK_NTTIME(io
.ntcreatex
.out
.create_time
, create_time
);
1007 CHECK_NTTIME(io
.ntcreatex
.out
.access_time
, access_time
);
1008 CHECK_NTTIME(io
.ntcreatex
.out
.write_time
, write_time
);
1009 CHECK_NTTIME(io
.ntcreatex
.out
.change_time
, change_time
);
1010 CHECK_ALL_INFO(io
.ntcreatex
.out
.attrib
, attrib
);
1011 CHECK_ALL_INFO(io
.ntcreatex
.out
.alloc_size
, alloc_size
);
1012 CHECK_ALL_INFO(io
.ntcreatex
.out
.size
, size
);
1013 CHECK_ALL_INFO(io
.ntcreatex
.out
.is_directory
, directory
);
1014 CHECK_VAL(io
.ntcreatex
.out
.file_type
, FILE_TYPE_DISK
);
1015 smbcli_close(cli
->tree
, fnum
);
1017 /* Check some create options (these all should be ignored) */
1018 for (i
=0; i
< 32; i
++) {
1019 uint32_t create_option
= (1 << i
) & NTCREATEX_OPTIONS_MUST_IGNORE_MASK
;
1020 if (create_option
== 0) {
1023 io
.ntcreatex
.in
.create_options
= create_option
;
1024 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1025 if (!NT_STATUS_IS_OK(status
)) {
1026 torture_warning(tctx
, "ntcreatex create option 0x%08x "
1027 "gave %s - should give NT_STATUS_OK\n",
1028 create_option
, nt_errstr(status
));
1030 CHECK_STATUS(status
, NT_STATUS_OK
);
1031 fnum
= io
.ntcreatex
.out
.file
.fnum
;
1033 CHECK_VAL(io
.ntcreatex
.out
.oplock_level
, 0);
1034 CHECK_VAL(io
.ntcreatex
.out
.create_action
, NTCREATEX_ACTION_EXISTED
);
1035 CHECK_NTTIME(io
.ntcreatex
.out
.create_time
, create_time
);
1036 CHECK_NTTIME(io
.ntcreatex
.out
.access_time
, access_time
);
1037 CHECK_NTTIME(io
.ntcreatex
.out
.write_time
, write_time
);
1038 CHECK_NTTIME(io
.ntcreatex
.out
.change_time
, change_time
);
1039 CHECK_ALL_INFO(io
.ntcreatex
.out
.attrib
, attrib
);
1040 CHECK_ALL_INFO(io
.ntcreatex
.out
.alloc_size
, alloc_size
);
1041 CHECK_ALL_INFO(io
.ntcreatex
.out
.size
, size
);
1042 CHECK_ALL_INFO(io
.ntcreatex
.out
.is_directory
, directory
);
1043 CHECK_VAL(io
.ntcreatex
.out
.file_type
, FILE_TYPE_DISK
);
1044 smbcli_close(cli
->tree
, fnum
);
1047 io
.ntcreatex
.in
.file_attr
= 0;
1048 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN_IF
;
1049 io
.ntcreatex
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1051 /* Check for options that should return NOT_SUPPORTED, OK or INVALID_PARAMETER */
1053 not_supported_mask
= 0;
1054 invalid_parameter_mask
= 0;
1055 not_a_directory_mask
= 0;
1056 unexpected_mask
= 0;
1057 for (i
=0; i
< 32; i
++) {
1058 uint32_t create_option
= 1<<i
;
1059 if (create_option
& NTCREATEX_OPTIONS_DELETE_ON_CLOSE
) {
1062 io
.ntcreatex
.in
.create_options
= create_option
;
1063 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1064 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_SUPPORTED
)) {
1065 not_supported_mask
|= create_option
;
1066 } else if (NT_STATUS_EQUAL(status
, NT_STATUS_OK
)) {
1067 ok_mask
|= create_option
;
1068 smbcli_close(cli
->tree
, io
.ntcreatex
.out
.file
.fnum
);
1069 } else if (NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_PARAMETER
)) {
1070 invalid_parameter_mask
|= create_option
;
1071 } else if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_A_DIRECTORY
)) {
1072 not_a_directory_mask
|= 1<<i
;
1074 unexpected_mask
|= 1<<i
;
1075 torture_comment(tctx
, "create option 0x%08x returned %s\n",
1076 create_option
, nt_errstr(status
));
1080 CHECK_VAL(ok_mask
, 0x00efcfce);
1081 CHECK_VAL(not_a_directory_mask
, 0x00000001);
1082 CHECK_VAL(not_supported_mask
, 0x00002000);
1083 CHECK_VAL(invalid_parameter_mask
, 0xff100030);
1084 CHECK_VAL(unexpected_mask
, 0x00000000);
1086 smbcli_unlink(cli
->tree
, fname
);
1089 /* create a directory */
1090 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
1091 io
.ntcreatex
.in
.access_mask
= SEC_RIGHTS_FILE_ALL
;
1092 io
.ntcreatex
.in
.alloc_size
= 0;
1093 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_DIRECTORY
;
1094 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
1095 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
1096 io
.ntcreatex
.in
.create_options
= 0;
1097 io
.ntcreatex
.in
.fname
= dname
;
1100 smbcli_rmdir(cli
->tree
, fname
);
1101 smbcli_unlink(cli
->tree
, fname
);
1103 io
.ntcreatex
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1104 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1105 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1106 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
1107 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1108 CHECK_STATUS(status
, NT_STATUS_OK
);
1109 fnum
= io
.ntcreatex
.out
.file
.fnum
;
1111 CHECK_VAL(io
.ntcreatex
.out
.oplock_level
, 0);
1112 CHECK_VAL(io
.ntcreatex
.out
.create_action
, NTCREATEX_ACTION_CREATED
);
1113 CHECK_NTTIME(io
.ntcreatex
.out
.create_time
, create_time
);
1114 CHECK_NTTIME(io
.ntcreatex
.out
.access_time
, access_time
);
1115 CHECK_NTTIME(io
.ntcreatex
.out
.write_time
, write_time
);
1116 CHECK_NTTIME(io
.ntcreatex
.out
.change_time
, change_time
);
1117 CHECK_ALL_INFO(io
.ntcreatex
.out
.attrib
, attrib
);
1118 CHECK_VAL(io
.ntcreatex
.out
.attrib
& ~FILE_ATTRIBUTE_NONINDEXED
,
1119 FILE_ATTRIBUTE_DIRECTORY
);
1120 CHECK_ALL_INFO(io
.ntcreatex
.out
.alloc_size
, alloc_size
);
1121 CHECK_ALL_INFO(io
.ntcreatex
.out
.size
, size
);
1122 CHECK_ALL_INFO(io
.ntcreatex
.out
.is_directory
, directory
);
1123 CHECK_VAL(io
.ntcreatex
.out
.is_directory
, 1);
1124 CHECK_VAL(io
.ntcreatex
.out
.size
, 0);
1125 CHECK_VAL(io
.ntcreatex
.out
.alloc_size
, 0);
1126 CHECK_VAL(io
.ntcreatex
.out
.file_type
, FILE_TYPE_DISK
);
1127 smbcli_unlink(cli
->tree
, fname
);
1131 smbcli_close(cli
->tree
, fnum
);
1132 smbcli_deltree(cli
->tree
, BASEDIR
);
1138 test RAW_OPEN_NTCREATEX with an already opened and byte range locked file
1140 I've got an application that does a similar sequence of ntcreate&x,
1141 locking&x and another ntcreate&x with
1142 open_disposition==NTCREATEX_DISP_OVERWRITE_IF. Windows 2003 allows the
1145 static bool test_ntcreatex_brlocked(struct torture_context
*tctx
, struct smbcli_state
*cli
)
1147 union smb_open io
, io1
;
1149 struct smb_lock_entry lock
[1];
1150 const char *fname
= BASEDIR
"\\torture_ntcreatex.txt";
1154 if (!torture_setup_dir(cli
, BASEDIR
)) {
1158 torture_comment(tctx
, "Testing ntcreatex with a byte range locked file\n");
1160 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
1161 io
.ntcreatex
.in
.flags
= NTCREATEX_FLAGS_EXTENDED
;
1162 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
1163 io
.ntcreatex
.in
.access_mask
= 0x2019f;
1164 io
.ntcreatex
.in
.alloc_size
= 0;
1165 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1166 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
1167 NTCREATEX_SHARE_ACCESS_WRITE
;
1168 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
1169 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_NON_DIRECTORY_FILE
;
1170 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_IMPERSONATION
;
1171 io
.ntcreatex
.in
.security_flags
= NTCREATEX_SECURITY_DYNAMIC
|
1172 NTCREATEX_SECURITY_ALL
;
1173 io
.ntcreatex
.in
.fname
= fname
;
1175 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1176 CHECK_STATUS(status
, NT_STATUS_OK
);
1178 io2
.lockx
.level
= RAW_LOCK_LOCKX
;
1179 io2
.lockx
.in
.file
.fnum
= io
.ntcreatex
.out
.file
.fnum
;
1180 io2
.lockx
.in
.mode
= LOCKING_ANDX_LARGE_FILES
;
1181 io2
.lockx
.in
.timeout
= 0;
1182 io2
.lockx
.in
.ulock_cnt
= 0;
1183 io2
.lockx
.in
.lock_cnt
= 1;
1184 lock
[0].pid
= cli
->session
->pid
;
1186 lock
[0].count
= 0x1;
1187 io2
.lockx
.in
.locks
= &lock
[0];
1188 status
= smb_raw_lock(cli
->tree
, &io2
);
1189 CHECK_STATUS(status
, NT_STATUS_OK
);
1191 io1
.generic
.level
= RAW_OPEN_NTCREATEX
;
1192 io1
.ntcreatex
.in
.flags
= NTCREATEX_FLAGS_EXTENDED
;
1193 io1
.ntcreatex
.in
.root_fid
.fnum
= 0;
1194 io1
.ntcreatex
.in
.access_mask
= 0x20196;
1195 io1
.ntcreatex
.in
.alloc_size
= 0;
1196 io1
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1197 io1
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
1198 NTCREATEX_SHARE_ACCESS_WRITE
;
1199 io1
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OVERWRITE_IF
;
1200 io1
.ntcreatex
.in
.create_options
= 0;
1201 io1
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_IMPERSONATION
;
1202 io1
.ntcreatex
.in
.security_flags
= NTCREATEX_SECURITY_DYNAMIC
|
1203 NTCREATEX_SECURITY_ALL
;
1204 io1
.ntcreatex
.in
.fname
= fname
;
1206 status
= smb_raw_open(cli
->tree
, tctx
, &io1
);
1207 CHECK_STATUS(status
, NT_STATUS_OK
);
1210 smbcli_close(cli
->tree
, io
.ntcreatex
.out
.file
.fnum
);
1211 smbcli_close(cli
->tree
, io1
.ntcreatex
.out
.file
.fnum
);
1212 smbcli_deltree(cli
->tree
, BASEDIR
);
1219 static bool test_mknew(struct torture_context
*tctx
, struct smbcli_state
*cli
)
1222 const char *fname
= BASEDIR
"\\torture_mknew.txt";
1226 time_t basetime
= (time(NULL
) + 3600*24*3) & ~1;
1227 union smb_fileinfo finfo
;
1229 if (!torture_setup_dir(cli
, BASEDIR
)) {
1233 io
.mknew
.level
= RAW_OPEN_MKNEW
;
1234 io
.mknew
.in
.attrib
= 0;
1235 io
.mknew
.in
.write_time
= 0;
1236 io
.mknew
.in
.fname
= fname
;
1237 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1238 CHECK_STATUS(status
, NT_STATUS_OK
);
1239 fnum
= io
.mknew
.out
.file
.fnum
;
1241 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1242 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_COLLISION
);
1244 smbcli_close(cli
->tree
, fnum
);
1245 smbcli_unlink(cli
->tree
, fname
);
1247 /* make sure write_time works */
1248 io
.mknew
.in
.write_time
= basetime
;
1249 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1250 CHECK_STATUS(status
, NT_STATUS_OK
);
1251 fnum
= io
.mknew
.out
.file
.fnum
;
1252 CHECK_TIME(basetime
, write_time
);
1254 smbcli_close(cli
->tree
, fnum
);
1255 smbcli_unlink(cli
->tree
, fname
);
1257 /* make sure file_attrs works */
1258 io
.mknew
.in
.attrib
= FILE_ATTRIBUTE_HIDDEN
;
1259 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1260 CHECK_STATUS(status
, NT_STATUS_OK
);
1261 fnum
= io
.mknew
.out
.file
.fnum
;
1262 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_ARCHIVE
,
1263 attrib
& ~FILE_ATTRIBUTE_NONINDEXED
);
1266 smbcli_close(cli
->tree
, fnum
);
1267 smbcli_deltree(cli
->tree
, BASEDIR
);
1274 test RAW_OPEN_CREATE
1276 static bool test_create(struct torture_context
*tctx
, struct smbcli_state
*cli
)
1279 const char *fname
= BASEDIR
"\\torture_create.txt";
1283 time_t basetime
= (time(NULL
) + 3600*24*3) & ~1;
1284 union smb_fileinfo finfo
;
1286 if (!torture_setup_dir(cli
, BASEDIR
)) {
1290 io
.create
.level
= RAW_OPEN_CREATE
;
1291 io
.create
.in
.attrib
= 0;
1292 io
.create
.in
.write_time
= 0;
1293 io
.create
.in
.fname
= fname
;
1294 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1295 CHECK_STATUS(status
, NT_STATUS_OK
);
1296 fnum
= io
.create
.out
.file
.fnum
;
1298 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1299 CHECK_STATUS(status
, NT_STATUS_OK
);
1301 smbcli_close(cli
->tree
, io
.create
.out
.file
.fnum
);
1302 smbcli_close(cli
->tree
, fnum
);
1303 smbcli_unlink(cli
->tree
, fname
);
1305 /* make sure write_time works */
1306 io
.create
.in
.write_time
= basetime
;
1307 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1308 CHECK_STATUS(status
, NT_STATUS_OK
);
1309 fnum
= io
.create
.out
.file
.fnum
;
1310 CHECK_TIME(basetime
, write_time
);
1312 smbcli_close(cli
->tree
, fnum
);
1313 smbcli_unlink(cli
->tree
, fname
);
1315 /* make sure file_attrs works */
1316 io
.create
.in
.attrib
= FILE_ATTRIBUTE_HIDDEN
;
1317 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1318 CHECK_STATUS(status
, NT_STATUS_OK
);
1319 fnum
= io
.create
.out
.file
.fnum
;
1320 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_ARCHIVE
,
1321 attrib
& ~FILE_ATTRIBUTE_NONINDEXED
);
1324 smbcli_close(cli
->tree
, fnum
);
1325 smbcli_deltree(cli
->tree
, BASEDIR
);
1334 static bool test_ctemp(struct torture_context
*tctx
, struct smbcli_state
*cli
)
1340 time_t basetime
= (time(NULL
) + 3600*24*3) & ~1;
1341 union smb_fileinfo finfo
;
1342 const char *name
, *fname
= NULL
;
1344 if (!torture_setup_dir(cli
, BASEDIR
)) {
1348 io
.ctemp
.level
= RAW_OPEN_CTEMP
;
1349 io
.ctemp
.in
.attrib
= FILE_ATTRIBUTE_HIDDEN
;
1350 io
.ctemp
.in
.write_time
= basetime
;
1351 io
.ctemp
.in
.directory
= BASEDIR
;
1352 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1353 CHECK_STATUS(status
, NT_STATUS_OK
);
1354 fnum
= io
.ctemp
.out
.file
.fnum
;
1356 name
= io
.ctemp
.out
.name
;
1358 finfo
.generic
.level
= RAW_FILEINFO_NAME_INFO
;
1359 finfo
.generic
.in
.file
.fnum
= fnum
;
1360 status
= smb_raw_fileinfo(cli
->tree
, tctx
, &finfo
);
1361 CHECK_STATUS(status
, NT_STATUS_OK
);
1363 fname
= finfo
.name_info
.out
.fname
.s
;
1364 torture_comment(tctx
, "ctemp name=%s real name=%s\n", name
, fname
);
1367 smbcli_close(cli
->tree
, fnum
);
1368 smbcli_deltree(cli
->tree
, BASEDIR
);
1375 test chained RAW_OPEN_OPENX_READX
1377 static bool test_chained(struct torture_context
*tctx
, struct smbcli_state
*cli
)
1380 const char *fname
= BASEDIR
"\\torture_chained.txt";
1384 const char *buf
= "test";
1387 if (!torture_setup_dir(cli
, BASEDIR
)) {
1391 fnum
= create_complex_file(cli
, tctx
, fname
);
1393 smbcli_write(cli
->tree
, fnum
, 0, buf
, 0, sizeof(buf
));
1395 smbcli_close(cli
->tree
, fnum
);
1397 io
.openxreadx
.level
= RAW_OPEN_OPENX_READX
;
1398 io
.openxreadx
.in
.fname
= fname
;
1399 io
.openxreadx
.in
.flags
= OPENX_FLAGS_ADDITIONAL_INFO
;
1400 io
.openxreadx
.in
.open_mode
= OPENX_MODE_ACCESS_RDWR
;
1401 io
.openxreadx
.in
.open_func
= OPENX_OPEN_FUNC_OPEN
;
1402 io
.openxreadx
.in
.search_attrs
= 0;
1403 io
.openxreadx
.in
.file_attrs
= 0;
1404 io
.openxreadx
.in
.write_time
= 0;
1405 io
.openxreadx
.in
.size
= 1024*1024;
1406 io
.openxreadx
.in
.timeout
= 0;
1408 io
.openxreadx
.in
.offset
= 0;
1409 io
.openxreadx
.in
.mincnt
= sizeof(buf
);
1410 io
.openxreadx
.in
.maxcnt
= sizeof(buf
);
1411 io
.openxreadx
.in
.remaining
= 0;
1412 io
.openxreadx
.out
.data
= (uint8_t *)buf2
;
1414 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1415 CHECK_STATUS(status
, NT_STATUS_OK
);
1416 fnum
= io
.openxreadx
.out
.file
.fnum
;
1418 if (memcmp(buf
, buf2
, sizeof(buf
)) != 0) {
1419 torture_result(tctx
, TORTURE_FAIL
,
1420 "wrong data in reply buffer\n");
1425 smbcli_close(cli
->tree
, fnum
);
1426 smbcli_deltree(cli
->tree
, BASEDIR
);
1432 test RAW_OPEN_OPENX without a leading slash on the path.
1433 NetApp filers are known to fail on this.
1436 static bool test_no_leading_slash(struct torture_context
*tctx
, struct smbcli_state
*cli
)
1439 const char *fname
= BASEDIR
"\\torture_no_leading_slash.txt";
1443 const char *buf
= "test";
1445 if (!torture_setup_dir(cli
, BASEDIR
)) {
1449 smbcli_unlink(cli
->tree
, fname
);
1451 /* Create the file */
1452 fnum
= create_complex_file(cli
, tctx
, fname
);
1453 smbcli_write(cli
->tree
, fnum
, 0, buf
, 0, sizeof(buf
));
1454 smbcli_close(cli
->tree
, fnum
);
1456 /* Prepare to open the file using path without leading slash */
1457 io
.openx
.level
= RAW_OPEN_OPENX
;
1458 io
.openx
.in
.fname
= fname
+ 1;
1459 io
.openx
.in
.flags
= OPENX_FLAGS_ADDITIONAL_INFO
;
1460 io
.openx
.in
.open_mode
= OPENX_MODE_ACCESS_RDWR
;
1461 io
.openx
.in
.open_func
= OPENX_OPEN_FUNC_OPEN
;
1462 io
.openx
.in
.search_attrs
= 0;
1463 io
.openx
.in
.file_attrs
= 0;
1464 io
.openx
.in
.write_time
= 0;
1465 io
.openx
.in
.size
= 1024*1024;
1466 io
.openx
.in
.timeout
= 0;
1468 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1469 CHECK_STATUS(status
, NT_STATUS_OK
);
1470 fnum
= io
.openx
.out
.file
.fnum
;
1473 smbcli_close(cli
->tree
, fnum
);
1474 smbcli_deltree(cli
->tree
, BASEDIR
);
1480 test RAW_OPEN_OPENX against an existing directory to
1481 ensure it returns NT_STATUS_FILE_IS_A_DIRECTORY.
1482 Samba 3.2.0 - 3.2.6 are known to fail this.
1485 static bool test_openx_over_dir(struct torture_context
*tctx
, struct smbcli_state
*cli
)
1488 const char *fname
= BASEDIR
"\\openx_over_dir";
1494 if (!torture_setup_dir(cli
, BASEDIR
)) {
1498 /* Create the Directory */
1499 status
= create_directory_handle(cli
->tree
, fname
, &d_fnum
);
1500 smbcli_close(cli
->tree
, d_fnum
);
1502 /* Prepare to open the file over the directory. */
1503 io
.openx
.level
= RAW_OPEN_OPENX
;
1504 io
.openx
.in
.fname
= fname
;
1505 io
.openx
.in
.flags
= OPENX_FLAGS_ADDITIONAL_INFO
;
1506 io
.openx
.in
.open_mode
= OPENX_MODE_ACCESS_RDWR
;
1507 io
.openx
.in
.open_func
= OPENX_OPEN_FUNC_OPEN
;
1508 io
.openx
.in
.search_attrs
= 0;
1509 io
.openx
.in
.file_attrs
= 0;
1510 io
.openx
.in
.write_time
= 0;
1511 io
.openx
.in
.size
= 1024*1024;
1512 io
.openx
.in
.timeout
= 0;
1514 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1515 CHECK_STATUS(status
, NT_STATUS_FILE_IS_A_DIRECTORY
);
1516 fnum
= io
.openx
.out
.file
.fnum
;
1519 smbcli_close(cli
->tree
, fnum
);
1520 smbcli_deltree(cli
->tree
, BASEDIR
);
1526 /* A little torture test to expose a race condition in Samba 3.0.20 ... :-) */
1528 static bool test_raw_open_multi(struct torture_context
*tctx
, struct smbcli_state
*cli_ignored
)
1530 struct smbcli_state
*cli
;
1531 TALLOC_CTX
*mem_ctx
= talloc_init("torture_test_oplock_multi");
1532 const char *fname
= "\\test_oplock.dat";
1536 struct smbcli_state
**clients
;
1537 struct smbcli_request
**requests
;
1538 union smb_open
*ios
;
1539 const char *host
= torture_setting_string(tctx
, "host", NULL
);
1540 const char *share
= torture_setting_string(tctx
, "share", NULL
);
1541 int i
, num_files
= 3;
1543 int num_collision
= 0;
1545 clients
= talloc_array(mem_ctx
, struct smbcli_state
*, num_files
);
1546 requests
= talloc_array(mem_ctx
, struct smbcli_request
*, num_files
);
1547 ios
= talloc_array(mem_ctx
, union smb_open
, num_files
);
1548 if ((tctx
->ev
== NULL
) || (clients
== NULL
) || (requests
== NULL
) ||
1550 torture_result(tctx
, TORTURE_FAIL
, "(%s): talloc failed\n",
1555 if (!torture_open_connection_share(mem_ctx
, &cli
, tctx
, host
, share
, tctx
->ev
)) {
1559 cli
->tree
->session
->transport
->options
.request_timeout
= 60;
1561 for (i
=0; i
<num_files
; i
++) {
1562 if (!torture_open_connection_share(mem_ctx
, &(clients
[i
]),
1563 tctx
, host
, share
, tctx
->ev
)) {
1564 torture_result(tctx
, TORTURE_FAIL
,
1565 "(%s): Could not open %d'th connection\n",
1569 clients
[i
]->tree
->session
->transport
->options
.request_timeout
= 60;
1573 smbcli_unlink(cli
->tree
, fname
);
1576 base ntcreatex parms
1578 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
1579 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
1580 io
.ntcreatex
.in
.access_mask
= SEC_RIGHTS_FILE_ALL
;
1581 io
.ntcreatex
.in
.alloc_size
= 0;
1582 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1583 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
1584 NTCREATEX_SHARE_ACCESS_WRITE
|
1585 NTCREATEX_SHARE_ACCESS_DELETE
;
1586 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
1587 io
.ntcreatex
.in
.create_options
= 0;
1588 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
1589 io
.ntcreatex
.in
.security_flags
= 0;
1590 io
.ntcreatex
.in
.fname
= fname
;
1591 io
.ntcreatex
.in
.flags
= 0;
1593 for (i
=0; i
<num_files
; i
++) {
1595 requests
[i
] = smb_raw_open_send(clients
[i
]->tree
, &ios
[i
]);
1596 if (requests
[i
] == NULL
) {
1597 torture_result(tctx
, TORTURE_FAIL
,
1598 "(%s): could not send %d'th request\n",
1604 torture_comment(tctx
, "waiting for replies\n");
1606 bool unreplied
= false;
1607 for (i
=0; i
<num_files
; i
++) {
1608 if (requests
[i
] == NULL
) {
1611 if (requests
[i
]->state
< SMBCLI_REQUEST_DONE
) {
1615 status
= smb_raw_open_recv(requests
[i
], mem_ctx
,
1618 torture_comment(tctx
, "File %d returned status %s\n", i
,
1621 if (NT_STATUS_IS_OK(status
)) {
1625 if (NT_STATUS_EQUAL(status
,
1626 NT_STATUS_OBJECT_NAME_COLLISION
)) {
1636 if (event_loop_once(tctx
->ev
) != 0) {
1637 torture_result(tctx
, TORTURE_FAIL
,
1638 "(%s): event_loop_once failed\n", __location__
);
1643 if ((num_ok
!= 1) || (num_ok
+ num_collision
!= num_files
)) {
1647 for (i
=0; i
<num_files
; i
++) {
1648 torture_close_connection(clients
[i
]);
1650 talloc_free(mem_ctx
);
1655 test opening for delete on a read-only attribute file.
1657 static bool test_open_for_delete(struct torture_context
*tctx
, struct smbcli_state
*cli
)
1660 union smb_fileinfo finfo
;
1661 const char *fname
= BASEDIR
"\\torture_open_for_delete.txt";
1666 if (!torture_setup_dir(cli
, BASEDIR
)) {
1670 /* reasonable default parameters */
1671 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
1672 io
.ntcreatex
.in
.flags
= NTCREATEX_FLAGS_EXTENDED
;
1673 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
1674 io
.ntcreatex
.in
.alloc_size
= 0;
1675 io
.ntcreatex
.in
.access_mask
= SEC_RIGHTS_FILE_ALL
;
1676 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_READONLY
;
1677 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
1678 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
1679 io
.ntcreatex
.in
.create_options
= 0;
1680 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
1681 io
.ntcreatex
.in
.security_flags
= 0;
1682 io
.ntcreatex
.in
.fname
= fname
;
1684 /* Create the readonly file. */
1686 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1687 CHECK_STATUS(status
, NT_STATUS_OK
);
1688 fnum
= io
.ntcreatex
.out
.file
.fnum
;
1690 CHECK_VAL(io
.ntcreatex
.out
.oplock_level
, 0);
1691 io
.ntcreatex
.in
.create_options
= 0;
1692 CHECK_VAL(io
.ntcreatex
.out
.create_action
, NTCREATEX_ACTION_CREATED
);
1693 CHECK_ALL_INFO(io
.ntcreatex
.out
.attrib
, attrib
);
1694 smbcli_close(cli
->tree
, fnum
);
1696 /* Now try and open for delete only - should succeed. */
1697 io
.ntcreatex
.in
.access_mask
= SEC_STD_DELETE
;
1698 io
.ntcreatex
.in
.file_attr
= 0;
1699 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
| NTCREATEX_SHARE_ACCESS_DELETE
;
1700 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
1701 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1702 CHECK_STATUS(status
, NT_STATUS_OK
);
1704 smbcli_unlink(cli
->tree
, fname
);
1707 smbcli_close(cli
->tree
, fnum
);
1708 smbcli_deltree(cli
->tree
, BASEDIR
);
1714 test chained RAW_OPEN_NTCREATEX_READX
1715 Send chained NTCREATEX_READX on a file that doesn't exist, then create
1716 the file and try again.
1718 static bool test_chained_ntcreatex_readx(struct torture_context
*tctx
, struct smbcli_state
*cli
)
1720 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
1722 const char *fname
= BASEDIR
"\\torture_chained.txt";
1726 const char *buf
= "test";
1729 if (!torture_setup_dir(cli
, BASEDIR
)) {
1733 torture_comment(tctx
, "Checking RAW_NTCREATEX_READX chained on "
1734 "non-existant file \n");
1736 /* ntcreatex parameters */
1737 io
.generic
.level
= RAW_OPEN_NTCREATEX_READX
;
1738 io
.ntcreatexreadx
.in
.flags
= 0;
1739 io
.ntcreatexreadx
.in
.root_fid
.fnum
= 0;
1740 io
.ntcreatexreadx
.in
.access_mask
= SEC_FILE_READ_DATA
;
1741 io
.ntcreatexreadx
.in
.alloc_size
= 0;
1742 io
.ntcreatexreadx
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1743 io
.ntcreatexreadx
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
1744 NTCREATEX_SHARE_ACCESS_WRITE
| NTCREATEX_SHARE_ACCESS_DELETE
;
1745 io
.ntcreatexreadx
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
1746 io
.ntcreatexreadx
.in
.create_options
= 0;
1747 io
.ntcreatexreadx
.in
.impersonation
= NTCREATEX_IMPERSONATION_IMPERSONATION
;
1748 io
.ntcreatexreadx
.in
.security_flags
= 0;
1749 io
.ntcreatexreadx
.in
.fname
= fname
;
1751 /* readx parameters */
1752 io
.ntcreatexreadx
.in
.offset
= 0;
1753 io
.ntcreatexreadx
.in
.mincnt
= sizeof(buf
);
1754 io
.ntcreatexreadx
.in
.maxcnt
= sizeof(buf
);
1755 io
.ntcreatexreadx
.in
.remaining
= 0;
1756 io
.ntcreatexreadx
.out
.data
= (uint8_t *)buf2
;
1758 /* try to open the non-existant file */
1759 status
= smb_raw_open(cli
->tree
, mem_ctx
, &io
);
1760 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
1761 fnum
= io
.ntcreatexreadx
.out
.file
.fnum
;
1763 smbcli_close(cli
->tree
, fnum
);
1764 smbcli_unlink(cli
->tree
, fname
);
1766 torture_comment(tctx
, "Checking RAW_NTCREATEX_READX chained on "
1767 "existing file \n");
1769 fnum
= create_complex_file(cli
, mem_ctx
, fname
);
1770 smbcli_write(cli
->tree
, fnum
, 0, buf
, 0, sizeof(buf
));
1771 smbcli_close(cli
->tree
, fnum
);
1773 status
= smb_raw_open(cli
->tree
, mem_ctx
, &io
);
1774 CHECK_STATUS(status
, NT_STATUS_OK
);
1775 fnum
= io
.ntcreatexreadx
.out
.file
.fnum
;
1777 if (memcmp(buf
, buf2
, sizeof(buf
)) != 0) {
1778 torture_result(tctx
, TORTURE_FAIL
,
1779 "(%s): wrong data in reply buffer\n", __location__
);
1784 smbcli_close(cli
->tree
, fnum
);
1785 smbcli_deltree(cli
->tree
, BASEDIR
);
1786 talloc_free(mem_ctx
);
1791 static bool test_ntcreatex_opendisp_dir(struct torture_context
*tctx
,
1792 struct smbcli_state
*cli
)
1794 const char *dname
= BASEDIR
"\\torture_ntcreatex_opendisp_dir";
1801 NTSTATUS correct_status
;
1802 } open_funcs_dir
[] = {
1803 { NTCREATEX_DISP_SUPERSEDE
, true, NT_STATUS_INVALID_PARAMETER
},
1804 { NTCREATEX_DISP_SUPERSEDE
, false, NT_STATUS_INVALID_PARAMETER
},
1805 { NTCREATEX_DISP_OPEN
, true, NT_STATUS_OK
},
1806 { NTCREATEX_DISP_OPEN
, false, NT_STATUS_OBJECT_NAME_NOT_FOUND
},
1807 { NTCREATEX_DISP_CREATE
, true, NT_STATUS_OBJECT_NAME_COLLISION
},
1808 { NTCREATEX_DISP_CREATE
, false, NT_STATUS_OK
},
1809 { NTCREATEX_DISP_OPEN_IF
, true, NT_STATUS_OK
},
1810 { NTCREATEX_DISP_OPEN_IF
, false, NT_STATUS_OK
},
1811 { NTCREATEX_DISP_OVERWRITE
, true, NT_STATUS_INVALID_PARAMETER
},
1812 { NTCREATEX_DISP_OVERWRITE
, false, NT_STATUS_INVALID_PARAMETER
},
1813 { NTCREATEX_DISP_OVERWRITE_IF
, true, NT_STATUS_INVALID_PARAMETER
},
1814 { NTCREATEX_DISP_OVERWRITE_IF
, false, NT_STATUS_INVALID_PARAMETER
},
1815 { 6, true, NT_STATUS_INVALID_PARAMETER
},
1816 { 6, false, NT_STATUS_INVALID_PARAMETER
},
1821 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
1822 io
.ntcreatex
.in
.flags
= NTCREATEX_FLAGS_EXTENDED
;
1823 io
.ntcreatex
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1824 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_DIRECTORY
;
1825 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
1826 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1827 io
.ntcreatex
.in
.fname
= dname
;
1829 if (!torture_setup_dir(cli
, BASEDIR
)) {
1833 smbcli_rmdir(cli
->tree
, dname
);
1834 smbcli_unlink(cli
->tree
, dname
);
1836 /* test the open disposition for directories */
1837 torture_comment(tctx
, "Testing open dispositions for directories...\n");
1839 for (i
=0; i
<ARRAY_SIZE(open_funcs_dir
); i
++) {
1840 if (open_funcs_dir
[i
].dir_exists
) {
1841 status
= smbcli_mkdir(cli
->tree
, dname
);
1842 if (!NT_STATUS_IS_OK(status
)) {
1843 torture_result(tctx
, TORTURE_FAIL
,
1844 "(%s): Failed to make directory "
1845 "%s - %s\n", __location__
, dname
,
1846 smbcli_errstr(cli
->tree
));
1852 io
.ntcreatex
.in
.open_disposition
= open_funcs_dir
[i
].open_disp
;
1853 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1854 if (!NT_STATUS_EQUAL(status
, open_funcs_dir
[i
].correct_status
)) {
1855 torture_result(tctx
, TORTURE_FAIL
,
1856 "(%s) incorrect status %s should be %s "
1857 "(i=%d dir_exists=%d open_disp=%d)\n",
1858 __location__
, nt_errstr(status
),
1859 nt_errstr(open_funcs_dir
[i
].correct_status
),
1860 i
, (int)open_funcs_dir
[i
].dir_exists
,
1861 (int)open_funcs_dir
[i
].open_disp
);
1864 if (NT_STATUS_IS_OK(status
) || open_funcs_dir
[i
].dir_exists
) {
1865 smbcli_close(cli
->tree
, io
.ntcreatex
.out
.file
.fnum
);
1866 smbcli_rmdir(cli
->tree
, dname
);
1871 smbcli_deltree(cli
->tree
, BASEDIR
);
1877 * Test what happens when trying to open a file with directory parameters and
1878 * vice-versa. Also test that NTCREATEX_OPTIONS_DIRECTORY is treated as
1879 * mandatory and FILE_ATTRIBUTE_DIRECTORY is advisory for directory
1882 static bool test_ntcreatexdir(struct torture_context
*tctx
,
1883 struct smbcli_state
*cli
)
1886 const char *fname
= BASEDIR
"\\torture_ntcreatex.txt";
1887 const char *dname
= BASEDIR
"\\torture_ntcreatex_dir";
1894 uint32_t create_options
;
1895 NTSTATUS correct_status
;
1897 { NTCREATEX_DISP_SUPERSEDE
, 0, NTCREATEX_OPTIONS_DIRECTORY
,
1898 NT_STATUS_INVALID_PARAMETER
},
1899 { NTCREATEX_DISP_OPEN
, 0, NTCREATEX_OPTIONS_DIRECTORY
,
1900 NT_STATUS_OBJECT_NAME_NOT_FOUND
},
1901 { NTCREATEX_DISP_CREATE
, 0, NTCREATEX_OPTIONS_DIRECTORY
,
1903 { NTCREATEX_DISP_OPEN_IF
, 0, NTCREATEX_OPTIONS_DIRECTORY
,
1905 { NTCREATEX_DISP_OVERWRITE
, 0, NTCREATEX_OPTIONS_DIRECTORY
,
1906 NT_STATUS_INVALID_PARAMETER
},
1907 { NTCREATEX_DISP_OVERWRITE_IF
, 0, NTCREATEX_OPTIONS_DIRECTORY
,
1908 NT_STATUS_INVALID_PARAMETER
},
1909 { NTCREATEX_DISP_SUPERSEDE
, FILE_ATTRIBUTE_DIRECTORY
, 0,
1911 { NTCREATEX_DISP_OPEN
, FILE_ATTRIBUTE_DIRECTORY
, 0,
1912 NT_STATUS_OBJECT_NAME_NOT_FOUND
},
1913 { NTCREATEX_DISP_CREATE
, FILE_ATTRIBUTE_DIRECTORY
, 0,
1915 { NTCREATEX_DISP_OPEN_IF
, FILE_ATTRIBUTE_DIRECTORY
, 0,
1917 { NTCREATEX_DISP_OVERWRITE
, FILE_ATTRIBUTE_DIRECTORY
, 0,
1918 NT_STATUS_OBJECT_NAME_NOT_FOUND
},
1919 { NTCREATEX_DISP_OVERWRITE_IF
, FILE_ATTRIBUTE_DIRECTORY
, 0,
1924 if (!torture_setup_dir(cli
, BASEDIR
)) {
1928 /* setup some base params. */
1929 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
1930 io
.ntcreatex
.in
.flags
= NTCREATEX_FLAGS_EXTENDED
;
1931 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
1932 io
.ntcreatex
.in
.access_mask
= SEC_RIGHTS_FILE_ALL
;
1933 io
.ntcreatex
.in
.alloc_size
= 0;
1934 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
1935 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
1936 io
.ntcreatex
.in
.security_flags
= 0;
1937 io
.ntcreatex
.in
.fname
= fname
;
1940 * Test the validity checking for create dispositions, which is done
1941 * against the requested parameters rather than what's actually on
1944 for (i
=0; i
<ARRAY_SIZE(open_funcs
); i
++) {
1945 io
.ntcreatex
.in
.open_disposition
= open_funcs
[i
].open_disp
;
1946 io
.ntcreatex
.in
.file_attr
= open_funcs
[i
].file_attr
;
1947 io
.ntcreatex
.in
.create_options
= open_funcs
[i
].create_options
;
1948 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1949 if (!NT_STATUS_EQUAL(status
, open_funcs
[i
].correct_status
)) {
1950 torture_result(tctx
, TORTURE_FAIL
,
1951 "(%s) incorrect status %s should be %s "
1952 "(i=%d open_disp=%d)\n",
1953 __location__
, nt_errstr(status
),
1954 nt_errstr(open_funcs
[i
].correct_status
),
1955 i
, (int)open_funcs
[i
].open_disp
);
1958 /* Close and delete the file. */
1959 if (NT_STATUS_IS_OK(status
)) {
1960 if (open_funcs
[i
].create_options
!= 0) {
1961 /* out attrib should be a directory. */
1962 torture_assert_int_equal(tctx
,
1963 io
.ntcreatex
.out
.attrib
,
1964 FILE_ATTRIBUTE_DIRECTORY
, "should have "
1965 "created a directory");
1967 smbcli_close(cli
->tree
,
1968 io
.ntcreatex
.out
.file
.fnum
);
1970 /* Make sure unlink fails. */
1971 status
= smbcli_unlink(cli
->tree
, fname
);
1972 torture_assert_ntstatus_equal(tctx
, status
,
1973 NT_STATUS_FILE_IS_A_DIRECTORY
,
1974 "unlink should fail for a directory");
1976 status
= smbcli_rmdir(cli
->tree
, fname
);
1977 torture_assert_ntstatus_ok(tctx
, status
,
1980 torture_assert_int_equal(tctx
,
1981 io
.ntcreatex
.out
.attrib
,
1982 FILE_ATTRIBUTE_ARCHIVE
, "should not have "
1983 "created a directory");
1985 smbcli_close(cli
->tree
,
1986 io
.ntcreatex
.out
.file
.fnum
);
1988 /* Make sure rmdir fails. */
1989 status
= smbcli_rmdir(cli
->tree
, fname
);
1990 torture_assert_ntstatus_equal(tctx
, status
,
1991 NT_STATUS_NOT_A_DIRECTORY
,
1992 "rmdir should fail for a file");
1994 status
= smbcli_unlink(cli
->tree
, fname
);
1995 torture_assert_ntstatus_ok(tctx
, status
,
2001 /* Create a file. */
2002 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
2003 io
.ntcreatex
.in
.create_options
= 0;
2004 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
2005 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
2006 torture_assert_ntstatus_ok(tctx
, status
, "Failed to create file.");
2007 smbcli_close(cli
->tree
, io
.ntcreatex
.out
.file
.fnum
);
2009 /* Try and open the file with file_attr_dir and check the error. */
2010 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_DIRECTORY
;
2011 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
2013 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
2014 torture_assert_ntstatus_ok(tctx
, status
, "FILE_ATTRIBUTE_DIRECTORY "
2015 "doesn't produce a hard failure.");
2016 smbcli_close(cli
->tree
, io
.ntcreatex
.out
.file
.fnum
);
2018 /* Try and open file with createx_option_dir and check the error. */
2019 io
.ntcreatex
.in
.file_attr
= 0;
2020 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
2022 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
2023 torture_assert_ntstatus_equal(tctx
, status
, NT_STATUS_NOT_A_DIRECTORY
,
2024 "NTCREATEX_OPTIONS_DIRECTORY will a file from being opened.");
2025 smbcli_close(cli
->tree
, io
.ntcreatex
.out
.file
.fnum
);
2027 /* Delete the file and move onto directory testing. */
2028 smbcli_unlink(cli
->tree
, fname
);
2030 /* Now try some tests on a directory. */
2031 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
2032 io
.ntcreatex
.in
.file_attr
= 0;
2033 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
2034 io
.ntcreatex
.in
.fname
= dname
;
2036 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
2037 torture_assert_ntstatus_ok(tctx
, status
, "Failed to create dir.");
2039 /* out attrib should be a directory. */
2040 torture_assert_int_equal(tctx
, io
.ntcreatex
.out
.attrib
,
2041 FILE_ATTRIBUTE_DIRECTORY
, "should have created a directory");
2043 smbcli_close(cli
->tree
, io
.ntcreatex
.out
.file
.fnum
);
2045 /* Try and open it with normal attr and check the error. */
2046 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
2047 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
2049 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
2050 torture_assert_ntstatus_ok(tctx
, status
, "FILE_ATTRIBUTE_NORMAL "
2051 "doesn't produce a hard failure.");
2052 smbcli_close(cli
->tree
, io
.ntcreatex
.out
.file
.fnum
);
2054 /* Try and open it with file create_options and check the error. */
2055 io
.ntcreatex
.in
.file_attr
= 0;
2056 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_NON_DIRECTORY_FILE
;
2058 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
2059 torture_assert_ntstatus_equal(tctx
, status
,
2060 NT_STATUS_FILE_IS_A_DIRECTORY
,
2061 "NTCREATEX_OPTIONS_NON_DIRECTORY_FILE should be returned ");
2062 smbcli_close(cli
->tree
, io
.ntcreatex
.out
.file
.fnum
);
2064 smbcli_deltree(cli
->tree
, BASEDIR
);
2069 /* basic testing of all RAW_OPEN_* calls
2071 struct torture_suite
*torture_raw_open(TALLOC_CTX
*mem_ctx
)
2073 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "open");
2075 torture_suite_add_1smb_test(suite
, "brlocked", test_ntcreatex_brlocked
);
2076 torture_suite_add_1smb_test(suite
, "open", test_open
);
2077 torture_suite_add_1smb_test(suite
, "open-multi", test_raw_open_multi
);
2078 torture_suite_add_1smb_test(suite
, "openx", test_openx
);
2079 torture_suite_add_1smb_test(suite
, "ntcreatex", test_ntcreatex
);
2080 torture_suite_add_1smb_test(suite
, "nttrans-create", test_nttrans_create
);
2081 torture_suite_add_1smb_test(suite
, "t2open", test_t2open
);
2082 torture_suite_add_1smb_test(suite
, "mknew", test_mknew
);
2083 torture_suite_add_1smb_test(suite
, "create", test_create
);
2084 torture_suite_add_1smb_test(suite
, "ctemp", test_ctemp
);
2085 torture_suite_add_1smb_test(suite
, "chained-openx", test_chained
);
2086 torture_suite_add_1smb_test(suite
, "chained-ntcreatex", test_chained_ntcreatex_readx
);
2087 torture_suite_add_1smb_test(suite
, "no-leading-slash", test_no_leading_slash
);
2088 torture_suite_add_1smb_test(suite
, "openx-over-dir", test_openx_over_dir
);
2089 torture_suite_add_1smb_test(suite
, "open-for-delete", test_open_for_delete
);
2090 torture_suite_add_1smb_test(suite
, "opendisp-dir", test_ntcreatex_opendisp_dir
);
2091 torture_suite_add_1smb_test(suite
, "ntcreatedir", test_ntcreatexdir
);