Restructuring of vfs layer to include a "this" pointer - can be an fsp or
[kamenim/samba-autobuild/.git] / source3 / include / smb.h
index daf617bd7f09090a21b252143279a9a0b1535c1f..24211b0d50ddeb671e95fb7b6688d0970e041ae7 100644 (file)
@@ -2,10 +2,10 @@
    Unix SMB/Netbios implementation.
    Version 1.9.
    SMB parameters and setup
-   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
+   Copyright (C) Andrew Tridgell              1992-2000
+   Copyright (C) John H Terpstra              1996-2000
+   Copyright (C) Luke Kenneth Casson Leighton 1996-2000
+   Copyright (C) Paul Ashton                  1998-2000
    
    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
@@ -21,6 +21,7 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
+
 #ifndef _SMB_H
 #define _SMB_H
 
 
 #define False (0)
 #define True (1)
-#define BOOLSTR(b) ((b) ? "Yes" : "No")
-#define BITSETB(ptr,bit) ((((char *)ptr)[0] & (1<<(bit)))!=0)
-#define BITSETW(ptr,bit) ((SVAL(ptr,0) & (1<<(bit)))!=0)
-
-#define IS_BITS_SET_ALL(var,bit) (((var)&(bit))==(bit))
-#define IS_BITS_SET_SOME(var,bit) (((var)&(bit))!=0)
-#define IS_BITS_CLR_ALL(var,bit) (((var)&(~(bit)))==0)
-
-#define PTR_DIFF(p1,p2) ((ptrdiff_t)(((const char *)(p1)) - (const char *)(p2)))
+#define Auto (2)
 
+#ifndef _BOOL
 typedef int BOOL;
+#define _BOOL       /* So we don't typedef BOOL again in vfs.h */
+#endif
 
 /* limiting size of ipc replies */
 #define REALLOC(ptr,size) Realloc(ptr,MAX((size),4*1024))
@@ -57,98 +53,8 @@ typedef int BOOL;
 /* how long to wait for secondary SMB packets (milli-seconds) */
 #define SMB_SECONDARY_WAIT (60*1000)
 
-/* -------------------------------------------------------------------------- **
- * Debugging code.  See also debug.c
- */
-
-/* mkproto.awk has trouble with ifdef'd function definitions (it ignores
- * the #ifdef directive and will read both definitions, thus creating two
- * diffferent prototype declarations), so we must do these by hand.
- */
-/* I know the __attribute__ stuff is ugly, but it does ensure we get the 
-   arguemnts to DEBUG() right. We have got them wrong too often in the 
-   past.
- */
-#ifdef HAVE_STDARG_H
-int  Debug1( char *, ... )
-#ifdef __GNUC__
-     __attribute__ ((format (printf, 1, 2)))
-#endif
-;
-BOOL dbgtext( char *, ... )
-#ifdef __GNUC__
-     __attribute__ ((format (printf, 1, 2)))
-#endif
-;
-#else
-int  Debug1();
-BOOL dbgtext();
-#endif
-
-/* If we have these macros, we can add additional info to the header. */
-#ifdef HAVE_FILE_MACRO
-#define FILE_MACRO (__FILE__)
-#else
-#define FILE_MACRO ("")
-#endif
-
-#ifdef HAVE_FUNCTION_MACRO
-#define FUNCTION_MACRO  (__FUNCTION__)
-#else
-#define FUNCTION_MACRO  ("")
-#endif
-
-/* Debugging macros. 
- *  DEBUGLVL() - If level is <= the system-wide DEBUGLEVEL then generate a
- *               header using the default macros for file, line, and
- *               function name.
- *               Returns True if the debug level was <= DEBUGLEVEL.
- *               Example usage:
- *                 if( DEBUGLVL( 2 ) )
- *                   dbgtext( "Some text.\n" );
- *  DEGUG()    - Good old DEBUG().  Each call to DEBUG() will generate a new
- *               header *unless* the previous debug output was unterminated
- *               (i.e., no '\n').  See debug.c:dbghdr() for more info.
- *               Example usage:
- *                 DEBUG( 2, ("Some text.\n") );
- *  DEBUGADD() - If level <= DEBUGLEVEL, then the text is appended to the
- *               current message (i.e., no header).
- *               Usage:
- *                 DEBUGADD( 2, ("Some additional text.\n") );
- */
-#define DEBUGLVL( level ) \
-  ( (DEBUGLEVEL >= (level)) \
-   && dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) ) )
-
-#define DEBUG( level, body ) \
-  (void)( (DEBUGLEVEL >= (level)) \
-       && (dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) )) \
-       && (dbgtext body) )
-
-#define DEBUGADD( level, body ) \
-  (void)( (DEBUGLEVEL >= (level)) && (dbgtext body) )
-
-/* -------------------------------------------------------------------------- **
- * These are the tokens returned by dbg_char2token().
- */
-
-typedef enum
-  {
-  dbg_null = 0,
-  dbg_ignore,
-  dbg_header,
-  dbg_timestamp,
-  dbg_level,
-  dbg_sourcefile,
-  dbg_function,
-  dbg_lineno,
-  dbg_message,
-  dbg_eof
-  } dbg_Token;
-
-/* End Debugging code section.
- * -------------------------------------------------------------------------- **
- */
+/* Debugging stuff */
+#include "debug.h"
 
 /* this defines the error codes that receive_smb can put in smb_read_error */
 #define READ_TIMEOUT 1
@@ -172,13 +78,6 @@ implemented */
 #define aDIR (1L<<4)
 #define aARCH (1L<<5)
 
-/* for readability... */
-#define IS_DOS_READONLY(test_mode) (((test_mode) & aRONLY) != 0)
-#define IS_DOS_DIR(test_mode) (((test_mode) & aDIR) != 0)
-#define IS_DOS_ARCHIVE(test_mode) (((test_mode) & aARCH) != 0)
-#define IS_DOS_SYSTEM(test_mode) (((test_mode) & aSYSTEM) != 0)
-#define IS_DOS_HIDDEN(test_mode) (((test_mode) & aHIDDEN) != 0)
-
 /* deny modes */
 #define DENY_DOS 0
 #define DENY_ALL 1
@@ -260,6 +159,7 @@ implemented */
 #define ERRbadshare 32 /* Share mode on file conflict with open mode */
 #define ERRlock 33 /* Lock request conflicts with existing lock */
 #define ERRunsup 50 /* Request unsupported, returned by Win 95, RJS 20Jun98 */
+#define ERRnosuchshare 67 /* You specified an invalid share name */
 #define ERRfilexists 80 /* File in operation already exists */
 #define ERRcannotopen 110 /* Cannot open the file specified */
 #define ERRunknownlevel 124
@@ -270,11 +170,25 @@ implemented */
 #define ERRnotconnected 233 /* No process on other end of named pipe */
 #define ERRmoredata 234 /* More data to be returned */
 #define ERRbaddirectory 267 /* Invalid directory name in a path. */
-#define ERROR_EAS_DIDNT_FIT 275 /* Extended attributes didn't fit */
-#define ERROR_EAS_NOT_SUPPORTED 282 /* Extended attributes not supported */
-#define ERROR_NOTIFY_ENUM_DIR 1022 /* Buffer too small to return change notify. */
 #define ERRunknownipc 2142
 
