SYSV IPC implementation of fast share modes.
[kai/samba.git] / source3 / include / smb.h
index 4850b33e4947ed7e026d6bbfcc22ee860ae39335..d7a576de857227ee890ba5aa227f71c5ee64cacd 100644 (file)
@@ -4,6 +4,8 @@
    SMB parameters and setup
    Copyright (C) Andrew Tridgell 1992-1997
    Copyright (C) John H Terpstra 1996-1997
+   Copyright (C) Luke Kenneth Casson Leighton 1996-1997
+   Copyright (C) Paul Ashton 1997
    
    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
 
 /* Default number of hash buckets used in shared memory share mode */
 #ifndef SHMEM_HASH_SIZE
+#ifdef SEMMSL
+#define SHMEM_HASH_SIZE (SEMMSL-1)
+#else
 #define SHMEM_HASH_SIZE 113
 #endif
+#endif
 
 #define NMB_PORT 137
 #define DGRAM_PORT 138
 typedef int BOOL;
 
 /* offset in shared memory */
-typedef  int smb_shm_offset_t;
-#define NULL_OFFSET (smb_shm_offset_t)(0)
+#define NULL_OFFSET (int)(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.
@@ -154,10 +161,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) */
@@ -256,6 +264,86 @@ typedef char fstring[128];
 typedef fstring string;
 
 
+/* pipe strings */
+#define PIPE_LANMAN   "\\PIPE\\LANMAN"
+#define PIPE_SRVSVC   "\\PIPE\\srvsvc"
+#define PIPE_NETLOGON "\\PIPE\\NETLOGON"
+#define PIPE_NTLSA    "\\PIPE\\ntlsa"
+#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
+#define NET_SAMLOGON_R      19
+
+/* Allowable account control bits */
+#define ACB_DISABLED   1 /* 1 = User account disabled */
+#define ACB_HOMDIRREQ  2 /* 1 = Home directory required */
+#define ACB_PWNOTREQ   4 /* 1 = User password not required */
+#define ACB_TEMPDUP      /* 1 = Temporary duplicate account */
+#define ACB_NORMAL       /* 1 = Normal user account */
+#define ACB_MNS          /* 1 = MNS logon user account */
+#define ACB_DOMTRUST     /* 1 = Interdomain trust account */
+#define ACB_WSTRUST      /* 1 = Workstation trust account */
+#define ACB_SVRTRUST     /* 1 = Server trust account */
+#define ACB_PWNOEXP      /* 1 = User password does not expire */
+#define ACB_AUTOLOCK     /* 1 = Account auto locked */
+
+#define LSA_OPENPOLICY      0x2c
+#define LSA_QUERYINFOPOLICY 0x07
+#define LSA_ENUMTRUSTDOM    0x0d
+#define LSA_REQCHAL         0x04
+#define LSA_SRVPWSET        0x06
+#define LSA_SAMLOGON        0x02
+#define LSA_AUTH2           0x0f
+#define LSA_CLOSE           0x00
+
+/* unknown .... */
+#define LSA_OPENSECRET      0xFF
+#define LSA_LOOKUPSIDS      0xFE
+#define LSA_LOOKUPNAMES     0xFD
+#define LSA_SAMLOGOFF       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 */
 typedef struct time_info
 {
@@ -272,15 +360,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;
 
@@ -326,6 +414,7 @@ typedef struct domsid2_info
 {
   uint32 type; /* value is 5 */
   uint32 undoc; /* value is 0 */
+
   UNIHDR2 hdr; /* XXXX conflict between hdr and str for length */
   UNISTR  str; /* XXXX conflict between hdr and str for length */
 
@@ -341,6 +430,16 @@ typedef struct domrid2_info
 
 } DOM_RID2;
 
+/* 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
 {
@@ -355,7 +454,7 @@ typedef struct log_info
 /* DOM_CHAL - challenge info */
 typedef struct chal_info
 {
-  uint8 data[8]; /* credentials */
+  uint32 data[2]; /* credentials */
 
 } DOM_CHAL;
 
@@ -375,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
 {
@@ -394,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 */
-  ARC4_OWF          arc4_lm_owf;         /* rc4 LM OWF Password */
-  ARC4_OWF          arc4_nt_owf;         /* rc4 NT OWF Password */
+  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;
   
@@ -426,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;
@@ -438,14 +548,14 @@ 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. */
   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;
 
@@ -453,7 +563,6 @@ typedef struct rpc_hdr_info
 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 */
@@ -475,6 +584,27 @@ 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
+{
+       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
@@ -488,7 +618,8 @@ typedef struct lsa_r_open_pol_info
 /* LSA_Q_QUERY_INFO - LSA query info policy */
 typedef struct lsa_query_info
 {
-    uint16 info_class; /* info class (also a policy handle?) */
+       LSA_POL_HND pol; /* policy handle */
+    uint16 info_class; /* info class */
 
 } LSA_Q_QUERY_INFO;
 
@@ -502,12 +633,30 @@ 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_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 */
@@ -563,11 +712,7 @@ typedef struct lsa_r_lookup_sids
 typedef struct dom_name_info
 {
     uint32 uni_str_len;
-#if 1 /* don't know if buffer is null-terminated */
-       UNISTR buffer;
-#else /* or length indicated by uni_str_len member */
-    uint16 buffer[MAX_UNISTRLEN];
-#endif
+       UNISTR str;
 
 } DOM_NAME;
 
@@ -677,11 +822,12 @@ typedef struct lsa_r_srv_pwset_info
 } LSA_R_SRV_PWSET;
 
 #define LSA_MAX_GROUPS 32
+#define LSA_MAX_SIDS 32
 
 /* 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 */
@@ -706,16 +852,16 @@ 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_sids; /* 0 - num_sids */
-       uint32 buffer_sids; /* NULL - undocumented pointer to SIDs. */
+       uint32 num_other_sids; /* 0 - num_sids */
+       uint32 buffer_other_sids; /* NULL - undocumented pointer to SIDs. */
        
        UNISTR2 uni_user_name;    /* username unicode string */
        UNISTR2 uni_full_name;    /* user's full name unicode string */
@@ -730,8 +876,8 @@ typedef struct lsa_q_user_info
        UNISTR2 uni_logon_srv; /* logon server unicode string */
        UNISTR2 uni_logon_dom; /* logon domain unicode string */
 
-       DOM_SID undoc_dom_sids[2]; /* undocumented - domain SIDs */
        DOM_SID dom_sid;           /* domain SID */
+       DOM_SID other_sids[LSA_MAX_SIDS]; /* undocumented - domain SIDs */
 
 } LSA_USER_INFO;
 
@@ -749,8 +895,8 @@ 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;
-    LSA_USER_INFO user;
+       uint16 switch_value; /* 3 - indicates type of USER INFO */
+    LSA_USER_INFO *user;
 
     uint32 auth_resp; /* 1 - Authoritative response; 0 - Non-Auth? */
 
@@ -776,6 +922,83 @@ typedef struct lsa_r_sam_logoff_info
 
 } LSA_R_SAM_LOGOFF;
 
