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