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