2 * Unix SMB/CIFS implementation.
4 * test SMB2 multichannel operations
6 * Copyright (C) Guenther Deschner, 2016
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "libcli/smb2/smb2.h"
24 #include "libcli/smb2/smb2_calls.h"
25 #include "torture/torture.h"
26 #include "torture/smb2/proto.h"
27 #include "libcli/security/security.h"
28 #include "librpc/gen_ndr/ndr_security.h"
29 #include "librpc/gen_ndr/ndr_ioctl.h"
30 #include "../libcli/smb/smbXcli_base.h"
31 #include "lib/cmdline/popt_common.h"
32 #include "libcli/security/security.h"
33 #include "libcli/resolve/resolve.h"
34 #include "lib/param/param.h"
35 #include "lib/events/events.h"
36 #include "oplock_break_handler.h"
37 #include "lease_break_handler.h"
38 #include "torture/smb2/block.h"
40 #define BASEDIR "multichanneltestdir"
42 #define CHECK_STATUS(status, correct) \
43 torture_assert_ntstatus_equal_goto(tctx, status, correct,\
46 #define CHECK_VAL(v, correct) do { \
47 if ((v) != (correct)) { \
48 torture_result(tctx, TORTURE_FAIL, "(%s): wrong value for %s" \
49 " got 0x%x - should be 0x%x\n", \
50 __location__, #v, (int)v, (int)correct); \
55 #define CHECK_VAL_GREATER_THAN(v, gt_val) do { \
56 if ((v) <= (gt_val)) { \
57 torture_result(tctx, TORTURE_FAIL, \
58 "(%s): wrong value for %s got 0x%x - " \
59 "should be greater than 0x%x\n", \
60 __location__, #v, (int)v, (int)gt_val); \
65 #define CHECK_CREATED(__io, __created, __attribute) \
67 CHECK_VAL((__io)->out.create_action, \
68 NTCREATEX_ACTION_ ## __created); \
69 CHECK_VAL((__io)->out.alloc_size, 0); \
70 CHECK_VAL((__io)->out.size, 0); \
71 CHECK_VAL((__io)->out.file_attr, (__attribute)); \
72 CHECK_VAL((__io)->out.reserved2, 0); \
75 #define CHECK_PTR(ptr, correct) do { \
76 if ((ptr) != (correct)) { \
77 torture_result(tctx, TORTURE_FAIL, "(%s): wrong value for %s " \
78 "got 0x%p - should be 0x%p\n", \
79 __location__, #ptr, ptr, correct); \
84 #define CHECK_LEASE(__io, __state, __oplevel, __key, __flags) \
86 CHECK_VAL((__io)->out.lease_response.lease_version, 1); \
88 CHECK_VAL((__io)->out.oplock_level, \
89 SMB2_OPLOCK_LEVEL_LEASE); \
90 CHECK_VAL((__io)->out.lease_response.lease_key.data[0],\
92 CHECK_VAL((__io)->out.lease_response.lease_key.data[1],\
94 CHECK_VAL((__io)->out.lease_response.lease_state,\
95 smb2_util_lease_state(__state)); \
97 CHECK_VAL((__io)->out.oplock_level,\
98 SMB2_OPLOCK_LEVEL_NONE); \
99 CHECK_VAL((__io)->out.lease_response.lease_key.data[0],\
101 CHECK_VAL((__io)->out.lease_response.lease_key.data[1],\
103 CHECK_VAL((__io)->out.lease_response.lease_state, 0); \
106 CHECK_VAL((__io)->out.lease_response.lease_flags, (__flags)); \
107 CHECK_VAL((__io)->out.lease_response.lease_duration, 0); \
108 CHECK_VAL((__io)->out.lease_response.lease_epoch, 0); \
111 static bool test_ioctl_network_interface_info(struct torture_context *tctx,
112 struct smb2_tree *tree,
113 struct fsctl_net_iface_info *info)
115 union smb_ioctl ioctl;
116 struct smb2_handle fh;
119 caps = smb2cli_conn_server_capabilities(tree->session->transport->conn);
120 if (!(caps & SMB2_CAP_MULTI_CHANNEL)) {
122 "server doesn't support SMB2_CAP_MULTI_CHANNEL\n");
127 ioctl.smb2.level = RAW_IOCTL_SMB2;
129 fh.data[0] = UINT64_MAX;
130 fh.data[1] = UINT64_MAX;
132 ioctl.smb2.in.file.handle = fh;
133 ioctl.smb2.in.function = FSCTL_QUERY_NETWORK_INTERFACE_INFO;
134 /* Windows client sets this to 64KiB */
135 ioctl.smb2.in.max_output_response = 0x10000;
136 ioctl.smb2.in.flags = SMB2_IOCTL_FLAG_IS_FSCTL;
138 torture_assert_ntstatus_ok(tctx,
139 smb2_ioctl(tree, tctx, &ioctl.smb2),
140 "FSCTL_QUERY_NETWORK_INTERFACE_INFO failed");
143 (ioctl.smb2.out.out.length != 0),
144 "no interface info returned???");
146 torture_assert_ndr_success(tctx,
147 ndr_pull_struct_blob(&ioctl.smb2.out.out, tctx, info,
148 (ndr_pull_flags_fn_t)ndr_pull_fsctl_net_iface_info),
149 "failed to ndr pull");
152 NDR_PRINT_DEBUG(fsctl_net_iface_info, info);
158 static bool test_multichannel_interface_info(struct torture_context *tctx,
159 struct smb2_tree *tree)
161 struct fsctl_net_iface_info info;
163 return test_ioctl_network_interface_info(tctx, tree, &info);
166 static struct smb2_tree *test_multichannel_create_channel(
167 struct torture_context *tctx,
170 struct cli_credentials *credentials,
171 struct smbcli_options *transport_options,
172 struct smb2_tree *parent_tree
176 struct smb2_transport *transport;
177 struct smb2_session *session;
179 struct smb2_tree *tree;
181 status = smb2_connect(tctx,
183 lpcfg_smb_ports(tctx->lp_ctx),
185 lpcfg_resolve_context(tctx->lp_ctx),
190 lpcfg_socket_options(tctx->lp_ctx),
191 lpcfg_gensec_settings(tctx, tctx->lp_ctx)
193 torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
194 "smb2_connect failed");
195 transport = tree->session->transport;
196 transport->oplock.handler = torture_oplock_ack_handler;
197 transport->oplock.private_data = tree;
198 transport->lease.handler = torture_lease_handler;
199 transport->lease.private_data = tree;
200 torture_comment(tctx, "established transport [%p]\n", transport);
203 * If parent tree is set, bind the session to the parent transport
206 session = smb2_session_channel(transport,
207 lpcfg_gensec_settings(tctx, tctx->lp_ctx),
208 parent_tree, parent_tree->session);
209 torture_assert_goto(tctx, session != NULL, ret, done,
210 "smb2_session_channel failed");
212 tree->smbXcli = parent_tree->smbXcli;
213 tree->session = session;
214 status = smb2_session_setup_spnego(session,
216 0 /* previous_session_id */);
217 CHECK_STATUS(status, NT_STATUS_OK);
218 torture_comment(tctx, "bound new session to parent\n");
221 * We absolutely need to make sure to send something over this
222 * connection to register the oplock break handler with the smb client
223 * connection. If we do not send something (at least a keepalive), we
224 * will *NEVER* receive anything over this transport.
226 smb2_keepalive(transport);
236 bool test_multichannel_create_channels(
237 struct torture_context *tctx,
240 struct cli_credentials *credentials,
241 struct smbcli_options *transport_options,
242 struct smb2_tree **tree2A,
243 struct smb2_tree **tree2B,
244 struct smb2_tree **tree2C
247 struct smb2_tree *tree;
248 struct smb2_transport *transport2A;
249 struct smb2_transport *transport2B;
250 struct smb2_transport *transport2C;
251 uint16_t local_port = 0;
253 transport_options->client_guid = GUID_random();
256 torture_comment(tctx, "Setting up connection 2A\n");
257 tree = test_multichannel_create_channel(tctx, host, share,
258 credentials, transport_options, NULL);
263 transport2A = tree->session->transport;
264 local_port = torture_get_local_port_from_transport(transport2A);
265 torture_comment(tctx, "transport2A uses tcp port: %d\n", local_port);
269 torture_comment(tctx, "Setting up connection 2B\n");
270 tree = test_multichannel_create_channel(tctx, host, share,
271 credentials, transport_options, *tree2A);
276 transport2B = tree->session->transport;
277 local_port = torture_get_local_port_from_transport(transport2B);
278 torture_comment(tctx, "transport2B uses tcp port: %d\n",
284 torture_comment(tctx, "Setting up connection 2C\n");
285 tree = test_multichannel_create_channel(tctx, host, share,
286 credentials, transport_options, *tree2A);
291 transport2C = tree->session->transport;
292 local_port = torture_get_local_port_from_transport(transport2C);
293 torture_comment(tctx, "transport2C uses tcp port: %d\n",
302 static void test_multichannel_free_channels(struct smb2_tree *tree2A,
303 struct smb2_tree *tree2B,
304 struct smb2_tree *tree2C)
311 static bool test_multichannel_initial_checks(struct torture_context *tctx,
312 struct smb2_tree *tree1)
314 struct smb2_transport *transport1 = tree1->session->transport;
315 uint32_t server_capabilities;
316 struct fsctl_net_iface_info info;
318 if (smbXcli_conn_protocol(transport1->conn) < PROTOCOL_SMB3_00) {
319 torture_skip_goto(tctx, fail,
320 "SMB 3.X Dialect family required for "
321 "Multichannel tests\n");
324 server_capabilities = smb2cli_conn_server_capabilities(
325 tree1->session->transport->conn);
326 if (!(server_capabilities & SMB2_CAP_MULTI_CHANNEL)) {
327 torture_skip_goto(tctx, fail,
328 "Server does not support multichannel.");
332 test_ioctl_network_interface_info(tctx, tree1, &info),
333 "failed to retrieve network interface info");
340 static void test_multichannel_init_smb_create(struct smb2_create *io)
342 io->in.durable_open = false;
343 io->in.durable_open_v2 = true;
344 io->in.persistent_open = false;
345 io->in.create_guid = GUID_random();
346 io->in.timeout = 0x493E0; /* 300000 */
347 /* windows 2016 returns 300000 0x493E0 */
351 * We simulate blocking incoming oplock break requests by simply ignoring
352 * the incoming break requests.
354 static bool test_set_ignore_break_handler(struct torture_context *tctx,
355 struct smb2_transport *transport)
357 transport->oplock.handler = torture_oplock_ignore_handler;
358 transport->lease.handler = torture_lease_ignore_handler;
363 static bool test_reset_break_handler(struct torture_context *tctx,
364 struct smb2_transport *transport)
366 transport->oplock.handler = torture_oplock_ack_handler;
367 transport->lease.handler = torture_lease_handler;
373 * Use iptables to block channels
375 static bool test_iptables_block_channel(struct torture_context *tctx,
376 struct smb2_transport *transport,
382 local_port = torture_get_local_port_from_transport(transport);
383 torture_comment(tctx, "transport uses tcp port: %d\n", local_port);
384 ret = torture_block_tcp_transport_name(tctx, transport, name);
385 torture_assert(tctx, ret, "we could not block tcp transport");
390 static bool test_iptables_unblock_channel(struct torture_context *tctx,
391 struct smb2_transport *transport,
397 local_port = torture_get_local_port_from_transport(transport);
398 torture_comment(tctx, "transport uses tcp port: %d\n", local_port);
399 ret = torture_unblock_tcp_transport_name(tctx, transport, name);
400 torture_assert(tctx, ret, "we could not block tcp transport");
405 #define test_block_channel(_tctx, _t) _test_block_channel(_tctx, _t, #_t)
406 static bool _test_block_channel(struct torture_context *tctx,
407 struct smb2_transport *transport,
410 bool use_iptables = torture_setting_bool(tctx,
411 "use_iptables", false);
414 return test_iptables_block_channel(tctx, transport, name);
416 return test_set_ignore_break_handler(tctx, transport);
420 #define test_unblock_channel(_tctx, _t) _test_unblock_channel(_tctx, _t, #_t)
421 static bool _test_unblock_channel(struct torture_context *tctx,
422 struct smb2_transport *transport,
425 bool use_iptables = torture_setting_bool(tctx,
426 "use_iptables", false);
429 return test_iptables_unblock_channel(tctx, transport, name);
431 return test_reset_break_handler(tctx, transport);
435 static void test_cleanup_blocked_channels(struct torture_context *tctx)
437 bool use_iptables = torture_setting_bool(tctx,
438 "use_iptables", false);
441 torture_unblock_cleanup(tctx);
445 /* Timer handler function notifies the registering function that time is up */
446 static void timeout_cb(struct tevent_context *ev,
447 struct tevent_timer *te,
448 struct timeval current_time,
451 bool *timesup = (bool *)private_data;
456 * Oplock break - Test 1
457 * Test to confirm that server sends oplock breaks as expected.
458 * open file1 in session 2A
459 * open file2 in session 2B
460 * open file1 in session 1
461 * oplock break received
462 * open file1 in session 1
463 * oplock break received
466 static bool test_multichannel_oplock_break_test1(struct torture_context *tctx,
467 struct smb2_tree *tree1)
469 const char *host = torture_setting_string(tctx, "host", NULL);
470 const char *share = torture_setting_string(tctx, "share", NULL);
471 struct cli_credentials *credentials = popt_get_cmdline_credentials();
473 TALLOC_CTX *mem_ctx = talloc_new(tctx);
474 struct smb2_handle _h;
475 struct smb2_handle h_client1_file1 = {{0}};
476 struct smb2_handle h_client1_file2 = {{0}};
477 struct smb2_handle h_client1_file3 = {{0}};
478 struct smb2_handle h_client2_file1 = {{0}};
479 struct smb2_handle h_client2_file2 = {{0}};
480 struct smb2_handle h_client2_file3 = {{0}};
481 struct smb2_create io1, io2, io3;
483 const char *fname1 = BASEDIR "\\oplock_break_test1.dat";
484 const char *fname2 = BASEDIR "\\oplock_break_test2.dat";
485 const char *fname3 = BASEDIR "\\oplock_break_test3.dat";
486 struct smb2_tree *tree2A = NULL;
487 struct smb2_tree *tree2B = NULL;
488 struct smb2_tree *tree2C = NULL;
489 struct smb2_transport *transport1 = tree1->session->transport;
490 struct smbcli_options transport2_options;
491 struct smb2_session *session1 = tree1->session;
492 uint16_t local_port = 0;
494 if (!test_multichannel_initial_checks(tctx, tree1)) {
498 torture_comment(tctx, "Oplock break retry: Test1\n");
500 torture_reset_break_info(tctx, &break_info);
502 transport1->oplock.handler = torture_oplock_ack_handler;
503 transport1->oplock.private_data = tree1;
504 torture_comment(tctx, "transport1 [%p]\n", transport1);
505 local_port = torture_get_local_port_from_transport(transport1);
506 torture_comment(tctx, "transport1 uses tcp port: %d\n", local_port);
508 status = torture_smb2_testdir(tree1, BASEDIR, &_h);
509 CHECK_STATUS(status, NT_STATUS_OK);
510 smb2_util_close(tree1, _h);
511 smb2_util_unlink(tree1, fname1);
512 smb2_util_unlink(tree1, fname2);
513 smb2_util_unlink(tree1, fname3);
514 CHECK_VAL(break_info.count, 0);
516 smb2_oplock_create_share(&io1, fname1,
517 smb2_util_share_access("RWD"),
518 smb2_util_oplock_level("b"));
519 test_multichannel_init_smb_create(&io1);
521 smb2_oplock_create_share(&io2, fname2,
522 smb2_util_share_access("RWD"),
523 smb2_util_oplock_level("b"));
524 test_multichannel_init_smb_create(&io2);
526 smb2_oplock_create_share(&io3, fname3,
527 smb2_util_share_access("RWD"),
528 smb2_util_oplock_level("b"));
529 test_multichannel_init_smb_create(&io3);
531 transport2_options = transport1->options;
533 ret = test_multichannel_create_channels(tctx, host, share,
536 &tree2A, &tree2B, NULL);
537 torture_assert(tctx, ret, "Could not create channels.\n");
540 torture_comment(tctx, "client2 opens fname1 via session 2A\n");
541 status = smb2_create(tree2A, mem_ctx, &io1);
542 CHECK_STATUS(status, NT_STATUS_OK);
543 h_client2_file1 = io1.out.file.handle;
544 CHECK_CREATED(&io1, CREATED, FILE_ATTRIBUTE_ARCHIVE);
545 CHECK_VAL(io1.out.oplock_level, smb2_util_oplock_level("b"));
546 torture_wait_for_oplock_break(tctx);
547 CHECK_VAL(break_info.count, 0);
550 torture_comment(tctx, "client2 opens fname2 via session 2B\n");
551 status = smb2_create(tree2B, mem_ctx, &io2);
552 CHECK_STATUS(status, NT_STATUS_OK);
553 h_client2_file2 = io2.out.file.handle;
554 CHECK_CREATED(&io2, CREATED, FILE_ATTRIBUTE_ARCHIVE);
555 CHECK_VAL(io2.out.oplock_level, smb2_util_oplock_level("b"));
556 torture_wait_for_oplock_break(tctx);
557 CHECK_VAL(break_info.count, 0);
560 /* 1 opens file1 - batchoplock break? */
561 torture_comment(tctx, "client1 opens fname1 via session 1\n");
562 io1.in.oplock_level = smb2_util_oplock_level("b");
563 status = smb2_create(tree1, mem_ctx, &io1);
564 CHECK_STATUS(status, NT_STATUS_OK);
565 h_client1_file1 = io1.out.file.handle;
566 CHECK_CREATED(&io1, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
567 CHECK_VAL(io1.out.oplock_level, smb2_util_oplock_level("s"));
568 torture_wait_for_oplock_break(tctx);
569 CHECK_VAL(break_info.count, 1);
571 torture_reset_break_info(tctx, &break_info);
573 /* 1 opens file2 - batchoplock break? */
574 torture_comment(tctx, "client1 opens fname2 via session 1\n");
575 io2.in.oplock_level = smb2_util_oplock_level("b");
576 status = smb2_create(tree1, mem_ctx, &io2);
577 CHECK_STATUS(status, NT_STATUS_OK);
578 h_client1_file2 = io2.out.file.handle;
579 CHECK_CREATED(&io2, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
580 CHECK_VAL(io2.out.oplock_level, smb2_util_oplock_level("s"));
581 torture_wait_for_oplock_break(tctx);
582 CHECK_VAL(break_info.count, 1);
584 /* cleanup everything */
585 torture_reset_break_info(tctx, &break_info);
587 smb2_util_close(tree1, h_client1_file1);
588 smb2_util_close(tree1, h_client1_file2);
589 smb2_util_close(tree1, h_client1_file3);
590 smb2_util_close(tree2A, h_client2_file1);
591 smb2_util_close(tree2A, h_client2_file2);
592 smb2_util_close(tree2A, h_client2_file3);
594 smb2_util_unlink(tree1, fname1);
595 smb2_util_unlink(tree1, fname2);
596 smb2_util_unlink(tree1, fname3);
597 CHECK_VAL(break_info.count, 0);
598 test_multichannel_free_channels(tree2A, tree2B, tree2C);
599 tree2A = tree2B = tree2C = NULL;
601 tree1->session = session1;
603 smb2_util_close(tree1, h_client1_file1);
604 smb2_util_close(tree1, h_client1_file2);
605 smb2_util_close(tree1, h_client1_file3);
606 if (tree2A != NULL) {
607 smb2_util_close(tree2A, h_client2_file1);
608 smb2_util_close(tree2A, h_client2_file2);
609 smb2_util_close(tree2A, h_client2_file3);
612 smb2_util_unlink(tree1, fname1);
613 smb2_util_unlink(tree1, fname2);
614 smb2_util_unlink(tree1, fname3);
615 smb2_deltree(tree1, BASEDIR);
617 test_multichannel_free_channels(tree2A, tree2B, tree2C);
619 talloc_free(mem_ctx);
625 * Oplock Break Test 2
626 * Test to see if oplock break retries are sent by the server.
627 * Also checks to see if new channels can be created and used
628 * after an oplock break retry.
631 * open file1 in session 1
632 * oplock break received
633 * block channel on which oplock break received
634 * open file2 in session 1
635 * oplock break not received. Retry received.
637 * write to file2 on 2B
638 * Break sent to session 1(which has file2 open)
639 * Break sent to session 2A(which has read oplock)
640 * close file1 in session 1
641 * open file1 with session 1
642 * unblock blocked channel
643 * disconnect blocked channel
646 * open file3 in session 1
649 static bool test_multichannel_oplock_break_test2(struct torture_context *tctx,
650 struct smb2_tree *tree1)
652 const char *host = torture_setting_string(tctx, "host", NULL);
653 const char *share = torture_setting_string(tctx, "share", NULL);
654 struct cli_credentials *credentials = popt_get_cmdline_credentials();
656 TALLOC_CTX *mem_ctx = talloc_new(tctx);
657 struct smb2_handle _h;
658 struct smb2_handle h_client1_file1 = {{0}};
659 struct smb2_handle h_client1_file2 = {{0}};
660 struct smb2_handle h_client1_file3 = {{0}};
661 struct smb2_handle h_client2_file1 = {{0}};
662 struct smb2_handle h_client2_file2 = {{0}};
663 struct smb2_handle h_client2_file3 = {{0}};
664 struct smb2_create io1, io2, io3;
666 const char *fname1 = BASEDIR "\\oplock_break_test1.dat";
667 const char *fname2 = BASEDIR "\\oplock_break_test2.dat";
668 const char *fname3 = BASEDIR "\\oplock_break_test3.dat";
669 struct smb2_tree *tree2A = NULL;
670 struct smb2_tree *tree2B = NULL;
671 struct smb2_tree *tree2C = NULL;
672 struct smb2_tree *tree2D = NULL;
673 struct smb2_transport *transport1 = tree1->session->transport;
674 struct smb2_transport *transport2 = NULL;
675 struct smbcli_options transport2_options;
676 struct smb2_session *session1 = tree1->session;
677 uint16_t local_port = 0;
679 bool block_ok = false;
680 bool unblock_ok = false;
682 if (!test_multichannel_initial_checks(tctx, tree1)) {
686 torture_comment(tctx, "Oplock break retry: Test2\n");
688 torture_reset_break_info(tctx, &break_info);
690 transport1->oplock.handler = torture_oplock_ack_handler;
691 transport1->oplock.private_data = tree1;
692 torture_comment(tctx, "transport1 [%p]\n", transport1);
693 local_port = torture_get_local_port_from_transport(transport1);
694 torture_comment(tctx, "transport1 uses tcp port: %d\n", local_port);
696 status = torture_smb2_testdir(tree1, BASEDIR, &_h);
697 CHECK_STATUS(status, NT_STATUS_OK);
698 smb2_util_close(tree1, _h);
699 smb2_util_unlink(tree1, fname1);
700 smb2_util_unlink(tree1, fname2);
701 smb2_util_unlink(tree1, fname3);
702 CHECK_VAL(break_info.count, 0);
704 smb2_oplock_create_share(&io1, fname1,
705 smb2_util_share_access("RWD"),
706 smb2_util_oplock_level("b"));
707 test_multichannel_init_smb_create(&io1);
709 smb2_oplock_create_share(&io2, fname2,
710 smb2_util_share_access("RWD"),
711 smb2_util_oplock_level("b"));
712 test_multichannel_init_smb_create(&io2);
714 smb2_oplock_create_share(&io3, fname3,
715 smb2_util_share_access("RWD"),
716 smb2_util_oplock_level("b"));
717 test_multichannel_init_smb_create(&io3);
719 transport2_options = transport1->options;
721 ret = test_multichannel_create_channels(tctx, host, share,
724 &tree2A, &tree2B, &tree2C);
725 torture_assert(tctx, ret, "Could not create channels.\n")
727 torture_comment(tctx, "client2 opens fname1 via session 2A\n");
728 io1.in.oplock_level = smb2_util_oplock_level("b");
729 status = smb2_create(tree2A, mem_ctx, &io1);
730 CHECK_STATUS(status, NT_STATUS_OK);
731 h_client2_file1 = io1.out.file.handle;
732 CHECK_CREATED(&io1, CREATED, FILE_ATTRIBUTE_ARCHIVE);
733 CHECK_VAL(io1.out.oplock_level, smb2_util_oplock_level("b"));
734 torture_wait_for_oplock_break(tctx);
735 CHECK_VAL(break_info.count, 0);
738 torture_comment(tctx, "client2 opens fname2 via session 2B\n");
739 io2.in.oplock_level = smb2_util_oplock_level("b");
740 status = smb2_create(tree2B, mem_ctx, &io2);
741 CHECK_STATUS(status, NT_STATUS_OK);
742 h_client2_file2 = io2.out.file.handle;
743 CHECK_CREATED(&io2, CREATED, FILE_ATTRIBUTE_ARCHIVE);
744 CHECK_VAL(io2.out.oplock_level, smb2_util_oplock_level("b"));
745 torture_wait_for_oplock_break(tctx);
746 CHECK_VAL(break_info.count, 0);
749 torture_comment(tctx, "client1 opens fname1 via session 1\n");
750 io1.in.oplock_level = smb2_util_oplock_level("b");
751 status = smb2_create(tree1, mem_ctx, &io1);
752 CHECK_STATUS(status, NT_STATUS_OK);
753 h_client1_file1 = io1.out.file.handle;
754 CHECK_CREATED(&io1, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
755 CHECK_VAL(io1.out.oplock_level, smb2_util_oplock_level("s"));
756 torture_wait_for_oplock_break(tctx);
757 CHECK_VAL(break_info.count, 1);
759 /* We use the transport over which this oplock break was received */
760 transport2 = break_info.received_transport;
761 torture_reset_break_info(tctx, &break_info);
764 block_ok = test_block_channel(tctx, transport2);
766 torture_comment(tctx, "client1 opens fname2 via session 1\n");
767 io2.in.oplock_level = smb2_util_oplock_level("b");
768 status = smb2_create(tree1, mem_ctx, &io2);
769 CHECK_STATUS(status, NT_STATUS_OK);
770 h_client1_file2 = io2.out.file.handle;
771 CHECK_CREATED(&io2, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
772 CHECK_VAL(io2.out.oplock_level, smb2_util_oplock_level("s"));
775 * Samba downgrades oplock to a level 2 oplock.
776 * Windows 2016 revokes oplock
778 torture_wait_for_oplock_break(tctx);
779 CHECK_VAL(break_info.count, 1);
780 torture_reset_break_info(tctx, &break_info);
782 torture_comment(tctx, "Trying write to file2 on tree2B\n");
784 blob = data_blob_string_const("Here I am");
785 status = smb2_util_write(tree2B,
790 torture_assert_ntstatus_ok(tctx, status,
791 "failed to write file2 via channel 2B");
794 * Samba: Write triggers 2 oplock breaks
795 * for session 1 which has file2 open
796 * for session 2 which has type 2 oplock
797 * Windows 2016: Only one oplock break for session 1
799 torture_wait_for_oplock_break(tctx);
800 CHECK_VAL_GREATER_THAN(break_info.count, 0);
801 torture_reset_break_info(tctx, &break_info);
803 torture_comment(tctx, "client1 closes fname2 via session 1\n");
804 smb2_util_close(tree1, h_client1_file2);
806 torture_comment(tctx, "client1 opens fname2 via session 1 again\n");
807 io2.in.oplock_level = smb2_util_oplock_level("b");
808 status = smb2_create(tree1, mem_ctx, &io2);
809 CHECK_STATUS(status, NT_STATUS_OK);
810 h_client1_file2 = io2.out.file.handle;
811 io2.out.alloc_size = 0;
813 CHECK_CREATED(&io2, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
814 CHECK_VAL(io2.out.oplock_level, smb2_util_oplock_level("s"));
817 * now add a fourth channel and repeat the test, we need to reestablish
818 * transport2 because the remote end has invalidated our connection
820 torture_comment(tctx, "Connecting session 2D\n");
821 tree2D = test_multichannel_create_channel(tctx, host, share,
822 credentials, &transport2_options, tree2B);
827 torture_reset_break_info(tctx, &break_info);
828 torture_comment(tctx, "client 2 opening fname3 over transport2D\n");
829 status = smb2_create(tree2D, mem_ctx, &io3);
830 CHECK_STATUS(status, NT_STATUS_OK);
831 h_client2_file3 = io3.out.file.handle;
832 CHECK_CREATED(&io3, CREATED, FILE_ATTRIBUTE_ARCHIVE);
833 CHECK_VAL(io3.out.oplock_level, smb2_util_oplock_level("b"));
834 torture_wait_for_oplock_break(tctx);
835 CHECK_VAL(break_info.count, 0);
837 torture_comment(tctx, "client1 opens fname3 via session 1\n");
838 status = smb2_create(tree1, mem_ctx, &io3);
839 CHECK_STATUS(status, NT_STATUS_OK);
840 h_client1_file3 = io3.out.file.handle;
841 CHECK_CREATED(&io3, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
842 CHECK_VAL(io3.out.oplock_level, smb2_util_oplock_level("s"));
843 torture_wait_for_oplock_break(tctx);
844 CHECK_VAL(break_info.count, 1);
847 if (block_ok && !unblock_ok) {
848 test_unblock_channel(tctx, transport2);
850 test_cleanup_blocked_channels(tctx);
852 tree1->session = session1;
854 smb2_util_close(tree1, h_client1_file1);
855 smb2_util_close(tree1, h_client1_file2);
856 smb2_util_close(tree1, h_client1_file3);
857 if (tree2B != NULL) {
858 smb2_util_close(tree2B, h_client2_file1);
859 smb2_util_close(tree2B, h_client2_file2);
860 smb2_util_close(tree2B, h_client2_file3);
863 smb2_util_unlink(tree1, fname1);
864 smb2_util_unlink(tree1, fname2);
865 smb2_util_unlink(tree1, fname3);
866 smb2_deltree(tree1, BASEDIR);
868 test_multichannel_free_channels(tree2A, tree2B, tree2C);
869 if (tree2D != NULL) {
873 talloc_free(mem_ctx);
878 static const uint64_t LEASE1F1 = 0xBADC0FFEE0DDF00Dull;
879 static const uint64_t LEASE1F2 = 0xBADC0FFEE0DDD00Dull;
880 static const uint64_t LEASE1F3 = 0xDADC0FFEE0DDD00Dull;
881 static const uint64_t LEASE2F1 = 0xDEADBEEFFEEDBEADull;
882 static const uint64_t LEASE2F2 = 0xDAD0FFEDD00DF00Dull;
883 static const uint64_t LEASE2F3 = 0xBAD0FFEDD00DF00Dull;
886 * Lease Break Test 1:
887 * Test to check if lease breaks are sent by the server as expected.
888 * open file1 in session 2A
889 * open file2 in session 2B
890 * open file3 in session 2C
891 * open file1 in session 1
893 * open file2 in session 1
895 * open file3 in session 1
898 static bool test_multichannel_lease_break_test1(struct torture_context *tctx,
899 struct smb2_tree *tree1)
901 const char *host = torture_setting_string(tctx, "host", NULL);
902 const char *share = torture_setting_string(tctx, "share", NULL);
903 struct cli_credentials *credentials = popt_get_cmdline_credentials();
905 TALLOC_CTX *mem_ctx = talloc_new(tctx);
906 struct smb2_handle _h;
907 struct smb2_handle *h = NULL;
908 struct smb2_handle h_client1_file1 = {{0}};
909 struct smb2_handle h_client1_file2 = {{0}};
910 struct smb2_handle h_client1_file3 = {{0}};
911 struct smb2_handle h_client2_file1 = {{0}};
912 struct smb2_handle h_client2_file2 = {{0}};
913 struct smb2_handle h_client2_file3 = {{0}};
914 struct smb2_create io1, io2, io3;
916 const char *fname1 = BASEDIR "\\lease_break_test1.dat";
917 const char *fname2 = BASEDIR "\\lease_break_test2.dat";
918 const char *fname3 = BASEDIR "\\lease_break_test3.dat";
919 struct smb2_tree *tree2A = NULL;
920 struct smb2_tree *tree2B = NULL;
921 struct smb2_tree *tree2C = NULL;
922 struct smb2_transport *transport1 = tree1->session->transport;
923 struct smbcli_options transport2_options;
924 struct smb2_session *session1 = tree1->session;
925 uint16_t local_port = 0;
926 struct smb2_lease ls1;
927 struct smb2_lease ls2;
928 struct smb2_lease ls3;
930 if (!test_multichannel_initial_checks(tctx, tree1)) {
934 torture_comment(tctx, "Lease break retry: Test1\n");
936 torture_reset_lease_break_info(tctx, &lease_break_info);
938 transport1->lease.handler = torture_lease_handler;
939 transport1->lease.private_data = tree1;
940 torture_comment(tctx, "transport1 [%p]\n", transport1);
941 local_port = torture_get_local_port_from_transport(transport1);
942 torture_comment(tctx, "transport1 uses tcp port: %d\n", local_port);
944 status = torture_smb2_testdir(tree1, BASEDIR, &_h);
945 CHECK_STATUS(status, NT_STATUS_OK);
946 smb2_util_close(tree1, _h);
947 smb2_util_unlink(tree1, fname1);
948 smb2_util_unlink(tree1, fname2);
949 smb2_util_unlink(tree1, fname3);
950 CHECK_VAL(lease_break_info.count, 0);
952 smb2_lease_create(&io1, &ls1, false, fname1, LEASE2F1,
953 smb2_util_lease_state("RHW"));
954 test_multichannel_init_smb_create(&io1);
956 smb2_lease_create(&io2, &ls2, false, fname2, LEASE2F2,
957 smb2_util_lease_state("RHW"));
958 test_multichannel_init_smb_create(&io2);
960 smb2_lease_create(&io3, &ls3, false, fname3, LEASE2F3,
961 smb2_util_lease_state("RHW"));
962 test_multichannel_init_smb_create(&io3);
964 transport2_options = transport1->options;
966 ret = test_multichannel_create_channels(tctx, host, share,
969 &tree2A, &tree2B, &tree2C);
970 torture_assert(tctx, ret, "Could not create channels.\n");
973 torture_comment(tctx, "client2 opens fname1 via session 2A\n");
974 status = smb2_create(tree2A, mem_ctx, &io1);
975 CHECK_STATUS(status, NT_STATUS_OK);
976 h_client2_file1 = io1.out.file.handle;
977 CHECK_CREATED(&io1, CREATED, FILE_ATTRIBUTE_ARCHIVE);
978 CHECK_LEASE(&io1, "RHW", true, LEASE2F1, 0);
979 CHECK_VAL(lease_break_info.count, 0);
982 torture_comment(tctx, "client2 opens fname2 via session 2B\n");
983 status = smb2_create(tree2B, mem_ctx, &io2);
984 CHECK_STATUS(status, NT_STATUS_OK);
985 h_client2_file2 = io2.out.file.handle;
986 CHECK_CREATED(&io2, CREATED, FILE_ATTRIBUTE_ARCHIVE);
987 CHECK_LEASE(&io2, "RHW", true, LEASE2F2, 0);
988 CHECK_VAL(lease_break_info.count, 0);
991 torture_comment(tctx, "client2 opens fname3 via session 2C\n");
992 smb2_lease_create(&io3, &ls3, false, fname3, LEASE2F3,
993 smb2_util_lease_state("RHW"));
994 status = smb2_create(tree2C, mem_ctx, &io3);
995 CHECK_STATUS(status, NT_STATUS_OK);
996 h_client2_file3 = io3.out.file.handle;
997 CHECK_CREATED(&io3, CREATED, FILE_ATTRIBUTE_ARCHIVE);
998 CHECK_LEASE(&io3, "RHW", true, LEASE2F3, 0);
999 CHECK_VAL(lease_break_info.count, 0);
1001 /* 1 opens file1 - lease break? */
1002 torture_comment(tctx, "client1 opens fname1 via session 1\n");
1003 smb2_lease_create(&io1, &ls1, false, fname1, LEASE1F1,
1004 smb2_util_lease_state("RHW"));
1005 status = smb2_create(tree1, mem_ctx, &io1);
1006 CHECK_STATUS(status, NT_STATUS_OK);
1007 h_client1_file1 = io1.out.file.handle;
1008 CHECK_CREATED(&io1, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
1009 CHECK_LEASE(&io1, "RH", true, LEASE1F1, 0);
1010 CHECK_BREAK_INFO("RHW", "RH", LEASE2F1);
1011 CHECK_VAL(lease_break_info.count, 1);
1013 torture_reset_lease_break_info(tctx, &lease_break_info);
1015 /* 1 opens file2 - lease break? */
1016 torture_comment(tctx, "client1 opens fname2 via session 1\n");
1017 smb2_lease_create(&io2, &ls2, false, fname2, LEASE1F2,
1018 smb2_util_lease_state("RHW"));
1019 status = smb2_create(tree1, mem_ctx, &io2);
1020 CHECK_STATUS(status, NT_STATUS_OK);
1021 h_client1_file2 = io2.out.file.handle;
1022 CHECK_CREATED(&io2, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
1023 CHECK_LEASE(&io2, "RH", true, LEASE1F2, 0);
1024 CHECK_BREAK_INFO("RHW", "RH", LEASE2F2);
1025 CHECK_VAL(lease_break_info.count, 1);
1027 torture_reset_lease_break_info(tctx, &lease_break_info);
1029 /* 1 opens file3 - lease break? */
1030 torture_comment(tctx, "client1 opens fname3 via session 1\n");
1031 smb2_lease_create(&io3, &ls3, false, fname3, LEASE1F3,
1032 smb2_util_lease_state("RHW"));
1033 status = smb2_create(tree1, mem_ctx, &io3);
1034 CHECK_STATUS(status, NT_STATUS_OK);
1035 h_client1_file3 = io3.out.file.handle;
1036 CHECK_CREATED(&io3, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
1037 CHECK_LEASE(&io3, "RH", true, LEASE1F3, 0);
1038 CHECK_BREAK_INFO("RHW", "RH", LEASE2F3);
1039 CHECK_VAL(lease_break_info.count, 1);
1041 /* cleanup everything */
1042 torture_reset_lease_break_info(tctx, &lease_break_info);
1044 smb2_util_close(tree1, h_client1_file1);
1045 smb2_util_close(tree1, h_client1_file2);
1046 smb2_util_close(tree1, h_client1_file3);
1047 smb2_util_close(tree2A, h_client2_file1);
1048 smb2_util_close(tree2A, h_client2_file2);
1049 smb2_util_close(tree2A, h_client2_file3);
1051 smb2_util_unlink(tree1, fname1);
1052 smb2_util_unlink(tree1, fname2);
1053 smb2_util_unlink(tree1, fname3);
1054 CHECK_VAL(lease_break_info.count, 0);
1055 test_multichannel_free_channels(tree2A, tree2B, tree2C);
1056 tree2A = tree2B = tree2C = NULL;
1058 tree1->session = session1;
1060 smb2_util_close(tree1, h_client1_file1);
1061 smb2_util_close(tree1, h_client1_file2);
1062 smb2_util_close(tree1, h_client1_file3);
1063 if (tree2A != NULL) {
1064 smb2_util_close(tree2A, h_client2_file1);
1065 smb2_util_close(tree2A, h_client2_file2);
1066 smb2_util_close(tree2A, h_client2_file3);
1070 smb2_util_close(tree1, *h);
1073 smb2_util_unlink(tree1, fname1);
1074 smb2_util_unlink(tree1, fname2);
1075 smb2_util_unlink(tree1, fname3);
1076 smb2_deltree(tree1, BASEDIR);
1078 test_multichannel_free_channels(tree2A, tree2B, tree2C);
1080 talloc_free(mem_ctx);
1086 * Lease Break Test 2:
1087 * Test for lease break retries being sent by the server.
1089 * open file1 in session 2A
1090 * open file2 in session 2B
1092 * open file2 in session 1
1093 * lease break retry reaches the client?
1095 * open file3 in session 2C
1097 * open file1 in session 1
1098 * lease break reaches the client?
1099 * open file3 in session 1
1100 * lease break reached the client?
1102 * On deletion by 1, lease breaks sent for file1, file2 and file3
1104 * This changes RH lease to R for Session 2.
1105 * (This has been disabled while we add support for sending lease
1106 * break for handle leases.)
1108 static bool test_multichannel_lease_break_test2(struct torture_context *tctx,
1109 struct smb2_tree *tree1)
1111 const char *host = torture_setting_string(tctx, "host", NULL);
1112 const char *share = torture_setting_string(tctx, "share", NULL);
1113 struct cli_credentials *credentials = popt_get_cmdline_credentials();
1115 TALLOC_CTX *mem_ctx = talloc_new(tctx);
1116 struct smb2_handle _h;
1117 struct smb2_handle *h = NULL;
1118 struct smb2_handle h_client1_file1 = {{0}};
1119 struct smb2_handle h_client1_file2 = {{0}};
1120 struct smb2_handle h_client1_file3 = {{0}};
1121 struct smb2_handle h_client2_file1 = {{0}};
1122 struct smb2_handle h_client2_file2 = {{0}};
1123 struct smb2_handle h_client2_file3 = {{0}};
1124 struct smb2_create io1, io2, io3;
1126 const char *fname1 = BASEDIR "\\lease_break_test1.dat";
1127 const char *fname2 = BASEDIR "\\lease_break_test2.dat";
1128 const char *fname3 = BASEDIR "\\lease_break_test3.dat";
1129 struct smb2_tree *tree2A = NULL;
1130 struct smb2_tree *tree2B = NULL;
1131 struct smb2_tree *tree2C = NULL;
1132 struct smb2_transport *transport1 = tree1->session->transport;
1133 struct smb2_transport *transport2A = NULL;
1134 struct smbcli_options transport2_options;
1135 struct smb2_session *session1 = tree1->session;
1136 uint16_t local_port = 0;
1137 struct smb2_lease ls1;
1138 struct smb2_lease ls2;
1139 struct smb2_lease ls3;
1140 bool block_ok = false;
1141 bool unblock_ok = false;
1144 if (!test_multichannel_initial_checks(tctx, tree1)) {
1148 torture_comment(tctx, "Lease break retry: Test2\n");
1150 torture_reset_lease_break_info(tctx, &lease_break_info);
1152 transport1->lease.handler = torture_lease_handler;
1153 transport1->lease.private_data = tree1;
1154 torture_comment(tctx, "transport1 [%p]\n", transport1);
1155 local_port = torture_get_local_port_from_transport(transport1);
1156 torture_comment(tctx, "transport1 uses tcp port: %d\n", local_port);
1158 status = torture_smb2_testdir(tree1, BASEDIR, &_h);
1159 CHECK_STATUS(status, NT_STATUS_OK);
1160 smb2_util_close(tree1, _h);
1161 smb2_util_unlink(tree1, fname1);
1162 smb2_util_unlink(tree1, fname2);
1163 smb2_util_unlink(tree1, fname3);
1164 CHECK_VAL(lease_break_info.count, 0);
1166 smb2_lease_create(&io1, &ls1, false, fname1, LEASE2F1,
1167 smb2_util_lease_state("RHW"));
1168 test_multichannel_init_smb_create(&io1);
1170 smb2_lease_create(&io2, &ls2, false, fname2, LEASE2F2,
1171 smb2_util_lease_state("RHW"));
1172 test_multichannel_init_smb_create(&io2);
1174 smb2_lease_create(&io3, &ls3, false, fname3, LEASE2F3,
1175 smb2_util_lease_state("RHW"));
1176 test_multichannel_init_smb_create(&io3);
1178 transport2_options = transport1->options;
1180 ret = test_multichannel_create_channels(tctx, host, share,
1182 &transport2_options,
1183 &tree2A, &tree2B, NULL);
1184 torture_assert(tctx, ret, "Could not create channels.\n");
1185 transport2A = tree2A->session->transport;
1187 /* 2a opens file1 */
1188 torture_comment(tctx, "client2 opens fname1 via session 2A\n");
1189 smb2_lease_create(&io1, &ls1, false, fname1, LEASE2F1,
1190 smb2_util_lease_state("RHW"));
1191 status = smb2_create(tree2A, mem_ctx, &io1);
1192 CHECK_STATUS(status, NT_STATUS_OK);
1193 h_client2_file1 = io1.out.file.handle;
1194 CHECK_CREATED(&io1, CREATED, FILE_ATTRIBUTE_ARCHIVE);
1195 CHECK_LEASE(&io1, "RHW", true, LEASE2F1, 0);
1196 CHECK_VAL(io1.out.durable_open_v2, false); //true);
1197 CHECK_VAL(io1.out.timeout, io1.in.timeout);
1198 CHECK_VAL(io1.out.durable_open, false);
1199 CHECK_VAL(lease_break_info.count, 0);
1201 /* 2b opens file2 */
1202 torture_comment(tctx, "client2 opens fname2 via session 2B\n");
1203 smb2_lease_create(&io2, &ls2, false, fname2, LEASE2F2,
1204 smb2_util_lease_state("RHW"));
1205 status = smb2_create(tree2B, mem_ctx, &io2);
1206 CHECK_STATUS(status, NT_STATUS_OK);
1207 h_client2_file2 = io2.out.file.handle;
1208 CHECK_CREATED(&io2, CREATED, FILE_ATTRIBUTE_ARCHIVE);
1209 CHECK_LEASE(&io2, "RHW", true, LEASE2F2, 0);
1210 CHECK_VAL(io2.out.durable_open_v2, false); //true);
1211 CHECK_VAL(io2.out.timeout, io2.in.timeout);
1212 CHECK_VAL(io2.out.durable_open, false);
1213 CHECK_VAL(lease_break_info.count, 0);
1216 torture_comment(tctx, "Blocking 2A\n");
1218 block_ok = test_block_channel(tctx, transport2A);
1219 torture_assert(tctx, block_ok, "we could not block tcp transport");
1222 torture_comment(tctx,
1223 "Client opens fname2 with session1 with 2A blocked\n");
1224 smb2_lease_create(&io2, &ls2, false, fname2, LEASE1F2,
1225 smb2_util_lease_state("RHW"));
1226 status = smb2_create(tree1, mem_ctx, &io2);
1227 CHECK_STATUS(status, NT_STATUS_OK);
1228 h_client1_file2 = io2.out.file.handle;
1229 CHECK_CREATED(&io2, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
1230 CHECK_LEASE(&io2, "RH", true, LEASE1F2, 0);
1231 CHECK_VAL(io2.out.durable_open_v2, false);
1232 CHECK_VAL(io2.out.timeout, 0);
1233 CHECK_VAL(io2.out.durable_open, false);
1235 if (lease_break_info.count == 0) {
1236 torture_comment(tctx,
1237 "Did not receive expected lease break!!\n");
1239 torture_comment(tctx, "Received %d lease break(s)!!\n",
1240 lease_break_info.count);
1243 CHECK_VAL(lease_break_info.count, 1);
1244 CHECK_BREAK_INFO("RHW", "RH", LEASE2F2);
1245 torture_reset_lease_break_info(tctx, &lease_break_info);
1248 torture_comment(tctx, "Connecting session 2C\n");
1249 talloc_free(tree2C);
1250 tree2C = test_multichannel_create_channel(tctx, host, share,
1251 credentials, &transport2_options, tree2A);
1256 /* 2c opens file3 */
1257 torture_comment(tctx, "client2 opens fname3 via session 2C\n");
1258 smb2_lease_create(&io3, &ls3, false, fname3, LEASE2F3,
1259 smb2_util_lease_state("RHW"));
1260 status = smb2_create(tree2C, mem_ctx, &io3);
1261 CHECK_STATUS(status, NT_STATUS_OK);
1262 h_client2_file3 = io3.out.file.handle;
1263 CHECK_CREATED(&io3, CREATED, FILE_ATTRIBUTE_ARCHIVE);
1264 CHECK_LEASE(&io3, "RHW", true, LEASE2F3, 0);
1265 CHECK_VAL(io3.out.durable_open_v2, false);
1266 CHECK_VAL(io3.out.timeout, io2.in.timeout);
1267 CHECK_VAL(io3.out.durable_open, false);
1268 CHECK_VAL(lease_break_info.count, 0);
1271 torture_comment(tctx, "Unblocking 2A\n");
1272 unblock_ok = test_unblock_channel(tctx, transport2A);
1273 torture_assert(tctx, unblock_ok, "we could not unblock tcp transport");
1276 torture_comment(tctx, "Client opens fname1 with session 1\n");
1277 smb2_lease_create(&io1, &ls1, false, fname1, LEASE1F1,
1278 smb2_util_lease_state("RHW"));
1279 status = smb2_create(tree1, mem_ctx, &io1);
1280 CHECK_STATUS(status, NT_STATUS_OK);
1281 h_client1_file1 = io1.out.file.handle;
1282 CHECK_CREATED(&io1, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
1283 CHECK_LEASE(&io1, "RH", true, LEASE1F1, 0);
1285 if (lease_break_info.count == 0) {
1286 torture_comment(tctx,
1287 "Did not receive expected lease break!!\n");
1289 torture_comment(tctx,
1290 "Received %d lease break(s)!!\n",
1291 lease_break_info.count);
1293 CHECK_VAL(lease_break_info.count, 1);
1294 CHECK_BREAK_INFO("RHW", "RH", LEASE2F1);
1295 torture_reset_lease_break_info(tctx, &lease_break_info);
1298 torture_comment(tctx, "client opens fname3 via session 1\n");
1300 smb2_lease_create(&io3, &ls3, false, fname3, LEASE1F3,
1301 smb2_util_lease_state("RHW"));
1302 status = smb2_create(tree1, mem_ctx, &io3);
1303 CHECK_STATUS(status, NT_STATUS_OK);
1304 h_client1_file3 = io3.out.file.handle;
1305 CHECK_CREATED(&io3, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
1306 CHECK_LEASE(&io3, "RH", true, LEASE1F3, 0);
1308 if (lease_break_info.count == 0) {
1309 torture_comment(tctx,
1310 "Did not receive expected lease break!!\n");
1312 torture_comment(tctx,
1313 "Received %d lease break(s)!!\n",
1314 lease_break_info.count);
1316 CHECK_VAL(lease_break_info.count, 1);
1317 CHECK_BREAK_INFO("RHW", "RH", LEASE2F3);
1318 torture_reset_lease_break_info(tctx, &lease_break_info);
1320 smb2_util_close(tree1, h_client1_file1);
1321 smb2_util_close(tree1, h_client1_file2);
1322 smb2_util_close(tree1, h_client1_file3);
1325 * Session 2 still has RW lease on file 1. Deletion of this file by 1
1326 * leads to a lease break call to session 2 file1
1328 smb2_util_unlink(tree1, fname1);
1330 * Bug - Samba does not revoke Handle lease on unlink
1331 * CHECK_BREAK_INFO("RH", "R", LEASE2F1);
1333 torture_reset_lease_break_info(tctx, &lease_break_info);
1336 * Session 2 still has RW lease on file 2. Deletion of this file by 1
1337 * leads to a lease break call to session 2 file2
1339 smb2_util_unlink(tree1, fname2);
1341 * Bug - Samba does not revoke Handle lease on unlink
1342 * CHECK_BREAK_INFO("RH", "R", LEASE2F2);
1344 torture_reset_lease_break_info(tctx, &lease_break_info);
1347 * Session 2 still has RW lease on file 3. Deletion of this file by 1
1348 * leads to a lease break call to session 2 file3
1350 smb2_util_unlink(tree1, fname3);
1352 * Bug - Samba does not revoke Handle lease on unlink
1353 * CHECK_BREAK_INFO("RH", "R", LEASE2F3);
1355 torture_reset_lease_break_info(tctx, &lease_break_info);
1357 smb2_util_close(tree2C, h_client2_file1);
1358 smb2_util_close(tree2C, h_client2_file2);
1359 smb2_util_close(tree2C, h_client2_file3);
1361 test_multichannel_free_channels(tree2A, tree2B, tree2C);
1362 tree2A = tree2B = tree2C = NULL;
1365 if (block_ok && !unblock_ok) {
1366 test_unblock_channel(tctx, transport2A);
1368 test_cleanup_blocked_channels(tctx);
1370 tree1->session = session1;
1372 smb2_util_close(tree1, h_client1_file1);
1373 smb2_util_close(tree1, h_client1_file2);
1374 smb2_util_close(tree1, h_client1_file3);
1375 if (tree2A != NULL) {
1376 smb2_util_close(tree2A, h_client2_file1);
1377 smb2_util_close(tree2A, h_client2_file2);
1378 smb2_util_close(tree2A, h_client2_file3);
1382 smb2_util_close(tree1, *h);
1385 smb2_util_unlink(tree1, fname1);
1386 smb2_util_unlink(tree1, fname2);
1387 smb2_util_unlink(tree1, fname3);
1388 smb2_deltree(tree1, BASEDIR);
1390 test_multichannel_free_channels(tree2A, tree2B, tree2C);
1392 talloc_free(mem_ctx);
1398 * Test 3: Check to see how the server behaves if lease break
1399 * response is sent over a different channel to one over which
1400 * the break is received.
1402 * open file1 in session 2A
1403 * open file1 in session 1
1404 * Lease break sent to 2A
1405 * 2B sends back lease break reply.
1406 * session 1 allowed to open file
1408 static bool test_multichannel_lease_break_test3(struct torture_context *tctx,
1409 struct smb2_tree *tree1)
1411 const char *host = torture_setting_string(tctx, "host", NULL);
1412 const char *share = torture_setting_string(tctx, "share", NULL);
1413 struct cli_credentials *credentials = popt_get_cmdline_credentials();
1415 TALLOC_CTX *mem_ctx = talloc_new(tctx);
1416 struct smb2_handle _h;
1417 struct smb2_handle *h = NULL;
1418 struct smb2_handle h_client1_file1 = {{0}};
1419 struct smb2_handle h_client2_file1 = {{0}};
1420 struct smb2_create io1;
1422 const char *fname1 = BASEDIR "\\lease_break_test1.dat";
1423 struct smb2_tree *tree2A = NULL;
1424 struct smb2_tree *tree2B = NULL;
1425 struct smb2_transport *transport1 = tree1->session->transport;
1426 struct smb2_transport *transport2A = NULL;
1427 struct smbcli_options transport2_options;
1428 uint16_t local_port = 0;
1429 struct smb2_lease ls1;
1430 struct tevent_timer *te = NULL;
1432 bool timesup = false;
1433 TALLOC_CTX *tmp_ctx = talloc_new(NULL);
1435 if (!test_multichannel_initial_checks(tctx, tree1)) {
1439 torture_comment(tctx, "Lease break retry: Test3\n");
1441 torture_reset_lease_break_info(tctx, &lease_break_info);
1443 transport1->lease.handler = torture_lease_handler;
1444 transport1->lease.private_data = tree1;
1445 torture_comment(tctx, "transport1 [%p]\n", transport1);
1446 local_port = torture_get_local_port_from_transport(transport1);
1447 torture_comment(tctx, "transport1 uses tcp port: %d\n", local_port);
1449 status = torture_smb2_testdir(tree1, BASEDIR, &_h);
1450 CHECK_STATUS(status, NT_STATUS_OK);
1451 smb2_util_close(tree1, _h);
1452 smb2_util_unlink(tree1, fname1);
1453 CHECK_VAL(lease_break_info.count, 0);
1455 smb2_lease_create(&io1, &ls1, false, fname1, LEASE2F1,
1456 smb2_util_lease_state("RHW"));
1457 test_multichannel_init_smb_create(&io1);
1459 transport2_options = transport1->options;
1461 ret = test_multichannel_create_channels(tctx, host, share,
1463 &transport2_options,
1464 &tree2A, &tree2B, NULL);
1465 torture_assert(tctx, ret, "Could not create channels.\n");
1466 transport2A = tree2A->session->transport;
1467 transport2A->lease.private_data = tree2B;
1469 /* 2a opens file1 */
1470 torture_comment(tctx, "client2 opens fname1 via session 2A\n");
1471 smb2_lease_create(&io1, &ls1, false, fname1, LEASE2F1,
1472 smb2_util_lease_state("RHW"));
1473 status = smb2_create(tree2A, mem_ctx, &io1);
1474 CHECK_STATUS(status, NT_STATUS_OK);
1475 h_client2_file1 = io1.out.file.handle;
1476 CHECK_CREATED(&io1, CREATED, FILE_ATTRIBUTE_ARCHIVE);
1477 CHECK_LEASE(&io1, "RHW", true, LEASE2F1, 0);
1478 CHECK_VAL(io1.out.durable_open_v2, false); //true);
1479 CHECK_VAL(io1.out.timeout, io1.in.timeout);
1480 CHECK_VAL(io1.out.durable_open, false);
1481 CHECK_VAL(lease_break_info.count, 0);
1483 /* Set a timeout for 5 seconds for session 1 to open file1 */
1484 ne = tevent_timeval_current_ofs(0, 5000000);
1485 te = tevent_add_timer(tctx->ev, tmp_ctx, ne, timeout_cb, ×up);
1487 torture_comment(tctx, "Failed to add timer.");
1492 torture_comment(tctx, "Client opens fname1 with session 1\n");
1493 smb2_lease_create(&io1, &ls1, false, fname1, LEASE1F1,
1494 smb2_util_lease_state("RHW"));
1495 status = smb2_create(tree1, mem_ctx, &io1);
1496 CHECK_STATUS(status, NT_STATUS_OK);
1497 h_client1_file1 = io1.out.file.handle;
1498 CHECK_CREATED(&io1, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
1499 CHECK_LEASE(&io1, "RH", true, LEASE1F1, 0);
1500 CHECK_VAL(io1.out.durable_open_v2, false);
1501 CHECK_VAL(io1.out.timeout, 0);
1502 CHECK_VAL(io1.out.durable_open, false);
1504 CHECK_VAL(lease_break_info.count, 1);
1505 CHECK_BREAK_INFO("RHW", "RH", LEASE2F1);
1508 * Check if timeout handler was fired. This would indicate
1509 * that the server didn't receive a reply for the oplock break
1510 * from the client and the server let session 1 open the file
1511 * only after the oplock break timeout.
1513 CHECK_VAL(timesup, false);
1516 smb2_util_close(tree1, h_client1_file1);
1517 if (tree2A != NULL) {
1518 smb2_util_close(tree2A, h_client2_file1);
1522 smb2_util_close(tree1, *h);
1525 smb2_util_unlink(tree1, fname1);
1526 smb2_deltree(tree1, BASEDIR);
1528 test_multichannel_free_channels(tree2A, tree2B, NULL);
1530 talloc_free(mem_ctx);
1535 struct torture_suite *torture_smb2_multichannel_init(TALLOC_CTX *ctx)
1537 struct torture_suite *suite = torture_suite_create(ctx, "multichannel");
1538 struct torture_suite *suite_generic = torture_suite_create(ctx,
1540 struct torture_suite *suite_oplocks = torture_suite_create(ctx,
1542 struct torture_suite *suite_leases = torture_suite_create(ctx,
1545 torture_suite_add_suite(suite, suite_generic);
1546 torture_suite_add_suite(suite, suite_oplocks);
1547 torture_suite_add_suite(suite, suite_leases);
1549 torture_suite_add_1smb2_test(suite, "interface_info",
1550 test_multichannel_interface_info);
1551 torture_suite_add_1smb2_test(suite_oplocks, "test1",
1552 test_multichannel_oplock_break_test1);
1553 torture_suite_add_1smb2_test(suite_oplocks, "test2",
1554 test_multichannel_oplock_break_test2);
1555 torture_suite_add_1smb2_test(suite_leases, "test1",
1556 test_multichannel_lease_break_test1);
1557 torture_suite_add_1smb2_test(suite_leases, "test2",
1558 test_multichannel_lease_break_test2);
1559 torture_suite_add_1smb2_test(suite_leases, "test3",
1560 test_multichannel_lease_break_test3);
1562 suite->description = talloc_strdup(suite, "SMB2 Multichannel tests");