s4:smb2: Add rudimentary SMB2.1 lease support to libcli
[ira/wip.git] / source4 / libcli / raw / interfaces.h
index f715c10e115ed33fde85c106b340e1a19dc9e98e..bd93fa1695d4039950ad4d768b6323ddbc2f0d1a 100644 (file)
@@ -3,10 +3,11 @@
    SMB request interface structures
    Copyright (C) Andrew Tridgell                       2003
    Copyright (C) James J Myers 2003 <myersjj@samba.org>
+   Copyright (C) James Peach 2007
    
    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 2 of the License, or
+   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,
    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, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifndef __LIBCLI_RAW_INTERFACES_H__
 #define __LIBCLI_RAW_INTERFACES_H__
 
 #include "smb.h" 
+#include "librpc/gen_ndr/misc.h" /* for struct GUID */
 
 /* this structure is just a wrapper for a string, the only reason we
    bother with this is that it allows us to check the length provided
@@ -52,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;
 
 /*
@@ -174,7 +185,7 @@ struct smb_rmdir {
 };
 
 /* struct used in rename() call */
-enum smb_rename_level {RAW_RENAME_RENAME, RAW_RENAME_NTRENAME};
+enum smb_rename_level {RAW_RENAME_RENAME, RAW_RENAME_NTRENAME, RAW_RENAME_NTTRANS};
 
 union smb_rename {
        struct {
@@ -205,9 +216,24 @@ union smb_rename {
                        const char *new_name;
                } in;
        } ntrename;
+
+       /* NT TRANS rename interface */
+       struct {
+               enum smb_rename_level level;
+
+               struct {
+                       union smb_handle file;
+                       uint16_t flags;/* see RENAME_REPLACE_IF_EXISTS */
+                       const char *new_name;
+               } in;
+       } nttrans;
 };
 
-enum smb_tcon_level {RAW_TCON_TCON, RAW_TCON_TCONX};
+enum smb_tcon_level {
+       RAW_TCON_TCON,
+       RAW_TCON_TCONX,
+       RAW_TCON_SMB2
+};
 
 /* union used in tree connect call */
 union smb_tcon {
@@ -248,10 +274,41 @@ union smb_tcon {
                        uint16_t tid;
                } out;
        } tconx;
+
+       /* SMB2 TreeConnect */
+       struct smb2_tree_connect {
+               enum smb_tcon_level level;
+
+               struct {
+                       /* static body buffer 8 (0x08) bytes */
+                       uint16_t reserved;
+                       /* uint16_t path_ofs */
+                       /* uint16_t path_size */
+                               /* dynamic body */
+                       const char *path; /* as non-terminated UTF-16 on the wire */
+               } in;
+               struct {
+                       /* static body buffer 16 (0x10) bytes */
+                       /* uint16_t buffer_code;  0x10 */
+                       uint8_t share_type;
+                       uint8_t reserved;
+                       uint32_t flags;
+                       uint32_t capabilities;
+                       uint32_t access_mask;
+       
+                       /* extracted from the SMB2 header */
+                       uint32_t tid;
+               } out;
+       } smb2;
 };
 
 
-enum smb_sesssetup_level {RAW_SESSSETUP_OLD, RAW_SESSSETUP_NT1, RAW_SESSSETUP_SPNEGO};
+enum smb_sesssetup_level {
+       RAW_SESSSETUP_OLD,
+       RAW_SESSSETUP_NT1,
+       RAW_SESSSETUP_SPNEGO,
+       RAW_SESSSETUP_SMB2
+};
 
 /* union used in session_setup call */
 union smb_sesssetup {
@@ -330,6 +387,35 @@ union smb_sesssetup {
                        uint16_t vuid;
                } out;
        } spnego;
