*** empty log message ***
[samba.git] / source / include / smb.h
index 87fcb22cac939bfa7b007b4a97b656e86d64806c..e6c0565b056955356fa46b62ab9faf6c6e7193cf 100644 (file)
 #ifndef _SMB_H
 #define _SMB_H
 
-#ifndef MAX_CONNECTIONS
-#define MAX_CONNECTIONS 127
-#endif
-
-#ifndef MAX_OPEN_FILES
-#define MAX_OPEN_FILES 50
-#endif
-
-#ifndef GUEST_ACCOUNT
-#define GUEST_ACCOUNT "nobody"
-#endif
-
 #define BUFFER_SIZE (0xFFFF)
 #define SAFETY_MARGIN 1024
 
 #define SHMEM_SIZE 102400
 #endif
 
-/* Default number of hash buckets used in shared memory share mode */
-#ifndef SHMEM_HASH_SIZE
-#define SHMEM_HASH_SIZE 113
-#endif
-
 #define NMB_PORT 137
 #define DGRAM_PORT 138
 #define SMB_PORT 139
 
 typedef int BOOL;
 
-/* offset in shared memory */
-typedef  int smb_shm_offset_t;
-#define NULL_OFFSET (smb_shm_offset_t)(0)
-
+/* limiting size of ipc replies */
+#define REALLOC(ptr,size) Realloc(ptr,MAX((size),4*1024))
 
 /*
    Samba needs type definitions for int16, int32, uint16 and uint32.
@@ -156,10 +137,11 @@ implemented */
 #define DENY_FCB 7
 
 /* share types */
-#define STYPE_DISKTREE 0       /* Disk drive */
-#define STYPE_PRINTQ   1       /* Spooler queue */
-#define STYPE_DEVICE   2       /* Serial device */
-#define STYPE_IPC      3       /* Interprocess communication (IPC) */
+#define STYPE_DISKTREE  0      /* Disk drive */
+#define STYPE_PRINTQ    1      /* Spooler queue */
+#define STYPE_DEVICE    2      /* Serial device */
+#define STYPE_IPC       3      /* Interprocess communication (IPC) */
+#define STYPE_HIDDEN    0x80000000 /* share is a hidden one (ends with $) */
 
 /* SMB X/Open error codes for the ERRdos error class */
 #define ERRbadfunc 1 /* Invalid function (or system call) */
@@ -258,8 +240,27 @@ typedef char fstring[128];
 typedef fstring string;
 
 
+/* pipe strings */
+#define PIPE_LANMAN   "\\PIPE\\LANMAN"
+#define PIPE_SRVSVC   "\\PIPE\\srvsvc"
+#define PIPE_SAMR     "\\PIPE\\samr"
+#define PIPE_WKSSVC   "\\PIPE\\wkssvc"
+#define PIPE_NETLOGON "\\PIPE\\NETLOGON"
+#define PIPE_NTLSA    "\\PIPE\\ntlsa"
+#define PIPE_NTSVCS   "\\PIPE\\ntsvcs"
+#define PIPE_LSASS    "\\PIPE\\lsass"
+#define PIPE_LSARPC   "\\PIPE\\lsarpc"
+
 /* NETLOGON opcodes and data structures */
 
+enum RPC_PKT_TYPE
+{
+       RPC_REQUEST = 0x00,
+       RPC_RESPONSE = 0x02,
+       RPC_BIND     = 0x0B,
+       RPC_BINDACK  = 0x0C
+};
+
 #define NET_QUERYFORPDC             7 /* Query for PDC */
 #define NET_QUERYFORPDC_R   12 /* Response to Query for PDC */
 #define NET_SAMLOGON        18
@@ -278,20 +279,60 @@ typedef fstring string;
 #define ACB_PWNOEXP      /* 1 = User password does not expire */
 #define ACB_AUTOLOCK     /* 1 = Account auto locked */
 
+#define SAMR_CLOSE          0x01
+#define SAMR_OPEN_SECRET    0x07
+#define SAMR_LOOKUP_RIDS    0x11
+#define SAMR_UNKNOWN_3      0x03
+#define SAMR_UNKNOWN_22     0x22
+#define SAMR_UNKNOWN_24     0x24
+#define SAMR_UNKNOWN_34     0x34
+#define SAMR_OPEN_POLICY    0x39
+
 #define LSA_OPENPOLICY      0x2c
 #define LSA_QUERYINFOPOLICY 0x07
 #define LSA_ENUMTRUSTDOM    0x0d
 #define LSA_REQCHAL         0x04
-#define LSA_SVRPWSET        0x06
+#define LSA_SRVPWSET        0x06
 #define LSA_SAMLOGON        0x02
+#define LSA_SAMLOGOFF       0x03
 #define LSA_AUTH2           0x0f
 #define LSA_CLOSE           0x00
 
-/* unknown .... */
+/* XXXX these are here to get a compile! */
+
 #define LSA_OPENSECRET      0xFF
 #define LSA_LOOKUPSIDS      0xFE
