1/*
2 * Copyright (c) 2011 - 2012 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24#ifndef _NETSMB_SMB_2_H_
25#define _NETSMB_SMB_2_H_
26
27#include <stdint.h>
28#include <sys/types.h>
29
30/*
31 * SMB 2/3 Crediting constants
32 * kCREDIT_REQUEST_AMT - number of credits to request when client needs more
33 * kCREDIT_LOW_WATER - If client gets below this number of credits,
34 *                     1) Start using only 1 credit at a time instead of multi
35 *                     2) If multi credit leaves less than this amount, adjust
36 *                        length of the request to use less credits
37 *                     3) Optional Request more credits if change source code
38 * kCREDIT_MIN_AMT - If client gets to this number of credits, stop sending
39 *                   Be very careful in changing this value as there are times
40 *                   when we only have one credit granted to us.
41 * kCREDIT_MAX_AMT - maximum of credits that client will try to get.
42 *                   Currently as long as below this amount, keep asking for
43 *                   more credits until we get this amount.
44 */
45#define kCREDIT_REQUEST_AMT 256
46#define kCREDIT_LOW_WATER 10
47#define kCREDIT_MIN_AMT 1
48/* crediting fields are UInt32, but SMB 2/3 Header has UInt16 credit fields */
49#define kCREDIT_MAX_AMT UINT16_MAX
50
51/* smb2_durable_handle flags */
52typedef enum _SMB2_DURABLE_HANDLE_FLAGS
53{
54    SMB2_DURABLE_HANDLE_REQUEST = 0x0001,
55    SMB2_DURABLE_HANDLE_RECONNECT = 0x0002,
56    SMB2_DURABLE_HANDLE_GRANTED = 0x0004,
57    SMB2_LEASE_GRANTED = 0x0008
58} _SMB2_DURABLE_HANDLE_FLAGS;
59
60struct smb2_durable_handle {
61    uint64_t fid;               /* SMBFID to reconnect in durable handle reconnect */
62    uint64_t flags;
63    uint64_t lease_key_hi;      /* atomic increment number */
64    uint64_t lease_key_low;     /* node hash value */
65    uint32_t lease_state;
66    uint32_t pad;
67};
68
69/*
70 * Apple SMB 2/3 "AAPL" Create Context extensions
71 */
72
73/* Define "AAPL" Context Command Codes */
74enum {
75    kAAPL_SERVER_QUERY = 1,
76    kAAPL_RESOLVE_ID = 2
77};
78
79/*
80 * Server Query Request
81 *
82 *      uint32_t command_code = kAAPL_SERVER_QUERY;
83 *      uint32_t reserved = 0;
84 *      uint64_t request_bitmap;
85 *      uint64_t client_capabilities;
86 *
87 * Server Query Response
88 *
89 *      uint32_t command_code = kAAPL_SERVER_QUERY;
90 *      uint32_t reserved = 0;
91 *      uint64_t reply_bitmap;
92 *      <reply specific data>
93 *
94 *      The reply data is packed in the response block in the order specified
95 *      by the reply_bitmap.
96 *
97 * Server Query request/reply bitmap
98 *  Bit 0 - kAAPL_SERVER_CAPS returns uint64_t bitmap of server capabilities
99 *  Bit 1 - kAAPL_VOLUME_CAPS returns uint64_t bitmap of volume capabilities
100 *  Bit 2 - kAAPL_MODEL_INFO returns uint32_t Pad2 followed by uint32_t length
101 *      followed by the Unicode model string. The Unicode string is padded with
102 *      zeros to end on an 8 byte boundary.
103 *
104 * Example Server Query Context Response Buffer:
105 *      uint32_t Next = 0;
106 *      uint16_t NameOffset = 16;
107 *      uint16_t NameLength = 4;
108 *      uint16_t Reserved = 0;
109 *      uint16_t DataOffset = 24;
110 *      uint32_t DataLength = variable based on ModelString length;
111 *      uint32_t ContextName = "AAPL";
112 *      uint32_t Pad = 0;
113 *      uint32_t CommandCode = kAAPL_SERVER_QUERY
114 *      uint32_t Reserved = 0;
115 *      uint64_t ReplyBitmap = kAAPL_SERVER_CAPS | kAAPL_VOLUME_CAPS |
116 *                             kAAPL_MODEL_INFO;
117 *      uint64_t ServerCaps = kAAPL_SUPPORTS_READDIR_ATTR |
118 *                            kAAPL_SUPPORTS_OSX_COPYFILE;
119 *      uint64_t VolumeCaps = kAAPL_SUPPORT_RESOLVE_ID | kAAPL_CASE_SENSITIVE;
120 *      uint32_t Pad2 = 0;
121 *      uint32_t ModelStringLen = variable;
122 *      char *   ModelString;
123 *      char     PadBytes = variable to end on 8 byte boundary;
124 *
125 * kAAPL_SUPPORTS_NFS_ACE - Uses to set Posix permission when ACLs are off
126 *      on the server. The server must allow the client to get the current
127 *      ACL and then the client will return it with the desired Posix
128 *      permissions in the NFS ACE in the ACL.
129 */
130
131/* Define Server Query request/response bitmap */
132enum {
133    kAAPL_SERVER_CAPS = 0x01,
134    kAAPL_VOLUME_CAPS = 0x02,
135    kAAPL_MODEL_INFO = 0x04
136};
137
138/* Define Client/Server Capabilities bitmap */
139enum {
140    kAAPL_SUPPORTS_READ_DIR_ATTR = 0x01,
141    kAAPL_SUPPORTS_OSX_COPYFILE = 0x02,
142    kAAPL_UNIX_BASED = 0x04,
143    kAAPL_SUPPORTS_NFS_ACE = 0x08
144};
145
146/* Define Volume Capabilities bitmap */
147enum {
148    kAAPL_SUPPORT_RESOLVE_ID = 0x01,
149    kAAPL_CASE_SENSITIVE = 0x02
150};
151
152/*
153 * Resolve ID Request
154 *
155 *      uint32_t command_code = kAAPL_RESOLVE_ID;
156 *      uint32_t reserved = 0;
157 *      uint64_t file_id;
158 *
159 * Resolve ID Response
160 *
161 *      uint32_t command_code = kAAPL_RESOLVE_ID;
162 *      uint32_t reserved = 0;
163 *      uint32_t resolve_id_ntstatus;
164 *      uint32_t path_string_len = variable;
165 *      char *   path_string;
166 *
167 * Example Resolve ID Context Response Buffer:
168 *      uint32_t Next = 0;
169 *      uint16_t NameOffset = 16;
170 *      uint16_t NameLength = 4;
171 *      uint16_t Reserved = 0;
172 *      uint16_t DataOffset = 24;
173 *      uint32_t DataLength = variable based on PathString length;
174 *      uint32_t ContextName = "AAPL";
175 *      uint32_t Pad = 0;
176 *      uint32_t CommandCode = kAAPL_RESOLVE_ID;
177 *      uint32_t Reserved = 0;
178 *      uint32_t ResolveID_NTStatus = 0;
179 *      uint32_t ServerPathLen = variable;
180 *      char *   ServerPath;
181 *      char     PadBytes = variable to end on 8 byte boundary;
182 */
183
184/*
185 * ReadDirAttr Support
186 *
187 * Server has to support AAPL Create Context and support the
188 * command of kAAPL_SERVER_QUERY. In the ReplyBitMap, kAAPL_SERVER_CAPS
189 * has to be set and in the ServerCaps field, kAAPL_SUPPORTS_READ_DIR_ATTR
190 * must be set.
191 *
192 * Client uses FILE_ID_BOTH_DIR_INFORMATION for QueryDir
193 *
194 * In the Server reply for FILE_ID_BOTH_DIR_INFORMATION, fields are defined as:
195 *      uint32_t ea_size;
196 *      uint8_t short_name_len;
197 *      uint8_t reserved;
198 *      uint8_t short_name[24];
199 *      uint16_t reserved2;
200 *
201 * If kAAPL_SUPPORTS_READ_DIR_ATTR is set, the fields will be filled in as:
202 *      uint32_t max_access;
203 *      uint8_t short_name_len = 0;
204 *      uint8_t reserved = 0;
205 *      uint64_t rsrc_fork_len;
206 *      uint8_t compressed_finder_info[16];
207 *      uint16_t unix_mode;  (only if kAAPL_UNIX_BASED is set)
208 *
209 * Notes:
210 *      (1) ea_size is the max access if SMB_EFA_REPARSE_POINT is NOT set in
211 *      the file attributes. For a reparse point, the SMB Client will assume
212 *      full access.
213 *      (2) short_name is now the Resource Fork logical length and minimal
214 *      Finder Info.
215 *      (3) SMB Cient will calculate the resource fork allocation size based on
216 *      block size. This will be done in all places resource fork allocation
217 *      size is returned by the SMB Client so we return consistent answers.
218 *      (4) Compressed Finder Info will be only the fields actually still in
219 *      use in the regular Finder Info and in the Ext Finder Info. SMB client
220 *      will build a normal Finder Info and Ext Finder Info and fill in the
221 *      other fields in with zeros.
222 *      (5) If kAAPL_UNIX_BASED is set, then reserved2 is the entire Posix mode
223 *
224 *          struct smb_finder_file_info {
225 *              uint32_t finder_type;
226 *              uint32_t finder_creator;
227 *              uint16_t finder_flags;
228 *              uint16_t finder_ext_flags;
229 *              uint32_t finder_date_added;
230 *          }
231 *
232 *          struct smb_finder_folder_info {
233 *              uint64_t reserved1;
234 *              uint16_t finder_flags;
235 *              uint16_t finder_ext_flags;
236 *              uint32_t finder_date_added;
237 *          }
238 *
239 *
240 * Normal Finder Info and Extended Finder Info definitions
241 *          struct finder_file_info {
242 *              uint32_t finder_type;
243 *              uint32_t finder_creator;
244 *              uint16_t finder_flags;
245 *              uint32_t finder_old_location = 0;
246 *              uint16_t reserved = 0;
247 *
248 *              uint32_t reserved2 = 0;
249 *              uint32_t finder_date_added;
250 *              uint16_t finder_ext_flags;
251 *              uint16_t reserved3 = 0;
252 *              uint32_t reserved4 = 0;
253 *          }
254 *
255 *          struct finder_folder_info {
256 *              uint64_t reserved1;
257 *              uint16_t finder_flags;
258 *              uint32_t finder_old_location = 0;
259 *              uint16_t finder_old_view_flags = 0;
260 *
261 *              uint32_t finder_old_scroll_position = 0;
262 *              uint32_t finder_date_added;
263 *              uint16_t finder_ext_flags;
264 *              uint16_t reserved3 = 0;
265 *              uint32_t reserved4 = 0;
266 *          }
267 */
268
269struct smb_finder_file_info {
270    uint32_t finder_type;
271    uint32_t finder_creator;
272    uint16_t finder_flags;
273    uint32_t finder_date_added;
274    uint16_t finder_ext_flags;
275};
276
277struct smb_finder_folder_info {
278    uint64_t reserved1;
279    uint16_t finder_flags;
280    uint32_t finder_date_added;
281    uint16_t finder_ext_flags;
282};
283
284struct smb_finder_info {
285    union {
286        struct smb_finder_file_info file_info;
287        struct smb_finder_folder_info folder_info;
288    } u2;
289};
290
291struct finder_file_info {
292    uint32_t finder_type;
293    uint32_t finder_creator;
294    uint16_t finder_flags;
295    uint32_t finder_old_location;   /* always set to 0 */
296    uint16_t reserved;              /* always set to 0 */
297    /* End of Finder Info and start of Ext Finder Info */
298    uint32_t reserved2;             /* always set to 0 */
299    uint32_t finder_date_added;
300    uint16_t finder_ext_flags;
301    uint16_t reserved3;             /* always set to 0 */
302    uint32_t reserved4;             /* always set to 0 */
303};
304
305struct finder_folder_info {
306    uint64_t reserved1;
307    uint16_t finder_flags;
308    uint32_t finder_old_location;   /* always set to 0 */
309    uint16_t finder_old_view_flags; /* always set to 0 */
310    /* End of Finder Info and start of Ext Finder Info */
311    uint32_t finder_old_scroll_position; /* always set to 0 */
312    uint32_t finder_date_added;
313    uint16_t finder_ext_flags;
314    uint16_t reserved3;             /* always set to 0 */
315    uint32_t reserved4;             /* always set to 0 */
316};
317
318struct finder_info {
319    union {
320        struct finder_file_info file_info;
321        struct finder_folder_info folder_info;
322    } u2;
323};
324
325
326/* SMB 2/3 Commands, 2.2.1 */
327#define SMB2_NEGOTIATE		0x0000
328#define SMB2_SESSION_SETUP	0x0001
329#define SMB2_LOGOFF		0x0002
330#define SMB2_TREE_CONNECT	0x0003
331#define SMB2_TREE_DISCONNECT	0x0004
332#define SMB2_CREATE		0x0005
333#define SMB2_CLOSE		0x0006
334#define SMB2_FLUSH		0x0007
335#define SMB2_READ		0x0008
336#define SMB2_WRITE		0x0009
337#define SMB2_LOCK		0x000A
338#define SMB2_IOCTL		0x000B
339#define SMB2_CANCEL		0x000C
340#define SMB2_ECHO		0x000D
341#define SMB2_QUERY_DIRECTORY	0x000E
342#define SMB2_CHANGE_NOTIFY	0x000F
343#define SMB2_QUERY_INFO		0x0010
344#define SMB2_SET_INFO		0x0011
345#define SMB2_OPLOCK_BREAK	0x0012
346
347/* SMB 2/3 Write Request Header Length, 2.2.21 */
348#define SMB2_WRITE_REQ_HDRLEN       48
349
350/* SMB 2/3 Dialects, 2.2.3 */
351#define SMB2_DIALECT_0202   0x0202
352#define SMB2_DIALECT_02ff   0x02ff
353#define SMB2_DIALECT_0210   0x0210
354#define SMB2_DIALECT_0300   0x0300
355#define SMB2_DIALECT_0302   0x0302
356
357#define	SMB2_TID_UNKNOWN	0xffffffff
358
359/* Bitmask to define the valid SMB command range. */
360#define SMB2_VALID_COMMAND_MASK 0x001F
361
362/* SMB 2/3 Flags, 2.2.1 */
363#define SMB2_FLAGS_SERVER_TO_REDIR      0x00000001
364#define SMB2_FLAGS_ASYNC_COMMAND        0x00000002
365#define SMB2_FLAGS_RELATED_OPERATIONS   0x00000004
366#define SMB2_FLAGS_SIGNED               0x00000008
367#define SMB2_FLAGS_DFS_OPERATIONS       0x10000000
368
369/* Bitmask to define the valid SMB flags set. */
370#define SMB2_VALID_FLAGS_MASK 0x1000000F
371
372/* SMB 2/3 Security Mode, 2.2.3 */
373#define SMB2_NEGOTIATE_SIGNING_ENABLED	0x0001
374#define SMB2_NEGOTIATE_SIGNING_REQUIRED	0x0002
375
376/* SMB 2/3 Negotiate Capabilities, 2.2.3 */
377#define SMB2_GLOBAL_CAP_DFS                 0x00000001
378#define SMB2_GLOBAL_CAP_LEASING             0x00000002
379#define SMB2_GLOBAL_CAP_LARGE_MTU           0x00000004
380#define SMB2_GLOBAL_CAP_MULTI_CHANNEL       0x00000008
381#define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES	0x00000010
382#define SMB2_GLOBAL_CAP_DIRECTORY_LEASING	0x00000020
383#define SMB2_GLOBAL_CAP_ENCRYPTION          0x00000040
384
385/* SMB 2/3 SessionFlags, 2.2.6 */
386#define SMB2_SESSION_FLAG_IS_GUEST      0x0001
387#define SMB2_SESSION_FLAG_IS_NULL       0x0002
388#define SMB2_SESSION_FLAG_ENCRYPT_DATA  0x0004  /* Encryption Required */
389
390/* SMB 2/3 ShareType, 2.2.10 */
391#define SMB2_SHARE_TYPE_DISK	0x01
392#define SMB2_SHARE_TYPE_PIPE	0x02
393#define SMB2_SHARE_TYPE_PRINT	0x03
394
395/* SMB 2/3 ShareFlags, 2.2.10 */
396#define SMB2_SHAREFLAG_DFS              0x00000001
397#define SMB2_SHAREFLAG_DFS_ROOT         0x00000002
398#define SMB2_SHAREFLAG_ENCRYPT_DATA     0x00008000 /* Encryption Required */
399
400/* SMB 2/3 ShareCapabilities, 2.2.10 */
401#define SMB2_SHARE_CAP_DFS                      0x00000008
402#define SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY  0x00000010
403
404/* SMB 2/3 RequestedOplockLevel, 2.2.13 */
405#define SMB2_OPLOCK_LEVEL_NONE	    0x00
406#define SMB2_OPLOCK_LEVEL_II	    0x01
407#define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08
408#define SMB2_OPLOCK_LEVEL_BATCH	    0x09
409#define SMB2_OPLOCK_LEVEL_LEASE	    0xff
410
411/* SMB 2/3 Lease Break Notification Flags, 2.2.23.2 */
412#define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED   0x01
413
414/* SMB 2/3 RequestedLeaseLevel, 2.2.13 */
415#define SMB2_LEASE_NONE             0x00
416#define SMB2_LEASE_READ_CACHING	    0x01
417#define SMB2_LEASE_HANDLE_CACHING   0x02
418#define SMB2_LEASE_WRITE_CACHING	0x04
419
420/* SMB 2/3 ImpersonationLevel, 2.2.13 */
421#define SMB2_IMPERSONATION_ANONYMOUS	    0x00000000
422#define SMB2_IMPERSONATION_IDENTIFICATION   0x00000001
423#define SMB2_IMPERSONATION_IMPERSONATION    0x00000002
424#define SMB2_IMPERSONATION_DELEGATE	    0x00000003
425
426#define SMB2_WRITEFLAG_WRITE_THROUGH	0x00000001
427
428
429/*
430 * Access mask encoding:
431 *
432 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
433 * | | | | | | | | | | |1| | | | | | | | | |2| | | | | | | | | |3| |
434 * |0|1|2|3|4|5|6|7|8|9|0|1|2|3|4|5|6|7|8|9|0|1|2|3|4|5|6|7|8|9|0|1|
435 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
436 * |R|W|E|A|   |M|S|  standard     |  specific                     |
437 * +-------+-------+---------------+-------------------------------+
438 *
439 * R => generic read
440 * W => generic write
441 * E => generic execute
442 * A => generic all
443 * S => SACL access (ACCESS_SYSTEM_SECURITY)
444 * M => maximal access
445 */
446
447#define SMB2_GENERIC_ALL		0x10000000
448#define SMB2_GENERIC_EXECUTE		0x20000000
449#define SMB2_GENERIC_WRITE		0x40000000
450#define SMB2_GENERIC_READ		0x80000000
451
452/* #define SMB2_FILE_LIST_DIRECTORY	0x00000001 */   /* defined in smb.h */
453/* #define SMB2_FILE_ADD_FILE		0x00000002 */   /* defined in smb.h */
454/* #define SMB2_FILE_ADD_SUBDIRECTORY	0x00000004 */ /* defined in smb.h */
455#define SMB2_FILE_READ_EA		0x00000008
456#define SMB2_FILE_WRITE_EA		0x00000010
457/* #define SMB2_FILE_TRAVERSE		0x00000020 */   /* defined in smb.h */
458#define SMB2_FILE_DELETE_CHILD		0x00000040
459#define SMB2_FILE_READ_ATTRIBUTES	0x00000080
460#define SMB2_FILE_WRITE_ATTRIBUTES	0x00000100
461
462#define SMB2_STD_ACCESS_DELETE		0x00010000
463#define SMB2_STD_ACCESS_READ_CONTROL	0x00020000
464#define SMB2_STD_ACCESS_WRITE_DAC	0x00040000
465#define SMB2_STD_ACCESS_WRITE_OWNER	0x00080000
466#define SMB2_STD_ACCESS_SYNCHRONIZE	0x00100000
467#define SMB2_STD_ACCESS_SYSTEM_SECURITY	0x01000000
468#define SMB2_STD_ACCESS_MAXIMAL		0x02000000
469#define SMB2_STD_RESERVED_1		0x04000000
470#define SMB2_STD_RESERVED_2		0x08000000
471
472/* SMB 2/3 CREATE_CONTEXT names, 2.2.13.2 */
473#define SMB2_CREATE_EA_BUFFER                   0x45787441 /* "ExtA" */
474#define SMB2_CREATE_SD_BUFFER                   0x53656344 /* "SecD" */
475#define SMB2_CREATE_DURABLE_HANDLE_REQUEST      0x44486e51 /* "DHnQ" */
476#define SMB2_CREATE_DURABLE_HANDLE_RECONNECT    0x44486e43 /* "DHnC" */
477#define SMB2_CREATE_ALLOCATION_SIZE             0x416c5369 /* "AISi" */
478#define SMB2_CREATE_QUERY_MAXIMAL_ACCESS        0x4d784163 /* "MxAc" */
479#define SMB2_CREATE_TIMEWARP_TOKEN              0x54577270 /* "Twrp" */
480#define SMB2_CREATE_QUERY_ON_DISK_ID            0x51466964 /* "QFid" */
481#define SMB2_CREATE_REQUEST_LEASE               0x52714c73 /* "RqLs" */
482
483/* Apple Defined Contexts */
484#define	SMB2_CREATE_AAPL                        0x4141504c
485
486
487/* SMB 2/3 CloseFlags, 2.2.15 */
488#define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB    0x0001
489
490/* SMB 2/3 Lockflags, 2.2.26.1 */
491#define SMB2_LOCKFLAG_SHARED_LOCK	0x00000001
492#define SMB2_LOCKFLAG_EXCLUSIVE_LOCK	0x00000002
493#define SMB2_LOCKFLAG_UNLOCK		0x00000004
494#define SMB2_LOCKFLAG_FAIL_IMMEDIATELY	0x00000010
495
496/* SMB 2/3 IoctlFlags, 2.2.31 */
497#define SMB2_IOCTL_IS_FSCTL		0x00000001
498
499/* SMB 2/3 QUERY_DIRECTORY Flags, 2.2.33 */
500#define SMB2_RESTART_SCANS		0x01
501#define SMB2_RETURN_SINGLE_ENTRY	0x02
502#define SMB2_INDEX_SPECIFIED		0x04
503#define SMB2_REOPEN			0x10
504
505/* SMB 2/3 CHANGE_NOTIFY Flags, 2.2.35 */
506#define SMB2_WATCH_TREE			0x0001
507
508/* SMB 2/3 QUERY_INFO InfoType, 2.2.37 */
509#define SMB2_0_INFO_FILE	0x01
510#define SMB2_0_INFO_FILESYSTEM	0x02
511#define SMB2_0_INFO_SECURITY	0x03
512#define SMB2_0_INFO_QUOTA	0x04
513
514/* MS-FSCC 2.5 FileSystem Information Classes.
515 * Also see MSDN for ZwQueryVolumeInformationFile.
516 */
517typedef enum _FS_INFORMATION_CLASS
518{
519    FileFsVolumeInformation     = 1, /* Query */
520    FileFsLabelInformation      = 2, /* Set */
521    FileFsSizeInformation       = 3, /* Query */
522    FileFsDeviceInformation     = 4, /* Query */
523    FileFsAttributeInformation  = 5, /* Query */
524    FileFsControlInformation    = 6, /* Query, Set */
525    FileFsFullSizeInformation   = 7, /* Query */
526    FileFsObjectIdInformation   = 8, /* Query, Set */
527    FileFsDriverPathInformation = 9 /* Query */
528} FS_INFORMATION_CLASS;
529
530/* MS-FSCC 2.4 File Information Classes */
531typedef enum _FILE_INFORMATION_CLASS
532{
533    FileDirectoryInformation        = 1,
534    FileFullDirectoryInformation    = 2,
535    FileBothDirectoryInformation    = 3,
536    FileBasicInformation            = 4,
537    FileStandardInformation         = 5,
538    FileInternalInformation         = 6,
539    FileEaInformation               = 7,
540    FileAccessInformation           = 8,
541    FileNameInformation             = 9,
542    FileRenameInformation           = 10,
543    FileLinkInformation             = 11,
544    FileNamesInformation            = 12,
545    FileDispositionInformation      = 13,
546    FilePositionInformation         = 14,
547    FileFullEaInformation           = 15,
548    FileModeInformation             = 16,
549    FileAlignmentInformation        = 17,
550    FileAllInformation              = 18,
551    FileAllocationInformation       = 19,
552    FileEndOfFileInformation        = 20,
553    FileAlternateNameInformation    = 21,
554    FileStreamInformation           = 22,
555    FilePipeInformation             = 23,
556    FilePipeLocalInformation        = 24,
557    FilePipeRemoteInformation       = 25,
558    FileMailslotQueryInformation    = 26,
559    FileMailslotSetInformation      = 27,
560    FileCompressionInformation      = 28,
561    FileObjectIdInformation         = 29,
562    FileMoveClusterInformation      = 31,
563    FileQuotaInformation            = 32,
564    FileReparsePointInformation     = 33,
565    FileNetworkOpenInformation      = 34,
566    FileAttributeTagInformation     = 35,
567    FileTrackingInformation         = 36,
568    FileIdBothDirectoryInformation  = 37,
569    FileIdFullDirectoryInformation  = 38,
570    FileValidDataLengthInformation  = 39,
571    FileShortNameInformation        = 40,
572    FileSfioReserveInformation      = 44,
573    FileSfioVolumeInformation       = 45,
574    FileHardLinkInformation         = 46,
575    FileNormalizedNameInformation   = 48,
576    FileIdGlobalTxDirectoryInformation = 50,
577    FileStandardLinkInformation     = 54
578} FILE_INFORMATION_CLASS;
579
580#if !defined(_SMBFID)
581#define _SMBFID
582typedef uint64_t SMBFID;
583#endif
584
585#if !defined(_SMB2FID)
586#define _SMB2FID
587typedef struct _SMB2FID
588{
589    uint64_t fid_persistent;
590    uint64_t fid_volatile;
591} SMB2FID;
592#endif
593
594/*
595 * BasicInfo 40 bytes, StdInfo 24 bytes, InternalInfo 8 bytes,
596 * EaInfo 4 bytes, AccessInfo 4 bytes, PosInfo 8 bytes, ModeInfo 4 bytes,
597 * AlignInfo 4 bytes, Name Info 4 bytes + name length (PATH_MAX)
598 * which adds up to be 100 + PATH_MAX
599 */
600#define SMB2_FILE_ALL_INFO_LEN (100 + PATH_MAX)
601
602struct FILE_ALL_INFORMATION
603{
604    struct smb_share *share;
605    struct smbnode *np;
606    struct smbfattr *fap;
607    const char **namep;
608    size_t *name_lenp;
609};
610
611struct FILE_FS_ATTRIBUTE_INFORMATION
612{
613    uint32_t file_system_attrs;
614    uint32_t max_component_name_len;
615    uint32_t file_system_name_len;
616    uint32_t pad;
617    char *file_system_namep;
618};
619
620struct FILE_FS_SIZE_INFORMATION
621{
622    uint64_t total_alloc_units;
623    uint64_t avail_alloc_units;
624    uint32_t sectors_per_alloc_unit;
625    uint32_t bytes_per_sector;
626};
627
628/* FILE_STREAM_INFORMATION flags */
629typedef enum _FILE_STREAM_INFO_FLAGS
630{
631    SMB_NO_RESOURCE_FORK = 0x0001,
632    SMB_NO_FINDER_INFO = 0x0002,
633    SMB_NO_TRANSLATE_NAMES = 0x0010,  /* input flag-  Don't translate stream names to xattr names */
634    SMB_NO_SUBSTREAMS = 0x0020
635} _FILE_STREAM_INFO_FLAGS;
636
637struct FILE_STREAM_INFORMATION
638{
639    struct smb_share *share;
640    struct smbnode *np;
641    const char *namep;
642    size_t name_len;
643    void *uio;
644    size_t *stream_buf_sizep;
645    const char *stream_namep;
646    uint64_t *stream_sizep;
647    uint64_t *stream_alloc_sizep;
648    uint32_t *stream_flagsp;
649};
650
651/* SMB3 Encryption defines */
652
653/* Authenticated Data */
654#define SMB3_AES_AUTHDATA_OFF       20
655#define SMB3_AES_AUTHDATA_LEN       32
656#define SMB3_CCM_NONCE_LEN          11
657
658/* Transform Header (TF) */
659#define SMB3_AES_TF_HDR_LEN         52
660
661#define SMB2_ENCRYPTION_AES128_CCM  0x0001
662
663#define SMB3_AES_TF_PROTO_OFF   0
664#define	SMB3_AES_TF_PROTO_STR   "\xFDSMB"
665#define	SMB3_AES_TF_PROTO_LEN   4
666
667#define SMB3_AES_TF_SIG_OFF     4
668#define SMB3_AES_TF_SIG_LEN     16
669
670#define SMB3_AES_TF_NONCE_OFF   20
671#define SMB3_AES_TF_NONCE_LEN   16
672
673#define SMB3_AES_TF_MSGLEN_OFF  36
674#define SMB3_AES_TF_MSGLEN_LEN  4
675
676#define SMB3_AES_TF_ENCR_ALG_OFF    42
677#define SMB3_AES_TF_ENCR_ALG_LEN    2
678
679#define SMB3_AES_TF_SESSID_OFF      44
680#define SMB3_AES_TF_SESSID_LEN      8
681
682/* SMB 3 Transform Header */
683
684struct smb3_aes_transform_hdr
685{
686    uint32_t        proto;
687    unsigned char   signature[SMB3_AES_TF_SIG_LEN];
688    unsigned char   nonce[SMB3_AES_TF_NONCE_LEN];
689    uint32_t        orig_msg_size;
690    uint16_t        reserved;
691    uint16_t        encrypt_algorithm;
692    uint64_t        sess_id;
693} __attribute__((__packed__));
694
695typedef struct smb3_aes_transform_hdr SMB3_AES_TF_HEADER;
696
697#endif /* SMB_SMB2_H */
698