+
+       /* SMB2 SessionSetup */
+       struct smb2_session_setup {
+               enum smb_sesssetup_level level;
+
+               struct {
+                       /* static body 24 (0x18) bytes */
+                       uint8_t vc_number;
+                       uint8_t security_mode;
+                       uint32_t capabilities;
+                       uint32_t channel;
+                       /* uint16_t secblob_ofs */
+                       /* uint16_t secblob_size */
+                       uint64_t previous_sessionid;
+                       /* dynamic body */
+                       DATA_BLOB secblob;
+               } in;
+               struct {
+                       /* body buffer 8 (0x08) bytes */
+                       uint16_t session_flags;
+                       /* uint16_t secblob_ofs */
+                       /* uint16_t secblob_size */
+                       /* dynamic body */
+                       DATA_BLOB secblob;
+
+                       /* extracted from the SMB2 header */
+                       uint64_t uid;
+               } out;
+       } smb2;
 };
 
 /* Note that the specified enum values are identical to the actual info-levels used
@@ -354,6 +440,7 @@ enum smb_fileinfo_level {
                     RAW_FILEINFO_STREAM_INFO                = SMB_QFILEINFO_STREAM_INFO,
                     RAW_FILEINFO_COMPRESSION_INFO           = SMB_QFILEINFO_COMPRESSION_INFO,
                     RAW_FILEINFO_UNIX_BASIC                 = SMB_QFILEINFO_UNIX_BASIC,
+                    RAW_FILEINFO_UNIX_INFO2                 = SMB_QFILEINFO_UNIX_INFO2,
                     RAW_FILEINFO_UNIX_LINK                  = SMB_QFILEINFO_UNIX_LINK,
                     RAW_FILEINFO_BASIC_INFORMATION          = SMB_QFILEINFO_BASIC_INFORMATION,
                     RAW_FILEINFO_STANDARD_INFORMATION       = SMB_QFILEINFO_STANDARD_INFORMATION,
@@ -535,8 +622,8 @@ union smb_fileinfo {
                        uint64_t alloc_size;
                        uint64_t size;
                        uint32_t nlink;
-                       BOOL delete_pending;
-                       BOOL directory;
+                       bool delete_pending;
+                       bool directory;
                } out;
        } standard_info;
        
@@ -607,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;
@@ -673,6 +761,32 @@ union smb_fileinfo {
                } out;
        } unix_basic_info;
 
+       /* RAW_FILEINFO_UNIX_INFO2 interface */
+       struct {
+               enum smb_fileinfo_level level;
+               struct {
+                       union smb_handle_or_path file;
+               } in;
+               struct {
+                       uint64_t end_of_file;
+                       uint64_t num_bytes;
+                       NTTIME status_change_time;
+                       NTTIME access_time;
+                       NTTIME change_time;
+                       uint64_t uid;
+                       uint64_t gid;
+                       uint32_t file_type;
+                       uint64_t dev_major;
+                       uint64_t dev_minor;
+                       uint64_t unique_id;
+                       uint64_t permissions;
+                       uint64_t nlink;
+                       NTTIME create_time;
+                       uint32_t file_flags;
+                       uint32_t flags_mask;
+               } out;
+       } unix_info2;
+
        /* RAW_FILEINFO_UNIX_LINK interface */
        struct {
                enum smb_fileinfo_level level;
@@ -795,21 +909,35 @@ enum smb_setfileinfo_level {
        RAW_SFILEINFO_ALLOCATION_INFO         = SMB_SFILEINFO_ALLOCATION_INFO,
        RAW_SFILEINFO_END_OF_FILE_INFO        = SMB_SFILEINFO_END_OF_FILE_INFO,
        RAW_SFILEINFO_UNIX_BASIC              = SMB_SFILEINFO_UNIX_BASIC,
+       RAW_SFILEINFO_UNIX_INFO2              = SMB_SFILEINFO_UNIX_INFO2,
        RAW_SFILEINFO_UNIX_LINK               = SMB_SFILEINFO_UNIX_LINK,
        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,
 };
 
 /* union used in setfileinfo() and setpathinfo() calls */
@@ -867,6 +995,7 @@ union smb_setfileinfo {
                        NTTIME write_time;
                        NTTIME change_time;
                        uint32_t attrib;
+                       uint32_t reserved;
                } in;
        } basic_info;
 
@@ -876,7 +1005,7 @@ union smb_setfileinfo {
                enum smb_setfileinfo_level level;
                struct {
                        union smb_handle_or_path file;
-                       BOOL delete_on_close;
+                       bool delete_on_close;
                } in;
        } disposition_info;
 
@@ -907,11 +1036,22 @@ union smb_setfileinfo {
                struct {
                        union smb_handle_or_path file;
                        uint8_t overwrite;
-                       uint32_t root_fid;
+                       uint64_t root_fid;
                        const char *new_name;
                } 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;
@@ -931,8 +1071,6 @@ union smb_setfileinfo {
                } in;
        } mode_information;
 
-
-
        /* RAW_SFILEINFO_UNIX_BASIC interface */
        struct {
                enum smb_setfileinfo_level level;
@@ -954,7 +1092,31 @@ union smb_setfileinfo {
                        uint64_t nlink;
                } in;
        } unix_basic;
-       
+
+       /* RAW_SFILEINFO_UNIX_INFO2 interface */
+       struct {
+               enum smb_setfileinfo_level level;
+               struct {
+                       union smb_handle_or_path file;
+                       uint64_t end_of_file;
+                       uint64_t num_bytes;
+                       NTTIME status_change_time;
+                       NTTIME access_time;
+                       NTTIME change_time;
+                       uint64_t uid;
+                       uint64_t gid;
+                       uint32_t file_type;
+                       uint64_t dev_major;
+                       uint64_t dev_minor;
+                       uint64_t unique_id;
+                       uint64_t permissions;
+                       uint64_t nlink;
+                       NTTIME create_time;
+                       uint32_t file_flags;
+                       uint32_t flags_mask;
+               } in;
+       } unix_info2;
+
        /* RAW_SFILEINFO_UNIX_LINK, RAW_SFILEINFO_UNIX_HLINK interface */
        struct {
                enum smb_setfileinfo_level level;
@@ -973,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;
 };
 
 