-#define LSA_LOOKUPNAMES     0xFD
-#define LSA_SAMLOGOFF       0xFC
+#define LSA_LOOKUPRIDS      0xFD
+#define LSA_LOOKUPNAMES     0xFC
+
+/* srvsvc pipe */
+#define NETSERVERGETINFO 0x15
+#define NETSHAREENUM     0x0f
+
+/* well-known RIDs - Relative IDs */
+
+/* RIDs - Well-known users ... */
+#define DOMAIN_USER_RID_ADMIN          (0x000001F4L)
+#define DOMAIN_USER_RID_GUEST          (0x000001F5L)
+
+/* RIDs - well-known groups ... */
+#define DOMAIN_GROUP_RID_ADMINS        (0x00000200L)
+#define DOMAIN_GROUP_RID_USERS         (0x00000201L)
+#define DOMAIN_GROUP_RID_GUESTS        (0x00000202L)
+
+/* RIDs - well-known aliases ... */
+#define DOMAIN_ALIAS_RID_ADMINS        (0x00000220L)
+#define DOMAIN_ALIAS_RID_USERS         (0x00000221L)
+#define DOMAIN_ALIAS_RID_GUESTS        (0x00000222L)
+#define DOMAIN_ALIAS_RID_POWER_USERS   (0x00000223L)
+
+#define DOMAIN_ALIAS_RID_ACCOUNT_OPS   (0x00000224L)
+#define DOMAIN_ALIAS_RID_SYSTEM_OPS    (0x00000225L)
+#define DOMAIN_ALIAS_RID_PRINT_OPS     (0x00000226L)
+#define DOMAIN_ALIAS_RID_BACKUP_OPS    (0x00000227L)
+
+#define DOMAIN_ALIAS_RID_REPLICATOR    (0x00000228L)
+
 
 
 /* 32 bit time (sec) since 01jan1970 - cifs6.txt, section 3.5, page 30 */
@@ -310,15 +351,15 @@ typedef struct nttime_info
 } NTTIME;
  
 
-#define MAXSUBAUTHS 10 /* max sub authorities in a SID */
+#define MAXSUBAUTHS 15 /* max sub authorities in a SID */
 
 /* DOM_SID - security id */
 typedef struct sid_info
 {
-  uint8  sid_no;                  /* SID revision number */
+  uint8  sid_rev_num;             /* SID revision number */
   uint8  num_auths;               /* number of sub-authorities */
   uint8  id_auth[6];              /* Identifier Authority */
-  uint16 sub_auths[MAXSUBAUTHS]; /* pointer to sub-authorities. */
+  uint32 sub_auths[MAXSUBAUTHS];  /* pointer to sub-authorities. */
 
 } DOM_SID;
 
@@ -370,16 +411,36 @@ typedef struct domsid2_info
 
 } DOM_SID2;
 
-/* DOM_RID2 - domain RID structure */
+/* DOM_RID2 - domain RID structure for ntlsa pipe */
 typedef struct domrid2_info
 {
   uint32 type; /* value is 5 */
-  uint32 undoc; /* value is 5 */
+  uint32 undoc; /* value is non-zero */
   uint32 rid;
   uint32 rid_idx; /* don't know what this is */
 
 } DOM_RID2;
 
+/* DOM_RID3 - domain RID structure for samr pipe */
+typedef struct domrid3_info
+{
+  uint32 rid;        /* domain-relative (to a SID) id */
+  uint32 type1;      /* value is 0x1 */
+  uint32 ptr_type;   /* undocumented pointer */
+  uint32 type2;      /* value is 0x1 */
+
+} DOM_RID3;
+
+/* DOM_CLNT_SRV - client / server names */
+typedef struct clnt_srv_info
+{
+  uint32  undoc_buffer; /* undocumented 32 bit buffer pointer */
+  UNISTR2 uni_logon_srv; /* logon server name */
+  uint32  undoc_buffer2; /* undocumented 32 bit buffer pointer */
+  UNISTR2 uni_comp_name; /* client machine name */
+
+} DOM_CLNT_SRV;
+
 /* DOM_LOG_INFO - login info */
 typedef struct log_info
 {
@@ -394,8 +455,7 @@ typedef struct log_info
 /* DOM_CHAL - challenge info */
 typedef struct chal_info
 {
-  uint8 data[8]; /* credentials */
-
+  uchar data[8]; /* credentials */
 } DOM_CHAL;
 
 /* DOM_CREDs - timestamped client or server credentials */
@@ -414,6 +474,15 @@ typedef struct clnt_info
 
 } DOM_CLNT_INFO;
 
