2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 #define __SMB_H_ENV__ 1
14 #include "netbios95.h"
17 /* basic core protocol SMB structure */
24 unsigned char errHigh;
27 unsigned short res[6];
33 unsigned char vdata[1];
37 #define SMB_NOPCODES 256 /* # of opcodes in the dispatch table */
40 #define SMB_THREADSPERVC 4 /* threads per VC */
42 /* flags for functions */
43 #define SMB_FLAG_CREATE 1 /* create the structure if necessary */
45 /* max # of bytes we'll receive in an incoming SMB message */
46 #define SMB_PACKETSIZE 8400
48 /* a packet structure for receiving SMB messages; locked by smb_globalLock.
49 * Most of the work involved is in handling chained requests and responses.
51 * When handling input, inWctp points to the current request's wct field (and
52 * the other parameters and request data can be found from this field). The
53 * opcode, unfortunately, isn't available there, so is instead copied to the
54 * packet's inCom field. It is initially set to com, but each chained
55 * operation sets it, also.
56 * The function smb_AdvanceInput advances an input packet to the next request
57 * in the chain. The inCom field is set to 0xFF when there are no more
58 * requests. The inCount field is 0 if this is the first request, and
59 * otherwise counts which request it is.
61 * When handling output, we also have to chain all of the responses together.
62 * The function smb_GetResponsePacket will setup outWctp to point to the right
65 #define SMB_PACKETMAGIC 0x7436353 /* magic # for packets */
66 typedef struct smb_packet {
67 char data[SMB_PACKETSIZE];
68 struct smb_packet *nextp; /* in free list, or whatever */
70 cm_space_t *spacep; /* use this for stripping last component */
71 NCB *ncbp; /* use this for sending */
73 unsigned long resumeCode;
74 unsigned short inCount;
75 unsigned short fid; /* for calls bundled with openAndX */
78 unsigned char oddByte;
79 unsigned short ncb_length;
83 unsigned int dos_pkt_sel;
87 /* smb_packet flags */
88 #define SMB_PACKETFLAG_PROFILE_UPDATE_OK 1
89 #define SMB_PACKETFLAG_NOSEND 2
90 #define SMB_PACKETFLAG_SUSPENDED 4
92 /* a structure for making Netbios calls; locked by smb_globalLock */
93 #define SMB_NCBMAGIC 0x2334344
94 typedef struct myncb {
95 NCB ncb; /* ncb to use */
96 struct myncb *nextp; /* when on free list */
100 smb_packet_t *orig_pkt;
101 unsigned int dos_ncb_sel;
105 /* structures representing environments from kernel / SMB network.
106 * Most have their own locks, but the tree connection fields and
107 * reference counts are locked by the smb_rctLock. Those fields will
108 * be marked in comments.
111 /* one per virtual circuit */
112 typedef struct smb_vc {
113 struct smb_vc *nextp; /* not used */
114 int refCount; /* the reference count */
115 long flags; /* the flags, if any; locked by mx */
116 osi_mutex_t mx; /* the mutex */
117 long vcID; /* VC id */
118 unsigned short lsn; /* the NCB LSN associated with this */
119 unsigned short uidCounter; /* session ID counter */
120 unsigned short tidCounter; /* tree ID counter */
121 unsigned short fidCounter; /* file handle ID counter */
122 struct smb_tid *tidsp; /* the first child in the tid list */
123 struct smb_user *usersp; /* the first child in the user session list */
124 struct smb_fid *fidsp; /* the first child in the open file list */
125 struct smb_user *justLoggedOut; /* ready for profile upload? */
126 unsigned long logoffTime; /* tick count when logged off */
127 /*struct cm_user *logonDLLUser; /* integrated logon user */
128 unsigned char errorCount;
133 /* have we negotiated ... */
134 #define SMB_VCFLAG_USEV3 1 /* ... version 3 of the protocol */
135 #define SMB_VCFLAG_USECORE 2 /* ... the core protocol */
136 #define SMB_VCFLAG_USENT 4 /* ... NT LM 0.12 or beyond */
137 #define SMB_VCFLAG_STATUS32 8 /* use 32-bit NT status codes */
138 #define SMB_VCFLAG_REMOTECONN 0x10 /* bad: remote conns not allowed */
139 #define SMB_VCFLAG_ALREADYDEAD 0x20 /* do not get tokens from this vc */
141 /* one per user session */
142 typedef struct smb_user {
143 struct smb_user *nextp; /* next sibling */
144 long refCount; /* ref count */
145 long flags; /* flags; locked by mx */
147 long userID; /* the session identifier */
148 struct smb_vc *vcp; /* back ptr to virtual circuit */
149 struct smb_username *unp; /* user name struct */
152 typedef struct smb_username {
153 struct smb_username *nextp; /* next sibling */
154 long refCount; /* ref count */
155 long flags; /* flags; locked by mx */
157 struct cm_user *userp; /* CM user structure */
158 char *name; /* user name */
159 char *machine; /* machine name */
162 #define SMB_USERFLAG_DELETE 1 /* delete struct when ref count zero */
164 /* one per tree-connect */
165 typedef struct smb_tid {
166 struct smb_tid *nextp; /* next sibling */
169 osi_mutex_t mx; /* for non-tree-related stuff */
170 unsigned short tid; /* the tid */
171 struct smb_vc *vcp; /* back ptr */
172 struct cm_user *userp; /* user logged in at the
173 * tree connect level (base) */
174 char *pathname; /* pathname derived from sharename */
177 #define SMB_TIDFLAG_DELETE 1 /* delete struct when ref count zero */
179 /* one per process ID */
180 typedef struct smb_pid {
181 struct smb_pid *nextp; /* next sibling */
184 osi_mutex_t mx; /* for non-tree-related stuff */
185 unsigned short pid; /* the pid */
186 struct smb_tid *tidp; /* back ptr */
189 /* ioctl parameter, while being assembled and/or processed */
190 typedef struct smb_ioctl {
192 char *inDatap; /* ioctl func's current position
193 * in input parameter block */
194 char *inAllocp; /* allocated input parameter block */
195 long inCopied; /* # of input bytes copied in so far
197 cm_space_t *prefix; /* prefix for subst drives */
198 char *tidPathp; /* Pathname associated with Tree ID */
201 char *outDatap; /* output results assembled so far */
202 char *outAllocp; /* output results assembled so far */
203 long outCopied; /* # of output bytes copied back so far
210 struct smb_fid *fidp;
217 /* flags for smb_ioctl_t */
218 #define SMB_IOCTLFLAG_DATAIN 1 /* reading data from client to server */
219 #define SMB_IOCTLFLAG_LOGON 2 /* got tokens from integrated logon */
221 /* one per file ID; these are really file descriptors */
222 typedef struct smb_fid {
226 osi_mutex_t mx; /* for non-tree-related stuff */
227 unsigned short fid; /* the file ID */
228 struct smb_vc *vcp; /* back ptr */
229 struct cm_scache *scp; /* scache of open file */
230 long offset; /* our file pointer */
231 smb_ioctl_t *ioctlp; /* ptr to ioctl structure */
232 /* Under NT, we may need to know the
233 * parent directory and pathname used
234 * to open the file, either to delete
235 * the file on close, or to do a
236 * change notification */
237 struct cm_scache *NTopen_dscp; /* parent directory (NT) */
238 char *NTopen_pathp; /* path used in open (NT) */
239 char *NTopen_wholepathp; /* entire path, not just last name */
240 int curr_chunk; /* chunk being read */
241 int prev_chunk; /* previous chunk read */
242 int raw_writers; /* pending async raw writes */
243 EVENT_HANDLE raw_write_event; /* signal this when raw_writers zero */
246 #define SMB_FID_OPENREAD 1 /* open for reading */
247 #define SMB_FID_OPENWRITE 2 /* open for writing */
248 #define SMB_FID_DELETE 4 /* delete struct on ref count 0 */
249 #define SMB_FID_IOCTL 8 /* a file descriptor for the
250 * magic ioctl file */
251 #define SMB_FID_OPENDELETE 0x10 /* open for deletion (NT) */
252 #define SMB_FID_DELONCLOSE 0x20 /* marked for deletion */
254 * Now some special flags to work around a bug in NT Client
256 #define SMB_FID_LENGTHSETDONE 0x40 /* have done 0-length write */
257 #define SMB_FID_MTIMESETDONE 0x80 /* have set modtime via Tr2 */
258 #define SMB_FID_LOOKSLIKECOPY (SMB_FID_LENGTHSETDONE | SMB_FID_MTIMESETDONE)
259 #define SMB_FID_NTOPEN 0x100 /* have dscp and pathp */
261 /* for tracking in-progress directory searches */
262 typedef struct smb_dirSearch {
263 osi_queue_t q; /* queue of all outstanding cookies */
264 osi_mutex_t mx; /* just in case the caller screws up */
265 int refCount; /* reference count */
266 long cookie; /* value returned to the caller */
267 struct cm_scache *scp; /* vnode of the dir we're searching */
268 long lastTime; /* last time we used this */
269 long flags; /* flags (see below);
270 * locked by smb_globalLock */
271 unsigned short attribute; /* search attribute
272 * (used for extended protocol) */
273 char mask[256]; /* search mask for V3 */
276 #define SMB_DIRSEARCH_DELETE 1 /* delete struct when ref count zero */
277 #define SMB_DIRSEARCH_HITEOF 2 /* perhaps useful for advisory later */
278 #define SMB_DIRSEARCH_SMALLID 4 /* cookie can only be 8 bits, not 16 */
279 #define SMB_DIRSEARCH_BULKST 8 /* get bulk stat info */
281 /* type for patching directory listings */
282 typedef struct smb_dirListPatch {
284 char *dptr; /* ptr to attr, time, data, sizel, sizeh */
286 cm_dirEntry_t *dep; /* temp */
287 } smb_dirListPatch_t;
289 /* waiting lock list elements */
290 typedef struct smb_waitingLock {
295 u_long timeRemaining;
299 extern smb_waitingLock_t *smb_allWaitingLocks;
301 typedef long (smb_proc_t)(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp);
303 typedef struct smb_dispatch {
304 smb_proc_t *procp; /* proc to call */
305 int flags; /* flags describing function */
308 #define SMB_DISPATCHFLAG_CHAINED 1 /* this is an _AND_X function */
309 #define SMB_DISPATCHFLAG_NORESPONSE 2 /* don't send the response
310 * packet, typically because
311 * the response was already
314 #define SMB_MAX_PATH 256 /* max path length */
318 extern void smb_Init(osi_log_t *logp, char *smbNamep, int useV3, int LANadapt,
325 extern void smb_LargeSearchTimeFromUnixTime(FILETIME *largeTimep, long unixTime);
327 extern void smb_UnixTimeFromLargeSearchTime(long *unixTimep, FILETIME *largeTimep);
329 extern void smb_SearchTimeFromUnixTime(long *dosTimep, long unixTime);
331 extern void smb_UnixTimeFromSearchTime(long *unixTimep, long searchTime);
333 extern void smb_DosUTimeFromUnixTime(long *dosUTimep, long unixTime);
335 extern void smb_UnixTimeFromDosUTime(long *unixTimep, long dosUTime);
337 extern smb_vc_t *smb_FindVC(unsigned short lsn, int flags, int lana);
339 extern void smb_ReleaseVC(smb_vc_t *vcp);
341 extern smb_tid_t *smb_FindTID(smb_vc_t *vcp, unsigned short tid, int flags);
343 extern void smb_ReleaseTID(smb_tid_t *tidp);
345 extern smb_user_t *smb_FindUID(smb_vc_t *vcp, unsigned short uid, int flags);
347 extern smb_username_t *smb_FindUserByName(char *usern, char *machine, int flags);
349 extern smb_user_t *smb_FindUserByNameThisSession(smb_vc_t *vcp, char *usern);
351 extern smb_username_t *smb_FindUserByName(char *usern, char *machine, int flags);
353 extern smb_user_t *smb_FindUserByNameThisSession(smb_vc_t *vcp, char *usern);
355 extern void smb_ReleaseUID(smb_user_t *uidp);
357 extern cm_user_t *smb_GetUser(smb_vc_t *vcp, smb_packet_t *inp);
359 extern char *smb_GetTIDPath(smb_vc_t *vcp, unsigned short tid);
361 extern smb_fid_t *smb_FindFID(smb_vc_t *vcp, unsigned short fid, int flags);
363 extern void smb_ReleaseFID(smb_fid_t *fidp);
365 extern int smb_FindShare(smb_vc_t *vcp, smb_packet_t *inp, char *shareName, char **pathNamep);
367 extern smb_dirSearch_t *smb_FindDirSearchNL(long cookie);
369 extern void smb_DeleteDirSearch(smb_dirSearch_t *dsp);
371 extern void smb_ReleaseDirSearch(smb_dirSearch_t *dsp);
373 extern smb_dirSearch_t *smb_FindDirSearch(long cookie);
375 extern smb_dirSearch_t *smb_NewDirSearch(int isV3);
377 extern smb_packet_t *smb_CopyPacket(smb_packet_t *packetp);
379 extern void smb_FreePacket(smb_packet_t *packetp);
381 extern unsigned char *smb_GetSMBData(smb_packet_t *smbp, int *nbytesp);
383 extern void smb_SetSMBDataLength(smb_packet_t *smbp, unsigned int dsize);
385 extern unsigned int smb_GetSMBParm(smb_packet_t *smbp, int parm);
387 extern unsigned int smb_GetSMBOffsetParm(smb_packet_t *smbp, int parm, int offset);
389 extern void smb_SetSMBParm(smb_packet_t *smbp, int slot, unsigned int parmValue);
391 extern void smb_SetSMBParmLong(smb_packet_t *smbp, int slot, unsigned int parmValue);
393 extern void smb_SetSMBParmDouble(smb_packet_t *smbp, int slot, char *parmValuep);
395 extern void smb_SetSMBParmByte(smb_packet_t *smbp, int slot, unsigned int parmValue);
397 extern void smb_StripLastComponent(char *outPathp, char **lastComponentp,
400 extern unsigned char *smb_ParseASCIIBlock(unsigned char *inp, char **chainpp);
402 extern unsigned char *smb_ParseVblBlock(unsigned char *inp, char **chainpp,
405 extern smb_packet_t *smb_GetResponsePacket(smb_vc_t *vcp, smb_packet_t *inp);
407 extern void smb_SendPacket(smb_vc_t *vcp, smb_packet_t *inp);
409 extern void smb_MapCoreError(long code, smb_vc_t *vcp, unsigned short *scodep,
410 unsigned char *classp);
412 extern void smb_MapNTError(long code, unsigned long *NTStatusp);
414 extern void smb_HoldVC(smb_vc_t *vcp);
416 /* some globals, too */
417 extern int loggedOut;
418 extern unsigned long loggedOutTime;
419 extern char *loggedOutName;
420 extern smb_user_t *loggedOutUserp;
422 extern osi_log_t *smb_logp;
424 extern osi_rwlock_t smb_globalLock;
426 extern osi_rwlock_t smb_rctLock;
428 extern int smb_LogoffTokenTransfer;
429 extern unsigned long smb_LogoffTransferTimeout;
431 extern void smb_FormatResponsePacket(smb_vc_t *vcp, smb_packet_t *inp,
434 extern char *myCrt_2Dispatch(int i);
436 extern char *myCrt_2Dispatch(int i);
438 extern unsigned int smb_Attributes(cm_scache_t *scp);
440 extern int smb_ChainFID(int fid, smb_packet_t *inp);
442 extern smb_fid_t *smb_FindFID(smb_vc_t *vcp, unsigned short fid, int flags);
444 extern void smb_ReleaseFID(smb_fid_t *fidp);
446 extern unsigned char *smb_ParseDataBlock(unsigned char *inp, char **chainpp, int *lengthp);
448 extern unsigned char *smb_ParseASCIIBlock(unsigned char *inp, char **chainpp);
450 extern unsigned char *smb_ParseVblBlock(unsigned char *inp, char **chainpp, int *lengthp);
452 extern int smb_SUser(cm_user_t *userp);
455 extern long smb_ReadData(smb_fid_t *fidp, osi_hyper_t *offsetp, long count,
456 char *op, cm_user_t *userp, long *readp);
458 extern long smb_ReadData(smb_fid_t *fidp, osi_hyper_t *offsetp, long count,
459 char *op, cm_user_t *userp, long *readp, int dosflag);
462 extern BOOL smb_IsLegalFilename(char *filename);
464 /* include other include files */
466 #include "smb_ioctl.h"
467 #include "smb_iocons.h"
469 cm_user_t *smb_FindOrCreateUser(smb_vc_t *vcp, char *usern);
471 #endif /* whole file */