OpenAFS
OpenAFS distributed network file system
/cygdrive/c/src/openafs/openafs.git/repo/src/WINNT/afsd/smb.h
00001 /*
00002  * Copyright 2000, International Business Machines Corporation and others.
00003  * All Rights Reserved.
00004  *
00005  * This software has been released under the terms of the IBM Public
00006  * License.  For details, see the LICENSE file in the top-level source
00007  * directory or online at http://www.openafs.org/dl/license10.html
00008  */
00009 
00010 #ifndef OPENAFS_WINNT_AFSD_SMB_H
00011 #define OPENAFS_WINNT_AFSD_SMB_H 1
00012 
00013 /* #define DEBUG_SMB_REFCOUNT 1 */
00014 
00015 #if _WIN32_WINNT < 0x0501
00016 #undef _WIN32_WINNT
00017 #define _WIN32_WINNT 0x0501
00018 #endif
00019 #include <ntsecapi.h>
00020 
00021 #include <cm_nls.h>
00022 
00023 /* basic core protocol SMB structure */
00024 #pragma pack(push, 1)
00025 typedef struct smb {
00026     unsigned char id[4];
00027     unsigned char com;
00028     unsigned char rcls;
00029     unsigned char reh;
00030     unsigned char errLow;
00031     unsigned char errHigh;
00032     unsigned char reb;
00033     unsigned short flg2;
00034     unsigned short res[6];
00035     unsigned short tid;
00036     unsigned short pid;
00037     unsigned short uid;
00038     unsigned short mid;
00039     unsigned char wct;
00040     unsigned char vdata[1];
00041 } smb_t;
00042 #pragma pack(pop)
00043 
00044 /* reb values */
00045 #define SMB_FLAGS_SUPPORT_LOCKREAD         0x01
00046 #define SMB_FLAGS_CLIENT_BUF_AVAIL         0x02
00047 #define SMB_FLAGS_CASELESS_PATHNAMES       0x08
00048 #define SMB_FLAGS_CANONICAL_PATHNAMES      0x10
00049 #define SMB_FLAGS_REQUEST_OPLOCK           0x20
00050 #define SMB_FLAGS_REQUEST_BATCH_OPLOCK     0x40
00051 #define SMB_FLAGS_SERVER_TO_CLIENT         0x80
00052 
00053 /* flg2 values */
00054 
00055 #define SMB_FLAGS2_KNOWS_LONG_NAMES        0x0001
00056 #define SMB_FLAGS2_KNOWS_EAS               0x0002
00057 #define SMB_FLAGS2_SECURITY_SIGNATURE      0x0004
00058 #define SMB_FLAGS2_RESERVED1               0x0008
00059 #define SMB_FLAGS2_IS_LONG_NAME            0x0040
00060 #define SMB_FLAGS2_EXT_SEC                 0x0800
00061 #define SMB_FLAGS2_DFS_PATHNAMES           0x1000
00062 #define SMB_FLAGS2_PAGING_IO               0x2000
00063 #define SMB_FLAGS2_32BIT_STATUS            0x4000
00064 #define SMB_FLAGS2_UNICODE                 0x8000
00065 
00066 #define KNOWS_LONG_NAMES(inp) ((((smb_t *)inp)->flg2 & SMB_FLAGS2_KNOWS_LONG_NAMES)?1:0)
00067 #define WANTS_DFS_PATHNAMES(inp) ((((smb_t *)inp)->flg2 & SMB_FLAGS2_DFS_PATHNAMES)?1:0)
00068 #define WANTS_UNICODE(inp) ((((smb_t *)inp)->flg2 & SMB_FLAGS2_UNICODE)?1:0)
00069 
00070 /* Information Levels */
00071 #define SMB_INFO_STANDARD               1
00072 #define SMB_INFO_QUERY_EA_SIZE          2
00073 #define SMB_INFO_QUERY_EAS_FROM_LIST    3
00074 #define SMB_INFO_QUERY_ALL_EAS          4
00075 #define SMB_INFO_IS_NAME_VALID          6
00076 
00077 #define SMB_QUERY_FILE_BASIC_INFO       0x101
00078 #define SMB_QUERY_FILE_STANDARD_INFO    0x102
00079 #define SMB_QUERY_FILE_EA_INFO          0x103
00080 #define SMB_QUERY_FILE_NAME_INFO        0x104
00081 #define SMB_QUERY_FILE_ALL_INFO         0x107
00082 #define SMB_QUERY_FILE_ALT_NAME_INFO    0x108
00083 #define SMB_QUERY_FILE_STREAM_INFO      0x109
00084 #define SMB_QUERY_FILE_COMPRESSION_INFO 0x10B
00085 #define SMB_QUERY_FILE_UNIX_BASIC       0x200
00086 #define SMB_QUERY_FILE_UNIX_LINK        0x201
00087 #define SMB_INFO_PASSTHROUGH           0x1000
00088 
00089 #define SMB_SET_FILE_BASIC_INFO         0x101
00090 #define SMB_SET_FILE_DISPOSITION_INFO   0x102
00091 #define SMB_SET_FILE_ALLOCATION_INFO    0x103
00092 #define SMB_SET_FILE_END_OF_FILE_INFO   0x104
00093 #define SMB_SET_FILE_UNIX_BASIC         0x200
00094 #define SMB_SET_FILE_UNIX_LINK          0x201
00095 #define SMB_SET_FILE_UNIX_HLINK         0x203
00096 
00097 #define SMB_INFO_ALLOCATION             1
00098 #define SMB_INFO_VOLUME                 2
00099 #define SMB_QUERY_FS_LABEL_INFO         0x101
00100 #define SMB_QUERY_FS_VOLUME_INFO        0x102
00101 #define SMB_QUERY_FS_SIZE_INFO          0x103
00102 #define SMB_QUERY_FS_DEVICE_INFO        0x104
00103 #define SMB_QUERY_FS_ATTRIBUTE_INFO     0x105
00104 #define SMB_QUERY_FS_QUOTA_INFO         0x106
00105 #define SMB_QUERY_FS_CONTROL_INFO       0x107
00106 #define SMB_INFO_UNIX                   0x200
00107 #define SMB_INFO_MACOS                  0x301
00108 
00109 #define SMB_FIND_FILE_DIRECTORY_INFO      0x101
00110 #define SMB_FIND_FILE_FULL_DIRECTORY_INFO 0x102
00111 #define SMB_FIND_FILE_NAMES_INFO          0x103
00112 #define SMB_FIND_FILE_BOTH_DIRECTORY_INFO 0x104
00113 
00114 /* SMB_COM_TRANSACTION Named pipe operations */
00115 #define SMB_TRANS_SET_NMPIPE_STATE      0x0001
00116 #define SMB_TRANS_RAW_READ_NMPIPE       0x0011
00117 #define SMB_TRANS_QUERY_NMPIPE_STATE    0x0021
00118 #define SMB_TRANS_QUERY_NMPIPE_INFO     0x0022
00119 #define SMB_TRANS_PEEK_NMPIPE           0x0023
00120 #define SMB_TRANS_TRANSACT_NMPIPE       0x0026
00121 #define SMB_TRANS_RAW_WRITE_NMPIPE      0x0031
00122 #define SMB_TRANS_READ_NMPIPE           0x0036
00123 #define SMB_TRANS_WRITE_NMPIPE          0x0037
00124 #define SMB_TRANS_WAIT_NMPIPE           0x0053
00125 #define SMB_TRANS_CALL_NMPIPE           0x0054
00126 
00127 /* more defines */
00128 #define SMB_NOPCODES            256     /* # of opcodes in the dispatch table */
00129 
00130 /* threads per VC */
00131 #define SMB_THREADSPERVC        4       /* threads per VC */
00132 
00133 /* flags for functions */
00134 #define SMB_FLAG_CREATE         1       /* create the structure if necessary */
00135 #define SMB_FLAG_AFSLOGON       2       /* operating on behalf of afslogon.dll */
00136 
00137 /* max # of bytes we'll receive in an incoming SMB message */
00138 /* the maximum is 2^18-1 for NBT and 2^25-1 for Raw transport messages */
00139 /* we will use something smaller but large enough to be efficient */
00140 #define SMB_PACKETSIZE  32768 /* was 8400 */
00141 /* raw mode is considered obsolete and cannot be used with message signing */
00142 #define SMB_MAXRAWSIZE  65536
00143 /* max STRING characters per packet per request */
00144 #define SMB_STRINGBUFSIZE 4096
00145 
00146 /* Negotiate protocol constants */
00147 /* Security */
00148 #define NEGOTIATE_SECURITY_USER_LEVEL               0x01
00149 #define NEGOTIATE_SECURITY_CHALLENGE_RESPONSE       0x02
00150 #define NEGOTIATE_SECURITY_SIGNATURES_ENABLED       0x04
00151 #define NEGOTIATE_SECURITY_SIGNATURES_REQUIRED      0x08
00152 
00153 /* Capabilities */
00154 #define NTNEGOTIATE_CAPABILITY_RAWMODE                  0x00000001L
00155 #define NTNEGOTIATE_CAPABILITY_MPXMODE                  0x00000002L
00156 #define NTNEGOTIATE_CAPABILITY_UNICODE                  0x00000004L
00157 #define NTNEGOTIATE_CAPABILITY_LARGEFILES               0x00000008L
00158 #define NTNEGOTIATE_CAPABILITY_NTSMB                    0x00000010L
00159 #define NTNEGOTIATE_CAPABILITY_RPCAPI                   0x00000020L
00160 #define NTNEGOTIATE_CAPABILITY_NTSTATUS                 0x00000040L
00161 #define NTNEGOTIATE_CAPABILITY_LEVEL_II_OPLOCKS         0x00000080L
00162 #define NTNEGOTIATE_CAPABILITY_LOCK_AND_READ            0x00000100L
00163 #define NTNEGOTIATE_CAPABILITY_NTFIND                   0x00000200L
00164 #define NTNEGOTIATE_CAPABILITY_DFS                      0x00001000L
00165 #define NTNEGOTIATE_CAPABILITY_NT_INFO_PASSTHRU         0x00002000L
00166 #define NTNEGOTIATE_CAPABILITY_LARGE_READX              0x00004000L
00167 #define NTNEGOTIATE_CAPABILITY_LARGE_WRITEX             0x00008000L
00168 #define NTNEGOTIATE_CAPABILITY_UNIX                     0x00800000L
00169 #define NTNEGOTIATE_CAPABILITY_BULK_TRANSFER            0x20000000L
00170 #define NTNEGOTIATE_CAPABILITY_COMPRESSED               0x40000000L
00171 #define NTNEGOTIATE_CAPABILITY_EXTENDED_SECURITY        0x80000000L
00172 
00173 #define NTSID_LOCAL_SYSTEM L"S-1-5-18"
00174 
00175 /* a packet structure for receiving SMB messages; locked by smb_globalLock.
00176  * Most of the work involved is in handling chained requests and responses.
00177  *
00178  * When handling input, inWctp points to the current request's wct field (and
00179  * the other parameters and request data can be found from this field).  The
00180  * opcode, unfortunately, isn't available there, so is instead copied to the
00181  * packet's inCom field.  It is initially set to com, but each chained
00182  * operation sets it, also.
00183  * The function smb_AdvanceInput advances an input packet to the next request
00184  * in the chain.  The inCom field is set to 0xFF when there are no more
00185  * requests.  The inCount field is 0 if this is the first request, and
00186  * otherwise counts which request it is.
00187  *
00188  * When handling output, we also have to chain all of the responses together.
00189  * The function smb_GetResponsePacket will setup outWctp to point to the right
00190  * place.
00191  */
00192 #define SMB_PACKETMAGIC 0x7436353       /* magic # for packets */
00193 typedef struct smb_packet {
00194     char data[SMB_PACKETSIZE];
00195     struct smb_packet *nextp;           /* in free list, or whatever */
00196     long magic;
00197     cm_space_t *spacep;                 /* use this for stripping last component */
00198     NCB *ncbp;                          /* use this for sending */
00199     struct smb_vc *vcp;
00200     unsigned long resumeCode;
00201     unsigned short inCount;
00202     unsigned short fid;                 /* for calls bundled with openAndX */
00203     unsigned char *wctp;
00204     unsigned char inCom;
00205     unsigned char oddByte;
00206     unsigned short ncb_length;
00207     unsigned char flags;
00208     cm_space_t *stringsp;               /* decoded strings from this packet */
00209 } smb_packet_t;
00210 
00211 /* smb_packet flags */
00212 #define SMB_PACKETFLAG_NOSEND                   1
00213 #define SMB_PACKETFLAG_SUSPENDED                2
00214 
00215 /* a structure for making Netbios calls; locked by smb_globalLock */
00216 #define SMB_NCBMAGIC    0x2334344
00217 typedef struct myncb {
00218     NCB ncb;                            /* ncb to use */
00219     struct myncb *nextp;                /* when on free list */
00220     long magic;
00221 } smb_ncb_t;
00222 
00223 /* structures representing environments from kernel / SMB network.
00224  * Most have their own locks, but the tree connection fields and
00225  * reference counts are locked by the smb_rctLock.  Those fields will
00226  * be marked in comments.
00227  */
00228 
00229 /* one per virtual circuit */
00230 typedef struct smb_vc {
00231     struct smb_vc *nextp;               /* not used */
00232     afs_uint32 magic;                   /* a magic value to detect bad entries */
00233     afs_int32 refCount;                 /* the reference count */
00234     afs_uint32 flags;                   /* the flags, if any; locked by mx */
00235     osi_mutex_t mx;                     /* the mutex */
00236     afs_uint32 vcID;                    /* VC id */
00237     unsigned short lsn;                 /* the NCB LSN associated with this */
00238     unsigned short uidCounter;          /* session ID counter */
00239     unsigned short tidCounter;          /* tree ID counter */
00240     unsigned short fidCounter;          /* file handle ID counter */
00241     struct smb_tid *tidsp;              /* the first child in the tid list */
00242     struct smb_user *usersp;            /* the first child in the user session list */
00243     struct smb_fid *fidsp;              /* the first child in the open file list */
00244     unsigned char errorCount;
00245     clientchar_t rname[17];
00246     int lana;
00247     char encKey[MSV1_0_CHALLENGE_LENGTH]; /* MSV1_0_CHALLENGE_LENGTH is 8 */
00248     void * secCtx;                      /* security context when negotiating SMB extended auth
00249                                          * valid when SMB_VCFLAG_AUTH_IN_PROGRESS is set
00250                                          */
00251     unsigned short session;             /* This is the Session Index associated with the NCBs */
00252 } smb_vc_t;
00253 
00254 #define SMB_VC_MAGIC ('S' | 'C'<<8 | 'A'<<16 | 'C'<<24)
00255                                         /* have we negotiated ... */
00256 #define SMB_VCFLAG_USEV3        1       /* ... version 3 of the protocol */
00257 #define SMB_VCFLAG_USECORE      2       /* ... the core protocol */
00258 #define SMB_VCFLAG_USENT        4       /* ... NT LM 0.12 or beyond */
00259 #define SMB_VCFLAG_STATUS32     8       /* use 32-bit NT status codes */
00260 #define SMB_VCFLAG_REMOTECONN   0x10    /* bad: remote conns not allowed */
00261 #define SMB_VCFLAG_ALREADYDEAD  0x20    /* do not get tokens from this vc */
00262 #define SMB_VCFLAG_SESSX_RCVD   0x40    /* we received at least one session setups on this vc */
00263 #define SMB_VCFLAG_AUTH_IN_PROGRESS 0x80 /* a SMB NT extended authentication is in progress */
00264 #define SMB_VCFLAG_CLEAN_IN_PROGRESS 0x100
00265 #define SMB_VCFLAG_USEUNICODE   0x200   /* une UNICODE for STRING fields (NTLM 0.12 or later) */
00266 
00267 /* one per user session */
00268 typedef struct smb_user {
00269     struct smb_user *nextp;             /* next sibling */
00270     afs_int32 refCount;                 /* ref count */
00271     afs_uint32 flags;                   /* flags; locked by mx */
00272     osi_mutex_t mx;
00273     unsigned short userID;              /* the session identifier */
00274     struct smb_vc *vcp;                 /* back ptr to virtual circuit */
00275     struct smb_username *unp;           /* user name struct */
00276     afs_uint32  deleteOk;               /* ok to del: locked by smb_rctLock */
00277 } smb_user_t;
00278 
00279 #define SMB_USERFLAG_DELETE         1   /* delete struct when ref count zero */
00280 
00281 typedef struct smb_username {
00282     struct smb_username *nextp;         /* next sibling */
00283     afs_int32 refCount;                 /* ref count */
00284     long flags;                         /* flags; locked by mx */
00285     osi_mutex_t mx;
00286     struct cm_user *userp;              /* CM user structure */
00287     clientchar_t *name;                 /* user name */
00288     clientchar_t *machine;              /* machine name */
00289     time_t last_logoff_t;               /* most recent logoff time */
00290 } smb_username_t;
00291 
00292 /* The SMB_USERNAMEFLAG_AFSLOGON is used to preserve the existence of an
00293  * smb_username_t even when the refCount is zero.  This is used to ensure
00294  * that tokens set to a username during the integrated logon process are
00295  * preserved until the SMB Session that will require the tokens is created.
00296  * The cm_IoctlSetTokens() function when executed from the Network Provider
00297  * connects to the AFS Client Service using the credentials of the machine
00298  * and not the user for whom the tokens are being configured. */
00299 #define SMB_USERNAMEFLAG_AFSLOGON   1
00300 
00301 /* The SMB_USERNAMEFLAG_LOGOFF is used to indicate that the user most
00302  * recently logged off at 'last_logoff_t'.  The smb_username_t should not
00303  * be deleted even if the refCount is zero before 'last_logoff_t' +
00304  * 'smb_LogoffTransferTimeout' if 'smb_LogoffTokenTransfer' is non-zero.
00305  * The smb_Daemon() thread is responsible for purging the expired objects */
00306 
00307 #define SMB_USERNAMEFLAG_LOGOFF     2
00308 
00309 /*
00310  * The SMB_USERNAMEFLAG_SID flag indicates that the name is not a username
00311  * but a SID string.
00312  */
00313 #define SMB_USERNAMEFLAG_SID        4
00314 
00315 #define SMB_MAX_USERNAME_LENGTH 256
00316 
00317 /* one per tree-connect */
00318 typedef struct smb_tid {
00319     struct smb_tid *nextp;              /* next sibling */
00320     afs_int32 refCount;
00321     afs_uint32 flags;                   /* protected by mx */
00322     osi_mutex_t mx;                     /* for non-tree-related stuff */
00323     unsigned short tid;                 /* the tid */
00324     struct smb_vc *vcp;                 /* back ptr */
00325     struct cm_user *userp;              /* user logged in at the
00326                                          * tree connect level (base) */
00327     clientchar_t *pathname;             /* pathname derived from sharename */
00328     afs_uint32  deleteOk;               /* ok to del: locked by smb_rctLock */
00329 } smb_tid_t;
00330 
00331 #define SMB_TIDFLAG_IPC         1       /* IPC$ */
00332 
00333 /* one per process ID */
00334 typedef struct smb_pid {
00335     struct smb_pid *nextp;              /* next sibling */
00336     afs_int32 refCount;
00337     long flags;
00338     osi_mutex_t mx;                     /* for non-tree-related stuff */
00339     unsigned short pid;                 /* the pid */
00340     struct smb_tid *tidp;               /* back ptr */
00341 } smb_pid_t;
00342 
00343 
00344 /* Defined in smb_ioctl.h */
00345 struct smb_ioctl;
00346 
00347 /* Defined in smb_rpc.h */
00348 struct smb_rpc;
00349 
00350 /* one per file ID; these are really file descriptors */
00351 typedef struct smb_fid {
00352     osi_queue_t q;
00353     afs_int32 refCount;
00354     afs_uint32 flags;                   /* protected by mx */
00355     osi_mutex_t mx;                     /* for non-tree-related stuff */
00356     unsigned short fid;                 /* the file ID */
00357     struct smb_vc *vcp;                 /* back ptr */
00358     struct cm_scache *scp;              /* scache of open file */
00359     struct cm_user *userp;              /* user that opened the file
00360                                            originally (used to close
00361                                            the file if session is
00362                                            terminated) */
00363     osi_hyper_t offset;                 /* our file pointer */
00364     struct smb_ioctl *ioctlp;           /* ptr to ioctl structure */
00365                                         /* Under NT, we may need to know the
00366                                          * parent directory and pathname used
00367                                          * to open the file, either to delete
00368                                          * the file on close, or to do a
00369                                          * change notification */
00370     struct smb_rpc   *rpcp;             /* ptr to RPC structure.  Used
00371                                            to keep track of endpoint
00372                                            that was opened for the
00373                                            RPC. */
00374     struct cm_scache *NTopen_dscp;      /* parent directory (NT) */
00375     clientchar_t *NTopen_pathp;         /* path used in open (NT) */
00376     clientchar_t *NTopen_wholepathp;    /* entire path, not just last name */
00377     int curr_chunk;                     /* chunk being read */
00378     int prev_chunk;                     /* previous chunk read */
00379     int raw_writers;                    /* pending async raw writes */
00380     EVENT_HANDLE raw_write_event;       /* signal this when raw_writers zero */
00381     afs_uint32  deleteOk;               /* ok to del: locked by smb_rctLock */
00382 } smb_fid_t;
00383 
00384 #define SMB_FID_OPENREAD_LISTDIR        1       /* open for reading / listing directory */
00385 #define SMB_FID_OPENWRITE               2       /* open for writing */
00386 #define SMB_FID_CREATED                 4       /* a new file */
00387 #define SMB_FID_IOCTL                   8       /* a file descriptor for the
00388                                                  * magic ioctl file */
00389 #define SMB_FID_OPENDELETE              0x10    /* open for deletion (NT) */
00390 #define SMB_FID_DELONCLOSE              0x20    /* marked for deletion */
00391 
00392 /*
00393  * Now some special flags to work around a bug in NT Client
00394  */
00395 #define SMB_FID_LENGTHSETDONE           0x40    /* have done 0-length write */
00396 #define SMB_FID_MTIMESETDONE            0x80    /* have set modtime via Tr2 */
00397 #define SMB_FID_LOOKSLIKECOPY   (SMB_FID_LENGTHSETDONE | SMB_FID_MTIMESETDONE)
00398 #define SMB_FID_NTOPEN                  0x100   /* have dscp and pathp */
00399 #define SMB_FID_SEQUENTIAL              0x200
00400 #define SMB_FID_RANDOM                  0x400
00401 #define SMB_FID_EXECUTABLE              0x800
00402 
00403 #define SMB_FID_SHARE_READ              0x1000
00404 #define SMB_FID_SHARE_WRITE             0x2000
00405 
00406 #define SMB_FID_RPC                     0x4000  /* open for MS RPC */
00407 #define SMB_FID_MESSAGEMODEPIPE         0x8000  /* message mode pipe */
00408 #define SMB_FID_BLOCKINGPIPE           0x10000  /* blocking pipe */
00409 #define SMB_FID_RPC_INCALL             0x20000  /* in an RPC call */
00410 
00411 #define SMB_FID_QLOCK_HIGH              0x7f000000
00412 #define SMB_FID_QLOCK_LOW               0x00000000
00413 #define SMB_FID_QLOCK_LENGTH            1
00414 #define SMB_FID_QLOCK_PID               0
00415 
00416 /*
00417  * SMB file attributes (16-bit)
00418  */
00419 #define SMB_ATTR_READONLY       0x0001
00420 #define SMB_ATTR_HIDDEN         0x0002 /* hidden file for the purpose of dir listings */
00421 #define SMB_ATTR_SYSTEM         0x0004
00422 #define SMB_ATTR_VOLUMEID       0x0008 /* obsolete */
00423 #define SMB_ATTR_DIRECTORY      0x0010
00424 #define SMB_ATTR_ARCHIVE        0x0020
00425 #define SMB_ATTR_DEVICE         0x0040
00426 
00427 /* the following are Extended File Attributes (32-bit) */
00428 #define SMB_ATTR_NORMAL         0x0080 /* normal file. Only valid if used alone */
00429 #define SMB_ATTR_TEMPORARY      0x0100
00430 #define SMB_ATTR_SPARSE_FILE    0x0200 /* used with dfs links */
00431 #define SMB_ATTR_REPARSE_POINT  0x0400
00432 #define SMB_ATTR_COMPRESSED     0x0800 /* file or dir is compressed */
00433 #define SMB_ATTR_OFFLINE        0x1000
00434 #define SMB_ATTR_NOT_CONTENT_INDEXED 0x2000
00435 #define SMB_ATTR_ENCRYPTED      0x4000
00436 #define SMB_ATTR_POSIX_SEMANTICS        0x01000000
00437 #define SMB_ATTR_BACKUP_SEMANTICS       0x02000000
00438 #define SMB_ATTR_DELETE_ON_CLOSE        0x04000000
00439 #define SMB_ATTR_SEQUENTIAL_SCAN        0x08000000
00440 #define SMB_ATTR_RANDOM_ACCESS          0x10000000
00441 #define SMB_ATTR_NO_BUFFERING           0x20000000
00442 #define SMB_ATTR_WRITE_THROUGH          0x80000000
00443 
00444 #define LOCKING_ANDX_SHARED_LOCK        0x01 /* Read-only lock */
00445 #define LOCKING_ANDX_OPLOCK_RELEASE     0x02 /* Oplock break notification */
00446 #define LOCKING_ANDX_CHANGE_LOCKTYPE    0x04 /* Change lock type */
00447 #define LOCKING_ANDX_CANCEL_LOCK        0x08 /* Cancel outstanding request */
00448 #define LOCKING_ANDX_LARGE_FILES        0x10 /* Large file locking format */
00449 
00450 /* File type constants */
00451 #define SMB_FILETYPE_DISK               0x0000
00452 #define SMB_FILETYPE_BYTE_MODE_PIPE     0x0001
00453 #define SMB_FILETYPE_MESSAGE_MODE_PIPE  0x0002
00454 #define SMB_FILETYPE_PRINTER            0x0003
00455 #define SMB_FILETYPE_UNKNOWN            0xffff
00456 
00457 /* Device state constants */
00458 #define SMB_DEVICESTATE_READASBYTESTREAM    0x0000
00459 #define SMB_DEVICESTATE_READMSGFROMPIPE     0x0100
00460 #define SMB_DEVICESTATE_BYTESTREAMPIPE      0x0000
00461 #define SMB_DEVICESTATE_MESSAGEMODEPIPE     0x0400
00462 #define SMB_DEVICESTATE_PIPECLIENTEND       0x0000
00463 #define SMB_DEVICESTATE_PIPESERVEREND       0x4000
00464 #define SMB_DEVICESTATE_BLOCKING            0x8000
00465 
00466 /* for tracking in-progress directory searches */
00467 typedef struct smb_dirSearch {
00468     osi_queue_t q;                      /* queue of all outstanding cookies */
00469     osi_mutex_t mx;                     /* just in case the caller screws up */
00470     afs_int32 refCount;                 /* reference count */
00471     long cookie;                        /* value returned to the caller */
00472     struct cm_scache *scp;              /* vnode of the dir we're searching */
00473     time_t lastTime;                    /* last time we used this (osi_Time) */
00474     long flags;                         /* flags (see below);
00475                                          * locked by smb_globalLock */
00476     unsigned short attribute;           /* search attribute
00477                                          * (used for extended protocol) */
00478     clientchar_t tidPath[256];          /* tid path */
00479     clientchar_t relPath[1024];         /* relative path */
00480     clientchar_t mask[256];             /* search mask for V3 */
00481 } smb_dirSearch_t;
00482 
00483 #define SMB_DIRSEARCH_DELETE    1       /* delete struct when ref count zero */
00484 #define SMB_DIRSEARCH_HITEOF    2       /* perhaps useful for advisory later */
00485 #define SMB_DIRSEARCH_SMALLID   4       /* cookie can only be 8 bits, not 16 */
00486 #define SMB_DIRSEARCH_BULKST    8       /* get bulk stat info */
00487 
00488 /* type for patching directory listings */
00489 typedef struct smb_dirListPatch {
00490     osi_queue_t q;
00491     char *dptr;                         /* ptr to attr, time, data, sizel, sizeh */
00492     long flags;                         /* flags.  See below */
00493     cm_fid_t fid;
00494     cm_dirEntry_t *dep;                 /* temp */
00495 } smb_dirListPatch_t;
00496 
00497 /* dirListPatch Flags */
00498 #define SMB_DIRLISTPATCH_DOTFILE        1
00499 /* the file referenced is a dot file
00500  * Note: will not be set if smb_hideDotFiles is false
00501  */
00502 #define SMB_DIRLISTPATCH_IOCTL          2
00503 
00504 /* individual lock on a waiting lock request */
00505 typedef struct smb_waitingLock {
00506     osi_queue_t      q;
00507     cm_key_t         key;
00508     LARGE_INTEGER    LOffset;
00509     LARGE_INTEGER    LLength;
00510     cm_file_lock_t * lockp;
00511     int              state;
00512 } smb_waitingLock_t;
00513 
00514 #define SMB_WAITINGLOCKSTATE_WAITING   0
00515 #define SMB_WAITINGLOCKSTATE_DONE      1
00516 #define SMB_WAITINGLOCKSTATE_ERROR     2
00517 #define SMB_WAITINGLOCKSTATE_CANCELLED 3
00518 
00519 /* waiting lock request */
00520 typedef struct smb_waitingLockRequest {
00521     osi_queue_t   q;
00522     smb_vc_t *    vcp;
00523     cm_scache_t * scp;
00524     smb_packet_t *inp;
00525     smb_packet_t *outp;
00526     int           lockType;
00527     time_t        start_t;              /* osi_Time */
00528     afs_uint32    msTimeout;            /* msecs, 0xFFFFFFFF = wait forever */
00529     smb_waitingLock_t * locks;
00530 } smb_waitingLockRequest_t;
00531 
00532 extern smb_waitingLockRequest_t *smb_allWaitingLocks;
00533 
00534 typedef long (smb_proc_t)(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp);
00535 
00536 typedef struct smb_dispatch {
00537     smb_proc_t *procp;                  /* proc to call */
00538     int flags;                          /* flags describing function */
00539 } smb_dispatch_t;
00540 
00541 #define SMB_DISPATCHFLAG_CHAINED        1       /* this is an _AND_X function */
00542 #define SMB_DISPATCHFLAG_NORESPONSE     2       /* don't send the response
00543                                                  * packet, typically because
00544                                                  * the response was already
00545                                                  * sent.
00546                                                  */
00547 #define SMB_MAX_PATH                    260     /* max path length */
00548 
00549 /* prototypes */
00550 
00551 extern void smb_Init(osi_log_t *logp, int useV3,
00552         int nThreads
00553         , void *aMBfunc
00554   );
00555 
00556 extern void smb_DosUTimeFromUnixTime(afs_uint32 *dosUTimep, time_t unixTime);
00557 
00558 extern void smb_UnixTimeFromDosUTime(time_t *unixTimep, afs_uint32 dosUTime);
00559 
00560 extern void CompensateForSmbClientLastWriteTimeBugs(afs_uint32 *dosTimep);
00561 
00562 #ifdef DEBUG_SMB_REFCOUNT
00563 extern smb_vc_t *smb_FindVCDbg(unsigned short lsn, int flags, int lana, char *, long);
00564 #define smb_FindVC(a,b,c) smb_FindVCDbg(a,b,c,__FILE__,__LINE__);
00565 
00566 extern void smb_HoldVCDbg(smb_vc_t *vcp, char *, long);
00567 #define smb_HoldVC(a) smb_HoldVCDbg(a,__FILE__,__LINE__);
00568 
00569 extern void smb_HoldVCNoLockDbg(smb_vc_t *vcp, char *, long);
00570 #define smb_HoldVCNoLock(a) smb_HoldVCNoLockDbg(a,__FILE__,__LINE__);
00571 
00572 extern void smb_ReleaseVCDbg(smb_vc_t *vcp, char *, long);
00573 #define smb_ReleaseVC(a) smb_ReleaseVCDbg(a,__FILE__,__LINE__);
00574 
00575 extern void smb_ReleaseVCNoLockDbg(smb_vc_t *vcp, char *, long);
00576 #define smb_ReleaseVCNoLock(a) smb_ReleaseVCNoLockDbg(a,__FILE__,__LINE__);
00577 #else
00578 extern smb_vc_t *smb_FindVC(unsigned short lsn, int flags, int lana);
00579 
00580 extern void smb_HoldVC(smb_vc_t *vcp);
00581 
00582 extern void smb_HoldVCNoLock(smb_vc_t *vcp);
00583 
00584 extern void smb_ReleaseVC(smb_vc_t *vcp);
00585 
00586 extern void smb_ReleaseVCNoLock(smb_vc_t *vcp);
00587 #endif
00588 
00589 extern void smb_CleanupDeadVC(smb_vc_t *vcp);
00590 
00591 extern void smb_MarkAllVCsDead(smb_vc_t *exclude_vcp);
00592 
00593 #ifdef DEBUG_SMB_REFCOUNT
00594 extern smb_tid_t *smb_FindTIDDbg(smb_vc_t *vcp, unsigned short tid, int flags, char *, long);
00595 #define smb_FindTID(a,b,c) smb_FindTIDDbg(a,b,c,__FILE__,__LINE__);
00596 
00597 extern void smb_HoldTIDNoLockDbg(smb_tid_t *tidp, char *, long);
00598 #define smb_HoldTIDNoLock(a) smb_HoldTIDNoLockDbg(a,__FILE__,__LINE__);
00599 
00600 extern void smb_ReleaseTIDDbg(smb_tid_t *tidp, afs_uint32 locked, char *, long);
00601 #define smb_ReleaseTID(a,b) smb_ReleaseTIDDbg(a,b,__FILE__,__LINE__);
00602 #else
00603 extern smb_tid_t *smb_FindTID(smb_vc_t *vcp, unsigned short tid, int flags);
00604 
00605 extern void smb_HoldTIDNoLock(smb_tid_t *tidp);
00606 
00607 extern void smb_ReleaseTID(smb_tid_t *tidp, afs_uint32 locked);
00608 #endif
00609 
00610 extern smb_user_t *smb_FindUID(smb_vc_t *vcp, unsigned short uid, int flags);
00611 
00612 extern afs_int32 smb_userIsLocalSystem(smb_user_t *userp);
00613 
00614 extern smb_username_t *smb_FindUserByName(clientchar_t *usern, clientchar_t *machine, afs_uint32 flags);
00615 
00616 extern cm_user_t *smb_FindCMUserByName(clientchar_t *usern, clientchar_t *machine, afs_uint32 flags);
00617 
00618 extern cm_user_t *smb_FindCMUserBySID(clientchar_t *usern, clientchar_t *machine, afs_uint32 flags);
00619 
00620 extern smb_user_t *smb_FindUserByNameThisSession(smb_vc_t *vcp, clientchar_t *usern);
00621 
00622 extern void smb_ReleaseUsername(smb_username_t *unp);
00623 
00624 extern void smb_HoldUIDNoLock(smb_user_t *uidp);
00625 
00626 extern void smb_ReleaseUID(smb_user_t *uidp);
00627 
00628 extern cm_user_t *smb_GetUserFromVCP(smb_vc_t *vcp, smb_packet_t *inp);
00629 
00630 extern cm_user_t *smb_GetUserFromUID(smb_user_t *uidp);
00631 
00632 extern long smb_LookupTIDPath(smb_vc_t *vcp, unsigned short tid, clientchar_t ** tidPathp);
00633 
00634 #ifdef DEBUG_SMB_REFCOUNT
00635 extern smb_fid_t *smb_FindFIDDbg(smb_vc_t *vcp, unsigned short fid, int flags, char *, long);
00636 #define smb_FindFID(a,b,c) smb_FindFIDDbg(a,b,c,__FILE__,__LINE__);
00637 
00638 extern smb_fid_t *smb_FindFIDByScacheDbg(smb_vc_t *vcp, cm_scache_t * scp, char *, long);
00639 #define smb_FindFIDByScache(a,b) smb_FindFIDByScacheDbg(a,b,__FILE__,__LINE__);
00640 
00641 extern void smb_HoldFIDNoLockDbg(smb_fid_t *fidp, char *, long);
00642 #define smb_HoldFIDNoLock(a) smb_HoldFIDNoLockDbg(a,__FILE__,__LINE__);
00643 
00644 extern void smb_ReleaseFIDDbg(smb_fid_t *fidp, char *, long);
00645 #define smb_ReleaseFID(a) smb_ReleaseFIDDbg(a,__FILE__,__LINE__);
00646 #else
00647 extern smb_fid_t *smb_FindFID(smb_vc_t *vcp, unsigned short fid, int flags);
00648 
00649 extern smb_fid_t *smb_FindFIDByScache(smb_vc_t *vcp, cm_scache_t * scp);
00650 
00651 extern void smb_HoldFIDNoLock(smb_fid_t *fidp);
00652 
00653 extern void smb_ReleaseFID(smb_fid_t *fidp);
00654 #endif
00655 
00656 extern long smb_CloseFID(smb_vc_t *vcp, smb_fid_t *fidp, cm_user_t *userp,
00657                          afs_uint32 dosTime);
00658 
00659 extern int smb_FindShare(smb_vc_t *vcp, smb_user_t *uidp, clientchar_t *shareName, clientchar_t **pathNamep);
00660 
00661 extern int smb_FindShareCSCPolicy(clientchar_t *shareName);
00662 
00663 extern smb_dirSearch_t *smb_FindDirSearchNL(long cookie);
00664 
00665 extern void smb_DeleteDirSearch(smb_dirSearch_t *dsp);
00666 
00667 extern void smb_ReleaseDirSearch(smb_dirSearch_t *dsp);
00668 
00669 extern smb_dirSearch_t *smb_FindDirSearch(long cookie);
00670 
00671 extern smb_dirSearch_t *smb_NewDirSearch(int isV3);
00672 
00673 extern smb_packet_t *smb_CopyPacket(smb_packet_t *packetp);
00674 
00675 extern void smb_FreePacket(smb_packet_t *packetp);
00676 
00677 extern unsigned char *smb_GetSMBData(smb_packet_t *smbp, int *nbytesp);
00678 
00679 extern void smb_SetSMBDataLength(smb_packet_t *smbp, unsigned int dsize);
00680 
00681 extern unsigned short smb_GetSMBParm(smb_packet_t *smbp, int parm);
00682 
00683 extern unsigned char smb_GetSMBParmByte(smb_packet_t *smbp, int parm);
00684 
00685 extern unsigned int smb_GetSMBParmLong(smb_packet_t *smbp, int parm);
00686 
00687 extern unsigned int smb_GetSMBOffsetParm(smb_packet_t *smbp, int parm, int offset);
00688 
00689 extern void smb_SetSMBParm(smb_packet_t *smbp, int slot, unsigned int parmValue);
00690 
00691 extern void smb_SetSMBParmLong(smb_packet_t *smbp, int slot, unsigned int parmValue);
00692 
00693 extern void smb_SetSMBParmDouble(smb_packet_t *smbp, int slot, char *parmValuep);
00694 
00695 extern void smb_SetSMBParmByte(smb_packet_t *smbp, int slot, unsigned int parmValue);
00696 
00697 extern void smb_StripLastComponent(clientchar_t *outPathp, clientchar_t **lastComponentp,
00698         clientchar_t *inPathp);
00699 
00700 #define SMB_STRF_FORCEASCII (1<<0)
00701 #define SMB_STRF_ANSIPATH   (1<<1)
00702 #define SMB_STRF_IGNORENUL  (1<<2)
00703 #define SMB_STRF_SRCNULTERM (1<<3)
00704 
00705 extern clientchar_t *smb_ParseASCIIBlock(smb_packet_t * pktp, unsigned char *inp,
00706                                          char **chainpp, int flags);
00707 
00708 extern clientchar_t *smb_ParseString(smb_packet_t * pktp, unsigned char * inp,
00709                                      char ** chainpp, int flags);
00710 
00711 extern clientchar_t *smb_ParseStringBuf(const unsigned char * bufbase,
00712                                         cm_space_t ** stringspp,
00713                                         unsigned char *inp, size_t *pcb_max,
00714                                         char **chainpp, int flags);
00715 
00716 extern clientchar_t *smb_ParseStringCb(smb_packet_t * pktp, unsigned char * inp,
00717                                        size_t cb, char ** chainpp, int flags);
00718 
00719 extern clientchar_t *smb_ParseStringCch(smb_packet_t * pktp, unsigned char * inp,
00720                                         size_t cch, char ** chainpp, int flags);
00721 
00722 extern unsigned char * smb_UnparseString(smb_packet_t * pktp, unsigned char * outp,
00723                                    clientchar_t * str,
00724                                    size_t * plen, int flags);
00725 
00726 extern unsigned char *smb_ParseVblBlock(unsigned char *inp, char **chainpp,
00727                                   int *lengthp);
00728 
00729 extern smb_packet_t *smb_GetResponsePacket(smb_vc_t *vcp, smb_packet_t *inp);
00730 
00731 extern void smb_SendPacket(smb_vc_t *vcp, smb_packet_t *inp);
00732 
00733 extern void smb_MapCoreError(long code, smb_vc_t *vcp, unsigned short *scodep,
00734         unsigned char *classp);
00735 
00736 extern void smb_MapNTError(long code, unsigned long *NTStatusp, afs_uint32 redir);
00737 
00738 extern void smb_MapWin32Error(long code, unsigned long *Win32Ep);
00739 
00740 /* some globals, too */
00741 extern char *smb_localNamep;
00742 
00743 extern osi_log_t *smb_logp;
00744 
00745 extern osi_rwlock_t smb_globalLock;
00746 
00747 extern osi_rwlock_t smb_rctLock;
00748 
00749 extern int smb_LogoffTokenTransfer;
00750 extern time_t smb_LogoffTransferTimeout;
00751 
00752 extern int smb_maxVCPerServer; /* max # of VCs per server */
00753 extern int smb_maxMpxRequests; /* max # of mpx requests */
00754 
00755 extern int smb_StoreAnsiFilenames;
00756 extern int smb_hideDotFiles;
00757 extern unsigned int smb_IsDotFile(clientchar_t *lastComp);
00758 extern afs_uint32 smb_AsyncStore;
00759 extern afs_uint32 smb_AsyncStoreSize;
00760 
00761 /* the following are used for smb auth */
00762 extern int smb_authType; /* Type of SMB authentication to be used. One from below. */
00763 
00764 #define SMB_AUTH_NONE 0
00765 #define SMB_AUTH_NTLM 1
00766 #define SMB_AUTH_EXTENDED 2
00767 
00768 extern HANDLE smb_lsaHandle; /* LSA handle obtained during smb_init if using SMB auth */
00769 extern ULONG smb_lsaSecPackage; /* LSA security package id. Set during smb_init */
00770 extern clientchar_t smb_ServerDomainName[];
00771 extern int smb_ServerDomainNameLength;
00772 extern clientchar_t smb_ServerOS[];
00773 extern int smb_ServerOSLength;
00774 extern clientchar_t smb_ServerLanManager[];
00775 extern int smb_ServerLanManagerLength;
00776 extern GUID smb_ServerGUID;
00777 extern LSA_STRING smb_lsaLogonOrigin;
00778 extern LONG smb_UseUnicode;
00779 extern DWORD smb_monitorReqs;
00780 
00781 /* used for getting a challenge for SMB auth */
00782 typedef struct _MSV1_0_LM20_CHALLENGE_REQUEST {
00783     MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType;
00784 } MSV1_0_LM20_CHALLENGE_REQUEST, *PMSV1_0_LM20_CHALLENGE_REQUEST;
00785 
00786 typedef struct _MSV1_0_LM20_CHALLENGE_RESPONSE {
00787     MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType;
00788     UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH];
00789 } MSV1_0_LM20_CHALLENGE_RESPONSE, *PMSV1_0_LM20_CHALLENGE_RESPONSE;
00790 
00791 
00792 extern long smb_AuthenticateUserLM(smb_vc_t *vcp, clientchar_t * accountName, clientchar_t * primaryDomain, char * ciPwd, unsigned ciPwdLength, char * csPwd, unsigned csPwdLength);
00793 
00794 extern long smb_GetNormalizedUsername(clientchar_t * usern, const clientchar_t * accountName, const clientchar_t * domainName);
00795 
00796 extern void smb_FormatResponsePacket(smb_vc_t *vcp, smb_packet_t *inp,
00797         smb_packet_t *op);
00798 
00799 extern char *myCrt_Dispatch(int i);
00800 
00801 extern char *myCrt_2Dispatch(int i);
00802 
00803 extern char *myCrt_RapDispatch(int i);
00804 
00805 extern char * myCrt_NmpipeDispatch(int i);
00806 
00807 extern unsigned int smb_Attributes(cm_scache_t *scp);
00808 
00809 extern int smb_ChainFID(int fid, smb_packet_t *inp);
00810 
00811 extern unsigned char *smb_ParseDataBlock(unsigned char *inp, char **chainpp, int *lengthp);
00812 
00813 extern unsigned char *smb_ParseVblBlock(unsigned char *inp, char **chainpp, int *lengthp);
00814 
00815 extern int smb_SUser(cm_user_t *userp);
00816 
00817 long smb_WriteData(smb_fid_t *fidp, osi_hyper_t *offsetp, afs_uint32 count, char *op,
00818         cm_user_t *userp, long *writtenp);
00819 
00820 extern long smb_ReadData(smb_fid_t *fidp, osi_hyper_t *offsetp, afs_uint32 count,
00821         char *op, cm_user_t *userp, long *readp);
00822 
00823 extern long smb_Rename(smb_vc_t *vcp, smb_packet_t *inp, clientchar_t *oldPathp, clientchar_t *newPathp, int attrs);
00824 
00825 extern long smb_Link(smb_vc_t *vcp, smb_packet_t *inp, clientchar_t *oldPathp, clientchar_t *newPathp);
00826 
00827 extern BOOL smb_IsLegalFilename(clientchar_t *filename);
00828 
00829 extern char *smb_GetSharename(void);
00830 
00831 extern DWORD smb_ServerExceptionFilter(void);
00832 
00833 extern void smb_RestartListeners(int);
00834 extern void smb_StopListeners(int);
00835 extern void smb_StopListener(NCB *ncbp, int lana, int wait);
00836 extern long smb_IsNetworkStarted(void);
00837 extern void smb_LanAdapterChange(int);
00838 extern void smb_SetLanAdapterChangeDetected(void);
00839 
00840 extern void smb_InitReq(cm_req_t *reqp);
00841 
00842 #define SMB_LISTENER_UNINITIALIZED -1
00843 #define SMB_LISTENER_STOPPED 0
00844 #define SMB_LISTENER_STARTED 1
00845 
00846 /* include other include files */
00847 #include "smb3.h"
00848 #include "smb_ioctl.h"
00849 #include "smb_iocons.h"
00850 #include "smb_rpc.h"
00851 #include "cm_vnodeops.h"
00852 
00853 extern int smb_unixModeDefaultFile;
00854 extern int smb_unixModeDefaultDir;
00855 extern void smb_SetInitialModeBitsForFile(int smb_attr, cm_attr_t * attr);
00856 extern void smb_SetInitialModeBitsForDir(int smb_attr, cm_attr_t * attr);
00857 extern void smb_configureBackConnectionHostNames(int bEnable);
00858 extern void smb_configureExtendedSMBSessionTimeouts(int bEnable);
00859 
00860 cm_user_t *smb_FindOrCreateUser(smb_vc_t *vcp, clientchar_t *usern);
00861 
00862 int smb_DumpVCP(FILE *outputFile, char *cookie, int lock);
00863 
00864 void smb_Shutdown(void);
00865 
00866 #ifdef NOTSERVICE
00867 extern void smb_LogPacket(smb_packet_t *packet);
00868 #endif /* NOTSERVICE */
00869 
00870 #ifndef MSV1_0_OPTION_ALLOW_BLANK_PASSWORD
00871 #define MSV1_0_OPTION_ALLOW_BLANK_PASSWORD      0x1
00872 #define MSV1_0_OPTION_DISABLE_ADMIN_LOCKOUT     0x2
00873 #define MSV1_0_OPTION_DISABLE_FORCE_GUEST       0x4
00874 #define MSV1_0_OPTION_TRY_CACHE_FIRST           0x10
00875 
00876 typedef struct _MSV1_0_SETPROCESSOPTION_REQUEST {
00877     MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType;
00878     ULONG ProcessOptions;
00879     BOOLEAN DisableOptions;
00880 } MSV1_0_SETPROCESSOPTION_REQUEST, *PMSV1_0_SETPROCESSOPTION_REQUEST;
00881 #endif
00882 
00883 #endif /* whole file */
 All Data Structures Files Functions Variables