+/* DOM_CLNT_INFO2 - client info */
+typedef struct clnt_info2
+{
+  DOM_CLNT_SRV login;
+  uint32        ptr_cred;
+  DOM_CRED      cred;
+
+} DOM_CLNT_INFO2;
+
 /* DOM_LOGON_ID - logon id */
 typedef struct logon_info
 {
@@ -433,30 +502,32 @@ typedef struct arc4_owf_info
 /* DOM_ID_INFO_1 */
 typedef struct id_info_1
 {
+  uint32            ptr_id_info1;        /* pointer to id_info_1 */
   UNIHDR            hdr_domain_name;     /* domain name unicode header */
-  uint32            param;               /* param control */
+  uint32            param_ctrl;          /* param control */
   DOM_LOGON_ID      logon_id;            /* logon ID */
   UNIHDR            hdr_user_name;       /* user name unicode header */
-  UNIHDR            hdr_workgroup_name;  /* workgroup name unicode header */
+  UNIHDR            hdr_wksta_name;      /* workgroup name unicode header */
   ARC4_OWF          arc4_lm_owf;         /* arc4 LM OWF Password */
   ARC4_OWF          arc4_nt_owf;         /* arc4 NT OWF Password */
   UNISTR2           uni_domain_name;     /* domain name unicode string */
   UNISTR2           uni_user_name;       /* user name unicode string */
-  UNISTR2           uni_workgroup_name;  /* workgroup name unicode string */
+  UNISTR2           uni_wksta_name;      /* workgroup name unicode string */
 
 } DOM_ID_INFO_1;
 
 /* SAM_INFO - sam logon/off id structure */
 typedef struct sam_info
 {
-  DOM_CLNT_INFO client;
-  DOM_CRED      rtn_cred; /* return credentials */
-  uint16        logon_level;
-  uint32        auth_level; /* undocumented */
+  DOM_CLNT_INFO2 client;
+  uint32         ptr_rtn_cred; /* pointer to return credentials */
+  DOM_CRED       rtn_cred; /* return credentials */
+  uint16         logon_level;
+  uint16         switch_value;
   
   union
   {
-    DOM_ID_INFO_1 id1; /* auth-level 1 */
+    DOM_ID_INFO_1 *id1; /* auth-level 1 */
 
   } auth;
   
@@ -465,7 +536,7 @@ typedef struct sam_info
 /* DOM_GID - group id + user attributes */
 typedef struct gid_info
 {
-  uint32 gid;  /* group id */
+  uint32 g_rid;  /* a group RID */
   uint32 attr;
 
 } DOM_GID;
@@ -477,22 +548,108 @@ typedef struct rpc_hdr_info
   uint8  minor; /* 0 - RPC minor version */
   uint8  pkt_type; /* 2 - RPC response packet */
   uint8  frag; /* 3 - first frag + last frag */
-  uint32 pack_type; /* 0x0000 0010 - packed data representation */
+  uint32 pack_type; /* 0x1000 0000 - packed data representation */
   uint16 frag_len; /* fragment length - data size (bytes) inc header and tail. */
   uint16 auth_len; /* 0 - authentication length  */
   uint32 call_id; /* call identifier.  matches 12th uint32 of incoming RPC data. */
+
+} RPC_HDR;
+
+/* RPC_HDR_RR - ms request / response rpc header */
+typedef struct rpc_hdr_rr_info
+{
+  RPC_HDR hdr;
+
   uint32 alloc_hint; /* allocation hint - data size (bytes) minus header and tail. */
   uint16 context_id; /* 0 - presentation context identifier */
   uint8  cancel_count; /* 0 - cancel count */
-  uint8  reserved; /* 0 - reserved */
+  uint8  opnum; /* request: 0 - reserved.  response: opnum */
+
+} RPC_HDR_RR;
+
+/* the interfaces are numbered. as yet I haven't seen more than one interface
+ * used on the same pipe name
+ * srvsvc
+ *   abstract (0x4B324FC8, 0x01D31670, 0x475A7812, 0x88E16EBF, 0x00000003)
+ *   transfer (0x8A885D04, 0x11C91CEB, 0x0008E89F, 0x6048102B, 0x00000002)
+ */
+/* RPC_IFACE */
+typedef struct rpc_iface_info
+{
+  uint8 data[16];    /* 16 bytes of number */
+  uint32 version;    /* the interface number */
+
+} RPC_IFACE;
+
+
+/* this seems to be the same string name depending on the name of the pipe,
+ * but is more likely to be linked to the interface name
+ * "srvsvc", "\\PIPE\\ntsvcs"
+ * "samr", "\\PIPE\\lsass"
+ * "wkssvc", "\\PIPE\\wksvcs"
+ * "NETLOGON", "\\PIPE\\NETLOGON"
+ */
+/* RPC_ADDR_STR */
+typedef struct rpc_addr_info
+{
+  uint16 len;   /* length of the string including null terminator */
+  fstring str; /* the string above in single byte, null terminated form */
+
+} RPC_ADDR_STR;
+
+/* RPC_HDR_BBA */
+typedef struct rpc_hdr_bba_info
+{
+  uint16 max_tsize;       /* maximum transmission fragment size (0x1630) */
+  uint16 max_rsize;       /* max receive fragment size (0x1630) */
+  uint32 assoc_gid;       /* associated group id (0x0) */
+
+} RPC_HDR_BBA;
+
+/* RPC_BIND_REQ - ms req bind */
+typedef struct rpc_bind_req_info
+{
+  RPC_HDR_BBA bba;
+
+  uint32 num_elements;    /* the number of elements (0x1) */
+  uint16 context_id;      /* presentation context identifier (0x0) */
+  uint8 num_syntaxes;     /* the number of syntaxes (has always been 1?)(0x1) */
+
+  RPC_IFACE abstract;     /* num and vers. of interface client is using */
+  RPC_IFACE transfer;     /* num and vers. of interface to use for replies */
+  
+} RPC_HDR_RB;
+
+/* RPC_RESULTS - can only cope with one reason, right now... */
+typedef struct rpc_results_info
+{
+/* uint8[] # 4-byte alignment padding, against SMB header */
+
+  uint8 num_results; /* the number of results (0x01) */
+
+/* uint8[] # 4-byte alignment padding, against SMB header */
+
+  uint16 result; /* result (0x00 = accept) */
+  uint16 reason; /* reason (0x00 = no reason specified) */
+
+} RPC_RESULTS;
+
+/* RPC_HDR_BA */
+typedef struct rpc_hdr_ba_info
+{
+  RPC_HDR_BBA bba;
+
+  RPC_ADDR_STR addr    ;  /* the secondary address string, as described earlier */
+  RPC_RESULTS  res     ; /* results and reasons */
+  RPC_IFACE    transfer; /* the transfer syntax from the request */
+
+} RPC_HDR_BA;
 
-} RPC_HDR;
 
 /* DOM_QUERY - info class 3 and 5 LSA Query response */
 typedef struct dom_query_info
 {
   uint16 uni_dom_max_len; /* domain name string length * 2 */
-  uint16 padding;         /* 2 padding bytes? */
   uint16 uni_dom_str_len; /* domain name string length * 2 */
   uint32 buffer_dom_name; /* undocumented domain name string buffer pointer */
   uint32 buffer_dom_sid; /* undocumented domain SID string buffer pointer */
@@ -514,6 +671,28 @@ typedef struct lsa_policy_info
 
 } LSA_POL_HND;
 
