s4:smb2: Add rudimentary SMB2.1 lease support to libcli
[ira/wip.git] / source4 / libcli / raw / interfaces.h
index 61441b2cdc5f0a4269e086833fd7d23eb243dbf8..bd93fa1695d4039950ad4d768b6323ddbc2f0d1a 100644 (file)
@@ -53,6 +53,16 @@ struct smb2_handle {
        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;
 
 /*
@@ -684,7 +694,8 @@ union smb_fileinfo {
                        uint32_t ea_size;
                        uint32_t access_mask;
                        uint64_t position;
-                       uint64_t mode;
+                       uint32_t mode;
+                       uint32_t alignment_requirement;
                        struct smb_wire_string fname;
                } out;
        } all_info2;
@@ -903,17 +914,27 @@ enum smb_setfileinfo_level {
        RAW_SFILEINFO_UNIX_HLINK              = SMB_SFILEINFO_UNIX_HLINK,
        RAW_SFILEINFO_BASIC_INFORMATION       = SMB_SFILEINFO_BASIC_INFORMATION,
        RAW_SFILEINFO_RENAME_INFORMATION      = SMB_SFILEINFO_RENAME_INFORMATION,
+       RAW_SFILEINFO_LINK_INFORMATION        = SMB_SFILEINFO_LINK_INFORMATION,
        RAW_SFILEINFO_DISPOSITION_INFORMATION = SMB_SFILEINFO_DISPOSITION_INFORMATION,
        RAW_SFILEINFO_POSITION_INFORMATION    = SMB_SFILEINFO_POSITION_INFORMATION,
+       RAW_SFILEINFO_FULL_EA_INFORMATION     = SMB_SFILEINFO_FULL_EA_INFORMATION,
        RAW_SFILEINFO_MODE_INFORMATION        = SMB_SFILEINFO_MODE_INFORMATION,
        RAW_SFILEINFO_ALLOCATION_INFORMATION  = SMB_SFILEINFO_ALLOCATION_INFORMATION,
        RAW_SFILEINFO_END_OF_FILE_INFORMATION = SMB_SFILEINFO_END_OF_FILE_INFORMATION,
-       RAW_SFILEINFO_1023                    = SMB_SFILEINFO_1023,
+       RAW_SFILEINFO_PIPE_INFORMATION        = SMB_SFILEINFO_PIPE_INFORMATION,
+       RAW_SFILEINFO_VALID_DATA_INFORMATION  = SMB_SFILEINFO_VALID_DATA_INFORMATION,
+       RAW_SFILEINFO_SHORT_NAME_INFORMATION  = SMB_SFILEINFO_SHORT_NAME_INFORMATION,
        RAW_SFILEINFO_1025                    = SMB_SFILEINFO_1025,
+       RAW_SFILEINFO_1027                    = SMB_SFILEINFO_1027,
        RAW_SFILEINFO_1029                    = SMB_SFILEINFO_1029,
+       RAW_SFILEINFO_1030                    = SMB_SFILEINFO_1030,
+       RAW_SFILEINFO_1031                    = SMB_SFILEINFO_1031,
        RAW_SFILEINFO_1032                    = SMB_SFILEINFO_1032,
-       RAW_SFILEINFO_1039                    = SMB_SFILEINFO_1039,
-       RAW_SFILEINFO_1040                    = SMB_SFILEINFO_1040,
+       RAW_SFILEINFO_1036                    = SMB_SFILEINFO_1036,
+       RAW_SFILEINFO_1041                    = SMB_SFILEINFO_1041,
+       RAW_SFILEINFO_1042                    = SMB_SFILEINFO_1042,
+       RAW_SFILEINFO_1043                    = SMB_SFILEINFO_1043,
+       RAW_SFILEINFO_1044                    = SMB_SFILEINFO_1044,
        
        /* cope with breakage in SMB2 */
        RAW_SFILEINFO_RENAME_INFORMATION_SMB2 = SMB_SFILEINFO_RENAME_INFORMATION|0x80000000,
@@ -974,6 +995,7 @@ union smb_setfileinfo {
                        NTTIME write_time;
                        NTTIME change_time;
                        uint32_t attrib;
+                       uint32_t reserved;
                } in;
        } basic_info;
 
@@ -1019,6 +1041,17 @@ union smb_setfileinfo {
                } in;
        } rename_information;
 
+       /* RAW_SFILEINFO_LINK_INFORMATION interface */
+       struct {
+               enum smb_setfileinfo_level level;
+               struct {
+                       union smb_handle_or_path file;
+                       uint8_t overwrite;
+                       uint64_t root_fid;
+                       const char *new_name;
+               } in;
+       } link_information;
+
        /* RAW_SFILEINFO_POSITION_INFORMATION interface */
        struct {
                enum smb_setfileinfo_level level;
@@ -1102,6 +1135,15 @@ union smb_setfileinfo {
                        struct security_descriptor *sd;
                } in;
        } set_secdesc;