@@ -1161,19 +1332,70 @@ union smb_fsinfo {
 
 
 enum smb_open_level {
-                RAW_OPEN_OPEN, RAW_OPEN_OPENX, 
-                RAW_OPEN_MKNEW, RAW_OPEN_CREATE, 
-                RAW_OPEN_CTEMP, RAW_OPEN_SPLOPEN,
-                RAW_OPEN_NTCREATEX, RAW_OPEN_T2OPEN,
-                RAW_OPEN_NTTRANS_CREATE, 
-                RAW_OPEN_OPENX_READX};
+       RAW_OPEN_OPEN,
+       RAW_OPEN_OPENX, 
+       RAW_OPEN_MKNEW,
+       RAW_OPEN_CREATE, 
+       RAW_OPEN_CTEMP,
+       RAW_OPEN_SPLOPEN,
+       RAW_OPEN_NTCREATEX,
+       RAW_OPEN_T2OPEN,
+       RAW_OPEN_NTTRANS_CREATE, 
+       RAW_OPEN_OPENX_READX,
+       RAW_OPEN_SMB2
+};
 
 /* the generic interface is defined to be equal to the NTCREATEX interface */
 #define RAW_OPEN_GENERIC RAW_OPEN_NTCREATEX
 
 /* union for open() backend call */
 union smb_open {
-       /* SMBNTCreateX interface */
+/* 
+ * because the *.out.file structs are not aligned to the same offset for each level
+ * we provide a hepler macro that should be used to find the current smb_handle structure
+ */
+#define SMB_OPEN_OUT_FILE(op, file) do { \
+       switch (op->generic.level) { \
+       case RAW_OPEN_OPEN: \
+               file = &op->openold.out.file; \
+               break; \
+       case RAW_OPEN_OPENX: \
+               file = &op->openx.out.file; \
+               break; \
+       case RAW_OPEN_MKNEW: \
+               file = &op->mknew.out.file; \
+               break; \
+       case RAW_OPEN_CREATE: \
+               file = &op->create.out.file; \
+               break; \
+       case RAW_OPEN_CTEMP: \
+               file = &op->ctemp.out.file; \
+               break; \
+       case RAW_OPEN_SPLOPEN: \
+               file = &op->splopen.out.file; \
+               break; \
+       case RAW_OPEN_NTCREATEX: \
+               file = &op->ntcreatex.out.file; \
+               break; \
+       case RAW_OPEN_T2OPEN: \
+               file = &op->t2open.out.file; \
+               break; \
+       case RAW_OPEN_NTTRANS_CREATE: \
+               file = &op->nttrans.out.file; \
+               break; \
+       case RAW_OPEN_OPENX_READX: \
+               file = &op->openxreadx.out.file; \
+               break; \
+       case RAW_OPEN_SMB2: \
+               file = &op->smb2.out.file; \
+               break; \
+       default: \
+               /* this must be a programmer error */ \
+               file = NULL; \
+               break; \
+       } \
+} while (0)
+       /* SMBNTCreateX, nttrans and generic interface */
        struct {
                enum smb_open_level level;
                struct {
@@ -1196,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;
@@ -1211,8 +1436,12 @@ 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, generic;
+       } ntcreatex, nttrans, generic;
 
        /* TRANS2_OPEN interface */
        struct {
@@ -1375,11 +1604,96 @@ union smb_open {
                        uint16_t nread;
                } out;
        } openxreadx;
+
+#define SMB2_CREATE_FLAG_REQUEST_OPLOCK           0x0100
+#define SMB2_CREATE_FLAG_REQUEST_EXCLUSIVE_OPLOCK 0x0800
+#define SMB2_CREATE_FLAG_GRANT_OPLOCK             0x0001
+#define SMB2_CREATE_FLAG_GRANT_EXCLUSIVE_OPLOCK   0x0080
+
+       /* SMB2 Create */
+       struct smb2_create {
+               enum smb_open_level level;
+               struct {
+                       /* static body buffer 56 (0x38) bytes */
+                       uint8_t  security_flags;      /* SMB2_SECURITY_* */
+                       uint8_t  oplock_level;        /* SMB2_OPLOCK_LEVEL_* */
+                       uint32_t impersonation_level; /* SMB2_IMPERSONATION_* */
+                       uint64_t create_flags;
+                       uint64_t reserved;
+                       uint32_t desired_access;
+                       uint32_t file_attributes;
+                       uint32_t share_access; /* NTCREATEX_SHARE_ACCESS_* */
+                       uint32_t create_disposition; /* NTCREATEX_DISP_* */
+                       uint32_t create_options; /* NTCREATEX_OPTIONS_* */
+
+                       /* uint16_t fname_ofs */
+                       /* uint16_t fname_size */
+                       /* uint32_t blob_ofs; */
+                       /* uint32_t blob_size; */
+
+                       /* dynamic body */
+                       const char *fname;
+
+                       /* 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;
+
+                       /* static body buffer 88 (0x58) bytes */
+                       /* uint16_t buffer_code;  0x59 = 0x58 + 1 */
+                       uint8_t oplock_level;
+                       uint8_t reserved;
+                       uint32_t create_action;
+                       NTTIME   create_time;
+                       NTTIME   access_time;
+                       NTTIME   write_time;
+                       NTTIME   change_time;
+                       uint64_t alloc_size;
+                       uint64_t size;
+                       uint32_t file_attr;
+                       uint32_t reserved2;
+                       /* struct smb2_handle handle;*/
+                       /* uint32_t blob_ofs; */
+                       /* uint32_t blob_size; */
+
+                       /* 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;
 };
 
 
 
-enum smb_read_level {RAW_READ_READBRAW, RAW_READ_LOCKREAD, RAW_READ_READ, RAW_READ_READX};
+enum smb_read_level {
+       RAW_READ_READBRAW,
+       RAW_READ_LOCKREAD,
+       RAW_READ_READ,
+       RAW_READ_READX,
+       RAW_READ_SMB2
+};
 
 #define RAW_READ_GENERIC RAW_READ_READX
 
@@ -1395,16 +1709,16 @@ 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;
+                       bool read_for_execute;
                } in;
                struct {
                        uint8_t *data;
                        uint16_t remaining;
                        uint16_t compaction_mode;
-                       uint16_t nread;
+                       uint32_t nread;
                } out;
        } readx, generic;
 
@@ -1454,12 +1768,52 @@ union smb_read {
                        uint16_t nread;
                } out;
        } read;
+
+       /* SMB2 Read */
+       struct smb2_read {
+               enum smb_read_level level;
+               struct {
+                       union smb_handle file;
+
+                       /* static body buffer 48 (0x30) bytes */
+                       /* uint16_t buffer_code;  0x31 = 0x30 + 1 */
+                       uint8_t _pad;
+                       uint8_t reserved;
+                       uint32_t length;
+                       uint64_t offset;
+                       /* struct smb2_handle handle; */
+                       uint32_t min_count;
+                       uint32_t channel;
+                       uint32_t remaining;
+                       /* the docs give no indication of what
+                          these channel variables are for */
+                       uint16_t channel_offset;
+                       uint16_t channel_length;
+               } in;
+               struct {
+                       /* static body buffer 16 (0x10) bytes */
+                       /* uint16_t buffer_code;  0x11 = 0x10 + 1 */
+                       /* uint8_t data_ofs; */
+                       /* uint8_t reserved; */
+                       /* uint32_t data_size; */
+                       uint32_t remaining;
+                       uint32_t reserved;
+
+                       /* dynamic body */
+                       DATA_BLOB data;
+               } out;
+       } smb2;
 };
 
 
-enum smb_write_level {RAW_WRITE_WRITEUNLOCK, RAW_WRITE_WRITE, 
-                     RAW_WRITE_WRITEX, RAW_WRITE_WRITECLOSE, 
-                     RAW_WRITE_SPLWRITE};
+enum smb_write_level {
+       RAW_WRITE_WRITEUNLOCK,
+       RAW_WRITE_WRITE,
+       RAW_WRITE_WRITEX,
+       RAW_WRITE_WRITECLOSE,
+       RAW_WRITE_SPLWRITE,
+       RAW_WRITE_SMB2
+};
 
 #define RAW_WRITE_GENERIC RAW_WRITE_WRITEX
 
@@ -1537,18 +1891,50 @@ union smb_write {
                        const uint8_t *data;
                } in;
        } splwrite;
+
+       /* SMB2 Write */
+       struct smb2_write {
+               enum smb_write_level level;
+               struct {
+                       union smb_handle file;
+
+                       /* static body buffer 48 (0x30) bytes */
+                       /* uint16_t buffer_code;  0x31 = 0x30 + 1 */
+                       /* uint16_t data_ofs; */
+                       /* uint32_t data_size; */
+                       uint64_t offset;
+                       /* struct smb2_handle handle; */
+                       uint64_t unknown1; /* 0xFFFFFFFFFFFFFFFF */
+                       uint64_t unknown2; /* 0xFFFFFFFFFFFFFFFF */
+
+                       /* dynamic body */
+                       DATA_BLOB data;
+               } in;
+               struct {
+                       /* static body buffer 17 (0x11) bytes */
+                       /* uint16_t buffer_code;  0x11 = 0x10 + 1*/
+                       uint16_t _pad;
+                       uint32_t nwritten;
+                       uint64_t unknown1; /* 0x0000000000000000 */
+               } out;
+       } smb2;
 };
 
 