+#define ERROR_INVALID_FUNCTION           (1)
+#define ERROR_ACCESS_DENIED              (5)
+#define ERROR_INVALID_HANDLE             (6)
+#define ERROR_NOT_ENOUGH_MEMORY                  (8)
+#define ERROR_INVALID_PARAMETER                 (87)
+#define ERROR_INSUFFICIENT_BUFFER      (122)
+#define ERROR_INVALID_NAME             (123)
+#define ERROR_INVALID_LEVEL            (124)
+#define ERROR_MORE_DATA         (234)
+#define ERROR_NO_MORE_ITEMS            (259)
+#define ERROR_EAS_DIDNT_FIT            (275) /* Extended attributes didn't fit */
+#define ERROR_EAS_NOT_SUPPORTED                (282) /* Extended attributes not supported */
+#define ERROR_NOTIFY_ENUM_DIR         (1022) /* Buffer too small to return change notify. */
+#define ERROR_UNKNOWN_PRINTER_DRIVER   (1797)
+#define ERROR_INVALID_PRINTER_NAME     (1801)
+#define ERROR_INVALID_DATATYPE        (1804)
+#define ERROR_INVALID_ENVIRONMENT      (1805)
 
 /* here's a special one from observing NT */
 #define ERRnoipc 66 /* don't support ipc */
@@ -334,9 +248,27 @@ implemented */
 #define ERRsharebufexc 36 /* share buffer exceeded */
 #define ERRdiskfull 39
 
+#ifndef _PSTRING
+
+#define PSTRING_LEN 1024
+#define FSTRING_LEN 128
+
+typedef char pstring[PSTRING_LEN];
+typedef char fstring[FSTRING_LEN];
+
+#define _PSTRING
+
+#endif
+
+/*
+ * SMB UCS2 (16-bit unicode) internal type.
+ */
+
+typedef uint16 smb_ucs2_t;
 
-typedef char pstring[1024];
-typedef char fstring[128];
+/* ucs2 string types. */
+typedef smb_ucs2_t wpstring[1024];
+typedef smb_ucs2_t wfstring[128];
 
 /* pipe string names */
 #define PIPE_LANMAN   "\\PIPE\\LANMAN"
@@ -345,12 +277,12 @@ typedef char fstring[128];
 #define PIPE_WINREG   "\\PIPE\\winreg"
 #define PIPE_WKSSVC   "\\PIPE\\wkssvc"
 #define PIPE_NETLOGON "\\PIPE\\NETLOGON"
-#define PIPE_SVCCTL   "\\PIPE\\SVCCTL"
 #define PIPE_NTLSA    "\\PIPE\\ntlsa"
 #define PIPE_NTSVCS   "\\PIPE\\ntsvcs"
 #define PIPE_LSASS    "\\PIPE\\lsass"
 #define PIPE_LSARPC   "\\PIPE\\lsarpc"
-
+#define PIPE_SPOOLSS  "\\PIPE\\spoolss"
+#define PIPE_NETDFS   "\\PIPE\\netdfs"
 
 /* 64 bit time (100usec) since ????? - cifs6.txt, section 3.5, page 30 */
 typedef struct nttime_info
@@ -377,15 +309,14 @@ typedef struct nttime_info
 
 struct sam_passwd
 {
-       NTTIME logon_time;            /* logon time */
-       NTTIME logoff_time;           /* logoff time */
-       NTTIME kickoff_time;          /* kickoff time */
-       NTTIME pass_last_set_time;    /* password last set time */
-       NTTIME pass_can_change_time;  /* password can change time */
-       NTTIME pass_must_change_time; /* password must change time */
-
-       char *unix_name;    /* unix username string */
-       char *nt_name;      /* nt username string */
+       time_t logon_time;            /* logon time */
+       time_t logoff_time;           /* logoff time */
+       time_t kickoff_time;          /* kickoff time */
+       time_t pass_last_set_time;    /* password last set time */
+       time_t pass_can_change_time;  /* password can change time */
+       time_t pass_must_change_time; /* password must change time */
+
+       char *smb_name;     /* username string */
        char *full_name;    /* user's full name string */
        char *home_dir;     /* home directory string */
        char *dir_drive;    /* home directory drive string */
@@ -396,8 +327,8 @@ struct sam_passwd
        char *unknown_str ; /* don't know what this is, yet. */
        char *munged_dial ; /* munged path name and dial-back tel number */
 
-       uid_t unix_uid;       /* this is actually the unix uid_t */
-       gid_t unix_gid;        /* this is actually the unix gid_t */
+       uid_t smb_userid;       /* this is actually the unix uid_t */
+       gid_t smb_grpid;        /* this is actually the unix gid_t */
        uint32 user_rid;      /* Primary User ID */
        uint32 group_rid;     /* Primary Group ID */
 
@@ -417,11 +348,8 @@ struct sam_passwd
 
 struct smb_passwd
 {
-       uid_t unix_uid;     /* unix userid */
-       char *unix_name;     /* unix username string */
-
-       uint32 user_rid;     /* Primary User ID */
-       char *nt_name;     /* unix username string */
+       uid_t smb_userid;     /* this is actually the unix uid_t */
+       char *smb_name;     /* username string */
 
        unsigned char *smb_passwd; /* Null if no password */
        unsigned char *smb_nt_passwd; /* Null if no password */
@@ -434,12 +362,33 @@ struct smb_passwd
 struct sam_disp_info
 {
        uint32 user_rid;      /* Primary User ID */
-       char *nt_name;        /* username string */
-       char *full_name;      /* user's full name string */
+       char *smb_name;     /* username string */
+       char *full_name;    /* user's full name string */
+};
+
+typedef struct
+{
+        uint32 pid;
+        uint16 vuid;
+
+}
+vuser_key;
+
+
+struct use_info
+{
+       BOOL connected;
+       char *srv_name;
+       vuser_key key;
+       char *user_name;
+       char *domain;
 };
 
+#ifndef MAXSUBAUTHS
 #define MAXSUBAUTHS 15 /* max sub authorities in a SID */
+#endif
 
+#ifndef _DOM_SID
 /* DOM_SID - security id */
 typedef struct sid_info
 {
@@ -453,29 +402,26 @@ typedef struct sid_info
   uint32 sub_auths[MAXSUBAUTHS];  /* pointer to sub-authorities. */
 
 } DOM_SID;
+#define _DOM_SID
+#endif
 
+/*
+ * The complete list of SIDS belonging to this user.
+ * Created when a vuid is registered.
+ * The definition of the user_sids array is as follows :
+ *
+ * token->user_sids[0] = primary user SID.
+ * token->user_sids[1] = primary group SID.
+ * token->user_sids[2-num_sids] = supplementary group SIDS.
+ */
 
-typedef struct group_name_info
-{
-       char *nt_name;
-       char *nt_domain;
-       char *unix_name;
-
-       DOM_SID sid;
-       uint8 type;
-       uint32 unix_id;
-
-} DOM_NAME_MAP;
-
-/* map either local aliases, domain groups or builtin aliases */
-typedef enum 
-{
-       DOM_MAP_LOCAL,
-       DOM_MAP_DOMAIN,
-       DOM_MAP_USER
-
-} DOM_MAP_TYPE;
-
+#ifndef _NT_USER_TOKEN
+typedef struct _nt_user_token {
+       size_t num_sids;
+       DOM_SID *user_sids;
+} NT_USER_TOKEN;
+#define _NT_USER_TOKEN
+#endif
 
 /*** query a local group, get a list of these: shows who is in that group ***/
 
@@ -495,22 +441,9 @@ typedef struct local_grp_info
 {
        fstring name;
        fstring comment;
-       uint32  rid; /* alias rid */
 
 } LOCAL_GRP;
 
-/*** query a domain group, get a list of these: shows who is in that group ***/
-
-/* domain group info */
-typedef struct domain_grp_member_info
-{
-       fstring name;
-       uint8   attr; /* attributes forced to be set to 0x7: SE_GROUP_xxx */
-       uint32  rid; /* rid of domain group member */
-       uint8   sid_use; /* usr=1 grp=2 dom=3 alias=4 wkng=5 del=6 inv=7 unk=8 */
-
-} DOMAIN_GRP_MEMBER;
-
 /*** enumerate these to get list of domain groups ***/
 
 /* domain group member info */
@@ -523,6 +456,16 @@ typedef struct domain_grp_info
 
 } DOMAIN_GRP;
 
+/*** query a domain group, get a list of these: shows who is in that group ***/
+
+/* domain group info */
+typedef struct domain_grp_member_info
+{
+       fstring name;
+       uint8   attr; /* attributes forced to be set to 0x7: SE_GROUP_xxx */
+
+} DOMAIN_GRP_MEMBER;
+
 /* DOM_CHAL - challenge info */
 typedef struct chal_info
 {
@@ -553,26 +496,46 @@ typedef struct
   BOOL  wr_discard; /* discard all further data */
 } write_bmpx_struct;
 
-/*
- * Structure used to indirect fd's from the files_struct.
- * Needed as POSIX locking is based on file and process, not
- * file descriptor and process.
- */
+typedef struct write_cache
+{
+    SMB_OFF_T file_size;
+    SMB_OFF_T offset;
+    size_t alloc_size;
+    size_t data_size;
+    char *data;
+} write_cache;
 
-typedef struct file_fd_struct
+typedef struct files_struct
 {
-       struct file_fd_struct *next, *prev;
-       uint16 ref_count;
-       uint16 uid_cache_count;
-       uid_t uid_users_cache[10];
+       struct files_struct *next, *prev;
+       int fnum;
+       struct connection_struct *conn;
+       int fd;
+       int print_jobid;
        SMB_DEV_T dev;
        SMB_INO_T inode;
-       int fd;
-       int fd_readonly;
-       int fd_writeonly;
-       int real_open_flags;
        BOOL delete_on_close;
-} file_fd_struct;
+       SMB_OFF_T pos;
+       SMB_OFF_T size;
+       mode_t mode;
+       uint16 vuid;
+       write_bmpx_struct *wbmpx_ptr;
+       write_cache *wcp;
+       struct timeval open_time;
+       int share_mode;
+       time_t pending_modtime;
+       int oplock_type;
+       int sent_oplock_break;
+       BOOL can_lock;
+       BOOL can_read;
+       BOOL can_write;
+       BOOL print_file;
+       BOOL modified;
+       BOOL is_directory;
+       BOOL directory_delete_on_close;
+       BOOL stat_open;
+       char *fsp_name;
+} files_struct;
 
 /*
  * Structure used to keep directory state information around.
@@ -596,6 +559,10 @@ typedef struct
   BOOL is_wild;
 } name_compare_entry;
 
+/* Include VFS stuff */
+
+#include "vfs.h"
+
 typedef struct connection_struct
 {
        struct connection_struct *next, *prev;
@@ -611,9 +578,15 @@ typedef struct connection_struct
        char *dirpath;
        char *connectpath;
        char *origpath;
+
+       struct vfs_ops vfs_ops;                   /* Filesystem operations */
+       /* Handle on dlopen() call */
+       void *dl_handle;
+
        char *user; /* name of user who *opened* this connection */
        uid_t uid; /* uid of user who *opened* this connection */
        gid_t gid; /* gid of user who *opened* this connection */
+       char client_address[18]; /* String version of client IP address. */
 
        uint16 vuid; /* vuid of user who *opened* this connection, or UID_FIELD_INVALID */
 
@@ -622,6 +595,7 @@ typedef struct connection_struct
        /* This groups info is valid for the user that *opened* the connection */
        int ngroups;
        gid_t *groups;
+       NT_USER_TOKEN *nt_user_token;
        
        time_t lastused;
        BOOL used;
@@ -632,34 +606,6 @@ typedef struct connection_struct
 
 } connection_struct;
 
