windows-smb-started-synchronization-20080108
[openafs.git] / src / WINNT / afsd / smb.h
index e2002a0..f8f8980 100644 (file)
 #ifndef __SMB_H_ENV__
 #define __SMB_H_ENV__ 1
 
-#ifdef DJGPP
-#include "netbios95.h"
-#endif /* DJGPP */
-
+#if _WIN32_WINNT < 0x0501
+#undef _WIN32_WINNT
+#define _WIN32_WINNT 0x0501
+#endif
 #include <ntsecapi.h>
 
+/* Support largefiles by default */
+#define AFS_LARGEFILES
+
 /* basic core protocol SMB structure */
+#pragma pack(push, 1)
 typedef struct smb {
     unsigned char id[4];
     unsigned char com;
@@ -34,7 +38,7 @@ typedef struct smb {
     unsigned char wct;
     unsigned char vdata[1];
 } smb_t;
-
+#pragma pack(pop)
 
 /* reb values */
 #define SMB_FLAGS_SUPPORT_LOCKREAD         0x01
@@ -78,11 +82,33 @@ typedef struct smb {
 #define SMB_QUERY_FILE_COMPRESSION_INFO 0x10B
 #define SMB_QUERY_FILE_UNIX_BASIC       0x200
 #define SMB_QUERY_FILE_UNIX_LINK        0x201
+#define SMB_INFO_PASSTHROUGH           0x1000
 
+#define SMB_SET_FILE_BASIC_INFO         0x101
+#define SMB_SET_FILE_DISPOSITION_INFO   0x102
+#define SMB_SET_FILE_ALLOCATION_INFO    0x103
+#define SMB_SET_FILE_END_OF_FILE_INFO   0x104
 #define SMB_SET_FILE_UNIX_BASIC         0x200
 #define SMB_SET_FILE_UNIX_LINK          0x201
 #define SMB_SET_FILE_UNIX_HLINK         0x203
 
+#define SMB_INFO_ALLOCATION            1
+#define SMB_INFO_VOLUME                        2
+#define SMB_QUERY_FS_LABEL_INFO         0x101
+#define SMB_QUERY_FS_VOLUME_INFO       0x102
+#define SMB_QUERY_FS_SIZE_INFO         0x103
+#define SMB_QUERY_FS_DEVICE_INFO       0x104
+#define SMB_QUERY_FS_ATTRIBUTE_INFO    0x105
+#define SMB_QUERY_FS_QUOTA_INFO         0x106
+#define SMB_QUERY_FS_CONTROL_INFO       0x107
+#define SMB_INFO_UNIX                  0x200
+#define SMB_INFO_MACOS                 0x301
+
+#define SMB_FIND_FILE_DIRECTORY_INFO      0x101
+#define SMB_FIND_FILE_FULL_DIRECTORY_INFO 0x102
+#define SMB_FIND_FILE_NAMES_INFO         0x103
+#define SMB_FIND_FILE_BOTH_DIRECTORY_INFO 0x104
+
 /* more defines */
 #define SMB_NOPCODES           256     /* # of opcodes in the dispatch table */
 
@@ -160,16 +186,11 @@ typedef struct smb_packet {
     unsigned char oddByte;
     unsigned short ncb_length;
     unsigned char flags;
-#ifdef DJGPP
-    dos_ptr dos_pkt;
-    unsigned int dos_pkt_sel;
-#endif /* DJGPP */
 } smb_packet_t;
 
 /* smb_packet flags */
-#define SMB_PACKETFLAG_PROFILE_UPDATE_OK       1
-#define SMB_PACKETFLAG_NOSEND                  2
-#define SMB_PACKETFLAG_SUSPENDED               4
+#define SMB_PACKETFLAG_NOSEND                  1
+#define SMB_PACKETFLAG_SUSPENDED               2
 
 /* a structure for making Netbios calls; locked by smb_globalLock */
 #define SMB_NCBMAGIC   0x2334344
@@ -177,11 +198,6 @@ typedef struct myncb {
     NCB ncb;                           /* ncb to use */
     struct myncb *nextp;               /* when on free list */
     long magic;
-#ifdef DJGPP
-    dos_ptr dos_ncb;
-    smb_packet_t *orig_pkt;
-    unsigned int dos_ncb_sel;
-#endif /* DJGPP */
 } smb_ncb_t;
 
 /* structures representing environments from kernel / SMB network.
@@ -193,6 +209,7 @@ typedef struct myncb {
 /* one per virtual circuit */
 typedef struct smb_vc {
     struct smb_vc *nextp;              /* not used */
+    afs_uint32 magic;                  /* a magic value to detect bad entries */
     unsigned long refCount;            /* the reference count */
     long flags;                                /* the flags, if any; locked by mx */
     osi_mutex_t mx;                    /* the mutex */
@@ -204,8 +221,6 @@ typedef struct smb_vc {
     struct smb_tid *tidsp;             /* the first child in the tid list */
     struct smb_user *usersp;           /* the first child in the user session list */
     struct smb_fid *fidsp;             /* the first child in the open file list */
-    struct smb_user *justLoggedOut;    /* ready for profile upload? */
-    time_t logoffTime;                 /* tick count when logged off */
     unsigned char errorCount;
     char rname[17];
     int lana;
@@ -213,8 +228,10 @@ typedef struct smb_vc {
     void * secCtx;                      /* security context when negotiating SMB extended auth
                                          * valid when SMB_VCFLAG_AUTH_IN_PROGRESS is set
                                          */
+    unsigned short session;            /* This is the Session Index associated with the NCBs */
 } smb_vc_t;
 
+#define SMB_VC_MAGIC ('S' | 'C'<<8 | 'A'<<16 | 'C'<<24)
                                        /* have we negotiated ... */
 #define SMB_VCFLAG_USEV3       1       /* ... version 3 of the protocol */
 #define SMB_VCFLAG_USECORE     2       /* ... the core protocol */
@@ -224,18 +241,22 @@ typedef struct smb_vc {
 #define SMB_VCFLAG_ALREADYDEAD 0x20    /* do not get tokens from this vc */
 #define SMB_VCFLAG_SESSX_RCVD  0x40    /* we received at least one session setups on this vc */
 #define SMB_VCFLAG_AUTH_IN_PROGRESS 0x80 /* a SMB NT extended authentication is in progress */
+#define SMB_VCFLAG_CLEAN_IN_PROGRESS 0x100
 
 /* one per user session */
 typedef struct smb_user {
     struct smb_user *nextp;            /* next sibling */
     unsigned long refCount;            /* ref count */
-    long flags;                                /* flags; locked by mx */
+    afs_uint32 flags;                  /* flags; locked by mx */
     osi_mutex_t mx;
     unsigned short userID;             /* the session identifier */
     struct smb_vc *vcp;                        /* back ptr to virtual circuit */
     struct smb_username *unp;           /* user name struct */
+    afs_uint32 delete;                 /* ok to del: locked by smb_rctLock */
 } smb_user_t;
 
+#define SMB_USERFLAG_DELETE        1   /* delete struct when ref count zero */
+
 typedef struct smb_username {
     struct smb_username *nextp;                /* next sibling */
     unsigned long refCount;            /* ref count */
@@ -244,10 +265,25 @@ typedef struct smb_username {
     struct cm_user *userp;             /* CM user structure */
     char *name;                                /* user name */
     char *machine;                      /* machine name */
+    time_t last_logoff_t;              /* most recent logoff time */
 } smb_username_t;
 
-#define SMB_USERFLAG_DELETE    1       /* delete struct when ref count zero */
-#define SMB_USERFLAG_AFSLOGON   2       /* do not delete when the refCount reaches zero */
+/* The SMB_USERNAMEFLAG_AFSLOGON is used to preserve the existence of an 
+ * smb_username_t even when the refCount is zero.  This is used to ensure
+ * that tokens set to a username during the integrated logon process are 
+ * preserved until the SMB Session that will require the tokens is created.
+ * The cm_IoctlSetTokens() function when executed from the Network Provider
+ * connects to the AFS Client Service using the credentials of the machine
+ * and not the user for whom the tokens are being configured. */
+#define SMB_USERNAMEFLAG_AFSLOGON   1
+
+/* The SMB_USERNAMEFLAG_LOGOFF is used to indicate that the user most
+ * recently logged off at 'last_logoff_t'.  The smb_username_t should not
+ * be deleted even if the refCount is zero before 'last_logoff_t' + 
+ * 'smb_LogoffTransferTimeout' if 'smb_LogoffTokenTransfer' is non-zero.
+ * The smb_Daemon() thread is responsible for purging the expired objects */
+
+#define SMB_USERNAMEFLAG_LOGOFF     2
 
 #define SMB_MAX_USERNAME_LENGTH 256
 
@@ -255,17 +291,17 @@ typedef struct smb_username {
 typedef struct smb_tid {
     struct smb_tid *nextp;             /* next sibling */
     unsigned long refCount;
-    long flags;
+    afs_uint32 flags;                  /* protected by mx */
     osi_mutex_t mx;                    /* for non-tree-related stuff */
     unsigned short tid;                        /* the tid */
     struct smb_vc *vcp;                        /* back ptr */
     struct cm_user *userp;             /* user logged in at the
                                         * tree connect level (base) */
     char *pathname;                    /* pathname derived from sharename */
+    afs_uint32 delete;                 /* ok to del: locked by smb_rctLock */
 } smb_tid_t;
 
-#define SMB_TIDFLAG_DELETE     1       /* delete struct when ref count zero */
-#define SMB_TIDFLAG_IPC        2 /* IPC$ */
+#define SMB_TIDFLAG_IPC                1       /* IPC$ */
 
 /* one per process ID */
 typedef struct smb_pid {
@@ -283,7 +319,7 @@ typedef struct smb_ioctl {
     char *inDatap;                     /* ioctl func's current position
                                         * in input parameter block */
     char *inAllocp;                    /* allocated input parameter block */
-    long inCopied;                     /* # of input bytes copied in so far
+    afs_uint32 inCopied;                       /* # of input bytes copied in so far
                                         * by write calls */
     cm_space_t *prefix;                        /* prefix for subst drives */
     char *tidPathp;                    /* Pathname associated with Tree ID */
@@ -291,11 +327,11 @@ typedef struct smb_ioctl {
     /* output side */
     char *outDatap;                    /* output results assembled so far */
     char *outAllocp;                   /* output results assembled so far */
-    long outCopied;                    /* # of output bytes copied back so far
+    afs_uint32 outCopied;              /* # of output bytes copied back so far
                                          * by read calls */
        
     /* flags */
-    long flags;
+    afs_uint32 flags;
 
     /* fid pointer */
     struct smb_fid *fidp;
@@ -312,7 +348,7 @@ typedef struct smb_ioctl {
 typedef struct smb_fid {
     osi_queue_t q;
     unsigned long refCount;
-    unsigned long flags;
+    afs_uint32 flags;                  /* protected by mx */
     osi_mutex_t mx;                    /* for non-tree-related stuff */
     unsigned short fid;                        /* the file ID */
     struct smb_vc *vcp;                        /* back ptr */
@@ -321,7 +357,7 @@ typedef struct smb_fid {
                                            originally (used to close
                                            the file if session is
                                            terminated) */
-    long offset;                       /* our file pointer */
+    osi_hyper_t offset;                        /* our file pointer */
     smb_ioctl_t *ioctlp;               /* ptr to ioctl structure */
                                        /* Under NT, we may need to know the
                                         * parent directory and pathname used
@@ -335,11 +371,12 @@ typedef struct smb_fid {
     int prev_chunk;                    /* previous chunk read */
     int raw_writers;                   /* pending async raw writes */
     EVENT_HANDLE raw_write_event;      /* signal this when raw_writers zero */
+    afs_uint32 delete;                 /* ok to del: locked by smb_rctLock */
 } smb_fid_t;
 
-#define SMB_FID_OPENREAD               1       /* open for reading */
+#define SMB_FID_OPENREAD_LISTDIR       1       /* open for reading / listing directory */
 #define SMB_FID_OPENWRITE              2       /* open for writing */
-#define SMB_FID_DELETE                 4       /* delete struct on ref count 0 */
+#define SMB_FID_CREATED                 4       /* a new file */
 #define SMB_FID_IOCTL                  8       /* a file descriptor for the
                                                 * magic ioctl file */
 #define SMB_FID_OPENDELETE             0x10    /* open for deletion (NT) */
@@ -352,17 +389,20 @@ typedef struct smb_fid {
 #define SMB_FID_MTIMESETDONE           0x80    /* have set modtime via Tr2 */
 #define SMB_FID_LOOKSLIKECOPY  (SMB_FID_LENGTHSETDONE | SMB_FID_MTIMESETDONE)
 #define SMB_FID_NTOPEN                 0x100   /* have dscp and pathp */
+#define SMB_FID_SEQUENTIAL             0x200
+#define SMB_FID_RANDOM                 0x400
+#define SMB_FID_EXECUTABLE              0x800
 
 #define SMB_FID_SHARE_READ              0x1000
 #define SMB_FID_SHARE_WRITE             0x2000
 
-#define SMB_FID_QLOCK_HIGH              0x0fe00000
+#define SMB_FID_QLOCK_HIGH              0x7f000000
 #define SMB_FID_QLOCK_LOW               0x00000000
 #define SMB_FID_QLOCK_LENGTH            1
 #define SMB_FID_QLOCK_PID               0
 
 /*
- * SMB file attributes (32-bit)
+ * SMB file attributes (16-bit)
  */
 #define SMB_ATTR_READONLY       0x0001
 #define SMB_ATTR_HIDDEN         0x0002 /* hidden file for the purpose of dir listings */
@@ -371,6 +411,8 @@ typedef struct smb_fid {
 #define SMB_ATTR_DIRECTORY      0x0010
 #define SMB_ATTR_ARCHIVE        0x0020
 #define SMB_ATTR_DEVICE         0x0040
+
+/* the following are Extended File Attributes (32-bit) */
 #define SMB_ATTR_NORMAL         0x0080 /* normal file. Only valid if used alone */
 #define SMB_ATTR_TEMPORARY      0x0100
 #define SMB_ATTR_SPARSE_FILE    0x0200 /* used with dfs links */
@@ -379,6 +421,13 @@ typedef struct smb_fid {
 #define SMB_ATTR_OFFLINE        0x1000
 #define SMB_ATTR_NOT_CONTENT_INDEXED 0x2000
 #define SMB_ATTR_ENCRYPTED      0x4000
+#define SMB_ATTR_POSIX_SEMANTICS       0x01000000
+#define SMB_ATTR_BACKUP_SEMANTICS      0x02000000
+#define SMB_ATTR_DELETE_ON_CLOSE       0x04000000
+#define SMB_ATTR_SEQUENTIAL_SCAN       0x08000000
+#define SMB_ATTR_RANDOM_ACCESS         0x10000000
+#define SMB_ATTR_NO_BUFFERING          0x20000000
+#define SMB_ATTR_WRITE_THROUGH         0x80000000
 
 #define LOCKING_ANDX_SHARED_LOCK        0x01 /* Read-only lock */
 #define LOCKING_ANDX_OPLOCK_RELEASE     0x02 /* Oplock break notification */
@@ -398,6 +447,8 @@ typedef struct smb_dirSearch {
                                         * locked by smb_globalLock */
     unsigned short attribute;          /* search attribute
                                         * (used for extended protocol) */
+    char tidPath[256];                  /* tid path */
+    char relPath[1024];                 /* relative path */        
     char mask[256];                    /* search mask for V3 */
 } smb_dirSearch_t;
 
@@ -462,15 +513,13 @@ typedef struct smb_dispatch {
                                                 * the response was already
                                                 * sent.
                                                  */
-#define SMB_MAX_PATH                    256     /* max path length */
+#define SMB_MAX_PATH                    260     /* max path length */
 
 /* prototypes */
 
-extern void smb_Init(osi_log_t *logp, char *smbNamep, int useV3, int LANadapt,
+extern void smb_Init(osi_log_t *logp, int useV3,
        int nThreads
-#ifndef DJGPP
         , void *aMBfunc
-#endif
   );
 
 extern void smb_LargeSearchTimeFromUnixTime(FILETIME *largeTimep, time_t unixTime);
@@ -497,6 +546,8 @@ extern void smb_ReleaseVCNoLock(smb_vc_t *vcp);
 
 extern smb_tid_t *smb_FindTID(smb_vc_t *vcp, unsigned short tid, int flags);
 
+extern void smb_HoldTIDNoLock(smb_tid_t *tidp);
+
 extern void smb_ReleaseTID(smb_tid_t *tidp);
 
 extern smb_user_t *smb_FindUID(smb_vc_t *vcp, unsigned short uid, int flags);
@@ -507,14 +558,22 @@ extern smb_user_t *smb_FindUserByNameThisSession(smb_vc_t *vcp, char *usern);
 
 extern void smb_ReleaseUsername(smb_username_t *unp);
 
+extern void smb_HoldUIDNoLock(smb_user_t *uidp);
+
 extern void smb_ReleaseUID(smb_user_t *uidp);
 
-extern cm_user_t *smb_GetUser(smb_vc_t *vcp, smb_packet_t *inp);
+extern cm_user_t *smb_GetUserFromVCP(smb_vc_t *vcp, smb_packet_t *inp);
+
+extern cm_user_t *smb_GetUserFromUID(smb_user_t *uidp);
 
 extern long smb_LookupTIDPath(smb_vc_t *vcp, unsigned short tid, char ** tidPathp);
 
 extern smb_fid_t *smb_FindFID(smb_vc_t *vcp, unsigned short fid, int flags);
 
+extern smb_fid_t *smb_FindFIDByScache(smb_vc_t *vcp, cm_scache_t * scp);
+
+extern void smb_HoldFIDNoLock(smb_fid_t *fidp);
+
 extern void smb_ReleaseFID(smb_fid_t *fidp);
 
 extern long smb_CloseFID(smb_vc_t *vcp, smb_fid_t *fidp, cm_user_t *userp,
@@ -542,7 +601,11 @@ extern unsigned char *smb_GetSMBData(smb_packet_t *smbp, int *nbytesp);
 
 extern void smb_SetSMBDataLength(smb_packet_t *smbp, unsigned int dsize);
 
-extern unsigned int smb_GetSMBParm(smb_packet_t *smbp, int parm);
+extern unsigned short smb_GetSMBParm(smb_packet_t *smbp, int parm);
+
+extern unsigned char smb_GetSMBParmByte(smb_packet_t *smbp, int parm);
+
+extern unsigned int smb_GetSMBParmLong(smb_packet_t *smbp, int parm);
 
 extern unsigned int smb_GetSMBOffsetParm(smb_packet_t *smbp, int parm, int offset);
 
@@ -577,10 +640,6 @@ extern void smb_HoldVCNoLock(smb_vc_t *vcp);
 
 /* some globals, too */
 extern char *smb_localNamep;
-extern int loggedOut;
-extern time_t loggedOutTime;
-extern char *loggedOutName;
-extern smb_user_t *loggedOutUserp;
 
 extern osi_log_t *smb_logp;
 
@@ -644,10 +703,6 @@ extern unsigned int smb_Attributes(cm_scache_t *scp);
 
 extern int smb_ChainFID(int fid, smb_packet_t *inp);
 
-extern smb_fid_t *smb_FindFID(smb_vc_t *vcp, unsigned short fid, int flags);
-
-extern void smb_ReleaseFID(smb_fid_t *fidp);
-
 extern unsigned char *smb_ParseDataBlock(unsigned char *inp, char **chainpp, int *lengthp);
 
 extern unsigned char *smb_ParseASCIIBlock(unsigned char *inp, char **chainpp);
@@ -656,13 +711,11 @@ extern unsigned char *smb_ParseVblBlock(unsigned char *inp, char **chainpp, int
 
 extern int smb_SUser(cm_user_t *userp);
 
-#ifndef DJGPP
+long smb_WriteData(smb_fid_t *fidp, osi_hyper_t *offsetp, long count, char *op,
+       cm_user_t *userp, long *writtenp);
+
 extern long smb_ReadData(smb_fid_t *fidp, osi_hyper_t *offsetp, long count,
        char *op, cm_user_t *userp, long *readp);
-#else /* DJGPP */
-extern long smb_ReadData(smb_fid_t *fidp, osi_hyper_t *offsetp, long count,
-       char *op, cm_user_t *userp, long *readp, int dosflag);
-#endif /* !DJGPP */
 
 extern long smb_Rename(smb_vc_t *vcp, smb_packet_t *inp, char *oldPathp, char *newPathp, int attrs);
 
@@ -674,6 +727,21 @@ extern char *smb_GetSharename(void);
 
 extern DWORD smb_ServerExceptionFilter(void);
 
+extern void smb_UpdateServerPriority(void);
+extern void smb_SetRequestStartTime(void);
+extern void smb_ResetServerPriority(void);
+extern void smb_RestartListeners(int);
+extern void smb_StopListeners(int);
+extern void smb_StopListener(NCB *ncbp, int lana);
+extern long smb_IsNetworkStarted(void);
+extern void smb_LanAdapterChange(int);
+extern void smb_SetLanAdapterChangeDetected(void);
+
+
+#define SMB_LISTENER_UNINITIALIZED -1
+#define SMB_LISTENER_STOPPED 0
+#define SMB_LISTENER_STARTED 1
+
 /* include other include files */
 #include "smb3.h"
 #include "smb_ioctl.h"