-enum smb_lock_level {RAW_LOCK_LOCK, RAW_LOCK_UNLOCK, RAW_LOCK_LOCKX};
+enum smb_lock_level {
+       RAW_LOCK_LOCK,
+       RAW_LOCK_UNLOCK,
+       RAW_LOCK_LOCKX,
+       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 {
@@ -1558,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 {
@@ -1574,25 +1960,95 @@ union smb_lock {
                        uint32_t offset;
                } in;
        } lock, unlock;
-};
 
+       /* SMB2 Lock */
+       struct smb2_lock {
+               enum smb_lock_level level;
+               struct {
+                       union smb_handle file;
+
+                       /* static body buffer 48 (0x30) bytes */
+                       /* uint16_t buffer_code;  0x30 */
+                       uint16_t lock_count;
+                       uint32_t reserved;
+                       /* struct smb2_handle handle; */
+                       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_EXCLUSIVE       0x00000002
+#define SMB2_LOCK_FLAG_UNLOCK          0x00000004
+#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 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};
 
-#define RAW_CLOSE_GENERIC RAW_CLOSE_CLOSE
+enum smb_close_level {
+       RAW_CLOSE_CLOSE,
+       RAW_CLOSE_SPLCLOSE,
+       RAW_CLOSE_SMB2,
+       RAW_CLOSE_GENERIC,
+};
 
 /*
   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;
-       } close, generic;
+               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;
 
        /* SMBsplclose interface - empty! */
        struct {
@@ -1601,6 +2057,32 @@ union smb_close {
                        union smb_handle file;
                } in;
        } splclose;
+
+       /* SMB2 Close */
+       struct smb2_close {
+               enum smb_close_level level;
+               struct {
+                       union smb_handle file;
+
+                       /* static body buffer 24 (0x18) bytes */
+                       /* uint16_t buffer_code;  0x18 */
+                       uint16_t flags; /* SMB2_CLOSE_FLAGS_* */
+                       uint32_t _pad;
+               } in;
+               struct {
+                       /* static body buffer 60 (0x3C) bytes */
+                       /* uint16_t buffer_code;  0x3C */
+                       uint16_t flags;
+                       uint32_t _pad;
+                       NTTIME   create_time;
+                       NTTIME   access_time;
+                       NTTIME   write_time;
+                       NTTIME   change_time;
+                       uint64_t alloc_size;
+                       uint64_t size;
+                       uint32_t file_attr;
+               } out;
+       } smb2;
 };
 
 
@@ -1639,7 +2121,12 @@ union smb_lpq {
        } retq;
 };
 
-enum smb_ioctl_level {RAW_IOCTL_IOCTL, RAW_IOCTL_NTIOCTL};
+enum smb_ioctl_level {
+       RAW_IOCTL_IOCTL,
+       RAW_IOCTL_NTIOCTL,
+       RAW_IOCTL_SMB2,
+       RAW_IOCTL_SMB2_NO_HANDLE
+};
 
 /*
   union for ioctl() backend
@@ -1672,24 +2159,94 @@ union smb_ioctl {
                struct {
                        union smb_handle file;
                        uint32_t function;
-                       BOOL fsctl;
+                       bool fsctl;
                        uint8_t filter;
+                       uint32_t max_data;
+                       DATA_BLOB blob;
                } in;
                struct {
                        DATA_BLOB blob;
                } out;
        } ntioctl;
+
+       /* SMB2 Ioctl */
+       struct smb2_ioctl {
+               enum smb_ioctl_level level;
+               struct {
+                       union smb_handle file;
+
+                       /* static body buffer 56 (0x38) bytes */
+                       /* uint16_t buffer_code;  0x39 = 0x38 + 1 */
+                       uint16_t _pad;
+                       uint32_t function;
+                       /*struct smb2_handle handle;*/
+                       /* uint32_t out_ofs; */
+                       /* uint32_t out_size; */
+                       uint32_t unknown2;
+                       /* uint32_t in_ofs; */
+                       /* uint32_t in_size; */
+                       uint32_t max_response_size;
+                       uint64_t flags;
+
+                       /* dynamic body */
+                       DATA_BLOB out;
+                       DATA_BLOB in;
+               } in;
+               struct {
+                       union smb_handle file;
+
+                       /* static body buffer 48 (0x30) bytes */
+                       /* uint16_t buffer_code;  0x31 = 0x30 + 1 */
+                       uint16_t _pad;
+                       uint32_t function;
+                       /* struct smb2_handle handle; */
+                       /* uint32_t in_ofs; */
+                       /* uint32_t in_size; */
+                       /* uint32_t out_ofs; */
+                       /* uint32_t out_size; */
+                       uint32_t unknown2;
+                       uint32_t unknown3;
+
+                       /* dynamic body */
+                       DATA_BLOB in;
+                       DATA_BLOB out;
+               } out;
+       } smb2;
+};
+
+enum smb_flush_level {
+       RAW_FLUSH_FLUSH,
+       RAW_FLUSH_ALL,
+       RAW_FLUSH_SMB2
 };
 