-struct unix_sec_ctxt
-{
-       uid_t uid;
-       gid_t gid;
-       int ngroups;
-       gid_t *groups;
-
-       char *name;
-};
-
-struct nt_sec_ctxt
-{
-       /* this should (will?) probably become a SEC_DESC */
-       DOM_SID user_sid;
-       DOM_SID group_sid;
-
-       char *name;
-       char *domain;
-};
-
-#if 0
-struct sec_ctxt
-{
-       struct unix_sec_ctxt unix;
-       struct nt_sec_ctxt   nt;
-};
-#endif
-
 struct current_user
 {
        connection_struct *conn;
@@ -668,35 +614,20 @@ struct current_user
        gid_t gid;
        int ngroups;
        gid_t *groups;
+       NT_USER_TOKEN *nt_user_token;
 };
 
-typedef struct files_struct
-{
-       struct files_struct *next, *prev;
-       int fnum;
-       connection_struct *conn;
-       file_fd_struct *fd_ptr;
-       SMB_OFF_T pos;
-       SMB_OFF_T size;
-       mode_t mode;
-       uint16 vuid;
-       char *mmap_ptr;
-       SMB_OFF_T mmap_size;
-       write_bmpx_struct *wbmpx_ptr;
-       struct timeval open_time;
-       int share_mode;
-       time_t pending_modtime;
-       BOOL open;
-       BOOL can_lock;
-       BOOL can_read;
-       BOOL can_write;
-       BOOL print_file;
-       BOOL modified;
-       BOOL granted_oplock;
-       BOOL sent_oplock_break;
-       BOOL is_directory;
-       char *fsp_name;
-} files_struct;
+/*
+ * Reasons for cache flush.
+ */
+
+#define NUM_FLUSH_REASONS 8 /* Keep this in sync with the enum below. */
+enum flush_reason_enum { SEEK_FLUSH, READ_FLUSH, WRITE_FLUSH, READRAW_FLUSH,
+                       OPLOCK_RELEASE_FLUSH, CLOSE_FLUSH, SYNC_FLUSH, SIZECHANGE_FLUSH };
+/* Defines for the sent_oplock_break field above. */
+#define NO_BREAK_SENT 0
+#define EXCLUSIVE_BREAK_SENT 1
+#define LEVEL_II_BREAK_SENT 2
 
 /* Domain controller authentication protocol info */
 struct dcinfo
@@ -710,41 +641,25 @@ struct dcinfo
   uchar  md4pw[16];   /* md4(machine password) */
 };
 
-typedef struct
-{
-  uid_t uid; /* uid of a validated user */
-  gid_t gid; /* gid of a validated user */
-
-  fstring requested_name; /* user name from the client */
-  fstring name; /* unix user 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 n_groups;
-  gid_t *groups;
-
-  int n_sids;
-  int *sids;
-
-  /* per-user authentication information on NT RPCs */
-  struct dcinfo dc;
-
-} user_struct;
 
+typedef struct {
+       fstring smb_name; /* user name from the client */
+       fstring unix_name; /* unix user name of a validated user */
+       fstring full_name; /* to store full name (such as "Joe Bloggs") from gecos field of password file */
+       fstring domain; /* domain that the client specified */
+} userdom_struct;
 
 enum {LPQ_QUEUED,LPQ_PAUSED,LPQ_SPOOLING,LPQ_PRINTING};
 
-typedef struct
+typedef struct _print_queue_struct
 {
   int job;
   int size;
   int status;
   int priority;
   time_t time;
-  char user[30];
-  char file[100];
+  fstring user;
+  fstring file;
 } print_queue_struct;
 
 enum {LPSTAT_OK, LPSTAT_STOPPED, LPSTAT_ERROR};
