s4-torture: move oplock break handler out of the replay testsuite.
authorGünther Deschner <gd@samba.org>
Wed, 28 Sep 2016 19:23:20 +0000 (21:23 +0200)
committerJeremy Allison <jra@samba.org>
Fri, 19 Apr 2019 17:27:12 +0000 (17:27 +0000)
Signed-off-by: Guenther Deschner <gd@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source4/torture/smb2/oplock_break_handler.c [new file with mode: 0644]
source4/torture/smb2/oplock_break_handler.h [new file with mode: 0644]
source4/torture/smb2/replay.c
source4/torture/smb2/wscript_build

diff --git a/source4/torture/smb2/oplock_break_handler.c b/source4/torture/smb2/oplock_break_handler.c
new file mode 100644 (file)
index 0000000..30863a9
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * Unix SMB/CIFS implementation.
+ *
+ * test suite for SMB2 replay
+ *
+ * Copyright (C) Anubhav Rakshit 2014
+ * Copyright (C) Stefan Metzmacher 2014
+ *
+ * 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 "libcli/smb2/smb2.h"
+#include "libcli/smb2/smb2_calls.h"
+#include "torture/torture.h"
+#include "torture/smb2/proto.h"
+#include "../libcli/smb/smbXcli_base.h"
+#include "oplock_break_handler.h"
+
+struct break_info break_info;
+
+static void torture_oplock_ack_callback(struct smb2_request *req)
+{
+       NTSTATUS status;
+
+       status = smb2_break_recv(req, &break_info.br);
+       if (!NT_STATUS_IS_OK(status)) {
+               break_info.failures++;
+               break_info.failure_status = status;
+       }
+}
+
+/**
+ * A general oplock break notification handler.  This should be used when a
+ * test expects to break from batch or exclusive to a lower level.
+ */
+
+bool torture_oplock_ack_handler(struct smb2_transport *transport,
+                               const struct smb2_handle *handle,
+                               uint8_t level,
+                               void *private_data)
+{
+       struct smb2_tree *tree = private_data;
+       const char *name;
+       struct smb2_request *req;
+
+       ZERO_STRUCT(break_info.br);
+
+       break_info.handle       = *handle;
+       break_info.level        = level;
+       break_info.count++;
+
+       switch (level) {
+       case SMB2_OPLOCK_LEVEL_II:
+               name = "level II";
+               break;
+       case SMB2_OPLOCK_LEVEL_NONE:
+               name = "none";
+               break;
+       default:
+               name = "unknown";
+               break_info.failures++;
+       }
+       torture_comment(break_info.tctx,
+                       "transport[%p] Acking to %s [0x%02X] in oplock handler\n",
+                       transport, name, level);
+
+       break_info.br.in.file.handle    = *handle;
+       break_info.br.in.oplock_level   = level;
+       break_info.br.in.reserved       = 0;
+       break_info.br.in.reserved2      = 0;
+       break_info.received_transport = tree->session->transport;
+       SMB_ASSERT(tree->session->transport == transport);
+
+       req = smb2_break_send(tree, &break_info.br);
+       req->async.fn = torture_oplock_ack_callback;
+       req->async.private_data = NULL;
+
+       return true;
+}
diff --git a/source4/torture/smb2/oplock_break_handler.h b/source4/torture/smb2/oplock_break_handler.h
new file mode 100644 (file)
index 0000000..78bba10
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Unix SMB/CIFS implementation.
+ *
+ * test suite for SMB2 replay
+ *
+ * Copyright (C) Anubhav Rakshit 2014
+ * Copyright (C) Stefan Metzmacher 2014
+ *
+ * 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/>.
+ */
+
+#ifndef __OPLOCK_BREAK_HANDLER_H__
+#define __OPLOCK_BREAK_HANDLER_H__
+
+struct break_info {
+       struct torture_context *tctx;
+       struct smb2_handle handle;
+       uint8_t level;
+       struct smb2_break br;
+       int count;
+       int failures;
+       NTSTATUS failure_status;
+       struct smb2_transport *received_transport;
+};
+
+extern struct break_info break_info;
+
+bool torture_oplock_ack_handler(struct smb2_transport *transport,
+                               const struct smb2_handle *handle,
+                               uint8_t level,
+                               void *private_data);
+
+static inline void torture_reset_break_info(struct torture_context *tctx,
+                             struct break_info *r)
+{
+       ZERO_STRUCTP(r);
+       r->tctx = tctx;
+}
+
+#endif /* __OPLOCK_BREAK_HANDLER_H__ */
index 57c7bef..903adc6 100644 (file)
@@ -32,6 +32,7 @@
 #include "libcli/resolve/resolve.h"
 #include "lib/param/param.h"
 #include "lib/events/events.h"
+#include "oplock_break_handler.h"
 
 #define CHECK_VAL(v, correct) do { \
        if ((v) != (correct)) { \
 
 #define BASEDIR "replaytestdir"
 
-struct break_info {
-       struct torture_context *tctx;
-       struct smb2_handle handle;
-       uint8_t level;
-       struct smb2_break br;
-       int count;
-       int failures;
-       NTSTATUS failure_status;
-};
-
-static struct break_info break_info;
-
-static void torture_reset_break_info(struct torture_context *tctx,
-                                    struct break_info *r)
-{
-       ZERO_STRUCTP(r);
-       r->tctx = tctx;
-}
-
-static void torture_oplock_ack_callback(struct smb2_request *req)
-{
-       NTSTATUS status;
-
-       status = smb2_break_recv(req, &break_info.br);
-       if (!NT_STATUS_IS_OK(status)) {
-               break_info.failures++;
-               break_info.failure_status = status;
-       }
-
-       return;
-}
-
-/**
- * A general oplock break notification handler.  This should be used when a
- * test expects to break from batch or exclusive to a lower level.
- */
-static bool torture_oplock_ack_handler(struct smb2_transport *transport,
-                                      const struct smb2_handle *handle,
-                                      uint8_t level,
-                                      void *private_data)
-{
-       struct smb2_tree *tree = private_data;
-       const char *name;
-       struct smb2_request *req;
-
-       ZERO_STRUCT(break_info.br);
-
-       break_info.handle       = *handle;
-       break_info.level        = level;
-       break_info.count++;
-
-       switch (level) {
-       case SMB2_OPLOCK_LEVEL_II:
-               name = "level II";
-               break;
-       case SMB2_OPLOCK_LEVEL_NONE:
-               name = "none";
-               break;
-       default:
-               name = "unknown";
-               break_info.failures++;
-       }
-       torture_comment(break_info.tctx,
-                       "Acking to %s [0x%02X] in oplock handler\n",
-                       name, level);
-
-       break_info.br.in.file.handle    = *handle;
-       break_info.br.in.oplock_level   = level;
-       break_info.br.in.reserved       = 0;
-       break_info.br.in.reserved2      = 0;
-
-       req = smb2_break_send(tree, &break_info.br);
-       req->async.fn = torture_oplock_ack_callback;
-       req->async.private_data = NULL;
-       return true;
-}
-
 /**
  * Timer handler function notifies the registering function that time is up
  */
index e10d3d9..1183cb9 100644 (file)
@@ -20,6 +20,7 @@ bld.SAMBA_MODULE('TORTURE_SMB2',
         maxfid.c
         maxwrite.c
         multichannel.c
+        oplock_break_handler.c
         notify.c
         notify_disabled.c
         oplock.c