2 Unix SMB/CIFS implementation.
4 test suite for SMB2 durable opens
6 Copyright (C) Stefan Metzmacher 2008
7 Copyright (C) Michael Adam 2011-2012
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "libcli/smb2/smb2.h"
25 #include "libcli/smb2/smb2_calls.h"
26 #include "../libcli/smb/smbXcli_base.h"
27 #include "torture/torture.h"
28 #include "torture/smb2/proto.h"
29 #include "../libcli/smb/smbXcli_base.h"
31 #define CHECK_VAL(v, correct) do { \
32 if ((v) != (correct)) { \
33 torture_result(tctx, TORTURE_FAIL, "(%s): wrong value for %s got 0x%llx - should be 0x%llx\n", \
34 __location__, #v, (unsigned long long)v, (unsigned long long)correct); \
38 #define CHECK_NOT_VAL(v, correct) do { \
39 if ((v) == (correct)) { \
40 torture_result(tctx, TORTURE_FAIL, "(%s): wrong value for %s got 0x%llx - should not be 0x%llx\n", \
41 __location__, #v, (unsigned long long)v, (unsigned long long)correct); \
45 #define CHECK_STATUS(status, correct) do { \
46 if (!NT_STATUS_EQUAL(status, correct)) { \
47 torture_result(tctx, TORTURE_FAIL, __location__": Incorrect status %s - should be %s", \
48 nt_errstr(status), nt_errstr(correct)); \
53 #define CHECK_CREATED(__io, __created, __attribute) \
55 CHECK_VAL((__io)->out.create_action, NTCREATEX_ACTION_ ## __created); \
56 CHECK_VAL((__io)->out.alloc_size, 0); \
57 CHECK_VAL((__io)->out.size, 0); \
58 CHECK_VAL((__io)->out.file_attr, (__attribute)); \
59 CHECK_VAL((__io)->out.reserved2, 0); \
62 #define CHECK_CREATED_SIZE(__io, __created, __attribute, __alloc_size, __size) \
64 CHECK_VAL((__io)->out.create_action, NTCREATEX_ACTION_ ## __created); \
65 CHECK_VAL((__io)->out.alloc_size, (__alloc_size)); \
66 CHECK_VAL((__io)->out.size, (__size)); \
67 CHECK_VAL((__io)->out.file_attr, (__attribute)); \
68 CHECK_VAL((__io)->out.reserved2, 0); \
74 * basic durable_open test.
75 * durable state should only be granted when requested
76 * along with a batch oplock or a handle lease.
78 * This test tests durable open with all possible oplock types.
81 struct durable_open_vs_oplock
{
83 const char *share_mode
;
87 #define NUM_OPLOCK_TYPES 4
88 #define NUM_SHARE_MODES 8
89 #define NUM_OPLOCK_OPEN_TESTS ( NUM_OPLOCK_TYPES * NUM_SHARE_MODES )
90 static struct durable_open_vs_oplock durable_open_vs_oplock_table
[NUM_OPLOCK_OPEN_TESTS
] =
105 { "s", "RD", false },
106 { "s", "RW", false },
107 { "s", "WD", false },
108 { "s", "RWD", false },
114 { "x", "RD", false },
115 { "x", "RW", false },
116 { "x", "WD", false },
117 { "x", "RWD", false },
126 { "b", "RWD", true },
129 static bool test_one_durable_open_open_oplock(struct torture_context
*tctx
,
130 struct smb2_tree
*tree
,
132 struct durable_open_vs_oplock test
)
135 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
136 struct smb2_handle _h
;
137 struct smb2_handle
*h
= NULL
;
139 struct smb2_create io
;
141 smb2_util_unlink(tree
, fname
);
143 smb2_oplock_create_share(&io
, fname
,
144 smb2_util_share_access(test
.share_mode
),
145 smb2_util_oplock_level(test
.level
));
146 io
.in
.durable_open
= true;
148 status
= smb2_create(tree
, mem_ctx
, &io
);
149 CHECK_STATUS(status
, NT_STATUS_OK
);
150 _h
= io
.out
.file
.handle
;
152 CHECK_CREATED(&io
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
153 CHECK_VAL(io
.out
.durable_open
, test
.expected
);
154 CHECK_VAL(io
.out
.oplock_level
, smb2_util_oplock_level(test
.level
));
158 smb2_util_close(tree
, *h
);
160 smb2_util_unlink(tree
, fname
);
161 talloc_free(mem_ctx
);
166 bool test_durable_open_open_oplock(struct torture_context
*tctx
,
167 struct smb2_tree
*tree
)
169 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
174 /* Choose a random name in case the state is left a little funky. */
175 snprintf(fname
, 256, "durable_open_open_oplock_%s.dat", generate_random_str(tctx
, 8));
177 smb2_util_unlink(tree
, fname
);
179 /* test various oplock levels with durable open */
181 for (i
= 0; i
< NUM_OPLOCK_OPEN_TESTS
; i
++) {
182 ret
= test_one_durable_open_open_oplock(tctx
,
185 durable_open_vs_oplock_table
[i
]);
192 smb2_util_unlink(tree
, fname
);
194 talloc_free(mem_ctx
);
200 * basic durable_open test.
201 * durable state should only be granted when requested
202 * along with a batch oplock or a handle lease.
204 * This test tests durable open with all valid lease types.
207 struct durable_open_vs_lease
{
209 const char *share_mode
;
213 #define NUM_LEASE_TYPES 5
214 #define NUM_LEASE_OPEN_TESTS ( NUM_LEASE_TYPES * NUM_SHARE_MODES )
215 static struct durable_open_vs_lease durable_open_vs_lease_table
[NUM_LEASE_OPEN_TESTS
] =
224 { "", "RWD", false },
230 { "R", "RW", false },
231 { "R", "RD", false },
232 { "R", "DW", false },
233 { "R", "RWD", false },
236 { "RW", "R", false },
237 { "RW", "W", false },
238 { "RW", "D", false },
239 { "RW", "RW", false },
240 { "RW", "RD", false },
241 { "RW", "WD", false },
242 { "RW", "RWD", false },
248 { "RH", "RW", true },
249 { "RH", "RD", true },
250 { "RH", "WD", true },
251 { "RH", "RWD", true },
254 { "RHW", "R", true },
255 { "RHW", "W", true },
256 { "RHW", "D", true },
257 { "RHW", "RW", true },
258 { "RHW", "RD", true },
259 { "RHW", "WD", true },
260 { "RHW", "RWD", true },
263 static bool test_one_durable_open_open_lease(struct torture_context
*tctx
,
264 struct smb2_tree
*tree
,
266 struct durable_open_vs_lease test
)
269 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
270 struct smb2_handle _h
;
271 struct smb2_handle
*h
= NULL
;
273 struct smb2_create io
;
274 struct smb2_lease ls
;
278 caps
= smb2cli_conn_server_capabilities(tree
->session
->transport
->conn
);
279 if (!(caps
& SMB2_CAP_LEASING
)) {
280 torture_skip(tctx
, "leases are not supported");
283 smb2_util_unlink(tree
, fname
);
287 smb2_lease_create_share(&io
, &ls
, false /* dir */, fname
,
288 smb2_util_share_access(test
.share_mode
),
290 smb2_util_lease_state(test
.type
));
291 io
.in
.durable_open
= true;
293 status
= smb2_create(tree
, mem_ctx
, &io
);
294 CHECK_STATUS(status
, NT_STATUS_OK
);
295 _h
= io
.out
.file
.handle
;
297 CHECK_CREATED(&io
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
298 CHECK_VAL(io
.out
.durable_open
, test
.expected
);
299 CHECK_VAL(io
.out
.oplock_level
, SMB2_OPLOCK_LEVEL_LEASE
);
300 CHECK_VAL(io
.out
.lease_response
.lease_key
.data
[0], lease
);
301 CHECK_VAL(io
.out
.lease_response
.lease_key
.data
[1], ~lease
);
302 CHECK_VAL(io
.out
.lease_response
.lease_state
,
303 smb2_util_lease_state(test
.type
));
306 smb2_util_close(tree
, *h
);
308 smb2_util_unlink(tree
, fname
);
309 talloc_free(mem_ctx
);
314 bool test_durable_open_open_lease(struct torture_context
*tctx
,
315 struct smb2_tree
*tree
)
317 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
323 caps
= smb2cli_conn_server_capabilities(tree
->session
->transport
->conn
);
324 if (!(caps
& SMB2_CAP_LEASING
)) {
325 torture_skip(tctx
, "leases are not supported");
328 /* Choose a random name in case the state is left a little funky. */
329 snprintf(fname
, 256, "durable_open_open_lease_%s.dat", generate_random_str(tctx
, 8));
331 smb2_util_unlink(tree
, fname
);
334 /* test various oplock levels with durable open */
336 for (i
= 0; i
< NUM_LEASE_OPEN_TESTS
; i
++) {
337 ret
= test_one_durable_open_open_lease(tctx
,
340 durable_open_vs_lease_table
[i
]);
347 smb2_util_unlink(tree
, fname
);
349 talloc_free(mem_ctx
);
355 * basic test for doing a durable open
356 * and do a durable reopen on the same connection
357 * while the first open is still active (fails)
359 bool test_durable_open_reopen1(struct torture_context
*tctx
,
360 struct smb2_tree
*tree
)
363 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
365 struct smb2_handle _h
;
366 struct smb2_handle
*h
= NULL
;
367 struct smb2_create io1
, io2
;
370 /* Choose a random name in case the state is left a little funky. */
371 snprintf(fname
, 256, "durable_open_reopen1_%s.dat",
372 generate_random_str(tctx
, 8));
374 smb2_util_unlink(tree
, fname
);
376 smb2_oplock_create_share(&io1
, fname
,
377 smb2_util_share_access(""),
378 smb2_util_oplock_level("b"));
379 io1
.in
.durable_open
= true;
381 status
= smb2_create(tree
, mem_ctx
, &io1
);
382 CHECK_STATUS(status
, NT_STATUS_OK
);
383 _h
= io1
.out
.file
.handle
;
385 CHECK_CREATED(&io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
386 CHECK_VAL(io1
.out
.durable_open
, true);
387 CHECK_VAL(io1
.out
.oplock_level
, smb2_util_oplock_level("b"));
389 /* try a durable reconnect while the file is still open */
391 io2
.in
.fname
= fname
;
392 io2
.in
.durable_handle
= h
;
394 status
= smb2_create(tree
, mem_ctx
, &io2
);
395 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
399 smb2_util_close(tree
, *h
);
402 smb2_util_unlink(tree
, fname
);
406 talloc_free(mem_ctx
);
412 * basic test for doing a durable open
413 * tcp disconnect, reconnect, do a durable reopen (succeeds)
415 bool test_durable_open_reopen2(struct torture_context
*tctx
,
416 struct smb2_tree
*tree
)
419 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
421 struct smb2_handle _h
;
422 struct smb2_handle
*h
= NULL
;
423 struct smb2_create io1
, io2
;
426 /* Choose a random name in case the state is left a little funky. */
427 snprintf(fname
, 256, "durable_open_reopen2_%s.dat",
428 generate_random_str(tctx
, 8));
430 smb2_util_unlink(tree
, fname
);
432 smb2_oplock_create_share(&io1
, fname
,
433 smb2_util_share_access(""),
434 smb2_util_oplock_level("b"));
435 io1
.in
.durable_open
= true;
437 status
= smb2_create(tree
, mem_ctx
, &io1
);
438 CHECK_STATUS(status
, NT_STATUS_OK
);
439 _h
= io1
.out
.file
.handle
;
441 CHECK_CREATED(&io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
442 CHECK_VAL(io1
.out
.durable_open
, true);
443 CHECK_VAL(io1
.out
.oplock_level
, smb2_util_oplock_level("b"));
445 /* disconnect, reconnect and then do durable reopen */
449 if (!torture_smb2_connection(tctx
, &tree
)) {
450 torture_warning(tctx
, "couldn't reconnect, bailing\n");
456 /* the path name is ignored by the server */
457 io2
.in
.fname
= "__non_existing_fname__";
458 io2
.in
.durable_handle
= h
;
461 status
= smb2_create(tree
, mem_ctx
, &io2
);
462 CHECK_STATUS(status
, NT_STATUS_OK
);
463 CHECK_CREATED(&io2
, EXISTED
, FILE_ATTRIBUTE_ARCHIVE
);
464 CHECK_VAL(io2
.out
.oplock_level
, smb2_util_oplock_level("b"));
465 _h
= io2
.out
.file
.handle
;
470 smb2_util_close(tree
, *h
);
473 smb2_util_unlink(tree
, fname
);
477 talloc_free(mem_ctx
);
483 * basic test for doing a durable open
484 * tcp disconnect, reconnect with a session reconnect and
485 * do a durable reopen (succeeds)
487 bool test_durable_open_reopen2a(struct torture_context
*tctx
,
488 struct smb2_tree
*tree
)
491 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
493 struct smb2_handle _h
;
494 struct smb2_handle
*h
= NULL
;
495 struct smb2_create io1
, io2
;
496 uint64_t previous_session_id
;
499 /* Choose a random name in case the state is left a little funky. */
500 snprintf(fname
, 256, "durable_open_reopen2_%s.dat",
501 generate_random_str(tctx
, 8));
503 smb2_util_unlink(tree
, fname
);
505 smb2_oplock_create_share(&io1
, fname
,
506 smb2_util_share_access(""),
507 smb2_util_oplock_level("b"));
508 io1
.in
.durable_open
= true;
510 status
= smb2_create(tree
, mem_ctx
, &io1
);
511 CHECK_STATUS(status
, NT_STATUS_OK
);
512 _h
= io1
.out
.file
.handle
;
514 CHECK_CREATED(&io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
515 CHECK_VAL(io1
.out
.durable_open
, true);
516 CHECK_VAL(io1
.out
.oplock_level
, smb2_util_oplock_level("b"));
518 /* disconnect, reconnect and then do durable reopen */
519 previous_session_id
= smb2cli_session_current_id(tree
->session
->smbXcli
);
523 if (!torture_smb2_connection_ext(tctx
, previous_session_id
, &tree
)) {
524 torture_warning(tctx
, "couldn't reconnect, bailing\n");
530 io2
.in
.fname
= fname
;
531 io2
.in
.durable_handle
= h
;
534 status
= smb2_create(tree
, mem_ctx
, &io2
);
535 CHECK_STATUS(status
, NT_STATUS_OK
);
536 CHECK_CREATED(&io2
, EXISTED
, FILE_ATTRIBUTE_ARCHIVE
);
537 CHECK_VAL(io2
.out
.oplock_level
, smb2_util_oplock_level("b"));
538 _h
= io2
.out
.file
.handle
;
543 smb2_util_close(tree
, *h
);
546 smb2_util_unlink(tree
, fname
);
550 talloc_free(mem_ctx
);
557 * basic test for doing a durable open:
558 * tdis, new tcon, try durable reopen (fails)
560 bool test_durable_open_reopen3(struct torture_context
*tctx
,
561 struct smb2_tree
*tree
)
564 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
566 struct smb2_handle _h
;
567 struct smb2_handle
*h
= NULL
;
568 struct smb2_create io1
, io2
;
570 struct smb2_tree
*tree2
;
572 /* Choose a random name in case the state is left a little funky. */
573 snprintf(fname
, 256, "durable_open_reopen3_%s.dat",
574 generate_random_str(tctx
, 8));
576 smb2_util_unlink(tree
, fname
);
578 smb2_oplock_create_share(&io1
, fname
,
579 smb2_util_share_access(""),
580 smb2_util_oplock_level("b"));
581 io1
.in
.durable_open
= true;
583 status
= smb2_create(tree
, mem_ctx
, &io1
);
584 CHECK_STATUS(status
, NT_STATUS_OK
);
585 _h
= io1
.out
.file
.handle
;
587 CHECK_CREATED(&io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
588 CHECK_VAL(io1
.out
.durable_open
, true);
589 CHECK_VAL(io1
.out
.oplock_level
, smb2_util_oplock_level("b"));
591 /* disconnect, reconnect and then do durable reopen */
592 status
= smb2_tdis(tree
);
593 CHECK_STATUS(status
, NT_STATUS_OK
);
595 if (!torture_smb2_tree_connect(tctx
, tree
->session
, mem_ctx
, &tree2
)) {
596 torture_warning(tctx
, "couldn't reconnect to share, bailing\n");
603 io2
.in
.fname
= fname
;
604 io2
.in
.durable_handle
= h
;
606 status
= smb2_create(tree2
, mem_ctx
, &io2
);
607 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
611 smb2_util_close(tree
, *h
);
614 smb2_util_unlink(tree2
, fname
);
618 talloc_free(mem_ctx
);
624 * basic test for doing a durable open:
625 * logoff, create a new session, do a durable reopen (succeeds)
627 bool test_durable_open_reopen4(struct torture_context
*tctx
,
628 struct smb2_tree
*tree
)
631 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
633 struct smb2_handle _h
;
634 struct smb2_handle
*h
= NULL
;
635 struct smb2_create io1
, io2
;
637 struct smb2_transport
*transport
;
638 struct smb2_session
*session2
;
639 struct smb2_tree
*tree2
;
641 /* Choose a random name in case the state is left a little funky. */
642 snprintf(fname
, 256, "durable_open_reopen4_%s.dat",
643 generate_random_str(tctx
, 8));
645 smb2_util_unlink(tree
, fname
);
647 smb2_oplock_create_share(&io1
, fname
,
648 smb2_util_share_access(""),
649 smb2_util_oplock_level("b"));
650 io1
.in
.durable_open
= true;
651 io1
.in
.create_options
|= NTCREATEX_OPTIONS_DELETE_ON_CLOSE
;
653 status
= smb2_create(tree
, mem_ctx
, &io1
);
654 CHECK_STATUS(status
, NT_STATUS_OK
);
655 _h
= io1
.out
.file
.handle
;
657 CHECK_CREATED(&io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
658 CHECK_VAL(io1
.out
.durable_open
, true);
659 CHECK_VAL(io1
.out
.oplock_level
, smb2_util_oplock_level("b"));
662 * do a session logoff, establish a new session and tree
663 * connect on the same transport, and try a durable reopen
665 transport
= tree
->session
->transport
;
666 status
= smb2_logoff(tree
->session
);
667 CHECK_STATUS(status
, NT_STATUS_OK
);
669 if (!torture_smb2_session_setup(tctx
, transport
,
670 0, /* previous_session_id */
673 torture_warning(tctx
, "session setup failed.\n");
679 * the session setup has talloc-stolen the transport,
680 * so we can safely free the old tree+session for clarity
684 if (!torture_smb2_tree_connect(tctx
, session2
, mem_ctx
, &tree2
)) {
685 torture_warning(tctx
, "tree connect failed.\n");
691 io2
.in
.fname
= fname
;
692 io2
.in
.durable_handle
= h
;
695 status
= smb2_create(tree2
, mem_ctx
, &io2
);
696 CHECK_STATUS(status
, NT_STATUS_OK
);
698 _h
= io2
.out
.file
.handle
;
700 CHECK_CREATED(&io2
, EXISTED
, FILE_ATTRIBUTE_ARCHIVE
);
701 CHECK_VAL(io2
.out
.oplock_level
, smb2_util_oplock_level("b"));
705 smb2_util_close(tree2
, *h
);
708 smb2_util_unlink(tree2
, fname
);
712 talloc_free(mem_ctx
);
717 bool test_durable_open_delete_on_close1(struct torture_context
*tctx
,
718 struct smb2_tree
*tree
)
721 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
723 struct smb2_handle _h
;
724 struct smb2_handle
*h
= NULL
;
725 struct smb2_create io1
, io2
;
729 /* Choose a random name in case the state is left a little funky. */
730 snprintf(fname
, 256, "durable_open_delete_on_close1_%s.dat",
731 generate_random_str(tctx
, 8));
733 smb2_util_unlink(tree
, fname
);
735 smb2_oplock_create_share(&io1
, fname
,
736 smb2_util_share_access(""),
737 smb2_util_oplock_level("b"));
738 io1
.in
.durable_open
= true;
739 io1
.in
.create_options
|= NTCREATEX_OPTIONS_DELETE_ON_CLOSE
;
741 status
= smb2_create(tree
, mem_ctx
, &io1
);
742 CHECK_STATUS(status
, NT_STATUS_OK
);
743 _h
= io1
.out
.file
.handle
;
745 CHECK_CREATED(&io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
746 CHECK_VAL(io1
.out
.durable_open
, true);
747 CHECK_VAL(io1
.out
.oplock_level
, smb2_util_oplock_level("b"));
749 status
= smb2_util_write(tree
, *h
, &b
, 0, 1);
750 CHECK_STATUS(status
, NT_STATUS_OK
);
752 /* disconnect, leaving the durable handle in place */
755 if (!torture_smb2_connection(tctx
, &tree
)) {
756 torture_warning(tctx
, "could not reconnect, bailing\n");
762 * Open the file on the new connection again
763 * and check that it has been newly created,
764 * i.e. delete on close was effective on the disconnected handle.
765 * Also check that the file is really empty,
766 * the previously written byte gone.
768 smb2_oplock_create_share(&io2
, fname
,
769 smb2_util_share_access(""),
770 smb2_util_oplock_level("b"));
771 io2
.in
.create_options
|= NTCREATEX_OPTIONS_DELETE_ON_CLOSE
;
773 status
= smb2_create(tree
, mem_ctx
, &io2
);
774 CHECK_STATUS(status
, NT_STATUS_OK
);
775 _h
= io2
.out
.file
.handle
;
777 CHECK_CREATED_SIZE(&io2
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
, 0, 0);
778 CHECK_VAL(io2
.out
.durable_open
, false);
779 CHECK_VAL(io2
.out
.oplock_level
, smb2_util_oplock_level("b"));
783 smb2_util_close(tree
, *h
);
786 smb2_util_unlink(tree
, fname
);
790 talloc_free(mem_ctx
);
796 basic testing of SMB2 durable opens
797 regarding the position information on the handle
799 bool test_durable_open_file_position(struct torture_context
*tctx
,
800 struct smb2_tree
*tree
)
802 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
803 struct smb2_handle h
;
804 struct smb2_create io
;
806 const char *fname
= "durable_open_position.dat";
807 union smb_fileinfo qfinfo
;
808 union smb_setfileinfo sfinfo
;
811 uint64_t previous_session_id
;
813 smb2_util_unlink(tree
, fname
);
815 smb2_oplock_create(&io
, fname
, SMB2_OPLOCK_LEVEL_BATCH
);
816 io
.in
.durable_open
= true;
818 status
= smb2_create(tree
, mem_ctx
, &io
);
819 CHECK_STATUS(status
, NT_STATUS_OK
);
820 h
= io
.out
.file
.handle
;
821 CHECK_CREATED(&io
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
822 CHECK_VAL(io
.out
.durable_open
, true);
823 CHECK_VAL(io
.out
.oplock_level
, SMB2_OPLOCK_LEVEL_BATCH
);
825 /* TODO: check extra blob content */
828 qfinfo
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
829 qfinfo
.generic
.in
.file
.handle
= h
;
830 status
= smb2_getinfo_file(tree
, mem_ctx
, &qfinfo
);
831 CHECK_STATUS(status
, NT_STATUS_OK
);
832 CHECK_VAL(qfinfo
.position_information
.out
.position
, 0);
833 pos
= qfinfo
.position_information
.out
.position
;
834 torture_comment(tctx
, "position: %llu\n",
835 (unsigned long long)pos
);
838 sfinfo
.generic
.level
= RAW_SFILEINFO_POSITION_INFORMATION
;
839 sfinfo
.generic
.in
.file
.handle
= h
;
840 sfinfo
.position_information
.in
.position
= 0x1000;
841 status
= smb2_setinfo_file(tree
, &sfinfo
);
842 CHECK_STATUS(status
, NT_STATUS_OK
);
845 qfinfo
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
846 qfinfo
.generic
.in
.file
.handle
= h
;
847 status
= smb2_getinfo_file(tree
, mem_ctx
, &qfinfo
);
848 CHECK_STATUS(status
, NT_STATUS_OK
);
849 CHECK_VAL(qfinfo
.position_information
.out
.position
, 0x1000);
850 pos
= qfinfo
.position_information
.out
.position
;
851 torture_comment(tctx
, "position: %llu\n",
852 (unsigned long long)pos
);
854 previous_session_id
= smb2cli_session_current_id(tree
->session
->smbXcli
);
860 /* do a session reconnect */
861 if (!torture_smb2_connection_ext(tctx
, previous_session_id
, &tree
)) {
862 torture_warning(tctx
, "couldn't reconnect, bailing\n");
868 qfinfo
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
869 qfinfo
.generic
.in
.file
.handle
= h
;
870 status
= smb2_getinfo_file(tree
, mem_ctx
, &qfinfo
);
871 CHECK_STATUS(status
, NT_STATUS_FILE_CLOSED
);
875 io
.in
.durable_handle
= &h
;
877 status
= smb2_create(tree
, mem_ctx
, &io
);
878 CHECK_STATUS(status
, NT_STATUS_OK
);
879 CHECK_VAL(io
.out
.oplock_level
, SMB2_OPLOCK_LEVEL_BATCH
);
880 CHECK_VAL(io
.out
.reserved
, 0x00);
881 CHECK_VAL(io
.out
.create_action
, NTCREATEX_ACTION_EXISTED
);
882 CHECK_VAL(io
.out
.alloc_size
, 0);
883 CHECK_VAL(io
.out
.size
, 0);
884 CHECK_VAL(io
.out
.file_attr
, FILE_ATTRIBUTE_ARCHIVE
);
885 CHECK_VAL(io
.out
.reserved2
, 0);
887 h
= io
.out
.file
.handle
;
890 qfinfo
.generic
.level
= RAW_FILEINFO_POSITION_INFORMATION
;
891 qfinfo
.generic
.in
.file
.handle
= h
;
892 status
= smb2_getinfo_file(tree
, mem_ctx
, &qfinfo
);
893 CHECK_STATUS(status
, NT_STATUS_OK
);
894 CHECK_VAL(qfinfo
.position_information
.out
.position
, 0x1000);
895 pos
= qfinfo
.position_information
.out
.position
;
896 torture_comment(tctx
, "position: %llu\n",
897 (unsigned long long)pos
);
899 smb2_util_close(tree
, h
);
901 talloc_free(mem_ctx
);
903 smb2_util_unlink(tree
, fname
);
912 Open, disconnect, oplock break, reconnect.
914 bool test_durable_open_oplock(struct torture_context
*tctx
,
915 struct smb2_tree
*tree1
,
916 struct smb2_tree
*tree2
)
918 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
919 struct smb2_create io1
, io2
;
920 struct smb2_handle h1
, h2
;
925 /* Choose a random name in case the state is left a little funky. */
926 snprintf(fname
, 256, "durable_open_oplock_%s.dat", generate_random_str(tctx
, 8));
929 smb2_util_unlink(tree1
, fname
);
931 /* Create with batch oplock */
932 smb2_oplock_create(&io1
, fname
, SMB2_OPLOCK_LEVEL_BATCH
);
933 io1
.in
.durable_open
= true;
936 io2
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
938 status
= smb2_create(tree1
, mem_ctx
, &io1
);
939 CHECK_STATUS(status
, NT_STATUS_OK
);
940 h1
= io1
.out
.file
.handle
;
941 CHECK_CREATED(&io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
942 CHECK_VAL(io1
.out
.durable_open
, true);
943 CHECK_VAL(io1
.out
.oplock_level
, SMB2_OPLOCK_LEVEL_BATCH
);
945 /* Disconnect after getting the batch */
950 * Windows7 (build 7000) will break a batch oplock immediately if the
951 * original client is gone. (ZML: This seems like a bug. It should give
952 * some time for the client to reconnect!)
954 status
= smb2_create(tree2
, mem_ctx
, &io2
);
955 CHECK_STATUS(status
, NT_STATUS_OK
);
956 h2
= io2
.out
.file
.handle
;
957 CHECK_CREATED(&io2
, EXISTED
, FILE_ATTRIBUTE_ARCHIVE
);
958 CHECK_VAL(io2
.out
.durable_open
, true);
959 CHECK_VAL(io2
.out
.oplock_level
, SMB2_OPLOCK_LEVEL_BATCH
);
961 /* What if tree1 tries to come back and reclaim? */
962 if (!torture_smb2_connection(tctx
, &tree1
)) {
963 torture_warning(tctx
, "couldn't reconnect, bailing\n");
969 io1
.in
.fname
= fname
;
970 io1
.in
.durable_handle
= &h1
;
972 status
= smb2_create(tree1
, mem_ctx
, &io1
);
973 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
976 smb2_util_close(tree2
, h2
);
977 smb2_util_unlink(tree2
, fname
);
986 Open, disconnect, lease break, reconnect.
988 bool test_durable_open_lease(struct torture_context
*tctx
,
989 struct smb2_tree
*tree1
,
990 struct smb2_tree
*tree2
)
992 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
993 struct smb2_create io1
, io2
;
994 struct smb2_lease ls1
, ls2
;
995 struct smb2_handle h1
, h2
;
999 uint64_t lease1
, lease2
;
1002 caps
= smb2cli_conn_server_capabilities(tree1
->session
->transport
->conn
);
1003 if (!(caps
& SMB2_CAP_LEASING
)) {
1004 torture_skip(tctx
, "leases are not supported");
1008 * Choose a random name and random lease in case the state is left a
1013 snprintf(fname
, 256, "durable_open_lease_%s.dat", generate_random_str(tctx
, 8));
1016 smb2_util_unlink(tree1
, fname
);
1018 /* Create with lease */
1019 smb2_lease_create(&io1
, &ls1
, false /* dir */, fname
,
1020 lease1
, smb2_util_lease_state("RHW"));
1021 io1
.in
.durable_open
= true;
1023 smb2_lease_create(&io2
, &ls2
, false /* dir */, fname
,
1024 lease2
, smb2_util_lease_state("RHW"));
1025 io2
.in
.durable_open
= true;
1026 io2
.in
.create_disposition
= NTCREATEX_DISP_OPEN
;
1028 status
= smb2_create(tree1
, mem_ctx
, &io1
);
1029 CHECK_STATUS(status
, NT_STATUS_OK
);
1030 h1
= io1
.out
.file
.handle
;
1031 CHECK_VAL(io1
.out
.durable_open
, true);
1032 CHECK_CREATED(&io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
1034 CHECK_VAL(io1
.out
.oplock_level
, SMB2_OPLOCK_LEVEL_LEASE
);
1035 CHECK_VAL(io1
.out
.lease_response
.lease_key
.data
[0], lease1
);
1036 CHECK_VAL(io1
.out
.lease_response
.lease_key
.data
[1], ~lease1
);
1037 CHECK_VAL(io1
.out
.lease_response
.lease_state
,
1038 SMB2_LEASE_READ
|SMB2_LEASE_HANDLE
|SMB2_LEASE_WRITE
);
1040 /* Disconnect after getting the lease */
1045 * Windows7 (build 7000) will grant an RH lease immediate (not an RHW?)
1046 * even if the original client is gone. (ZML: This seems like a bug. It
1047 * should give some time for the client to reconnect! And why RH?)
1049 * obnox: Current windows 7 and w2k8r2 grant RHW instead of RH.
1050 * Test is adapted accordingly.
1052 status
= smb2_create(tree2
, mem_ctx
, &io2
);
1053 CHECK_STATUS(status
, NT_STATUS_OK
);
1054 h2
= io2
.out
.file
.handle
;
1055 CHECK_VAL(io2
.out
.durable_open
, true);
1056 CHECK_CREATED(&io2
, EXISTED
, FILE_ATTRIBUTE_ARCHIVE
);
1058 CHECK_VAL(io2
.out
.oplock_level
, SMB2_OPLOCK_LEVEL_LEASE
);
1059 CHECK_VAL(io2
.out
.lease_response
.lease_key
.data
[0], lease2
);
1060 CHECK_VAL(io2
.out
.lease_response
.lease_key
.data
[1], ~lease2
);
1061 CHECK_VAL(io2
.out
.lease_response
.lease_state
,
1062 SMB2_LEASE_READ
|SMB2_LEASE_HANDLE
|SMB2_LEASE_WRITE
);
1064 /* What if tree1 tries to come back and reclaim? */
1065 if (!torture_smb2_connection(tctx
, &tree1
)) {
1066 torture_warning(tctx
, "couldn't reconnect, bailing\n");
1072 io1
.in
.fname
= fname
;
1073 io1
.in
.durable_handle
= &h1
;
1074 io1
.in
.lease_request
= &ls1
;
1076 status
= smb2_create(tree1
, mem_ctx
, &io1
);
1077 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
1080 smb2_util_close(tree2
, h2
);
1081 smb2_util_unlink(tree2
, fname
);
1089 bool test_durable_open_lock_oplock(struct torture_context
*tctx
,
1090 struct smb2_tree
*tree
)
1092 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
1093 struct smb2_create io
;
1094 struct smb2_handle h
;
1095 struct smb2_lock lck
;
1096 struct smb2_lock_element el
[2];
1103 snprintf(fname
, 256, "durable_open_oplock_lock_%s.dat", generate_random_str(tctx
, 8));
1106 smb2_util_unlink(tree
, fname
);
1108 /* Create with lease */
1110 smb2_oplock_create_share(&io
, fname
,
1111 smb2_util_share_access(""),
1112 smb2_util_oplock_level("b"));
1113 io
.in
.durable_open
= true;
1115 status
= smb2_create(tree
, mem_ctx
, &io
);
1116 CHECK_STATUS(status
, NT_STATUS_OK
);
1117 h
= io
.out
.file
.handle
;
1118 CHECK_CREATED(&io
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
1120 CHECK_VAL(io
.out
.durable_open
, true);
1121 CHECK_VAL(io
.out
.oplock_level
, smb2_util_oplock_level("b"));
1126 lck
.in
.lock_count
= 0x0001;
1127 lck
.in
.lock_sequence
= 0x00000000;
1128 lck
.in
.file
.handle
= h
;
1131 el
[0].reserved
= 0x00000000;
1132 el
[0].flags
= SMB2_LOCK_FLAG_EXCLUSIVE
;
1133 status
= smb2_lock(tree
, &lck
);
1134 CHECK_STATUS(status
, NT_STATUS_OK
);
1136 /* Disconnect/Reconnect. */
1140 if (!torture_smb2_connection(tctx
, &tree
)) {
1141 torture_warning(tctx
, "couldn't reconnect, bailing\n");
1147 io
.in
.fname
= fname
;
1148 io
.in
.durable_handle
= &h
;
1150 status
= smb2_create(tree
, mem_ctx
, &io
);
1151 CHECK_STATUS(status
, NT_STATUS_OK
);
1152 h
= io
.out
.file
.handle
;
1154 lck
.in
.file
.handle
= h
;
1155 el
[0].flags
= SMB2_LOCK_FLAG_UNLOCK
;
1156 status
= smb2_lock(tree
, &lck
);
1157 CHECK_STATUS(status
, NT_STATUS_OK
);
1160 smb2_util_close(tree
, h
);
1161 smb2_util_unlink(tree
, fname
);
1168 Open, take BRL, disconnect, reconnect.
1170 bool test_durable_open_lock_lease(struct torture_context
*tctx
,
1171 struct smb2_tree
*tree
)
1173 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
1174 struct smb2_create io
;
1175 struct smb2_lease ls
;
1176 struct smb2_handle h
;
1177 struct smb2_lock lck
;
1178 struct smb2_lock_element el
[2];
1185 caps
= smb2cli_conn_server_capabilities(tree
->session
->transport
->conn
);
1186 if (!(caps
& SMB2_CAP_LEASING
)) {
1187 torture_skip(tctx
, "leases are not supported");
1191 * Choose a random name and random lease in case the state is left a
1195 snprintf(fname
, 256, "durable_open_lease_lock_%s.dat", generate_random_str(tctx
, 8));
1198 smb2_util_unlink(tree
, fname
);
1200 /* Create with lease */
1202 smb2_lease_create(&io
, &ls
, false /* dir */, fname
, lease
,
1203 smb2_util_lease_state("RWH"));
1204 io
.in
.durable_open
= true;
1206 status
= smb2_create(tree
, mem_ctx
, &io
);
1207 CHECK_STATUS(status
, NT_STATUS_OK
);
1208 h
= io
.out
.file
.handle
;
1209 CHECK_CREATED(&io
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
1211 CHECK_VAL(io
.out
.durable_open
, true);
1212 CHECK_VAL(io
.out
.oplock_level
, SMB2_OPLOCK_LEVEL_LEASE
);
1213 CHECK_VAL(io
.out
.lease_response
.lease_key
.data
[0], lease
);
1214 CHECK_VAL(io
.out
.lease_response
.lease_key
.data
[1], ~lease
);
1215 CHECK_VAL(io
.out
.lease_response
.lease_state
,
1216 SMB2_LEASE_READ
|SMB2_LEASE_HANDLE
|SMB2_LEASE_WRITE
);
1221 lck
.in
.lock_count
= 0x0001;
1222 lck
.in
.lock_sequence
= 0x00000000;
1223 lck
.in
.file
.handle
= h
;
1226 el
[0].reserved
= 0x00000000;
1227 el
[0].flags
= SMB2_LOCK_FLAG_EXCLUSIVE
;
1228 status
= smb2_lock(tree
, &lck
);
1229 CHECK_STATUS(status
, NT_STATUS_OK
);
1231 /* Disconnect/Reconnect. */
1235 if (!torture_smb2_connection(tctx
, &tree
)) {
1236 torture_warning(tctx
, "couldn't reconnect, bailing\n");
1242 io
.in
.fname
= fname
;
1243 io
.in
.durable_handle
= &h
;
1244 io
.in
.lease_request
= &ls
;
1246 status
= smb2_create(tree
, mem_ctx
, &io
);
1247 CHECK_STATUS(status
, NT_STATUS_OK
);
1248 h
= io
.out
.file
.handle
;
1250 lck
.in
.file
.handle
= h
;
1251 el
[0].flags
= SMB2_LOCK_FLAG_UNLOCK
;
1252 status
= smb2_lock(tree
, &lck
);
1253 CHECK_STATUS(status
, NT_STATUS_OK
);
1256 smb2_util_close(tree
, h
);
1257 smb2_util_unlink(tree
, fname
);
1264 * Open with a RH lease, disconnect, open in another tree, reconnect.
1266 * This test actually demonstrates a minimum level of respect for the durable
1267 * open in the face of another open. As long as this test shows an inability to
1268 * reconnect after an open, the oplock/lease tests above will certainly
1269 * demonstrate an error on reconnect.
1271 bool test_durable_open_open2_lease(struct torture_context
*tctx
,
1272 struct smb2_tree
*tree1
,
1273 struct smb2_tree
*tree2
)
1275 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
1276 struct smb2_create io1
, io2
;
1277 struct smb2_lease ls
;
1278 struct smb2_handle h1
, h2
;
1285 caps
= smb2cli_conn_server_capabilities(tree1
->session
->transport
->conn
);
1286 if (!(caps
& SMB2_CAP_LEASING
)) {
1287 torture_skip(tctx
, "leases are not supported");
1291 * Choose a random name and random lease in case the state is left a
1295 snprintf(fname
, 256, "durable_open_open2_lease_%s.dat",
1296 generate_random_str(tctx
, 8));
1299 smb2_util_unlink(tree1
, fname
);
1301 /* Create with lease */
1302 smb2_lease_create_share(&io1
, &ls
, false /* dir */, fname
,
1303 smb2_util_share_access(""),
1305 smb2_util_lease_state("RH"));
1306 io1
.in
.durable_open
= true;
1308 status
= smb2_create(tree1
, mem_ctx
, &io1
);
1309 CHECK_STATUS(status
, NT_STATUS_OK
);
1310 h1
= io1
.out
.file
.handle
;
1311 CHECK_VAL(io1
.out
.durable_open
, true);
1312 CHECK_CREATED(&io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
1314 CHECK_VAL(io1
.out
.oplock_level
, SMB2_OPLOCK_LEVEL_LEASE
);
1315 CHECK_VAL(io1
.out
.lease_response
.lease_key
.data
[0], lease
);
1316 CHECK_VAL(io1
.out
.lease_response
.lease_key
.data
[1], ~lease
);
1317 CHECK_VAL(io1
.out
.lease_response
.lease_state
,
1318 smb2_util_lease_state("RH"));
1324 /* Open the file in tree2 */
1325 smb2_oplock_create(&io2
, fname
, SMB2_OPLOCK_LEVEL_NONE
);
1327 status
= smb2_create(tree2
, mem_ctx
, &io2
);
1328 CHECK_STATUS(status
, NT_STATUS_OK
);
1329 h2
= io2
.out
.file
.handle
;
1330 CHECK_CREATED(&io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
1333 if (!torture_smb2_connection(tctx
, &tree1
)) {
1334 torture_warning(tctx
, "couldn't reconnect, bailing\n");
1340 io1
.in
.fname
= fname
;
1341 io1
.in
.durable_handle
= &h1
;
1342 io1
.in
.lease_request
= &ls
;
1345 * Windows7 (build 7000) will give away an open immediately if the
1346 * original client is gone. (ZML: This seems like a bug. It should give
1347 * some time for the client to reconnect!)
1349 status
= smb2_create(tree1
, mem_ctx
, &io1
);
1350 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
1351 h1
= io1
.out
.file
.handle
;
1354 smb2_util_close(tree2
, h2
);
1355 smb2_util_unlink(tree2
, fname
);
1356 smb2_util_close(tree1
, h1
);
1357 smb2_util_unlink(tree1
, fname
);
1366 * Open with a batch oplock, disconnect, open in another tree, reconnect.
1368 * This test actually demonstrates a minimum level of respect for the durable
1369 * open in the face of another open. As long as this test shows an inability to
1370 * reconnect after an open, the oplock/lease tests above will certainly
1371 * demonstrate an error on reconnect.
1373 bool test_durable_open_open2_oplock(struct torture_context
*tctx
,
1374 struct smb2_tree
*tree1
,
1375 struct smb2_tree
*tree2
)
1377 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
1378 struct smb2_create io1
, io2
;
1379 struct smb2_handle h1
, h2
;
1385 * Choose a random name and random lease in case the state is left a
1388 snprintf(fname
, 256, "durable_open_open2_oplock_%s.dat",
1389 generate_random_str(tctx
, 8));
1392 smb2_util_unlink(tree1
, fname
);
1394 /* Create with batch oplock */
1395 smb2_oplock_create(&io1
, fname
, SMB2_OPLOCK_LEVEL_BATCH
);
1396 io1
.in
.durable_open
= true;
1398 status
= smb2_create(tree1
, mem_ctx
, &io1
);
1399 CHECK_STATUS(status
, NT_STATUS_OK
);
1400 h1
= io1
.out
.file
.handle
;
1401 CHECK_CREATED(&io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
1402 CHECK_VAL(io1
.out
.durable_open
, true);
1403 CHECK_VAL(io1
.out
.oplock_level
, SMB2_OPLOCK_LEVEL_BATCH
);
1409 /* Open the file in tree2 */
1410 smb2_oplock_create(&io2
, fname
, SMB2_OPLOCK_LEVEL_NONE
);
1412 status
= smb2_create(tree2
, mem_ctx
, &io2
);
1413 CHECK_STATUS(status
, NT_STATUS_OK
);
1414 h2
= io2
.out
.file
.handle
;
1415 CHECK_CREATED(&io1
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
);
1418 if (!torture_smb2_connection(tctx
, &tree1
)) {
1419 torture_warning(tctx
, "couldn't reconnect, bailing\n");
1425 io1
.in
.fname
= fname
;
1426 io1
.in
.durable_handle
= &h1
;
1428 status
= smb2_create(tree1
, mem_ctx
, &io1
);
1429 CHECK_STATUS(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
1430 h1
= io1
.out
.file
.handle
;
1433 smb2_util_close(tree2
, h2
);
1434 smb2_util_unlink(tree2
, fname
);
1435 smb2_util_close(tree1
, h1
);
1436 smb2_util_unlink(tree1
, fname
);
1445 * test behaviour with initial allocation size
1447 bool test_durable_open_alloc_size(struct torture_context
*tctx
,
1448 struct smb2_tree
*tree
)
1451 TALLOC_CTX
*mem_ctx
= talloc_new(tctx
);
1453 struct smb2_handle _h
;
1454 struct smb2_handle
*h
= NULL
;
1455 struct smb2_create io
;
1457 uint64_t previous_session_id
;
1458 uint64_t alloc_size_step
;
1459 uint64_t initial_alloc_size
= 0x100;
1460 const uint8_t *b
= NULL
;
1462 /* Choose a random name in case the state is left a little funky. */
1463 snprintf(fname
, 256, "durable_open_alloc_size_%s.dat",
1464 generate_random_str(tctx
, 8));
1466 smb2_util_unlink(tree
, fname
);
1468 smb2_oplock_create_share(&io
, fname
,
1469 smb2_util_share_access(""),
1470 smb2_util_oplock_level("b"));
1471 io
.in
.durable_open
= true;
1472 io
.in
.alloc_size
= initial_alloc_size
;
1474 status
= smb2_create(tree
, mem_ctx
, &io
);
1475 CHECK_STATUS(status
, NT_STATUS_OK
);
1476 _h
= io
.out
.file
.handle
;
1478 CHECK_NOT_VAL(io
.out
.alloc_size
, 0);
1479 alloc_size_step
= io
.out
.alloc_size
;
1480 CHECK_CREATED_SIZE(&io
, CREATED
, FILE_ATTRIBUTE_ARCHIVE
,
1481 alloc_size_step
, 0);
1482 CHECK_VAL(io
.out
.durable_open
, true);
1483 CHECK_VAL(io
.out
.oplock_level
, smb2_util_oplock_level("b"));
1485 /* prepare buffer */
1486 b
= talloc_zero_size(mem_ctx
, alloc_size_step
);
1487 CHECK_NOT_VAL(b
, NULL
);
1489 previous_session_id
= smb2cli_session_current_id(tree
->session
->smbXcli
);
1491 /* disconnect, reconnect and then do durable reopen */
1495 if (!torture_smb2_connection_ext(tctx
, previous_session_id
, &tree
)) {
1496 torture_warning(tctx
, "couldn't reconnect, bailing\n");
1502 io
.in
.fname
= fname
;
1503 io
.in
.durable_handle
= h
;
1506 status
= smb2_create(tree
, mem_ctx
, &io
);
1507 CHECK_STATUS(status
, NT_STATUS_OK
);
1508 CHECK_CREATED_SIZE(&io
, EXISTED
, FILE_ATTRIBUTE_ARCHIVE
,
1509 alloc_size_step
, 0);
1510 CHECK_VAL(io
.out
.oplock_level
, smb2_util_oplock_level("b"));
1511 _h
= io
.out
.file
.handle
;
1514 previous_session_id
= smb2cli_session_current_id(tree
->session
->smbXcli
);
1516 /* write one byte */
1517 status
= smb2_util_write(tree
, *h
, b
, 0, 1);
1518 CHECK_STATUS(status
, NT_STATUS_OK
);
1520 /* disconnect, reconnect and then do durable reopen */
1524 if (!torture_smb2_connection_ext(tctx
, previous_session_id
, &tree
)) {
1525 torture_warning(tctx
, "couldn't reconnect, bailing\n");
1531 io
.in
.fname
= fname
;
1532 io
.in
.durable_handle
= h
;
1535 status
= smb2_create(tree
, mem_ctx
, &io
);
1536 CHECK_STATUS(status
, NT_STATUS_OK
);
1537 CHECK_CREATED_SIZE(&io
, EXISTED
, FILE_ATTRIBUTE_ARCHIVE
,
1538 alloc_size_step
, 1);
1539 CHECK_VAL(io
.out
.oplock_level
, smb2_util_oplock_level("b"));
1540 _h
= io
.out
.file
.handle
;
1543 previous_session_id
= smb2cli_session_current_id(tree
->session
->smbXcli
);
1545 /* write more byte than initial allocation size */
1546 status
= smb2_util_write(tree
, *h
, b
, 1, alloc_size_step
);
1548 /* disconnect, reconnect and then do durable reopen */
1552 if (!torture_smb2_connection_ext(tctx
, previous_session_id
, &tree
)) {
1553 torture_warning(tctx
, "couldn't reconnect, bailing\n");
1559 io
.in
.fname
= fname
;
1560 io
.in
.durable_handle
= h
;
1563 status
= smb2_create(tree
, mem_ctx
, &io
);
1564 CHECK_STATUS(status
, NT_STATUS_OK
);
1565 CHECK_CREATED_SIZE(&io
, EXISTED
, FILE_ATTRIBUTE_ARCHIVE
,
1566 alloc_size_step
* 2, alloc_size_step
+ 1);
1567 CHECK_VAL(io
.out
.oplock_level
, smb2_util_oplock_level("b"));
1568 _h
= io
.out
.file
.handle
;
1573 smb2_util_close(tree
, *h
);
1576 smb2_util_unlink(tree
, fname
);
1580 talloc_free(mem_ctx
);
1586 struct torture_suite
*torture_smb2_durable_open_init(void)
1588 struct torture_suite
*suite
=
1589 torture_suite_create(talloc_autofree_context(), "durable-open");
1591 torture_suite_add_1smb2_test(suite
, "open-oplock", test_durable_open_open_oplock
);
1592 torture_suite_add_1smb2_test(suite
, "open-lease", test_durable_open_open_lease
);
1593 torture_suite_add_1smb2_test(suite
, "reopen1", test_durable_open_reopen1
);
1594 torture_suite_add_1smb2_test(suite
, "reopen2", test_durable_open_reopen2
);
1595 torture_suite_add_1smb2_test(suite
, "reopen2a", test_durable_open_reopen2a
);
1596 torture_suite_add_1smb2_test(suite
, "reopen3", test_durable_open_reopen3
);
1597 torture_suite_add_1smb2_test(suite
, "reopen4", test_durable_open_reopen4
);
1598 torture_suite_add_1smb2_test(suite
, "delete_on_close1",
1599 test_durable_open_delete_on_close1
);
1600 torture_suite_add_1smb2_test(suite
, "file-position",
1601 test_durable_open_file_position
);
1602 torture_suite_add_2smb2_test(suite
, "oplock", test_durable_open_oplock
);
1603 torture_suite_add_2smb2_test(suite
, "lease", test_durable_open_lease
);
1604 torture_suite_add_1smb2_test(suite
, "lock-oplock", test_durable_open_lock_oplock
);
1605 torture_suite_add_1smb2_test(suite
, "lock-lease", test_durable_open_lock_lease
);
1606 torture_suite_add_2smb2_test(suite
, "open2-lease",
1607 test_durable_open_open2_lease
);
1608 torture_suite_add_2smb2_test(suite
, "open2-oplock",
1609 test_durable_open_open2_oplock
);
1610 torture_suite_add_1smb2_test(suite
, "alloc-size",
1611 test_durable_open_alloc_size
);
1613 suite
->description
= talloc_strdup(suite
, "SMB2-DURABLE-OPEN tests");