xref: /illumos-gate/usr/src/uts/common/netsmb/smb2.h (revision 63f91fbc3c024870d86dc3332a4a0080fb29bc40)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
14  */
15 
16 #ifndef _NETSMB_SMB2_H
17 #define	_NETSMB_SMB2_H
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 #define	SMB2_PROTOCOL_ID	{ 0xFE, 'S', 'M', 'B' }
24 #define	SMB2_HDR_SIZE	64
25 #define	SMB2_HDRLEN	SMB2_HDR_SIZE
26 
27 /*
28  * SMB2 header command codes.
29  * These are uint16_t on the wire.
30  */
31 typedef enum {
32 	SMB2_NEGOTIATE = 0,
33 	SMB2_SESSION_SETUP,
34 	SMB2_LOGOFF,
35 	SMB2_TREE_CONNECT,
36 	SMB2_TREE_DISCONNECT,
37 	SMB2_CREATE,
38 	SMB2_CLOSE,
39 	SMB2_FLUSH,
40 	SMB2_READ,
41 	SMB2_WRITE,
42 	SMB2_LOCK,
43 	SMB2_IOCTL,
44 	SMB2_CANCEL,
45 	SMB2_ECHO,
46 	SMB2_QUERY_DIRECTORY,
47 	SMB2_CHANGE_NOTIFY,
48 	SMB2_QUERY_INFO,
49 	SMB2_SET_INFO,
50 	SMB2_OPLOCK_BREAK,
51 	/*
52 	 * The above (oplock break) is the last real SMB2 op-code.
53 	 * We use one more slot to represent invalid commands, and
54 	 * the final enum value is used for array sizes. Keep last!
55 	 */
56 	SMB2_INVALID_CMD,
57 	SMB2__NCMDS
58 } SMB2_cmd_code;
59 
60 /*
61  * SMB2 header flags.
62  */
63 
64 /*
65  * SERVER_TO_REDIR
66  * When set, indicates the message is a response rather than
67  * a request. This MUST be set on responses sent from the
68  * server to the client, and MUST NOT be set on requests
69  * sent from the client to the server.
70  */
71 #define	SMB2_FLAGS_SERVER_TO_REDIR	0x00000001
72 
73 /*
74  * ASYNC_COMMAND
75  * When set, indicates that this is an ASYNC SMB2 header.
76  * Always set for headers of the form described in this
77  * section.
78  */
79 #define	SMB2_FLAGS_ASYNC_COMMAND	0x00000002
80 
81 /*
82  * RELATED_OPERATIONS
83  * When set in an SMB2 request, indicates that this request
84  * is a related operation in a compounded request chain.
85  * [MS-SMB2 sec. 3.2.4.1.4]
86  *
87  * When set in an SMB2 compound response, indicates that
88  * the request corresponding to this response was part of a
89  * related operation in a compounded request chain.
90  * [MS-SMB2 sec. 3.3.5.2.7.2]
91  */
92 #define	SMB2_FLAGS_RELATED_OPERATIONS	0x00000004
93 
94 /*
95  * SIGNED
96  * When set, indicates that this packet has been signed.
97  * [MS-SMB2 3.1.5.1]
98  */
99 #define	SMB2_FLAGS_SIGNED	0x00000008
100 
101 /*
102  * [MS-SMB2] 3.2.5.3.1 The SessionKey MUST be set to the
103  * first 16 bytes of the cryptographic key from GSSAPI.
104  * (Padded with zeros if the GSSAPI key is shorter.)
105  */
106 #define	SMB2_SESSION_KEY_LEN	16
107 
108 /*
109  * DFS_OPERATIONS
110  * When set, indicates that this command is a Distributed
111  * File System (DFS) operation.  [MS-SMB2 3.3.5.9]
112  */
113 #define	SMB2_FLAGS_DFS_OPERATIONS	0x10000000
114 
115 /*
116  * REPLAY_OPERATION
117  * This flag is only valid for the SMB 3.0 dialect. When set,
118  * it indicates that this command is a replay operation.
119  * The client MUST ignore this bit on receipt.
120  */
121 #define	SMB2_FLAGS_REPLAY_OPERATION	0x20000000
122 
123 /*
124  * SMB2 Netgotiate [MS-SMB2 2.2.3]
125  */
126 
127 #define	SMB2_NEGOTIATE_SIGNING_ENABLED	0x01
128 #define	SMB2_NEGOTIATE_SIGNING_REQUIRED	0x02
129 
130 #define	SMB2_CAP_DFS			0x00000001
131 
132 /* Added with SMB2.1 */
133 #define	SMB2_CAP_DFS			0x00000001
134 #define	SMB2_CAP_LEASING		0x00000002
135 /*
136  * LARGE_MTU:
137  * When set, indicates that the client supports multi-credit operations.
138  */
139 #define	SMB2_CAP_LARGE_MTU		0x00000004
140 
141 /* Added with SMB3.0 */
142 #define	SMB2_CAP_MULTI_CHANNEL		0x00000008
143 #define	SMB2_CAP_PERSISTENT_HANDLES	0x00000010
144 #define	SMB2_CAP_DIRECTORY_LEASING	0x00000020
145 #define	SMB2_CAP_ENCRYPTION		0x00000040
146 
147 /* SMB2 session flags */
148 #define	SMB2_SESSION_FLAG_IS_GUEST	0x0001
149 #define	SMB2_SESSION_FLAG_IS_NULL	0x0002
150 #define	SMB2_SESSION_FLAG_ENCRYPT_DATA	0x0004
151 
152 /*
153  * SMB2 Tree connect, disconnect
154  */
155 
156 /* SMB2 sharetype flags */
157 #define	SMB2_SHARE_TYPE_DISK		0x1
158 #define	SMB2_SHARE_TYPE_PIPE		0x2
159 #define	SMB2_SHARE_TYPE_PRINT		0x3
160 
161 /* SMB2 share flags */
162 #define	SMB2_SHAREFLAG_MANUAL_CACHING			0x00000000
163 #define	SMB2_SHAREFLAG_AUTO_CACHING			0x00000010
164 #define	SMB2_SHAREFLAG_VDO_CACHING			0x00000020
165 #define	SMB2_SHAREFLAG_NO_CACHING			0x00000030
166 #define	SMB2_SHAREFLAG_DFS				0x00000001
167 #define	SMB2_SHAREFLAG_DFS_ROOT				0x00000002
168 #define	SMB2_SHAREFLAG_RESTRICT_EXCLUSIVE_OPENS		0x00000100
169 #define	SMB2_SHAREFLAG_FORCE_SHARED_DELETE		0x00000200
170 #define	SMB2_SHAREFLAG_ALLOW_NAMESPACE_CACHING		0x00000400
171 #define	SMB2_SHAREFLAG_ACCESS_BASED_DIRECTORY_ENUM	0x00000800
172 #define	SMB2_SHAREFLAG_FORCE_LEVELII_OPLOCK		0x00001000
173 /* SMB 3.0 */
174 #define	SMB2_SHAREFLAG_ENABLE_HASH_V1			0x00002000
175 #define	SMB2_SHAREFLAG_ENABLE_HASH_V2			0x00004000
176 #define	SMB2_SHAREFLAG_ENCRYPT_DATA			0x00008000
177 
178 /* SMB2 share capabilities */
179 #define	SMB2_SHARE_CAP_DFS				0x00000008
180 /* SMB 3.0 */
181 #define	SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY		0x00000010
182 #define	SMB2_SHARE_CAP_SCALEOUT				0x00000020
183 #define	SMB2_SHARE_CAP_CLUSTER				0x00000040
184 
185 /*
186  * SMB2 Create (open)
187  */
188 
189 /* SMB2 requested oplock levels */
190 #define	SMB2_OPLOCK_LEVEL_NONE				0x00
191 #define	SMB2_OPLOCK_LEVEL_II				0x01
192 #define	SMB2_OPLOCK_LEVEL_EXCLUSIVE			0x08
193 #define	SMB2_OPLOCK_LEVEL_BATCH				0x09
194 #define	SMB2_OPLOCK_LEVEL_LEASE				0xFF
195 
196 /* SMB2 impersonation levels */
197 #define	SMB2_IMPERSONATION_ANONYMOUS			0x00
198 #define	SMB2_IMPERSONATION_IDENTIFICATION		0x01
199 #define	SMB2_IMPERSONATION_IMPERSONATION		0x02
200 #define	SMB2_IMPERSONATION_DELEGATE			0x03
201 
202 /*
203  * Note: ShareAccess, CreateDispositon, CreateOptions,
204  * all use the same definitions as SMB1 (from MS-FSA).
205  * Ditto FileAccess flags (as with ACLs)
206  */
207 
208 /* SMB2 Create Context tags */
209 
210 #define	SMB2_CREATE_EA_BUFFER			0x45787441 /* ("ExtA") */
211 /*
212  * The data contains the extended attributes
213  * that MUST be stored on the created file.
214  * This value MUST NOT be set for named
215  * pipes and print files.
216  */
217 
218 #define	SMB2_CREATE_SD_BUFFER			0x53656344 /* ("SecD") */
219 /*
220  * The data contains a security descriptor that
221  * MUST be stored on the created file.
222  * This value MUST NOT be set for named
223  * pipes and print files.
224  */
225 
226 #define	SMB2_CREATE_DURABLE_HANDLE_REQUEST	0x44486e51 /* ("DHnQ") */
227 /* The client is requesting the open to be durable */
228 
229 #define	SMB2_CREATE_DURABLE_HANDLE_RECONNECT	0x44486e43 /* ("DHnC") */
230 /*
231  * The client is requesting to reconnect to a
232  * durable open after being disconnected
233  */
234 
235 #define	SMB2_CREATE_ALLOCATION_SIZE		0x416c5369 /* ("AISi") */
236 /*
237  * The data contains the required allocation
238  * size of the newly created file.
239  */
240 
241 #define	SMB2_CREATE_QUERY_MAXIMAL_ACCESS	0x4d784163 /* ("MxAc") */
242 /*
243  * The client is requesting that the server
244  * return maximal access information.
245  */
246 
247 #define	SMB2_CREATE_TIMEWARP_TOKEN		0x54577270 /* ("TWrp") */
248 /*
249  * The client is requesting that the server
250  * open an earlier version of the file identified
251  * by the provided time stamp.
252  */
253 
254 #define	SMB2_CREATE_QUERY_ON_DISK_ID		0x51466964 /* ("QFid") */
255 /*
256  * The client is requesting that the server return a 32-byte
257  * opaque BLOB that uniquely identifies the file being opened
258  * on disk. No data is passed to the server by the client.
259  */
260 
261 #define	SMB2_CREATE_REQUEST_LEASE		0x52714c73 /* ("RqLs") */
262 /*
263  * The client is requesting that the server return a lease.
264  * This value is only supported for the SMB 2.1 and 3.0 dialects.
265  */
266 
267 /* SMB2 create request lease */
268 #define	SMB2_LEASE_NONE				0x00
269 #define	SMB2_LEASE_READ_CACHING			0x01
270 #define	SMB2_LEASE_HANDLE_CACHING		0x02
271 #define	SMB2_LEASE_WRITE_CACHING		0x04
272 
273 /* SMB2 lease break notification flags */
274 #define	SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED  0x01
275 
276 /*
277  * SMB2 Close
278  */
279 #define	SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB	0x0001
280 
281 /*
282  * SMB2 Write
283  */
284 #define	SMB2_WRITEFLAG_WRITE_THROUGH		0x00000001
285 
286 /*
287  * SMB2 Lock Request
288  */
289 
290 /* SMB2 lock flags */
291 
292 /*
293  * SMB2_LOCKFLAG_SHARED_LOCK
294  * The range MUST be locked shared, allowing other opens
295  * to read from or take a shared lock on the range. All opens
296  * MUST NOT be allowed to write within the range. Other
297  * locks can be requested and taken on this range.
298  */
299 #define	SMB2_LOCKFLAG_SHARED_LOCK	0x00000001
300 
301 /*
302  * SMB2_LOCKFLAG_EXCLUSIVE_LOCK
303  * The range MUST be locked exclusive, not allowing other
304  * opens to read, write, or lock within the range.
305  */
306 #define	SMB2_LOCKFLAG_EXCLUSIVE_LOCK	0x00000002
307 
308 /*
309  * SMB2_LOCKFLAG_UNLOCK
310  * The range MUST be unlocked from a previous lock taken
311  * on this range. The unlock range MUST be identical to the
312  * lock range. Sub-ranges cannot be unlocked.
313  */
314 #define	SMB2_LOCKFLAG_UNLOCK		0x00000004
315 
316 /*
317  * SMB2_LOCKFLAG_FAIL_IMMEDIATELY
318  * The lock operation MUST fail immediately if it conflicts
319  * with an existing lock, instead of waiting for the range to
320  * become available.  This can be OR'ed with either of
321  * shared_lock, exclusive_lock (nothing else).
322  */
323 #define	SMB2_LOCKFLAG_FAIL_IMMEDIATELY	0x00000010
324 
325 /*
326  * SMB2 Ioctl Request
327  */
328 #define	SMB2_IOCTL_IS_FSCTL		0x00000001
329 
330 
331 /*
332  * SMB2 Query Directory
333  */
334 
335 /*
336  * SMB2 query directory info levels
337  * Same as SMB1 (see ntifs.h)
338  */
339 
340 /*
341  * SMB2 Query Directory Flags
342  * (our own names for these - spec. used poor names)
343  */
344 #define	SMB2_QDIR_FLAG_RESTART		0x01 /* SMB2_RESTART_SCANS */
345 #define	SMB2_QDIR_FLAG_SINGLE		0x02 /* SMB2_RETURN_SINGLE_ENTRY */
346 #define	SMB2_QDIR_FLAG_INDEX		0x04 /* SMB2_INDEX_SPECIFIED */
347 #define	SMB2_QDIR_FLAG_REOPEN		0x10 /* SMB2_REOPEN */
348 
349 /*
350  * SMB2 Query Info Request
351  */
352 
353 /* info type */
354 #define	SMB2_0_INFO_FILE		0x01
355 /* The file information is requested. */
356 #define	SMB2_0_INFO_FILESYSTEM		0x02
357 /* The underlying object store information is requested. */
358 #define	SMB2_0_INFO_SECURITY		0x03
359 /* The security information is requested. */
360 #define	SMB2_0_INFO_QUOTA		0x04
361 /* The underlying object store quota information is requested. */
362 
363 /*
364  * MS-FSCC 2.5 FileSystem Information Classes.
365  * Also see MSDN for ZwQueryVolumeInformationFile.
366  */
367 typedef enum _FS_INFORMATION_CLASS
368 {
369 	FileFsVolumeInformation		= 1, /* Query */
370 	FileFsLabelInformation		= 2, /* Set */
371 	FileFsSizeInformation		= 3, /* Query */
372 	FileFsDeviceInformation		= 4, /* Query */
373 	FileFsAttributeInformation	= 5, /* Query */
374 	FileFsControlInformation	= 6, /* Query, Set */
375 	FileFsFullSizeInformation	= 7, /* Query */
376 	FileFsObjectIdInformation	= 8, /* Query, Set */
377 	FileFsDriverPathInformation	= 9 /* Query */
378 } FS_INFORMATION_CLASS;
379 
380 /*
381  * MS-FSCC 2.4 File Information Classes
382  */
383 typedef enum _FILE_INFORMATION_CLASS
384 {
385 	FileDirectoryInformation	= 1,
386 	FileFullDirectoryInformation	= 2,
387 	FileBothDirectoryInformation	= 3,
388 	FileBasicInformation		= 4,
389 	FileStandardInformation		= 5,
390 	FileInternalInformation		= 6,
391 	FileEaInformation		= 7,
392 	FileAccessInformation		= 8,
393 	FileNameInformation		= 9,
394 	FileRenameInformation		= 10,
395 	FileLinkInformation		= 11,
396 	FileNamesInformation		= 12,
397 	FileDispositionInformation	= 13,
398 	FilePositionInformation		= 14,
399 	FileFullEaInformation		= 15,
400 	FileModeInformation		= 16,
401 	FileAlignmentInformation	= 17,
402 	FileAllInformation		= 18,
403 	FileAllocationInformation	= 19,
404 	FileEndOfFileInformation	= 20,
405 	FileAlternateNameInformation	= 21,
406 	FileStreamInformation		= 22,
407 	FilePipeInformation		= 23,
408 	FilePipeLocalInformation	= 24,
409 	FilePipeRemoteInformation	= 25,
410 	FileMailslotQueryInformation	= 26,
411 	FileMailslotSetInformation	= 27,
412 	FileCompressionInformation	= 28,
413 	FileObjectIdInformation		= 29,
414 	FileMoveClusterInformation	= 31,
415 	FileQuotaInformation		= 32,
416 	FileReparsePointInformation	= 33,
417 	FileNetworkOpenInformation	= 34,
418 	FileAttributeTagInformation	= 35,
419 	FileTrackingInformation		= 36,
420 	FileIdBothDirectoryInformation	= 37,
421 	FileIdFullDirectoryInformation	= 38,
422 	FileValidDataLengthInformation	= 39,
423 	FileShortNameInformation	= 40,
424 	FileSfioReserveInformation	= 44,
425 	FileSfioVolumeInformation	= 45,
426 	FileHardLinkInformation		= 46,
427 	FileNormalizedNameInformation	= 48,
428 	FileIdGlobalTxDirectoryInformation = 50,
429 	FileStandardLinkInformation	= 54
430 } FILE_INFORMATION_CLASS;
431 
432 /*
433  * SMB2 Change Nofity Request
434  */
435 #define	SMB2_WATCH_TREE			0x00000001
436 
437 /*
438  * After here, added stuff from darwin
439  */
440 #define	SMB2_TID_UNKNOWN	0
441 #define	SMB2_FID_UNUSED		0xffffffffffffffff
442 
443 /* smb2_durable_handle flags */
444 typedef enum _SMB2_DURABLE_HANDLE_FLAGS
445 {
446 	SMB2_DURABLE_HANDLE_REQUEST = 0x0001,
447 	SMB2_DURABLE_HANDLE_RECONNECT = 0x0002,
448 	SMB2_DURABLE_HANDLE_GRANTED = 0x0004,
449 	SMB2_LEASE_GRANTED = 0x0008
450 } _SMB2_DURABLE_HANDLE_FLAGS;
451 
452 struct smb2_durable_handle {
453 	uint64_t fid;	/* SMBFID to reconnect in durable handle reconnect */
454 	uint64_t flags;
455 	uint64_t lease_key_hi;	/* atomic increment number */
456 	uint64_t lease_key_low;	/* node hash value */
457 	uint32_t lease_state;
458 	uint32_t pad;
459 };
460 
461 #ifdef __cplusplus
462 }
463 #endif
464 
465 #endif /* _NETSMB_SMB2_H */
466