+
+/* 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. */
+
+} 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;
+
+
+
 /*
 
 Yet to be turned into structures:
@@ -840,7 +1063,8 @@ Response:
 */
 
 
-struct smb_passwd {
+struct smb_passwd
+{
        int smb_userid;
        char *smb_name;
        unsigned char *smb_passwd; /* Null if no password */
@@ -849,12 +1073,40 @@ struct smb_passwd {
 };
 
 
-struct current_user {
+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
+{
   int cnum, id;
   int uid, gid;
   int ngroups;
   gid_t *groups;
   int *igroups;
+  int *attrs;
 };
 
 typedef struct
@@ -868,6 +1120,7 @@ typedef struct
   time_t atime;
   time_t ctime;
   pstring name;
+
 } file_info;
 
 
@@ -951,35 +1204,59 @@ typedef struct
   char *user; /* name of user who *opened* this connection */
   int uid; /* uid of user who *opened* this connection */
   int gid; /* gid of user who *opened* this connection */
+
   uint16 vuid; /* vuid of user who *opened* this connection, or UID_FIELD_INVALID */
+
   /* following groups stuff added by ih */
+
   /* This groups info is valid for the user that *opened* the connection */
   int ngroups;
   gid_t *groups;
   int *igroups; /* an integer version - some OSes are broken :-( */
+  int *attrs;
+
   time_t lastused;
   BOOL used;
   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). */
+
 } connection_struct;
 
+/* Domain controller authentication protocol info */
+struct dcinfo
+{
+  DOM_CHAL clnt_chal; /* Initial challenge received from client */
+  DOM_CHAL srv_chal;  /* Initial server challenge */
+  DOM_CRED clnt_cred; /* Last client credential */
+  DOM_CRED srv_cred;  /* Last server credential */
+
+  uint32 sess_key[2]; /* Session key */
+  uchar  md4pw[16];   /* md4(machine password) */
+};
 
 typedef struct
 {
   int uid; /* uid of a validated user */
   int gid; /* gid of a validated user */
+
   fstring name; /* name of a validated user */
+  fstring real_name;   /* to store real name from password file - simeon */
   BOOL guest;
+
   /* following groups stuff added by ih */
   /* This groups info is needed for when we become_user() for this uid */
-  int user_ngroups;
-  gid_t *user_groups;
-  int *user_igroups; /* an integer version - some OSes are broken :-( */
-#if (defined(NETGROUP) && defined(AUTOMOUNT))
-  char *home_share;  /* to store NIS home of a user - simeon */
-#endif
-  char *real_name;   /* to store real name from password file - simeon */
+  int n_groups;
+  gid_t *groups;
+  int *igroups; /* an integer version - some OSes are broken :-( */
+  int *attrs; /* attributes associated with each gid */
+
+  int n_sids;
+  int *sids;
+
+  /* per-user authentication information on NT RPCs */
+  struct dcinfo dc;
+
 } user_struct;
 
 
