The branch, master has been updated
       via  33c6907 selftest: S3 does not do leases yet
       via  d496ccd s4:torture/smb2: add v2 lease requests
       via  3c9846c s4:torture/smb2: add smb2_lease_v2_create_share() helper
       via  6c81893 s4:libcli/smb2: add support for SMB2 LEASES v2
       via  f367d07 libcli/smb: add SMB2_LEASE_FLAG_* defines
       via  1bfc7e8 s4:torture/smb2: add NTCREATEX_SHARE_ACCESS_DELETE in 
smb2_generic_create_share()
      from  87685b3 s4:torture:smb2 delete temp memory context in 
test_durable_open_oplock_disconnect

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 33c690746b0bd0e24da6d07f926a3139a5e48099
Author: Volker Lendecke <[email protected]>
Date:   Wed Apr 17 17:19:59 2013 +0200

    selftest: S3 does not do leases yet
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Stefan Metzmacher <[email protected]>
    
    Autobuild-User(master): Volker Lendecke <[email protected]>
    Autobuild-Date(master): Thu Apr 18 16:59:39 CEST 2013 on sn-devel-104

commit d496ccdb905c3897bcacef7f4d56010eb523c965
Author: Stefan Metzmacher <[email protected]>
Date:   Wed Oct 31 09:07:19 2012 +0100

    s4:torture/smb2: add v2 lease requests
    
    Signed-off-by: Stefan Metzmacher <[email protected]>
    Reviewed-by: Volker Lendecke <[email protected]>

commit 3c9846cafde28fb8d40ae81cafb03f2e2ec8d9e2
Author: Stefan Metzmacher <[email protected]>
Date:   Wed Oct 31 09:06:48 2012 +0100

    s4:torture/smb2: add smb2_lease_v2_create_share() helper
    
    Signed-off-by: Stefan Metzmacher <[email protected]>
    Reviewed-by: Volker Lendecke <[email protected]>

commit 6c81893b342786d5f63aaa89e855e9378def50c3
Author: Stefan Metzmacher <[email protected]>
Date:   Wed Oct 31 08:37:13 2012 +0100

    s4:libcli/smb2: add support for SMB2 LEASES v2
    
    Signed-off-by: Stefan Metzmacher <[email protected]>
    Reviewed-by: Volker Lendecke <[email protected]>

commit f367d07f521b26cfb5813dd679a4e4883b69752f
Author: Stefan Metzmacher <[email protected]>
Date:   Wed Oct 31 08:19:52 2012 +0100

    libcli/smb: add SMB2_LEASE_FLAG_* defines
    
    Signed-off-by: Stefan Metzmacher <[email protected]>
    Reviewed-by: Volker Lendecke <[email protected]>

commit 1bfc7e863e76124c287228b772c331bc5c9f8616
Author: Stefan Metzmacher <[email protected]>
Date:   Thu Nov 1 16:20:35 2012 +0100

    s4:torture/smb2: add NTCREATEX_SHARE_ACCESS_DELETE in 
smb2_generic_create_share()
    
    Signed-off-by: Stefan Metzmacher <[email protected]>
    Reviewed-by: Volker Lendecke <[email protected]>

-----------------------------------------------------------------------

Summary of changes:
 libcli/smb/smb2_constants.h     |    4 +
 selftest/knownfail              |    1 +
 source4/libcli/raw/interfaces.h |    7 +-
 source4/libcli/smb2/create.c    |   48 ++++++++-
 source4/torture/smb2/lease.c    |  210 ++++++++++++++++++++++++++++++++++++++-
 source4/torture/smb2/util.c     |   29 +++++-
 6 files changed, 291 insertions(+), 8 deletions(-)


Changeset truncated at 500 lines:

diff --git a/libcli/smb/smb2_constants.h b/libcli/smb/smb2_constants.h
index 22fe23a..60fedbb 100644
--- a/libcli/smb/smb2_constants.h
+++ b/libcli/smb/smb2_constants.h
@@ -183,6 +183,10 @@
 #define SMB2_LEASE_HANDLE                                0x02
 #define SMB2_LEASE_WRITE                                 0x04
 
+/* SMB2 lease flags */
+#define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS                0x00000002
+#define SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET             0x00000004
+
 /* SMB2 lease break flags */
 #define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED        0x01
 
