resilient NT_STATUS_OK 9ca9b44c58d96ef2691fd0935a859ea373117d70
authorStefan Metzmacher <metze@samba.org>
Tue, 8 Nov 2011 13:36:16 +0000 (14:36 +0100)
committerStefan Metzmacher <metze@samba.org>
Thu, 10 May 2012 16:47:07 +0000 (18:47 +0200)
source4/torture/smb2/resilient_open.c [new file with mode: 0644]
source4/torture/smb2/smb2.c
source4/torture/smb2/wscript_build

diff --git a/source4/torture/smb2/resilient_open.c b/source4/torture/smb2/resilient_open.c
new file mode 100644 (file)
index 0000000..a8c2562
--- /dev/null
@@ -0,0 +1,191 @@
+/*
+   Unix SMB/CIFS implementation.
+
+   test suite for SMB2 resilient opens
+
+   Copyright (C) Stefan Metzmacher 2008
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "libcli/smb2/smb2.h"
+#include "libcli/smb2/smb2_calls.h"
+#include "torture/torture.h"
+#include "torture/smb2/proto.h"
+
+#define CHECK_VAL(v, correct) do { \
+       if ((v) != (correct)) { \
+               torture_result(tctx, TORTURE_FAIL, "(%s): wrong value for %s got 0x%x - should be 0x%x\n", \
+                               __location__, #v, (int)v, (int)correct); \
+               ret = false; \
+       }} while (0)
+
+#define CHECK_STATUS(status, correct) do { \
+       if (!NT_STATUS_EQUAL(status, correct)) { \
+               torture_result(tctx, TORTURE_FAIL, __location__": Incorrect status %s - should be %s", \
+                      nt_errstr(status), nt_errstr(correct)); \
+               ret = false; \
+               goto done; \
+       }} while (0)
+
+#define CHECK_CREATED(__io, __created, __attribute)                    \
+       do {                                                            \
+               CHECK_VAL((__io)->out.create_action, NTCREATEX_ACTION_ ## __created); \
+               CHECK_VAL((__io)->out.alloc_size, 0);                   \
+               CHECK_VAL((__io)->out.size, 0);                         \
+               CHECK_VAL((__io)->out.file_attr, (__attribute));        \
+               CHECK_VAL((__io)->out.reserved2, 0);                    \
+       } while(0)
+
+
+static inline uint32_t map_lease(const char *ls)
+{
+       uint32_t val = 0;
+       int i;
+
+       for (i = 0; i < strlen(ls); i++) {
+               switch (ls[i]) {
+               case 'R':
+                       val |= SMB2_LEASE_READ;
+                       break;
+               case 'H':
+                       val |= SMB2_LEASE_HANDLE;
+                       break;
+               case 'W':
+                       val |= SMB2_LEASE_WRITE;
+                       break;
+               }
+       }
+
+       return val;
+}
+
+static inline uint32_t map_sharemode(const char *sharemode)
+{
+       uint32_t val = NTCREATEX_SHARE_ACCESS_NONE; /* 0 */
+       int i;
+
+       for (i = 0; i < strlen(sharemode); i++) {
+               switch(sharemode[i]) {
+               case 'R':
+                       val |= NTCREATEX_SHARE_ACCESS_READ;
+                       break;
+               case 'W':
+                       val |= NTCREATEX_SHARE_ACCESS_WRITE;
+                       break;
+               case 'D':
+                       val |= NTCREATEX_SHARE_ACCESS_DELETE;
+                       break;
+               }
+       }
+
+       return val;
+}
+
+/**
+ * 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.
+ */
+
+bool test_resilient_open_open1(struct torture_context *tctx,
+                              struct smb2_tree *tree)
+{
+       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;
+       uint8_t resiliency[8];
+       struct smb2_lease ls;
+
+       /* 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(ls);
+       memset(&ls.lease_key, 0xef, sizeof(ls.lease_key));
+       ls.lease_state = SMB2_LEASE_READ|SMB2_LEASE_WRITE|SMB2_LEASE_HANDLE;
+
+       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_CREATE;
+       cr.in.create_options            = NTCREATEX_OPTIONS_SEQUENTIAL_ONLY |
+                                         NTCREATEX_OPTIONS_ASYNC_ALERT |
+                                         NTCREATEX_OPTIONS_NON_DIRECTORY_FILE |
+                                         0x00200000 |
+                                         NTCREATEX_OPTIONS_DELETE_ON_CLOSE;
+       cr.in.durable_open              = true;
+       cr.in.fname                     = fname;
+       cr.in.share_access              = map_sharemode("RWD");
+       cr.in.oplock_level              = SMB2_OPLOCK_LEVEL_LEASE;
+       cr.in.lease_request             = &ls;
+
+       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, true);
+       CHECK_VAL(cr.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE);
+
+       SIVAL(resiliency, 0, 60*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);
+
+done:
+       if (h != NULL) {
+               smb2_util_close(tree, *h);
+       }
+       talloc_free(mem_ctx);
+
+       return ret;
+}
+
+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);
+
+       suite->description = talloc_strdup(suite, "SMB2-RESILIENT-OPEN tests");
+
+       return suite;
+}
index 9ea71b463efee10238d06f2824f8163c6c61adf8..6198ec79210f00ab048fe10f746cf8bd8973cb89 100644 (file)
@@ -150,6 +150,7 @@ NTSTATUS torture_smb2_init(void)
        torture_suite_add_suite(suite, torture_smb2_notify_init());
        torture_suite_add_suite(suite, torture_smb2_durable_open_init());
        torture_suite_add_suite(suite, torture_smb2_durable_v2_open_init());
+       torture_suite_add_suite(suite, torture_smb2_resilient_open_init());
        torture_suite_add_suite(suite, torture_smb2_dir_init());
        torture_suite_add_suite(suite, torture_smb2_lease_init());
        torture_suite_add_suite(suite, torture_smb2_compound_init());
index d60c5d2ddb4eabed5e95578fe52af6d12e74c293..b8818f6f74ff4ddb8bb658a1627adbe4fa020001 100644 (file)
@@ -1,10 +1,10 @@
 #!/usr/bin/env python
 
 bld.SAMBA_MODULE('TORTURE_SMB2',
-       source='''connect.c scan.c util.c getinfo.c setinfo.c lock.c notify.c
-       smb2.c durable_open.c durable_v2_open.c oplock.c dir.c lease.c create.c
-       acls.c read.c compound.c streams.c ioctl.c rename.c
-       session.c ''',
+        source='''connect.c scan.c util.c getinfo.c setinfo.c lock.c notify.c
+        smb2.c durable_open.c durable_v2_open.c resilient_open.c oplock.c dir.c
+        lease.c create.c acls.c read.c compound.c streams.c ioctl.c rename.c
+        session.c ''',
        subsystem='smbtorture',
        deps='LIBCLI_SMB2 POPT_CREDENTIALS torture NDR_IOCTL',
        internal_module=True,