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 (labs(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; \
115 if (llabs((int64_t)(t-t2)) > 20000) { \
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 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
), "Failed to setup up test directory: " BASEDIR
);
172 io
.openold
.level
= RAW_OPEN_OPEN
;
173 io
.openold
.in
.fname
= fname
;
174 io
.openold
.in
.open_mode
= OPEN_FLAGS_FCB
;
175 io
.openold
.in
.search_attrs
= 0;
176 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
177 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
178 fnum
= io
.openold
.out
.file
.fnum
;
180 smbcli_unlink(cli
->tree
, fname
);
182 smbcli_close(cli
->tree
, fnum
);
184 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
185 CHECK_STATUS(status
, NT_STATUS_OK
);
186 fnum
= io
.openold
.out
.file
.fnum
;
187 CHECK_RDWR(fnum
, RDWR_RDWR
);
189 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
190 CHECK_STATUS(status
, NT_STATUS_OK
);
191 fnum2
= io
.openold
.out
.file
.fnum
;
192 CHECK_RDWR(fnum2
, RDWR_RDWR
);
193 smbcli_close(cli
->tree
, fnum2
);
194 smbcli_close(cli
->tree
, fnum
);
196 /* check the read/write modes */
197 io
.openold
.level
= RAW_OPEN_OPEN
;
198 io
.openold
.in
.fname
= fname
;
199 io
.openold
.in
.search_attrs
= 0;
201 io
.openold
.in
.open_mode
= OPEN_FLAGS_OPEN_READ
;
202 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
203 CHECK_STATUS(status
, NT_STATUS_OK
);
204 fnum
= io
.openold
.out
.file
.fnum
;
205 CHECK_RDWR(fnum
, RDWR_RDONLY
);
206 smbcli_close(cli
->tree
, fnum
);
208 io
.openold
.in
.open_mode
= OPEN_FLAGS_OPEN_WRITE
;
209 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
210 CHECK_STATUS(status
, NT_STATUS_OK
);
211 fnum
= io
.openold
.out
.file
.fnum
;
212 CHECK_RDWR(fnum
, RDWR_WRONLY
);
213 smbcli_close(cli
->tree
, fnum
);
215 io
.openold
.in
.open_mode
= OPEN_FLAGS_OPEN_RDWR
;
216 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
217 CHECK_STATUS(status
, NT_STATUS_OK
);
218 fnum
= io
.openold
.out
.file
.fnum
;
219 CHECK_RDWR(fnum
, RDWR_RDWR
);
220 smbcli_close(cli
->tree
, fnum
);
222 /* check the share modes roughly - not a complete matrix */
223 io
.openold
.in
.open_mode
= OPEN_FLAGS_OPEN_RDWR
| OPEN_FLAGS_DENY_WRITE
;
224 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
225 CHECK_STATUS(status
, NT_STATUS_OK
);
226 fnum
= io
.openold
.out
.file
.fnum
;
227 CHECK_RDWR(fnum
, RDWR_RDWR
);
229 if (io
.openold
.in
.open_mode
!= io
.openold
.out
.rmode
) {
230 torture_warning(tctx
, "(%s) rmode should equal open_mode - 0x%x 0x%x\n",
231 __location__
, io
.openold
.out
.rmode
, io
.openold
.in
.open_mode
);
234 io
.openold
.in
.open_mode
= OPEN_FLAGS_OPEN_RDWR
| OPEN_FLAGS_DENY_NONE
;
235 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
236 CHECK_STATUS(status
, NT_STATUS_SHARING_VIOLATION
);
238 io
.openold
.in
.open_mode
= OPEN_FLAGS_OPEN_READ
| OPEN_FLAGS_DENY_NONE
;
239 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
240 CHECK_STATUS(status
, NT_STATUS_OK
);
241 fnum2
= io
.openold
.out
.file
.fnum
;
242 CHECK_RDWR(fnum2
, RDWR_RDONLY
);
243 smbcli_close(cli
->tree
, fnum
);
244 smbcli_close(cli
->tree
, fnum2
);
247 /* check the returned write time */
248 io
.openold
.level
= RAW_OPEN_OPEN
;
249 io
.openold
.in
.fname
= fname
;
250 io
.openold
.in
.search_attrs
= 0;
251 io
.openold
.in
.open_mode
= OPEN_FLAGS_OPEN_READ
;
252 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
253 CHECK_STATUS(status
, NT_STATUS_OK
);
254 fnum
= io
.openold
.out
.file
.fnum
;
256 /* check other reply fields */
257 CHECK_TIME(io
.openold
.out
.write_time
, write_time
);
258 CHECK_ALL_INFO(io
.openold
.out
.size
, size
);
259 CHECK_ALL_INFO(io
.openold
.out
.attrib
, attrib
& ~FILE_ATTRIBUTE_NONINDEXED
);
262 smbcli_close(cli
->tree
, fnum
);
263 smbcli_deltree(cli
->tree
, BASEDIR
);
272 static bool test_openx(struct torture_context
*tctx
, struct smbcli_state
*cli
)
275 union smb_fileinfo finfo
;
276 const char *fname
= BASEDIR
"\\torture_openx.txt";
277 const char *fname_exe
= BASEDIR
"\\torture_openx.exe";
279 int fnum
= -1, fnum2
;
286 NTSTATUS correct_status
;
288 { OPENX_OPEN_FUNC_OPEN
, true, NT_STATUS_OK
},
289 { OPENX_OPEN_FUNC_OPEN
, false, NT_STATUS_OBJECT_NAME_NOT_FOUND
},
290 { OPENX_OPEN_FUNC_OPEN
| OPENX_OPEN_FUNC_CREATE
, true, NT_STATUS_OK
},
291 { OPENX_OPEN_FUNC_OPEN
| OPENX_OPEN_FUNC_CREATE
, false, NT_STATUS_OK
},
292 { OPENX_OPEN_FUNC_FAIL
, true, NT_STATUS_DOS(ERRDOS
, ERRbadaccess
) },
293 { OPENX_OPEN_FUNC_FAIL
, false, NT_STATUS_DOS(ERRDOS
, ERRbadaccess
) },
294 { OPENX_OPEN_FUNC_FAIL
| OPENX_OPEN_FUNC_CREATE
, true, NT_STATUS_OBJECT_NAME_COLLISION
},
295 { OPENX_OPEN_FUNC_FAIL
| OPENX_OPEN_FUNC_CREATE
, false, NT_STATUS_OK
},
296 { OPENX_OPEN_FUNC_TRUNC
, true, NT_STATUS_OK
},
297 { OPENX_OPEN_FUNC_TRUNC
, false, NT_STATUS_OBJECT_NAME_NOT_FOUND
},
298 { OPENX_OPEN_FUNC_TRUNC
| OPENX_OPEN_FUNC_CREATE
, true, NT_STATUS_OK
},
299 { OPENX_OPEN_FUNC_TRUNC
| OPENX_OPEN_FUNC_CREATE
, false, NT_STATUS_OK
},
302 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
), "Failed to setup up test directory: " BASEDIR
);
304 io
.openx
.level
= RAW_OPEN_OPENX
;
305 io
.openx
.in
.fname
= fname
;
306 io
.openx
.in
.flags
= OPENX_FLAGS_ADDITIONAL_INFO
;
307 io
.openx
.in
.open_mode
= OPENX_MODE_ACCESS_RDWR
;
308 io
.openx
.in
.search_attrs
= 0;
309 io
.openx
.in
.file_attrs
= 0;
310 io
.openx
.in
.write_time
= 0;
311 io
.openx
.in
.size
= 1024*1024;
312 io
.openx
.in
.timeout
= 0;
314 /* check all combinations of open_func */
315 for (i
=0; i
<ARRAY_SIZE(open_funcs
); i
++) {
316 if (open_funcs
[i
].with_file
) {
317 fnum
= create_complex_file(cli
, tctx
, fname
);
319 torture_result(tctx
, TORTURE_FAIL
,
320 "Failed to create file %s - %s\n",
321 fname
, smbcli_errstr(cli
->tree
));
325 smbcli_close(cli
->tree
, fnum
);
327 io
.openx
.in
.open_func
= open_funcs
[i
].open_func
;
328 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
329 if (!NT_STATUS_EQUAL(status
, open_funcs
[i
].correct_status
)) {
330 torture_result(tctx
, TORTURE_FAIL
,
331 "(%s) incorrect status %s should be %s "
332 "(i=%d with_file=%d open_func=0x%x)\n",
333 __location__
, nt_errstr(status
),
334 nt_errstr(open_funcs
[i
].correct_status
),
335 i
, (int)open_funcs
[i
].with_file
,
336 open_funcs
[i
].open_func
);
339 if (NT_STATUS_IS_OK(status
)) {
340 smbcli_close(cli
->tree
, io
.openx
.out
.file
.fnum
);
342 if (open_funcs
[i
].with_file
) {
343 smbcli_unlink(cli
->tree
, fname
);
347 smbcli_unlink(cli
->tree
, fname
);
349 /* check the basic return fields */
350 io
.openx
.in
.open_func
= OPENX_OPEN_FUNC_OPEN
| OPENX_OPEN_FUNC_CREATE
;
351 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
352 CHECK_STATUS(status
, NT_STATUS_OK
);
353 fnum
= io
.openx
.out
.file
.fnum
;
355 CHECK_ALL_INFO(io
.openx
.out
.size
, size
);
356 CHECK_TIME(io
.openx
.out
.write_time
, write_time
);
357 CHECK_ALL_INFO(io
.openx
.out
.attrib
, attrib
& ~FILE_ATTRIBUTE_NONINDEXED
);
358 CHECK_VAL(io
.openx
.out
.access
, OPENX_MODE_ACCESS_RDWR
);
359 CHECK_VAL(io
.openx
.out
.ftype
, 0);
360 CHECK_VAL(io
.openx
.out
.devstate
, 0);
361 CHECK_VAL(io
.openx
.out
.action
, OPENX_ACTION_CREATED
);
362 CHECK_VAL(io
.openx
.out
.size
, 1024*1024);
363 CHECK_ALL_INFO(io
.openx
.in
.size
, size
);
364 smbcli_close(cli
->tree
, fnum
);
365 smbcli_unlink(cli
->tree
, fname
);
367 /* check the fields when the file already existed */
368 fnum2
= create_complex_file(cli
, tctx
, fname
);
373 smbcli_close(cli
->tree
, fnum2
);
375 io
.openx
.in
.open_func
= OPENX_OPEN_FUNC_OPEN
;
376 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
377 CHECK_STATUS(status
, NT_STATUS_OK
);
378 fnum
= io
.openx
.out
.file
.fnum
;
380 CHECK_ALL_INFO(io
.openx
.out
.size
, size
);
381 CHECK_TIME(io
.openx
.out
.write_time
, write_time
);
382 CHECK_VAL(io
.openx
.out
.action
, OPENX_ACTION_EXISTED
);
383 CHECK_VAL(io
.openx
.out
.unknown
, 0);
384 CHECK_ALL_INFO(io
.openx
.out
.attrib
, attrib
& ~FILE_ATTRIBUTE_NONINDEXED
);
385 smbcli_close(cli
->tree
, fnum
);
387 /* now check the search attrib for hidden files - win2003 ignores this? */
388 SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN
);
389 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN
, attrib
);
391 io
.openx
.in
.search_attrs
= FILE_ATTRIBUTE_HIDDEN
;
392 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
393 CHECK_STATUS(status
, NT_STATUS_OK
);
394 smbcli_close(cli
->tree
, io
.openx
.out
.file
.fnum
);
396 io
.openx
.in
.search_attrs
= 0;
397 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
398 CHECK_STATUS(status
, NT_STATUS_OK
);
399 smbcli_close(cli
->tree
, io
.openx
.out
.file
.fnum
);
401 SET_ATTRIB(FILE_ATTRIBUTE_NORMAL
);
402 smbcli_unlink(cli
->tree
, fname
);
404 /* and check attrib on create */
405 io
.openx
.in
.open_func
= OPENX_OPEN_FUNC_FAIL
| OPENX_OPEN_FUNC_CREATE
;
406 io
.openx
.in
.search_attrs
= 0;
407 io
.openx
.in
.file_attrs
= FILE_ATTRIBUTE_SYSTEM
;
408 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
409 CHECK_STATUS(status
, NT_STATUS_OK
);
410 if (torture_setting_bool(tctx
, "samba3", false)) {
411 CHECK_ALL_INFO(FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_ARCHIVE
,
412 attrib
& ~(FILE_ATTRIBUTE_NONINDEXED
|
413 FILE_ATTRIBUTE_SPARSE
));
416 CHECK_ALL_INFO(FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_ARCHIVE
,
417 attrib
& ~(FILE_ATTRIBUTE_NONINDEXED
));
419 smbcli_close(cli
->tree
, io
.openx
.out
.file
.fnum
);
420 smbcli_unlink(cli
->tree
, fname
);
422 /* check timeout on create - win2003 ignores the timeout! */
423 io
.openx
.in
.open_func
= OPENX_OPEN_FUNC_OPEN
| OPENX_OPEN_FUNC_CREATE
;
424 io
.openx
.in
.file_attrs
= 0;
425 io
.openx
.in
.open_mode
= OPENX_MODE_ACCESS_RDWR
| OPENX_MODE_DENY_ALL
;
426 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
427 CHECK_STATUS(status
, NT_STATUS_OK
);
428 fnum
= io
.openx
.out
.file
.fnum
;
430 io
.openx
.in
.timeout
= 20000;
431 tv
= timeval_current();
432 io
.openx
.in
.open_mode
= OPENX_MODE_ACCESS_RDWR
| OPENX_MODE_DENY_NONE
;
433 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
434 CHECK_STATUS(status
, NT_STATUS_SHARING_VIOLATION
);
435 if (timeval_elapsed(&tv
) > 3.0) {
436 torture_result(tctx
, TORTURE_FAIL
,
437 "(%s) Incorrect timing in openx with timeout "
438 "- waited %.2f seconds\n",
439 __location__
, timeval_elapsed(&tv
));
442 smbcli_close(cli
->tree
, fnum
);
443 smbcli_unlink(cli
->tree
, fname
);
445 /* now this is a really weird one - open for execute implies create?! */
446 io
.openx
.in
.fname
= fname
;
447 io
.openx
.in
.flags
= OPENX_FLAGS_ADDITIONAL_INFO
;
448 io
.openx
.in
.open_mode
= OPENX_MODE_ACCESS_EXEC
| OPENX_MODE_DENY_NONE
;
449 io
.openx
.in
.search_attrs
= 0;
450 io
.openx
.in
.open_func
= OPENX_OPEN_FUNC_FAIL
;
451 io
.openx
.in
.file_attrs
= 0;
452 io
.openx
.in
.write_time
= 0;
453 io
.openx
.in
.size
= 0;
454 io
.openx
.in
.timeout
= 0;
455 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
456 CHECK_STATUS(status
, NT_STATUS_OK
);
457 smbcli_close(cli
->tree
, io
.openx
.out
.file
.fnum
);
459 /* check the extended return flag */
460 io
.openx
.in
.flags
= OPENX_FLAGS_ADDITIONAL_INFO
| OPENX_FLAGS_EXTENDED_RETURN
;
461 io
.openx
.in
.open_func
= OPENX_OPEN_FUNC_OPEN
;
462 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
463 CHECK_STATUS(status
, NT_STATUS_OK
);
464 CHECK_VAL(io
.openx
.out
.access_mask
, SEC_STD_ALL
);
465 smbcli_close(cli
->tree
, io
.openx
.out
.file
.fnum
);
467 io
.openx
.in
.fname
= "\\A.+,;=[].B";
468 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
469 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
471 /* Check the mapping for open exec. */
473 /* First create an .exe file. */
474 smbcli_unlink(cli
->tree
, fname_exe
);
475 fnum
= create_complex_file(cli
, tctx
, fname_exe
);
476 smbcli_close(cli
->tree
, fnum
);
478 io
.openx
.level
= RAW_OPEN_OPENX
;
479 io
.openx
.in
.fname
= fname_exe
;
480 io
.openx
.in
.flags
= OPENX_FLAGS_ADDITIONAL_INFO
;
481 io
.openx
.in
.open_mode
= OPENX_MODE_ACCESS_EXEC
| OPENX_MODE_DENY_NONE
;
482 io
.openx
.in
.search_attrs
= 0;
483 io
.openx
.in
.file_attrs
= 0;
484 io
.openx
.in
.write_time
= 0;
485 io
.openx
.in
.size
= 0;
486 io
.openx
.in
.timeout
= 0;
487 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
488 CHECK_STATUS(status
, NT_STATUS_OK
);
490 /* Can we read and write ? */
491 CHECK_RDWR(io
.openx
.out
.file
.fnum
, RDWR_RDONLY
);
492 smbcli_close(cli
->tree
, io
.openx
.out
.file
.fnum
);
493 smbcli_unlink(cli
->tree
, fname
);
496 smbcli_close(cli
->tree
, fnum
);
497 smbcli_deltree(cli
->tree
, BASEDIR
);
506 many thanks to kukks for a sniff showing how this works with os2->w2k
508 static bool test_t2open(struct torture_context
*tctx
, struct smbcli_state
*cli
)
511 union smb_fileinfo finfo
;
512 const char *fname1
= BASEDIR
"\\torture_t2open_yes.txt";
513 const char *fname2
= BASEDIR
"\\torture_t2open_no.txt";
514 const char *fname
= BASEDIR
"\\torture_t2open_3.txt";
522 NTSTATUS correct_status
;
524 { OPENX_OPEN_FUNC_OPEN
, true, NT_STATUS_OK
},
525 { OPENX_OPEN_FUNC_OPEN
, false, NT_STATUS_OBJECT_NAME_NOT_FOUND
},
526 { OPENX_OPEN_FUNC_OPEN
| OPENX_OPEN_FUNC_CREATE
, true, NT_STATUS_OK
},
527 { OPENX_OPEN_FUNC_OPEN
| OPENX_OPEN_FUNC_CREATE
, false, NT_STATUS_OK
},
528 { OPENX_OPEN_FUNC_FAIL
, true, NT_STATUS_OBJECT_NAME_COLLISION
},
529 { OPENX_OPEN_FUNC_FAIL
, false, NT_STATUS_OBJECT_NAME_COLLISION
},
530 { OPENX_OPEN_FUNC_FAIL
| OPENX_OPEN_FUNC_CREATE
, true, NT_STATUS_OBJECT_NAME_COLLISION
},
531 { OPENX_OPEN_FUNC_FAIL
| OPENX_OPEN_FUNC_CREATE
, false, NT_STATUS_OBJECT_NAME_COLLISION
},
532 { OPENX_OPEN_FUNC_TRUNC
, true, NT_STATUS_OK
},
533 { OPENX_OPEN_FUNC_TRUNC
, false, NT_STATUS_OK
},
534 { OPENX_OPEN_FUNC_TRUNC
| OPENX_OPEN_FUNC_CREATE
, true, NT_STATUS_OK
},
535 { OPENX_OPEN_FUNC_TRUNC
| OPENX_OPEN_FUNC_CREATE
, false, NT_STATUS_OK
},
538 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
), "Failed to setup up test directory: " BASEDIR
);
540 fnum
= create_complex_file(cli
, tctx
, fname1
);
542 torture_result(tctx
, TORTURE_FAIL
,
543 "(%s): Failed to create file %s - %s\n",
544 __location__
, fname1
, smbcli_errstr(cli
->tree
));
548 smbcli_close(cli
->tree
, fnum
);
550 io
.t2open
.level
= RAW_OPEN_T2OPEN
;
551 io
.t2open
.in
.flags
= OPENX_FLAGS_ADDITIONAL_INFO
;
552 io
.t2open
.in
.open_mode
= OPENX_MODE_DENY_NONE
| OPENX_MODE_ACCESS_RDWR
;
553 io
.t2open
.in
.open_func
= OPENX_OPEN_FUNC_OPEN
| OPENX_OPEN_FUNC_CREATE
;
554 io
.t2open
.in
.search_attrs
= 0;
555 io
.t2open
.in
.file_attrs
= 0;
556 io
.t2open
.in
.write_time
= 0;
557 io
.t2open
.in
.size
= 0;
558 io
.t2open
.in
.timeout
= 0;
560 io
.t2open
.in
.num_eas
= 3;
561 io
.t2open
.in
.eas
= talloc_array(tctx
, struct ea_struct
, io
.t2open
.in
.num_eas
);
562 io
.t2open
.in
.eas
[0].flags
= 0;
563 io
.t2open
.in
.eas
[0].name
.s
= ".CLASSINFO";
564 io
.t2open
.in
.eas
[0].value
= data_blob_talloc(tctx
, "first value", 11);
565 io
.t2open
.in
.eas
[1].flags
= 0;
566 io
.t2open
.in
.eas
[1].name
.s
= "EA TWO";
567 io
.t2open
.in
.eas
[1].value
= data_blob_talloc(tctx
, "foo", 3);
568 io
.t2open
.in
.eas
[2].flags
= 0;
569 io
.t2open
.in
.eas
[2].name
.s
= "X THIRD";
570 io
.t2open
.in
.eas
[2].value
= data_blob_talloc(tctx
, "xy", 2);
572 /* check all combinations of open_func */
573 for (i
=0; i
<ARRAY_SIZE(open_funcs
); i
++) {
575 if (open_funcs
[i
].with_file
) {
576 io
.t2open
.in
.fname
= fname1
;
578 io
.t2open
.in
.fname
= fname2
;
580 io
.t2open
.in
.open_func
= open_funcs
[i
].open_func
;
581 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
582 if ((io
.t2open
.in
.num_eas
!= 0)
583 && NT_STATUS_EQUAL(status
, NT_STATUS_EAS_NOT_SUPPORTED
)
584 && torture_setting_bool(tctx
, "samba3", false)) {
585 torture_warning(tctx
, "(%s) EAs not supported, not "
586 "treating as fatal in Samba3 test\n",
588 io
.t2open
.in
.num_eas
= 0;
592 if (!NT_STATUS_EQUAL(status
, open_funcs
[i
].correct_status
)) {
593 torture_result(tctx
, TORTURE_FAIL
,
594 "(%s) incorrect status %s should be %s "
595 "(i=%d with_file=%d open_func=0x%x)\n",
596 __location__
, nt_errstr(status
),
597 nt_errstr(open_funcs
[i
].correct_status
),
598 i
, (int)open_funcs
[i
].with_file
,
599 open_funcs
[i
].open_func
);
602 if (NT_STATUS_IS_OK(status
)) {
603 smbcli_close(cli
->tree
, io
.t2open
.out
.file
.fnum
);
607 smbcli_unlink(cli
->tree
, fname1
);
608 smbcli_unlink(cli
->tree
, fname2
);
610 /* check the basic return fields */
611 io
.t2open
.in
.open_func
= OPENX_OPEN_FUNC_OPEN
| OPENX_OPEN_FUNC_CREATE
;
612 io
.t2open
.in
.write_time
= 0;
613 io
.t2open
.in
.fname
= fname
;
614 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
615 CHECK_STATUS(status
, NT_STATUS_OK
);
616 fnum
= io
.t2open
.out
.file
.fnum
;
618 CHECK_ALL_INFO(io
.t2open
.out
.size
, size
);
620 /* windows appears to leak uninitialised memory here */
621 CHECK_VAL(io
.t2open
.out
.write_time
, 0);
623 CHECK_ALL_INFO(io
.t2open
.out
.attrib
, attrib
& ~FILE_ATTRIBUTE_NONINDEXED
);
624 CHECK_VAL(io
.t2open
.out
.access
, OPENX_MODE_DENY_NONE
| OPENX_MODE_ACCESS_RDWR
);
625 CHECK_VAL(io
.t2open
.out
.ftype
, 0);
626 CHECK_VAL(io
.t2open
.out
.devstate
, 0);
627 CHECK_VAL(io
.t2open
.out
.action
, OPENX_ACTION_CREATED
);
628 smbcli_close(cli
->tree
, fnum
);
630 status
= torture_check_ea(cli
, fname
, ".CLASSINFO", "first value");
631 CHECK_STATUS(status
, io
.t2open
.in
.num_eas
632 ? NT_STATUS_OK
: NT_STATUS_EAS_NOT_SUPPORTED
);
633 status
= torture_check_ea(cli
, fname
, "EA TWO", "foo");
634 CHECK_STATUS(status
, io
.t2open
.in
.num_eas
635 ? NT_STATUS_OK
: NT_STATUS_EAS_NOT_SUPPORTED
);
636 status
= torture_check_ea(cli
, fname
, "X THIRD", "xy");
637 CHECK_STATUS(status
, io
.t2open
.in
.num_eas
638 ? NT_STATUS_OK
: NT_STATUS_EAS_NOT_SUPPORTED
);
640 /* now check the search attrib for hidden files - win2003 ignores this? */
641 SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN
);
642 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN
, attrib
);
644 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
645 CHECK_STATUS(status
, NT_STATUS_OK
);
646 smbcli_close(cli
->tree
, io
.t2open
.out
.file
.fnum
);
648 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
649 CHECK_STATUS(status
, NT_STATUS_OK
);
650 smbcli_close(cli
->tree
, io
.t2open
.out
.file
.fnum
);
652 SET_ATTRIB(FILE_ATTRIBUTE_NORMAL
);
653 smbcli_unlink(cli
->tree
, fname
);
655 /* and check attrib on create */
656 io
.t2open
.in
.open_func
= OPENX_OPEN_FUNC_FAIL
| OPENX_OPEN_FUNC_CREATE
;
657 io
.t2open
.in
.file_attrs
= FILE_ATTRIBUTE_SYSTEM
;
658 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
659 CHECK_STATUS(status
, NT_STATUS_OK
);
661 /* check timeout on create - win2003 ignores the timeout! */
662 io
.t2open
.in
.open_func
= OPENX_OPEN_FUNC_OPEN
| OPENX_OPEN_FUNC_CREATE
;
663 io
.t2open
.in
.file_attrs
= 0;
664 io
.t2open
.in
.timeout
= 20000;
665 io
.t2open
.in
.open_mode
= OPENX_MODE_ACCESS_RDWR
| OPENX_MODE_DENY_ALL
;
666 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
667 CHECK_STATUS(status
, NT_STATUS_SHARING_VIOLATION
);
670 smbcli_close(cli
->tree
, fnum
);
671 smbcli_deltree(cli
->tree
, BASEDIR
);
678 test RAW_OPEN_NTCREATEX
680 static bool test_ntcreatex(struct torture_context
*tctx
, struct smbcli_state
*cli
)
683 union smb_fileinfo finfo
;
684 const char *fname
= BASEDIR
"\\torture_ntcreatex.txt";
685 const char *dname
= BASEDIR
"\\torture_ntcreatex.dir";
693 NTSTATUS correct_status
;
695 { NTCREATEX_DISP_SUPERSEDE
, true, NT_STATUS_OK
},
696 { NTCREATEX_DISP_SUPERSEDE
, false, NT_STATUS_OK
},
697 { NTCREATEX_DISP_OPEN
, true, NT_STATUS_OK
},
698 { NTCREATEX_DISP_OPEN
, false, NT_STATUS_OBJECT_NAME_NOT_FOUND
},
699 { NTCREATEX_DISP_CREATE
, true, NT_STATUS_OBJECT_NAME_COLLISION
},
700 { NTCREATEX_DISP_CREATE
, false, NT_STATUS_OK
},
701 { NTCREATEX_DISP_OPEN_IF
, true, NT_STATUS_OK
},
702 { NTCREATEX_DISP_OPEN_IF
, false, NT_STATUS_OK
},
703 { NTCREATEX_DISP_OVERWRITE
, true, NT_STATUS_OK
},
704 { NTCREATEX_DISP_OVERWRITE
, false, NT_STATUS_OBJECT_NAME_NOT_FOUND
},
705 { NTCREATEX_DISP_OVERWRITE_IF
, true, NT_STATUS_OK
},
706 { NTCREATEX_DISP_OVERWRITE_IF
, false, NT_STATUS_OK
},
707 { 6, true, NT_STATUS_INVALID_PARAMETER
},
708 { 6, false, NT_STATUS_INVALID_PARAMETER
},
711 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
), "Failed to setup up test directory: " BASEDIR
);
713 /* reasonable default parameters */
714 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
715 io
.ntcreatex
.in
.flags
= NTCREATEX_FLAGS_EXTENDED
;
716 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
717 io
.ntcreatex
.in
.access_mask
= SEC_RIGHTS_FILE_ALL
;
718 io
.ntcreatex
.in
.alloc_size
= 1024*1024;
719 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
720 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
721 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
722 io
.ntcreatex
.in
.create_options
= 0;
723 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
724 io
.ntcreatex
.in
.security_flags
= 0;
725 io
.ntcreatex
.in
.fname
= fname
;
727 /* test the open disposition */
728 for (i
=0; i
<ARRAY_SIZE(open_funcs
); i
++) {
729 if (open_funcs
[i
].with_file
) {
730 fnum
= smbcli_open(cli
->tree
, fname
, O_CREAT
|O_RDWR
|O_TRUNC
, DENY_NONE
);
732 torture_result(tctx
, TORTURE_FAIL
,
733 "Failed to create file %s - %s\n",
734 fname
, smbcli_errstr(cli
->tree
));
738 smbcli_close(cli
->tree
, fnum
);
740 io
.ntcreatex
.in
.open_disposition
= open_funcs
[i
].open_disp
;
741 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
742 if (!NT_STATUS_EQUAL(status
, open_funcs
[i
].correct_status
)) {
743 torture_result(tctx
, TORTURE_FAIL
,
744 "(%s) incorrect status %s should be %s "
745 "(i=%d with_file=%d open_disp=%d)\n",
746 __location__
, nt_errstr(status
),
747 nt_errstr(open_funcs
[i
].correct_status
),
748 i
, (int)open_funcs
[i
].with_file
,
749 (int)open_funcs
[i
].open_disp
);
752 if (NT_STATUS_IS_OK(status
) || open_funcs
[i
].with_file
) {
753 smbcli_close(cli
->tree
, io
.ntcreatex
.out
.file
.fnum
);
754 smbcli_unlink(cli
->tree
, fname
);
758 /* basic field testing */
759 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
761 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
762 CHECK_STATUS(status
, NT_STATUS_OK
);
763 fnum
= io
.ntcreatex
.out
.file
.fnum
;
765 CHECK_VAL(io
.ntcreatex
.out
.oplock_level
, 0);
766 CHECK_VAL(io
.ntcreatex
.out
.create_action
, NTCREATEX_ACTION_CREATED
);
767 CHECK_NTTIME(io
.ntcreatex
.out
.create_time
, create_time
);
768 CHECK_NTTIME(io
.ntcreatex
.out
.access_time
, access_time
);
769 CHECK_NTTIME(io
.ntcreatex
.out
.write_time
, write_time
);
770 CHECK_NTTIME(io
.ntcreatex
.out
.change_time
, change_time
);
771 CHECK_ALL_INFO(io
.ntcreatex
.out
.attrib
, attrib
);
772 CHECK_ALL_INFO(io
.ntcreatex
.out
.alloc_size
, alloc_size
);
773 CHECK_ALL_INFO(io
.ntcreatex
.out
.size
, size
);
774 CHECK_ALL_INFO(io
.ntcreatex
.out
.is_directory
, directory
);
775 CHECK_VAL(io
.ntcreatex
.out
.file_type
, FILE_TYPE_DISK
);
777 /* check fields when the file already existed */
778 smbcli_close(cli
->tree
, fnum
);
779 smbcli_unlink(cli
->tree
, fname
);
780 fnum
= create_complex_file(cli
, tctx
, fname
);
785 smbcli_close(cli
->tree
, fnum
);
787 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
788 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
789 CHECK_STATUS(status
, NT_STATUS_OK
);
790 fnum
= io
.ntcreatex
.out
.file
.fnum
;
792 CHECK_VAL(io
.ntcreatex
.out
.oplock_level
, 0);
793 CHECK_VAL(io
.ntcreatex
.out
.create_action
, NTCREATEX_ACTION_EXISTED
);
794 CHECK_NTTIME(io
.ntcreatex
.out
.create_time
, create_time
);
795 CHECK_NTTIME(io
.ntcreatex
.out
.access_time
, access_time
);
796 CHECK_NTTIME(io
.ntcreatex
.out
.write_time
, write_time
);
797 CHECK_NTTIME(io
.ntcreatex
.out
.change_time
, change_time
);
798 CHECK_ALL_INFO(io
.ntcreatex
.out
.attrib
, attrib
);
799 CHECK_ALL_INFO(io
.ntcreatex
.out
.alloc_size
, alloc_size
);
800 CHECK_ALL_INFO(io
.ntcreatex
.out
.size
, size
);
801 CHECK_ALL_INFO(io
.ntcreatex
.out
.is_directory
, directory
);
802 CHECK_VAL(io
.ntcreatex
.out
.file_type
, FILE_TYPE_DISK
);
803 smbcli_close(cli
->tree
, fnum
);
804 smbcli_unlink(cli
->tree
, fname
);
807 /* create a directory */
808 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
809 io
.ntcreatex
.in
.access_mask
= SEC_RIGHTS_FILE_ALL
;
810 io
.ntcreatex
.in
.alloc_size
= 0;
811 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_DIRECTORY
;
812 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
813 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
814 io
.ntcreatex
.in
.create_options
= 0;
815 io
.ntcreatex
.in
.fname
= dname
;
818 smbcli_rmdir(cli
->tree
, fname
);
819 smbcli_unlink(cli
->tree
, fname
);
821 io
.ntcreatex
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
822 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
823 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
824 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
825 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
826 CHECK_STATUS(status
, NT_STATUS_OK
);
827 fnum
= io
.ntcreatex
.out
.file
.fnum
;
829 CHECK_VAL(io
.ntcreatex
.out
.oplock_level
, 0);
830 CHECK_VAL(io
.ntcreatex
.out
.create_action
, NTCREATEX_ACTION_CREATED
);
831 CHECK_NTTIME(io
.ntcreatex
.out
.create_time
, create_time
);
832 CHECK_NTTIME(io
.ntcreatex
.out
.access_time
, access_time
);
833 CHECK_NTTIME(io
.ntcreatex
.out
.write_time
, write_time
);
834 CHECK_NTTIME(io
.ntcreatex
.out
.change_time
, change_time
);
835 CHECK_ALL_INFO(io
.ntcreatex
.out
.attrib
, attrib
);
836 CHECK_VAL(io
.ntcreatex
.out
.attrib
& ~FILE_ATTRIBUTE_NONINDEXED
,
837 FILE_ATTRIBUTE_DIRECTORY
);
838 CHECK_ALL_INFO(io
.ntcreatex
.out
.alloc_size
, alloc_size
);
839 CHECK_ALL_INFO(io
.ntcreatex
.out
.size
, size
);
840 CHECK_ALL_INFO(io
.ntcreatex
.out
.is_directory
, directory
);
841 CHECK_VAL(io
.ntcreatex
.out
.is_directory
, 1);
842 CHECK_VAL(io
.ntcreatex
.out
.size
, 0);
843 CHECK_VAL(io
.ntcreatex
.out
.file_type
, FILE_TYPE_DISK
);
844 smbcli_unlink(cli
->tree
, fname
);
848 smbcli_close(cli
->tree
, fnum
);
849 smbcli_deltree(cli
->tree
, BASEDIR
);
856 test RAW_OPEN_NTTRANS_CREATE
858 static bool test_nttrans_create(struct torture_context
*tctx
, struct smbcli_state
*cli
)
861 union smb_fileinfo finfo
;
862 const char *fname
= BASEDIR
"\\torture_ntcreatex.txt";
863 const char *dname
= BASEDIR
"\\torture_ntcreatex.dir";
868 uint32_t ok_mask
, not_supported_mask
, invalid_parameter_mask
;
869 uint32_t not_a_directory_mask
, unexpected_mask
;
873 NTSTATUS correct_status
;
875 { NTCREATEX_DISP_SUPERSEDE
, true, NT_STATUS_OK
},
876 { NTCREATEX_DISP_SUPERSEDE
, false, NT_STATUS_OK
},
877 { NTCREATEX_DISP_OPEN
, true, NT_STATUS_OK
},
878 { NTCREATEX_DISP_OPEN
, false, NT_STATUS_OBJECT_NAME_NOT_FOUND
},
879 { NTCREATEX_DISP_CREATE
, true, NT_STATUS_OBJECT_NAME_COLLISION
},
880 { NTCREATEX_DISP_CREATE
, false, NT_STATUS_OK
},
881 { NTCREATEX_DISP_OPEN_IF
, true, NT_STATUS_OK
},
882 { NTCREATEX_DISP_OPEN_IF
, false, NT_STATUS_OK
},
883 { NTCREATEX_DISP_OVERWRITE
, true, NT_STATUS_OK
},
884 { NTCREATEX_DISP_OVERWRITE
, false, NT_STATUS_OBJECT_NAME_NOT_FOUND
},
885 { NTCREATEX_DISP_OVERWRITE_IF
, true, NT_STATUS_OK
},
886 { NTCREATEX_DISP_OVERWRITE_IF
, false, NT_STATUS_OK
},
887 { 6, true, NT_STATUS_INVALID_PARAMETER
},
888 { 6, false, NT_STATUS_INVALID_PARAMETER
},
891 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
), "Failed to setup up test directory: " BASEDIR
);
893 /* reasonable default parameters */
894 io
.generic
.level
= RAW_OPEN_NTTRANS_CREATE
;
895 io
.ntcreatex
.in
.flags
= NTCREATEX_FLAGS_EXTENDED
;
896 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
897 io
.ntcreatex
.in
.access_mask
= SEC_RIGHTS_FILE_ALL
;
898 io
.ntcreatex
.in
.alloc_size
= 1024*1024;
899 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
900 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
901 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
902 io
.ntcreatex
.in
.create_options
= 0;
903 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
904 io
.ntcreatex
.in
.security_flags
= 0;
905 io
.ntcreatex
.in
.fname
= fname
;
906 io
.ntcreatex
.in
.sec_desc
= NULL
;
907 io
.ntcreatex
.in
.ea_list
= NULL
;
909 /* test the open disposition */
910 for (i
=0; i
<ARRAY_SIZE(open_funcs
); i
++) {
911 if (open_funcs
[i
].with_file
) {
912 fnum
= smbcli_open(cli
->tree
, fname
, O_CREAT
|O_RDWR
|O_TRUNC
, DENY_NONE
);
914 torture_result(tctx
, TORTURE_FAIL
,
915 "Failed to create file %s - %s\n",
916 fname
, smbcli_errstr(cli
->tree
));
920 smbcli_close(cli
->tree
, fnum
);
922 io
.ntcreatex
.in
.open_disposition
= open_funcs
[i
].open_disp
;
923 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
924 if (!NT_STATUS_EQUAL(status
, open_funcs
[i
].correct_status
)) {
925 torture_result(tctx
, TORTURE_FAIL
,
926 "(%s) incorrect status %s should be %s "
927 "(i=%d with_file=%d open_disp=%d)\n",
928 __location__
, nt_errstr(status
),
929 nt_errstr(open_funcs
[i
].correct_status
),
930 i
, (int)open_funcs
[i
].with_file
,
931 (int)open_funcs
[i
].open_disp
);
934 if (NT_STATUS_IS_OK(status
) || open_funcs
[i
].with_file
) {
935 smbcli_close(cli
->tree
, io
.ntcreatex
.out
.file
.fnum
);
936 smbcli_unlink(cli
->tree
, fname
);
940 /* basic field testing */
941 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
943 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
944 CHECK_STATUS(status
, NT_STATUS_OK
);
945 fnum
= io
.ntcreatex
.out
.file
.fnum
;
947 CHECK_VAL(io
.ntcreatex
.out
.oplock_level
, 0);
948 CHECK_VAL(io
.ntcreatex
.out
.create_action
, NTCREATEX_ACTION_CREATED
);
949 CHECK_NTTIME(io
.ntcreatex
.out
.create_time
, create_time
);
950 CHECK_NTTIME(io
.ntcreatex
.out
.access_time
, access_time
);
951 CHECK_NTTIME(io
.ntcreatex
.out
.write_time
, write_time
);
952 CHECK_NTTIME(io
.ntcreatex
.out
.change_time
, change_time
);
953 CHECK_ALL_INFO(io
.ntcreatex
.out
.attrib
, attrib
);
954 CHECK_ALL_INFO(io
.ntcreatex
.out
.alloc_size
, alloc_size
);
955 CHECK_ALL_INFO(io
.ntcreatex
.out
.size
, size
);
956 CHECK_ALL_INFO(io
.ntcreatex
.out
.is_directory
, directory
);
957 CHECK_VAL(io
.ntcreatex
.out
.file_type
, FILE_TYPE_DISK
);
959 /* check fields when the file already existed */
960 smbcli_close(cli
->tree
, fnum
);
961 smbcli_unlink(cli
->tree
, fname
);
962 fnum
= create_complex_file(cli
, tctx
, fname
);
967 smbcli_close(cli
->tree
, fnum
);
969 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
970 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
971 CHECK_STATUS(status
, NT_STATUS_OK
);
972 fnum
= io
.ntcreatex
.out
.file
.fnum
;
974 CHECK_VAL(io
.ntcreatex
.out
.oplock_level
, 0);
975 CHECK_VAL(io
.ntcreatex
.out
.create_action
, NTCREATEX_ACTION_EXISTED
);
976 CHECK_NTTIME(io
.ntcreatex
.out
.create_time
, create_time
);
977 CHECK_NTTIME(io
.ntcreatex
.out
.access_time
, access_time
);
978 CHECK_NTTIME(io
.ntcreatex
.out
.write_time
, write_time
);
979 CHECK_NTTIME(io
.ntcreatex
.out
.change_time
, change_time
);
980 CHECK_ALL_INFO(io
.ntcreatex
.out
.attrib
, attrib
);
981 CHECK_ALL_INFO(io
.ntcreatex
.out
.alloc_size
, alloc_size
);
982 CHECK_ALL_INFO(io
.ntcreatex
.out
.size
, size
);
983 CHECK_ALL_INFO(io
.ntcreatex
.out
.is_directory
, directory
);
984 CHECK_VAL(io
.ntcreatex
.out
.file_type
, FILE_TYPE_DISK
);
985 smbcli_close(cli
->tree
, fnum
);
987 /* check no-recall - don't pull a file from tape on a HSM */
988 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_NO_RECALL
;
989 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
990 CHECK_STATUS(status
, NT_STATUS_OK
);
991 fnum
= io
.ntcreatex
.out
.file
.fnum
;
993 CHECK_VAL(io
.ntcreatex
.out
.oplock_level
, 0);
994 CHECK_VAL(io
.ntcreatex
.out
.create_action
, NTCREATEX_ACTION_EXISTED
);
995 CHECK_NTTIME(io
.ntcreatex
.out
.create_time
, create_time
);
996 CHECK_NTTIME(io
.ntcreatex
.out
.access_time
, access_time
);
997 CHECK_NTTIME(io
.ntcreatex
.out
.write_time
, write_time
);
998 CHECK_NTTIME(io
.ntcreatex
.out
.change_time
, change_time
);
999 CHECK_ALL_INFO(io
.ntcreatex
.out
.attrib
, attrib
);
1000 CHECK_ALL_INFO(io
.ntcreatex
.out
.alloc_size
, alloc_size
);
1001 CHECK_ALL_INFO(io
.ntcreatex
.out
.size
, size
);
1002 CHECK_ALL_INFO(io
.ntcreatex
.out
.is_directory
, directory
);
1003 CHECK_VAL(io
.ntcreatex
.out
.file_type
, FILE_TYPE_DISK
);
1004 smbcli_close(cli
->tree
, fnum
);
1006 /* Check some create options (these all should be ignored) */
1007 for (i
=0; i
< 32; i
++) {
1008 uint32_t create_option
=
1009 ((uint32_t)1 << i
) & NTCREATEX_OPTIONS_MUST_IGNORE_MASK
;
1010 if (create_option
== 0) {
1013 io
.ntcreatex
.in
.create_options
= create_option
;
1014 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1015 if (!NT_STATUS_IS_OK(status
)) {
1016 torture_warning(tctx
, "ntcreatex create option 0x%08x "
1017 "gave %s - should give NT_STATUS_OK\n",
1018 create_option
, nt_errstr(status
));
1020 CHECK_STATUS(status
, NT_STATUS_OK
);
1021 fnum
= io
.ntcreatex
.out
.file
.fnum
;
1023 CHECK_VAL(io
.ntcreatex
.out
.oplock_level
, 0);
1024 CHECK_VAL(io
.ntcreatex
.out
.create_action
, NTCREATEX_ACTION_EXISTED
);
1025 CHECK_NTTIME(io
.ntcreatex
.out
.create_time
, create_time
);
1026 CHECK_NTTIME(io
.ntcreatex
.out
.access_time
, access_time
);
1027 CHECK_NTTIME(io
.ntcreatex
.out
.write_time
, write_time
);
1028 CHECK_NTTIME(io
.ntcreatex
.out
.change_time
, change_time
);
1029 CHECK_ALL_INFO(io
.ntcreatex
.out
.attrib
, attrib
);
1030 CHECK_ALL_INFO(io
.ntcreatex
.out
.alloc_size
, alloc_size
);
1031 CHECK_ALL_INFO(io
.ntcreatex
.out
.size
, size
);
1032 CHECK_ALL_INFO(io
.ntcreatex
.out
.is_directory
, directory
);
1033 CHECK_VAL(io
.ntcreatex
.out
.file_type
, FILE_TYPE_DISK
);
1034 smbcli_close(cli
->tree
, fnum
);
1037 io
.ntcreatex
.in
.file_attr
= 0;
1038 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN_IF
;
1039 io
.ntcreatex
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1041 /* Check for options that should return NOT_SUPPORTED, OK or INVALID_PARAMETER */
1043 not_supported_mask
= 0;
1044 invalid_parameter_mask
= 0;
1045 not_a_directory_mask
= 0;
1046 unexpected_mask
= 0;
1047 for (i
=0; i
< 32; i
++) {
1048 uint32_t create_option
= (uint32_t)1<<i
;
1049 if (create_option
& NTCREATEX_OPTIONS_DELETE_ON_CLOSE
) {
1052 io
.ntcreatex
.in
.create_options
= create_option
;
1053 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1054 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_SUPPORTED
)) {
1055 not_supported_mask
|= create_option
;
1056 } else if (NT_STATUS_EQUAL(status
, NT_STATUS_OK
)) {
1057 ok_mask
|= create_option
;
1058 smbcli_close(cli
->tree
, io
.ntcreatex
.out
.file
.fnum
);
1059 } else if (NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_PARAMETER
)) {
1060 invalid_parameter_mask
|= create_option
;
1061 } else if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_A_DIRECTORY
)) {
1062 not_a_directory_mask
|= 1<<i
;
1064 unexpected_mask
|= 1<<i
;
1065 torture_comment(tctx
, "create option 0x%08x returned %s\n",
1066 create_option
, nt_errstr(status
));
1070 CHECK_VAL(ok_mask
, 0x00efcfce);
1071 CHECK_VAL(not_a_directory_mask
, 0x00000001);
1072 CHECK_VAL(not_supported_mask
, 0x00002000);
1073 CHECK_VAL(invalid_parameter_mask
, 0xff100030);
1074 CHECK_VAL(unexpected_mask
, 0x00000000);
1076 smbcli_unlink(cli
->tree
, fname
);
1079 /* create a directory */
1080 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
1081 io
.ntcreatex
.in
.access_mask
= SEC_RIGHTS_FILE_ALL
;
1082 io
.ntcreatex
.in
.alloc_size
= 0;
1083 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_DIRECTORY
;
1084 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
1085 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
1086 io
.ntcreatex
.in
.create_options
= 0;
1087 io
.ntcreatex
.in
.fname
= dname
;
1090 smbcli_rmdir(cli
->tree
, fname
);
1091 smbcli_unlink(cli
->tree
, fname
);
1093 io
.ntcreatex
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1094 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1095 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1096 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
1097 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1098 CHECK_STATUS(status
, NT_STATUS_OK
);
1099 fnum
= io
.ntcreatex
.out
.file
.fnum
;
1101 CHECK_VAL(io
.ntcreatex
.out
.oplock_level
, 0);
1102 CHECK_VAL(io
.ntcreatex
.out
.create_action
, NTCREATEX_ACTION_CREATED
);
1103 CHECK_NTTIME(io
.ntcreatex
.out
.create_time
, create_time
);
1104 CHECK_NTTIME(io
.ntcreatex
.out
.access_time
, access_time
);
1105 CHECK_NTTIME(io
.ntcreatex
.out
.write_time
, write_time
);
1106 CHECK_NTTIME(io
.ntcreatex
.out
.change_time
, change_time
);
1107 CHECK_ALL_INFO(io
.ntcreatex
.out
.attrib
, attrib
);
1108 CHECK_VAL(io
.ntcreatex
.out
.attrib
& ~FILE_ATTRIBUTE_NONINDEXED
,
1109 FILE_ATTRIBUTE_DIRECTORY
);
1110 CHECK_ALL_INFO(io
.ntcreatex
.out
.alloc_size
, alloc_size
);
1111 CHECK_ALL_INFO(io
.ntcreatex
.out
.size
, size
);
1112 CHECK_ALL_INFO(io
.ntcreatex
.out
.is_directory
, directory
);
1113 CHECK_VAL(io
.ntcreatex
.out
.is_directory
, 1);
1114 CHECK_VAL(io
.ntcreatex
.out
.size
, 0);
1115 CHECK_VAL(io
.ntcreatex
.out
.file_type
, FILE_TYPE_DISK
);
1116 smbcli_unlink(cli
->tree
, fname
);
1120 smbcli_close(cli
->tree
, fnum
);
1121 smbcli_deltree(cli
->tree
, BASEDIR
);
1127 test RAW_OPEN_NTCREATEX with an already opened and byte range locked file
1129 I've got an application that does a similar sequence of ntcreate&x,
1130 locking&x and another ntcreate&x with
1131 open_disposition==NTCREATEX_DISP_OVERWRITE_IF. Windows 2003 allows the
1134 static bool test_ntcreatex_brlocked(struct torture_context
*tctx
, struct smbcli_state
*cli
)
1136 union smb_open io
, io1
;
1138 struct smb_lock_entry lock
[1];
1139 const char *fname
= BASEDIR
"\\torture_ntcreatex.txt";
1143 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
), "Failed to setup up test directory: " BASEDIR
);
1145 torture_comment(tctx
, "Testing ntcreatex with a byte range locked file\n");
1147 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
1148 io
.ntcreatex
.in
.flags
= NTCREATEX_FLAGS_EXTENDED
;
1149 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
1150 io
.ntcreatex
.in
.access_mask
= 0x2019f;
1151 io
.ntcreatex
.in
.alloc_size
= 0;
1152 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1153 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
1154 NTCREATEX_SHARE_ACCESS_WRITE
;
1155 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
1156 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_NON_DIRECTORY_FILE
;
1157 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_IMPERSONATION
;
1158 io
.ntcreatex
.in
.security_flags
= NTCREATEX_SECURITY_DYNAMIC
|
1159 NTCREATEX_SECURITY_ALL
;
1160 io
.ntcreatex
.in
.fname
= fname
;
1162 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1163 CHECK_STATUS(status
, NT_STATUS_OK
);
1165 io2
.lockx
.level
= RAW_LOCK_LOCKX
;
1166 io2
.lockx
.in
.file
.fnum
= io
.ntcreatex
.out
.file
.fnum
;
1167 io2
.lockx
.in
.mode
= LOCKING_ANDX_LARGE_FILES
;
1168 io2
.lockx
.in
.timeout
= 0;
1169 io2
.lockx
.in
.ulock_cnt
= 0;
1170 io2
.lockx
.in
.lock_cnt
= 1;
1171 lock
[0].pid
= cli
->session
->pid
;
1173 lock
[0].count
= 0x1;
1174 io2
.lockx
.in
.locks
= &lock
[0];
1175 status
= smb_raw_lock(cli
->tree
, &io2
);
1176 CHECK_STATUS(status
, NT_STATUS_OK
);
1178 io1
.generic
.level
= RAW_OPEN_NTCREATEX
;
1179 io1
.ntcreatex
.in
.flags
= NTCREATEX_FLAGS_EXTENDED
;
1180 io1
.ntcreatex
.in
.root_fid
.fnum
= 0;
1181 io1
.ntcreatex
.in
.access_mask
= 0x20196;
1182 io1
.ntcreatex
.in
.alloc_size
= 0;
1183 io1
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1184 io1
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
1185 NTCREATEX_SHARE_ACCESS_WRITE
;
1186 io1
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OVERWRITE_IF
;
1187 io1
.ntcreatex
.in
.create_options
= 0;
1188 io1
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_IMPERSONATION
;
1189 io1
.ntcreatex
.in
.security_flags
= NTCREATEX_SECURITY_DYNAMIC
|
1190 NTCREATEX_SECURITY_ALL
;
1191 io1
.ntcreatex
.in
.fname
= fname
;
1193 status
= smb_raw_open(cli
->tree
, tctx
, &io1
);
1194 CHECK_STATUS(status
, NT_STATUS_OK
);
1197 smbcli_close(cli
->tree
, io
.ntcreatex
.out
.file
.fnum
);
1198 smbcli_close(cli
->tree
, io1
.ntcreatex
.out
.file
.fnum
);
1199 smbcli_deltree(cli
->tree
, BASEDIR
);
1206 static bool test_mknew(struct torture_context
*tctx
, struct smbcli_state
*cli
)
1209 const char *fname
= BASEDIR
"\\torture_mknew.txt";
1213 time_t basetime
= (time(NULL
) + 3600*24*3) & ~1;
1214 union smb_fileinfo finfo
;
1216 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
), "Failed to setup up test directory: " BASEDIR
);
1218 io
.mknew
.level
= RAW_OPEN_MKNEW
;
1219 io
.mknew
.in
.attrib
= 0;
1220 io
.mknew
.in
.write_time
= 0;
1221 io
.mknew
.in
.fname
= fname
;
1222 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1223 CHECK_STATUS(status
, NT_STATUS_OK
);
1224 fnum
= io
.mknew
.out
.file
.fnum
;
1226 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1227 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_COLLISION
);
1229 smbcli_close(cli
->tree
, fnum
);
1230 smbcli_unlink(cli
->tree
, fname
);
1232 /* make sure write_time works */
1233 io
.mknew
.in
.write_time
= basetime
;
1234 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1235 CHECK_STATUS(status
, NT_STATUS_OK
);
1236 fnum
= io
.mknew
.out
.file
.fnum
;
1237 CHECK_TIME(basetime
, write_time
);
1239 smbcli_close(cli
->tree
, fnum
);
1240 smbcli_unlink(cli
->tree
, fname
);
1242 /* make sure file_attrs works */
1243 io
.mknew
.in
.attrib
= FILE_ATTRIBUTE_HIDDEN
;
1244 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1245 CHECK_STATUS(status
, NT_STATUS_OK
);
1246 fnum
= io
.mknew
.out
.file
.fnum
;
1247 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_ARCHIVE
,
1248 attrib
& ~FILE_ATTRIBUTE_NONINDEXED
);
1251 smbcli_close(cli
->tree
, fnum
);
1252 smbcli_deltree(cli
->tree
, BASEDIR
);
1259 test RAW_OPEN_CREATE
1261 static bool test_create(struct torture_context
*tctx
, struct smbcli_state
*cli
)
1264 const char *fname
= BASEDIR
"\\torture_create.txt";
1268 time_t basetime
= (time(NULL
) + 3600*24*3) & ~1;
1269 union smb_fileinfo finfo
;
1271 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
), "Failed to setup up test directory: " BASEDIR
);
1273 io
.create
.level
= RAW_OPEN_CREATE
;
1274 io
.create
.in
.attrib
= 0;
1275 io
.create
.in
.write_time
= 0;
1276 io
.create
.in
.fname
= fname
;
1277 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1278 CHECK_STATUS(status
, NT_STATUS_OK
);
1279 fnum
= io
.create
.out
.file
.fnum
;
1281 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1282 CHECK_STATUS(status
, NT_STATUS_OK
);
1284 smbcli_close(cli
->tree
, io
.create
.out
.file
.fnum
);
1285 smbcli_close(cli
->tree
, fnum
);
1286 smbcli_unlink(cli
->tree
, fname
);
1288 /* make sure write_time works */
1289 io
.create
.in
.write_time
= basetime
;
1290 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1291 CHECK_STATUS(status
, NT_STATUS_OK
);
1292 fnum
= io
.create
.out
.file
.fnum
;
1293 CHECK_TIME(basetime
, write_time
);
1295 smbcli_close(cli
->tree
, fnum
);
1296 smbcli_unlink(cli
->tree
, fname
);
1298 /* make sure file_attrs works */
1299 io
.create
.in
.attrib
= FILE_ATTRIBUTE_HIDDEN
;
1300 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1301 CHECK_STATUS(status
, NT_STATUS_OK
);
1302 fnum
= io
.create
.out
.file
.fnum
;
1303 CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_ARCHIVE
,
1304 attrib
& ~FILE_ATTRIBUTE_NONINDEXED
);
1307 smbcli_close(cli
->tree
, fnum
);
1308 smbcli_deltree(cli
->tree
, BASEDIR
);
1317 static bool test_ctemp(struct torture_context
*tctx
, struct smbcli_state
*cli
)
1323 time_t basetime
= (time(NULL
) + 3600*24*3) & ~1;
1324 union smb_fileinfo finfo
;
1325 const char *name
, *fname
= NULL
;
1327 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
), "Failed to setup up test directory: " BASEDIR
);
1329 io
.ctemp
.level
= RAW_OPEN_CTEMP
;
1330 io
.ctemp
.in
.attrib
= FILE_ATTRIBUTE_HIDDEN
;
1331 io
.ctemp
.in
.write_time
= basetime
;
1332 io
.ctemp
.in
.directory
= BASEDIR
;
1333 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1334 CHECK_STATUS(status
, NT_STATUS_OK
);
1335 fnum
= io
.ctemp
.out
.file
.fnum
;
1337 name
= io
.ctemp
.out
.name
;
1339 finfo
.generic
.level
= RAW_FILEINFO_NAME_INFO
;
1340 finfo
.generic
.in
.file
.fnum
= fnum
;
1341 status
= smb_raw_fileinfo(cli
->tree
, tctx
, &finfo
);
1342 CHECK_STATUS(status
, NT_STATUS_OK
);
1344 fname
= finfo
.name_info
.out
.fname
.s
;
1345 torture_comment(tctx
, "ctemp name=%s real name=%s\n", name
, fname
);
1348 smbcli_close(cli
->tree
, fnum
);
1349 smbcli_deltree(cli
->tree
, BASEDIR
);
1356 test chained RAW_OPEN_OPENX_READX
1358 static bool test_chained(struct torture_context
*tctx
, struct smbcli_state
*cli
)
1361 const char *fname
= BASEDIR
"\\torture_chained.txt";
1365 const char buf
[] = "test";
1368 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
), "Failed to setup up test directory: " BASEDIR
);
1370 fnum
= create_complex_file(cli
, tctx
, fname
);
1372 smbcli_write(cli
->tree
, fnum
, 0, buf
, 0, sizeof(buf
));
1374 smbcli_close(cli
->tree
, fnum
);
1376 io
.openxreadx
.level
= RAW_OPEN_OPENX_READX
;
1377 io
.openxreadx
.in
.fname
= fname
;
1378 io
.openxreadx
.in
.flags
= OPENX_FLAGS_ADDITIONAL_INFO
;
1379 io
.openxreadx
.in
.open_mode
= OPENX_MODE_ACCESS_RDWR
;
1380 io
.openxreadx
.in
.open_func
= OPENX_OPEN_FUNC_OPEN
;
1381 io
.openxreadx
.in
.search_attrs
= 0;
1382 io
.openxreadx
.in
.file_attrs
= 0;
1383 io
.openxreadx
.in
.write_time
= 0;
1384 io
.openxreadx
.in
.size
= 1024*1024;
1385 io
.openxreadx
.in
.timeout
= 0;
1387 io
.openxreadx
.in
.offset
= 0;
1388 io
.openxreadx
.in
.mincnt
= sizeof(buf2
);
1389 io
.openxreadx
.in
.maxcnt
= sizeof(buf2
);
1390 io
.openxreadx
.in
.remaining
= 0;
1391 io
.openxreadx
.out
.data
= (uint8_t *)buf2
;
1393 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1394 CHECK_STATUS(status
, NT_STATUS_OK
);
1395 fnum
= io
.openxreadx
.out
.file
.fnum
;
1397 if (memcmp(buf
, buf2
, MIN(sizeof(buf
), sizeof(buf2
))) != 0) {
1398 torture_result(tctx
, TORTURE_FAIL
,
1399 "wrong data in reply buffer\n");
1404 smbcli_close(cli
->tree
, fnum
);
1405 smbcli_deltree(cli
->tree
, BASEDIR
);
1411 test RAW_OPEN_OPENX without a leading slash on the path.
1412 NetApp filers are known to fail on this.
1415 static bool test_no_leading_slash(struct torture_context
*tctx
, struct smbcli_state
*cli
)
1418 const char *fname
= BASEDIR
"\\torture_no_leading_slash.txt";
1422 const char buf
[] = "test";
1424 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
), "Failed to setup up test directory: " BASEDIR
);
1426 smbcli_unlink(cli
->tree
, fname
);
1428 /* Create the file */
1429 fnum
= create_complex_file(cli
, tctx
, fname
);
1430 smbcli_write(cli
->tree
, fnum
, 0, buf
, 0, sizeof(buf
));
1431 smbcli_close(cli
->tree
, fnum
);
1433 /* Prepare to open the file using path without leading slash */
1434 io
.openx
.level
= RAW_OPEN_OPENX
;
1435 io
.openx
.in
.fname
= fname
+ 1;
1436 io
.openx
.in
.flags
= OPENX_FLAGS_ADDITIONAL_INFO
;
1437 io
.openx
.in
.open_mode
= OPENX_MODE_ACCESS_RDWR
;
1438 io
.openx
.in
.open_func
= OPENX_OPEN_FUNC_OPEN
;
1439 io
.openx
.in
.search_attrs
= 0;
1440 io
.openx
.in
.file_attrs
= 0;
1441 io
.openx
.in
.write_time
= 0;
1442 io
.openx
.in
.size
= 1024*1024;
1443 io
.openx
.in
.timeout
= 0;
1445 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1446 CHECK_STATUS(status
, NT_STATUS_OK
);
1447 fnum
= io
.openx
.out
.file
.fnum
;
1450 smbcli_close(cli
->tree
, fnum
);
1451 smbcli_deltree(cli
->tree
, BASEDIR
);
1457 test RAW_OPEN_OPENX against an existing directory to
1458 ensure it returns NT_STATUS_FILE_IS_A_DIRECTORY.
1459 Samba 3.2.0 - 3.2.6 are known to fail this.
1462 static bool test_openx_over_dir(struct torture_context
*tctx
, struct smbcli_state
*cli
)
1465 const char *fname
= BASEDIR
"\\openx_over_dir";
1473 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
), "Failed to setup up test directory: " BASEDIR
);
1475 /* Create the Directory */
1476 status
= create_directory_handle(cli
->tree
, fname
, &d_fnum
);
1477 smbcli_close(cli
->tree
, d_fnum
);
1479 /* Prepare to open the file over the directory. */
1480 io
.openx
.level
= RAW_OPEN_OPENX
;
1481 io
.openx
.in
.fname
= fname
;
1482 io
.openx
.in
.flags
= OPENX_FLAGS_ADDITIONAL_INFO
;
1483 io
.openx
.in
.open_mode
= OPENX_MODE_ACCESS_RDWR
;
1484 io
.openx
.in
.open_func
= OPENX_OPEN_FUNC_OPEN
;
1485 io
.openx
.in
.search_attrs
= 0;
1486 io
.openx
.in
.file_attrs
= 0;
1487 io
.openx
.in
.write_time
= 0;
1488 io
.openx
.in
.size
= 1024*1024;
1489 io
.openx
.in
.timeout
= 0;
1491 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1492 CHECK_STATUS(status
, NT_STATUS_FILE_IS_A_DIRECTORY
);
1493 fnum
= io
.openx
.out
.file
.fnum
;
1496 smbcli_close(cli
->tree
, fnum
);
1497 smbcli_deltree(cli
->tree
, BASEDIR
);
1503 /* A little torture test to expose a race condition in Samba 3.0.20 ... :-) */
1505 static bool test_raw_open_multi(struct torture_context
*tctx
, struct smbcli_state
*cli_ignored
)
1507 struct smbcli_state
*cli
;
1508 TALLOC_CTX
*mem_ctx
= talloc_init("torture_test_oplock_multi");
1509 const char *fname
= "\\test_oplock.dat";
1513 struct smbcli_state
**clients
;
1514 struct smbcli_request
**requests
;
1515 union smb_open
*ios
;
1516 const char *host
= torture_setting_string(tctx
, "host", NULL
);
1517 const char *share
= torture_setting_string(tctx
, "share", NULL
);
1518 int i
, num_files
= 3;
1520 int num_collision
= 0;
1522 clients
= talloc_array(mem_ctx
, struct smbcli_state
*, num_files
);
1523 requests
= talloc_array(mem_ctx
, struct smbcli_request
*, num_files
);
1524 ios
= talloc_array(mem_ctx
, union smb_open
, num_files
);
1525 if ((tctx
->ev
== NULL
) || (clients
== NULL
) || (requests
== NULL
) ||
1527 torture_result(tctx
, TORTURE_FAIL
, "(%s): talloc failed\n",
1532 if (!torture_open_connection_share(mem_ctx
, &cli
, tctx
, host
, share
, tctx
->ev
)) {
1536 cli
->tree
->session
->transport
->options
.request_timeout
= 60;
1538 for (i
=0; i
<num_files
; i
++) {
1539 if (!torture_open_connection_share(mem_ctx
, &(clients
[i
]),
1540 tctx
, host
, share
, tctx
->ev
)) {
1541 torture_result(tctx
, TORTURE_FAIL
,
1542 "(%s): Could not open %d'th connection\n",
1546 clients
[i
]->tree
->session
->transport
->options
.request_timeout
= 60;
1550 smbcli_unlink(cli
->tree
, fname
);
1553 base ntcreatex parms
1555 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
1556 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
1557 io
.ntcreatex
.in
.access_mask
= SEC_RIGHTS_FILE_ALL
;
1558 io
.ntcreatex
.in
.alloc_size
= 0;
1559 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1560 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
1561 NTCREATEX_SHARE_ACCESS_WRITE
|
1562 NTCREATEX_SHARE_ACCESS_DELETE
;
1563 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
1564 io
.ntcreatex
.in
.create_options
= 0;
1565 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
1566 io
.ntcreatex
.in
.security_flags
= 0;
1567 io
.ntcreatex
.in
.fname
= fname
;
1568 io
.ntcreatex
.in
.flags
= 0;
1570 for (i
=0; i
<num_files
; i
++) {
1572 requests
[i
] = smb_raw_open_send(clients
[i
]->tree
, &ios
[i
]);
1573 if (requests
[i
] == NULL
) {
1574 torture_result(tctx
, TORTURE_FAIL
,
1575 "(%s): could not send %d'th request\n",
1581 torture_comment(tctx
, "waiting for replies\n");
1583 bool unreplied
= false;
1584 for (i
=0; i
<num_files
; i
++) {
1585 if (requests
[i
] == NULL
) {
1588 if (requests
[i
]->state
< SMBCLI_REQUEST_DONE
) {
1592 status
= smb_raw_open_recv(requests
[i
], mem_ctx
,
1595 torture_comment(tctx
, "File %d returned status %s\n", i
,
1598 if (NT_STATUS_IS_OK(status
)) {
1602 if (NT_STATUS_EQUAL(status
,
1603 NT_STATUS_OBJECT_NAME_COLLISION
)) {
1613 if (tevent_loop_once(tctx
->ev
) != 0) {
1614 torture_result(tctx
, TORTURE_FAIL
,
1615 "(%s): tevent_loop_once failed\n", __location__
);
1620 if ((num_ok
!= 1) || (num_ok
+ num_collision
!= num_files
)) {
1624 for (i
=0; i
<num_files
; i
++) {
1625 torture_close_connection(clients
[i
]);
1627 talloc_free(mem_ctx
);
1632 test opening for delete on a read-only attribute file.
1634 static bool test_open_for_delete(struct torture_context
*tctx
, struct smbcli_state
*cli
)
1637 union smb_fileinfo finfo
;
1638 const char *fname
= BASEDIR
"\\torture_open_for_delete.txt";
1643 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
), "Failed to setup up test directory: " BASEDIR
);
1645 /* reasonable default parameters */
1646 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
1647 io
.ntcreatex
.in
.flags
= NTCREATEX_FLAGS_EXTENDED
;
1648 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
1649 io
.ntcreatex
.in
.alloc_size
= 0;
1650 io
.ntcreatex
.in
.access_mask
= SEC_RIGHTS_FILE_ALL
;
1651 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_READONLY
;
1652 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
1653 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
1654 io
.ntcreatex
.in
.create_options
= 0;
1655 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
1656 io
.ntcreatex
.in
.security_flags
= 0;
1657 io
.ntcreatex
.in
.fname
= fname
;
1659 /* Create the readonly file. */
1661 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1662 CHECK_STATUS(status
, NT_STATUS_OK
);
1663 fnum
= io
.ntcreatex
.out
.file
.fnum
;
1665 CHECK_VAL(io
.ntcreatex
.out
.oplock_level
, 0);
1666 io
.ntcreatex
.in
.create_options
= 0;
1667 CHECK_VAL(io
.ntcreatex
.out
.create_action
, NTCREATEX_ACTION_CREATED
);
1668 CHECK_ALL_INFO(io
.ntcreatex
.out
.attrib
, attrib
);
1669 smbcli_close(cli
->tree
, fnum
);
1671 /* Now try and open for delete only - should succeed. */
1672 io
.ntcreatex
.in
.access_mask
= SEC_STD_DELETE
;
1673 io
.ntcreatex
.in
.file_attr
= 0;
1674 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
| NTCREATEX_SHARE_ACCESS_DELETE
;
1675 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
1676 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1677 CHECK_STATUS(status
, NT_STATUS_OK
);
1679 smbcli_unlink(cli
->tree
, fname
);
1682 smbcli_close(cli
->tree
, fnum
);
1683 smbcli_deltree(cli
->tree
, BASEDIR
);
1689 test chained RAW_OPEN_NTCREATEX_READX
1690 Send chained NTCREATEX_READX on a file that doesn't exist, then create
1691 the file and try again.
1693 static bool test_chained_ntcreatex_readx(struct torture_context
*tctx
, struct smbcli_state
*cli
)
1695 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
1697 const char *fname
= BASEDIR
"\\torture_chained.txt";
1701 const char buf
[] = "test";
1706 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
), "Failed to setup up test directory: " BASEDIR
);
1708 torture_comment(tctx
, "Checking RAW_NTCREATEX_READX chained on "
1709 "non-existent file \n");
1711 /* ntcreatex parameters */
1712 io
.generic
.level
= RAW_OPEN_NTCREATEX_READX
;
1713 io
.ntcreatexreadx
.in
.flags
= 0;
1714 io
.ntcreatexreadx
.in
.root_fid
.fnum
= 0;
1715 io
.ntcreatexreadx
.in
.access_mask
= SEC_FILE_READ_DATA
;
1716 io
.ntcreatexreadx
.in
.alloc_size
= 0;
1717 io
.ntcreatexreadx
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1718 io
.ntcreatexreadx
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
1719 NTCREATEX_SHARE_ACCESS_WRITE
| NTCREATEX_SHARE_ACCESS_DELETE
;
1720 io
.ntcreatexreadx
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
1721 io
.ntcreatexreadx
.in
.create_options
= 0;
1722 io
.ntcreatexreadx
.in
.impersonation
= NTCREATEX_IMPERSONATION_IMPERSONATION
;
1723 io
.ntcreatexreadx
.in
.security_flags
= 0;
1724 io
.ntcreatexreadx
.in
.fname
= fname
;
1726 /* readx parameters */
1727 io
.ntcreatexreadx
.in
.offset
= 0;
1728 io
.ntcreatexreadx
.in
.mincnt
= sizeof(buf2
);
1729 io
.ntcreatexreadx
.in
.maxcnt
= sizeof(buf2
);
1730 io
.ntcreatexreadx
.in
.remaining
= 0;
1731 io
.ntcreatexreadx
.out
.data
= (uint8_t *)buf2
;
1733 /* try to open the non-existent file */
1734 status
= smb_raw_open(cli
->tree
, mem_ctx
, &io
);
1735 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
1736 fnum
= io
.ntcreatexreadx
.out
.file
.fnum
;
1738 smbcli_close(cli
->tree
, fnum
);
1739 smbcli_unlink(cli
->tree
, fname
);
1741 torture_comment(tctx
, "Checking RAW_NTCREATEX_READX chained on "
1742 "existing file \n");
1744 fnum
= create_complex_file(cli
, mem_ctx
, fname
);
1745 smbcli_write(cli
->tree
, fnum
, 0, buf
, 0, sizeof(buf
));
1746 smbcli_close(cli
->tree
, fnum
);
1748 status
= smb_raw_open(cli
->tree
, mem_ctx
, &io
);
1749 CHECK_STATUS(status
, NT_STATUS_OK
);
1750 fnum
= io
.ntcreatexreadx
.out
.file
.fnum
;
1752 if (memcmp(buf
, buf2
, MIN(sizeof(buf
), sizeof(buf2
))) != 0) {
1753 torture_result(tctx
, TORTURE_FAIL
,
1754 "(%s): wrong data in reply buffer\n", __location__
);
1759 smbcli_close(cli
->tree
, fnum
);
1760 smbcli_deltree(cli
->tree
, BASEDIR
);
1761 talloc_free(mem_ctx
);
1766 static bool test_ntcreatex_opendisp_dir(struct torture_context
*tctx
,
1767 struct smbcli_state
*cli
)
1769 const char *dname
= BASEDIR
"\\torture_ntcreatex_opendisp_dir";
1776 NTSTATUS correct_status
;
1777 } open_funcs_dir
[] = {
1778 { NTCREATEX_DISP_SUPERSEDE
, true, NT_STATUS_INVALID_PARAMETER
},
1779 { NTCREATEX_DISP_SUPERSEDE
, false, NT_STATUS_INVALID_PARAMETER
},
1780 { NTCREATEX_DISP_OPEN
, true, NT_STATUS_OK
},
1781 { NTCREATEX_DISP_OPEN
, false, NT_STATUS_OBJECT_NAME_NOT_FOUND
},
1782 { NTCREATEX_DISP_CREATE
, true, NT_STATUS_OBJECT_NAME_COLLISION
},
1783 { NTCREATEX_DISP_CREATE
, false, NT_STATUS_OK
},
1784 { NTCREATEX_DISP_OPEN_IF
, true, NT_STATUS_OK
},
1785 { NTCREATEX_DISP_OPEN_IF
, false, NT_STATUS_OK
},
1786 { NTCREATEX_DISP_OVERWRITE
, true, NT_STATUS_INVALID_PARAMETER
},
1787 { NTCREATEX_DISP_OVERWRITE
, false, NT_STATUS_INVALID_PARAMETER
},
1788 { NTCREATEX_DISP_OVERWRITE_IF
, true, NT_STATUS_INVALID_PARAMETER
},
1789 { NTCREATEX_DISP_OVERWRITE_IF
, false, NT_STATUS_INVALID_PARAMETER
},
1790 { 6, true, NT_STATUS_INVALID_PARAMETER
},
1791 { 6, false, NT_STATUS_INVALID_PARAMETER
},
1796 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
1797 io
.ntcreatex
.in
.flags
= NTCREATEX_FLAGS_EXTENDED
;
1798 io
.ntcreatex
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1799 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_DIRECTORY
;
1800 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
| NTCREATEX_SHARE_ACCESS_WRITE
;
1801 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1802 io
.ntcreatex
.in
.fname
= dname
;
1804 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
), "Failed to setup up test directory: " BASEDIR
);
1806 smbcli_rmdir(cli
->tree
, dname
);
1807 smbcli_unlink(cli
->tree
, dname
);
1809 /* test the open disposition for directories */
1810 torture_comment(tctx
, "Testing open dispositions for directories...\n");
1812 for (i
=0; i
<ARRAY_SIZE(open_funcs_dir
); i
++) {
1813 if (open_funcs_dir
[i
].dir_exists
) {
1814 status
= smbcli_mkdir(cli
->tree
, dname
);
1815 if (!NT_STATUS_IS_OK(status
)) {
1816 torture_result(tctx
, TORTURE_FAIL
,
1817 "(%s): Failed to make directory "
1818 "%s - %s\n", __location__
, dname
,
1819 smbcli_errstr(cli
->tree
));
1825 io
.ntcreatex
.in
.open_disposition
= open_funcs_dir
[i
].open_disp
;
1826 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1827 if (!NT_STATUS_EQUAL(status
, open_funcs_dir
[i
].correct_status
)) {
1828 torture_result(tctx
, TORTURE_FAIL
,
1829 "(%s) incorrect status %s should be %s "
1830 "(i=%d dir_exists=%d open_disp=%d)\n",
1831 __location__
, nt_errstr(status
),
1832 nt_errstr(open_funcs_dir
[i
].correct_status
),
1833 i
, (int)open_funcs_dir
[i
].dir_exists
,
1834 (int)open_funcs_dir
[i
].open_disp
);
1837 if (NT_STATUS_IS_OK(status
) || open_funcs_dir
[i
].dir_exists
) {
1838 smbcli_close(cli
->tree
, io
.ntcreatex
.out
.file
.fnum
);
1839 smbcli_rmdir(cli
->tree
, dname
);
1844 smbcli_deltree(cli
->tree
, BASEDIR
);
1850 * Test what happens when trying to open a file with directory parameters and
1851 * vice-versa. Also test that NTCREATEX_OPTIONS_DIRECTORY is treated as
1852 * mandatory and FILE_ATTRIBUTE_DIRECTORY is advisory for directory
1855 static bool test_ntcreatexdir(struct torture_context
*tctx
,
1856 struct smbcli_state
*cli
)
1859 const char *fname
= BASEDIR
"\\torture_ntcreatex.txt";
1860 const char *dname
= BASEDIR
"\\torture_ntcreatex_dir";
1867 uint32_t create_options
;
1868 NTSTATUS correct_status
;
1870 { NTCREATEX_DISP_SUPERSEDE
, 0, NTCREATEX_OPTIONS_DIRECTORY
,
1871 NT_STATUS_INVALID_PARAMETER
},
1872 { NTCREATEX_DISP_OPEN
, 0, NTCREATEX_OPTIONS_DIRECTORY
,
1873 NT_STATUS_OBJECT_NAME_NOT_FOUND
},
1874 { NTCREATEX_DISP_CREATE
, 0, NTCREATEX_OPTIONS_DIRECTORY
,
1876 { NTCREATEX_DISP_OPEN_IF
, 0, NTCREATEX_OPTIONS_DIRECTORY
,
1878 { NTCREATEX_DISP_OVERWRITE
, 0, NTCREATEX_OPTIONS_DIRECTORY
,
1879 NT_STATUS_INVALID_PARAMETER
},
1880 { NTCREATEX_DISP_OVERWRITE_IF
, 0, NTCREATEX_OPTIONS_DIRECTORY
,
1881 NT_STATUS_INVALID_PARAMETER
},
1882 { NTCREATEX_DISP_SUPERSEDE
, FILE_ATTRIBUTE_DIRECTORY
, 0,
1884 { NTCREATEX_DISP_OPEN
, FILE_ATTRIBUTE_DIRECTORY
, 0,
1885 NT_STATUS_OBJECT_NAME_NOT_FOUND
},
1886 { NTCREATEX_DISP_CREATE
, FILE_ATTRIBUTE_DIRECTORY
, 0,
1888 { NTCREATEX_DISP_OPEN_IF
, FILE_ATTRIBUTE_DIRECTORY
, 0,
1890 { NTCREATEX_DISP_OVERWRITE
, FILE_ATTRIBUTE_DIRECTORY
, 0,
1891 NT_STATUS_OBJECT_NAME_NOT_FOUND
},
1892 { NTCREATEX_DISP_OVERWRITE_IF
, FILE_ATTRIBUTE_DIRECTORY
, 0,
1897 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
), "Failed to setup up test directory: " BASEDIR
);
1899 /* setup some base params. */
1900 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
1901 io
.ntcreatex
.in
.flags
= NTCREATEX_FLAGS_EXTENDED
;
1902 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
1903 io
.ntcreatex
.in
.access_mask
= SEC_RIGHTS_FILE_ALL
;
1904 io
.ntcreatex
.in
.alloc_size
= 0;
1905 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
1906 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
1907 io
.ntcreatex
.in
.security_flags
= 0;
1908 io
.ntcreatex
.in
.fname
= fname
;
1911 * Test the validity checking for create dispositions, which is done
1912 * against the requested parameters rather than what's actually on
1915 for (i
=0; i
<ARRAY_SIZE(open_funcs
); i
++) {
1916 io
.ntcreatex
.in
.open_disposition
= open_funcs
[i
].open_disp
;
1917 io
.ntcreatex
.in
.file_attr
= open_funcs
[i
].file_attr
;
1918 io
.ntcreatex
.in
.create_options
= open_funcs
[i
].create_options
;
1919 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1920 if (!NT_STATUS_EQUAL(status
, open_funcs
[i
].correct_status
)) {
1921 torture_result(tctx
, TORTURE_FAIL
,
1922 "(%s) incorrect status %s should be %s "
1923 "(i=%d open_disp=%d)\n",
1924 __location__
, nt_errstr(status
),
1925 nt_errstr(open_funcs
[i
].correct_status
),
1926 i
, (int)open_funcs
[i
].open_disp
);
1929 /* Close and delete the file. */
1930 if (NT_STATUS_IS_OK(status
)) {
1931 if (open_funcs
[i
].create_options
!= 0) {
1932 /* out attrib should be a directory. */
1933 torture_assert_int_equal(tctx
,
1934 io
.ntcreatex
.out
.attrib
,
1935 FILE_ATTRIBUTE_DIRECTORY
, "should have "
1936 "created a directory");
1938 smbcli_close(cli
->tree
,
1939 io
.ntcreatex
.out
.file
.fnum
);
1941 /* Make sure unlink fails. */
1942 status
= smbcli_unlink(cli
->tree
, fname
);
1943 torture_assert_ntstatus_equal(tctx
, status
,
1944 NT_STATUS_FILE_IS_A_DIRECTORY
,
1945 "unlink should fail for a directory");
1947 status
= smbcli_rmdir(cli
->tree
, fname
);
1948 torture_assert_ntstatus_ok(tctx
, status
,
1951 torture_assert_int_equal(tctx
,
1952 io
.ntcreatex
.out
.attrib
,
1953 FILE_ATTRIBUTE_ARCHIVE
, "should not have "
1954 "created a directory");
1956 smbcli_close(cli
->tree
,
1957 io
.ntcreatex
.out
.file
.fnum
);
1959 /* Make sure rmdir fails. */
1960 status
= smbcli_rmdir(cli
->tree
, fname
);
1961 torture_assert_ntstatus_equal(tctx
, status
,
1962 NT_STATUS_NOT_A_DIRECTORY
,
1963 "rmdir should fail for a file");
1965 status
= smbcli_unlink(cli
->tree
, fname
);
1966 torture_assert_ntstatus_ok(tctx
, status
,
1972 /* Create a file. */
1973 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
1974 io
.ntcreatex
.in
.create_options
= 0;
1975 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
1976 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1977 torture_assert_ntstatus_ok(tctx
, status
, "Failed to create file.");
1978 smbcli_close(cli
->tree
, io
.ntcreatex
.out
.file
.fnum
);
1980 /* Try and open the file with file_attr_dir and check the error. */
1981 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_DIRECTORY
;
1982 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
1984 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1985 torture_assert_ntstatus_ok(tctx
, status
, "FILE_ATTRIBUTE_DIRECTORY "
1986 "doesn't produce a hard failure.");
1987 smbcli_close(cli
->tree
, io
.ntcreatex
.out
.file
.fnum
);
1989 /* Try and open file with createx_option_dir and check the error. */
1990 io
.ntcreatex
.in
.file_attr
= 0;
1991 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
1993 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
1994 torture_assert_ntstatus_equal(tctx
, status
, NT_STATUS_NOT_A_DIRECTORY
,
1995 "NTCREATEX_OPTIONS_DIRECTORY will a file from being opened.");
1996 smbcli_close(cli
->tree
, io
.ntcreatex
.out
.file
.fnum
);
1998 /* Delete the file and move onto directory testing. */
1999 smbcli_unlink(cli
->tree
, fname
);
2001 /* Now try some tests on a directory. */
2002 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
2003 io
.ntcreatex
.in
.file_attr
= 0;
2004 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_DIRECTORY
;
2005 io
.ntcreatex
.in
.fname
= dname
;
2007 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
2008 torture_assert_ntstatus_ok(tctx
, status
, "Failed to create dir.");
2010 /* out attrib should be a directory. */
2011 torture_assert_int_equal(tctx
, io
.ntcreatex
.out
.attrib
,
2012 FILE_ATTRIBUTE_DIRECTORY
, "should have created a directory");
2014 smbcli_close(cli
->tree
, io
.ntcreatex
.out
.file
.fnum
);
2016 /* Try and open it with normal attr and check the error. */
2017 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
2018 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
2020 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
2021 torture_assert_ntstatus_ok(tctx
, status
, "FILE_ATTRIBUTE_NORMAL "
2022 "doesn't produce a hard failure.");
2023 smbcli_close(cli
->tree
, io
.ntcreatex
.out
.file
.fnum
);
2025 /* Try and open it with file create_options and check the error. */
2026 io
.ntcreatex
.in
.file_attr
= 0;
2027 io
.ntcreatex
.in
.create_options
= NTCREATEX_OPTIONS_NON_DIRECTORY_FILE
;
2029 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
2030 torture_assert_ntstatus_equal(tctx
, status
,
2031 NT_STATUS_FILE_IS_A_DIRECTORY
,
2032 "NTCREATEX_OPTIONS_NON_DIRECTORY_FILE should be returned ");
2033 smbcli_close(cli
->tree
, io
.ntcreatex
.out
.file
.fnum
);
2035 smbcli_deltree(cli
->tree
, BASEDIR
);
2041 test opening with truncate on an already open file
2042 returns share violation and doesn't truncate the file.
2043 Regression test for bug #10671.
2045 static bool test_open_for_truncate(struct torture_context
*tctx
, struct smbcli_state
*cli
)
2048 union smb_fileinfo finfo
;
2049 const char *fname
= BASEDIR
"\\torture_open_for_truncate.txt";
2056 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
),
2057 "Failed to setup up test directory: " BASEDIR
);
2059 torture_comment(tctx
, "Testing open truncate disposition.\n");
2061 /* reasonable default parameters */
2063 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
2064 io
.ntcreatex
.in
.flags
= NTCREATEX_FLAGS_EXTENDED
;
2065 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
2066 io
.ntcreatex
.in
.alloc_size
= 0;
2067 io
.ntcreatex
.in
.access_mask
= SEC_RIGHTS_FILE_ALL
;
2068 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
2069 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
2070 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
2071 io
.ntcreatex
.in
.create_options
= 0;
2072 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
2073 io
.ntcreatex
.in
.security_flags
= 0;
2074 io
.ntcreatex
.in
.fname
= fname
;
2076 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
2077 CHECK_STATUS(status
, NT_STATUS_OK
);
2078 fnum
= io
.ntcreatex
.out
.file
.fnum
;
2080 /* Write a byte at offset 1k-1. */
2081 val
=smbcli_write(cli
->tree
, fnum
, 0, &c
, 1023, 1);
2082 torture_assert_int_equal(tctx
, val
, 1, "write failed\n");
2084 /* Now try and open for read/write with truncate - should fail. */
2085 io
.ntcreatex
.in
.access_mask
= SEC_RIGHTS_FILE_WRITE
|SEC_RIGHTS_FILE_READ
;
2086 io
.ntcreatex
.in
.file_attr
= 0;
2087 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_READ
|
2088 NTCREATEX_SHARE_ACCESS_WRITE
|
2089 NTCREATEX_SHARE_ACCESS_DELETE
;
2090 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OVERWRITE
;
2091 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
2092 CHECK_STATUS(status
, NT_STATUS_SHARING_VIOLATION
);
2094 /* Ensure file size is still 1k */
2095 finfo
.generic
.level
= RAW_FILEINFO_GETATTRE
;
2096 finfo
.generic
.in
.file
.fnum
= fnum
;
2097 status
= smb_raw_fileinfo(cli
->tree
, tctx
, &finfo
);
2098 CHECK_STATUS(status
, NT_STATUS_OK
);
2099 CHECK_VAL(finfo
.getattre
.out
.size
, 1024);
2101 smbcli_close(cli
->tree
, fnum
);
2103 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
2104 CHECK_STATUS(status
, NT_STATUS_OK
);
2105 fnum
= io
.ntcreatex
.out
.file
.fnum
;
2107 /* Ensure truncate actually works */
2108 finfo
.generic
.level
= RAW_FILEINFO_GETATTRE
;
2109 finfo
.generic
.in
.file
.fnum
= fnum
;
2110 status
= smb_raw_fileinfo(cli
->tree
, tctx
, &finfo
);
2111 CHECK_STATUS(status
, NT_STATUS_OK
);
2112 CHECK_VAL(finfo
.getattre
.out
.size
, 0);
2114 smbcli_close(cli
->tree
, fnum
);
2115 smbcli_unlink(cli
->tree
, fname
);
2118 smbcli_close(cli
->tree
, fnum
);
2119 smbcli_deltree(cli
->tree
, BASEDIR
);
2125 * Test for file size to be 0 after create with FILE_SUPERSEDE
2127 static bool test_ntcreatex_supersede(struct torture_context
*tctx
, struct smbcli_state
*cli
)
2130 union smb_setfileinfo sfi
;
2131 union smb_fileinfo finfo
;
2132 const char *fname
= BASEDIR
"\\torture_ntcreatex_supersede.txt";
2137 torture_assert(tctx
, torture_setup_dir(cli
, BASEDIR
), "Failed to setup up test directory: " BASEDIR
);
2139 /* reasonable default parameters */
2140 io
.generic
.level
= RAW_OPEN_NTCREATEX
;
2141 io
.ntcreatex
.in
.flags
= 0;
2142 io
.ntcreatex
.in
.root_fid
.fnum
= 0;
2143 io
.ntcreatex
.in
.access_mask
= SEC_RIGHTS_FILE_ALL
;
2144 io
.ntcreatex
.in
.alloc_size
= 0;
2145 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
2146 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
2147 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_CREATE
;
2148 io
.ntcreatex
.in
.create_options
= 0;
2149 io
.ntcreatex
.in
.impersonation
= NTCREATEX_IMPERSONATION_ANONYMOUS
;
2150 io
.ntcreatex
.in
.security_flags
= 0;
2151 io
.ntcreatex
.in
.fname
= fname
;
2153 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
2154 CHECK_STATUS(status
, NT_STATUS_OK
);
2155 fnum
= io
.ntcreatex
.out
.file
.fnum
;
2157 CHECK_VAL(io
.ntcreatex
.out
.oplock_level
, 0);
2158 CHECK_VAL(io
.ntcreatex
.out
.create_action
, NTCREATEX_ACTION_CREATED
);
2159 CHECK_NTTIME(io
.ntcreatex
.out
.create_time
, create_time
);
2160 CHECK_NTTIME(io
.ntcreatex
.out
.access_time
, access_time
);
2161 CHECK_NTTIME(io
.ntcreatex
.out
.write_time
, write_time
);
2162 CHECK_NTTIME(io
.ntcreatex
.out
.change_time
, change_time
);
2163 CHECK_ALL_INFO(io
.ntcreatex
.out
.attrib
, attrib
);
2164 CHECK_ALL_INFO(io
.ntcreatex
.out
.alloc_size
, alloc_size
);
2165 CHECK_ALL_INFO(io
.ntcreatex
.out
.size
, size
);
2166 CHECK_ALL_INFO(io
.ntcreatex
.out
.is_directory
, directory
);
2167 CHECK_VAL(io
.ntcreatex
.out
.file_type
, FILE_TYPE_DISK
);
2169 /* extend the file size */
2171 sfi
.generic
.level
= RAW_SFILEINFO_END_OF_FILE_INFO
;
2172 sfi
.generic
.in
.file
.fnum
= fnum
;
2173 sfi
.end_of_file_info
.in
.size
= 512;
2174 status
= smb_raw_setfileinfo(cli
->tree
, &sfi
);
2175 CHECK_STATUS(status
, NT_STATUS_OK
);
2177 /* close the file and re-open with to verify new size */
2178 smbcli_close(cli
->tree
, fnum
);
2179 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_OPEN
;
2180 io
.ntcreatex
.in
.access_mask
= SEC_RIGHTS_FILE_READ
;
2181 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
2182 CHECK_STATUS(status
, NT_STATUS_OK
);
2183 fnum
= io
.ntcreatex
.out
.file
.fnum
;
2185 CHECK_VAL(io
.ntcreatex
.out
.oplock_level
, 0);
2186 CHECK_VAL(io
.ntcreatex
.out
.create_action
, NTCREATEX_ACTION_EXISTED
);
2187 CHECK_NTTIME(io
.ntcreatex
.out
.create_time
, create_time
);
2188 CHECK_NTTIME(io
.ntcreatex
.out
.access_time
, access_time
);
2189 CHECK_NTTIME(io
.ntcreatex
.out
.write_time
, write_time
);
2190 CHECK_NTTIME(io
.ntcreatex
.out
.change_time
, change_time
);
2191 CHECK_ALL_INFO(io
.ntcreatex
.out
.attrib
, attrib
);
2192 CHECK_ALL_INFO(io
.ntcreatex
.out
.alloc_size
, alloc_size
);
2193 CHECK_VAL(io
.ntcreatex
.out
.size
, 512);
2194 CHECK_ALL_INFO(io
.ntcreatex
.out
.is_directory
, directory
);
2195 CHECK_VAL(io
.ntcreatex
.out
.file_type
, FILE_TYPE_DISK
);
2197 /* close and re-open the file with SUPERSEDE flag */
2198 smbcli_close(cli
->tree
, fnum
);
2199 io
.ntcreatex
.in
.open_disposition
= NTCREATEX_DISP_SUPERSEDE
;
2200 io
.ntcreatex
.in
.access_mask
= SEC_RIGHTS_FILE_READ
;
2201 io
.ntcreatex
.in
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
2202 io
.ntcreatex
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
2203 io
.ntcreatex
.in
.create_options
= 0;
2205 status
= smb_raw_open(cli
->tree
, tctx
, &io
);
2206 CHECK_STATUS(status
, NT_STATUS_OK
);
2207 fnum
= io
.ntcreatex
.out
.file
.fnum
;
2209 /* The file size in the superseded create response should be 0 */
2210 CHECK_VAL(io
.ntcreatex
.out
.size
, 0);
2211 CHECK_VAL(io
.ntcreatex
.out
.oplock_level
, 0);
2212 CHECK_VAL(io
.ntcreatex
.out
.create_action
, FILE_WAS_SUPERSEDED
);
2213 CHECK_NTTIME(io
.ntcreatex
.out
.create_time
, create_time
);
2214 CHECK_NTTIME(io
.ntcreatex
.out
.access_time
, access_time
);
2215 CHECK_ALL_INFO(io
.ntcreatex
.out
.attrib
, attrib
);
2216 CHECK_ALL_INFO(io
.ntcreatex
.out
.alloc_size
, alloc_size
);
2217 CHECK_ALL_INFO(io
.ntcreatex
.out
.is_directory
, directory
);
2218 CHECK_VAL(io
.ntcreatex
.out
.file_type
, FILE_TYPE_DISK
);
2220 smbcli_close(cli
->tree
, fnum
);
2221 smbcli_deltree(cli
->tree
, BASEDIR
);
2226 /* basic testing of all RAW_OPEN_* calls
2228 struct torture_suite
*torture_raw_open(TALLOC_CTX
*mem_ctx
)
2230 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "open");
2232 torture_suite_add_1smb_test(suite
, "brlocked", test_ntcreatex_brlocked
);
2233 torture_suite_add_1smb_test(suite
, "open", test_open
);
2234 torture_suite_add_1smb_test(suite
, "open-multi", test_raw_open_multi
);
2235 torture_suite_add_1smb_test(suite
, "openx", test_openx
);
2236 torture_suite_add_1smb_test(suite
, "ntcreatex", test_ntcreatex
);
2237 torture_suite_add_1smb_test(suite
, "nttrans-create", test_nttrans_create
);
2238 torture_suite_add_1smb_test(suite
, "t2open", test_t2open
);
2239 torture_suite_add_1smb_test(suite
, "mknew", test_mknew
);
2240 torture_suite_add_1smb_test(suite
, "create", test_create
);
2241 torture_suite_add_1smb_test(suite
, "ctemp", test_ctemp
);
2242 torture_suite_add_1smb_test(suite
, "chained-openx", test_chained
);
2243 torture_suite_add_1smb_test(suite
, "chained-ntcreatex", test_chained_ntcreatex_readx
);
2244 torture_suite_add_1smb_test(suite
, "no-leading-slash", test_no_leading_slash
);
2245 torture_suite_add_1smb_test(suite
, "openx-over-dir", test_openx_over_dir
);
2246 torture_suite_add_1smb_test(suite
, "open-for-delete", test_open_for_delete
);
2247 torture_suite_add_1smb_test(suite
, "opendisp-dir", test_ntcreatex_opendisp_dir
);
2248 torture_suite_add_1smb_test(suite
, "ntcreatedir", test_ntcreatexdir
);
2249 torture_suite_add_1smb_test(suite
, "open-for-truncate", test_open_for_truncate
);
2250 torture_suite_add_1smb_test(suite
, "ntcreatex_supersede", test_ntcreatex_supersede
);