diff --git a/selftest/knownfail b/selftest/knownfail
index 61a0a0e..0c96eee 100644
--- a/selftest/knownfail
+++ b/selftest/knownfail
@@ -184,6 +184,7 @@
 ^samba3.smb2.lease.break
 ^samba3.smb2.lease.oplock
 ^samba3.smb2.lease.multibreak
+^samba3.smb2.lease.v2_request
 ^samba3.smb2.oplock.batch12
 ^samba3.smb2.oplock.batch20
 ^samba3.smb2.oplock.stream1
diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h
index c13475b..fb73f26 100644
--- a/source4/libcli/raw/interfaces.h
+++ b/source4/libcli/raw/interfaces.h
@@ -64,8 +64,11 @@ struct smb2_lease_key {
 struct smb2_lease {
        struct smb2_lease_key lease_key;
        uint32_t lease_state;
-       uint32_t lease_flags; /* should be 0 */
+       uint32_t lease_flags;
        uint64_t lease_duration; /* should be 0 */
+       /* only for v2 */
+       struct smb2_lease_key parent_lease_key;
+       uint16_t lease_epoch;
 };
 
 struct smb2_lease_break {
@@ -1743,6 +1746,7 @@ union smb_open {
                        NTTIME timewarp;
                        bool   query_on_disk_id;
                        struct smb2_lease *lease_request;
+                       struct smb2_lease *lease_request_v2;
 
                        struct GUID *app_instance_id;
 
@@ -1773,6 +1777,7 @@ union smb_open {
                        uint32_t maximal_access;
                        uint8_t on_disk_id[32];
                        struct smb2_lease lease_response;
+                       struct smb2_lease lease_response_v2;
                        bool durable_open;
 
                        /* durable handle v2 */
diff --git a/source4/libcli/smb2/create.c b/source4/libcli/smb2/create.c
index db9abbe..7267f92 100644
--- a/source4/libcli/smb2/create.c
+++ b/source4/libcli/smb2/create.c
@@ -226,6 +226,27 @@ struct smb2_request *smb2_create_send(struct smb2_tree 
*tree, struct smb2_create
                }
        }
 
+       if (io->in.lease_request_v2) {
+               struct smb2_lease *ls = io->in.lease_request_v2;
+               uint8_t data[52];
+
+               memcpy(&data[0], &ls->lease_key, 16);
+               SIVAL(data, 16, ls->lease_state);
+               SIVAL(data, 20, ls->lease_flags);
+               SBVAL(data, 24, ls->lease_duration);
+               memcpy(&data[32], &ls->parent_lease_key, 16);
+               SSVAL(data, 48, ls->lease_epoch);
+               SSVAL(data, 50, 0); /* reserved */
+
+               status = smb2_create_blob_add(req, &blobs,
+                                             SMB2_CREATE_TAG_RQLS,
+                                             data_blob_const(data, 52));
+               if (!NT_STATUS_IS_OK(status)) {
+                       talloc_free(req);
+                       return NULL;
+               }
+       }
+
        if (io->in.app_instance_id) {
                uint8_t data[20];
                DATA_BLOB guid_blob;
@@ -342,17 +363,34 @@ NTSTATUS smb2_create_recv(struct smb2_request *req, 
TALLOC_CTX *mem_ctx, struct
                        memcpy(io->out.on_disk_id, 
io->out.blobs.blobs[i].data.data, 32);
                }
                if (strcmp(io->out.blobs.blobs[i].tag, SMB2_CREATE_TAG_RQLS) == 
0) {
+                       struct smb2_lease *ls = NULL;
                        uint8_t *data;
-                       if (io->out.blobs.blobs[i].data.length != 32) {
+
+                       ZERO_STRUCT(io->out.lease_response);
+                       ZERO_STRUCT(io->out.lease_response_v2);
+
+                       switch (io->out.blobs.blobs[i].data.length) {
+                       case 32:
+                               ls = &io->out.lease_response;
+                               break;
+                       case 52:
+                               ls = &io->out.lease_response_v2;
+                               break;
+                       default:
                                smb2_request_destroy(req);
                                return NT_STATUS_INVALID_NETWORK_RESPONSE;
                        }
 
                        data = io->out.blobs.blobs[i].data.data;
-                       memcpy(&io->out.lease_response.lease_key, data, 16);
-                       io->out.lease_response.lease_state = IVAL(data, 16);
-                       io->out.lease_response.lease_flags = IVAL(data, 20);
-                       io->out.lease_response.lease_duration = BVAL(data, 24);
+                       memcpy(&ls->lease_key, data, 16);
+                       ls->lease_state = IVAL(data, 16);
+                       ls->lease_flags = IVAL(data, 20);
+                       ls->lease_duration = BVAL(data, 24);
+
+                       if (io->out.blobs.blobs[i].data.length == 52) {
+                               memcpy(&ls->parent_lease_key, data+32, 16);
+                               ls->lease_epoch = SVAL(data, 48);
+                       }
                }
                if (strcmp(io->out.blobs.blobs[i].tag, SMB2_CREATE_TAG_DHNQ) == 
0) {
                        if (io->out.blobs.blobs[i].data.length != 8) {
diff --git a/source4/torture/smb2/lease.c b/source4/torture/smb2/lease.c
index 5669c62..21d4679 100644
--- a/source4/torture/smb2/lease.c
+++ b/source4/torture/smb2/lease.c
@@ -20,6 +20,7 @@
 */
 
 #include "includes.h"
+#include <tevent.h>
 #include "libcli/smb2/smb2.h"
 #include "libcli/smb2/smb2_calls.h"
 #include "torture/torture.h"
@@ -65,11 +66,30 @@
                                                                        \
                CHECK_VAL((__io)->out.lease_response.lease_flags, 0);   \
                CHECK_VAL((__io)->out.lease_response.lease_duration, 0); \
-       } while(0)                                                      \
+       } while(0)
+
+#define CHECK_LEASE_V2(__io, __state, __oplevel, __key, __flags)       \
+       do {                                                            \
+               if (__oplevel) {                                        \
+                       CHECK_VAL((__io)->out.oplock_level, 
SMB2_OPLOCK_LEVEL_LEASE); \
+                       
CHECK_VAL((__io)->out.lease_response_v2.lease_key.data[0], (__key)); \
+                       
CHECK_VAL((__io)->out.lease_response_v2.lease_key.data[1], ~(__key)); \
+                       CHECK_VAL((__io)->out.lease_response_v2.lease_state, 
smb2_util_lease_state(__state)); \
+               } else {                                                \
+                       CHECK_VAL((__io)->out.oplock_level, 
SMB2_OPLOCK_LEVEL_NONE); \
+                       
CHECK_VAL((__io)->out.lease_response_v2.lease_key.data[0], 0); \
+                       
CHECK_VAL((__io)->out.lease_response_v2.lease_key.data[1], 0); \
+                       CHECK_VAL((__io)->out.lease_response_v2.lease_state, 
0); \
+               }                                                       \
+                                                                       \
+               CHECK_VAL((__io)->out.lease_response_v2.lease_flags, __flags); \
+               CHECK_VAL((__io)->out.lease_response_v2.lease_duration, 0); \
+       } while(0)
 
 static const uint64_t LEASE1 = 0xBADC0FFEE0DDF00Dull;
 static const uint64_t LEASE2 = 0xDEADBEEFFEEDBEADull;
 static const uint64_t LEASE3 = 0xDAD0FFEDD00DF00Dull;
+static const uint64_t LEASE4 = 0xBAD0FFEDD00DF00Dull;
 
 #define NREQUEST_RESULTS 8
 static const char *request_results[NREQUEST_RESULTS][2] = {
@@ -400,6 +420,59 @@ static bool torture_lease_handler(struct smb2_transport 
*transport,
 }
 
 /*
+   Timer handler function notifies the registering function that time is up
+*/
+static void timeout_cb(struct tevent_context *ev,
+                      struct tevent_timer *te,
+                      struct timeval current_time,
+                      void *private_data)
+{
+       bool *timesup = (bool *)private_data;
+       *timesup = true;
+       return;
+}
+
+/*
+   Wait a short period of time to receive a single oplock break request
+*/
+static void torture_wait_for_lease_break(struct torture_context *tctx)
+{
+       TALLOC_CTX *tmp_ctx = talloc_new(NULL);
+       struct tevent_timer *te = NULL;
+       struct timeval ne;
+       bool timesup = false;
+       int old_count = break_info.count;
+
+       /* Wait .1 seconds for an lease break */
+       ne = tevent_timeval_current_ofs(0, 100000);
+
+       te = tevent_add_timer(tctx->ev, tmp_ctx, ne, timeout_cb, &timesup);
+       if (te == NULL) {
+               torture_comment(tctx, "Failed to wait for an oplock break. "
+                                     "test results may not be accurate.");
+               goto done;
+       }
+
+       while (!timesup && break_info.count < old_count + 1) {
+               if (tevent_loop_once(tctx->ev) != 0) {
+                       torture_comment(tctx, "Failed to wait for an oplock "
+                                             "break. test results may not be "
+                                             "accurate.");
+                       goto done;
+               }
+       }
+
+done:
+       /* We don't know if the timed event fired and was freed, we received
+        * our oplock break, or some other event triggered the loop.  Thus,
+        * we create a tmp_ctx to be able to safely free/remove the timed
+        * event in all 3 cases. */
+       talloc_free(tmp_ctx);
+
+       return;
+}
+
+/*
   break_results should be read as "held lease, new lease, hold broken to, new
   grant", i.e. { "RH", "RW", "RH", "R" } means that if key1 holds RH and key2
   tries for RW, key1 will be broken to RH (in this case, not broken at all)
@@ -828,6 +901,140 @@ static bool test_lease_multibreak(struct torture_context 
*tctx,
        return ret;
 }
 
+static bool test_lease_v2_request(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 h1, h2, h3, h4, h5;
+       struct smb2_write w;
+       NTSTATUS status;
+       const char *fname = "lease.dat";
+       const char *dname = "lease.dir";
+       const char *dnamefname = "lease.dir\\lease.dat";
+       const char *dnamefname2 = "lease.dir\\lease2.dat";
+       bool ret = true;
+
+       smb2_util_unlink(tree, fname);
+       smb2_deltree(tree, dname);
+
+       tree->session->transport->lease.handler = torture_lease_handler;
+       tree->session->transport->lease.private_data = tree;
+       tree->session->transport->oplock.handler = torture_oplock_handler;
+       tree->session->transport->oplock.private_data = tree;
+
+       ZERO_STRUCT(break_info);
+
+       ZERO_STRUCT(io);
+       smb2_lease_v2_create_share(&io, &ls, false, fname,
+                                  smb2_util_share_access("RWD"),
+                                  LEASE1, NULL,
+                                  smb2_util_lease_state("RHW"),
+                                  0);
+
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       h1 = io.out.file.handle;
+       CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_LEASE_V2(&io, "RHW", true, LEASE1, 0);
+
+       ZERO_STRUCT(io);
+       smb2_lease_v2_create_share(&io, &ls, true, dname,
+                                  smb2_util_share_access("RWD"),
+                                  LEASE2, NULL,
+                                  smb2_util_lease_state("RHW"),
+                                  0);
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       h2 = io.out.file.handle;
+       CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_DIRECTORY);
+       CHECK_LEASE_V2(&io, "RH", true, LEASE2, 0);
+
+       ZERO_STRUCT(io);
+       smb2_lease_v2_create_share(&io, &ls, false, dnamefname,
+                                  smb2_util_share_access("RWD"),
+                                  LEASE3, &LEASE2,
+                                  smb2_util_lease_state("RHW"),
+                                  0);
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       h3 = io.out.file.handle;
+       CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_LEASE_V2(&io, "RHW", true, LEASE3,
+                      SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET);
+
+       torture_wait_for_lease_break(tctx);
+       CHECK_VAL(break_info.count, 0);
+       CHECK_VAL(break_info.failures, 0);
+
+       ZERO_STRUCT(io);
+       smb2_lease_v2_create_share(&io, &ls, false, dnamefname2,
+                                  smb2_util_share_access("RWD"),
+                                  LEASE4, NULL,
+                                  smb2_util_lease_state("RHW"),
+                                  0);
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       h4 = io.out.file.handle;
+       CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE);
+       CHECK_LEASE_V2(&io, "RHW", true, LEASE4, 0);
+
+       torture_wait_for_lease_break(tctx);
+       torture_wait_for_lease_break(tctx);
+       CHECK_BREAK_INFO("RH", "", LEASE2);
+       torture_wait_for_lease_break(tctx);
+
+       ZERO_STRUCT(break_info);
+
+       ZERO_STRUCT(io);
+       smb2_lease_v2_create_share(&io, &ls, true, dname,
+                                  smb2_util_share_access("RWD"),
+                                  LEASE2, NULL,
+                                  smb2_util_lease_state("RHW"),
+                                  0);
+       io.in.create_disposition = NTCREATEX_DISP_OPEN;
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       h5 = io.out.file.handle;
+       CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_DIRECTORY);
+       CHECK_LEASE_V2(&io, "RH", true, LEASE2, 0);
+       smb2_util_close(tree, h5);
+
+       ZERO_STRUCT(w);
+       w.in.file.handle = h4;
+       w.in.offset      = 0;
+       w.in.data        = data_blob_talloc(mem_ctx, NULL, 4096);
+       memset(w.in.data.data, 'o', w.in.data.length);
+       status = smb2_write(tree, &w);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       smb_msleep(2000);
+       torture_wait_for_lease_break(tctx);
+       CHECK_VAL(break_info.count, 0);
+       CHECK_VAL(break_info.failures, 0);
+
+       smb2_util_close(tree, h4);
+       torture_wait_for_lease_break(tctx);
+       torture_wait_for_lease_break(tctx);
+       CHECK_BREAK_INFO("RH", "", LEASE2);
+       torture_wait_for_lease_break(tctx);
+
+ done:
+       smb2_util_close(tree, h1);
+       smb2_util_close(tree, h2);
+       smb2_util_close(tree, h3);
+       smb2_util_close(tree, h4);
+       smb2_util_close(tree, h5);
+
+       smb2_util_unlink(tree, fname);
+       smb2_deltree(tree, dname);
+
+       talloc_free(mem_ctx);
+
+       return ret;
+}
+
 struct torture_suite *torture_smb2_lease_init(void)
 {
        struct torture_suite *suite =
@@ -839,6 +1046,7 @@ struct torture_suite *torture_smb2_lease_init(void)
        torture_suite_add_1smb2_test(suite, "break", test_lease_break);
        torture_suite_add_1smb2_test(suite, "oplock", test_lease_oplock);
        torture_suite_add_1smb2_test(suite, "multibreak", 
test_lease_multibreak);
+       torture_suite_add_1smb2_test(suite, "v2_request", 
test_lease_v2_request);
 
        suite->description = talloc_strdup(suite, "SMB2-LEASE tests");
 
diff --git a/source4/torture/smb2/util.c b/source4/torture/smb2/util.c
index 71e87f3..59748b7 100644
--- a/source4/torture/smb2/util.c
+++ b/source4/torture/smb2/util.c
@@ -687,7 +687,6 @@ void smb2_generic_create_share(struct smb2_create *io, 
struct smb2_lease *ls,
 
        if (dir) {
                io->in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
-               io->in.share_access &= ~NTCREATEX_SHARE_ACCESS_DELETE;
                io->in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
                io->in.create_disposition = NTCREATEX_DISP_CREATE;
        }
@@ -730,6 +729,34 @@ void smb2_lease_create(struct smb2_create *io, struct 
smb2_lease *ls,
                                leasekey, leasestate);
 }
 
+void smb2_lease_v2_create_share(struct smb2_create *io,
+                               struct smb2_lease *ls,
+                               bool dir,
+                               const char *name,
+                               uint32_t share_access,
+                               uint64_t leasekey,
+                               const uint64_t *parentleasekey,
+                               uint32_t leasestate,
+                               uint16_t lease_epoch)
+{
+       smb2_generic_create_share(io, NULL, dir, name, NTCREATEX_DISP_OPEN_IF,
+                                 share_access, SMB2_OPLOCK_LEVEL_LEASE, 0, 0);
+
+       if (ls) {
+               ZERO_STRUCT(*ls);
+               ls->lease_key.data[0] = leasekey;
+               ls->lease_key.data[1] = ~leasekey;
+               ls->lease_state = leasestate;
+               if (parentleasekey != NULL) {
+                       ls->lease_flags |= SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET;
+                       ls->parent_lease_key.data[0] = *parentleasekey;
+                       ls->parent_lease_key.data[1] = ~(*parentleasekey);
+               }
+               ls->lease_epoch = lease_epoch;
+               io->in.lease_request_v2 = ls;
+       }
+}
+
 void smb2_oplock_create_share(struct smb2_create *io, const char *name,
                              uint32_t share_access, uint8_t oplock)
 {


-- 
Samba Shared Repository

Reply via email to