+/* OBJ_ATTR (object attributes) */
+typedef struct object_attributes_info
+{
+       uint32 len;          /* 0x18 - length (in bytes) inc. the length field. */
+       uint32 ptr_root_dir; /* 0 - root directory (pointer) */
+       uint32 ptr_obj_name; /* 0 - object name (pointer) */
+       uint32 attributes;   /* 0 - attributes (undocumented) */
+       uint32 ptr_sec_desc; /* 0 - security descriptior (pointer) */
+       uint32 sec_qos;      /* 0 - security quality of service */
+
+} LSA_OBJ_ATTR;
+
+/* LSA_Q_OPEN_POL - LSA Query Open Policy */
+typedef struct lsa_q_open_pol_info
+{
+       uint32       ptr;             /* undocumented buffer pointer */
+       UNISTR2      uni_server_name; /* server name, starting with two '\'s */
+       LSA_OBJ_ATTR attr           ; /* object attributes */
+
+       uint32 des_access; /* desired access attributes */
+
+} LSA_Q_OPEN_POL;
 
 /* LSA_R_OPEN_POL - response to LSA Open Policy */
 typedef struct lsa_r_open_pol_info
@@ -542,12 +721,48 @@ typedef struct lsa_r_query_info
     {
         DOM_QUERY_3 id3;
                DOM_QUERY_5 id5;
+
     } dom;
 
-  uint32 status; /* return code */
+       uint32 status; /* return code */
 
 } LSA_R_QUERY_INFO;
 
+/* LSA_Q_ENUM_TRUST_DOM - LSA enumerate trusted domains */
+typedef struct lsa_enum_trust_dom_info
+{
+       LSA_POL_HND pol; /* policy handle */
+    uint32 enum_context; /* enumeration context handle */
+    uint32 preferred_len; /* preferred maximum length */
+
+} LSA_Q_ENUM_TRUST_DOM;
+
+/* LSA_R_ENUM_TRUST_DOM - response to LSA enumerate trusted domains */
+typedef struct lsa_r_enum_trust_dom_info
+{
+       LSA_POL_HND pol; /* policy handle */
+
+    uint32 status; /* return code */
+
+} LSA_R_ENUM_TRUST_DOM;
+
+/* LSA_Q_CLOSE */
+typedef struct lsa_q_close_info
+{
+       LSA_POL_HND pol; /* policy handle */
+
+} LSA_Q_CLOSE;
+
+/* LSA_R_CLOSE */
+typedef struct lsa_r_close_info
+{
+       LSA_POL_HND pol; /* policy handle.  should be all zeros. */
+
+       uint32 status; /* return code */
+
+} LSA_R_CLOSE;
+
+
 #define MAX_REF_DOMAINS 10
 
 /* DOM_R_REF */
@@ -624,7 +839,7 @@ typedef struct lsa_q_lookup_rids
 
 } LSA_Q_LOOKUP_RIDS;
 
