windows-cleanup-20060627
[openafs.git] / src / WINNT / afsd / smb.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 #ifndef __SMB_H_ENV__
11 #define __SMB_H_ENV__ 1
12
13 #ifdef DJGPP
14 #include "netbios95.h"
15 #endif /* DJGPP */
16
17 #include <ntsecapi.h>
18
19 /* Support largefiles by default */
20 #define AFS_LARGEFILES
21
22 /* basic core protocol SMB structure */
23 typedef struct smb {
24     unsigned char id[4];
25     unsigned char com;
26     unsigned char rcls;
27     unsigned char reh;
28     unsigned char errLow;
29     unsigned char errHigh;
30     unsigned char reb;
31     unsigned short flg2;
32     unsigned short res[6];
33     unsigned short tid;
34     unsigned short pid;
35     unsigned short uid;
36     unsigned short mid;
37     unsigned char wct;
38     unsigned char vdata[1];
39 } smb_t;
40
41
42 /* reb values */
43 #define SMB_FLAGS_SUPPORT_LOCKREAD         0x01
44 #define SMB_FLAGS_CLIENT_BUF_AVAIL         0x02
45 #define SMB_FLAGS_CASELESS_PATHNAMES       0x08
46 #define SMB_FLAGS_CANONICAL_PATHNAMES      0x10
47 #define SMB_FLAGS_REQUEST_OPLOCK           0x20
48 #define SMB_FLAGS_REQUEST_BATCH_OPLOCK     0x40
49 #define SMB_FLAGS_SERVER_TO_CLIENT         0x80           
50
51 /* flg2 values */
52
53 #define SMB_FLAGS2_KNOWS_LONG_NAMES        0x0001
54 #define SMB_FLAGS2_KNOWS_EAS               0x0002
55 #define SMB_FLAGS2_SECURITY_SIGNATURE      0x0004
56 #define SMB_FLAGS2_RESERVED1               0x0008
57 #define SMB_FLAGS2_IS_LONG_NAME            0x0040
58 #define SMB_FLAGS2_EXT_SEC                 0x0800
59 #define SMB_FLAGS2_DFS_PATHNAMES           0x1000
60 #define SMB_FLAGS2_PAGING_IO               0x2000
61 #define SMB_FLAGS2_32BIT_STATUS            0x4000
62 #define SMB_FLAGS2_UNICODE                 0x8000
63
64 #define KNOWS_LONG_NAMES(inp) ((((smb_t *)inp)->flg2 & SMB_FLAGS2_KNOWS_LONG_NAMES)?1:0)
65 #define WANTS_DFS_PATHNAMES(inp) ((((smb_t *)inp)->flg2 & SMB_FLAGS2_DFS_PATHNAMES)?1:0)
66
67 /* Information Levels */
68 #define SMB_INFO_STANDARD               1
69 #define SMB_INFO_QUERY_EA_SIZE          2
70 #define SMB_INFO_QUERY_EAS_FROM_LIST    3
71 #define SMB_INFO_QUERY_ALL_EAS          4
72 #define SMB_INFO_IS_NAME_VALID          6
73
74 #define SMB_QUERY_FILE_BASIC_INFO       0x101
75 #define SMB_QUERY_FILE_STANDARD_INFO    0x102
76 #define SMB_QUERY_FILE_EA_INFO          0x103
77 #define SMB_QUERY_FILE_NAME_INFO        0x104
78 #define SMB_QUERY_FILE_ALL_INFO         0x107
79 #define SMB_QUERY_FILE_ALT_NAME_INFO    0x108
80 #define SMB_QUERY_FILE_STREAM_INFO      0x109
81 #define SMB_QUERY_FILE_COMPRESSION_INFO 0x10B
82 #define SMB_QUERY_FILE_UNIX_BASIC       0x200
83 #define SMB_QUERY_FILE_UNIX_LINK        0x201
84
85 #define SMB_SET_FILE_UNIX_BASIC         0x200
86 #define SMB_SET_FILE_UNIX_LINK          0x201
87 #define SMB_SET_FILE_UNIX_HLINK         0x203
88
89 /* more defines */
90 #define SMB_NOPCODES            256     /* # of opcodes in the dispatch table */
91
92 /* threads per VC */
93 #define SMB_THREADSPERVC        4       /* threads per VC */
94
95 /* flags for functions */
96 #define SMB_FLAG_CREATE         1       /* create the structure if necessary */
97 #define SMB_FLAG_AFSLOGON       2       /* operating on behalf of afslogon.dll */
98
99 /* max # of bytes we'll receive in an incoming SMB message */
100 /* the maximum is 2^18-1 for NBT and 2^25-1 for Raw transport messages */
101 /* we will use something smaller but large enough to be efficient */
102 #define SMB_PACKETSIZE  32768 /* was 8400 */
103 /* raw mode is considered obsolete and cannot be used with message signing */
104 #define SMB_MAXRAWSIZE  65536
105
106 /* Negotiate protocol constants */
107 /* Security */
108 #define NEGOTIATE_SECURITY_USER_LEVEL               0x01
109 #define NEGOTIATE_SECURITY_CHALLENGE_RESPONSE       0x02
110 #define NEGOTIATE_SECURITY_SIGNATURES_ENABLED       0x04
111 #define NEGOTIATE_SECURITY_SIGNATURES_REQUIRED      0x08
112
113 /* Capabilities */
114 #define NTNEGOTIATE_CAPABILITY_RAWMODE                  0x00000001L
115 #define NTNEGOTIATE_CAPABILITY_MPXMODE                  0x00000002L
116 #define NTNEGOTIATE_CAPABILITY_UNICODE                  0x00000004L
117 #define NTNEGOTIATE_CAPABILITY_LARGEFILES               0x00000008L
118 #define NTNEGOTIATE_CAPABILITY_NTSMB                    0x00000010L
119 #define NTNEGOTIATE_CAPABILITY_RPCAPI                   0x00000020L
120 #define NTNEGOTIATE_CAPABILITY_NTSTATUS                 0x00000040L
121 #define NTNEGOTIATE_CAPABILITY_LEVEL_II_OPLOCKS         0x00000080L
122 #define NTNEGOTIATE_CAPABILITY_LOCK_AND_READ            0x00000100L
123 #define NTNEGOTIATE_CAPABILITY_NTFIND                   0x00000200L
124 #define NTNEGOTIATE_CAPABILITY_DFS                      0x00001000L
125 #define NTNEGOTIATE_CAPABILITY_NT_INFO_PASSTHRU         0x00002000L
126 #define NTNEGOTIATE_CAPABILITY_LARGE_READX              0x00004000L
127 #define NTNEGOTIATE_CAPABILITY_LARGE_WRITEX             0x00008000L
128 #define NTNEGOTIATE_CAPABILITY_UNIX                     0x00800000L
129 #define NTNEGOTIATE_CAPABILITY_BULK_TRANSFER            0x20000000L
130 #define NTNEGOTIATE_CAPABILITY_COMPRESSED               0x40000000L
131 #define NTNEGOTIATE_CAPABILITY_EXTENDED_SECURITY        0x80000000L
132
133 /* a packet structure for receiving SMB messages; locked by smb_globalLock.
134  * Most of the work involved is in handling chained requests and responses.
135  *
136  * When handling input, inWctp points to the current request's wct field (and
137  * the other parameters and request data can be found from this field).  The
138  * opcode, unfortunately, isn't available there, so is instead copied to the
139  * packet's inCom field.  It is initially set to com, but each chained
140  * operation sets it, also.
141  * The function smb_AdvanceInput advances an input packet to the next request
142  * in the chain.  The inCom field is set to 0xFF when there are no more
143  * requests.  The inCount field is 0 if this is the first request, and
144  * otherwise counts which request it is.
145  *
146  * When handling output, we also have to chain all of the responses together.
147  * The function smb_GetResponsePacket will setup outWctp to point to the right
148  * place.
149  */
150 #define SMB_PACKETMAGIC 0x7436353       /* magic # for packets */
151 typedef struct smb_packet {
152     char data[SMB_PACKETSIZE];
153     struct smb_packet *nextp;           /* in free list, or whatever */
154     long magic;
155     cm_space_t *spacep;                 /* use this for stripping last component */
156     NCB *ncbp;                          /* use this for sending */
157     struct smb_vc *vcp;
158     unsigned long resumeCode;
159     unsigned short inCount;
160     unsigned short fid;                 /* for calls bundled with openAndX */
161     unsigned char *wctp;
162     unsigned char inCom;
163     unsigned char oddByte;
164     unsigned short ncb_length;
165     unsigned char flags;
166 #ifdef DJGPP
167     dos_ptr dos_pkt;
168     unsigned int dos_pkt_sel;
169 #endif /* DJGPP */
170 } smb_packet_t;
171
172 /* smb_packet flags */
173 #define SMB_PACKETFLAG_NOSEND                   1
174 #define SMB_PACKETFLAG_SUSPENDED                2
175
176 /* a structure for making Netbios calls; locked by smb_globalLock */
177 #define SMB_NCBMAGIC    0x2334344
178 typedef struct myncb {
179     NCB ncb;                            /* ncb to use */
180     struct myncb *nextp;                /* when on free list */
181     long magic;
182 #ifdef DJGPP
183     dos_ptr dos_ncb;
184     smb_packet_t *orig_pkt;
185     unsigned int dos_ncb_sel;
186 #endif /* DJGPP */
187 } smb_ncb_t;
188
189 /* structures representing environments from kernel / SMB network.
190  * Most have their own locks, but the tree connection fields and
191  * reference counts are locked by the smb_rctLock.  Those fields will
192  * be marked in comments.
193  */
194
195 /* one per virtual circuit */
196 typedef struct smb_vc {
197     struct smb_vc *nextp;               /* not used */
198     afs_uint32 magic;                   /* a magic value to detect bad entries */
199     unsigned long refCount;             /* the reference count */
200     long flags;                         /* the flags, if any; locked by mx */
201     osi_mutex_t mx;                     /* the mutex */
202     long vcID;                          /* VC id */
203     unsigned short lsn;                 /* the NCB LSN associated with this */
204     unsigned short uidCounter;          /* session ID counter */
205     unsigned short tidCounter;          /* tree ID counter */
206     unsigned short fidCounter;          /* file handle ID counter */
207     struct smb_tid *tidsp;              /* the first child in the tid list */
208     struct smb_user *usersp;            /* the first child in the user session list */
209     struct smb_fid *fidsp;              /* the first child in the open file list */
210     unsigned char errorCount;
211     char rname[17];
212     int lana;
213     char encKey[MSV1_0_CHALLENGE_LENGTH]; /* MSV1_0_CHALLENGE_LENGTH is 8 */
214     void * secCtx;                      /* security context when negotiating SMB extended auth
215                                          * valid when SMB_VCFLAG_AUTH_IN_PROGRESS is set
216                                          */
217     unsigned short session;             /* This is the Session Index associated with the NCBs */
218 } smb_vc_t;
219
220 #define SMB_VC_MAGIC ('S' | 'C'<<8 | 'A'<<16 | 'C'<<24)
221                                         /* have we negotiated ... */
222 #define SMB_VCFLAG_USEV3        1       /* ... version 3 of the protocol */
223 #define SMB_VCFLAG_USECORE      2       /* ... the core protocol */
224 #define SMB_VCFLAG_USENT        4       /* ... NT LM 0.12 or beyond */
225 #define SMB_VCFLAG_STATUS32     8       /* use 32-bit NT status codes */
226 #define SMB_VCFLAG_REMOTECONN   0x10    /* bad: remote conns not allowed */
227 #define SMB_VCFLAG_ALREADYDEAD  0x20    /* do not get tokens from this vc */
228 #define SMB_VCFLAG_SESSX_RCVD   0x40    /* we received at least one session setups on this vc */
229 #define SMB_VCFLAG_AUTH_IN_PROGRESS 0x80 /* a SMB NT extended authentication is in progress */
230 #define SMB_VCFLAG_CLEAN_IN_PROGRESS 0x100
231
232 /* one per user session */
233 typedef struct smb_user {
234     struct smb_user *nextp;             /* next sibling */
235     unsigned long refCount;             /* ref count */
236     afs_uint32 flags;                   /* flags; locked by mx */
237     osi_mutex_t mx;
238     unsigned short userID;              /* the session identifier */
239     struct smb_vc *vcp;                 /* back ptr to virtual circuit */
240     struct smb_username *unp;           /* user name struct */
241     afs_uint32  delete;                 /* ok to del: locked by smb_rctLock */
242 } smb_user_t;
243
244 #define SMB_USERFLAG_DELETE         1   /* delete struct when ref count zero */
245
246 typedef struct smb_username {
247     struct smb_username *nextp;         /* next sibling */
248     unsigned long refCount;             /* ref count */
249     long flags;                         /* flags; locked by mx */
250     osi_mutex_t mx;
251     struct cm_user *userp;              /* CM user structure */
252     char *name;                         /* user name */
253     char *machine;                      /* machine name */
254     time_t last_logoff_t;               /* most recent logoff time */
255 } smb_username_t;
256
257 /* The SMB_USERNAMEFLAG_AFSLOGON is used to preserve the existence of an 
258  * smb_username_t even when the refCount is zero.  This is used to ensure
259  * that tokens set to a username during the integrated logon process are 
260  * preserved until the SMB Session that will require the tokens is created.
261  * The cm_IoctlSetTokens() function when executed from the Network Provider
262  * connects to the AFS Client Service using the credentials of the machine
263  * and not the user for whom the tokens are being configured. */
264 #define SMB_USERNAMEFLAG_AFSLOGON   1
265
266 /* The SMB_USERNAMEFLAG_LOGOFF is used to indicate that the user most
267  * recently logged off at 'last_logoff_t'.  The smb_username_t should not
268  * be deleted even if the refCount is zero before 'last_logoff_t' + 
269  * 'smb_LogoffTransferTimeout' if 'smb_LogoffTokenTransfer' is non-zero.
270  * The smb_Daemon() thread is responsible for purging the expired objects */
271
272 #define SMB_USERNAMEFLAG_LOGOFF     2
273
274 #define SMB_MAX_USERNAME_LENGTH 256
275
276 /* one per tree-connect */
277 typedef struct smb_tid {
278     struct smb_tid *nextp;              /* next sibling */
279     unsigned long refCount;
280     afs_uint32 flags;                   /* protected by mx */
281     osi_mutex_t mx;                     /* for non-tree-related stuff */
282     unsigned short tid;                 /* the tid */
283     struct smb_vc *vcp;                 /* back ptr */
284     struct cm_user *userp;              /* user logged in at the
285                                          * tree connect level (base) */
286     char *pathname;                     /* pathname derived from sharename */
287     afs_uint32  delete;                 /* ok to del: locked by smb_rctLock */
288 } smb_tid_t;
289
290 #define SMB_TIDFLAG_IPC         1       /* IPC$ */
291
292 /* one per process ID */
293 typedef struct smb_pid {
294     struct smb_pid *nextp;              /* next sibling */
295     unsigned long refCount;
296     long flags;
297     osi_mutex_t mx;                     /* for non-tree-related stuff */
298     unsigned short pid;                 /* the pid */
299     struct smb_tid *tidp;               /* back ptr */
300 } smb_pid_t;
301
302 /* ioctl parameter, while being assembled and/or processed */
303 typedef struct smb_ioctl {
304     /* input side */
305     char *inDatap;                      /* ioctl func's current position
306                                          * in input parameter block */
307     char *inAllocp;                     /* allocated input parameter block */
308     long inCopied;                      /* # of input bytes copied in so far
309                                          * by write calls */
310     cm_space_t *prefix;                 /* prefix for subst drives */
311     char *tidPathp;                     /* Pathname associated with Tree ID */
312
313     /* output side */
314     char *outDatap;                     /* output results assembled so far */
315     char *outAllocp;                    /* output results assembled so far */
316     long outCopied;                     /* # of output bytes copied back so far
317                                          * by read calls */
318         
319     /* flags */
320     long flags;
321
322     /* fid pointer */
323     struct smb_fid *fidp;
324
325     /* uid pointer */
326     smb_user_t *uidp;
327 } smb_ioctl_t;
328
329 /* flags for smb_ioctl_t */
330 #define SMB_IOCTLFLAG_DATAIN    1       /* reading data from client to server */
331 #define SMB_IOCTLFLAG_LOGON     2       /* got tokens from integrated logon */
332
333 /* one per file ID; these are really file descriptors */
334 typedef struct smb_fid {
335     osi_queue_t q;
336     unsigned long refCount;
337     afs_uint32 flags;                   /* protected by mx */
338     osi_mutex_t mx;                     /* for non-tree-related stuff */
339     unsigned short fid;                 /* the file ID */
340     struct smb_vc *vcp;                 /* back ptr */
341     struct cm_scache *scp;              /* scache of open file */
342     struct cm_user *userp;              /* user that opened the file
343                                            originally (used to close
344                                            the file if session is
345                                            terminated) */
346     osi_hyper_t offset;                 /* our file pointer */
347     smb_ioctl_t *ioctlp;                /* ptr to ioctl structure */
348                                         /* Under NT, we may need to know the
349                                          * parent directory and pathname used
350                                          * to open the file, either to delete
351                                          * the file on close, or to do a
352                                          * change notification */
353     struct cm_scache *NTopen_dscp;      /* parent directory (NT) */
354     char *NTopen_pathp;                 /* path used in open (NT) */
355     char *NTopen_wholepathp;            /* entire path, not just last name */
356     int curr_chunk;                     /* chunk being read */
357     int prev_chunk;                     /* previous chunk read */
358     int raw_writers;                    /* pending async raw writes */
359     EVENT_HANDLE raw_write_event;       /* signal this when raw_writers zero */
360     afs_uint32  delete;                 /* ok to del: locked by smb_rctLock */
361 } smb_fid_t;
362
363 #define SMB_FID_OPENREAD                1       /* open for reading */
364 #define SMB_FID_OPENWRITE               2       /* open for writing */
365 #define SMB_FID_CREATED                 4       /* a new file */
366 #define SMB_FID_IOCTL                   8       /* a file descriptor for the
367                                                  * magic ioctl file */
368 #define SMB_FID_OPENDELETE              0x10    /* open for deletion (NT) */
369 #define SMB_FID_DELONCLOSE              0x20    /* marked for deletion */
370
371 /*
372  * Now some special flags to work around a bug in NT Client
373  */
374 #define SMB_FID_LENGTHSETDONE           0x40    /* have done 0-length write */
375 #define SMB_FID_MTIMESETDONE            0x80    /* have set modtime via Tr2 */
376 #define SMB_FID_LOOKSLIKECOPY   (SMB_FID_LENGTHSETDONE | SMB_FID_MTIMESETDONE)
377 #define SMB_FID_NTOPEN                  0x100   /* have dscp and pathp */
378
379 #define SMB_FID_SHARE_READ              0x1000
380 #define SMB_FID_SHARE_WRITE             0x2000
381
382 #define SMB_FID_QLOCK_HIGH              0x7f000000
383 #define SMB_FID_QLOCK_LOW               0x00000000
384 #define SMB_FID_QLOCK_LENGTH            1
385 #define SMB_FID_QLOCK_PID               0
386
387 /*
388  * SMB file attributes (32-bit)
389  */
390 #define SMB_ATTR_READONLY       0x0001
391 #define SMB_ATTR_HIDDEN         0x0002 /* hidden file for the purpose of dir listings */
392 #define SMB_ATTR_SYSTEM         0x0004
393 #define SMB_ATTR_VOLUMEID       0x0008 /* obsolete */
394 #define SMB_ATTR_DIRECTORY      0x0010
395 #define SMB_ATTR_ARCHIVE        0x0020
396 #define SMB_ATTR_DEVICE         0x0040
397 #define SMB_ATTR_NORMAL         0x0080 /* normal file. Only valid if used alone */
398 #define SMB_ATTR_TEMPORARY      0x0100
399 #define SMB_ATTR_SPARSE_FILE    0x0200 /* used with dfs links */
400 #define SMB_ATTR_REPARSE_POINT  0x0400
401 #define SMB_ATTR_COMPRESSED     0x0800 /* file or dir is compressed */
402 #define SMB_ATTR_OFFLINE        0x1000
403 #define SMB_ATTR_NOT_CONTENT_INDEXED 0x2000
404 #define SMB_ATTR_ENCRYPTED      0x4000
405
406 #define LOCKING_ANDX_SHARED_LOCK        0x01 /* Read-only lock */
407 #define LOCKING_ANDX_OPLOCK_RELEASE     0x02 /* Oplock break notification */
408 #define LOCKING_ANDX_CHANGE_LOCKTYPE    0x04 /* Change lock type */
409 #define LOCKING_ANDX_CANCEL_LOCK        0x08 /* Cancel outstanding request */
410 #define LOCKING_ANDX_LARGE_FILES        0x10 /* Large file locking format */
411
412 /* for tracking in-progress directory searches */
413 typedef struct smb_dirSearch {
414     osi_queue_t q;                      /* queue of all outstanding cookies */
415     osi_mutex_t mx;                     /* just in case the caller screws up */
416     unsigned long refCount;             /* reference count */
417     long cookie;                        /* value returned to the caller */
418     struct cm_scache *scp;              /* vnode of the dir we're searching */
419     time_t lastTime;                    /* last time we used this (osi_Time) */
420     long flags;                         /* flags (see below);
421                                          * locked by smb_globalLock */
422     unsigned short attribute;           /* search attribute
423                                          * (used for extended protocol) */
424     char mask[256];                     /* search mask for V3 */
425 } smb_dirSearch_t;
426
427 #define SMB_DIRSEARCH_DELETE    1       /* delete struct when ref count zero */
428 #define SMB_DIRSEARCH_HITEOF    2       /* perhaps useful for advisory later */
429 #define SMB_DIRSEARCH_SMALLID   4       /* cookie can only be 8 bits, not 16 */
430 #define SMB_DIRSEARCH_BULKST    8       /* get bulk stat info */
431
432 /* type for patching directory listings */
433 typedef struct smb_dirListPatch {
434     osi_queue_t q;
435     char *dptr;                         /* ptr to attr, time, data, sizel, sizeh */
436     long flags;                         /* flags.  See below */
437     cm_fid_t fid;
438     cm_dirEntry_t *dep;                 /* temp */
439 } smb_dirListPatch_t;
440
441 /* dirListPatch Flags */
442 #define SMB_DIRLISTPATCH_DOTFILE 1  
443 /* the file referenced is a dot file
444  * Note: will not be set if smb_hideDotFiles is false 
445  */
446
447 /* individual lock on a waiting lock request */
448 typedef struct smb_waitingLock {
449     osi_queue_t      q;
450     cm_key_t         key;
451     LARGE_INTEGER    LOffset;
452     LARGE_INTEGER    LLength;
453     cm_file_lock_t * lockp;
454     int              state;
455 } smb_waitingLock_t;
456
457 #define SMB_WAITINGLOCKSTATE_WAITING 0
458 #define SMB_WAITINGLOCKSTATE_DONE    1
459 #define SMB_WAITINGLOCKSTATE_ERROR   2
460
461 /* waiting lock request */
462 typedef struct smb_waitingLockRequest {
463     osi_queue_t   q;
464     smb_vc_t *    vcp;
465     cm_scache_t * scp;
466     smb_packet_t *inp;
467     smb_packet_t *outp;
468     int           lockType;
469     time_t        timeRemaining;
470     smb_waitingLock_t * locks;
471 } smb_waitingLockRequest_t;
472
473 extern smb_waitingLockRequest_t *smb_allWaitingLocks;
474
475 typedef long (smb_proc_t)(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp);
476
477 typedef struct smb_dispatch {
478     smb_proc_t *procp;                  /* proc to call */
479     int flags;                          /* flags describing function */
480 } smb_dispatch_t;
481
482 #define SMB_DISPATCHFLAG_CHAINED        1       /* this is an _AND_X function */
483 #define SMB_DISPATCHFLAG_NORESPONSE     2       /* don't send the response
484                                                  * packet, typically because
485                                                  * the response was already
486                                                  * sent.
487                                                  */
488 #define SMB_MAX_PATH                    256     /* max path length */
489
490 /* prototypes */
491
492 extern void smb_Init(osi_log_t *logp, char *smbNamep, int useV3, int LANadapt,
493         int nThreads
494 #ifndef DJGPP
495         , void *aMBfunc
496 #endif
497   );
498
499 extern void smb_LargeSearchTimeFromUnixTime(FILETIME *largeTimep, time_t unixTime);
500
501 extern void smb_UnixTimeFromLargeSearchTime(time_t *unixTimep, FILETIME *largeTimep);
502
503 extern void smb_SearchTimeFromUnixTime(afs_uint32 *searchTimep, time_t unixTime);
504
505 extern void smb_UnixTimeFromSearchTime(time_t *unixTimep, afs_uint32 searchTime);
506
507 extern void smb_DosUTimeFromUnixTime(afs_uint32 *dosUTimep, time_t unixTime);
508
509 extern void smb_UnixTimeFromDosUTime(time_t *unixTimep, afs_uint32 dosUTime);
510
511 extern void CompensateForSmbClientLastWriteTimeBugs(afs_uint32 *dosTimep);
512
513 extern smb_vc_t *smb_FindVC(unsigned short lsn, int flags, int lana);
514
515 extern void smb_CleanupDeadVC(smb_vc_t *vcp);
516
517 extern void smb_ReleaseVC(smb_vc_t *vcp);
518
519 extern void smb_ReleaseVCNoLock(smb_vc_t *vcp);
520
521 extern smb_tid_t *smb_FindTID(smb_vc_t *vcp, unsigned short tid, int flags);
522
523 extern void smb_HoldTIDNoLock(smb_tid_t *tidp);
524
525 extern void smb_ReleaseTID(smb_tid_t *tidp);
526
527 extern smb_user_t *smb_FindUID(smb_vc_t *vcp, unsigned short uid, int flags);
528
529 extern smb_username_t *smb_FindUserByName(char *usern, char *machine, afs_uint32 flags);
530
531 extern smb_user_t *smb_FindUserByNameThisSession(smb_vc_t *vcp, char *usern); 
532
533 extern void smb_ReleaseUsername(smb_username_t *unp);
534
535 extern void smb_HoldUIDNoLock(smb_user_t *uidp);
536
537 extern void smb_ReleaseUID(smb_user_t *uidp);
538
539 extern cm_user_t *smb_GetUserFromVCP(smb_vc_t *vcp, smb_packet_t *inp);
540
541 extern cm_user_t *smb_GetUserFromUID(smb_user_t *uidp);
542
543 extern long smb_LookupTIDPath(smb_vc_t *vcp, unsigned short tid, char ** tidPathp);
544
545 extern smb_fid_t *smb_FindFID(smb_vc_t *vcp, unsigned short fid, int flags);
546
547 extern void smb_HoldFIDNoLock(smb_fid_t *fidp);
548
549 extern void smb_ReleaseFID(smb_fid_t *fidp);
550
551 extern long smb_CloseFID(smb_vc_t *vcp, smb_fid_t *fidp, cm_user_t *userp,
552                          afs_uint32 dosTime);
553
554 extern int smb_FindShare(smb_vc_t *vcp, smb_user_t *uidp, char *shareName, char **pathNamep);
555
556 extern int smb_FindShareCSCPolicy(char *shareName);
557
558 extern smb_dirSearch_t *smb_FindDirSearchNL(long cookie);
559
560 extern void smb_DeleteDirSearch(smb_dirSearch_t *dsp);
561
562 extern void smb_ReleaseDirSearch(smb_dirSearch_t *dsp);
563
564 extern smb_dirSearch_t *smb_FindDirSearch(long cookie);
565
566 extern smb_dirSearch_t *smb_NewDirSearch(int isV3);
567
568 extern smb_packet_t *smb_CopyPacket(smb_packet_t *packetp);
569
570 extern void smb_FreePacket(smb_packet_t *packetp);
571
572 extern unsigned char *smb_GetSMBData(smb_packet_t *smbp, int *nbytesp);
573
574 extern void smb_SetSMBDataLength(smb_packet_t *smbp, unsigned int dsize);
575
576 extern unsigned int smb_GetSMBParm(smb_packet_t *smbp, int parm);
577
578 extern unsigned int smb_GetSMBOffsetParm(smb_packet_t *smbp, int parm, int offset);
579
580 extern void smb_SetSMBParm(smb_packet_t *smbp, int slot, unsigned int parmValue);
581
582 extern void smb_SetSMBParmLong(smb_packet_t *smbp, int slot, unsigned int parmValue);
583
584 extern void smb_SetSMBParmDouble(smb_packet_t *smbp, int slot, char *parmValuep);
585
586 extern void smb_SetSMBParmByte(smb_packet_t *smbp, int slot, unsigned int parmValue);
587
588 extern void smb_StripLastComponent(char *outPathp, char **lastComponentp,
589         char *inPathp);
590
591 extern unsigned char *smb_ParseASCIIBlock(unsigned char *inp, char **chainpp);
592
593 extern unsigned char *smb_ParseVblBlock(unsigned char *inp, char **chainpp,
594         int *lengthp);
595
596 extern smb_packet_t *smb_GetResponsePacket(smb_vc_t *vcp, smb_packet_t *inp);
597
598 extern void smb_SendPacket(smb_vc_t *vcp, smb_packet_t *inp);
599
600 extern void smb_MapCoreError(long code, smb_vc_t *vcp, unsigned short *scodep,
601         unsigned char *classp);
602
603 extern void smb_MapNTError(long code, unsigned long *NTStatusp);
604
605 extern void smb_HoldVC(smb_vc_t *vcp);
606
607 extern void smb_HoldVCNoLock(smb_vc_t *vcp);
608
609 /* some globals, too */
610 extern char *smb_localNamep;
611
612 extern osi_log_t *smb_logp;
613
614 extern osi_rwlock_t smb_globalLock;
615
616 extern osi_rwlock_t smb_rctLock;
617
618 extern int smb_LogoffTokenTransfer;
619 extern time_t smb_LogoffTransferTimeout;
620
621 extern int smb_maxVCPerServer; /* max # of VCs per server */
622 extern int smb_maxMpxRequests; /* max # of mpx requests */
623
624 extern int smb_StoreAnsiFilenames;
625 extern int smb_hideDotFiles;
626 extern unsigned int smb_IsDotFile(char *lastComp);
627
628 /* the following are used for smb auth */
629 extern int smb_authType; /* Type of SMB authentication to be used. One from below. */
630
631 #define SMB_AUTH_NONE 0
632 #define SMB_AUTH_NTLM 1
633 #define SMB_AUTH_EXTENDED 2
634
635 extern HANDLE smb_lsaHandle; /* LSA handle obtained during smb_init if using SMB auth */
636 extern ULONG smb_lsaSecPackage; /* LSA security package id. Set during smb_init */
637 extern char smb_ServerDomainName[];
638 extern int smb_ServerDomainNameLength;
639 extern char smb_ServerOS[];
640 extern int smb_ServerOSLength;
641 extern char smb_ServerLanManager[];
642 extern int smb_ServerLanManagerLength;
643 extern GUID smb_ServerGUID;
644 extern LSA_STRING smb_lsaLogonOrigin;
645
646 /* used for getting a challenge for SMB auth */
647 typedef struct _MSV1_0_LM20_CHALLENGE_REQUEST {  
648     MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType;
649 } MSV1_0_LM20_CHALLENGE_REQUEST, *PMSV1_0_LM20_CHALLENGE_REQUEST;
650
651 typedef struct _MSV1_0_LM20_CHALLENGE_RESPONSE {  
652     MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType;  
653     UCHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH];
654 } MSV1_0_LM20_CHALLENGE_RESPONSE, *PMSV1_0_LM20_CHALLENGE_RESPONSE;
655 /**/
656
657 extern long smb_AuthenticateUserLM(smb_vc_t *vcp, char * accountName, char * primaryDomain, char * ciPwd, unsigned ciPwdLength, char * csPwd, unsigned csPwdLength);
658
659 extern long smb_GetNormalizedUsername(char * usern, const char * accountName, const char * domainName);
660
661 extern void smb_FormatResponsePacket(smb_vc_t *vcp, smb_packet_t *inp,
662         smb_packet_t *op);
663
664 extern char *myCrt_Dispatch(int i); 
665
666 extern char *myCrt_2Dispatch(int i);
667
668 extern char *myCrt_RapDispatch(int i);
669
670 extern unsigned int smb_Attributes(cm_scache_t *scp);
671
672 extern int smb_ChainFID(int fid, smb_packet_t *inp);
673
674 extern smb_fid_t *smb_FindFID(smb_vc_t *vcp, unsigned short fid, int flags);
675
676 extern void smb_ReleaseFID(smb_fid_t *fidp);
677
678 extern unsigned char *smb_ParseDataBlock(unsigned char *inp, char **chainpp, int *lengthp);
679
680 extern unsigned char *smb_ParseASCIIBlock(unsigned char *inp, char **chainpp);
681
682 extern unsigned char *smb_ParseVblBlock(unsigned char *inp, char **chainpp, int *lengthp);
683
684 extern int smb_SUser(cm_user_t *userp);
685
686 #ifndef DJGPP
687 long smb_WriteData(smb_fid_t *fidp, osi_hyper_t *offsetp, long count, char *op,
688         cm_user_t *userp, long *writtenp);
689 #else /* DJGPP */
690 long smb_WriteData(smb_fid_t *fidp, osi_hyper_t *offsetp, long count, char *op,
691         cm_user_t *userp, long *writtenp, int dosflag);
692 #endif /* !DJGPP */
693
694 #ifndef DJGPP
695 extern long smb_ReadData(smb_fid_t *fidp, osi_hyper_t *offsetp, long count,
696         char *op, cm_user_t *userp, long *readp);
697 #else /* DJGPP */
698 extern long smb_ReadData(smb_fid_t *fidp, osi_hyper_t *offsetp, long count,
699         char *op, cm_user_t *userp, long *readp, int dosflag);
700 #endif /* !DJGPP */
701
702 extern long smb_Rename(smb_vc_t *vcp, smb_packet_t *inp, char *oldPathp, char *newPathp, int attrs);
703
704 extern long smb_Link(smb_vc_t *vcp, smb_packet_t *inp, char *oldPathp, char *newPathp);
705
706 extern BOOL smb_IsLegalFilename(char *filename);
707
708 extern char *smb_GetSharename(void);
709
710 extern DWORD smb_ServerExceptionFilter(void);
711
712 extern void smb_UpdateServerPriority(void);
713 extern void smb_SetRequestStartTime(void);
714 extern void smb_ResetServerPriority(void);
715
716 /* include other include files */
717 #include "smb3.h"
718 #include "smb_ioctl.h"
719 #include "smb_iocons.h"
720
721 cm_user_t *smb_FindOrCreateUser(smb_vc_t *vcp, char *usern);
722
723 #ifdef NOTSERVICE
724 extern void smb_LogPacket(smb_packet_t *packet);
725 #endif /* NOTSERVICE */
726
727 #ifndef MSV1_0_OPTION_ALLOW_BLANK_PASSWORD
728 #define MSV1_0_OPTION_ALLOW_BLANK_PASSWORD      0x1
729 #define MSV1_0_OPTION_DISABLE_ADMIN_LOCKOUT     0x2
730 #define MSV1_0_OPTION_DISABLE_FORCE_GUEST       0x4
731 #define MSV1_0_OPTION_TRY_CACHE_FIRST           0x10
732
733 typedef struct _MSV1_0_SETPROCESSOPTION_REQUEST {
734     MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType;
735     ULONG ProcessOptions;
736     BOOLEAN DisableOptions;
737 } MSV1_0_SETPROCESSOPTION_REQUEST, *PMSV1_0_SETPROCESSOPTION_REQUEST; 
738 #endif
739
740 #endif /* whole file */