+
+       /* RAW_SFILEINFO_FULL_EA_INFORMATION */
+       struct {
+               enum smb_setfileinfo_level level;
+               struct {
+                       union smb_handle_or_path file;
+                       struct smb_ea_list eas;
+               } in;
+       } full_ea_information;
 };
 
 
@@ -1353,7 +1395,7 @@ union smb_open {
                break; \
        } \
 } while (0)
-       /* SMBNTCreateX interface */
+       /* SMBNTCreateX, nttrans and generic interface */
        struct {
                enum smb_open_level level;
                struct {
@@ -1376,6 +1418,9 @@ union smb_open {
                           NTTRANS varient of the call */
                        struct security_descriptor *sec_desc;
                        struct smb_ea_list *ea_list;
+                       
+                       /* some optional parameters from the SMB2 varient */
+                       bool query_maximal_access;
                } in;
                struct {
                        union smb_handle file;
@@ -1391,6 +1436,10 @@ union smb_open {
                        uint16_t file_type;
                        uint16_t ipc_state;
                        uint8_t  is_directory;
+
+                       /* optional return values matching SMB2 tagged
+                          values in the call */
+                       uint32_t maximal_access;
                } out;
        } ntcreatex, nttrans, generic;
 
@@ -1585,8 +1634,25 @@ union smb_open {
                        /* dynamic body */
                        const char *fname;
 
-                       /* optional list of extended attributes */
+                       /* now some optional parameters - encoded as tagged blobs */
                        struct smb_ea_list eas;
+                       uint64_t alloc_size;
+                       struct security_descriptor *sec_desc;
+                       bool   durable_open;
+                       struct smb2_handle *durable_handle;
+                       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 {
+                               uint32_t num_blobs;
+                               struct smb2_create_blob {
+                                       const char *tag;
+                                       DATA_BLOB data;
+                               } *blobs;
+                       } blobs;
                } in;
                struct {
                        union smb_handle file;
@@ -1608,8 +1674,13 @@ union smb_open {
                        /* uint32_t blob_ofs; */
                        /* uint32_t blob_size; */
 
-                       /* dynamic body */
-                       DATA_BLOB blob;
+                       /* 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;
                } out;
        } smb2;
 };
@@ -1638,7 +1709,7 @@ union smb_read {
                struct {
                        union smb_handle file;
                        uint64_t offset;
-                       uint16_t mincnt;
+                       uint32_t mincnt; /* enforced on SMB2, 16 bit on SMB */
                        uint32_t maxcnt;
                        uint16_t remaining;
                        bool read_for_execute;
@@ -1854,16 +1925,16 @@ enum smb_lock_level {
        RAW_LOCK_LOCK,
        RAW_LOCK_UNLOCK,
        RAW_LOCK_LOCKX,
-       RAW_LOCK_SMB2
+       RAW_LOCK_SMB2,
+       RAW_LOCK_SMB2_BREAK
 };
 
-/* the generic interface is defined to be equal to the lockingX interface */
-#define RAW_LOCK_GENERIC RAW_LOCK_LOCKX
+#define        RAW_LOCK_GENERIC RAW_LOCK_LOCKX
 
 /* union for lock() backend call 
 */
 union smb_lock {
-       /* SMBlockingX (and generic) interface */
+       /* SMBlockingX and generic interface */
        struct {
                enum smb_lock_level level;
                struct {
@@ -1873,12 +1944,12 @@ union smb_lock {
                        uint16_t ulock_cnt;
                        uint16_t lock_cnt;
                        struct smb_lock_entry {
-                               uint16_t pid;
+                               uint32_t pid; /* 16 bits in SMB1 */
                                uint64_t offset;
                                uint64_t count;
                        } *locks; /* unlocks are first in the arrray */
                } in;
-       } lockx, generic;
+       } generic, lockx;
 
        /* SMBlock and SMBunlock interface */
        struct {
@@ -1898,48 +1969,86 @@ union smb_lock {
 
                        /* static body buffer 48 (0x30) bytes */
                        /* uint16_t buffer_code;  0x30 */
-                       uint16_t unknown1; /* must be 0x0001 */
-                       uint32_t unknown2;
+                       uint16_t lock_count;
+                       uint32_t reserved;
                        /* struct smb2_handle handle; */
-                       uint64_t offset;
-                       uint64_t count;
-                       uint32_t unknown5;
+                       struct smb2_lock_element {
+                               uint64_t offset;
+                               uint64_t length;
+/* these flags are the same as the SMB2 lock flags */
 #define SMB2_LOCK_FLAG_NONE            0x00000000
 #define SMB2_LOCK_FLAG_SHARED          0x00000001
-#define SMB2_LOCK_FLAG_EXCLUSIV                0x00000002
+#define SMB2_LOCK_FLAG_EXCLUSIVE       0x00000002
 #define SMB2_LOCK_FLAG_UNLOCK          0x00000004
-#define SMB2_LOCK_FLAG_NO_PENDING      0x00000010
-                       uint32_t flags;
+#define SMB2_LOCK_FLAG_FAIL_IMMEDIATELY        0x00000010
+#define SMB2_LOCK_FLAG_ALL_MASK                0x00000017
+                               uint32_t flags;
+                               uint32_t reserved;
+                       } *locks;
                } in;
                struct {
                        /* static body buffer 4 (0x04) bytes */
                        /* uint16_t buffer_code;  0x04 */
-                       uint16_t unknown1;
+                       uint16_t reserved;
                } out;
        } smb2;
+
+       /* SMB2 Break */
+       struct smb2_break {
+               enum smb_lock_level level;
+               struct {
+                       union smb_handle file;
+
+                       /* static body buffer 24 (0x18) bytes */
+                       uint8_t oplock_level;
+                       uint8_t reserved;
+                       uint32_t reserved2;
+                       /* struct smb2_handle handle; */
+               } in, out;
+       } smb2_break;
 };
 
 
 enum smb_close_level {
        RAW_CLOSE_CLOSE,
        RAW_CLOSE_SPLCLOSE,
-       RAW_CLOSE_SMB2
+       RAW_CLOSE_SMB2,
+       RAW_CLOSE_GENERIC,
 };
 
-#define RAW_CLOSE_GENERIC RAW_CLOSE_CLOSE
-
 /*
   union for close() backend call
 */
 union smb_close {
-       /* SMBclose (and generic) interface */
+       /* generic interface */
+       struct {
+               enum smb_close_level level;
+               struct {
+                       union smb_handle file;
+                       time_t write_time;
+#define SMB2_CLOSE_FLAGS_FULL_INFORMATION (1<<0)
+                       uint16_t flags; /* SMB2_CLOSE_FLAGS_* */
+               } in;
+               struct {
+                       uint16_t flags;
+                       NTTIME   create_time;
+                       NTTIME   access_time;
+                       NTTIME   write_time;
+                       NTTIME   change_time;
+                       uint64_t alloc_size;
+                       uint64_t size;
+                       uint32_t file_attr;
+               } out;
+       } generic;
+
+       /* SMBclose interface */
        struct {
                enum smb_close_level level;
                struct {
                        union smb_handle file;
                        time_t write_time;
                } in;
-       } close, generic;
+       } close;
 
        /* SMBsplclose interface - empty! */
        struct {
@@ -1957,7 +2066,6 @@ union smb_close {
 
                        /* static body buffer 24 (0x18) bytes */
                        /* uint16_t buffer_code;  0x18 */
-#define SMB2_CLOSE_FLAGS_FULL_INFORMATION (1<<0)
                        uint16_t flags; /* SMB2_CLOSE_FLAGS_* */
                        uint32_t _pad;
                } in;
@@ -2131,8 +2239,12 @@ union smb_flush {
                enum smb_flush_level level;
                struct {
                        union smb_handle file;
-                       uint32_t unknown;
+                       uint16_t reserved1;
+                       uint32_t reserved2;
                } in;
+               struct {
+                       uint16_t reserved;
+               } out;
        } smb2;
 };
 
@@ -2180,7 +2292,7 @@ struct smb_nttrans {
                uint8_t  max_setup;
                uint32_t max_param;
                uint32_t max_data;
-               uint32_t setup_count;
+               uint8_t setup_count;
                uint16_t function;
                uint8_t  *setup;
                DATA_BLOB params;
@@ -2331,10 +2443,11 @@ union smb_search_first {
 #define SMB2_FIND_ID_BOTH_DIRECTORY_INFO 0x25
 #define SMB2_FIND_ID_FULL_DIRECTORY_INFO 0x26
 
-/* flags for RAW_FILEINFO_SMB2_ALL_EAS */
+/* flags for SMB2 find */
 #define SMB2_CONTINUE_FLAG_RESTART    0x01
 #define SMB2_CONTINUE_FLAG_SINGLE     0x02
-#define SMB2_CONTINUE_FLAG_NEW        0x10
+#define SMB2_CONTINUE_FLAG_INDEX      0x04
+#define SMB2_CONTINUE_FLAG_REOPEN     0x10
 
        /* SMB2 Find */
        struct smb2_find {
@@ -2347,7 +2460,7 @@ union smb_search_first {
                        /* uint16_t buffer_code;  0x21 = 0x20 + 1 */
                        uint8_t level;
                        uint8_t continue_flags; /* SMB2_CONTINUE_FLAG_* */
-                       uint32_t unknown; /* perhaps a continue token? */
+                       uint32_t file_index; 
                        /* struct smb2_handle handle; */
                        /* uint16_t pattern_ofs; */
                        /* uint16_t pattern_size; */
@@ -2597,7 +2710,7 @@ union smb_search_data {
 };
 
 /* Callback function passed to the raw search interface. */
-typedef bool (*smbcli_search_callback)(void *private, const union smb_search_data *file);
+typedef bool (*smbcli_search_callback)(void *private_data, const union smb_search_data *file);
 
 enum smb_search_close_level {RAW_FINDCLOSE_GENERIC, RAW_FINDCLOSE_FCLOSE, RAW_FINDCLOSE_FINDCLOSE};