-/* LSA_R_LOOKUP_RIDS - response to LSA Lookup Names */
+/* LSA_R_LOOKUP_RIDS - response to LSA Lookup RIDs by name */
 typedef struct lsa_r_lookup_rids
 {
     DOM_R_REF dom_ref; /* domain reference info */
@@ -718,7 +933,7 @@ typedef struct lsa_r_srv_pwset_info
 /* LSA_USER_INFO */
 typedef struct lsa_q_user_info
 {
-       uint32 undoc_buffer;
+       uint32 ptr_user_info;
 
        NTTIME logon_time;            /* logon time */
        NTTIME logoff_time;           /* logoff time */
@@ -743,13 +958,13 @@ typedef struct lsa_q_user_info
        uint32 buffer_groups; /* undocumented buffer pointer to groups. */
        uint32 user_flgs;     /* user flags */
 
-       char sess_key[16]; /* unused user session key */
+       char user_sess_key[16]; /* unused user session key */
 
        UNIHDR hdr_logon_srv; /* logon server unicode string header */
        UNIHDR hdr_logon_dom; /* logon domain unicode string header */
 
        uint32 buffer_dom_id; /* undocumented logon domain id pointer */
-       char padding[40];    /* unused padding bytes? */
+       char padding[40];    /* unused padding bytes.  expansion room */
 
        uint32 num_other_sids; /* 0 - num_sids */
        uint32 buffer_other_sids; /* NULL - undocumented pointer to SIDs. */
@@ -786,7 +1001,7 @@ typedef struct lsa_r_sam_logon_info
     uint32 buffer_creds; /* undocumented buffer pointer */
     DOM_CRED srv_creds; /* server credentials.  server time stamp appears to be ignored. */
     
-    uint32 buffer_user;
+       uint16 switch_value; /* 3 - indicates type of USER INFO */
     LSA_USER_INFO *user;
 
     uint32 auth_resp; /* 1 - Authoritative response; 0 - Non-Auth? */
@@ -813,68 +1028,309 @@ typedef struct lsa_r_sam_logoff_info
 
 } LSA_R_SAM_LOGOFF;
 
-/*
 
-Yet to be turned into structures:
-
-6) \\MAILSLOT\NET\NTLOGON
--------------------------
-
-6.1) Query for PDC
-------------------
-
-Request:
-
-    uint16         0x0007 - Query for PDC
-    STR            machine name
-    STR            response mailslot
-    uint8[]        padding to 2-byte align with start of mailslot.
-    UNISTR         machine name
-    uint32         NTversion
-    uint16         LMNTtoken
-    uint16         LM20token
-
-Response:
-
-    uint16         0x000A - Respose to Query for PDC
-    STR            machine name (in uppercase)
-    uint8[]        padding to 2-byte align with start of mailslot.
-    UNISTR         machine name
-    UNISTR         domain name
-    uint32         NTversion (same as received in request)
-    uint16         LMNTtoken (same as received in request)
-    uint16         LM20token (same as received in request)
-
-
-6.2) SAM Logon
---------------
-
-Request:
-
-    uint16         0x0012 - SAM Logon
-    uint16         request count
-    UNISTR         machine name
-    UNISTR         user name
-    STR            response mailslot
-    uint32         alloweable account
-    uint32         domain SID size
-    char[sid_size] domain SID, of sid_size bytes.
-    uint8[]        ???? padding to 4? 2? -byte align with start of mailslot.
-    uint32         NTversion
-    uint16         LMNTtoken
-    uint16         LM20token
-    
-Response:
+/* SH_INFO_1 (pointers to level 1 share info strings) */
+typedef struct ptr_share_info1
+{
+       uint32 ptr_netname; /* pointer to net name. */
+       uint32 type;        /* type of share.  0 - undocumented. */
+       uint32 ptr_remark;  /* pointer to comment. */
 
-    uint16         0x0013 - Response to SAM Logon
-    UNISTR         machine name
-    UNISTR         user name - workstation trust account
-    UNISTR         domain name 
-    uint32         NTversion
-    uint16         LMNTtoken
-    uint16         LM20token
+} SH_INFO_1;
 
-*/
+/* SH_INFO_1_STR (level 1 share info strings) */
+typedef struct str_share_info1
+{
+       UNISTR2 uni_netname; /* unicode string of net name */
+       UNISTR2 uni_remark;  /* unicode string of comment. */
+
+} SH_INFO_1_STR;
+
+/* oops - this is going to take up a *massive* amount of stack. */
+/* the UNISTR2s already have 1024 uint16 chars in them... */
+#define MAX_SHARE_ENTRIES 32
+
+/* SHARE_INFO_1_CONTAINER  */
+typedef struct share_info_ctr
+{
+       uint32 num_entries_read;                     /* EntriesRead */
+       uint32 ptr_share_info;                       /* Buffer */
+       uint32 num_entries_read2;                    /* EntriesRead */
+       SH_INFO_1     info_1    [MAX_SHARE_ENTRIES]; /* share entry pointers */
+       SH_INFO_1_STR info_1_str[MAX_SHARE_ENTRIES]; /* share entry strings */
+       uint32 num_entries_read3;                    /* EntriesRead2 */
+       uint32 padding;                              /* padding */
+
+} SHARE_INFO_1_CTR;
+
+
+/* SRV_Q_NET_SHARE_ENUM */
+typedef struct q_net_share_enum_info
+{
+       uint32 ptr_srv_name;         /* pointer (to server name?) */
+       UNISTR2 uni_srv_name;        /* server name */
+
+       uint32 share_level;          /* share level */
+       uint32 switch_value;         /* switch value */
+
+       uint32 ptr_share_info;       /* pointer to SHARE_INFO_1_CTR */
+
+       union
+    {
+               SHARE_INFO_1_CTR info1; /* share info with 0 entries */
+
+    } share;
+
+       uint32 preferred_len;        /* preferred maximum length (0xffff ffff) */
+
+} SRV_Q_NET_SHARE_ENUM;
+
+
+/* SRV_R_NET_SHARE_ENUM */
+typedef struct r_net_share_enum_info
+{
+       uint32 share_level;          /* share level */
+       uint32 switch_value;         /* switch value */
+
+       uint32 ptr_share_info;       /* pointer to SHARE_INFO_1_CTR */
+       union
+    {
+               SHARE_INFO_1_CTR info1; /* share info container */
+
+    } share;
+
+       uint32 status;               /* return status */
+
+} SRV_R_NET_SHARE_ENUM;
+
+
+/* SAMR_Q_CLOSE - probably a policy handle close */
+typedef struct q_samr_close_info
+{
+    LSA_POL_HND pol;          /* policy handle */
+
+} SAMR_Q_CLOSE;
+
+
+/* SAMR_R_CLOSE - probably a policy handle close */
+typedef struct r_samr_close_info
+{
+    LSA_POL_HND pol;       /* policy handle */
+       uint32 status;         /* return status */
+
+} SAMR_R_CLOSE;
+
+
+/****************************************************************************
+SAMR_Q_OPEN_SECRET - unknown_0 values seen associated with SIDs:
+
+0x0000 0200 and a specific   domain sid - S-1-5-21-44c01ca6-797e5c3d-33f83fd0
+0x0000 0280 and a well-known domain sid - S-1-5-20
+0x2000 0000 and a well-known domain sid - S-1-5-20
+0x2000 0000 and a specific   domain sid - S-1-5-21-44c01ca6-797e5c3d-33f83fd0
+*****************************************************************************/
+
+/* SAMR_Q_OPEN_SECRET - probably an open secret */
+typedef struct q_samr_open_secret_info
+{
+    LSA_POL_HND pol;          /* policy handle */
+       uint32 unknown_0;         /* 0x2000 0000; 0x0000 0211; 0x0000 0280; 0x0000 0200 - unknown */
+       DOM_SID dom_sid;          /* domain SID */
+
+} SAMR_Q_OPEN_SECRET;
+
+
+/* SAMR_R_OPEN_SECRET - probably an open */
+typedef struct r_samr_open_secret_info
+{
+    LSA_POL_HND pol;       /* policy handle associated with the SID */
+       uint32 status;         /* return status */
+
+} SAMR_R_OPEN_SECRET;
+
+
+/****************************************************************************
+SAMR_Q_LOOKUP_RIDS - do a conversion (only one!) from name to RID.
+
+the policy handle allocated by an "samr open secret" call is associated
+with a SID.  this policy handle is what is queried here, *not* the SID
+itself.  the response to the lookup rids is relative to this SID.
+*****************************************************************************/
+/* SAMR_Q_LOOKUP_RIDS - probably a "read SAM entry" */
+typedef struct q_samr_lookup_names_info
+{
+    LSA_POL_HND pol;             /* policy handle */
+
+       uint32 num_rids1;            /* 1          - number of rids being looked up */
+       uint32 rid;                  /* 0000 03e8  - RID of the server being queried? */
+       uint32 ptr;                  /* 0          - 32 bit unknown */
+       uint32 num_rids2;            /* 1          - number of rids being looked up */
+
+       UNIHDR  hdr_mach_acct;       /* unicode machine account name header */
+       UNISTR2 uni_mach_acct;       /* unicode machine account name */
+
+} SAMR_Q_LOOKUP_RIDS;
+
+
+/* SAMR_R_LOOKUP_RIDS - probably an open */
+typedef struct r_samr_lookup_names_info
+{
+       uint32 num_entries;
+       uint32 undoc_buffer; /* undocumented buffer pointer */
+
+       uint32 num_entries2; 
+       DOM_RID3 dom_rid[MAX_LOOKUP_SIDS]; /* domain RIDs being looked up */
+
+       uint32 num_entries3; 
+
+       uint32 status; /* return code */
+
+} SAMR_R_LOOKUP_RIDS;
+
+
+/* SAMR_Q_UNKNOWN_22 - probably an open */
+typedef struct q_samr_unknown_22_info
+{
+    LSA_POL_HND pol;          /* policy handle */
+       uint32 unknown_id_0;      /* 0x0000 03E8 - 32 bit unknown id */
+
+} SAMR_Q_UNKNOWN_22;
+
+
+/* SAMR_R_UNKNOWN_22 - probably an open */
+typedef struct r_samr_unknown_22_info
+{
+    LSA_POL_HND pol;       /* policy handle associated with unknown id */
+       uint32 status;         /* return status */
+
+} SAMR_R_UNKNOWN_22;
+
+
+/* SAMR_Q_UNKNOWN_24 - probably a get sam info */
+typedef struct q_samr_unknown_24_info
+{
+    LSA_POL_HND pol;          /* policy handle associated with unknown id */
+       uint16 unknown_0;         /* 0x0015 or 0x0011 - 16 bit unknown */
+
+} SAMR_Q_UNKNOWN_24;
+
+
+/* SAMR_R_UNKNOWN_24 - probably a get sam info */
+typedef struct r_samr_unknown_24_info
+{
+       uint32 ptr;            /* pointer */
+       uint16 unknown_0;      /* 0x0015 or 0x0011 - 16 bit unknown (same as above) */
+       uint16 unknown_1;      /* 0x8b73 - 16 bit unknown */
+       uint8  padding_0[16];  /* 0 - padding 16 bytes */
+       NTTIME expiry;         /* expiry time or something? */
+       uint8  padding_1[24];  /* 0 - padding 24 bytes */
+
+       UNIHDR hdr_mach_acct;  /* unicode header for machine account */
+       uint32 padding_2;      /* 0 - padding 4 bytes */
+
+       uint32 ptr_1;          /* pointer */
+       uint8  padding_3[32];  /* 0 - padding 32 bytes */
+       uint32 padding_4;      /* 0 - padding 4 bytes */
+
+       uint32 ptr_2;          /* pointer */
+       uint32 padding_5;      /* 0 - padding 4 bytes */
+
+       uint32 ptr_3;          /* pointer */
+       uint8  padding_6[32];  /* 0 - padding 32 bytes */
+
+       uint32 unknown_id_0;   /* unknown id associated with policy handle */
+       uint16 unknown_2;      /* 0x0201      - 16 bit unknown */
+       uint32 unknown_3;      /* 0x0000 0080 - 32 bit unknown */
+       uint16 unknown_4;      /* 0x003f      - 16 bit unknown */
+       uint16 unknown_5;      /* 0x003c      - 16 bit unknown */
+
+       uint8  padding_7[16];  /* 0 - padding 16 bytes */
+       uint32 padding_8;      /* 0 - padding 4 bytes */
+       
+       UNISTR2 uni_mach_acct; /* unicode string for machine account */
+
+       uint8  padding_9[48];  /* 0 - padding 48 bytes */
+
+       uint32 status;         /* return status */
+
+} SAMR_R_UNKNOWN_24;
+
+
+/* SAMR_Q_UNKNOWN_32 - probably a "create SAM entry" */
+typedef struct q_samr_unknown_32_info
+{
+    LSA_POL_HND pol;             /* policy handle */
+
+       UNIHDR  hdr_mach_acct;       /* unicode machine account name header */
+       UNISTR2 uni_mach_acct;       /* unicode machine account name */
+
+       uint32 unknown_0;            /* 32 bit unknown */
+       uint16 unknown_1;            /* 16 bit unknown */
+       uint16 unknown_2;            /* 16 bit unknown */
+
+} SAMR_Q_UNKNOWN_32;
+
+
+/* SAMR_R_UNKNOWN_32 - probably a "create SAM entry" */
+typedef struct r_samr_unknown_32_info
+{
+    LSA_POL_HND pol;       /* policy handle */
+       uint32 unknown_0;      /* 0x0000 0030 - 32 bit unknown */
+       uint32 padding;        /* 0           - 4 byte padding */
+
+       uint32 status;         /* return status - 0xC000 0099: user exists */
+
+} SAMR_R_UNKNOWN_32;
+
+
+/* SAMR_Q_OPEN_POLICY - probably an open */
+typedef struct q_samr_open_policy_info
+{
+       uint32 ptr_srv_name;         /* pointer (to server name?) */
+       UNISTR2 uni_srv_name;        /* unicode server name starting with '\\' */
+
+       uint32 unknown_0;            /* 32 bit unknown */
+
+} SAMR_Q_OPEN_POLICY;
+
+
+/* SAMR_R_OPEN_POLICY - probably an open */
+typedef struct r_samr_open_policy_info
+{
+    LSA_POL_HND pol;       /* policy handle */
+       uint32 status;             /* return status */
+
+} SAMR_R_OPEN_POLICY;
+
+
+/* WKS_Q_UNKNOWN_0 - probably a capabilities request */
+typedef struct q_wks_unknown_0_info
+{
+       uint32 ptr_srv_name;         /* pointer (to server name?) */
+       UNISTR2 uni_srv_name;        /* unicode server name starting with '\\' */
+
+       uint32 unknown_0;            /* 0x64 - 32 bit unknown */
+       uint16 unknown_1;            /* 16 bit unknown */
+
+} WKS_Q_UNKNOWN_0;
+
+
+/* WKS_R_UNKNOWN_0 - probably a capabilities request */
+typedef struct r_wks_unknown_0_info
+{
+       uint32 unknown_0;          /* 64 - unknown */
+       uint32 ptr_1;              /* pointer 1 */
+       uint32 unknown_1;          /* 0x0000 01f4 - unknown */
+       uint32 ptr_srv_name;       /* pointer to server name */
+       uint32 ptr_dom_name;       /* pointer to domain name */
+       uint32 unknown_2;          /* 4 - unknown */
+       uint32 unknown_3;          /* 0 - unknown */
+
+       UNISTR2 uni_srv_name;      /* unicode server name */
+       UNISTR2 uni_dom_name;      /* unicode domainn name */
+       uint32 status;             /* return status */
+
+} WKS_R_UNKNOWN_0;
 
 
 struct smb_passwd
@@ -886,6 +1342,32 @@ struct smb_passwd
        /* Other fields / flags may be added later */
 };
 
