s4:smb2: Add rudimentary SMB2.1 lease support to libcli
authorZach Loafman <zachary.loafman@isilon.com>
Sat, 28 Mar 2009 02:12:43 +0000 (19:12 -0700)
committerSteven Danneman <steven.danneman@isilon.com>
Sat, 28 Mar 2009 08:01:47 +0000 (01:01 -0700)
Add the structures, constants, and marshalling for SMB2.1 leases.

source4/libcli/raw/interfaces.h
source4/libcli/smb2/create.c
source4/libcli/smb2/smb2.h

index a0584c0aa42c7fe228a4ed51e2b35426a4caf33d..bd93fa1695d4039950ad4d768b6323ddbc2f0d1a 100644 (file)
@@ -53,6 +53,16 @@ struct smb2_handle {
        uint64_t data[2];
 };
 
        uint64_t data[2];
 };
 
+/*
+  SMB2 lease structure (per MS-SMB2 2.2.13)
+*/
+struct smb2_lease {
+       uint64_t lease_key[2];
+       uint32_t lease_state;
+       uint32_t lease_flags; /* should be 0 */
+       uint64_t lease_duration; /* should be 0 */
+};
+
 struct ntvfs_handle;
 
 /*
 struct ntvfs_handle;
 
 /*
@@ -1633,6 +1643,7 @@ union smb_open {
                        bool   query_maximal_access;
                        NTTIME timewarp;
                        bool   query_on_disk_id;
                        bool   query_maximal_access;
                        NTTIME timewarp;
                        bool   query_on_disk_id;
+                       struct smb2_lease *lease_request;
                        
                        /* and any additional blobs the caller wants */
                        struct smb2_create_blobs {
                        
                        /* and any additional blobs the caller wants */
                        struct smb2_create_blobs {
@@ -1666,6 +1677,7 @@ union smb_open {
                        /* optional return values matching tagged values in the call */
                        uint32_t maximal_access;
                        uint8_t on_disk_id[32];
                        /* optional return values matching tagged values in the call */
                        uint32_t maximal_access;
                        uint8_t on_disk_id[32];
+                       struct smb2_lease lease_response;
 
                        /* tagged blobs in the reply */
                        struct smb2_create_blobs blobs;
 
                        /* tagged blobs in the reply */
                        struct smb2_create_blobs blobs;
index 8a40e56a00e613a94c371f7ba852fefc38d960e7..344be60f6e233b066e505c5cb9ba326168ff91a9 100644 (file)
@@ -312,6 +312,23 @@ struct smb2_request *smb2_create_send(struct smb2_tree *tree, struct smb2_create
                }
        }
 
                }
        }
 
+       if (io->in.lease_request) {
+               uint8_t data[32];
+
+               memcpy(&data[0], io->in.lease_request->lease_key, 16);
+               SIVAL(data, 16, io->in.lease_request->lease_state);
+               SIVAL(data, 20, io->in.lease_request->lease_flags);
+               SBVAL(data, 24, io->in.lease_request->lease_duration);
+
+               status = smb2_create_blob_add(req, &blobs,
+                                             SMB2_CREATE_TAG_RQLS,
+                                             data_blob_const(data, 32));
+               if (!NT_STATUS_IS_OK(status)) {
+                       talloc_free(req);
+                       return NULL;
+               }
+       }
+
        /* and any custom blobs */
        for (i=0;i<io->in.blobs.num_blobs;i++) {
                status = smb2_create_blob_add(req, &blobs,
        /* and any custom blobs */
        for (i=0;i<io->in.blobs.num_blobs;i++) {
                status = smb2_create_blob_add(req, &blobs,
@@ -402,6 +419,19 @@ 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);
                }
                        }
                        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) {
+                       uint8_t *data;
+                       if (io->out.blobs.blobs[i].data.length != 32) {
+                               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);
+               }
        }
 
        data_blob_free(&blob);
        }
 
        data_blob_free(&blob);
index 7c07c847403837ccdb7a9a0b6d35b084b09be303..fd961ce5f3988241d82749be9edfb70967e76feb 100644 (file)
@@ -263,6 +263,13 @@ struct smb2_request {
 #define SMB2_OPLOCK_LEVEL_II                             0x01
 #define SMB2_OPLOCK_LEVEL_EXCLUSIVE                      0x08
 #define SMB2_OPLOCK_LEVEL_BATCH                          0x09
 #define SMB2_OPLOCK_LEVEL_II                             0x01
 #define SMB2_OPLOCK_LEVEL_EXCLUSIVE                      0x08
 #define SMB2_OPLOCK_LEVEL_BATCH                          0x09
+#define SMB2_OPLOCK_LEVEL_LEASE                          0xFF
+
+/* SMB2 lease bits */
+#define SMB2_LEASE_NONE                                  0x00
+#define SMB2_LEASE_READ                                  0x01
+#define SMB2_LEASE_HANDLE                                0x02
+#define SMB2_LEASE_WRITE                                 0x04
 
 /* SMB2 impersonation levels */
 #define SMB2_IMPERSONATION_ANONYMOUS                     0x00
 
 /* SMB2 impersonation levels */
 #define SMB2_IMPERSONATION_ANONYMOUS                     0x00
@@ -279,6 +286,7 @@ struct smb2_request {
 #define SMB2_CREATE_TAG_ALSI "AlSi"
 #define SMB2_CREATE_TAG_TWRP "TWrp"
 #define SMB2_CREATE_TAG_QFID "QFid"
 #define SMB2_CREATE_TAG_ALSI "AlSi"
 #define SMB2_CREATE_TAG_TWRP "TWrp"
 #define SMB2_CREATE_TAG_QFID "QFid"
+#define SMB2_CREATE_TAG_RQLS "RqLs"
 
 /* SMB2 Create ignore some more create_options */
 #define SMB2_CREATE_OPTIONS_NOT_SUPPORTED_MASK (NTCREATEX_OPTIONS_TREE_CONNECTION | \
 
 /* SMB2 Create ignore some more create_options */
 #define SMB2_CREATE_OPTIONS_NOT_SUPPORTED_MASK (NTCREATEX_OPTIONS_TREE_CONNECTION | \