@@ -769,7 +684,7 @@ struct server_info_struct
 /* used for network interfaces */
 struct interface
 {
-       struct interface *next;
+       struct interface *next, *prev;
        struct in_addr ip;
        struct in_addr bcast;
        struct in_addr nmask;
@@ -778,7 +693,7 @@ struct interface
 /* struct returned by get_share_modes */
 typedef struct
 {
-  int pid;
+  pid_t pid;
   uint16 op_port;
   uint16 op_type;
   int share_mode;
@@ -786,94 +701,52 @@ typedef struct
 } share_mode_entry;
 
 
-/* each implementation of the share mode code needs
-   to support the following operations */
-struct share_ops {
-       BOOL (*stop_mgmt)(void);
-       BOOL (*lock_entry)(connection_struct *, SMB_DEV_T , SMB_INO_T , int *);
-       BOOL (*unlock_entry)(connection_struct *, SMB_DEV_T , SMB_INO_T , int );
-       int (*get_entries)(connection_struct *, int , SMB_DEV_T , SMB_INO_T , share_mode_entry **);
-       void (*del_entry)(int , files_struct *);
-       BOOL (*set_entry)(int, files_struct *, uint16 , uint16 );
-    BOOL (*mod_entry)(int, files_struct *, void (*)(share_mode_entry *, SMB_DEV_T, SMB_INO_T, void *), void *);
-       int (*forall)(void (*)(share_mode_entry *, char *));
-       void (*status)(FILE *);
-};
+#define SHAREMODE_FN_CAST() \
+       void (*)(share_mode_entry *, char*)
 
-/* 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);
-};
+#define SHAREMODE_FN(fn) \
+       void (*fn)(share_mode_entry *, char*)
 
 /*
  * Each implementation of the password database code needs
  * to support the following operations.
  */
 
-struct smb_passdb_ops
-{
-       /*
-        * Password database operations.
-        */
-       void *(*startsmbpwent)(BOOL);
-       void (*endsmbpwent)(void *);
-       SMB_BIG_UINT (*getsmbpwpos)(void *);
-       BOOL (*setsmbpwpos)(void *, SMB_BIG_UINT);
-
-       /*
-        * smb password database query functions.
-        */
-       struct smb_passwd *(*getsmbpwnam)(const char *);
-       struct smb_passwd *(*getsmbpwuid)(uid_t);
-       struct smb_passwd *(*getsmbpwent)(void *);
-
-       /*
-        * smb password database modification functions.
-        */
-       BOOL (*add_smbpwd_entry)(struct smb_passwd *);
-       BOOL (*mod_smbpwd_entry)(struct smb_passwd *, BOOL);
+struct passdb_ops {
+  /*
+   * Password database ops.
+   */
+  void *(*startsmbpwent)(BOOL);
+  void (*endsmbpwent)(void *);
+  SMB_BIG_UINT (*getsmbpwpos)(void *);
+  BOOL (*setsmbpwpos)(void *, SMB_BIG_UINT);
 
-#if 0
   /*
-   * password checking functions
+   * smb password database query functions.
    */
-  struct smb_passwd *(*smb_password_chal  )(const char *username, const char lm_pass[24], const char nt_pass[24], char chal[8]);
-  struct smb_passwd *(*smb_password_check )(const char *username, const char lm_hash[16], const char nt_hash[16]);
-  struct passwd     *(*unix_password_check)(const char *username, const char *pass, int pass_len);
-#endif
-};
+  struct smb_passwd *(*getsmbpwnam)(char *);
+  struct smb_passwd *(*getsmbpwuid)(uid_t);
+  struct smb_passwd *(*getsmbpwrid)(uint32);
+  struct smb_passwd *(*getsmbpwent)(void *);
 
-/*
- * Each implementation of the password database code needs
- * to support the following operations.
- */
+  /*
+   * smb password database modification functions.
+   */
+  BOOL (*add_smbpwd_entry)(struct smb_passwd *);
+  BOOL (*mod_smbpwd_entry)(struct smb_passwd *, BOOL);
+  BOOL (*del_smbpwd_entry)(const char *);
 
-struct sam_passdb_ops {
   /*
-   * Password database operations.
+   * Functions that manupulate a struct sam_passwd.
    */
-  void *(*startsam21pwent)(BOOL);
-  void (*endsam21pwent)(void *);
-  SMB_BIG_UINT (*getsam21pwpos)(void *);
-  BOOL (*setsam21pwpos)(void *, SMB_BIG_UINT);
+  struct sam_passwd *(*getsam21pwent)(void *);
 
   /*
    * sam password database query functions.
    */
-  struct sam_passwd *(*getsam21pwntnam)(const char *);
+  struct sam_passwd *(*getsam21pwnam)(char *);
   struct sam_passwd *(*getsam21pwuid)(uid_t);
   struct sam_passwd *(*getsam21pwrid)(uint32);
-  struct sam_passwd *(*getsam21pwent)(void *);
 
   /*
    * sam password database modification functions.
@@ -884,155 +757,65 @@ struct sam_passdb_ops {
   /*
    * sam query display info functions.
    */
-  struct sam_disp_info *(*getsamdispntnam)(const char *);
+  struct sam_disp_info *(*getsamdispnam)(char *);
   struct sam_disp_info *(*getsamdisprid)(uint32);
   struct sam_disp_info *(*getsamdispent)(void *);
 
+#if 0
+  /*
+   * password checking functions
+   */
+  struct smb_passwd *(*smb_password_chal  )(char *username, char lm_pass[24], char nt_pass[24], char chal[8]);
+  struct smb_passwd *(*smb_password_check )(char *username, char lm_hash[16], char nt_hash[16]);
+  struct passwd     *(*unix_password_check)(char *username, char *pass, int pass_len);
+#endif
 };
 
 /*
- * Each implementation of the passgrp database code needs
- * to support the following operations.
+ * Flags for local user manipulation.
  */
 
-struct passgrp_ops
-{
-       /*
-        * Password group database ops.
-        */
-       void *(*startsmbgrpent)(BOOL);
-       void (*endsmbgrpent)(void *);
-       SMB_BIG_UINT (*getsmbgrppos)(void *);
-       BOOL (*setsmbgrppos)(void *, SMB_BIG_UINT);
-
-       /*
-        * smb passgrp database query functions, by user attributes.
-        */
-       struct smb_passwd *(*getsmbgrpntnam)(const char *, uint32**, int*, uint32**, int*);
-       struct smb_passwd *(*getsmbgrpuid)(uid_t , uint32**, int*, uint32**, int*);
-       struct smb_passwd *(*getsmbgrprid)(uint32, uint32**, int*, uint32**, int*);
-       struct smb_passwd *(*getsmbgrpent)(void *, uint32**, int*, uint32**, int*);
+#define LOCAL_ADD_USER 0x1
+#define LOCAL_DELETE_USER 0x2
+#define LOCAL_DISABLE_USER 0x4
+#define LOCAL_ENABLE_USER 0x8
+#define LOCAL_TRUST_ACCOUNT 0x10
+#define LOCAL_SET_NO_PASSWORD 0x20
+
+/* key and data in the connections database - used in smbstatus and smbd */
+struct connections_key {
+       pid_t pid;
+       int cnum;
+       fstring name;
 };
 
-/*
- * Each implementation of the group database code needs
- * to support the following operations.
- *
- * This allows enumeration, modification and addition of groups.  there
- * is _no_ deletion of groups: you can only modify them to a status of
- * "deleted" (this by the way is a requirement of c2 rating)
- */
-
-struct groupdb_ops
-{
-       /*
-        * Group database ops.
-        */
-       void *(*startgroupent)(BOOL);
-       void (*endgroupent)(void *);
-       SMB_BIG_UINT (*getgrouppos)(void *);
-       BOOL (*setgrouppos)(void *, SMB_BIG_UINT);
-
-       /*
-        * group database query functions. 
-        */
-       DOMAIN_GRP *(*getgroupntnam)(const char *, DOMAIN_GRP_MEMBER **, int *);
-       DOMAIN_GRP *(*getgroupgid)(gid_t , DOMAIN_GRP_MEMBER **, int *);
-       DOMAIN_GRP *(*getgrouprid)(uint32, DOMAIN_GRP_MEMBER **, int *);
-       DOMAIN_GRP *(*getgroupent)(void *, DOMAIN_GRP_MEMBER **, int *);
-
-       /*
-        * group database modification functions.
-        */
-       BOOL (*add_group_entry)(DOMAIN_GRP *);
-       BOOL (*mod_group_entry)(DOMAIN_GRP *);
-       BOOL (*del_group_entry)(uint32);
-
-       BOOL (*add_group_member)(uint32, uint32);
-       BOOL (*del_group_member)(uint32, uint32);
-
-       /*
-        * user group functions
-        */
-       BOOL (*getusergroupsntnam)(const char *, DOMAIN_GRP **, int *);
+struct connections_data {
+       int magic;
+       pid_t pid;
+       int cnum;
+       uid_t uid;
+       gid_t gid;
+       char name[24];
+       char addr[24];
+       char machine[128];
+       time_t start;
 };
 
-/*
- * Each implementation of the alias database code needs
- * to support the following operations.
- *
- * This allows enumeration, modification and addition of aliases.  there
- * is _no_ deletion of aliases: you can only modify them to a status of
- * "deleted" (this by the way is a requirement of c2 rating)
- */
 
-struct aliasdb_ops
-{
-       /*
-        * Alias database ops.
-        */
-       void *(*startaliasent)(BOOL);
-       void (*endaliasent)(void *);
-       SMB_BIG_UINT (*getaliaspos)(void *);
-       BOOL (*setaliaspos)(void *, SMB_BIG_UINT);
-
-       /*
-        * alias database query functions. 
-        */
-       LOCAL_GRP *(*getaliasntnam)(const char *, LOCAL_GRP_MEMBER **, int *);
-       LOCAL_GRP *(*getaliasgid)(gid_t , LOCAL_GRP_MEMBER **, int *);
-       LOCAL_GRP *(*getaliasrid)(uint32, LOCAL_GRP_MEMBER **, int *);
-       LOCAL_GRP *(*getaliasent)(void *, LOCAL_GRP_MEMBER **, int *);
-
-       /*
-        * alias database modification functions.
-        */
-       BOOL (*add_alias_entry)(LOCAL_GRP *);
-       BOOL (*mod_alias_entry)(LOCAL_GRP *);
-       BOOL (*del_alias_entry)(uint32);
-
-       BOOL (*add_alias_member)(uint32, DOM_SID*);
-       BOOL (*del_alias_member)(uint32, DOM_SID*);
-
-       /*
-        * user alias functions
-        */
-       BOOL (*getuseraliasntnam)(const char *, LOCAL_GRP **, int *);
+/* key and data records in the tdb locking database */
+struct locking_key {
+       SMB_DEV_T dev;
+       SMB_INO_T inode;
 };
 
-/* this is used for smbstatus */
-
-struct connect_record
-{
-  int magic;
-  int pid;
-  int cnum;
-  uid_t uid;
-  gid_t gid;
-  char name[24];
-  char addr[24];
-  char machine[128];
-  time_t start;
+struct locking_data {
+       int num_share_mode_entries;
+       /* the following two entries are implicit 
+          share_mode_entry modes[num_share_mode_entries];
+           char file_name[];
+       */
 };
 
-/* 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_vuid;
-  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;
-};
 
 /* the following are used by loadparm for option lists */
 typedef enum
@@ -1046,11 +829,22 @@ typedef enum
   P_LOCAL,P_GLOBAL,P_SEPARATOR,P_NONE
 } parm_class;
 
+/* passed to br lock code */
+enum brl_type {READ_LOCK, WRITE_LOCK};
+
 struct enum_list {
        int value;
        char *name;
 };
 
+#define BRLOCK_FN_CAST() \
+       void (*)(SMB_DEV_T dev, SMB_INO_T ino, int pid, \
+                                enum brl_type lock_type, \
+                                br_off start, br_off size)
+#define BRLOCK_FN(fn) \
+       void (*fn)(SMB_DEV_T dev, SMB_INO_T ino, int pid, \
+                                enum brl_type lock_type, \
+                                br_off start, br_off size)
 struct parm_struct
 {
        char *label;
@@ -1073,62 +867,18 @@ struct bitmap {
        int n;
 };
 
-#define FLAG_BASIC 1 /* fundamental options */
-#define FLAG_HIDE  2 /* options that should be hidden in SWAT */
-#define FLAG_PRINT 4 /* printing options */
-#define FLAG_GLOBAL 8 /* local options that should be globally settable in SWAT */
+#define FLAG_BASIC     0x01 /* fundamental options */
+#define FLAG_SHARE     0x02 /* file sharing options */
+#define FLAG_PRINT     0x04 /* printing options */
+#define FLAG_GLOBAL    0x08 /* local options that should be globally settable in SWAT */
 #define FLAG_DEPRECATED 0x10 /* options that should no longer be used */
+#define FLAG_HIDE      0x20 /* options that should be hidden in SWAT */
+#define FLAG_DOS_STRING 0x40 /* convert from UNIX to DOS codepage when reading this string. */
 
 #ifndef LOCKING_VERSION
 #define LOCKING_VERSION 4
 #endif /* LOCKING_VERSION */
 
-/* these are useful macros for checking validity of handles */
-#define OPEN_FSP(fsp)    ((fsp) && (fsp)->open && !(fsp)->is_directory)
-#define OPEN_CONN(conn)    ((conn) && (conn)->open)
-#define IS_IPC(conn)       ((conn) && (conn)->ipc)
-#define IS_PRINT(conn)       ((conn) && (conn)->printer)
-#define FNUM_OK(fsp,c) (OPEN_FSP(fsp) && (c)==(fsp)->conn)
-
-#define CHECK_FSP(fsp,conn) if (!FNUM_OK(fsp,conn)) \
-                               return(ERROR(ERRDOS,ERRbadfid))
-#define CHECK_READ(fsp) if (!(fsp)->can_read) \
-                               return(ERROR(ERRDOS,ERRbadaccess))
-#define CHECK_WRITE(fsp) if (!(fsp)->can_write) \
-                               return(ERROR(ERRDOS,ERRbadaccess))
-#define CHECK_ERROR(fsp) if (HAS_CACHED_ERROR(fsp)) \
-                               return(CACHED_ERROR(fsp))
-
-/* translates a connection number into a service number */
-#define SNUM(conn)         ((conn)?(conn)->service:-1)
-
-/* access various service details */
-#define SERVICE(snum)      (lp_servicename(snum))
-#define PRINTCAP           (lp_printcapname())
-#define PRINTCOMMAND(snum) (lp_printcommand(snum))
-#define PRINTERNAME(snum)  (lp_printername(snum))
-#define CAN_WRITE(conn)    (!conn->read_only)
-#define VALID_SNUM(snum)   (lp_snum_ok(snum))
-#define GUEST_OK(snum)     (VALID_SNUM(snum) && lp_guest_ok(snum))
-#define GUEST_ONLY(snum)   (VALID_SNUM(snum) && lp_guest_only(snum))
-#define CAN_SETDIR(snum)   (!lp_no_set_dir(snum))
-#define CAN_PRINT(conn)    ((conn) && lp_print_ok((conn)->service))
-#define MAP_HIDDEN(conn)   ((conn) && lp_map_hidden((conn)->service))
-#define MAP_SYSTEM(conn)   ((conn) && lp_map_system((conn)->service))
-#define MAP_ARCHIVE(conn)   ((conn) && lp_map_archive((conn)->service))
-#define IS_HIDDEN_PATH(conn,path)  ((conn) && is_in_path((path),(conn)->hide_list))
-#define IS_VETO_PATH(conn,path)  ((conn) && is_in_path((path),(conn)->veto_list))
-#define IS_VETO_OPLOCK_PATH(conn,path)  ((conn) && is_in_path((path),(conn)->veto_oplock_list))
-
-/* 
- * Used by the stat cache code to check if a returned
- * stat structure is valid.
- */
-
-#define VALID_STAT(st) (st.st_nlink != 0)  
-#define VALID_STAT_OF_DIR(st) (VALID_STAT(st) && S_ISDIR(st.st_mode))
-
-#define SMBENCRYPT()       (lp_encrypted_passwords())
 
 /* the basic packet size, assuming no words or bytes */
 #define smb_size 39
@@ -1290,6 +1040,9 @@ struct bitmap {
 #define NT_TRANSACT_RENAME                5
 #define NT_TRANSACT_QUERY_SECURITY_DESC   6
 
+/* Relevant IOCTL codes */
+#define IOCTL_QUERY_JOB_INFO      0x530060
+
 /* these are the trans2 sub fields for primary requests */
 #define smb_tpscnt smb_vwv0
 #define smb_tdscnt smb_vwv1
@@ -1377,6 +1130,11 @@ struct bitmap {
 
 /* this is used on a TConX. I'm not sure the name is very helpful though */
 #define SMB_SUPPORT_SEARCH_BITS        0x0001
+#define SMB_SHARE_IN_DFS               0x0002
+
+/* Named pipe write mode flags. Used in writeX calls. */
+#define PIPE_RAW_MODE 0x4
+#define PIPE_START_MESSAGE 0x8
 
 /* these are the constants used in the above call. */
 /* DesiredAccess */
@@ -1390,6 +1148,8 @@ struct bitmap {
 #define FILE_DELETE_CHILD     0x040
 #define FILE_READ_ATTRIBUTES  0x080
 #define FILE_WRITE_ATTRIBUTES 0x100
+
+#define FILE_ALL_ATTRIBUTES   0x1FF
  
 /* Generic access masks & rights. */
 #define SPECIFIC_RIGHTS_MASK 0x00FFFFL
@@ -1399,7 +1159,32 @@ struct bitmap {
 #define WRITE_DAC_ACCESS     (1L<<18)
 #define WRITE_OWNER_ACCESS   (1L<<19)
 #define SYNCHRONIZE_ACCESS   (1L<<20)
+
+/* Combinations of standard masks. */
+#define STANDARD_RIGHTS_ALL_ACCESS (DELETE_ACCESS|READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS|SYNCHRONIZE_ACCESS)
+#define STANDARD_RIGHTS_EXECUTE_ACCESS (READ_CONTROL_ACCESS)
+#define STANDARD_RIGHTS_READ_ACCESS (READ_CONTROL_ACCESS)
+#define STANDARD_RIGHTS_REQUIRED_ACCESS (DELETE_ACCESS|READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS)
+#define STANDARD_RIGHTS_WRITE_ACCESS (READ_CONTROL_ACCESS)
+
 #define SYSTEM_SECURITY_ACCESS (1L<<24)
+#define MAXIMUM_ALLOWED_ACCESS (1L<<25)
+#define GENERIC_ALL_ACCESS   (1<<28)
+#define GENERIC_EXECUTE_ACCESS  (1<<29)
+#define GENERIC_WRITE_ACCESS   (1<<30)
+#define GENERIC_READ_ACCESS   (((unsigned)1)<<31)
+
+/* Mapping of access rights to UNIX perms. */
+#define UNIX_ACCESS_RWX (UNIX_ACCESS_R|UNIX_ACCESS_W|UNIX_ACCESS_X)
+#define UNIX_ACCESS_R (READ_CONTROL_ACCESS|SYNCHRONIZE_ACCESS|\
+                       FILE_READ_ATTRIBUTES|FILE_READ_EA|FILE_READ_DATA)
+#define UNIX_ACCESS_W (READ_CONTROL_ACCESS|SYNCHRONIZE_ACCESS|\
+                       FILE_WRITE_ATTRIBUTES|FILE_WRITE_EA|\
+                       FILE_APPEND_DATA|FILE_WRITE_DATA)
+#define UNIX_ACCESS_X (READ_CONTROL_ACCESS|SYNCHRONIZE_ACCESS|\
+                       FILE_EXECUTE|FILE_READ_ATTRIBUTES)
+
+#define UNIX_ACCESS_NONE (WRITE_OWNER_ACCESS)
 
 /* Flags field. */
 #define REQUEST_OPLOCK 2
@@ -1467,13 +1252,20 @@ struct bitmap {
 #define RENAME_REPLACE_IF_EXISTS 1
 
 /* Filesystem Attributes. */
-#define FILE_CASE_SENSITIVE_SEARCH 0x1
-#define FILE_CASE_PRESERVED_NAMES 0x2
-#define FILE_UNICODE_ON_DISK 0x4
-#define FILE_PERISITANT_ACLS 0x8
+#define FILE_CASE_SENSITIVE_SEARCH 0x01
+#define FILE_CASE_PRESERVED_NAMES 0x02
+#define FILE_UNICODE_ON_DISK 0x04
+/* According to cifs9f, this is 4, not 8 */
+/* Acconding to testing, this actually sets the security attribute! */
+#define FILE_PERSISTENT_ACLS 0x08
+/* These entries added from cifs9f --tsb */
+#define FILE_FILE_COMPRESSION 0x08
+#define FILE_VOLUME_QUOTAS 0x10
+#define FILE_DEVICE_IS_MOUNTED 0x20
+#define FILE_VOLUME_IS_COMPRESSED 0x8000
 
 /* ChangeNotify flags. */
-#define FILE_NOTIFY_CHANGE_FILE_NAME   0x001
+#define FILE_NOTIFY_CHANGE_FILE        0x001
 #define FILE_NOTIFY_CHANGE_DIR_NAME    0x002
 #define FILE_NOTIFY_CHANGE_ATTRIBUTES  0x004
 #define FILE_NOTIFY_CHANGE_SIZE        0x008
@@ -1482,10 +1274,15 @@ struct bitmap {
 #define FILE_NOTIFY_CHANGE_CREATION    0x040
 #define FILE_NOTIFY_CHANGE_EA          0x080
 #define FILE_NOTIFY_CHANGE_SECURITY    0x100
+#define FILE_NOTIFY_CHANGE_FILE_NAME   0x200
 
 /* where to find the base of the SMB packet proper */
 #define smb_base(buf) (((char *)(buf))+4)
 
+/* we don't allow server strings to be longer than 48 characters as
+   otherwise NT will not honour the announce packets */
+#define MAX_SERVER_STRING_LENGTH 48
+
 
 #define SMB_SUCCESS 0  /* The request was successful. */
 #define ERRDOS 0x01 /*  Error is from the core DOS operating system set. */
@@ -1503,6 +1300,16 @@ int slprintf(char *str, int n, char *format, ...)
 int slprintf();
 #endif
 
+#ifdef HAVE_STDARG_H
+int fdprintf(int fd, char *format, ...)
+#ifdef __GNUC__
+     __attribute__ ((format (printf, 2, 3)))
+#endif
+;
+#else
+int fdprintf();
+#endif
+
 #ifdef WITH_DFS
 void dfs_unlogin(void);
 extern int dcelogin_atmost_once;
@@ -1512,17 +1319,6 @@ extern int dcelogin_atmost_once;
 char *strdup(char *s);
 #endif
 
-#ifndef MIN
-#define MIN(a,b) ((a)<(b)?(a):(b))
-#endif
-#ifndef MAX
-#define MAX(a,b) ((a)>(b)?(a):(b))
-#endif
-
-#ifndef ABS
-#define ABS(a) ((a)>0?(a):(-(a)))
-#endif
-
 #ifndef SIGNAL_CAST
 #define SIGNAL_CAST (RETSIGTYPE (*)(int))
 #endif
@@ -1531,53 +1327,6 @@ char *strdup(char *s);
 #define SELECT_CAST
 #endif
 
-
-/* Some POSIX definitions for those without */
-#ifndef S_IFDIR
-#define S_IFDIR         0x4000
-#endif
-#ifndef S_ISDIR
-#define S_ISDIR(mode)   ((mode & 0xF000) == S_IFDIR)
-#endif
-#ifndef S_IRWXU
-#define S_IRWXU 00700           /* read, write, execute: owner */
-#endif
-#ifndef S_IRUSR
-#define S_IRUSR 00400           /* read permission: owner */
-#endif
-#ifndef S_IWUSR
-#define S_IWUSR 00200           /* write permission: owner */
-#endif
-#ifndef S_IXUSR
-#define S_IXUSR 00100           /* execute permission: owner */
-#endif
-#ifndef S_IRWXG
-#define S_IRWXG 00070           /* read, write, execute: group */
-#endif
-#ifndef S_IRGRP
-#define S_IRGRP 00040           /* read permission: group */
-#endif
-#ifndef S_IWGRP
-#define S_IWGRP 00020           /* write permission: group */
-#endif
-#ifndef S_IXGRP
-#define S_IXGRP 00010           /* execute permission: group */
-#endif
-#ifndef S_IRWXO
-#define S_IRWXO 00007           /* read, write, execute: other */
-#endif
-#ifndef S_IROTH
-#define S_IROTH 00004           /* read permission: other */
-#endif
-#ifndef S_IWOTH
-#define S_IWOTH 00002           /* write permission: other */
-#endif
-#ifndef S_IXOTH
-#define S_IXOTH 00001           /* execute permission: other */
-#endif
-
-
 /* these are used in NetServerEnum to choose what to receive */
 #define SV_TYPE_WORKSTATION         0x00000001
 #define SV_TYPE_SERVER              0x00000002
@@ -1602,6 +1351,7 @@ char *strdup(char *s);
 #define SV_TYPE_SERVER_OSF          0x00100000
 #define SV_TYPE_SERVER_VMS          0x00200000
 #define SV_TYPE_WIN95_PLUS          0x00400000
+#define SV_TYPE_DFS_SERVER         0x00800000
 #define SV_TYPE_ALTERNATE_XPORT     0x20000000  
 #define SV_TYPE_LOCAL_LIST_ONLY     0x40000000  
 #define SV_TYPE_DOMAIN_ENUM         0x80000000
@@ -1632,6 +1382,8 @@ char *strdup(char *s);
 #define FLAGS2_32_BIT_ERROR_CODES     0x4000 
 #define FLAGS2_UNICODE_STRINGS        0x8000
 
+#define FLAGS2_WIN2K_SIGNATURE        0xC852 /* Hack alert ! For now... JRA. */
+
 /* Capabilities.  see ftp.microsoft.com/developr/drg/cifs/cifs/cifs4.txt */
 
 #define CAP_RAW_MODE         0x0001
@@ -1646,6 +1398,7 @@ char *strdup(char *s);
 #define CAP_NT_FIND          0x0200
 #define CAP_DFS              0x1000
 #define CAP_LARGE_READX      0x4000
+#define CAP_EXTENDED_SECURITY 0x80000000
 
 /* protocol types. It assumes that higher protocols include lower protocols
    as subsets */
@@ -1657,7 +1410,7 @@ enum security_types {SEC_SHARE,SEC_USER,SEC_SERVER,SEC_DOMAIN};
 /* server roles */
 enum server_types
 {
-       ROLE_DOMAIN_NONE,
+       ROLE_STANDALONE,
        ROLE_DOMAIN_MEMBER,
        ROLE_DOMAIN_BDC,
        ROLE_DOMAIN_PDC
@@ -1665,10 +1418,10 @@ enum server_types
 
 /* printing types */
 enum printing_types {PRINT_BSD,PRINT_SYSV,PRINT_AIX,PRINT_HPUX,
-                    PRINT_QNX,PRINT_PLP,PRINT_LPRNG,PRINT_SOFTQ};
+                    PRINT_QNX,PRINT_PLP,PRINT_LPRNG,PRINT_SOFTQ,PRINT_CUPS};
 
 /* Remote architectures we know about. */
-enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT, RA_SAMBA};
+enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT, RA_WIN2K, RA_SAMBA};
 
 /* case handling */
 enum case_handling {CASE_LOWER,CASE_UPPER};
@@ -1678,38 +1431,6 @@ enum case_handling {CASE_LOWER,CASE_UPPER};
 enum ssl_version_enum {SMB_SSL_V2,SMB_SSL_V3,SMB_SSL_V23,SMB_SSL_TLS1};
 #endif /* WITH_SSL */
 
-/* Macros to get at offsets within smb_lkrng and smb_unlkrng
-   structures. We cannot define these as actual structures
-   due to possible differences in structure packing
-   on different machines/compilers. */
-
-#define SMB_LPID_OFFSET(indx) (10 * (indx))
-#define SMB_LKOFF_OFFSET(indx) ( 2 + (10 * (indx)))
-#define SMB_LKLEN_OFFSET(indx) ( 6 + (10 * (indx)))
-#define SMB_LARGE_LKOFF_OFFSET_HIGH(indx) (4 + (20 * (indx)))
-#define SMB_LARGE_LKOFF_OFFSET_LOW(indx) (8 + (20 * (indx)))
-#define SMB_LARGE_LKLEN_OFFSET_HIGH(indx) (12 + (20 * (indx)))
-#define SMB_LARGE_LKLEN_OFFSET_LOW(indx) (16 + (20 * (indx)))
-
-/* Macro to cache an error in a write_bmpx_struct */
-#define CACHE_ERROR(w,c,e) ((w)->wr_errclass = (c), (w)->wr_error = (e), \
-                           w->wr_discard = True, -1)
-/* Macro to test if an error has been cached for this fnum */
-#define HAS_CACHED_ERROR(fsp) ((fsp)->open && (fsp)->wbmpx_ptr && \
-                               (fsp)->wbmpx_ptr->wr_discard)
-/* Macro to turn the cached error into an error packet */
-#define CACHED_ERROR(fsp) cached_error_packet(inbuf,outbuf,fsp,__LINE__)
-
-/* these are the datagram types */
-#define DGRAM_DIRECT_UNIQUE 0x10
-
-#define ERROR(class,x) error_packet(inbuf,outbuf,class,x,__LINE__)
-
-/* this is how errors are generated */
-#define UNIXERROR(defclass,deferror) unix_error_packet(inbuf,outbuf,defclass,deferror,__LINE__)
-
-#define SMB_ROUNDUP(x,g) (((x)+((g)-1))&~((g)-1))
-
 /*
  * Global value meaing that the smb_uid field should be
  * ingored (in share level security and protocol level == CORE)
@@ -1737,6 +1458,11 @@ enum ssl_version_enum {SMB_SSL_V2,SMB_SSL_V3,SMB_SSL_V23,SMB_SSL_TLS1};
 #define DEFAULT_CLIENT_CODE_PAGE MSDOS_LATIN_1_CODEPAGE
 #endif /* KANJI */
 
+/* Global val set if multibyte codepage. */
+extern int global_is_multibyte_codepage;
+
+#define get_character_len(x) (global_is_multibyte_codepage ? skip_multibyte_char((x)) : 0)
+
 /* 
  * Size of buffer to use when moving files across filesystems. 
  */
@@ -1748,6 +1474,11 @@ enum ssl_version_enum {SMB_SSL_V2,SMB_SSL_V3,SMB_SSL_V23,SMB_SSL_TLS1};
 extern int unix_ERR_class;
 extern int unix_ERR_code;
 
+/*
+ * Used in chaining code.
+ */
+extern int chain_size;
+
 /*
  * Map the Core and Extended Oplock requesst bits down
  * to common bits (EXCLUSIVE_OPLOCK & BATCH_OPLOCK).
@@ -1778,12 +1509,28 @@ extern int unix_ERR_code;
 /*
  * Bits we test with.
  */
+
+#define NO_OPLOCK 0
 #define EXCLUSIVE_OPLOCK 1
 #define BATCH_OPLOCK 2
+#define LEVEL_II_OPLOCK 4
+
+#define EXCLUSIVE_OPLOCK_TYPE(lck) ((lck) & (EXCLUSIVE_OPLOCK|BATCH_OPLOCK))
+#define BATCH_OPLOCK_TYPE(lck) ((lck) & BATCH_OPLOCK)
+#define LEVEL_II_OPLOCK_TYPE(lck) ((lck) & LEVEL_II_OPLOCK)
 
 #define CORE_OPLOCK_GRANTED (1<<5)
 #define EXTENDED_OPLOCK_GRANTED (1<<15)
 
+/*
+ * Return values for oplock types.
+ */
+
+#define NO_OPLOCK_RETURN 0
+#define EXCLUSIVE_OPLOCK_RETURN 1
+#define BATCH_OPLOCK_RETURN 2
+#define LEVEL_II_OPLOCK_RETURN 3
+
 /*
  * Loopback command offsets.
  */
@@ -1796,8 +1543,9 @@ extern int unix_ERR_code;
 
 /*
  * Oplock break command code to send over the udp socket.
+ * The same message is sent for both exlusive and level II breaks. 
  * 
- * Form of this is :
+ * The form of this is :
  *
  *  0     2       6        10       14    14+devsize 14+devsize+inodesize
  *  +----+--------+--------+--------+-------+--------+
@@ -1807,21 +1555,23 @@ extern int unix_ERR_code;
 
 #define OPLOCK_BREAK_CMD 0x1
 #define OPLOCK_BREAK_PID_OFFSET 2
-#define OPLOCK_BREAK_SEC_OFFSET 6
-#define OPLOCK_BREAK_USEC_OFFSET 10
-#define OPLOCK_BREAK_DEV_OFFSET 14
+#define OPLOCK_BREAK_SEC_OFFSET (OPLOCK_BREAK_PID_OFFSET + sizeof(pid_t))
+#define OPLOCK_BREAK_USEC_OFFSET (OPLOCK_BREAK_SEC_OFFSET + sizeof(time_t))
+#define OPLOCK_BREAK_DEV_OFFSET (OPLOCK_BREAK_USEC_OFFSET + sizeof(long))
 #define OPLOCK_BREAK_INODE_OFFSET (OPLOCK_BREAK_DEV_OFFSET + sizeof(SMB_DEV_T))
 #define OPLOCK_BREAK_MSG_LEN (OPLOCK_BREAK_INODE_OFFSET + sizeof(SMB_INO_T))
 
+#define KERNEL_OPLOCK_BREAK_CMD 0x2
+#define LEVEL_II_OPLOCK_BREAK_CMD 0x3
+
 /*
  * Capabilities abstracted for different systems.
  */
 
 #define KERNEL_OPLOCK_CAPABILITY 0x1
 
-#if defined(HAVE_KERNEL_OPLOCKS)
 /*
- * Oplock break command code sent via the kernel interface.
+ * Oplock break command code sent via the kernel interface (if it exists).
  *
  * Form of this is :
  *
@@ -1830,34 +1580,37 @@ extern int unix_ERR_code;
  *  | cmd| dev    |  inode |
  *  +----+--------+--------+
  */
-
-#define KERNEL_OPLOCK_BREAK_CMD 0x2
 #define KERNEL_OPLOCK_BREAK_DEV_OFFSET 2
 #define KERNEL_OPLOCK_BREAK_INODE_OFFSET (KERNEL_OPLOCK_BREAK_DEV_OFFSET + sizeof(SMB_DEV_T))
 #define KERNEL_OPLOCK_BREAK_MSG_LEN (KERNEL_OPLOCK_BREAK_INODE_OFFSET + sizeof(SMB_INO_T))
 
-#endif /* HAVE_KERNEL_OPLOCKS */
 
-#define CMD_REPLY 0x8000
+/* if a kernel does support oplocks then a structure of the following
+   typee is used to describe how to interact with the kernel */
+struct kernel_oplocks {
+       BOOL (*receive_message)(fd_set *fds, char *buffer, int buffer_len);
+       BOOL (*set_oplock)(files_struct *fsp, int oplock_type);
+       void (*release_oplock)(files_struct *fsp);
+       BOOL (*parse_message)(char *msg_start, int msg_len, SMB_INO_T *inode, SMB_DEV_T *dev);
+       BOOL (*msg_waiting)(fd_set *fds);
+       int notification_fd;
+};
 
-/* useful macros */
 
-/* zero a structure */
-#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
+#define CMD_REPLY 0x8000
 
-/* zero a structure given a pointer to the structure */
-#define ZERO_STRUCTP(x) { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); }
+/* this structure defines the functions for doing change notify in
+   various implementations */
+struct cnotify_fns {
+       void * (*register_notify)(connection_struct *conn, char *path, uint32 flags);
+       BOOL (*check_notify)(connection_struct *conn, uint16 vuid, char *path, uint32 flags, void *data, time_t t);
+       void (*remove_notify)(void *data);
+       int select_time;
+};
 
-/* zero an array - note that sizeof(array) must work - ie. it must not be a 
-   pointer */
-#define ZERO_ARRAY(x) memset((char *)(x), 0, sizeof(x))
 
-#define SMB_ASSERT(b) ((b)?(void)0: \
-        (DEBUG(0,("PANIC: assert failed at %s(%d)\n", \
-                __FILE__, __LINE__)), smb_panic("assert failed")))
-#define SMB_ASSERT_ARRAY(a,n) SMB_ASSERT((sizeof(a)/sizeof((a)[0])) >= (n))
 
-#include "ntdomain.h"
+#include "smb_macros.h"
 
 /* A netbios name structure. */
 struct nmb_name {
@@ -1866,6 +1619,85 @@ struct nmb_name {
   unsigned int name_type;
 };
 
+#define AGENT_CMD_CON       0
+#define AGENT_CMD_CON_ANON  2
+#define AGENT_CMD_CON_REUSE 1
+
+struct pwd_info
+{
+       BOOL null_pwd;
+       BOOL cleartext;
+       BOOL crypted;
+
+       fstring password;
+
+       uchar smb_lm_pwd[16];
+       uchar smb_nt_pwd[16];
+
+       uchar smb_lm_owf[24];
+       uchar smb_nt_owf[128];
+       size_t nt_owf_len;
+
+       uchar lm_cli_chal[8];
+       uchar nt_cli_chal[128];
+       size_t nt_cli_chal_len;
+
+       uchar sess_key[16];
+};
+
+struct ntdom_info
+{
+       unsigned char sess_key[16];        /* Current session key. */
+       unsigned char ntlmssp_hash[258];   /* ntlmssp data. */
+       uint32 ntlmssp_cli_flgs;           /* ntlmssp client flags */
+       uint32 ntlmssp_srv_flgs;           /* ntlmssp server flags */
+       uint32 ntlmssp_seq_num;            /* ntlmssp sequence number */
+       DOM_CRED clnt_cred;                /* Client credential. */
+
+       int max_recv_frag;
+       int max_xmit_frag;
+
+       vuser_key key;
+};
+
+/*
+ * Network Computing Architechture Context Name Named Pipe
+ * See MSDN docs for more information
+ */
+struct ncacn_np
+{
+        fstring pipe_name;
+        struct cli_state *smb;
+        uint16 fnum;
+        BOOL initialised;
+};
+
+#include "rpc_creds.h"
+#include "rpc_secdes.h"
+#include "nt_printing.h"
+
+typedef struct
+{
+       uid_t uid; /* uid of a validated user */
+       gid_t gid; /* gid of a validated user */
+
+       userdom_struct user;
+       BOOL guest;
+
+       /* following groups stuff added by ih */
+       /* This groups info is needed for when we become_user() for this uid */
+       int n_groups;
+       gid_t *groups;
+
+       NT_USER_TOKEN *nt_user_token;
+
+       /* per-user authentication information on NT RPCs */
+       /* lkclXXXX - THIS SHOULD NOT BE HERE! */
+       struct dcinfo dc;
+} user_struct;
+
+#include "ntdomain.h"
+
 #include "client.h"
 #include "rpcclient.h"
 
@@ -1900,13 +1732,6 @@ struct nmb_name {
 #define MAP_TO_GUEST_ON_BAD_USER 1
 #define MAP_TO_GUEST_ON_BAD_PASSWORD 2
 
-/* associate bit field or enumeration field with a string */
-struct field_info
-{
-       uint32 bits;
-       char *str;
-};
+#include "nsswitch/winbindd_nss.h"
 
 #endif /* _SMB_H */
-
-/* _SMB_H */