+struct cli_state {
+       int fd;
+       int cnum;
+       int pid;
+       int mid;
+       int uid;
+       int protocol;
+       int sec_mode;
+       int error;
+       int privilages;
+       fstring eff_name;
+       fstring desthost;
+       char cryptkey[8];
+       uint32 sesskey;
+       int serverzone;
+       uint32 servertime;
+       int readbraw_supported;
+       int writebraw_supported;
+       int timeout;
+       int max_xmit;
+       char *outbuf;
+       char *inbuf;
+       int bufsize;
+       int initialised;
+};
+
 
 struct current_user
 {
@@ -908,6 +1390,7 @@ typedef struct
   time_t atime;
   time_t ctime;
   pstring name;
+
 } file_info;
 
 
@@ -959,6 +1442,8 @@ typedef struct
   BOOL print_file;
   BOOL modified;
   BOOL granted_oplock;
+  BOOL sent_oplock_break;
+  BOOL reserved;
   char *name;
 } files_struct;
 
@@ -1007,6 +1492,7 @@ typedef struct
   int num_files_open;
   name_compare_entry *hide_list; /* Per-share list of files to return as hidden. */
   name_compare_entry *veto_list; /* Per-share list of files to veto (never show). */
+  name_compare_entry *veto_oplock_list; /* Per-share list of files to refuse oplocks on. */
 
 } connection_struct;
 
