torture3: Reproducer for bug 10593
authorVolker Lendecke <vl@samba.org>
Thu, 19 Jun 2014 14:37:40 +0000 (14:37 +0000)
committerVolker Lendecke <vl@samba.org>
Sat, 21 Jun 2014 21:05:47 +0000 (23:05 +0200)
We panic if we get an oplock break response for a cancelled create request

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Sat Jun 21 23:05:47 CEST 2014 on sn-devel-104

source3/selftest/tests.py
source3/torture/proto.h
source3/torture/test_oplock_cancel.c [new file with mode: 0644]
source3/torture/torture.c
source3/wscript_build

index 5cee5245a95b3024a7568900d41cd28b9c1e0aef..e529b3a1ac5465279a98f64734f0171d0fc75781 100755 (executable)
@@ -68,6 +68,12 @@ for t in tests:
         plantestsuite("samba3.smbtorture_s3.crypt_server(s3dc).%s" % t, "s3dc", [os.path.join(samba3srcdir, "script/tests/test_smbtorture_s3.sh"), t, '//$SERVER_IP/tmpenc', '$USERNAME', '$PASSWORD', smbtorture3, "", "-l $LOCAL_PATH"])
     plantestsuite("samba3.smbtorture_s3.plain(dc).%s" % t, "dc", [os.path.join(samba3srcdir, "script/tests/test_smbtorture_s3.sh"), t, '//$SERVER_IP/tmp', '$USERNAME', '$PASSWORD', smbtorture3, "", "-l $LOCAL_PATH"])
 
+# non-crypt only
+
+tests = ["OPLOCK-CANCEL"]
+for t in tests:
+    plantestsuite("samba3.smbtorture_s3.plain(s3dc).%s" % t, "s3dc", [os.path.join(samba3srcdir, "script/tests/test_smbtorture_s3.sh"), t, '//$SERVER_IP/tmp', '$USERNAME', '$PASSWORD', smbtorture3, "", "-l $LOCAL_PATH"])
+
 tests = ["RW1", "RW2", "RW3"]
 for t in tests:
     plantestsuite("samba3.smbtorture_s3.vfs_aio_fork(simpleserver).%s" % t, "simpleserver", [os.path.join(samba3srcdir, "script/tests/test_smbtorture_s3.sh"), t, '//$SERVER_IP/vfs_aio_fork', '$USERNAME', '$PASSWORD', smbtorture3, "", "-l $LOCAL_PATH"])
index 20c11103220ccdd6c2d2554a098f50b05564e696..08790c758e9b27790dcd6cf90101aa96d059f955 100644 (file)
@@ -116,5 +116,6 @@ bool run_bench_pthreadpool(int dummy);
 bool run_messaging_read1(int dummy);
 bool run_messaging_read2(int dummy);
 bool run_messaging_read3(int dummy);
+bool run_oplock_cancel(int dummy);
 
 #endif /* __TORTURE_H__ */
