selftest: add a durable handle test with delayed disconnect
authorRalph Boehme <slow@samba.org>
Thu, 30 Aug 2018 17:15:19 +0000 (19:15 +0200)
committerJeremy Allison <jra@samba.org>
Fri, 31 Aug 2018 20:22:23 +0000 (22:22 +0200)
Bug: https://bugzilla.samba.org/show_bug.cgi?id=13549

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
selftest/knownfail.d/samba3.blackbox [new file with mode: 0644]
selftest/target/Samba3.pm
source3/script/tests/test_durable_handle_reconnect.sh [new file with mode: 0755]
source3/selftest/tests.py
source4/selftest/tests.py
source4/torture/smb2/durable_v2_open.c
source4/torture/smb2/smb2.c

diff --git a/selftest/knownfail.d/samba3.blackbox b/selftest/knownfail.d/samba3.blackbox
new file mode 100644 (file)
index 0000000..b03a1ac
--- /dev/null
@@ -0,0 +1 @@
+^samba3.blackbox.durable_v2_delay.durable_v2_delay\(simpleserver:local\)
index d90c8f7e85b787b2d885cf0bd484351ab4f836bc..bcbf0addf2bcbb13541072c1c203a638a23a31dc 100755 (executable)
@@ -2218,6 +2218,14 @@ sub provision($$$$$$$$$)
        copy = tmp
        vfs objects = error_inject
        include = $libdir/error_inject.conf
+
+[delay_inject]
+       copy = tmp
+       vfs objects = delay_inject
+       kernel share modes = no
+       kernel oplocks = no
+       posix locking = no
+       include = $libdir/delay_inject.conf
        ";
        close(CONF);
 
diff --git a/source3/script/tests/test_durable_handle_reconnect.sh b/source3/script/tests/test_durable_handle_reconnect.sh
new file mode 100755 (executable)
index 0000000..bca8e2d
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/sh
+#
+# Test Durable Handle reconnect with injected delay in the disconnect.
+#
+# Copyright (C) 2018 Ralph Boehme
+
+. $(dirname $0)/../../../testprogs/blackbox/subunit.sh
+failed=0
+
+delay_inject_conf=$(dirname $SMB_CONF_PATH)/delay_inject.conf
+
+echo 'delay_inject:ntimes = 5000' > $delay_inject_conf
+
+testit "durable_v2_delay" $VALGRIND \
+       $BINDIR/smbtorture //$SERVER_IP/delay_inject \
+       -U$USERNAME%$PASSWORD  smb2.durable-v2-delay ||
+       failed=$(expr $failed + 1)
+
+rm $delay_inject_conf
+
+testok $0 $failed
index 3b6735231de10749eb4d5777422f11591d59e025..2f474ec2dbf14fd37ce4fffcebd5479fc7d2019f 100755 (executable)
@@ -484,7 +484,7 @@ for t in tests:
     elif t == "rpc.samr.passwords.validate":
         plansmbtorture4testsuite(t, "nt4_dc", 'ncacn_ip_tcp:$SERVER_IP[seal] -U$USERNAME%$PASSWORD', 'over ncacn_ip_tcp ')
         plansmbtorture4testsuite(t, "ad_dc", 'ncacn_ip_tcp:$SERVER_IP[seal] -U$USERNAME%$PASSWORD', 'over ncacn_ip_tcp ')
-    elif t == "smb2.durable-open" or t == "smb2.durable-v2-open" or t == "smb2.replay":
+    elif t == "smb2.durable-open" or t == "smb2.durable-v2-open" or t == "smb2.replay" or t == "smb2.durable-v2-delay":
         plansmbtorture4testsuite(t, "nt4_dc", '//$SERVER_IP/durable -U$USERNAME%$PASSWORD')
         plansmbtorture4testsuite(t, "ad_dc", '//$SERVER_IP/durable -U$USERNAME%$PASSWORD')
     elif t == "base.rw1":