-/* struct for SMBflush */
 union smb_flush {
+       /* struct for SMBflush */
        struct {
+               enum smb_flush_level level;
                struct {
                        union smb_handle file;
                } in;
        } flush, generic;
-};
 
+       /* SMBflush with 0xFFFF wildcard fnum */
+       struct {
+               enum smb_flush_level level;
+       } flush_all;
+
+       /* SMB2 Flush */
+       struct smb2_flush {
+               enum smb_flush_level level;
+               struct {
+                       union smb_handle file;
+                       uint16_t reserved1;
+                       uint32_t reserved2;
+               } in;
+               struct {
+                       uint16_t reserved;
+               } out;
+       } smb2;
+};
 
 /* struct for SMBcopy */
 struct smb_copy {
@@ -1735,66 +2292,113 @@ 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;
-               uint16_t *setup;
+               uint8_t  *setup;
                DATA_BLOB params;
                DATA_BLOB data;
        } in;
 
        struct {
-               uint8_t  setup_count;
-               uint16_t *setup;
+               uint8_t  setup_count; /* in units of 16 bit words */
+               uint8_t  *setup;
                DATA_BLOB params;
                DATA_BLOB data;
        } out;
 };
 
+enum smb_notify_level {
+       RAW_NOTIFY_NTTRANS,
+       RAW_NOTIFY_SMB2
+};
 
