works for SMB1 and SMB2
[metze/samba/wip.git] / source4 / torture / smb2 / durable_open.c
index c42588a204d9caf20f6089404131dc4f9050b580..63eb7e99922a84bbfd834862260d02522e941521 100644 (file)
@@ -25,8 +25,9 @@
 #include "libcli/smb2/smb2_calls.h"
 #include "../libcli/smb/smbXcli_base.h"
 #include "torture/torture.h"
+#include "torture/util.h"
 #include "torture/smb2/proto.h"
-#include "../libcli/smb/smbXcli_base.h"
+#include "../lib/util/time_basic.h"
 
 #define CHECK_VAL(v, correct) do { \
        if ((v) != (correct)) { \
                ret = false; \
        }} while (0)
 
-#define CHECK_NOT_VAL(v, correct) do { \
-       if ((v) == (correct)) { \
+#define CHECK_NOT_VAL(v, incorrect) do { \
+       if ((v) == (incorrect)) { \
                torture_result(tctx, TORTURE_FAIL, "(%s): wrong value for %s got 0x%llx - should not be 0x%llx\n", \
-                               __location__, #v, (unsigned long long)v, (unsigned long long)correct); \
+                               __location__, #v, (unsigned long long)v, (unsigned long long)incorrect); \
+               ret = false; \
+       }} while (0)
+
+#define CHECK_NOT_NULL(p) do { \
+       if ((p) == NULL) { \
+               torture_result(tctx, TORTURE_FAIL, "(%s): %s is NULL but it should not be.\n", \
+                               __location__, #p); \
                ret = false; \
        }} while (0)
 
@@ -163,8 +171,8 @@ done:
        return ret;
 }
 
-bool test_durable_open_open_oplock(struct torture_context *tctx,
-                                  struct smb2_tree *tree)
+static bool test_durable_open_open_oplock(struct torture_context *tctx,
+                                         struct smb2_tree *tree)
 {
        TALLOC_CTX *mem_ctx = talloc_new(tctx);
        char fname[256];
@@ -311,8 +319,8 @@ done:
        return ret;
 }
 