@@ -651,6 +651,9 @@ plantestsuite("samba3.blackbox.net_tdb", "simpleserver:local",
 plantestsuite("samba3.blackbox.smbd_error", "simpleserver:local",
               [os.path.join(samba3srcdir, "script/tests/test_smbd_error.sh")])
 
+plantestsuite("samba3.blackbox.durable_v2_delay", "simpleserver:local",
+              [os.path.join(samba3srcdir, "script/tests/test_durable_handle_reconnect.sh")])
+
 plantestsuite("samba3.blackbox.net_cache_samlogon", "ad_member:local",
               [os.path.join(samba3srcdir, "script/tests/test_net_cache_samlogon.sh"),
                 '$SERVER', 'tmp', '$DC_USERNAME', '$DC_PASSWORD'])
index c586b2d373970d42cb295b65eedd2d6d44facc57..751093a031c2beb8e2196354772ffd519913830a 100755 (executable)
@@ -318,6 +318,7 @@ smb2_s3only = [
     "smb2.dosmode",
     "smb2.credits",
     "smb2.kernel-oplocks",
+    "smb2.durable-v2-delay",
 ]
 smb2 = [x for x in smbtorture4_testsuites("smb2.") if x not in smb2_s3only]
 
index 0a928ec8c2651321ebbd14b34c02de5fbd8a88e2..25e6d27465a1833a98a8ad31d9b2d5233043422b 100644 (file)
@@ -2035,3 +2035,98 @@ struct torture_suite *torture_smb2_durable_v2_open_init(TALLOC_CTX *ctx)
 
        return suite;
 }
+
+/**
+ * basic test for doing a durable open
+ * tcp disconnect, reconnect, do a durable reopen (succeeds)
+ */
+static bool test_durable_v2_reconnect_delay(struct torture_context *tctx,
+                                           struct smb2_tree *tree)
+{
+       NTSTATUS status;
+       TALLOC_CTX *mem_ctx = talloc_new(tctx);
+       char fname[256];
+       struct smb2_handle _h;
+       struct smb2_handle *h = NULL;
+       struct smb2_create io;
+       struct GUID create_guid = GUID_random();
+       struct smbcli_options options;
+       uint64_t previous_session_id;
+       uint8_t b = 0;
+       bool ret = true;
+
+       options = tree->session->transport->options;
+       previous_session_id = smb2cli_session_current_id(tree->session->smbXcli);
+
+       /* Choose a random name in case the state is left a little funky. */
+       snprintf(fname, 256, "durable_v2_reconnect_delay_%s.dat",
+                generate_random_str(tctx, 8));
+
+       smb2_util_unlink(tree, fname);
+
+       smb2_oplock_create_share(&io, fname,
+                                smb2_util_share_access(""),
+                                smb2_util_oplock_level("b"));
+       io.in.durable_open = false;
+       io.in.durable_open_v2 = true;
+       io.in.persistent_open = false;
+       io.in.create_guid = create_guid;
+       io.in.timeout = 0;
+
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       _h = io.out.file.handle;
+       h = &_h;
+       CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b"));
+       CHECK_VAL(io.out.durable_open_v2, true);
+
+       status = smb2_util_write(tree, *h, &b, 0, 1);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       /* disconnect, leaving the durable open */
+       TALLOC_FREE(tree);
+
+       if (!torture_smb2_connection_ext(tctx, previous_session_id,
+                                        &options, &tree)) {
+               torture_warning(tctx, "couldn't reconnect, bailing\n");
+               ret = false;
+               goto done;
+       }
+
+       ZERO_STRUCT(io);
+       io.in.fname = fname;
+       io.in.durable_open_v2 = false;
+       io.in.durable_handle_v2 = h;
+       io.in.create_guid = create_guid;
+       h = NULL;
+
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b"));
+       _h = io.out.file.handle;
+       h = &_h;
+
+done:
+       if (h != NULL) {
+               smb2_util_close(tree, *h);
+       }
+
+       smb2_util_unlink(tree, fname);
+
+       talloc_free(tree);
+
+       talloc_free(mem_ctx);
+
+       return ret;
+}
+
+struct torture_suite *torture_smb2_durable_v2_delay_init(TALLOC_CTX *ctx)
+{
+       struct torture_suite *suite =
+           torture_suite_create(ctx, "durable-v2-delay");
+
+       torture_suite_add_1smb2_test(suite, "durable_v2_reconnect_delay", test_durable_v2_reconnect_delay);
+
+       return suite;
+}
index 344cf5a40a52bb79f80176920cacc2b45d00fcf8..12f7edf8f86154f75700be5f613d64e4f5145086 100644 (file)
@@ -163,6 +163,8 @@ NTSTATUS torture_smb2_init(TALLOC_CTX *ctx)
                torture_smb2_durable_open_disconnect_init(suite));
        torture_suite_add_suite(suite,
                torture_smb2_durable_v2_open_init(suite));
+       torture_suite_add_suite(suite,
+               torture_smb2_durable_v2_delay_init(suite));
        torture_suite_add_suite(suite, torture_smb2_dir_init(suite));
        torture_suite_add_suite(suite, torture_smb2_lease_init(suite));
        torture_suite_add_suite(suite, torture_smb2_compound_init(suite));