-/* struct for nttrans change notify call */
-struct smb_notify {
+union smb_notify {
+       /* struct for nttrans change notify call */
        struct {
-               union smb_handle file;
-               uint32_t buffer_size;
-               uint32_t completion_filter;
-               BOOL recursive;
-       } in;
+               enum smb_notify_level level;
 
-       struct {
-               uint32_t num_changes;
-               struct notify_changes {
-                       uint32_t action;
-                       struct smb_wire_string name;
-               } *changes;
-       } out;
+               struct {
+                       union smb_handle file;
+                       uint32_t buffer_size;
+                       uint32_t completion_filter;
+                       bool recursive;
+               } in;
+
+               struct {
+                       uint32_t num_changes;
+                       struct notify_changes {
+                               uint32_t action;
+                               struct smb_wire_string name;
+                       } *changes;
+               } out;
+       } nttrans;
+
+       struct smb2_notify {
+               enum smb_notify_level level;
+               
+               struct {
+                       union smb_handle file;
+                       /* static body buffer 32 (0x20) bytes */
+                       /* uint16_t buffer_code;  0x32 */
+                       uint16_t recursive;
+                       uint32_t buffer_size;
+                       /*struct  smb2_handle file;*/
+                       uint32_t completion_filter;
+                       uint32_t unknown;
+               } in;
+
+               struct {
+                       /* static body buffer 8 (0x08) bytes */
+                       /* uint16_t buffer_code; 0x09 = 0x08 + 1 */
+                       /* uint16_t blob_ofs; */
+                       /* uint16_t blob_size; */
+
+                       /* dynamic body */
+                       /*DATA_BLOB blob;*/
+
+                       /* DATA_BLOB content */
+                       uint32_t num_changes;
+                       struct notify_changes *changes;
+               } out;
+       } smb2;
 };
 
-enum smb_search_level {RAW_SEARCH_GENERIC                 = 0xF000, 
-                      RAW_SEARCH_SEARCH,                 /* SMBsearch */ 
-                      RAW_SEARCH_FFIRST,                 /* SMBffirst */ 
-                      RAW_SEARCH_FUNIQUE,                /* SMBfunique */ 
-                      RAW_SEARCH_STANDARD                = SMB_FIND_STANDARD,
-                      RAW_SEARCH_EA_SIZE                 = SMB_FIND_EA_SIZE,
-                      RAW_SEARCH_EA_LIST                 = SMB_FIND_EA_LIST,
-                      RAW_SEARCH_DIRECTORY_INFO          = SMB_FIND_DIRECTORY_INFO,
-                      RAW_SEARCH_FULL_DIRECTORY_INFO     = SMB_FIND_FULL_DIRECTORY_INFO,
-                      RAW_SEARCH_NAME_INFO               = SMB_FIND_NAME_INFO,
-                      RAW_SEARCH_BOTH_DIRECTORY_INFO     = SMB_FIND_BOTH_DIRECTORY_INFO,
-                      RAW_SEARCH_ID_FULL_DIRECTORY_INFO  = SMB_FIND_ID_FULL_DIRECTORY_INFO,
-                      RAW_SEARCH_ID_BOTH_DIRECTORY_INFO  = SMB_FIND_ID_BOTH_DIRECTORY_INFO,
-                      RAW_SEARCH_UNIX_INFO               = SMB_FIND_UNIX_INFO};
+enum smb_search_level {
+       RAW_SEARCH_SEARCH,      /* SMBsearch */ 
+       RAW_SEARCH_FFIRST,      /* SMBffirst */ 
+       RAW_SEARCH_FUNIQUE,     /* SMBfunique */
+       RAW_SEARCH_TRANS2,      /* SMBtrans2 */
+       RAW_SEARCH_SMB2         /* SMB2 Find */
+};
 
