Change the multibyte character set support so that
[kai/samba.git] / source3 / include / smb.h
index d847c6f3420429b0c513ad720224b107a1f2e2bb..f7a134d797b79cf020fbc67f350cd0cce4a71964 100644 (file)
@@ -2,10 +2,10 @@
    Unix SMB/Netbios implementation.
    Version 1.9.
    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
+   Copyright (C) Andrew Tridgell 1992-1998
+   Copyright (C) John H Terpstra 1996-1998
+   Copyright (C) Luke Kenneth Casson Leighton 1996-1998
+   Copyright (C) Paul Ashton 1998
    
    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
 #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
 
-/* Default size of shared memory used for share mode locking */
-#ifndef SHMEM_SIZE
-#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 +132,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 +235,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,25 +274,62 @@ 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_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 */
 typedef struct time_info
 {
@@ -313,15 +346,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;
 
@@ -373,16 +406,26 @@ 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
 {
@@ -407,8 +450,7 @@ typedef struct log_info
 /* DOM_CHAL - challenge info */
 typedef struct chal_info
 {
-  uint32 data[2]; /* credentials */
-
+  uchar data[8]; /* credentials */
 } DOM_CHAL;
 
 /* DOM_CREDs - timestamped client or server credentials */
@@ -460,12 +502,12 @@ typedef struct id_info_1
   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;
 
@@ -480,7 +522,7 @@ typedef struct sam_info
   
   union
   {
-    DOM_ID_INFO_1 id1; /* auth-level 1 */
+    DOM_ID_INFO_1 *id1; /* auth-level 1 */
 
   } auth;
   
@@ -489,7 +531,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;
@@ -505,12 +547,99 @@ typedef struct rpc_hdr_info
   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
@@ -537,6 +666,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
@@ -568,10 +719,45 @@ typedef struct lsa_r_query_info
 
     } 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 */
@@ -648,7 +834,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 */
@@ -767,7 +953,7 @@ 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 */
@@ -864,9 +1050,11 @@ 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_read2;                    /* EntriesRead2 */
+       uint32 num_entries_read3;                    /* EntriesRead2 */
+       uint32 padding;                              /* padding */
 
 } SHARE_INFO_1_CTR;
 
@@ -911,69 +1099,233 @@ typedef struct r_net_share_enum_info
 } 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;
 
-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:
 
-    uint16         0x0013 - Response to SAM Logon
-    UNISTR         machine name
-    UNISTR         user name - workstation trust account
-    UNISTR         domain name 
-    uint32         NTversion
-    uint16         LMNTtoken
-    uint16         LM20token
+/* 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
@@ -985,10 +1337,36 @@ 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
 {
-  int cnum, id;
+  int cnum, vuid;
   int uid, gid;
   int ngroups;
   gid_t *groups;
@@ -1046,7 +1424,7 @@ typedef struct
   int pos;
   uint32 size;
   int mode;
-  int uid;
+  int vuid;
   char *mmap_ptr;
   uint32 mmap_size;
   write_bmpx_struct *wbmpx_ptr;
@@ -1059,6 +1437,8 @@ typedef struct
   BOOL print_file;
   BOOL modified;
   BOOL granted_oplock;
+  BOOL sent_oplock_break;
+  BOOL reserved;
   char *name;
 } files_struct;
 
@@ -1107,6 +1487,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;
 
@@ -1115,10 +1496,10 @@ 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 */
 
-  uint32 sess_key[2]; /* Session key */
+  uchar  sess_key[8]; /* Session key */
   uchar  md4pw[16];   /* md4(machine password) */
 };
 
@@ -1138,10 +1519,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;
 
@@ -1192,22 +1569,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;
@@ -1215,21 +1579,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
@@ -1245,38 +1624,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)
@@ -1315,6 +1685,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())
 
@@ -1728,7 +2099,10 @@ enum case_handling {CASE_LOWER,CASE_UPPER};
 #endif 
 
 /* Defines needed for multi-codepage support. */
+#define MSDOS_LATIN_1_CODEPAGE 850
 #define KANJI_CODEPAGE 932
+#define HANGUL_CODEPAGE 949
+#define BIG5_CODEPAGE 950
 
 #ifdef KANJI
 /* 
@@ -1739,7 +2113,7 @@ enum case_handling {CASE_LOWER,CASE_UPPER};
 /* 
  * Default client code page - 850 - Western European 
  */
-#define DEFAULT_CLIENT_CODE_PAGE 850
+#define DEFAULT_CLIENT_CODE_PAGE MSDOS_LATIN_1_CODEPAGE
 #endif /* KANJI */
 
 /* 
@@ -1761,14 +2135,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