-bool test_durable_open_open_lease(struct torture_context *tctx,
-                                 struct smb2_tree *tree)
+static bool test_durable_open_open_lease(struct torture_context *tctx,
+                                        struct smb2_tree *tree)
 {
        TALLOC_CTX *mem_ctx = talloc_new(tctx);
        char fname[256];
@@ -356,8 +364,8 @@ done:
  * and do a durable reopen on the same connection
  * while the first open is still active (fails)
  */
-bool test_durable_open_reopen1(struct torture_context *tctx,
-                              struct smb2_tree *tree)
+static bool test_durable_open_reopen1(struct torture_context *tctx,
+                                     struct smb2_tree *tree)
 {
        NTSTATUS status;
        TALLOC_CTX *mem_ctx = talloc_new(tctx);
@@ -409,70 +417,151 @@ done:
 }
 
 /**
- * basic test for doing a durable open
- * tcp disconnect, reconnect, do a durable reopen (succeeds)
+ * Basic test for doing a durable open
+ * and do a session reconnect while the first
+ * session is still active and the handle is
+ * still open in the client.
+ * This closes the original session and  a
+ * durable reconnect on the new session succeeds.
  */
-bool test_durable_open_reopen2(struct torture_context *tctx,
-                              struct smb2_tree *tree)
+static bool test_durable_open_reopen1a(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 io1, io2;
+       struct smb2_create io;
        bool ret = true;
+       struct smb2_tree *tree2 = NULL;
+       struct smb2_tree *tree3 = NULL;
+       uint64_t previous_session_id;
+       struct smbcli_options options;
+       struct GUID orig_client_guid;
+
+       options = tree->session->transport->options;
+       orig_client_guid = options.client_guid;
 
        /* Choose a random name in case the state is left a little funky. */
-       snprintf(fname, 256, "durable_open_reopen2_%s.dat",
+       snprintf(fname, 256, "durable_open_reopen1a_%s.dat",
                 generate_random_str(tctx, 8));
 
        smb2_util_unlink(tree, fname);
 
-       smb2_oplock_create_share(&io1, fname,
+       smb2_oplock_create_share(&io, fname,
                                 smb2_util_share_access(""),
                                 smb2_util_oplock_level("b"));
-       io1.in.durable_open = true;
+       io.in.durable_open = true;
 
-       status = smb2_create(tree, mem_ctx, &io1);
+       status = smb2_create(tree, mem_ctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
-       _h = io1.out.file.handle;
+       _h = io.out.file.handle;
        h = &_h;
-       CHECK_CREATED(&io1, CREATED, FILE_ATTRIBUTE_ARCHIVE);
-       CHECK_VAL(io1.out.durable_open, true);
-       CHECK_VAL(io1.out.oplock_level, smb2_util_oplock_level("b"));
+       CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_VAL(io.out.durable_open, true);
+       CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b"));
 
-       /* disconnect, reconnect and then do durable reopen */
-       talloc_free(tree);
-       tree = NULL;
+       /*
+        * a session reconnect on a second tcp connection
+        */
 
-       if (!torture_smb2_connection(tctx, &tree)) {
-               torture_warning(tctx, "couldn't reconnect, bailing\n");
-               ret = false;
-               goto done;
-       }
+       previous_session_id = smb2cli_session_current_id(tree->session->smbXcli);
 
-       ZERO_STRUCT(io2);
-       /* the path name is ignored by the server */
-       io2.in.fname = "__non_existing_fname__";
-       io2.in.durable_handle = h;
-       h = NULL;
+       /* for oplocks, the client guid can be different: */
+       options.client_guid = GUID_random();
 
-       status = smb2_create(tree, mem_ctx, &io2);
+       ret = torture_smb2_connection_ext(tctx, previous_session_id,
+                                         &options, &tree2);
+       torture_assert_goto(tctx, ret, ret, done, "could not reconnect");
+
+       /*
+        * check that this has deleted the old session
+        */
+
+       ZERO_STRUCT(io);
+       io.in.fname = fname;
+       io.in.durable_handle = h;
+
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_USER_SESSION_DELETED);
+
+       TALLOC_FREE(tree);
+
+       /*
+        * but a durable reconnect on the new session succeeds:
+        */
+
+       ZERO_STRUCT(io);
+       io.in.fname = fname;
+       io.in.durable_handle = h;
+
+       status = smb2_create(tree2, mem_ctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
-       CHECK_CREATED(&io2, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
-       CHECK_VAL(io2.out.oplock_level, smb2_util_oplock_level("b"));
-       _h = io2.out.file.handle;
+       CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b"));
+       _h = io.out.file.handle;
+       h = &_h;
+
+       /*
+        * a session reconnect on a second tcp connection
+        */
+
+       previous_session_id = smb2cli_session_current_id(tree2->session->smbXcli);
+
+       /* the original client_guid works just the same */
+       options.client_guid = orig_client_guid;
+
+       ret = torture_smb2_connection_ext(tctx, previous_session_id,
+                                         &options, &tree3);
+       torture_assert_goto(tctx, ret, ret, done, "could not reconnect");
+
+       /*
+        * check that this has deleted the old session
+        */
+
+       ZERO_STRUCT(io);
+       io.in.fname = fname;
+       io.in.durable_handle = h;
+
+       status = smb2_create(tree2, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_USER_SESSION_DELETED);
+
+       TALLOC_FREE(tree2);
+
+       /*
+        * but a durable reconnect on the new session succeeds:
+        */
+
+       ZERO_STRUCT(io);
+       io.in.fname = fname;
+       io.in.durable_handle = h;
+
+       status = smb2_create(tree3, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
+       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);
+       if (tree == NULL) {
+               tree = tree2;
        }
 
-       smb2_util_unlink(tree, fname);
+       if (tree == NULL) {
+               tree = tree3;
+       }
 
-       talloc_free(tree);
+       if (tree != NULL) {
+               if (h != NULL) {
+                       smb2_util_close(tree, *h);
+                       h = NULL;
+               }
+               smb2_util_unlink(tree, fname);
+
+               talloc_free(tree);
+       }
 
        talloc_free(mem_ctx);
 
@@ -480,72 +569,167 @@ done:
 }
 
 /**
- * basic test for doing a durable open
- * tcp disconnect, reconnect with a session reconnect and
- * do a durable reopen (succeeds)
+ * lease variant of reopen1a
+ *
+ * Basic test for doing a durable open and doing a session
+ * reconnect while the first session is still active and the
+ * handle is still open in the client.
+ * This closes the original session and  a durable reconnect on
+ * the new session succeeds depending on the client guid:
+ *
+ * Durable reconnect on a session with a different client guid fails.
+ * Durable reconnect on a session with the original client guid succeeds.
  */
-bool test_durable_open_reopen2a(struct torture_context *tctx,
-                               struct smb2_tree *tree)
+bool test_durable_open_reopen1a_lease(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 io1, io2;
-       uint64_t previous_session_id;
+       struct smb2_create io;
+       struct smb2_lease ls;
+       uint64_t lease_key;
        bool ret = true;
+       struct smb2_tree *tree2 = NULL;
+       struct smb2_tree *tree3 = NULL;
+       uint64_t previous_session_id;
+       struct smbcli_options options;
+       struct GUID orig_client_guid;
+
+       options = tree->session->transport->options;
+       orig_client_guid = options.client_guid;
 
        /* Choose a random name in case the state is left a little funky. */
-       snprintf(fname, 256, "durable_open_reopen2_%s.dat",
+       snprintf(fname, 256, "durable_v2_open_reopen1a_lease_%s.dat",
                 generate_random_str(tctx, 8));
 
        smb2_util_unlink(tree, fname);
 
-       smb2_oplock_create_share(&io1, fname,
-                                smb2_util_share_access(""),
-                                smb2_util_oplock_level("b"));
-       io1.in.durable_open = true;
+       lease_key = random();
+       smb2_lease_create(&io, &ls, false /* dir */, fname,
+                         lease_key, smb2_util_lease_state("RWH"));
+       io.in.durable_open = true;
 
-       status = smb2_create(tree, mem_ctx, &io1);
+       status = smb2_create(tree, mem_ctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
-       _h = io1.out.file.handle;
+       _h = io.out.file.handle;
        h = &_h;
-       CHECK_CREATED(&io1, CREATED, FILE_ATTRIBUTE_ARCHIVE);
-       CHECK_VAL(io1.out.durable_open, true);
-       CHECK_VAL(io1.out.oplock_level, smb2_util_oplock_level("b"));
+       CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_VAL(io.out.durable_open, true);
+       CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE);
+       CHECK_VAL(io.out.lease_response.lease_key.data[0], lease_key);
+       CHECK_VAL(io.out.lease_response.lease_key.data[1], ~lease_key);
+       CHECK_VAL(io.out.lease_response.lease_state,
+                 smb2_util_lease_state("RWH"));
+       CHECK_VAL(io.out.lease_response.lease_flags, 0);
+       CHECK_VAL(io.out.lease_response.lease_duration, 0);
 
-       /* disconnect, reconnect and then do durable reopen */
        previous_session_id = smb2cli_session_current_id(tree->session->smbXcli);
-       talloc_free(tree);
-       tree = NULL;
 
-       if (!torture_smb2_connection_ext(tctx, previous_session_id, &tree)) {
-               torture_warning(tctx, "couldn't reconnect, bailing\n");
-               ret = false;
-               goto done;
-       }
+       /*
+        * a session reconnect on a second tcp connection
+        * with a different client_guid does not allow
+        * the durable reconnect.
+        */
 
-       ZERO_STRUCT(io2);
-       io2.in.fname = fname;
-       io2.in.durable_handle = h;
-       h = NULL;
+       options.client_guid = GUID_random();
 
-       status = smb2_create(tree, mem_ctx, &io2);
+       ret = torture_smb2_connection_ext(tctx, previous_session_id,
+                                         &options, &tree2);
+       torture_assert_goto(tctx, ret, ret, done, "couldn't reconnect");
+
+       /*
+        * check that this has deleted the old session
+        */
+
+       ZERO_STRUCT(io);
+       io.in.fname = fname;
+       io.in.durable_handle = h;
+       io.in.lease_request = &ls;
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_USER_SESSION_DELETED);
+       TALLOC_FREE(tree);
+
+
+       /*
+        * but a durable reconnect on the new session with the wrong
+        * client guid fails
+        */
+
+       ZERO_STRUCT(io);
+       io.in.fname = fname;
+       io.in.durable_handle = h;
+       io.in.lease_request = &ls;
+       status = smb2_create(tree2, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
+
+       /*
+        * now a session reconnect on a second tcp connection
+        * with original client_guid allows the durable reconnect.
+        */
+
+       options.client_guid = orig_client_guid;
+
+       ret = torture_smb2_connection_ext(tctx, previous_session_id,
+                                         &options, &tree3);
+       torture_assert_goto(tctx, ret, ret, done, "couldn't reconnect");
+
+       /*
+        * check that this has deleted the old session
+        * In this case, a durable reconnect attempt with the
+        * correct client_guid yields a different error code.
+        */
+
+       ZERO_STRUCT(io);
+       io.in.fname = fname;
+       io.in.durable_handle = h;
+       io.in.lease_request = &ls;
+       status = smb2_create(tree2, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
+       TALLOC_FREE(tree2);
+
+       /*
+        * but a durable reconnect on the new session succeeds:
+        */
+
+       ZERO_STRUCT(io);
+       io.in.fname = fname;
+       io.in.durable_handle = h;
+       io.in.lease_request = &ls;
+       status = smb2_create(tree3, mem_ctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
-       CHECK_CREATED(&io2, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
-       CHECK_VAL(io2.out.oplock_level, smb2_util_oplock_level("b"));
-       _h = io2.out.file.handle;
+       CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_VAL(io.out.durable_open, false); /* no dh response context... */
+       CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE);
+       CHECK_VAL(io.out.lease_response.lease_key.data[0], lease_key);
+       CHECK_VAL(io.out.lease_response.lease_key.data[1], ~lease_key);
+       CHECK_VAL(io.out.lease_response.lease_state,
+                 smb2_util_lease_state("RWH"));
+       CHECK_VAL(io.out.lease_response.lease_flags, 0);
+       CHECK_VAL(io.out.lease_response.lease_duration, 0);
+       _h = io.out.file.handle;
        h = &_h;
 
 done:
-       if (h != NULL) {
-               smb2_util_close(tree, *h);
+       if (tree == NULL) {
+               tree = tree2;
        }
 
-       smb2_util_unlink(tree, fname);
+       if (tree == NULL) {
+               tree = tree3;
+       }
 
-       talloc_free(tree);
+       if (tree != NULL) {
+               if (h != NULL) {
+                       smb2_util_close(tree, *h);
+               }
+
+               smb2_util_unlink(tree, fname);
+
+               talloc_free(tree);
+       }
 
        talloc_free(mem_ctx);
 
@@ -554,66 +738,761 @@ done:
 
 
 /**
- * basic test for doing a durable open:
- * tdis, new tcon, try durable reopen (fails)
+ * basic test for doing a durable open
+ * tcp disconnect, reconnect, do a durable reopen (succeeds)
  */
-bool test_durable_open_reopen3(struct torture_context *tctx,
-                              struct smb2_tree *tree)
+static bool test_durable_open_reopen2(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 io1, io2;
+       struct smb2_create io;
        bool ret = true;
-       struct smb2_tree *tree2;
 
        /* Choose a random name in case the state is left a little funky. */
-       snprintf(fname, 256, "durable_open_reopen3_%s.dat",
+       snprintf(fname, 256, "durable_open_reopen2_%s.dat",
                 generate_random_str(tctx, 8));
 
        smb2_util_unlink(tree, fname);
 
-       smb2_oplock_create_share(&io1, fname,
+       smb2_oplock_create_share(&io, fname,
                                 smb2_util_share_access(""),
                                 smb2_util_oplock_level("b"));
-       io1.in.durable_open = true;
+       io.in.durable_open = true;
 
-       status = smb2_create(tree, mem_ctx, &io1);
+       status = smb2_create(tree, mem_ctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
-       _h = io1.out.file.handle;
+       _h = io.out.file.handle;
        h = &_h;
-       CHECK_CREATED(&io1, CREATED, FILE_ATTRIBUTE_ARCHIVE);
-       CHECK_VAL(io1.out.durable_open, true);
-       CHECK_VAL(io1.out.oplock_level, smb2_util_oplock_level("b"));
+       CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_VAL(io.out.durable_open, true);
+       CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b"));
 
-       /* disconnect, reconnect and then do durable reopen */
-       status = smb2_tdis(tree);
-       CHECK_STATUS(status, NT_STATUS_OK);
+       /* disconnect, leaving the durable in place */
+       TALLOC_FREE(tree);
 
-       if (!torture_smb2_tree_connect(tctx, tree->session, mem_ctx, &tree2)) {
-               torture_warning(tctx, "couldn't reconnect to share, bailing\n");
+       if (!torture_smb2_connection(tctx, &tree)) {
+               torture_warning(tctx, "couldn't reconnect, bailing\n");
                ret = false;
                goto done;
        }
 
+       ZERO_STRUCT(io);
+       /* the path name is ignored by the server */
+       io.in.fname = fname;
+       io.in.durable_handle = h; /* durable v1 reconnect request */
+       h = NULL;
 
-       ZERO_STRUCT(io2);
-       io2.in.fname = fname;
-       io2.in.durable_handle = h;
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b"));
+       _h = io.out.file.handle;
+       h = &_h;
 
-       status = smb2_create(tree2, mem_ctx, &io2);
-       CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
+       /* disconnect again, leaving the durable in place */
+       TALLOC_FREE(tree);
 
-done:
-       if (h != NULL) {
-               smb2_util_close(tree, *h);
+       if (!torture_smb2_connection(tctx, &tree)) {
+               torture_warning(tctx, "couldn't reconnect, bailing\n");
+               ret = false;
+               goto done;
        }
 
-       smb2_util_unlink(tree2, fname);
-
-       talloc_free(tree);
+       /*
+        * show that the filename and many other fields
+        * are ignored. only the reconnect request blob
+        * is important.
+        */
+       ZERO_STRUCT(io);
+       /* the path name is ignored by the server */
+       io.in.security_flags = 0x78;
+       io.in.oplock_level = 0x78;
+       io.in.impersonation_level = 0x12345678;
+       io.in.create_flags = 0x12345678;
+       io.in.reserved = 0x12345678;
+       io.in.desired_access = 0x12345678;
+       io.in.file_attributes = 0x12345678;
+       io.in.share_access = 0x12345678;
+       io.in.create_disposition = 0x12345678;
+       io.in.create_options = 0x12345678;
+       io.in.fname = "__non_existing_fname__";
+       io.in.durable_handle = h; /* durable v1 reconnect request */
+       h = NULL;
+
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b"));
+       _h = io.out.file.handle;
+       h = &_h;
+
+       /* disconnect, leaving the durable in place */
+       TALLOC_FREE(tree);
+
+       if (!torture_smb2_connection(tctx, &tree)) {
+               torture_warning(tctx, "couldn't reconnect, bailing\n");
+               ret = false;
+               goto done;
+       }
+
+       /*
+        * show that an additionally specified durable v1 request
+        * is ignored by the server.
+        * See MS-SMB2, 3.3.5.9.7
+        * Handling the SMB2_CREATE_DURABLE_HANDLE_RECONNECT Create Context
+        */
+       ZERO_STRUCT(io);
+       /* the path name is ignored by the server */
+       io.in.fname = fname;
+       io.in.durable_handle = h;  /* durable v1 reconnect request */
+       io.in.durable_open = true; /* durable v1 handle request */
+       h = NULL;
+
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b"));
+       _h = io.out.file.handle;
+       h = &_h;
+
+done:
+       if (tree != NULL) {
+               if (h != NULL) {
+                       smb2_util_close(tree, *h);
+               }
+
+               smb2_util_unlink(tree, fname);
+
+               talloc_free(tree);
+       }
+
+       talloc_free(mem_ctx);
+
+       return ret;
+}
+
+/**
+ * lease variant of reopen2
+ * basic test for doing a durable open
+ * tcp disconnect, reconnect, do a durable reopen (succeeds)
+ */
+static bool test_durable_open_reopen2_lease(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 smb2_lease ls;
+       uint64_t lease_key;
+       bool ret = true;
+       struct smbcli_options options;
+       uint32_t caps;
+
+       caps = smb2cli_conn_server_capabilities(tree->session->transport->conn);
+       if (!(caps & SMB2_CAP_LEASING)) {
+               torture_skip(tctx, "leases are not supported");
+       }
+
+       options = tree->session->transport->options;
+
+       /* Choose a random name in case the state is left a little funky. */
+       snprintf(fname, 256, "durable_open_reopen2_%s.dat",
+                generate_random_str(tctx, 8));
+
+       smb2_util_unlink(tree, fname);
+
+       lease_key = random();
+       smb2_lease_create(&io, &ls, false /* dir */, fname, lease_key,
+                         smb2_util_lease_state("RWH"));
+       io.in.durable_open = true;
+
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       _h = io.out.file.handle;
+       h = &_h;
+       CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE);
+
+       CHECK_VAL(io.out.durable_open, true);
+       CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE);
+       CHECK_VAL(io.out.lease_response.lease_key.data[0], lease_key);
+       CHECK_VAL(io.out.lease_response.lease_key.data[1], ~lease_key);
+       CHECK_VAL(io.out.lease_response.lease_state,
+                 smb2_util_lease_state("RWH"));
+       CHECK_VAL(io.out.lease_response.lease_flags, 0);
+       CHECK_VAL(io.out.lease_response.lease_duration, 0);
+
+       /* disconnect, reconnect and then do durable reopen */
+       TALLOC_FREE(tree);
+
+       if (!torture_smb2_connection_ext(tctx, 0, &options, &tree)) {
+               torture_warning(tctx, "couldn't reconnect, bailing\n");
+               ret = false;
+               goto done;
+       }
+
+
+       /* a few failure tests: */
+
+       /*
+        * several attempts without lease attached:
+        * all fail with NT_STATUS_OBJECT_NAME_NOT_FOUND
+        * irrespective of file name provided
+        */
+
+       ZERO_STRUCT(io);
+       io.in.fname = "";
+       io.in.durable_handle = h;
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
+
+       ZERO_STRUCT(io);
+       io.in.fname = "__non_existing_fname__";
+       io.in.durable_handle = h;
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
+
+       ZERO_STRUCT(io);
+       io.in.fname = fname;
+       io.in.durable_handle = h;
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
+
+       /*
+        * attempt with lease provided, but
+        * with a changed lease key. => fails
+        */
+       ZERO_STRUCT(io);
+       io.in.fname = fname;
+       io.in.durable_open = false;
+       io.in.durable_handle = h;
+       io.in.lease_request = &ls;
+       io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE;
+       /* a wrong lease key lets the request fail */
+       ls.lease_key.data[0]++;
+
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
+
+       /* restore the correct lease key */
+       ls.lease_key.data[0]--;
+
+       /*
+        * this last failing attempt is almost correct:
+        * only problem is: we use the wrong filename...
+        * Note that this gives INVALID_PARAMETER.
+        * This is different from oplocks!
+        */
+       ZERO_STRUCT(io);
+       io.in.fname = "__non_existing_fname__";
+       io.in.durable_open = false;
+       io.in.durable_handle = h;
+       io.in.lease_request = &ls;
+       io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE;
+
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
+
+       /*
+        * Now for a succeeding reconnect:
+        */
+
+       ZERO_STRUCT(io);
+       io.in.fname = fname;
+       io.in.durable_open = false;
+       io.in.durable_handle = h;
+       io.in.lease_request = &ls;
+       io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE;
+
+       /* the requested lease state is irrelevant */
+       ls.lease_state = smb2_util_lease_state("");
+
+       h = NULL;
+
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_VAL(io.out.durable_open, false);
+       CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */
+       CHECK_VAL(io.out.persistent_open, false);
+       CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE);
+       CHECK_VAL(io.out.lease_response.lease_key.data[0], lease_key);
+       CHECK_VAL(io.out.lease_response.lease_key.data[1], ~lease_key);
+       CHECK_VAL(io.out.lease_response.lease_state,
+                 smb2_util_lease_state("RWH"));
+       CHECK_VAL(io.out.lease_response.lease_flags, 0);
+       CHECK_VAL(io.out.lease_response.lease_duration, 0);
+       _h = io.out.file.handle;
+       h = &_h;
+
+       /* disconnect one more time */
+       TALLOC_FREE(tree);
+
+       if (!torture_smb2_connection_ext(tctx, 0, &options, &tree)) {
+               torture_warning(tctx, "couldn't reconnect, bailing\n");
+               ret = false;
+               goto done;
+       }
+
+       /*
+        * demonstrate that various parameters are ignored
+        * in the reconnect
+        */
+
+       ZERO_STRUCT(io);
+       /*
+        * These are completely ignored by the server
+        */
+       io.in.security_flags = 0x78;
+       io.in.oplock_level = 0x78;
+       io.in.impersonation_level = 0x12345678;
+       io.in.create_flags = 0x12345678;
+       io.in.reserved = 0x12345678;
+       io.in.desired_access = 0x12345678;
+       io.in.file_attributes = 0x12345678;
+       io.in.share_access = 0x12345678;
+       io.in.create_disposition = 0x12345678;
+       io.in.create_options = 0x12345678;
+
+       /*
+        * only these are checked:
+        * - io.in.fname
+        * - io.in.durable_handle,
+        * - io.in.lease_request->lease_key
+        */
+
+       io.in.fname = fname;
+       io.in.durable_open_v2 = false;
+       io.in.durable_handle_v2 = h;
+       io.in.lease_request = &ls;
+
+       /* the requested lease state is irrelevant */
+       ls.lease_state = smb2_util_lease_state("");
+
+       h = NULL;
+
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_VAL(io.out.durable_open, false);
+       CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */
+       CHECK_VAL(io.out.persistent_open, false);
+       CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE);
+       CHECK_VAL(io.out.lease_response.lease_key.data[0], lease_key);
+       CHECK_VAL(io.out.lease_response.lease_key.data[1], ~lease_key);
+       CHECK_VAL(io.out.lease_response.lease_state,
+                 smb2_util_lease_state("RWH"));
+       CHECK_VAL(io.out.lease_response.lease_flags, 0);
+       CHECK_VAL(io.out.lease_response.lease_duration, 0);
+
+       _h = io.out.file.handle;
+       h = &_h;
+
+done:
+       if (tree != NULL) {
+               if (h != NULL) {
+                       smb2_util_close(tree, *h);
+               }
+
+               smb2_util_unlink(tree, fname);
+
+               talloc_free(tree);
+       }
+
+       talloc_free(mem_ctx);
+
+       return ret;
+}
+
+/**
+ * lease v2 variant of reopen2
+ * basic test for doing a durable open
+ * tcp disconnect, reconnect, do a durable reopen (succeeds)
+ */
+static bool test_durable_open_reopen2_lease_v2(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 smb2_lease ls;
+       uint64_t lease_key;
+       bool ret = true;
+       struct smbcli_options options;
+       uint32_t caps;
+
+       caps = smb2cli_conn_server_capabilities(tree->session->transport->conn);
+       if (!(caps & SMB2_CAP_LEASING)) {
+               torture_skip(tctx, "leases are not supported");
+       }
+
+       options = tree->session->transport->options;
+
+       /* Choose a random name in case the state is left a little funky. */
+       snprintf(fname, 256, "durable_open_reopen2_%s.dat",
+                generate_random_str(tctx, 8));
+
+       smb2_util_unlink(tree, fname);
+
+       lease_key = random();
+       smb2_lease_v2_create(&io, &ls, false /* dir */, fname,
+                            lease_key, 0, /* parent lease key */
+                            smb2_util_lease_state("RWH"), 0 /* lease epoch */);
+       io.in.durable_open = true;
+
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       _h = io.out.file.handle;
+       h = &_h;
+       CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE);
+
+       CHECK_VAL(io.out.durable_open, true);
+       CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE);
+       CHECK_VAL(io.out.lease_response_v2.lease_key.data[0], lease_key);
+       CHECK_VAL(io.out.lease_response_v2.lease_key.data[1], ~lease_key);
+       CHECK_VAL(io.out.lease_response_v2.lease_state,
+                 smb2_util_lease_state("RWH"));
+       CHECK_VAL(io.out.lease_response_v2.lease_flags, 0);
+       CHECK_VAL(io.out.lease_response_v2.lease_duration, 0);
+
+       /* disconnect, reconnect and then do durable reopen */
+       TALLOC_FREE(tree);
+
+       if (!torture_smb2_connection_ext(tctx, 0, &options, &tree)) {
+               torture_warning(tctx, "couldn't reconnect, bailing\n");
+               ret = false;
+               goto done;
+       }
+
+       /* a few failure tests: */
+
+       /*
+        * several attempts without lease attached:
+        * all fail with NT_STATUS_OBJECT_NAME_NOT_FOUND
+        * irrespective of file name provided
+        */
+
+       ZERO_STRUCT(io);
+       io.in.fname = "";
+       io.in.durable_handle = h;
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
+
+       ZERO_STRUCT(io);
+       io.in.fname = "__non_existing_fname__";
+       io.in.durable_handle = h;
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
+
+       ZERO_STRUCT(io);
+       io.in.fname = fname;
+       io.in.durable_handle = h;
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
+
+       /*
+        * attempt with lease provided, but
+        * with a changed lease key. => fails
+        */
+       ZERO_STRUCT(io);
+       io.in.fname = fname;
+       io.in.durable_open = false;
+       io.in.durable_handle = h;
+       io.in.lease_request_v2 = &ls;
+       io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE;
+       /* a wrong lease key lets the request fail */
+       ls.lease_key.data[0]++;
+
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
+
+       /* restore the correct lease key */
+       ls.lease_key.data[0]--;
+
+       /*
+        * this last failing attempt is almost correct:
+        * only problem is: we use the wrong filename...
+        * Note that this gives INVALID_PARAMETER.
+        * This is different from oplocks!
+        */
+       ZERO_STRUCT(io);
+       io.in.fname = "__non_existing_fname__";
+       io.in.durable_open = false;
+       io.in.durable_handle = h;
+       io.in.lease_request_v2 = &ls;
+       io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE;
+
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
+
+       /*
+        * Now for a succeeding reconnect:
+        */
+
+       ZERO_STRUCT(io);
+       io.in.fname = fname;
+       io.in.durable_open = false;
+       io.in.durable_handle = h;
+       io.in.lease_request_v2 = &ls;
+       io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE;
+
+       /* the requested lease state is irrelevant */
+       ls.lease_state = smb2_util_lease_state("");
+
+       h = NULL;
+
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_VAL(io.out.durable_open, false);
+       CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */
+       CHECK_VAL(io.out.persistent_open, false);
+       CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE);
+       CHECK_VAL(io.out.lease_response_v2.lease_key.data[0], lease_key);
+       CHECK_VAL(io.out.lease_response_v2.lease_key.data[1], ~lease_key);
+       CHECK_VAL(io.out.lease_response_v2.lease_state,
+                 smb2_util_lease_state("RWH"));
+       CHECK_VAL(io.out.lease_response_v2.lease_flags, 0);
+       CHECK_VAL(io.out.lease_response_v2.lease_duration, 0);
+       _h = io.out.file.handle;
+       h = &_h;
+
+       /* disconnect one more time */
+       TALLOC_FREE(tree);
+
+       if (!torture_smb2_connection_ext(tctx, 0, &options, &tree)) {
+               torture_warning(tctx, "couldn't reconnect, bailing\n");
+               ret = false;
+               goto done;
+       }
+
+       /*
+        * demonstrate that various parameters are ignored
+        * in the reconnect
+        */
+
+       ZERO_STRUCT(io);
+       /*
+        * These are completely ignored by the server
+        */
+       io.in.security_flags = 0x78;
+       io.in.oplock_level = 0x78;
+       io.in.impersonation_level = 0x12345678;
+       io.in.create_flags = 0x12345678;
+       io.in.reserved = 0x12345678;
+       io.in.desired_access = 0x12345678;
+       io.in.file_attributes = 0x12345678;
+       io.in.share_access = 0x12345678;
+       io.in.create_disposition = 0x12345678;
+       io.in.create_options = 0x12345678;
+
+       /*
+        * only these are checked:
+        * - io.in.fname
+        * - io.in.durable_handle,
+        * - io.in.lease_request->lease_key
+        */
+
+       io.in.fname = fname;
+       io.in.durable_open_v2 = false;
+       io.in.durable_handle_v2 = h;
+       io.in.lease_request_v2 = &ls;
+
+       /* the requested lease state is irrelevant */
+       ls.lease_state = smb2_util_lease_state("");
+
+       h = NULL;
+
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_VAL(io.out.durable_open, false);
+       CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */
+       CHECK_VAL(io.out.persistent_open, false);
+       CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE);
+       CHECK_VAL(io.out.lease_response_v2.lease_key.data[0], lease_key);
+       CHECK_VAL(io.out.lease_response_v2.lease_key.data[1], ~lease_key);
+       CHECK_VAL(io.out.lease_response_v2.lease_state,
+                 smb2_util_lease_state("RWH"));
+       CHECK_VAL(io.out.lease_response_v2.lease_flags, 0);
+       CHECK_VAL(io.out.lease_response_v2.lease_duration, 0);
+
+       _h = io.out.file.handle;
+       h = &_h;
+
+done:
+       if (tree != NULL) {
+               if (h != NULL) {
+                       smb2_util_close(tree, *h);
+               }
+
+               smb2_util_unlink(tree, fname);
+
+               talloc_free(tree);
+       }
+
+       talloc_free(mem_ctx);
+
+       return ret;
+}
+
+/**
+ * basic test for doing a durable open
+ * tcp disconnect, reconnect with a session reconnect and
+ * do a durable reopen (succeeds)
+ */
+static bool test_durable_open_reopen2a(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 io1, io2;
+       uint64_t previous_session_id;
+       bool ret = true;
+       struct smbcli_options options;
+
+       options = tree->session->transport->options;
+
+       /* Choose a random name in case the state is left a little funky. */
+       snprintf(fname, 256, "durable_open_reopen2_%s.dat",
+                generate_random_str(tctx, 8));
+
+       smb2_util_unlink(tree, fname);
+
+       smb2_oplock_create_share(&io1, fname,
+                                smb2_util_share_access(""),
+                                smb2_util_oplock_level("b"));
+       io1.in.durable_open = true;
+
+       status = smb2_create(tree, mem_ctx, &io1);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       _h = io1.out.file.handle;
+       h = &_h;
+       CHECK_CREATED(&io1, CREATED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_VAL(io1.out.durable_open, true);
+       CHECK_VAL(io1.out.oplock_level, smb2_util_oplock_level("b"));
+
+       /* disconnect, reconnect and then do durable reopen */
+       previous_session_id = smb2cli_session_current_id(tree->session->smbXcli);
+       talloc_free(tree);
+       tree = NULL;
+
+       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(io2);
+       io2.in.fname = fname;
+       io2.in.durable_handle = h;
+       h = NULL;
+
+       status = smb2_create(tree, mem_ctx, &io2);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_CREATED(&io2, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_VAL(io2.out.oplock_level, smb2_util_oplock_level("b"));
+       _h = io2.out.file.handle;
+       h = &_h;
+
+done:
+       if (tree != NULL) {
+               if (h != NULL) {
+                       smb2_util_close(tree, *h);
+               }
+
+               smb2_util_unlink(tree, fname);
+
+               talloc_free(tree);
+       }
+
+       talloc_free(mem_ctx);
+
+       return ret;
+}
+
+
+/**
+ * basic test for doing a durable open:
+ * tdis, new tcon, try durable reopen (fails)
+ */
+static bool test_durable_open_reopen3(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 io1, io2;
+       bool ret = true;
+       struct smb2_tree *tree2;
+
+       /* Choose a random name in case the state is left a little funky. */
+       snprintf(fname, 256, "durable_open_reopen3_%s.dat",
+                generate_random_str(tctx, 8));
+
+       smb2_util_unlink(tree, fname);
+
+       smb2_oplock_create_share(&io1, fname,
+                                smb2_util_share_access(""),
+                                smb2_util_oplock_level("b"));
+       io1.in.durable_open = true;
+
+       status = smb2_create(tree, mem_ctx, &io1);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       _h = io1.out.file.handle;
+       h = &_h;
+       CHECK_CREATED(&io1, CREATED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_VAL(io1.out.durable_open, true);
+       CHECK_VAL(io1.out.oplock_level, smb2_util_oplock_level("b"));
+
+       /* disconnect, reconnect and then do durable reopen */
+       status = smb2_tdis(tree);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       if (!torture_smb2_tree_connect(tctx, tree->session, mem_ctx, &tree2)) {
+               torture_warning(tctx, "couldn't reconnect to share, bailing\n");
+               ret = false;
+               goto done;
+       }
+
+
+       ZERO_STRUCT(io2);
+       io2.in.fname = fname;
+       io2.in.durable_handle = h;
+
+       status = smb2_create(tree2, mem_ctx, &io2);
+       CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
+
+done:
+       if (tree != NULL) {
+               if (h != NULL) {
+                       smb2_util_close(tree, *h);
+               }
+
+               smb2_util_unlink(tree2, fname);
+
+               talloc_free(tree);
+       }
 
        talloc_free(mem_ctx);
 
@@ -624,8 +1503,8 @@ done:
  * basic test for doing a durable open:
  * logoff, create a new session, do a durable reopen (succeeds)
  */
-bool test_durable_open_reopen4(struct torture_context *tctx,
-                              struct smb2_tree *tree)
+static bool test_durable_open_reopen4(struct torture_context *tctx,
+                                     struct smb2_tree *tree)
 {
        NTSTATUS status;
        TALLOC_CTX *mem_ctx = talloc_new(tctx);
@@ -648,7 +1527,6 @@ bool test_durable_open_reopen4(struct torture_context *tctx,
                                 smb2_util_share_access(""),
                                 smb2_util_oplock_level("b"));
        io1.in.durable_open = true;
-       io1.in.create_options |= NTCREATEX_OPTIONS_DELETE_ON_CLOSE;
 
        status = smb2_create(tree, mem_ctx, &io1);
        CHECK_STATUS(status, NT_STATUS_OK);
@@ -701,33 +1579,32 @@ bool test_durable_open_reopen4(struct torture_context *tctx,
        CHECK_VAL(io2.out.oplock_level, smb2_util_oplock_level("b"));
 
 done:
-       if (h != NULL) {
-               smb2_util_close(tree2, *h);
-       }
+       if (tree != NULL) {
+               if (h != NULL) {
+                       smb2_util_close(tree2, *h);
+               }
 
-       smb2_util_unlink(tree2, fname);
+               smb2_util_unlink(tree2, fname);
 
-       talloc_free(tree);
+               talloc_free(tree);
+       }
 
        talloc_free(mem_ctx);
 
        return ret;
 }
 
-bool test_durable_open_delete_on_close1(struct torture_context *tctx,
-                                       struct smb2_tree *tree)
+static bool test_durable_open_delete_on_close1(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 io1, io2, io3;
+       struct smb2_create io1, io2;
        bool ret = true;
-       struct smb2_transport *transport;
-       struct smb2_session *session2;
-       struct smb2_tree *tree2;
-       union smb_fileinfo info1, info2;
+       uint8_t b = 0;
 
        /* Choose a random name in case the state is left a little funky. */
        snprintf(fname, 256, "durable_open_delete_on_close1_%s.dat",
@@ -749,80 +1626,163 @@ bool test_durable_open_delete_on_close1(struct torture_context *tctx,
        CHECK_VAL(io1.out.durable_open, true);
        CHECK_VAL(io1.out.oplock_level, smb2_util_oplock_level("b"));
 
-       ZERO_STRUCT(info1);
-       info1.internal_information.level = RAW_FILEINFO_INTERNAL_INFORMATION;
-       info1.internal_information.in.file.handle = _h;
-       status = smb2_getinfo_file(tree, tree, &info1);
+       status = smb2_util_write(tree, *h, &b, 0, 1);
        CHECK_STATUS(status, NT_STATUS_OK);
 
-       /*
-        * do a session logoff, establish a new session and tree
-        * connect on the same transport, and try a durable reopen
-        */
-       transport = tree->session->transport;
-       status = smb2_logoff(tree->session);
-       CHECK_STATUS(status, NT_STATUS_OK);
+       /* disconnect, leaving the durable handle in place */
+       TALLOC_FREE(tree);
 
-       if (!torture_smb2_session_setup(tctx, transport,
-                                       0, /* previous_session_id */
-                                       mem_ctx, &session2))
-       {
-               torture_warning(tctx, "session setup failed.\n");
+       if (!torture_smb2_connection(tctx, &tree)) {
+               torture_warning(tctx, "could not reconnect, bailing\n");
                ret = false;
                goto done;
        }
 
        /*
-        * the session setup has talloc-stolen the transport,
-        * so we can safely free the old tree+session for clarity
+        * Open the file on the new connection again
+        * and check that it has been newly created,
+        * i.e. delete on close was effective on the disconnected handle.
+        * Also check that the file is really empty,
+        * the previously written byte gone.
         */
-       TALLOC_FREE(tree);
-
-       if (!torture_smb2_tree_connect(tctx, session2, mem_ctx, &tree2)) {
-               torture_warning(tctx, "tree connect failed.\n");
-               ret = false;
-               goto done;
-       }
-
-       ZERO_STRUCT(io3);
-       io3.in.fname = fname;
-       io3.in.durable_handle = h;
-       h = NULL;
-
        smb2_oplock_create_share(&io2, fname,
                                 smb2_util_share_access(""),
                                 smb2_util_oplock_level("b"));
        io2.in.create_options |= NTCREATEX_OPTIONS_DELETE_ON_CLOSE;
 
-       status = smb2_create(tree2, mem_ctx, &io2);
+       status = smb2_create(tree, mem_ctx, &io2);
        CHECK_STATUS(status, NT_STATUS_OK);
        _h = io2.out.file.handle;
        h = &_h;
-       CHECK_CREATED(&io2, CREATED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_CREATED_SIZE(&io2, CREATED, FILE_ATTRIBUTE_ARCHIVE, 0, 0);
        CHECK_VAL(io2.out.durable_open, false);
        CHECK_VAL(io2.out.oplock_level, smb2_util_oplock_level("b"));
 
-       ZERO_STRUCT(info2);
-       info2.internal_information.level = RAW_FILEINFO_INTERNAL_INFORMATION;
-       info2.internal_information.in.file.handle = _h;
-       status = smb2_getinfo_file(tree2, tree2, &info2);
+done:
+       if (tree != NULL) {
+               if (h != NULL) {
+                       smb2_util_close(tree, *h);
+               }
+
+               smb2_util_unlink(tree, fname);
+
+               talloc_free(tree);
+       }
+
+       talloc_free(mem_ctx);
+
+       return ret;
+}
+
+
+static bool test_durable_open_delete_on_close2(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;
+       bool ret = true;
+       uint8_t b = 0;
+       uint64_t previous_session_id;
+       uint64_t alloc_size_step;
+       struct smbcli_options options;
+
+       options = tree->session->transport->options;
+
+       /* Choose a random name in case the state is left a little funky. */
+       snprintf(fname, 256, "durable_open_delete_on_close2_%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 = true;
+       io.in.create_options |= NTCREATEX_OPTIONS_DELETE_ON_CLOSE;
+
+       status = smb2_create(tree, mem_ctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
+       _h = io.out.file.handle;
+       h = &_h;
+       CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_VAL(io.out.durable_open, true);
+       CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b"));
 
-       CHECK_NOT_VAL(info1.internal_information.out.file_id,
-                     info2.internal_information.out.file_id);
+       status = smb2_util_write(tree, *h, &b, 0, 1);
+       CHECK_STATUS(status, NT_STATUS_OK);
 
-       status = smb2_create(tree2, mem_ctx, &io3);
-       CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
+       previous_session_id = smb2cli_session_current_id(tree->session->smbXcli);
 
-done:
-       if (h != NULL) {
-               smb2_util_close(tree2, *h);
+       /* disconnect, leaving the durable handle in place */
+       TALLOC_FREE(tree);
+
+       if (!torture_smb2_connection_ext(tctx, previous_session_id,
+                                        &options, &tree))
+       {
+               torture_warning(tctx, "could not reconnect, bailing\n");
+               ret = false;
+               goto done;
        }
 
-       smb2_util_unlink(tree2, fname);
+       ZERO_STRUCT(io);
+       io.in.fname = fname;
+       io.in.durable_handle = h;
 
-       talloc_free(tree);
-       talloc_free(tree2);
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       _h = io.out.file.handle;
+       h = &_h;
+       alloc_size_step = io.out.alloc_size;
+       CHECK_CREATED_SIZE(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE, alloc_size_step, 1);
+       CHECK_VAL(io.out.durable_open, false);
+       CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b"));
+
+       /* close the file, thereby deleting it */
+       smb2_util_close(tree, *h);
+       status = smb2_logoff(tree->session);
+       TALLOC_FREE(tree);
+
+       if (!torture_smb2_connection(tctx, &tree)) {
+               torture_warning(tctx, "could not reconnect, bailing\n");
+               ret = false;
+               goto done;
+       }
+
+       /*
+        * Open the file on the new connection again
+        * and check that it has been newly created,
+        * i.e. delete on close was effective on the reconnected handle.
+        * Also check that the file is really empty,
+        * the previously written byte gone.
+        */
+       smb2_oplock_create_share(&io, fname,
+                                smb2_util_share_access(""),
+                                smb2_util_oplock_level("b"));
+       io.in.durable_open = true;
+       io.in.create_options |= NTCREATEX_OPTIONS_DELETE_ON_CLOSE;
+
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       _h = io.out.file.handle;
+       h = &_h;
+       CHECK_CREATED_SIZE(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE, 0, 0);
+       CHECK_VAL(io.out.durable_open, true);
+       CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b"));
+
+done:
+       if (tree != NULL) {
+               if (h != NULL) {
+                       smb2_util_close(tree, *h);
+               }
+
+               smb2_util_unlink(tree, fname);
+
+               talloc_free(tree);
+       }
 
        talloc_free(mem_ctx);
 
@@ -833,38 +1793,41 @@ done:
    basic testing of SMB2 durable opens
    regarding the position information on the handle
 */
-bool test_durable_open_file_position(struct torture_context *tctx,
-                                    struct smb2_tree *tree1,
-                                    struct smb2_tree *tree2)
+static bool test_durable_open_file_position(struct torture_context *tctx,
+                                           struct smb2_tree *tree)
 {
        TALLOC_CTX *mem_ctx = talloc_new(tctx);
-       struct smb2_handle h1, h2;
-       struct smb2_create io1, io2;
+       struct smb2_handle h;
+       struct smb2_create io;
        NTSTATUS status;
        const char *fname = "durable_open_position.dat";
        union smb_fileinfo qfinfo;
        union smb_setfileinfo sfinfo;
        bool ret = true;
        uint64_t pos;
+       uint64_t previous_session_id;
+       struct smbcli_options options;
 
-       smb2_util_unlink(tree1, fname);
+       options = tree->session->transport->options;
 
-       smb2_oplock_create(&io1, fname, SMB2_OPLOCK_LEVEL_BATCH);
-       io1.in.durable_open = true;
+       smb2_util_unlink(tree, fname);
 
-       status = smb2_create(tree1, mem_ctx, &io1);
+       smb2_oplock_create(&io, fname, SMB2_OPLOCK_LEVEL_BATCH);
+       io.in.durable_open = true;
+
+       status = smb2_create(tree, mem_ctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
-       h1 = io1.out.file.handle;
-       CHECK_CREATED(&io1, CREATED, FILE_ATTRIBUTE_ARCHIVE);
-       CHECK_VAL(io1.out.durable_open, true);
-       CHECK_VAL(io1.out.oplock_level, SMB2_OPLOCK_LEVEL_BATCH);
+       h = io.out.file.handle;
+       CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_VAL(io.out.durable_open, true);
+       CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_BATCH);
 
        /* TODO: check extra blob content */
 
        ZERO_STRUCT(qfinfo);
        qfinfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
-       qfinfo.generic.in.file.handle = h1;
-       status = smb2_getinfo_file(tree1, mem_ctx, &qfinfo);
+       qfinfo.generic.in.file.handle = h;
+       status = smb2_getinfo_file(tree, mem_ctx, &qfinfo);
        CHECK_STATUS(status, NT_STATUS_OK);
        CHECK_VAL(qfinfo.position_information.out.position, 0);
        pos = qfinfo.position_information.out.position;
@@ -873,64 +1836,76 @@ bool test_durable_open_file_position(struct torture_context *tctx,
 
        ZERO_STRUCT(sfinfo);
        sfinfo.generic.level = RAW_SFILEINFO_POSITION_INFORMATION;
-       sfinfo.generic.in.file.handle = h1;
+       sfinfo.generic.in.file.handle = h;
        sfinfo.position_information.in.position = 0x1000;
-       status = smb2_setinfo_file(tree1, &sfinfo);
+       status = smb2_setinfo_file(tree, &sfinfo);
        CHECK_STATUS(status, NT_STATUS_OK);
 
        ZERO_STRUCT(qfinfo);
        qfinfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
-       qfinfo.generic.in.file.handle = h1;
-       status = smb2_getinfo_file(tree1, mem_ctx, &qfinfo);
+       qfinfo.generic.in.file.handle = h;
+       status = smb2_getinfo_file(tree, mem_ctx, &qfinfo);
        CHECK_STATUS(status, NT_STATUS_OK);
        CHECK_VAL(qfinfo.position_information.out.position, 0x1000);
        pos = qfinfo.position_information.out.position;
        torture_comment(tctx, "position: %llu\n",
                        (unsigned long long)pos);
 
-       talloc_free(tree1);
-       tree1 = NULL;
+       previous_session_id = smb2cli_session_current_id(tree->session->smbXcli);
+
+       /* tcp disconnect */
+       talloc_free(tree);
+       tree = NULL;
+
+       /* do a session reconnect */
+       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(qfinfo);
        qfinfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
-       qfinfo.generic.in.file.handle = h1;
-       status = smb2_getinfo_file(tree2, mem_ctx, &qfinfo);
+       qfinfo.generic.in.file.handle = h;
+       status = smb2_getinfo_file(tree, mem_ctx, &qfinfo);
        CHECK_STATUS(status, NT_STATUS_FILE_CLOSED);
 
-       ZERO_STRUCT(io2);
-       io2.in.fname = fname;
-       io2.in.durable_handle = &h1;
+       ZERO_STRUCT(io);
+       io.in.fname = fname;
+       io.in.durable_handle = &h;
 
-       status = smb2_create(tree2, mem_ctx, &io2);
+       status = smb2_create(tree, mem_ctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
-       CHECK_VAL(io2.out.oplock_level, SMB2_OPLOCK_LEVEL_BATCH);
-       CHECK_VAL(io2.out.reserved, 0x00);
-       CHECK_VAL(io2.out.create_action, NTCREATEX_ACTION_EXISTED);
-       CHECK_VAL(io2.out.alloc_size, 0);
-       CHECK_VAL(io2.out.size, 0);
-       CHECK_VAL(io2.out.file_attr, FILE_ATTRIBUTE_ARCHIVE);
-       CHECK_VAL(io2.out.reserved2, 0);
+       CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_BATCH);
+       CHECK_VAL(io.out.reserved, 0x00);
+       CHECK_VAL(io.out.create_action, NTCREATEX_ACTION_EXISTED);
+       CHECK_VAL(io.out.alloc_size, 0);
+       CHECK_VAL(io.out.size, 0);
+       CHECK_VAL(io.out.file_attr, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_VAL(io.out.reserved2, 0);
 
-       h2 = io2.out.file.handle;
+       h = io.out.file.handle;
 
        ZERO_STRUCT(qfinfo);
        qfinfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
-       qfinfo.generic.in.file.handle = h2;
-       status = smb2_getinfo_file(tree2, mem_ctx, &qfinfo);
+       qfinfo.generic.in.file.handle = h;
+       status = smb2_getinfo_file(tree, mem_ctx, &qfinfo);
        CHECK_STATUS(status, NT_STATUS_OK);
        CHECK_VAL(qfinfo.position_information.out.position, 0x1000);
        pos = qfinfo.position_information.out.position;
        torture_comment(tctx, "position: %llu\n",
                        (unsigned long long)pos);
 
-       smb2_util_close(tree2, h2);
+       smb2_util_close(tree, h);
 
        talloc_free(mem_ctx);
 
-       smb2_util_unlink(tree2, fname);
+       smb2_util_unlink(tree, fname);
+
 done:
-       talloc_free(tree1);
-       talloc_free(tree2);
+       talloc_free(tree);
 
        return ret;
 }
@@ -938,13 +1913,14 @@ done:
 /*
   Open, disconnect, oplock break, reconnect.
 */
-bool test_durable_open_oplock(struct torture_context *tctx,
-                             struct smb2_tree *tree1,
-                             struct smb2_tree *tree2)
+static bool test_durable_open_oplock(struct torture_context *tctx,
+                                    struct smb2_tree *tree1,
+                                    struct smb2_tree *tree2)
 {
        TALLOC_CTX *mem_ctx = talloc_new(tctx);
        struct smb2_create io1, io2;
-       struct smb2_handle h1, h2;
+       struct smb2_handle h1 = {{0}};
+       struct smb2_handle h2 = {{0}};
        NTSTATUS status;
        char fname[256];
        bool ret = true;
@@ -1012,14 +1988,15 @@ bool test_durable_open_oplock(struct torture_context *tctx,
 /*
   Open, disconnect, lease break, reconnect.
 */
-bool test_durable_open_lease(struct torture_context *tctx,
-                            struct smb2_tree *tree1,
-                            struct smb2_tree *tree2)
+static bool test_durable_open_lease(struct torture_context *tctx,
+                                   struct smb2_tree *tree1,
+                                   struct smb2_tree *tree2)
 {
        TALLOC_CTX *mem_ctx = talloc_new(tctx);
        struct smb2_create io1, io2;
        struct smb2_lease ls1, ls2;
-       struct smb2_handle h1, h2;
+       struct smb2_handle h1 = {{0}};
+       struct smb2_handle h2 = {{0}};
        NTSTATUS status;
        char fname[256];
        bool ret = true;
@@ -1113,12 +2090,12 @@ bool test_durable_open_lease(struct torture_context *tctx,
        return ret;
 }
 
-bool test_durable_open_lock_oplock(struct torture_context *tctx,
-                                  struct smb2_tree *tree)
+static bool test_durable_open_lock_oplock(struct torture_context *tctx,
+                                         struct smb2_tree *tree)
 {
        TALLOC_CTX *mem_ctx = talloc_new(tctx);
        struct smb2_create io;
-       struct smb2_handle h;
+       struct smb2_handle h = {{0}};
        struct smb2_lock lck;
        struct smb2_lock_element el[2];
        NTSTATUS status;
@@ -1132,7 +2109,7 @@ bool test_durable_open_lock_oplock(struct torture_context *tctx,
        /* Clean slate */
        smb2_util_unlink(tree, fname);
 
-       /* Create with lease */
+       /* Create with oplock */
 
        smb2_oplock_create_share(&io, fname,
                                 smb2_util_share_access(""),
@@ -1194,13 +2171,13 @@ bool test_durable_open_lock_oplock(struct torture_context *tctx,
 /*
   Open, take BRL, disconnect, reconnect.
 */
-bool test_durable_open_lock_lease(struct torture_context *tctx,
-                                 struct smb2_tree *tree)
+static bool test_durable_open_lock_lease(struct torture_context *tctx,
+                                        struct smb2_tree *tree)
 {
        TALLOC_CTX *mem_ctx = talloc_new(tctx);
        struct smb2_create io;
        struct smb2_lease ls;
-       struct smb2_handle h;
+       struct smb2_handle h = {{0}};
        struct smb2_lock lck;
        struct smb2_lock_element el[2];
        NTSTATUS status;
@@ -1208,6 +2185,9 @@ bool test_durable_open_lock_lease(struct torture_context *tctx,
        bool ret = true;
        uint64_t lease;
        uint32_t caps;
+       struct smbcli_options options;
+
+       options = tree->session->transport->options;
 
        caps = smb2cli_conn_server_capabilities(tree->session->transport->conn);
        if (!(caps & SMB2_CAP_LEASING)) {
@@ -1259,7 +2239,7 @@ bool test_durable_open_lock_lease(struct torture_context *tctx,
        talloc_free(tree);
        tree = NULL;
 
-       if (!torture_smb2_connection(tctx, &tree)) {
+       if (!torture_smb2_connection_ext(tctx, 0, &options, &tree)) {
                torture_warning(tctx, "couldn't reconnect, bailing\n");
                ret = false;
                goto done;
@@ -1295,19 +2275,23 @@ bool test_durable_open_lock_lease(struct torture_context *tctx,
  * reconnect after an open, the oplock/lease tests above will certainly
  * demonstrate an error on reconnect.
  */
-bool test_durable_open_open2_lease(struct torture_context *tctx,
-                                 struct smb2_tree *tree1,
-                                 struct smb2_tree *tree2)
+static bool test_durable_open_open2_lease(struct torture_context *tctx,
+                                         struct smb2_tree *tree1,
+                                         struct smb2_tree *tree2)
 {
        TALLOC_CTX *mem_ctx = talloc_new(tctx);
        struct smb2_create io1, io2;
        struct smb2_lease ls;
-       struct smb2_handle h1, h2;
+       struct smb2_handle h1 = {{0}};
+       struct smb2_handle h2 = {{0}};
        NTSTATUS status;
        char fname[256];
        bool ret = true;
        uint64_t lease;
        uint32_t caps;
+       struct smbcli_options options;
+
+       options = tree1->session->transport->options;
 
        caps = smb2cli_conn_server_capabilities(tree1->session->transport->conn);
        if (!(caps & SMB2_CAP_LEASING)) {
@@ -1354,10 +2338,10 @@ bool test_durable_open_open2_lease(struct torture_context *tctx,
        status = smb2_create(tree2, mem_ctx, &io2);
        CHECK_STATUS(status, NT_STATUS_OK);
        h2 = io2.out.file.handle;
-       CHECK_CREATED(&io1, CREATED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_CREATED(&io2, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
 
        /* Reconnect */
-       if (!torture_smb2_connection(tctx, &tree1)) {
+       if (!torture_smb2_connection_ext(tctx, 0, &options, &tree1)) {
                torture_warning(tctx, "couldn't reconnect, bailing\n");
                ret = false;
                goto done;
@@ -1378,12 +2362,14 @@ bool test_durable_open_open2_lease(struct torture_context *tctx,
        h1 = io1.out.file.handle;
 
  done:
+       if (tree1 != NULL){
+               smb2_util_close(tree1, h1);
+               smb2_util_unlink(tree1, fname);
+               talloc_free(tree1);
+       }
+
        smb2_util_close(tree2, h2);
        smb2_util_unlink(tree2, fname);
-       smb2_util_close(tree1, h1);
-       smb2_util_unlink(tree1, fname);
-
-       talloc_free(tree1);
        talloc_free(tree2);
 
        return ret;
@@ -1397,13 +2383,14 @@ bool test_durable_open_open2_lease(struct torture_context *tctx,
  * reconnect after an open, the oplock/lease tests above will certainly
  * demonstrate an error on reconnect.
  */
-bool test_durable_open_open2_oplock(struct torture_context *tctx,
-                                   struct smb2_tree *tree1,
-                                   struct smb2_tree *tree2)
+static bool test_durable_open_open2_oplock(struct torture_context *tctx,
+                                          struct smb2_tree *tree1,
+                                          struct smb2_tree *tree2)
 {
        TALLOC_CTX *mem_ctx = talloc_new(tctx);
        struct smb2_create io1, io2;
-       struct smb2_handle h1, h2;
+       struct smb2_handle h1 = {{0}};
+       struct smb2_handle h2 = {{0}};
        NTSTATUS status;
        char fname[256];
        bool ret = true;
@@ -1459,8 +2446,10 @@ bool test_durable_open_open2_oplock(struct torture_context *tctx,
  done:
        smb2_util_close(tree2, h2);
        smb2_util_unlink(tree2, fname);
-       smb2_util_close(tree1, h1);
-       smb2_util_unlink(tree1, fname);
+       if (tree1 != NULL) {
+               smb2_util_close(tree1, h1);
+               smb2_util_unlink(tree1, fname);
+       }
 
        talloc_free(tree1);
        talloc_free(tree2);
@@ -1471,8 +2460,8 @@ bool test_durable_open_open2_oplock(struct torture_context *tctx,
 /**
  * test behaviour with initial allocation size
  */
-bool test_durable_open_alloc_size(struct torture_context *tctx,
-                                 struct smb2_tree *tree)
+static bool test_durable_open_alloc_size(struct torture_context *tctx,
+                                        struct smb2_tree *tree)
 {
        NTSTATUS status;
        TALLOC_CTX *mem_ctx = talloc_new(tctx);
@@ -1485,9 +2474,12 @@ bool test_durable_open_alloc_size(struct torture_context *tctx,
        uint64_t alloc_size_step;
        uint64_t initial_alloc_size = 0x100;
        const uint8_t *b = NULL;
+       struct smbcli_options options;
+
+       options = tree->session->transport->options;
 
        /* Choose a random name in case the state is left a little funky. */
-       snprintf(fname, 256, "durable_open_initial_alloc_%s.dat",
+       snprintf(fname, 256, "durable_open_alloc_size_%s.dat",
                 generate_random_str(tctx, 8));
 
        smb2_util_unlink(tree, fname);
@@ -1511,7 +2503,7 @@ bool test_durable_open_alloc_size(struct torture_context *tctx,
 
        /* prepare buffer */
        b = talloc_zero_size(mem_ctx, alloc_size_step);
-       CHECK_NOT_VAL(b, NULL);
+       CHECK_NOT_NULL(b);
 
        previous_session_id = smb2cli_session_current_id(tree->session->smbXcli);
 
@@ -1519,7 +2511,9 @@ bool test_durable_open_alloc_size(struct torture_context *tctx,
        talloc_free(tree);
        tree = NULL;
 
-       if (!torture_smb2_connection_ext(tctx, previous_session_id, &tree)) {
+       if (!torture_smb2_connection_ext(tctx, previous_session_id,
+                                        &options, &tree))
+       {
                torture_warning(tctx, "couldn't reconnect, bailing\n");
                ret = false;
                goto done;
@@ -1548,7 +2542,9 @@ bool test_durable_open_alloc_size(struct torture_context *tctx,
        talloc_free(tree);
        tree = NULL;
 
-       if (!torture_smb2_connection_ext(tctx, previous_session_id, &tree)) {
+       if (!torture_smb2_connection_ext(tctx, previous_session_id,
+                                        &options, &tree))
+       {
                torture_warning(tctx, "couldn't reconnect, bailing\n");
                ret = false;
                goto done;
@@ -1576,7 +2572,9 @@ bool test_durable_open_alloc_size(struct torture_context *tctx,
        talloc_free(tree);
        tree = NULL;
 
-       if (!torture_smb2_connection_ext(tctx, previous_session_id, &tree)) {
+       if (!torture_smb2_connection_ext(tctx, previous_session_id,
+                                        &options, &tree))
+       {
                torture_warning(tctx, "couldn't reconnect, bailing\n");
                ret = false;
                goto done;
@@ -1609,22 +2607,573 @@ done:
        return ret;
 }
 
+/**
+ * test behaviour when a disconnect happens while creating a read-only file
+ */
+static bool test_durable_open_read_only(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;
+       bool ret = true;
+       uint64_t previous_session_id;
+       const uint8_t b = 0;
+       uint64_t alloc_size = 0;
+       struct smbcli_options options;
+
+       options = tree->session->transport->options;
+
+       /* Choose a random name in case the state is left a little funky. */
+       snprintf(fname, 256, "durable_open_initial_alloc_%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 = true;
+       io.in.file_attributes = FILE_ATTRIBUTE_READONLY;
+
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       _h = io.out.file.handle;
+       h = &_h;
+       CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_VAL(io.out.durable_open, true);
+       CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b"));
+
+       previous_session_id = smb2cli_session_current_id(tree->session->smbXcli);
+
+       /* write one byte */
+       status = smb2_util_write(tree, *h, &b, 0, 1);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       /* disconnect, reconnect and then do durable reopen */
+       talloc_free(tree);
+       tree = NULL;
+
+       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_handle = h;
+       h = NULL;
+
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       alloc_size = io.out.alloc_size;
+       CHECK_CREATED_SIZE(&io, EXISTED,
+                          FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_ARCHIVE,
+                          alloc_size, 1);
+       CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("b"));
+       _h = io.out.file.handle;
+       h = &_h;
+
+       /* write one byte */
+       status = smb2_util_write(tree, *h, &b, 1, 1);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+done:
+       if (h != NULL) {
+               union smb_setfileinfo sfinfo;
+
+               ZERO_STRUCT(sfinfo);
+               sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFORMATION;
+               sfinfo.basic_info.in.file.handle = *h;
+               sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_NORMAL;
+               smb2_setinfo_file(tree, &sfinfo);
+
+               smb2_util_close(tree, *h);
+       }
+
+       smb2_util_unlink(tree, fname);
+
+       talloc_free(tree);
+
+       talloc_free(mem_ctx);
+
+       return ret;
+}
+
+/**
+ * durable open with oplock, disconnect, exit
+ */
+static bool test_durable_open_oplock_disconnect(struct torture_context *tctx,
+                                               struct smb2_tree *tree)
+{
+       TALLOC_CTX *mem_ctx = talloc_new(tctx);
+       struct smb2_create io;
+       struct smb2_handle _h;
+       struct smb2_handle *h = NULL;
+       NTSTATUS status;
+       char fname[256];
+       bool ret = true;
+
+       snprintf(fname, 256, "durable_open_oplock_disconnect_%s.dat",
+                generate_random_str(mem_ctx, 8));
+
+       smb2_util_unlink(tree, fname);
+
+       smb2_oplock_create(&io, fname, SMB2_OPLOCK_LEVEL_BATCH);
+       io.in.durable_open = true;
+
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       _h = io.out.file.handle;
+       h = &_h;
+
+       CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_VAL(io.out.durable_open, true);
+       CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_BATCH);
+
+       /* disconnect */
+       talloc_free(tree);
+       tree = NULL;
+
+done:
+       if (tree != NULL) {
+               if (h != NULL) {
+                       smb2_util_close(tree, *h);
+               }
+               smb2_util_unlink(tree, fname);
+       }
+       talloc_free(mem_ctx);
+       return ret;
+}
+
+#define COMPARE_TIME_CMP(given, gelem, correct, celem, cmp) do { \
+       const uint64_t _r = 10*1000*1000; \
+       NTTIME _g = (given).basic_info.out.gelem; \
+       NTTIME _gr = (_g / _r) * _r; \
+       NTTIME _c = (correct).basic_info.out.celem; \
+       NTTIME _cr = (_c / _r) * _r; \
+       bool _strict = torture_setting_bool(tctx, "strict mode", false); \
+       const char *_err = NULL; \
+       if (_strict && (_g cmp _c)) { \
+               _err = "strict"; \
+       } else if ((_g cmp _c) && (_gr cmp _cr)) { \
+               /* handle filesystem without high resolution timestamps */ \
+               _err = "rounded"; \
+       } \
+       if (_err != NULL) { \
+               struct timeval _gtv; \
+               struct timeval _ctv; \
+               struct timeval_buf _gtvb; \
+               struct timeval_buf _ctvb; \
+               nttime_to_timeval(&_gtv, _g); \
+               nttime_to_timeval(&_ctv, _c); \
+               torture_result(tctx, TORTURE_FAIL, \
+                              __location__": %s wrong (%s.%s)%s %s (%s.%s)%s", \
+                              _err, \
+                              #given, #gelem, \
+                              timeval_str_buf(&_gtv, false, true, &_gtvb), \
+                              #cmp, \
+                              #correct, #celem, \
+                              timeval_str_buf(&_ctv, false, true, &_ctvb)); \
+               ret = false; \
+               goto done; \
+       } \
+} while (0)
+#define COMPARE_WRITE_TIME_CMP(given, correct, cmp) do { \
+       COMPARE_TIME_CMP(given, write_time, correct, write_time, cmp); \
+} while (0)
+#define COMPARE_WRITE_TIME_EQUAL(given,correct) \
+       COMPARE_WRITE_TIME_CMP(given,correct,!=)
+#define COMPARE_WRITE_TIME_GREATER(given,correct) \
+       COMPARE_WRITE_TIME_CMP(given,correct,<=)
+
+#define COMPARE_ACCESS_TIME_CMP(given, correct, cmp) do { \
+       COMPARE_TIME_CMP(given, access_time, correct, access_time, cmp); \
+} while (0)
+#define COMPARE_ACCESS_TIME_EQUAL(given,correct) \
+       COMPARE_ACCESS_TIME_CMP(given,correct,!=)
+#define COMPARE_ACCESS_TIME_GREATER(given,correct) \
+       COMPARE_ACCESS_TIME_CMP(given,correct,<=)
+
+#define COMPARE_CHANGE_TIME_CMP(given, correct, cmp) do { \
+       COMPARE_TIME_CMP(given, change_time, correct, change_time, cmp); \
+} while (0)
+#define COMPARE_CHANGE_TIME_EQUAL(given,correct) \
+       COMPARE_CHANGE_TIME_CMP(given,correct,!=)
+#define COMPARE_CHANGE_TIME_GREATER(given,correct) \
+       COMPARE_CHANGE_TIME_CMP(given,correct,<=)
+
+#define COMPARE_CREATE_TIME_CMP(given, correct, cmp) do { \
+       COMPARE_TIME_CMP(given, create_time, correct, create_time, cmp); \
+} while (0)
+#define COMPARE_CREATE_TIME_EQUAL(given,correct) \
+       COMPARE_CREATE_TIME_CMP(given,correct,!=)
+
+#define COMPARE_ALL_TIMES_EQUAL(given,correct) do { \
+       COMPARE_WRITE_TIME_EQUAL(given,correct); \
+       COMPARE_CHANGE_TIME_EQUAL(given,correct); \
+       COMPARE_ACCESS_TIME_EQUAL(given,correct); \
+       COMPARE_CREATE_TIME_EQUAL(given,correct); \
+} while (0)
+
+#define COMPARE_TIMES_AFTER_WRITE(given,correct) do { \
+       COMPARE_WRITE_TIME_GREATER(given,correct); \
+       COMPARE_CHANGE_TIME_GREATER(given,correct); \
+       COMPARE_ACCESS_TIME_EQUAL(given,correct); \
+       COMPARE_CREATE_TIME_EQUAL(given,correct); \
+       COMPARE_TIME_CMP(given, change_time, given, write_time, !=); \
+} while (0)
+
+#define COMPARE_TIMES_AFTER_CLOSE(given,correct) do { \
+       COMPARE_WRITE_TIME_GREATER(given,correct); \
+       COMPARE_CHANGE_TIME_GREATER(given,correct); \
+       COMPARE_ACCESS_TIME_GREATER(given,correct); \
+       COMPARE_CREATE_TIME_EQUAL(given,correct); \
+       COMPARE_TIME_CMP(given, change_time, given, write_time, !=); \
+       COMPARE_TIME_CMP(given, access_time, given, write_time, !=); \
+} while (0)
+
+#define GET_INFO_FILE(tree, finfo) do { \
+       struct timeval _atv; \
+       struct timeval _wtv; \
+       struct timeval_buf _atvb; \
+       struct timeval_buf _wtvb; \
+       NTSTATUS _status; \
+       _status = smb2_getinfo_file(tree, tctx, &finfo); \
+       if (!NT_STATUS_IS_OK(_status)) { \
+               ret = false; \
+               torture_result(tctx, TORTURE_FAIL, __location__": fileinfo failed: %s", \
+                              nt_errstr(_status)); \
+               goto done; \
+       } \
+       nttime_to_timeval(&_atv, finfo.basic_info.out.access_time); \
+       nttime_to_timeval(&_wtv, finfo.basic_info.out.write_time); \
+       torture_comment(tctx, "fileinfo(%s,%s): Access(%s) Write(%s)\n", \
+                       #tree, #finfo, \
+                       timeval_str_buf(&_atv, false, true, &_atvb), \
+                       timeval_str_buf(&_wtv, false, true, &_wtvb)); \
+} while (0)
+
+#define GET_INFO_BOTH(finfo1, finfo2) do { \
+       GET_INFO_FILE(tree2, finfo2); \
+       GET_INFO_FILE(tree1, finfo1); \
+       COMPARE_ALL_TIMES_EQUAL(finfo1, finfo2); \
+} while (0)
+
+#define SET_INFO_FILE_EX(finfo, wrtime, tree, tfnum) do { \
+       NTSTATUS _status; \
+       union smb_setfileinfo sfinfo; \
+       sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFO; \
+       sfinfo.basic_info.in.file.fnum = tfnum; \
+       sfinfo.basic_info.in.create_time = 0; \
+       sfinfo.basic_info.in.access_time = 0; \
+       unix_to_nt_time(&sfinfo.basic_info.in.write_time, (wrtime)); \
+       sfinfo.basic_info.in.change_time = 0; \
+       sfinfo.basic_info.in.attrib = finfo1.basic_info.out.attrib; \
+       _status = smb_raw_setfileinfo(tree, &sfinfo); \
+       if (!NT_STATUS_IS_OK(_status)) { \
+               torture_result(tctx, TORTURE_FAIL, __location__": setfileinfo failed: %s", \
+                              nt_errstr(_status)); \
+               ret = false; \
+               goto done; \
+       } \
+} while (0)
+#define SET_INFO_FILE(finfo, wrtime) \
+       SET_INFO_FILE_EX(finfo, wrtime, cli->tree, fnum1)
+
+#define SET_INFO_FILE_NS(finfo, wrtime, ns, tree, tfnum) do { \
+       NTSTATUS _status; \
+       union smb_setfileinfo sfinfo; \
+       sfinfo.basic_info.level = RAW_SFILEINFO_BASIC_INFO; \
+       sfinfo.basic_info.in.file.fnum = tfnum; \
+       sfinfo.basic_info.in.create_time = 0; \
+       sfinfo.basic_info.in.access_time = 0; \
+       unix_to_nt_time(&sfinfo.basic_info.in.write_time, (wrtime)); \
+       sfinfo.basic_info.in.write_time += (ns); \
+       sfinfo.basic_info.in.change_time = 0; \
+       sfinfo.basic_info.in.attrib = finfo1.basic_info.out.attrib; \
+       _status = smb_raw_setfileinfo(tree, &sfinfo); \
+       if (!NT_STATUS_IS_OK(_status)) { \
+               torture_result(tctx, TORTURE_FAIL, __location__": setfileinfo failed: %s", \
+                              nt_errstr(_status)); \
+               ret = false; \
+               goto done; \
+       } \
+} while (0)
+
+struct test_durable_open_delaywrite1_state {
+       struct torture_context *tctx;
+       struct smb2_tree *tree1;
+       struct smb2_tree *tree2;
+       struct smb2_handle *h1;
+       struct smb2_handle *h2;
+};
+
+static bool test_durable_open_delaywrite1_get_info(void *private_data,
+                                                  union smb_fileinfo *finfo)
+{
+       struct test_durable_open_delaywrite1_state *state =
+               (struct test_durable_open_delaywrite1_state *)private_data;
+       struct torture_context *tctx = state->tctx;
+       union smb_fileinfo t1finfo;
+       union smb_fileinfo t2finfo;
+       bool ret = true;
+
+       ZERO_STRUCTP(finfo);
+
+       ZERO_STRUCT(t1finfo);
+       t1finfo.basic_info.level = RAW_FILEINFO_BASIC_INFORMATION;
+       t1finfo.basic_info.in.file.handle = *state->h1;
+
+       ZERO_STRUCT(t2finfo);
+       t2finfo.basic_info.level = RAW_FILEINFO_BASIC_INFORMATION;
+       t2finfo.basic_info.in.file.handle = *state->h2;
+
+       GET_INFO_FILE(state->tree2, t2finfo);
+       GET_INFO_FILE(state->tree1, t1finfo);
+       if (t1finfo.basic_info.out.write_time != t2finfo.basic_info.out.write_time) {
+               /*
+                * There was a race, get it again on handle 2,
+                * but then they have to match.
+                */
+               GET_INFO_FILE(state->tree2, t2finfo);
+       }
+       COMPARE_ALL_TIMES_EQUAL(t1finfo, t2finfo);
+
+       finfo->basic_info.out = t1finfo.basic_info.out;
+done:
+       return ret;
+}
+
+static bool test_durable_open_delaywrite1_write_data(void *private_data)
+{
+       struct test_durable_open_delaywrite1_state *state =
+               (struct test_durable_open_delaywrite1_state *)private_data;
+       struct torture_context *tctx = state->tctx;
+       struct smb2_write wr;
+       NTSTATUS status;
+       bool ret = true;
+
+       ZERO_STRUCT(wr);
+       wr.in.file.handle = *state->h1;
+       wr.in.offset      = 0;
+       wr.in.data        = data_blob_const("x", 1);
+       status = smb2_write(state->tree1, &wr);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       torture_assert_int_equal_goto(tctx, wr.out.nwritten, 1,
+                                     ret, done, "smb2_write");
+
+done:
+       return ret;
+}
+
+static bool test_durable_open_delaywrite1_close(void *private_data,
+                                               union smb_fileinfo *finfo)
+{
+       struct test_durable_open_delaywrite1_state *state =
+               (struct test_durable_open_delaywrite1_state *)private_data;
+       struct torture_context *tctx = state->tctx;
+       union smb_fileinfo t1finfoCL;
+       union smb_fileinfo t2finfoCL;
+       struct smb2_close cl1;
+       struct smb2_close cl2;
+       union smb_fileinfo t2finfo;
+       NTSTATUS status;
+       bool ret = true;
+
+       ZERO_STRUCTP(finfo);
+
+       ZERO_STRUCT(cl1);
+       cl1.in.file.handle = *state->h1;
+       cl1.in.flags = SMB2_CLOSE_FLAGS_FULL_INFORMATION;
+       status = smb2_close(state->tree1, &cl1);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       state->h1 = NULL;
+       ZERO_STRUCT(t1finfoCL);
+       t1finfoCL.basic_info.out.create_time = cl1.out.create_time;
+       t1finfoCL.basic_info.out.access_time = cl1.out.access_time;
+       t1finfoCL.basic_info.out.write_time = cl1.out.write_time;
+       t1finfoCL.basic_info.out.change_time = cl1.out.change_time;
+       t1finfoCL.basic_info.out.attrib = cl1.out.file_attr;
+
+       ZERO_STRUCT(t2finfo);
+       t2finfo.basic_info.level = RAW_FILEINFO_BASIC_INFORMATION;
+       t2finfo.basic_info.in.file.handle = *state->h2;
+
+       GET_INFO_FILE(state->tree2, t2finfo);
+       COMPARE_ALL_TIMES_EQUAL(t2finfo, t1finfoCL);
+
+       ZERO_STRUCT(cl2);
+       cl2.in.file.handle = *state->h2;
+       cl2.in.flags = SMB2_CLOSE_FLAGS_FULL_INFORMATION;
+       status = smb2_close(state->tree2, &cl2);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       state->h2 = NULL;
+       ZERO_STRUCT(t2finfoCL);
+       t2finfoCL.basic_info.out.create_time = cl2.out.create_time;
+       t2finfoCL.basic_info.out.access_time = cl2.out.access_time;
+       t2finfoCL.basic_info.out.write_time = cl2.out.write_time;
+       t2finfoCL.basic_info.out.change_time = cl2.out.change_time;
+       t2finfoCL.basic_info.out.attrib = cl2.out.file_attr;
+       COMPARE_ALL_TIMES_EQUAL(t2finfoCL, t1finfoCL);
+
+       finfo->basic_info.out = t1finfoCL.basic_info.out;
+
+done:
+       return ret;
+}
+
+static bool test_durable_open_delaywrite1(struct torture_context *tctx,
+                                         struct smb2_tree *tree1,
+                                         struct smb2_tree *tree2)
+{
+       struct test_durable_open_delaywrite1_state state = {
+               .tctx = tctx,
+               .tree1 = tree1,
+               .tree2 = tree2,
+       };
+       NTSTATUS status;
+       TALLOC_CTX *mem_ctx = talloc_new(tctx);
+       char fname[256];
+       struct smb2_handle _h1;
+       struct smb2_handle _h2;
+       struct smb2_create cr1;
+       struct smb2_create cr2;
+       union smb_fileinfo c1finfoCR, c1finfo0;
+       union smb_fileinfo c2finfoCR, c2finfo0;
+       //double used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000);
+       //double used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 1000000);
+       double normal_delay = 1000000;
+       double used_delay = torture_setting_int(tctx, "writetimeupdatedelay", normal_delay);
+       //double normal_delay = 1000000;
+       //int normal_delay = 2000000;
+       bool ret = true;
+       bool ok;
+
+       /* Choose a random name in case the state is left a little funky. */
+       snprintf(fname, 256, "durable_open_delaywrite1_%s.dat",
+                generate_random_str(tctx, 8));
+
+       smb2_util_unlink(tree1, fname);
+
+       smb2_oplock_create_share(&cr1, fname,
+                                smb2_util_share_access(""),
+                                smb2_util_oplock_level("b"));
+       cr1.in.durable_open = true;
+
+       status = smb2_create(tree1, mem_ctx, &cr1);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       _h1 = cr1.out.file.handle;
+       state.h1 = &_h1;
+       CHECK_CREATED(&cr1, CREATED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_VAL(cr1.out.oplock_level, smb2_util_oplock_level("b"));
+       CHECK_VAL(cr1.out.durable_open, true);
+       CHECK_VAL(cr1.out.durable_open_v2, false);
+       CHECK_VAL(cr1.out.persistent_open, false);
+
+       cr2 = cr1;
+       cr2.in.desired_access = SEC_FILE_READ_ATTRIBUTE;
+       cr2.in.durable_open = false;
+       cr2.in.oplock_level = 0;
+       cr2.in.create_disposition = NTCREATEX_DISP_OPEN;
+       status = smb2_create(tree2, mem_ctx, &cr2);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       _h2 = cr2.out.file.handle;
+       state.h2 = &_h2;
+       CHECK_CREATED(&cr2, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_VAL(cr2.out.oplock_level, 0);
+       CHECK_VAL(cr2.out.durable_open, false);
+       CHECK_VAL(cr2.out.durable_open_v2, false);
+       CHECK_VAL(cr2.out.persistent_open, false);
+
+       ZERO_STRUCT(c1finfoCR);
+       c1finfoCR.basic_info.out.create_time = cr1.out.create_time;
+       c1finfoCR.basic_info.out.access_time = cr1.out.access_time;
+       c1finfoCR.basic_info.out.write_time = cr1.out.write_time;
+       c1finfoCR.basic_info.out.change_time = cr1.out.change_time;
+       c1finfoCR.basic_info.out.attrib = cr1.out.file_attr;
+
+       ZERO_STRUCT(c2finfoCR);
+       c2finfoCR.basic_info.out.create_time = cr2.out.create_time;
+       c2finfoCR.basic_info.out.access_time = cr2.out.access_time;
+       c2finfoCR.basic_info.out.write_time = cr2.out.write_time;
+       c2finfoCR.basic_info.out.change_time = cr2.out.change_time;
+       c2finfoCR.basic_info.out.attrib = cr2.out.file_attr;
+
+       COMPARE_ALL_TIMES_EQUAL(c1finfoCR, c2finfoCR);
+
+       ZERO_STRUCT(c1finfo0);
+       c1finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFORMATION;
+       c1finfo0.basic_info.in.file.handle = *state.h1;
+
+       ZERO_STRUCT(c2finfo0);
+       c2finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFORMATION;
+       c2finfo0.basic_info.in.file.handle = *state.h2;
+
+       GET_INFO_BOTH(c1finfo0, c2finfo0);
+       COMPARE_ALL_TIMES_EQUAL(c1finfo0, c1finfoCR);
+
+       ok = test_delay_writetime1(tctx, used_delay, normal_delay,
+                       "run1",
+                       test_durable_open_delaywrite1_get_info,
+                       test_durable_open_delaywrite1_write_data,
+                       NULL, /* close_cb */
+                       &state);
+       torture_assert_goto(tctx, ok, ret, done, "test_delay_writetime1(1)");
+       ok = test_delay_writetime1(tctx, used_delay, normal_delay,
+                       "run2",
+                       test_durable_open_delaywrite1_get_info,
+                       test_durable_open_delaywrite1_write_data,
+                       test_durable_open_delaywrite1_close,
+                       &state);
+       torture_assert_goto(tctx, ok, ret, done, "test_delay_writetime1(2)");
+
+done:
+       if (state.h1 != NULL) {
+               smb2_util_close(tree1, *state.h1);
+       }
+       if (state.h2 != NULL) {
+               smb2_util_close(tree2, *state.h2);
+       }
+
+       smb2_util_unlink(tree1, fname);
 
-struct torture_suite *torture_smb2_durable_open_init(void)
+       talloc_free(tree1);
+       talloc_free(tree2);
+
+       talloc_free(mem_ctx);
+
+       return ret;
+}
+
+struct torture_suite *torture_smb2_durable_open_init(TALLOC_CTX *ctx)
 {
        struct torture_suite *suite =
-           torture_suite_create(talloc_autofree_context(), "durable-open");
+           torture_suite_create(ctx, "durable-open");
 
        torture_suite_add_1smb2_test(suite, "open-oplock", test_durable_open_open_oplock);
        torture_suite_add_1smb2_test(suite, "open-lease", test_durable_open_open_lease);
        torture_suite_add_1smb2_test(suite, "reopen1", test_durable_open_reopen1);
+       torture_suite_add_1smb2_test(suite, "reopen1a", test_durable_open_reopen1a);
+       torture_suite_add_1smb2_test(suite, "reopen1a-lease", test_durable_open_reopen1a_lease);
        torture_suite_add_1smb2_test(suite, "reopen2", test_durable_open_reopen2);
+       torture_suite_add_1smb2_test(suite, "reopen2-lease", test_durable_open_reopen2_lease);
+       torture_suite_add_1smb2_test(suite, "reopen2-lease-v2", test_durable_open_reopen2_lease_v2);
        torture_suite_add_1smb2_test(suite, "reopen2a", test_durable_open_reopen2a);
        torture_suite_add_1smb2_test(suite, "reopen3", test_durable_open_reopen3);
        torture_suite_add_1smb2_test(suite, "reopen4", test_durable_open_reopen4);
        torture_suite_add_1smb2_test(suite, "delete_on_close1",
                                     test_durable_open_delete_on_close1);
-       torture_suite_add_2smb2_test(suite, "file-position",
+       torture_suite_add_1smb2_test(suite, "delete_on_close2",
+                                    test_durable_open_delete_on_close2);
+       torture_suite_add_1smb2_test(suite, "file-position",
            test_durable_open_file_position);
        torture_suite_add_2smb2_test(suite, "oplock", test_durable_open_oplock);
        torture_suite_add_2smb2_test(suite, "lease", test_durable_open_lease);
@@ -1636,8 +3185,27 @@ struct torture_suite *torture_smb2_durable_open_init(void)
                                     test_durable_open_open2_oplock);
        torture_suite_add_1smb2_test(suite, "alloc-size",
                                     test_durable_open_alloc_size);
+       torture_suite_add_1smb2_test(suite, "read-only",
+                                    test_durable_open_read_only);
+       torture_suite_add_2smb2_test(suite, "delaywrite1",
+                                    test_durable_open_delaywrite1);
 
        suite->description = talloc_strdup(suite, "SMB2-DURABLE-OPEN tests");
 
        return suite;
 }
+
+struct torture_suite *torture_smb2_durable_open_disconnect_init(TALLOC_CTX *ctx)
+{
+       struct torture_suite *suite =
+           torture_suite_create(ctx,
+                                "durable-open-disconnect");
+
+       torture_suite_add_1smb2_test(suite, "open-oplock-disconnect",
+                                    test_durable_open_oplock_disconnect);
+
+       suite->description = talloc_strdup(suite,
+                                       "SMB2-DURABLE-OPEN-DISCONNECT tests");
+
+       return suite;
+}