@@ -1024,49 +1301,49 @@ 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 */
-typedef struct
-{
-  smb_shm_offset_t next_share_mode_entry;
-  int pid;
-#ifdef USE_OPLOCKS
-  uint16 op_port;
-  uint16 op_type;
-#endif /* USE_OPLOCKS */
-  int share_mode;
-  struct timeval time;
-} share_mode_entry;
-
 /* struct returned by get_share_modes */
 typedef struct
 {
   int pid;
-#ifdef USE_OPLOCKS
   uint16 op_port;
   uint16 op_type;
-#endif /* USE_OPLOCKS */
   int share_mode;
   struct timeval time;
-} min_share_mode_entry;
+} share_mode_entry;
 
-/* Token returned by lock_share_entry (actually ignored by FAST_SHARE_MODES code) */
-typedef int share_lock_token;
 
 /* Conversion to hash entry index from device and inode numbers. */
 #define HASH_ENTRY(dev,ino) ((( (uint32)(dev) )* ( (uint32)(ino) )) % lp_shmem_hash_size())
 
+/* 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 );
+       BOOL (*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 (*close)( void );
+       int (*alloc)(int );
+       BOOL (*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 *);
+};
+
+
 /* this is used for smbstatus */
 struct connect_record
 {
@@ -1082,48 +1359,9 @@ struct connect_record
 };
 
 #ifndef LOCKING_VERSION
-#ifdef USE_OPLOCKS
 #define LOCKING_VERSION 4
-#else /* USE_OPLOCKS */
-#define LOCKING_VERSION 3
-#endif /* USE_OPLOCKS */
 #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
-
-#ifdef USE_OPLOCKS
-#define SMF_ENTRY_LENGTH 20
-#else /* USE_OPLOCKS */
-#define SMF_ENTRY_LENGTH 16
-#endif /* USE_OPLOCKS */
-
-/*
- * Share mode record offsets.
- */
-
-#define SME_SEC_OFFSET 0
-#define SME_USEC_OFFSET 4
-#define SME_SHAREMODE_OFFSET 8
-#define SME_PID_OFFSET 12
-
-#ifdef USE_OPLOCKS
-#define SME_PORT_OFFSET 16
-#define SME_OPLOCK_TYPE_OFFSET 18
-#endif /* USE_OPLOCKS */
-
-#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)
@@ -1283,23 +1521,38 @@ struct connect_record
 #define SMBfindnclose    0x35   /* Terminate a TRANSACT2_FINDNOTIFYFIRST */
 #define SMBulogoffX      0x74   /* user logoff */
 
-
-/* these are the TRANS2 sub commands */
-#define TRANSACT2_OPEN          0
-#define TRANSACT2_FINDFIRST     1
-#define TRANSACT2_FINDNEXT      2
-#define TRANSACT2_QFSINFO       3
-#define TRANSACT2_SETFSINFO     4
-#define TRANSACT2_QPATHINFO     5
-#define TRANSACT2_SETPATHINFO   6
-#define TRANSACT2_QFILEINFO     7
-#define TRANSACT2_SETFILEINFO   8
-#define TRANSACT2_FSCTL         9
-#define TRANSACT2_IOCTL           10
-#define TRANSACT2_FINDNOTIFYFIRST 11
-#define TRANSACT2_FINDNOTIFYNEXT  12
-#define TRANSACT2_MKDIR           13
-
+/* NT SMB extensions. */
+#define SMBnttrans       0xA0   /* NT transact */
+#define SMBnttranss      0xA1   /* NT transact secondary */
+#define SMBntcreateX     0xA2   /* NT create and X */
+#define SMBntcancel      0xA4   /* NT cancel */
+
+/* These are the TRANS2 sub commands */
+#define TRANSACT2_OPEN                        0
+#define TRANSACT2_FINDFIRST                   1
+#define TRANSACT2_FINDNEXT                    2
+#define TRANSACT2_QFSINFO                     3
+#define TRANSACT2_SETFSINFO                   4
+#define TRANSACT2_QPATHINFO                   5
+#define TRANSACT2_SETPATHINFO                 6
+#define TRANSACT2_QFILEINFO                   7
+#define TRANSACT2_SETFILEINFO                 8
+#define TRANSACT2_FSCTL                       9
+#define TRANSACT2_IOCTL                     0xA
+#define TRANSACT2_FINDNOTIFYFIRST           0xB
+#define TRANSACT2_FINDNOTIFYNEXT            0xC
+#define TRANSACT2_MKDIR                     0xD
+#define TRANSACT2_SESSION_SETUP             0xE
+#define TRANSACT2_GET_DFS_REFERRAL         0x10
+#define TRANSACT2_REPORT_DFS_INCONSISTANCY 0x11
+
+/* These are the NT transact sub commands. */
+#define NT_TRANSACT_CREATE                1
+#define NT_TRANSACT_IOCTL                 2
+#define NT_TRANSACT_SET_SECURITY_DESC     3
+#define NT_TRANSACT_NOTIFY_CHANGE         4
+#define NT_TRANSACT_RENAME                5
+#define NT_TRANSACT_QUERY_SECURITY_DESC   6
 
 /* these are the trans2 sub fields for primary requests */
 #define smb_tpscnt smb_vwv0
@@ -1593,14 +1846,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