DEVEL15-windows-unicode-support-20080509
[openafs.git] / src / WINNT / afsd / smb3.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 __SMB3_H_ENV__
11 #define __SMB3_H_ENV__ 1
12
13 typedef struct smb_tran2Packet {
14         osi_queue_t q;                  /* queue of all packets */
15         int com;                        /* Trans or Trans2 (0x25 or 0x32) */
16         int totalData;                  /* total # of expected data bytes */
17         int totalParms;                 /* total # of expected parm bytes */
18         int oldTotalParms;              /* initial estimate of parm bytes */
19         int curData;                    /* current # of received data bytes */
20         int curParms;                   /* current # of received parm bytes */
21         int maxReturnData;              /* max # of returned data bytes */
22         int maxReturnParms;             /* max # of returned parm bytes */
23         int opcode;                     /* subopcode we're handling */
24         long flags;                     /* flags */
25         smb_vc_t *vcp;                  /* virtual circuit we're dealing with */
26         unsigned short tid;             /* tid to match */
27         unsigned short mid;             /* mid to match */
28         unsigned short pid;             /* pid to remember */
29         unsigned short uid;             /* uid to remember */
30         unsigned short res[6];          /* contains PidHigh */
31         unsigned short *parmsp;         /* parms */
32         unsigned char *datap;           /* data bytes */
33         cm_space_t * stringsp;          /* decoded strings */
34 } smb_tran2Packet_t;
35
36 /* for flags field */
37 #define SMB_TRAN2PFLAG_ALLOC    1
38 #define SMB_TRAN2PFLAG_USEUNICODE  2
39
40 typedef struct smb_tran2Dispatch {
41         long (*procp)(smb_vc_t *, smb_tran2Packet_t *, smb_packet_t *);
42         long flags;
43 } smb_tran2Dispatch_t;
44
45 /* Data Structures that are written to or read from the wire directly
46  * must be byte aligned (no padding).
47  */
48 #pragma pack(push, 1)
49 typedef struct smb_tran2QFSInfo {
50     union {
51         struct {
52             unsigned long FSID;                 /* file system ID */
53             unsigned long sectorsPerAllocUnit;
54             unsigned long totalAllocUnits;      /* on the disk */
55             unsigned long availAllocUnits;      /* free blocks */
56             unsigned short bytesPerSector;      /* bytes per sector */
57         } allocInfo;
58         struct {
59             unsigned long vsn;                  /* volume serial number */
60             char vnCount;                       /* count of chars in label, incl null */
61             char /* STRING */ label[24];        /* pad out with nulls */
62         } volumeInfo;
63         struct {
64             FILETIME      vct;          /* volume creation time */
65             unsigned long vsn;          /* volume serial number */
66             unsigned long vnCount;      /* length of volume label in bytes */
67             char res[2];                /* reserved */
68             char /* STRING */ label[20];        /* volume label */
69         } FSvolumeInfo;
70         struct {
71             LARGE_INTEGER totalAllocUnits;      /* on the disk */
72             LARGE_INTEGER availAllocUnits;      /* free blocks */
73             unsigned long sectorsPerAllocUnit;
74             unsigned long bytesPerSector;       /* bytes per sector */
75         } FSsizeInfo;
76         struct {
77             unsigned long devType;              /* device type */
78             unsigned long characteristics;
79         } FSdeviceInfo;
80         struct {
81             unsigned long attributes;
82             unsigned long maxCompLength;        /* max path component length */
83             unsigned long FSnameLength;         /* length of file system name */
84             unsigned char /* STRING */ FSname[24]; /* File system name */
85         } FSattributeInfo;
86     } u;
87 } smb_tran2QFSInfo_t;
88
89 typedef struct {
90     union {
91         struct {
92             unsigned long  creationDateTime;    /* SMB_DATE / SMB_TIME */
93             unsigned long  lastAccessDateTime;  /* SMB_DATE / SMB_TIME */
94             unsigned long  lastWriteDateTime;   /* SMB_DATE / SMB_TIME */
95             unsigned long  dataSize;
96             unsigned long  allocationSize;
97             unsigned short attributes;
98             unsigned long  eaSize;
99         } QPstandardInfo;
100         struct {
101             unsigned long  creationDateTime;    /* SMB_DATE / SMB_TIME */
102             unsigned long  lastAccessDateTime;  /* SMB_DATE / SMB_TIME */
103             unsigned long  lastWriteDateTime;   /* SMB_DATE / SMB_TIME */
104             unsigned long  dataSize;
105             unsigned long  allocationSize;
106             unsigned short attributes;
107             unsigned long  eaSize;
108         } QPeaSizeInfo;
109         struct {
110             unsigned short maxDataCount;
111             unsigned short eaErrorOffset;
112             unsigned long  listLength;
113             unsigned char  eaList[128];
114         } QPeasFromListInfo;
115         struct {
116             unsigned short maxDataCount;
117             unsigned short eaErrorOffset;
118             unsigned long  listLength;
119             unsigned char  eaList[128];
120         } QPallEasInfo;
121         struct {
122             FILETIME       creationTime;
123             FILETIME       lastAccessTime;
124             FILETIME       lastWriteTime;
125             FILETIME       changeTime;
126             unsigned long  attributes;
127             unsigned long  reserved;
128         } QPfileBasicInfo;
129         struct {
130             LARGE_INTEGER  allocationSize;
131             LARGE_INTEGER  endOfFile;
132             unsigned long  numberOfLinks;
133             unsigned char  deletePending;
134             unsigned char  directory;
135             unsigned short reserved;
136         } QPfileStandardInfo;
137         struct {
138             unsigned long  eaSize;
139         } QPfileEaInfo;
140         struct {
141             unsigned long  fileNameLength;
142             unsigned char  fileName[512]; /* STRING */
143         } QPfileNameInfo;
144         struct {
145             FILETIME       creationTime;
146             FILETIME       lastAccessTime;
147             FILETIME       lastWriteTime;
148             FILETIME       changeTime;
149             unsigned long  attributes;
150             LARGE_INTEGER  allocationSize;
151             LARGE_INTEGER  endOfFile;
152             unsigned long  numberOfLinks;
153             unsigned char  deletePending;
154             unsigned char  directory;
155             LARGE_INTEGER  indexNumber;
156             unsigned long  eaSize;
157             unsigned long  accessFlags;
158             LARGE_INTEGER  indexNumber2;
159             LARGE_INTEGER  currentByteOffset;
160             unsigned long  mode;
161             unsigned long  alignmentRequirement;
162             unsigned long  fileNameLength;
163             unsigned char  fileName[512]; /* STRING */
164         } QPfileAllInfo;
165         struct {
166             unsigned long  fileNameLength;
167             unsigned char  fileName[512]; /* STRING */
168         } QPfileAltNameInfo;
169         struct {
170             unsigned long  nextEntryOffset;
171             unsigned long  streamNameLength;
172             LARGE_INTEGER  streamSize;
173             LARGE_INTEGER  streamAllocationSize;
174             unsigned char  fileName[512]; /* STRING */
175         } QPfileStreamInfo;
176         struct {
177             LARGE_INTEGER  compressedFileSize;
178             unsigned short compressionFormat;
179             unsigned char  compressionUnitShift;
180             unsigned char  chuckShift;
181             unsigned char  clusterShift;
182             unsigned char  reserved[3];
183         } QPfileCompressionInfo;
184     } u;
185 } smb_tran2QPathInfo_t;
186
187 typedef struct {
188     union {
189         struct {
190             FILETIME       creationTime;
191             FILETIME       lastAccessTime;
192             FILETIME       lastWriteTime;
193             FILETIME       lastChangeTime;
194             unsigned long  attributes;
195         } QFbasicInfo;
196         struct {
197             LARGE_INTEGER  allocationSize;
198             LARGE_INTEGER  endOfFile;
199             unsigned long  numberOfLinks;
200             unsigned char  deletePending;
201             unsigned char  directory;
202         } QFstandardInfo;
203         struct {
204             unsigned long  eaSize;
205         } QFeaInfo;
206         struct {        
207             unsigned long  fileNameLength;
208             unsigned char  fileName[512];
209         } QFfileNameInfo;
210     } u;
211 } smb_tran2QFileInfo_t;
212
213 typedef struct {
214     unsigned long  creationDateTime;    /* SMB_DATE / SMB_TIME */
215     unsigned long  lastAccessDateTime;  /* SMB_DATE / SMB_TIME */
216     unsigned long  lastWriteDateTime;   /* SMB_DATE / SMB_TIME */
217     unsigned long  dataSize;
218     unsigned long  allocationSize;
219     unsigned short attributes;
220 } smb_V3FileAttrsShort;
221
222 typedef struct {
223     FILETIME       creationTime;
224     FILETIME       lastAccessTime;
225     FILETIME       lastWriteTime;
226     FILETIME       lastChangeTime;
227     LARGE_INTEGER  endOfFile;
228     LARGE_INTEGER  allocationSize;
229     unsigned long  extFileAttributes;
230 } smb_V3FileAttrsLong;
231
232 typedef struct {
233     union {
234         struct {
235             smb_V3FileAttrsShort fileAttrs;
236             unsigned char  fileNameLength;
237             /* STRING fileName */
238         } FstandardInfo;
239
240         struct {
241             smb_V3FileAttrsShort fileAttrs;
242             unsigned long  eaSize;
243             unsigned char  fileNameLength;
244             /* STRING fileName */
245         } FeaSizeInfo, FeasFromListInfo;
246
247         struct {
248             unsigned long  nextEntryOffset;
249             unsigned long  fileIndex;
250             smb_V3FileAttrsLong fileAttrs;
251             unsigned long  fileNameLength;
252             /* STRING fileName */
253         } FfileDirectoryInfo;
254
255         struct {
256             unsigned long  nextEntryOffset;
257             unsigned long  fileIndex;
258             smb_V3FileAttrsLong fileAttrs;
259             unsigned long  fileNameLength;
260             unsigned long  eaSize;
261             /* STRING fileName */
262         } FfileFullDirectoryInfo;
263
264         struct {
265             unsigned long  nextEntryOffset;
266             unsigned long  fileIndex;
267             smb_V3FileAttrsLong fileAttrs;
268             unsigned long  fileNameLength;
269             unsigned long  eaSize;
270             unsigned char  shortNameLength;
271             unsigned char  reserved;
272             wchar_t        shortName[12];
273             /* STRING fileName */
274         } FfileBothDirectoryInfo;
275
276         struct {
277             unsigned long  nextEntryOffset;
278             unsigned long  fileIndex;
279             unsigned long  fileNameLength;
280             /* STRING fileName */
281         } FfileNamesInfo;
282     } u;
283 } smb_tran2Find_t;
284
285 #pragma pack(pop)
286
287 /* more than enough opcodes for today, anyway */
288 #define SMB_TRAN2_NOPCODES              20
289
290 extern smb_tran2Dispatch_t smb_tran2DispatchTable[SMB_TRAN2_NOPCODES];
291
292 #define SMB_RAP_NOPCODES        64
293
294 extern smb_tran2Dispatch_t smb_rapDispatchTable[SMB_RAP_NOPCODES];
295
296 extern long smb_ReceiveV3SessionSetupX(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp);
297
298 extern long smb_ReceiveV3TreeConnectX(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp);
299
300 extern long smb_ReceiveV3Trans(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp);
301
302 extern long smb_ReceiveV3Tran2A(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp);
303
304 extern long smb_ReceiveRAPNetShareEnum(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t *op);
305
306 extern long smb_ReceiveRAPNetShareGetInfo(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t *op);
307
308 extern long smb_ReceiveRAPNetWkstaGetInfo(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t *op);
309
310 extern long smb_ReceiveRAPNetServerGetInfo(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t *op);
311
312 extern long smb_ReceiveTran2Open(smb_vc_t *vcp, smb_tran2Packet_t *p,
313         smb_packet_t *outp);
314
315 extern long smb_ReceiveTran2FindFirst(smb_vc_t *vcp, smb_tran2Packet_t *p,
316         smb_packet_t *outp);
317
318 extern long smb_ReceiveTran2SearchDir(smb_vc_t *vcp, smb_tran2Packet_t *p,
319         smb_packet_t *outp);
320
321 extern long smb_ReceiveTran2FindNext(smb_vc_t *vcp, smb_tran2Packet_t *p,
322         smb_packet_t *outp);
323
324 extern long smb_ReceiveTran2QFSInfo(smb_vc_t *vcp, smb_tran2Packet_t *p,
325         smb_packet_t *outp);
326
327 extern long smb_ReceiveTran2SetFSInfo(smb_vc_t *vcp, smb_tran2Packet_t *p,
328         smb_packet_t *outp);
329
330 extern long smb_ReceiveTran2QFSInfoFid(smb_vc_t *vcp, smb_tran2Packet_t *p,
331         smb_packet_t *outp);
332
333 extern long smb_ReceiveTran2QPathInfo(smb_vc_t *vcp, smb_tran2Packet_t *p,
334         smb_packet_t *outp);
335
336 extern long smb_ReceiveTran2SetPathInfo(smb_vc_t *vcp, smb_tran2Packet_t *p,
337         smb_packet_t *outp);
338
339 extern long smb_ReceiveTran2QFileInfo(smb_vc_t *vcp, smb_tran2Packet_t *p,
340         smb_packet_t *outp);
341
342 extern long smb_ReceiveTran2SetFileInfo(smb_vc_t *vcp, smb_tran2Packet_t *p,
343         smb_packet_t *outp);
344
345 extern long smb_ReceiveTran2FSCTL(smb_vc_t *vcp, smb_tran2Packet_t *p,
346         smb_packet_t *outp);
347
348 extern long smb_ReceiveTran2IOCTL(smb_vc_t *vcp, smb_tran2Packet_t *p,
349         smb_packet_t *outp);
350
351 extern long smb_ReceiveTran2FindNotifyFirst(smb_vc_t *vcp, smb_tran2Packet_t *p,
352         smb_packet_t *outp);
353
354 extern long smb_ReceiveTran2FindNotifyNext(smb_vc_t *vcp, smb_tran2Packet_t *p,
355         smb_packet_t *outp);
356
357 extern long smb_ReceiveTran2CreateDirectory(smb_vc_t *vcp, smb_tran2Packet_t *p,
358         smb_packet_t *outp);
359
360 extern long smb_ReceiveTran2SessionSetup(smb_vc_t *vcp, smb_tran2Packet_t *p,
361         smb_packet_t *outp);
362
363 extern long smb_ReceiveTran2GetDFSReferral(smb_vc_t *vcp, smb_tran2Packet_t *p,
364         smb_packet_t *outp);
365
366 extern long smb_ReceiveTran2ReportDFSInconsistency(smb_vc_t *vcp, smb_tran2Packet_t *p,
367         smb_packet_t *outp);
368
369 extern long smb_ReceiveV3FindClose(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp);
370
371 extern long smb_ReceiveV3FindNotifyClose(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp);
372
373 extern long smb_ReceiveV3UserLogoffX(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp);
374
375 extern long smb_ReceiveV3OpenX(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp);
376
377 extern long smb_ReceiveV3LockingX(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp);
378
379 extern long smb_ReceiveV3GetAttributes(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp);
380
381 extern long smb_ReceiveV3ReadX(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp);
382
383 extern long smb_ReceiveV3WriteX(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp);
384
385 extern long smb_ReceiveV3SetAttributes(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp);
386
387 extern long smb_ReceiveNTCreateX(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp);
388
389 extern long smb_ReceiveNTTransact(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp);
390
391 extern void smb_NotifyChange(DWORD action, DWORD notifyFilter,
392         cm_scache_t *dscp, char *filename, char *otherFilename,
393         BOOL isDirectParent);
394
395 extern long smb_ReceiveNTCancel(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp);
396
397 extern long smb_ReceiveNTRename(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp);
398
399 extern int smb_V3MatchMask(char *namep, char *maskp, int flags);
400
401 extern void smb3_Init();
402 extern cm_user_t *smb_FindCMUserByName(char *usern, char *machine, afs_uint32 flags);
403
404 /* SMB auth related functions */
405 extern void smb_NegotiateExtendedSecurity(void ** secBlob, int * secBlobLength);
406
407 #ifdef DJGPP
408 #define DELETE (0x00010000)
409 #define READ_CONTROL (0x00020000)
410 #define SYNCHRONIZE (0x00100000)
411 #define FILE_WRITE_ATTRIBUTES ( 0x0100 )
412 #define FILE_GENERIC_READ (0x00120089)
413 #define FILE_GENERIC_WRITE (0x00120116)
414 #define FILE_GENERIC_EXECUTE (0x001200a0)
415 #endif /* DJGPP */
416
417 /* Some of the FILE_NOTIFY_CHANGE values are undefined in winnt.h */
418 #define FILE_NOTIFY_CHANGE_EA           0x00000080
419 #define FILE_NOTIFY_CHANGE_STREAM_NAME  0x00000200
420 #define FILE_NOTIFY_CHANGE_STREAM_SIZE  0x00000400
421 #define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800
422 #endif /*  __SMB3_H_ENV__ */