+enum smb_search_data_level {
+       RAW_SEARCH_DATA_GENERIC                 = 0x10000, /* only used in the smbcli_ code */
+       RAW_SEARCH_DATA_SEARCH,
+       RAW_SEARCH_DATA_STANDARD                = SMB_FIND_STANDARD,
+       RAW_SEARCH_DATA_EA_SIZE                 = SMB_FIND_EA_SIZE,
+       RAW_SEARCH_DATA_EA_LIST                 = SMB_FIND_EA_LIST,
+       RAW_SEARCH_DATA_DIRECTORY_INFO          = SMB_FIND_DIRECTORY_INFO,
+       RAW_SEARCH_DATA_FULL_DIRECTORY_INFO     = SMB_FIND_FULL_DIRECTORY_INFO,
+       RAW_SEARCH_DATA_NAME_INFO               = SMB_FIND_NAME_INFO,
+       RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO     = SMB_FIND_BOTH_DIRECTORY_INFO,
+       RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO  = SMB_FIND_ID_FULL_DIRECTORY_INFO,
+       RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO  = SMB_FIND_ID_BOTH_DIRECTORY_INFO,
+       RAW_SEARCH_DATA_UNIX_INFO               = SMB_FIND_UNIX_INFO,
+       RAW_SEARCH_DATA_UNIX_INFO2              = SMB_FIND_UNIX_INFO2
+};
        
 /* union for file search */
 union smb_search_first {
        struct {
                enum smb_search_level level;
+               enum smb_search_data_level data_level;
        } generic;
        
        /* search (old) findfirst interface. 
           Also used for ffirst and funique. */
        struct {
                enum smb_search_level level;
+               enum smb_search_data_level data_level;
        
                struct {
                        uint16_t max_count;
@@ -1809,6 +2413,7 @@ union smb_search_first {
        /* trans2 findfirst interface */
        struct {
                enum smb_search_level level;
+               enum smb_search_data_level data_level;
                
                struct {
                        uint16_t search_attrib;
@@ -1827,18 +2432,67 @@ union smb_search_first {
                        uint16_t end_of_search;
                } out;
        } t2ffirst;
+
+/*
+  SMB2 uses different level numbers for the same old SMB trans2 search levels
+*/
+#define SMB2_FIND_DIRECTORY_INFO         0x01
+#define SMB2_FIND_FULL_DIRECTORY_INFO    0x02
+#define SMB2_FIND_BOTH_DIRECTORY_INFO    0x03
+#define SMB2_FIND_NAME_INFO              0x0C
+#define SMB2_FIND_ID_BOTH_DIRECTORY_INFO 0x25
+#define SMB2_FIND_ID_FULL_DIRECTORY_INFO 0x26
+
+/* flags for SMB2 find */
+#define SMB2_CONTINUE_FLAG_RESTART    0x01
+#define SMB2_CONTINUE_FLAG_SINGLE     0x02
+#define SMB2_CONTINUE_FLAG_INDEX      0x04
+#define SMB2_CONTINUE_FLAG_REOPEN     0x10
+
+       /* SMB2 Find */
+       struct smb2_find {
+               enum smb_search_level level;
+               enum smb_search_data_level data_level;
+               struct {
+                       union smb_handle file;
+
+                       /* static body buffer 32 (0x20) bytes */
+                       /* uint16_t buffer_code;  0x21 = 0x20 + 1 */
+                       uint8_t level;
+                       uint8_t continue_flags; /* SMB2_CONTINUE_FLAG_* */
+                       uint32_t file_index; 
+                       /* struct smb2_handle handle; */
+                       /* uint16_t pattern_ofs; */
+                       /* uint16_t pattern_size; */
+                       uint32_t max_response_size;
+       
+                       /* dynamic body */
+                       const char *pattern;
+               } in;
+               struct {
+                       /* static body buffer 8 (0x08) bytes */
+                       /* uint16_t buffer_code;  0x08 */
+                       /* uint16_t blob_ofs; */
+                       /* uint32_t blob_size; */
+
+                       /* dynamic body */
+                       DATA_BLOB blob;
+               } out;
+       } smb2;
 };
 
 /* union for file search continue */
 union smb_search_next {
        struct {
                enum smb_search_level level;
+               enum smb_search_data_level data_level;
        } generic;
 
        /* search (old) findnext interface. Also used
           for ffirst when continuing */
        struct {
                enum smb_search_level level;
+               enum smb_search_data_level data_level;
        
                struct {
                        uint16_t max_count;
@@ -1859,6 +2513,7 @@ union smb_search_next {
        /* trans2 findnext interface */
        struct {
                enum smb_search_level level;
+               enum smb_search_data_level data_level;
                
                struct {
                        uint16_t handle;
@@ -1876,11 +2531,17 @@ union smb_search_next {
                        uint16_t end_of_search;
                } out;
        } t2fnext;
+
+       /* SMB2 Find */
+       struct smb2_find smb2;
 };
 
 /* union for search reply file data */
 union smb_search_data {
-       /* search (old) findfirst */
+       /*
+        * search (old) findfirst 
+        * RAW_SEARCH_DATA_SEARCH
+        */
        struct {
                uint16_t attrib;
                time_t write_time;
@@ -1888,8 +2549,8 @@ union smb_search_data {
                struct smb_search_id id;
                const char *name;
        } search;
-       
-       /* trans2 findfirst RAW_SEARCH_STANDARD level */
+
+       /* trans2 findfirst RAW_SEARCH_DATA_STANDARD level */
        struct {
                uint32_t resume_key;
                time_t create_time;
@@ -1901,7 +2562,7 @@ union smb_search_data {
                struct smb_wire_string name;
        } standard;
 
-       /* trans2 findfirst RAW_SEARCH_EA_SIZE level */
+       /* trans2 findfirst RAW_SEARCH_DATA_EA_SIZE level */
        struct {
                uint32_t resume_key;
                time_t create_time;
@@ -1914,7 +2575,7 @@ union smb_search_data {
                struct smb_wire_string name;
        } ea_size;
 
-       /* trans2 findfirst RAW_SEARCH_EA_LIST level */
+       /* trans2 findfirst RAW_SEARCH_DATA_EA_LIST level */
        struct {
                uint32_t resume_key;
                time_t create_time;
@@ -1927,7 +2588,7 @@ union smb_search_data {
                struct smb_wire_string name;
        } ea_list;
 
-       /* RAW_SEARCH_DIRECTORY_INFO interface */
+       /* RAW_SEARCH_DATA_DIRECTORY_INFO interface */
        struct {
                uint32_t file_index;
                NTTIME create_time;
@@ -1940,7 +2601,7 @@ union smb_search_data {
                struct smb_wire_string name;
        } directory_info;
 
-       /* RAW_SEARCH_FULL_DIRECTORY_INFO interface */
+       /* RAW_SEARCH_DATA_FULL_DIRECTORY_INFO interface */
        struct {
                uint32_t file_index;
                NTTIME create_time;
@@ -1954,13 +2615,13 @@ union smb_search_data {
                struct smb_wire_string name;
        } full_directory_info;
 
-       /* RAW_SEARCH_NAME_INFO interface */
+       /* RAW_SEARCH_DATA_NAME_INFO interface */
        struct {
                uint32_t file_index;
                struct smb_wire_string name;
        } name_info;
 
-       /* RAW_SEARCH_BOTH_DIRECTORY_INFO interface */
+       /* RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO interface */
        struct {
                uint32_t file_index;
                NTTIME create_time;
@@ -1975,7 +2636,7 @@ union smb_search_data {
                struct smb_wire_string name;
        } both_directory_info;
 
-       /* RAW_SEARCH_ID_FULL_DIRECTORY_INFO interface */
+       /* RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO interface */
        struct {
                uint32_t file_index;
                NTTIME create_time;
@@ -1990,7 +2651,7 @@ union smb_search_data {
                struct smb_wire_string name;
        } id_full_directory_info;
 
-       /* RAW_SEARCH_ID_BOTH_DIRECTORY_INFO interface */
+       /* RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO interface */
        struct {
                uint32_t file_index;
                NTTIME create_time;
@@ -2006,7 +2667,7 @@ union smb_search_data {
                struct smb_wire_string name;
        } id_both_directory_info;
 
-       /* RAW_SEARCH_UNIX_INFO interface */
+       /* RAW_SEARCH_DATA_UNIX_INFO interface */
        struct {
                uint32_t file_index;
                uint64_t size;
@@ -2024,8 +2685,32 @@ union smb_search_data {
                uint64_t nlink;         
                const char *name;
        } unix_info;
+
+       /* RAW_SEARCH_DATA_UNIX_INFO2 interface */
+       struct {
+               uint32_t file_index;
+               uint64_t end_of_file;
+               uint64_t num_bytes;
+               NTTIME status_change_time;
+               NTTIME access_time;
+               NTTIME change_time;
+               uint64_t uid;
+               uint64_t gid;
+               uint32_t file_type;
+               uint64_t dev_major;
+               uint64_t dev_minor;
+               uint64_t unique_id;
+               uint64_t permissions;
+               uint64_t nlink;
+               NTTIME create_time;
+               uint32_t file_flags;
+               uint32_t flags_mask;
+               struct smb_wire_string name;
+       } unix_info2;
 };
 
+/* Callback function passed to the raw search interface. */
+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};
 
@@ -2057,4 +2742,37 @@ union smb_search_close {
        } findclose;
 };
 
+
+/*
+  struct for SMBecho call
+*/
+struct smb_echo {
+       struct {
+               uint16_t repeat_count;
+               uint16_t size;
+               uint8_t *data;
+       } in;
+       struct {
+               uint16_t count;
+               uint16_t sequence_number;
+               uint16_t size;
+               uint8_t *data;
+       } out;
+};
+
+/*
+  struct for shadow copy volumes
+ */
+struct smb_shadow_copy {
+       struct {
+               union smb_handle file;
+               uint32_t max_data;
+       } in;
+       struct {
+               uint32_t num_volumes;
+               uint32_t num_names;
+               const char **names;
+       } out;
+};
+
 #endif /* __LIBCLI_RAW_INTERFACES_H__ */