@@ -1015,11 +1501,11 @@ struct dcinfo
 {
   DOM_CHAL clnt_chal; /* Initial challenge received from client */
   DOM_CHAL srv_chal;  /* Initial server challenge */
-  DOM_CHAL clnt_cred; /* Last client credential */
-  DOM_CHAL srv_cred;  /* Last server credential */
+  DOM_CRED clnt_cred; /* Last client credential */
+  DOM_CRED srv_cred;  /* Last server credential */
 
-  char  sess_key[8]; /* Session key */
-  uchar md4pw[16];   /* md4(machine password) */
+  uchar  sess_key[8]; /* Session key */
+  uchar  md4pw[16];   /* md4(machine password) */
 };
 
 typedef struct
@@ -1038,10 +1524,6 @@ typedef struct
   int *igroups; /* an integer version - some OSes are broken :-( */
   int *attrs; /* attributes associated with each gid */
 
-#if (defined(NETGROUP) && defined(AUTOMOUNT))
-  char *home_share;  /* to store NIS home of a user - simeon */
-#endif
-
   int n_sids;
   int *sids;
 
@@ -1092,22 +1574,9 @@ struct interface
        struct in_addr nmask;
 };
 
-/* share mode record pointed to in shared memory hash bucket */
-typedef struct
-{
-  smb_shm_offset_t next_offset; /* offset of next record in chain from hash bucket */
-  int locking_version;
-  int32 st_dev;
-  int32 st_ino;
-  int num_share_mode_entries;
-  smb_shm_offset_t share_mode_entries; /* Chain of share mode entries for this file */
-  char file_name[1];
-} share_mode_record;
-
-/* share mode entry pointed to by share_mode_record struct */
+/* struct returned by get_share_modes */
 typedef struct
 {
-  smb_shm_offset_t next_share_mode_entry;
   int pid;
   uint16 op_port;
   uint16 op_type;
@@ -1115,21 +1584,36 @@ typedef struct
   struct timeval time;
 } share_mode_entry;
 
