resilient
authorStefan Metzmacher <metze@samba.org>
Fri, 9 Dec 2011 10:06:41 +0000 (11:06 +0100)
committerStefan Metzmacher <metze@samba.org>
Thu, 10 May 2012 16:47:09 +0000 (18:47 +0200)
source4/torture/smb2/resilient_open.c

index a093f899ae1bfee94648804a22aa4e05e70d482d..f55820e2b10c4ba403a02f8758860f092547b1a6 100644 (file)
@@ -24,6 +24,7 @@
 #include "libcli/smb2/smb2_calls.h"
 #include "torture/torture.h"
 #include "torture/smb2/proto.h"
+#include "../libcli/smb/smbXcli_base.h"
 
 #define CHECK_VAL(v, correct) do { \
        if ((v) != (correct)) { \
@@ -95,15 +96,98 @@ static inline uint32_t map_sharemode(const char *sharemode)
 }
 
 /**
- * basic durable_open test.
- * durable state should only be granted when requested
- * along with a batch oplock or a handle lease.
- *
- * This test tests durable open with all possible oplock types.
+ * basic resilient_open test.
  */
 
 bool test_resilient_open_open1(struct torture_context *tctx,
-                              struct smb2_tree *tree)
+                              struct smb2_tree *tree,
+                              struct smb2_tree *tree2)
+{
+       TALLOC_CTX *mem_ctx = talloc_new(tctx);
+       struct smb2_create cr;
+       struct smb2_ioctl io;
+       char fname[256];
+       bool ret = true;
+       int i;
+       NTSTATUS status;
+       struct smb2_handle _h;
+       struct smb2_handle *h = NULL;
+       struct smb2_tree *t = NULL;
+       uint8_t resiliency[8];
+
+       /* Choose a random name in case the state is left a little funky. */
+       snprintf(fname, 256, "resilient_open_open1_%s.dat",
+                generate_random_str(tctx, 8));
+
+       smb2_util_unlink(tree, fname);
+
+       ZERO_STRUCT(cr);
+       cr.in.security_flags            = 0x00;
+       cr.in.impersonation_level       = NTCREATEX_IMPERSONATION_IMPERSONATION;
+       cr.in.create_flags              = 0x00000000;
+       cr.in.reserved                  = 0x00000000;
+       cr.in.desired_access            = SEC_RIGHTS_FILE_ALL;
+       cr.in.file_attributes           = FILE_ATTRIBUTE_NORMAL;
+       cr.in.create_disposition        = NTCREATEX_DISP_OPEN_IF;
+       cr.in.create_options            = NTCREATEX_OPTIONS_SEQUENTIAL_ONLY |
+                                         NTCREATEX_OPTIONS_ASYNC_ALERT |
+                                         NTCREATEX_OPTIONS_NON_DIRECTORY_FILE |
+                                         NTCREATEX_OPTIONS_REPARSE_POINT |
+0;//                                     NTCREATEX_OPTIONS_DELETE_ON_CLOSE;
+       cr.in.durable_open              = false;
+       cr.in.fname                     = fname;
+       cr.in.share_access              = map_sharemode("");
+       cr.in.oplock_level              = SMB2_OPLOCK_LEVEL_NONE;
+
+       status = smb2_create(tree, mem_ctx, &cr);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       _h = cr.out.file.handle;
+       h = &_h;
+       CHECK_CREATED(&cr, CREATED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_VAL(cr.out.durable_open, false);
+       CHECK_VAL(cr.out.oplock_level, SMB2_OPLOCK_LEVEL_NONE);
+
+       SIVAL(resiliency, 0, 10*1000);
+       SIVAL(resiliency, 4, 0);
+
+       ZERO_STRUCT(io);
+       io.level = RAW_IOCTL_SMB2;
+       io.in.file.handle = *h;
+       io.in.function = FSCTL_LMR_REQ_RESILIENCY;
+       io.in.max_response_size = 0;
+       io.in.flags = SMB2_IOCTL_FLAG_IS_FSCTL;
+       io.in.in = data_blob_const(resiliency, ARRAY_SIZE(resiliency));
+       io.in.out = data_blob_const(resiliency, ARRAY_SIZE(resiliency));
+
+       status = smb2_ioctl(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       smbXcli_conn_disconnect(tree->session->transport->conn, NT_STATUS_OK);
+
+       smb_msleep(5*1000);
+       status = smb2_create(tree2, mem_ctx, &cr);
+       CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
+
+       smb_msleep(10*1000);
+       status = smb2_create(tree2, mem_ctx, &cr);
+       CHECK_STATUS(status, NT_STATUS_OK);
+done:
+       if (h != NULL) {
+               smb2_util_close(tree, *h);
+       }
+       smb2_util_unlink(tree, fname);
+       talloc_free(mem_ctx);
+
+       return ret;
+}
+
+/**
+ * basic resilient_open test.
+ */
+
+bool test_resilient_open_open2(struct torture_context *tctx,
+                              struct smb2_tree *tree,
+                              struct smb2_tree *tree2)
 {
        TALLOC_CTX *mem_ctx = talloc_new(tctx);
        struct smb2_create cr;
@@ -134,15 +218,16 @@ bool test_resilient_open_open1(struct torture_context *tctx,
        cr.in.reserved                  = 0x00000000;
        cr.in.desired_access            = SEC_RIGHTS_FILE_ALL;
        cr.in.file_attributes           = FILE_ATTRIBUTE_NORMAL;
-       cr.in.create_disposition        = NTCREATEX_DISP_CREATE;
+       //cr.in.create_disposition      = NTCREATEX_DISP_CREATE;
+       cr.in.create_disposition        = NTCREATEX_DISP_OPEN_IF;
        cr.in.create_options            = NTCREATEX_OPTIONS_SEQUENTIAL_ONLY |
                                          NTCREATEX_OPTIONS_ASYNC_ALERT |
                                          NTCREATEX_OPTIONS_NON_DIRECTORY_FILE |
                                          0x00200000 |
-                                         NTCREATEX_OPTIONS_DELETE_ON_CLOSE;
+0;//                                     NTCREATEX_OPTIONS_DELETE_ON_CLOSE;
        cr.in.durable_open              = false;
        cr.in.fname                     = fname;
-       cr.in.share_access              = map_sharemode("RWD");
+       cr.in.share_access              = map_sharemode("");
        cr.in.oplock_level              = SMB2_OPLOCK_LEVEL_LEASE;
        cr.in.lease_request             = &ls;
 
@@ -153,8 +238,13 @@ bool test_resilient_open_open1(struct torture_context *tctx,
        CHECK_CREATED(&cr, CREATED, FILE_ATTRIBUTE_ARCHIVE);
        CHECK_VAL(cr.out.durable_open, false);
        CHECK_VAL(cr.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE);
+       CHECK_VAL(cr.out.lease_response.lease_state, ls.lease_state);
+       CHECK_VAL(cr.out.lease_response.lease_flags, ls.lease_flags);
+       CHECK_VAL(cr.out.lease_response.lease_duration, ls.lease_duration);
+       CHECK_VAL(cr.out.lease_response.lease_key.data[0], ls.lease_key.data[0]);
+       CHECK_VAL(cr.out.lease_response.lease_key.data[1], ls.lease_key.data[1]);
 
-       SIVAL(resiliency, 0, 60*1000);
+       SIVAL(resiliency, 0, 10*1000);
        SIVAL(resiliency, 4, 0);
 
        ZERO_STRUCT(io);
@@ -169,6 +259,18 @@ bool test_resilient_open_open1(struct torture_context *tctx,
        status = smb2_ioctl(tree, mem_ctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
 
+       //smbXcli_conn_disconnect(tree->session->transport->conn, NT_STATUS_OK);
+
+       smb_msleep(5*1000);
+       memset(&ls.lease_key, 0xfe, sizeof(ls.lease_key));
+       status = smb2_create(tree2, mem_ctx, &cr);
+       CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
+
+       smb_msleep(10*1000);
+       memset(&ls.lease_key, 0xef, sizeof(ls.lease_key));
+       ls.lease_state = 0;
+       status = smb2_create(tree2, mem_ctx, &cr);
+       CHECK_STATUS(status, NT_STATUS_OK);
 done:
        if (h != NULL) {
                smb2_util_close(tree, *h);
@@ -183,7 +285,8 @@ struct torture_suite *torture_smb2_resilient_open_init(void)
        struct torture_suite *suite =
            torture_suite_create(talloc_autofree_context(), "resilient-open");
 
-       torture_suite_add_1smb2_test(suite, "open1", test_resilient_open_open1);
+       torture_suite_add_2smb2_test(suite, "open1", test_resilient_open_open1);
+       torture_suite_add_2smb2_test(suite, "open2", test_resilient_open_open2);
 
        suite->description = talloc_strdup(suite, "SMB2-RESILIENT-OPEN tests");