diff --git a/source3/torture/test_oplock_cancel.c b/source3/torture/test_oplock_cancel.c
new file mode 100644 (file)
index 0000000..aa4218a
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+   Unix SMB/CIFS implementation.
+   Test cleanup behaviour
+   Copyright (C) Volker Lendecke 2011
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "locking/proto.h"
+#include "torture/proto.h"
+#include "system/filesys.h"
+#include "system/select.h"
+#include "libsmb/libsmb.h"
+#include "libcli/smb/smbXcli_base.h"
+#include "libcli/security/security.h"
+#include "lib/util/tevent_ntstatus.h"
+
+struct create_cancel_state {
+       uint8_t dummy;
+};
+
+static void create_cancel_done(struct tevent_req *subreq);
+
+static struct tevent_req *create_cancel_send(
+       TALLOC_CTX *mem_ctx, struct tevent_context *ev,
+       struct cli_state *cli, const char *fname)
+{
+       struct tevent_req *req, *subreq;
+       struct create_cancel_state *state;
+
+       req = tevent_req_create(mem_ctx, &state, struct create_cancel_state);
+       if (req == NULL) {
+               return NULL;
+       }
+
+       subreq = cli_ntcreate_send(
+               mem_ctx, ev, cli, fname, 0, FILE_GENERIC_READ,
+               FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE,
+               FILE_OPEN_IF, 0, 0);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       if (!tevent_req_cancel(subreq)) {
+               tevent_req_oom(req);
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, create_cancel_done, req);
+       return req;
+}
+
+static void create_cancel_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       NTSTATUS status;
+
+       status = cli_ntcreate_recv(subreq, NULL, NULL);
+       TALLOC_FREE(subreq);
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_CANCELLED)) {
+               if (NT_STATUS_IS_OK(status)) {
+                       status = NT_STATUS_UNSUCCESSFUL;
+               }
+               tevent_req_nterror(req, status);
+               return;
+       }
+       tevent_req_done(req);
+}
+
+static NTSTATUS create_cancel_recv(struct tevent_req *req)
+{
+       return tevent_req_simple_recv_ntstatus(req);
+}
+
+static NTSTATUS create_cancel(struct cli_state *cli, const char *fname)
+{
+       TALLOC_CTX *frame = talloc_stackframe();
+       struct tevent_context *ev;
+       struct tevent_req *req;
+       NTSTATUS status = NT_STATUS_NO_MEMORY;
+
+       ev = samba_tevent_context_init(frame);
+       if (ev == NULL) {
+               goto fail;
+       }
+       req = create_cancel_send(frame, ev, cli, fname);
+       if (req == NULL) {
+               goto fail;
+       }
+       if (!tevent_req_poll_ntstatus(req, ev, &status)) {
+               goto fail;
+       }
+       status = create_cancel_recv(req);
+ fail:
+       TALLOC_FREE(frame);
+       return status;
+}
+
+bool run_oplock_cancel(int dummy)
+{
+       struct cli_state *cli1, *cli2;
+       const char *fname = "oplock-cancel";
+       uint16_t fnum1;
+       NTSTATUS status;
+
+       lp_set_cmdline("client max protocol", "smb3");
+
+       if (!torture_open_connection(&cli1, 0)) {
+               return false;
+       }
+       cli1->use_oplocks = true;
+
+       if (!torture_open_connection(&cli2, 0)) {
+               return false;
+       }
+       cli2->use_oplocks = true;
+
+       status = cli_ntcreate(
+               cli1, fname, 0, FILE_GENERIC_READ, FILE_ATTRIBUTE_NORMAL,
+               FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF, 0, 0,
+               &fnum1, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("cli_ntcreate failed: %s\n", nt_errstr(status));
+               return false;
+       }
+
+       status = create_cancel(cli2, fname);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("create_cancel failed: %s\n", nt_errstr(status));
+               return false;
+       }
+
+       TALLOC_FREE(cli1);
+
+       /*
+        * Give cli1's smbd time to inform cli2's smbd
+        */
+       smb_msleep(5000);
+
+       status = cli_unlink(cli2, fname,
+                           FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("cli_unlink failed: %s\n", nt_errstr(status));
+               return false;
+       }
+
+       return true;
+}
index cea908930c1e254478a28e43c40d79f5cfdaaac9..f5f8f86967ece5b6a2d32f7ff9ea8204c3571343 100644 (file)
@@ -9596,6 +9596,7 @@ static struct {
        { "CLEANUP2", run_cleanup2 },
        { "CLEANUP3", run_cleanup3 },
        { "CLEANUP4", run_cleanup4 },
+       { "OPLOCK-CANCEL", run_oplock_cancel },
        { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
        { "LOCAL-GENCACHE", run_local_gencache, 0},
        { "LOCAL-TALLOC-DICT", run_local_talloc_dict, 0},
index 5002f9363ed12d7316bcd5b60b3674532e525ec1..6f668bad371367c60e89dce163f3c9a5b158ee0d 100755 (executable)
@@ -1253,6 +1253,7 @@ bld.SAMBA3_BINARY('smbtorture' + bld.env.suffix3,
                  torture/test_dbwrap_ctdb.c
                  torture/test_buffersize.c
                  torture/test_messaging_read.c
+                 torture/test_oplock_cancel.c
                  torture/t_strappend.c
                  torture/bench_pthreadpool.c
                  torture/wbc_async.c''',