-/* struct returned by get_share_modes */
-typedef struct
-{
-  int pid;
-  uint16 op_port;
-  uint16 op_type;
-  int share_mode;
-  struct timeval time;
-} min_share_mode_entry;
 
-/* Token returned by lock_share_entry (actually ignored by FAST_SHARE_MODES code) */
-typedef int share_lock_token;
+/* each implementation of the share mode code needs
+   to support the following operations */
+struct share_ops {
+       BOOL (*stop_mgmt)(void);
+       BOOL (*lock_entry)(int , uint32 , uint32 , int *);
+       BOOL (*unlock_entry)(int , uint32 , uint32 , int );
+       int (*get_entries)(int , int , uint32 , uint32 , share_mode_entry **);
+       void (*del_entry)(int , int );
+       BOOL (*set_entry)(int , int , uint16 , uint16 );
+       BOOL (*remove_oplock)(int , int);
+       int (*forall)(void (*)(share_mode_entry *, char *));
+       void (*status)(FILE *);
+};
+
+/* each implementation of the shared memory code needs
+   to support the following operations */
+struct shmem_ops {
+       BOOL (*shm_close)( void );
+       int (*shm_alloc)(int );
+       BOOL (*shm_free)(int );
+       int (*get_userdef_off)(void);
+       void *(*offset2addr)(int );
+       int (*addr2offset)(void *addr);
+       BOOL (*lock_hash_entry)(unsigned int);
+       BOOL (*unlock_hash_entry)( unsigned int );
+       BOOL (*get_usage)(int *,int *,int *);
+       unsigned (*hash_size)(void);
+};
 
-/* Conversion to hash entry index from device and inode numbers. */
-#define HASH_ENTRY(dev,ino) ((( (uint32)(dev) )* ( (uint32)(ino) )) % lp_shmem_hash_size())
 
 /* this is used for smbstatus */
 struct connect_record
@@ -1145,38 +1629,29 @@ struct connect_record
   time_t start;
 };
 
+/* This is used by smbclient to send it to a smbfs mount point */
+struct connection_options {
+  int protocol;
+  /* Connection-Options */
+  uint32 max_xmit;
+  uint16 server_uid;
+  uint16 tid;
+  /* The following are LANMAN 1.0 options */
+  uint16 sec_mode;
+  uint16 max_mux;
+  uint16 max_vcs;
+  uint16 rawmode;
+  uint32 sesskey;
+  /* The following are NT LM 0.12 options */
+  uint32 maxraw;
+  uint32 capabilities;
+  uint16 serverzone;
+};
+
 #ifndef LOCKING_VERSION
 #define LOCKING_VERSION 4
 #endif /* LOCKING_VERSION */
 
-#if !defined(FAST_SHARE_MODES)
-/* 
- * Defines for slow share modes.
- */
-
-/* 
- * Locking file header lengths & offsets. 
- */
-#define SMF_VERSION_OFFSET 0
-#define SMF_NUM_ENTRIES_OFFSET 4
-#define SMF_FILENAME_LEN_OFFSET 8
-#define SMF_HEADER_LENGTH 10
-
-#define SMF_ENTRY_LENGTH 20
-
-/*
- * Share mode record offsets.
- */
-
-#define SME_SEC_OFFSET 0
-#define SME_USEC_OFFSET 4
-#define SME_SHAREMODE_OFFSET 8
-#define SME_PID_OFFSET 12
-#define SME_PORT_OFFSET 16
-#define SME_OPLOCK_TYPE_OFFSET 18
-
-#endif /* FAST_SHARE_MODES */
-
 /* these are useful macros for checking validity of handles */
 #define VALID_FNUM(fnum)   (((fnum) >= 0) && ((fnum) < MAX_OPEN_FILES))
 #define OPEN_FNUM(fnum)    (VALID_FNUM(fnum) && Files[fnum].open)
@@ -1215,6 +1690,7 @@ struct connect_record
 #define MAP_ARCHIVE(cnum)   (OPEN_CNUM(cnum) && lp_map_archive(SNUM(cnum)))
 #define IS_HIDDEN_PATH(cnum,path)  (is_in_path((path),Connections[(cnum)].hide_list))
 #define IS_VETO_PATH(cnum,path)  (is_in_path((path),Connections[(cnum)].veto_list))
+#define IS_VETO_OPLOCK_PATH(cnum,path)  (is_in_path((path),Connections[(cnum)].veto_oplock_list))
 
 #define SMBENCRYPT()       (lp_encrypted_passwords())
 
@@ -1661,14 +2137,12 @@ extern int unix_ERR_code;
 /*
  * Core protocol.
  */
-#define CORE_OPLOCK_REQUEST(inbuf) (((CVAL(inbuf,smb_flg)|(1<<5))>>5) | \
-                                    ((CVAL(inbuf,smb_flg)|(1<<6))>>5))
+#define CORE_OPLOCK_REQUEST(inbuf) ((CVAL(inbuf,smb_flg)&((1<<5)|(1<<6)))>>5)
 
 /*
  * Extended protocol.
  */
-#define EXTENDED_OPLOCK_REQUEST(inbuf) (((SVAL(inbuf,smb_vwv2)|(1<<1))>>1) | \
-                                        ((SVAL(inbuf,smb_vwv2)|(1<<2))>>1))
+#define EXTENDED_OPLOCK_REQUEST(inbuf) ((SVAL(inbuf,smb_vwv2)&((1<<1)|(1<<2)))>>1)
 
 /* Lock types. */
 #define LOCKING_ANDX_SHARED_LOCK 0x1