1 | /* SPDX-License-Identifier: LGPL-2.1 */ |
2 | #ifndef _COMMON_SMB2PDU_H |
3 | #define _COMMON_SMB2PDU_H |
4 | |
5 | /* |
6 | * Note that, due to trying to use names similar to the protocol specifications, |
7 | * there are many mixed case field names in the structures below. Although |
8 | * this does not match typical Linux kernel style, it is necessary to be |
9 | * able to match against the protocol specfication. |
10 | * |
11 | * SMB2 commands |
12 | * Some commands have minimal (wct=0,bcc=0), or uninteresting, responses |
13 | * (ie no useful data other than the SMB error code itself) and are marked such. |
14 | * Knowing this helps avoid response buffer allocations and copy in some cases. |
15 | */ |
16 | |
17 | /* List of commands in host endian */ |
18 | #define SMB2_NEGOTIATE_HE 0x0000 |
19 | #define SMB2_SESSION_SETUP_HE 0x0001 |
20 | #define SMB2_LOGOFF_HE 0x0002 /* trivial request/resp */ |
21 | #define SMB2_TREE_CONNECT_HE 0x0003 |
22 | #define SMB2_TREE_DISCONNECT_HE 0x0004 /* trivial req/resp */ |
23 | #define SMB2_CREATE_HE 0x0005 |
24 | #define SMB2_CLOSE_HE 0x0006 |
25 | #define SMB2_FLUSH_HE 0x0007 /* trivial resp */ |
26 | #define SMB2_READ_HE 0x0008 |
27 | #define SMB2_WRITE_HE 0x0009 |
28 | #define SMB2_LOCK_HE 0x000A |
29 | #define SMB2_IOCTL_HE 0x000B |
30 | #define SMB2_CANCEL_HE 0x000C |
31 | #define SMB2_ECHO_HE 0x000D |
32 | #define SMB2_QUERY_DIRECTORY_HE 0x000E |
33 | #define SMB2_CHANGE_NOTIFY_HE 0x000F |
34 | #define SMB2_QUERY_INFO_HE 0x0010 |
35 | #define SMB2_SET_INFO_HE 0x0011 |
36 | #define SMB2_OPLOCK_BREAK_HE 0x0012 |
37 | #define SMB2_SERVER_TO_CLIENT_NOTIFICATION 0x0013 |
38 | |
39 | /* The same list in little endian */ |
40 | #define SMB2_NEGOTIATE cpu_to_le16(SMB2_NEGOTIATE_HE) |
41 | #define SMB2_SESSION_SETUP cpu_to_le16(SMB2_SESSION_SETUP_HE) |
42 | #define SMB2_LOGOFF cpu_to_le16(SMB2_LOGOFF_HE) |
43 | #define SMB2_TREE_CONNECT cpu_to_le16(SMB2_TREE_CONNECT_HE) |
44 | #define SMB2_TREE_DISCONNECT cpu_to_le16(SMB2_TREE_DISCONNECT_HE) |
45 | #define SMB2_CREATE cpu_to_le16(SMB2_CREATE_HE) |
46 | #define SMB2_CLOSE cpu_to_le16(SMB2_CLOSE_HE) |
47 | #define SMB2_FLUSH cpu_to_le16(SMB2_FLUSH_HE) |
48 | #define SMB2_READ cpu_to_le16(SMB2_READ_HE) |
49 | #define SMB2_WRITE cpu_to_le16(SMB2_WRITE_HE) |
50 | #define SMB2_LOCK cpu_to_le16(SMB2_LOCK_HE) |
51 | #define SMB2_IOCTL cpu_to_le16(SMB2_IOCTL_HE) |
52 | #define SMB2_CANCEL cpu_to_le16(SMB2_CANCEL_HE) |
53 | #define SMB2_ECHO cpu_to_le16(SMB2_ECHO_HE) |
54 | #define SMB2_QUERY_DIRECTORY cpu_to_le16(SMB2_QUERY_DIRECTORY_HE) |
55 | #define SMB2_CHANGE_NOTIFY cpu_to_le16(SMB2_CHANGE_NOTIFY_HE) |
56 | #define SMB2_QUERY_INFO cpu_to_le16(SMB2_QUERY_INFO_HE) |
57 | #define SMB2_SET_INFO cpu_to_le16(SMB2_SET_INFO_HE) |
58 | #define SMB2_OPLOCK_BREAK cpu_to_le16(SMB2_OPLOCK_BREAK_HE) |
59 | |
60 | #define SMB2_INTERNAL_CMD cpu_to_le16(0xFFFF) |
61 | |
62 | #define NUMBER_OF_SMB2_COMMANDS 0x0013 |
63 | |
64 | /* |
65 | * Size of the session key (crypto key encrypted with the password |
66 | */ |
67 | #define SMB2_NTLMV2_SESSKEY_SIZE 16 |
68 | #define SMB2_SIGNATURE_SIZE 16 |
69 | #define SMB2_HMACSHA256_SIZE 32 |
70 | #define SMB2_CMACAES_SIZE 16 |
71 | #define SMB3_GCM128_CRYPTKEY_SIZE 16 |
72 | #define SMB3_GCM256_CRYPTKEY_SIZE 32 |
73 | |
74 | /* |
75 | * Size of the smb3 encryption/decryption keys |
76 | * This size is big enough to store any cipher key types. |
77 | */ |
78 | #define SMB3_ENC_DEC_KEY_SIZE 32 |
79 | |
80 | /* |
81 | * Size of the smb3 signing key |
82 | */ |
83 | #define SMB3_SIGN_KEY_SIZE 16 |
84 | |
85 | #define CIFS_CLIENT_CHALLENGE_SIZE 8 |
86 | |
87 | /* Maximum buffer size value we can send with 1 credit */ |
88 | #define SMB2_MAX_BUFFER_SIZE 65536 |
89 | |
90 | /* |
91 | * The default wsize is 1M for SMB2 (and for some CIFS cases). |
92 | * find_get_pages seems to return a maximum of 256 |
93 | * pages in a single call. With PAGE_SIZE == 4k, this means we can |
94 | * fill a single wsize request with a single call. |
95 | */ |
96 | #define SMB3_DEFAULT_IOSIZE (4 * 1024 * 1024) |
97 | |
98 | /* |
99 | * SMB2 Header Definition |
100 | * |
101 | * "MBZ" : Must be Zero |
102 | * "BB" : BugBug, Something to check/review/analyze later |
103 | * "PDU" : "Protocol Data Unit" (ie a network "frame") |
104 | * |
105 | */ |
106 | |
107 | #define 64 |
108 | #define \ |
109 | cpu_to_le16(__SMB2_HEADER_STRUCTURE_SIZE) |
110 | |
111 | #define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe) |
112 | #define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd) |
113 | #define SMB2_COMPRESSION_TRANSFORM_ID cpu_to_le32(0x424d53fc) |
114 | |
115 | /* |
116 | * SMB2 flag definitions |
117 | */ |
118 | #define SMB2_FLAGS_SERVER_TO_REDIR cpu_to_le32(0x00000001) |
119 | #define SMB2_FLAGS_ASYNC_COMMAND cpu_to_le32(0x00000002) |
120 | #define SMB2_FLAGS_RELATED_OPERATIONS cpu_to_le32(0x00000004) |
121 | #define SMB2_FLAGS_SIGNED cpu_to_le32(0x00000008) |
122 | #define SMB2_FLAGS_PRIORITY_MASK cpu_to_le32(0x00000070) /* SMB3.1.1 */ |
123 | #define SMB2_FLAGS_DFS_OPERATIONS cpu_to_le32(0x10000000) |
124 | #define SMB2_FLAGS_REPLAY_OPERATION cpu_to_le32(0x20000000) /* SMB3 & up */ |
125 | |
126 | /* |
127 | * Definitions for SMB2 Protocol Data Units (network frames) |
128 | * |
129 | * See MS-SMB2.PDF specification for protocol details. |
130 | * The Naming convention is the lower case version of the SMB2 |
131 | * command code name for the struct. Note that structures must be packed. |
132 | * |
133 | */ |
134 | |
135 | /* See MS-SMB2 section 2.2.1 */ |
136 | struct smb2_hdr { |
137 | __le32 ProtocolId; /* 0xFE 'S' 'M' 'B' */ |
138 | __le16 StructureSize; /* 64 */ |
139 | __le16 CreditCharge; /* MBZ */ |
140 | __le32 Status; /* Error from server */ |
141 | __le16 Command; |
142 | __le16 CreditRequest; /* CreditResponse */ |
143 | __le32 Flags; |
144 | __le32 NextCommand; |
145 | __le64 MessageId; |
146 | union { |
147 | struct { |
148 | __le32 ProcessId; |
149 | __le32 TreeId; |
150 | } __packed SyncId; |
151 | __le64 AsyncId; |
152 | } __packed Id; |
153 | __le64 SessionId; |
154 | __u8 Signature[16]; |
155 | } __packed; |
156 | |
157 | struct smb3_hdr_req { |
158 | __le32 ProtocolId; /* 0xFE 'S' 'M' 'B' */ |
159 | __le16 StructureSize; /* 64 */ |
160 | __le16 CreditCharge; /* MBZ */ |
161 | __le16 ChannelSequence; /* See MS-SMB2 3.2.4.1 and 3.2.7.1 */ |
162 | __le16 Reserved; |
163 | __le16 Command; |
164 | __le16 CreditRequest; /* CreditResponse */ |
165 | __le32 Flags; |
166 | __le32 NextCommand; |
167 | __le64 MessageId; |
168 | union { |
169 | struct { |
170 | __le32 ProcessId; |
171 | __le32 TreeId; |
172 | } __packed SyncId; |
173 | __le64 AsyncId; |
174 | } __packed Id; |
175 | __le64 SessionId; |
176 | __u8 Signature[16]; |
177 | } __packed; |
178 | |
179 | struct smb2_pdu { |
180 | struct smb2_hdr hdr; |
181 | __le16 StructureSize2; /* size of wct area (varies, request specific) */ |
182 | } __packed; |
183 | |
184 | #define SMB2_ERROR_STRUCTURE_SIZE2 9 |
185 | #define SMB2_ERROR_STRUCTURE_SIZE2_LE cpu_to_le16(SMB2_ERROR_STRUCTURE_SIZE2) |
186 | |
187 | struct smb2_err_rsp { |
188 | struct smb2_hdr hdr; |
189 | __le16 StructureSize; |
190 | __u8 ErrorContextCount; |
191 | __u8 Reserved; |
192 | __le32 ByteCount; /* even if zero, at least one byte follows */ |
193 | __u8 ErrorData[]; /* variable length */ |
194 | } __packed; |
195 | |
196 | #define SMB3_AES_CCM_NONCE 11 |
197 | #define SMB3_AES_GCM_NONCE 12 |
198 | |
199 | /* Transform flags (for 3.0 dialect this flag indicates CCM */ |
200 | #define TRANSFORM_FLAG_ENCRYPTED 0x0001 |
201 | struct smb2_transform_hdr { |
202 | __le32 ProtocolId; /* 0xFD 'S' 'M' 'B' */ |
203 | __u8 Signature[16]; |
204 | __u8 Nonce[16]; |
205 | __le32 OriginalMessageSize; |
206 | __u16 Reserved1; |
207 | __le16 Flags; /* EncryptionAlgorithm for 3.0, enc enabled for 3.1.1 */ |
208 | __le64 SessionId; |
209 | } __packed; |
210 | |
211 | /* |
212 | * These are simplified versions from the spec, as we don't need a fully fledged |
213 | * form of both unchained and chained structs. |
214 | * |
215 | * Moreover, even in chained compressed payloads, the initial compression header |
216 | * has the form of the unchained one -- i.e. it never has the |
217 | * OriginalPayloadSize field and ::Offset field always represent an offset |
218 | * (instead of a length, as it is in the chained header). |
219 | * |
220 | * See MS-SMB2 2.2.42 for more details. |
221 | */ |
222 | #define SMB2_COMPRESSION_FLAG_NONE 0x0000 |
223 | #define SMB2_COMPRESSION_FLAG_CHAINED 0x0001 |
224 | |
225 | struct smb2_compression_hdr { |
226 | __le32 ProtocolId; /* 0xFC 'S' 'M' 'B' */ |
227 | __le32 OriginalCompressedSegmentSize; |
228 | __le16 CompressionAlgorithm; |
229 | __le16 Flags; |
230 | __le32 Offset; /* this is the size of the uncompressed SMB2 header below */ |
231 | /* uncompressed SMB2 header (READ or WRITE) goes here */ |
232 | /* compressed data goes here */ |
233 | } __packed; |
234 | |
235 | /* |
236 | * ... OTOH, set compression payload header to always have OriginalPayloadSize |
237 | * as it's easier to pass the struct size minus sizeof(OriginalPayloadSize) |
238 | * than to juggle around the header/data memory. |
239 | */ |
240 | struct smb2_compression_payload_hdr { |
241 | __le16 CompressionAlgorithm; |
242 | __le16 Flags; |
243 | __le32 Length; /* length of compressed playload including field below if present */ |
244 | __le32 OriginalPayloadSize; /* accounted when LZNT1, LZ77, LZ77+Huffman */ |
245 | } __packed; |
246 | |
247 | struct smb2_compression_pattern_v1 { |
248 | __u8 Pattern; |
249 | __u8 Reserved1; |
250 | __le16 Reserved2; |
251 | __le32 Repetitions; |
252 | } __packed; |
253 | |
254 | /* See MS-SMB2 section 2.2.9.2 */ |
255 | /* Context Types */ |
256 | #define SMB2_RESERVED_TREE_CONNECT_CONTEXT_ID 0x0000 |
257 | #define SMB2_REMOTED_IDENTITY_TREE_CONNECT_CONTEXT_ID cpu_to_le16(0x0001) |
258 | |
259 | struct tree_connect_contexts { |
260 | __le16 ContextType; |
261 | __le16 DataLength; |
262 | __le32 Reserved; |
263 | __u8 Data[]; |
264 | } __packed; |
265 | |
266 | /* Remoted identity tree connect context structures - see MS-SMB2 2.2.9.2.1 */ |
267 | struct smb3_blob_data { |
268 | __le16 BlobSize; |
269 | __u8 BlobData[]; |
270 | } __packed; |
271 | |
272 | /* Valid values for Attr */ |
273 | #define SE_GROUP_MANDATORY 0x00000001 |
274 | #define SE_GROUP_ENABLED_BY_DEFAULT 0x00000002 |
275 | #define SE_GROUP_ENABLED 0x00000004 |
276 | #define SE_GROUP_OWNER 0x00000008 |
277 | #define SE_GROUP_USE_FOR_DENY_ONLY 0x00000010 |
278 | #define SE_GROUP_INTEGRITY 0x00000020 |
279 | #define SE_GROUP_INTEGRITY_ENABLED 0x00000040 |
280 | #define SE_GROUP_RESOURCE 0x20000000 |
281 | #define SE_GROUP_LOGON_ID 0xC0000000 |
282 | |
283 | struct sid_array_data { |
284 | __le16 SidAttrCount; |
285 | /* SidAttrList - array of sid_attr_data structs */ |
286 | } __packed; |
287 | |
288 | /* struct sid_attr_data is SidData array in BlobData format then le32 Attr */ |
289 | struct sid_attr_data { |
290 | __le16 BlobSize; |
291 | __u8 BlobData[]; |
292 | /* __le32 Attr */ |
293 | } __packed; |
294 | |
295 | /* |
296 | * struct privilege_data is the same as BLOB_DATA - see MS-SMB2 2.2.9.2.1.5 |
297 | * but with size of LUID_ATTR_DATA struct and BlobData set to LUID_ATTR DATA |
298 | */ |
299 | |
300 | struct privilege_array_data { |
301 | __le16 PrivilegeCount; |
302 | /* array of privilege_data structs */ |
303 | } __packed; |
304 | |
305 | struct remoted_identity_tcon_context { |
306 | __le16 TicketType; /* must be 0x0001 */ |
307 | __le16 TicketSize; /* total size of this struct */ |
308 | __le16 User; /* offset to SID_ATTR_DATA struct with user info */ |
309 | __le16 UserName; /* offset to null terminated Unicode username string */ |
310 | __le16 Domain; /* offset to null terminated Unicode domain name */ |
311 | __le16 Groups; /* offset to SID_ARRAY_DATA struct with group info */ |
312 | __le16 RestrictedGroups; /* similar to above */ |
313 | __le16 Privileges; /* offset to PRIVILEGE_ARRAY_DATA struct */ |
314 | __le16 PrimaryGroup; /* offset to SID_ARRAY_DATA struct */ |
315 | __le16 Owner; /* offset to BLOB_DATA struct */ |
316 | __le16 DefaultDacl; /* offset to BLOB_DATA struct */ |
317 | __le16 DeviceGroups; /* offset to SID_ARRAY_DATA struct */ |
318 | __le16 UserClaims; /* offset to BLOB_DATA struct */ |
319 | __le16 DeviceClaims; /* offset to BLOB_DATA struct */ |
320 | __u8 TicketInfo[]; /* variable length buf - remoted identity data */ |
321 | } __packed; |
322 | |
323 | struct smb2_tree_connect_req_extension { |
324 | __le32 TreeConnectContextOffset; |
325 | __le16 TreeConnectContextCount; |
326 | __u8 Reserved[10]; |
327 | __u8 PathName[]; /* variable sized array */ |
328 | /* followed by array of TreeConnectContexts */ |
329 | } __packed; |
330 | |
331 | /* Flags/Reserved for SMB3.1.1 */ |
332 | #define SMB2_TREE_CONNECT_FLAG_CLUSTER_RECONNECT cpu_to_le16(0x0001) |
333 | #define SMB2_TREE_CONNECT_FLAG_REDIRECT_TO_OWNER cpu_to_le16(0x0002) |
334 | #define SMB2_TREE_CONNECT_FLAG_EXTENSION_PRESENT cpu_to_le16(0x0004) |
335 | |
336 | struct smb2_tree_connect_req { |
337 | struct smb2_hdr hdr; |
338 | __le16 StructureSize; /* Must be 9 */ |
339 | __le16 Flags; /* Flags in SMB3.1.1 */ |
340 | __le16 PathOffset; |
341 | __le16 PathLength; |
342 | __u8 Buffer[]; /* variable length */ |
343 | } __packed; |
344 | |
345 | /* Possible ShareType values */ |
346 | #define SMB2_SHARE_TYPE_DISK 0x01 |
347 | #define SMB2_SHARE_TYPE_PIPE 0x02 |
348 | #define SMB2_SHARE_TYPE_PRINT 0x03 |
349 | |
350 | /* |
351 | * Possible ShareFlags - exactly one and only one of the first 4 caching flags |
352 | * must be set (any of the remaining, SHI1005, flags may be set individually |
353 | * or in combination. |
354 | */ |
355 | #define SMB2_SHAREFLAG_MANUAL_CACHING 0x00000000 |
356 | #define SMB2_SHAREFLAG_AUTO_CACHING 0x00000010 |
357 | #define SMB2_SHAREFLAG_VDO_CACHING 0x00000020 |
358 | #define SMB2_SHAREFLAG_NO_CACHING 0x00000030 |
359 | #define SHI1005_FLAGS_DFS 0x00000001 |
360 | #define SHI1005_FLAGS_DFS_ROOT 0x00000002 |
361 | #define SMB2_SHAREFLAG_RESTRICT_EXCLUSIVE_OPENS 0x00000100 |
362 | #define SMB2_SHAREFLAG_FORCE_SHARED_DELETE 0x00000200 |
363 | #define SMB2_SHAREFLAG_ALLOW_NAMESPACE_CACHING 0x00000400 |
364 | #define SMB2_SHAREFLAG_ACCESS_BASED_DIRECTORY_ENUM 0x00000800 |
365 | #define SMB2_SHAREFLAG_FORCE_LEVELII_OPLOCK 0x00001000 |
366 | #define SMB2_SHAREFLAG_ENABLE_HASH_V1 0x00002000 |
367 | #define SMB2_SHAREFLAG_ENABLE_HASH_V2 0x00004000 |
368 | #define SHI1005_FLAGS_ENCRYPT_DATA 0x00008000 |
369 | #define SMB2_SHAREFLAG_IDENTITY_REMOTING 0x00040000 /* 3.1.1 */ |
370 | #define SMB2_SHAREFLAG_COMPRESS_DATA 0x00100000 /* 3.1.1 */ |
371 | #define SMB2_SHAREFLAG_ISOLATED_TRANSPORT 0x00200000 |
372 | #define SHI1005_FLAGS_ALL 0x0034FF33 |
373 | |
374 | /* Possible share capabilities */ |
375 | #define SMB2_SHARE_CAP_DFS cpu_to_le32(0x00000008) /* all dialects */ |
376 | #define SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY cpu_to_le32(0x00000010) /* 3.0 */ |
377 | #define SMB2_SHARE_CAP_SCALEOUT cpu_to_le32(0x00000020) /* 3.0 */ |
378 | #define SMB2_SHARE_CAP_CLUSTER cpu_to_le32(0x00000040) /* 3.0 */ |
379 | #define SMB2_SHARE_CAP_ASYMMETRIC cpu_to_le32(0x00000080) /* 3.02 */ |
380 | #define SMB2_SHARE_CAP_REDIRECT_TO_OWNER cpu_to_le32(0x00000100) /* 3.1.1 */ |
381 | |
382 | struct smb2_tree_connect_rsp { |
383 | struct smb2_hdr hdr; |
384 | __le16 StructureSize; /* Must be 16 */ |
385 | __u8 ShareType; /* see below */ |
386 | __u8 Reserved; |
387 | __le32 ShareFlags; /* see below */ |
388 | __le32 Capabilities; /* see below */ |
389 | __le32 MaximalAccess; |
390 | } __packed; |
391 | |
392 | struct smb2_tree_disconnect_req { |
393 | struct smb2_hdr hdr; |
394 | __le16 StructureSize; /* Must be 4 */ |
395 | __le16 Reserved; |
396 | } __packed; |
397 | |
398 | struct smb2_tree_disconnect_rsp { |
399 | struct smb2_hdr hdr; |
400 | __le16 StructureSize; /* Must be 4 */ |
401 | __le16 Reserved; |
402 | } __packed; |
403 | |
404 | |
405 | /* |
406 | * SMB2_NEGOTIATE_PROTOCOL See MS-SMB2 section 2.2.3 |
407 | */ |
408 | /* SecurityMode flags */ |
409 | #define SMB2_NEGOTIATE_SIGNING_ENABLED 0x0001 |
410 | #define SMB2_NEGOTIATE_SIGNING_ENABLED_LE cpu_to_le16(0x0001) |
411 | #define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002 |
412 | #define SMB2_NEGOTIATE_SIGNING_REQUIRED_LE cpu_to_le16(0x0002) |
413 | #define SMB2_SEC_MODE_FLAGS_ALL 0x0003 |
414 | |
415 | /* Capabilities flags */ |
416 | #define SMB2_GLOBAL_CAP_DFS 0x00000001 |
417 | #define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */ |
418 | #define SMB2_GLOBAL_CAP_LARGE_MTU 0x00000004 /* Resp only New to SMB2.1 */ |
419 | #define SMB2_GLOBAL_CAP_MULTI_CHANNEL 0x00000008 /* New to SMB3 */ |
420 | #define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */ |
421 | #define SMB2_GLOBAL_CAP_DIRECTORY_LEASING 0x00000020 /* New to SMB3 */ |
422 | #define SMB2_GLOBAL_CAP_ENCRYPTION 0x00000040 /* New to SMB3 */ |
423 | #define SMB2_GLOBAL_CAP_NOTIFICATIONS 0x00000080 /* New to SMB3.1.1 */ |
424 | /* Internal types */ |
425 | #define SMB2_NT_FIND 0x00100000 |
426 | #define SMB2_LARGE_FILES 0x00200000 |
427 | |
428 | #define SMB2_CLIENT_GUID_SIZE 16 |
429 | #define SMB2_CREATE_GUID_SIZE 16 |
430 | |
431 | /* Dialects */ |
432 | #define SMB10_PROT_ID 0x0000 /* local only, not sent on wire w/CIFS negprot */ |
433 | #define SMB20_PROT_ID 0x0202 |
434 | #define SMB21_PROT_ID 0x0210 |
435 | #define SMB2X_PROT_ID 0x02FF |
436 | #define SMB30_PROT_ID 0x0300 |
437 | #define SMB302_PROT_ID 0x0302 |
438 | #define SMB311_PROT_ID 0x0311 |
439 | #define BAD_PROT_ID 0xFFFF |
440 | |
441 | #define SMB311_SALT_SIZE 32 |
442 | /* Hash Algorithm Types */ |
443 | #define SMB2_PREAUTH_INTEGRITY_SHA512 cpu_to_le16(0x0001) |
444 | #define SMB2_PREAUTH_HASH_SIZE 64 |
445 | |
446 | /* Negotiate Contexts - ContextTypes. See MS-SMB2 section 2.2.3.1 for details */ |
447 | #define SMB2_PREAUTH_INTEGRITY_CAPABILITIES cpu_to_le16(1) |
448 | #define SMB2_ENCRYPTION_CAPABILITIES cpu_to_le16(2) |
449 | #define SMB2_COMPRESSION_CAPABILITIES cpu_to_le16(3) |
450 | #define SMB2_NETNAME_NEGOTIATE_CONTEXT_ID cpu_to_le16(5) |
451 | #define SMB2_TRANSPORT_CAPABILITIES cpu_to_le16(6) |
452 | #define SMB2_RDMA_TRANSFORM_CAPABILITIES cpu_to_le16(7) |
453 | #define SMB2_SIGNING_CAPABILITIES cpu_to_le16(8) |
454 | #define SMB2_POSIX_EXTENSIONS_AVAILABLE cpu_to_le16(0x100) |
455 | |
456 | struct smb2_neg_context { |
457 | __le16 ContextType; |
458 | __le16 DataLength; |
459 | __le32 Reserved; |
460 | /* Followed by array of data. NOTE: some servers require padding to 8 byte boundary */ |
461 | } __packed; |
462 | |
463 | /* |
464 | * SaltLength that the server send can be zero, so the only three required |
465 | * fields (all __le16) end up six bytes total, so the minimum context data len |
466 | * in the response is six bytes which accounts for |
467 | * |
468 | * HashAlgorithmCount, SaltLength, and 1 HashAlgorithm. |
469 | */ |
470 | #define MIN_PREAUTH_CTXT_DATA_LEN 6 |
471 | |
472 | struct smb2_preauth_neg_context { |
473 | __le16 ContextType; /* 1 */ |
474 | __le16 DataLength; |
475 | __le32 Reserved; |
476 | __le16 HashAlgorithmCount; /* 1 */ |
477 | __le16 SaltLength; |
478 | __le16 HashAlgorithms; /* HashAlgorithms[0] since only one defined */ |
479 | __u8 Salt[SMB311_SALT_SIZE]; |
480 | } __packed; |
481 | |
482 | /* Encryption Algorithms Ciphers */ |
483 | #define SMB2_ENCRYPTION_AES128_CCM cpu_to_le16(0x0001) |
484 | #define SMB2_ENCRYPTION_AES128_GCM cpu_to_le16(0x0002) |
485 | #define SMB2_ENCRYPTION_AES256_CCM cpu_to_le16(0x0003) |
486 | #define SMB2_ENCRYPTION_AES256_GCM cpu_to_le16(0x0004) |
487 | |
488 | /* Min encrypt context data is one cipher so 2 bytes + 2 byte count field */ |
489 | #define MIN_ENCRYPT_CTXT_DATA_LEN 4 |
490 | struct smb2_encryption_neg_context { |
491 | __le16 ContextType; /* 2 */ |
492 | __le16 DataLength; |
493 | __le32 Reserved; |
494 | /* CipherCount usally 2, but can be 3 when AES256-GCM enabled */ |
495 | __le16 CipherCount; /* AES128-GCM and AES128-CCM by default */ |
496 | __le16 Ciphers[]; |
497 | } __packed; |
498 | |
499 | /* See MS-SMB2 2.2.3.1.3 */ |
500 | #define SMB3_COMPRESS_NONE cpu_to_le16(0x0000) |
501 | #define SMB3_COMPRESS_LZNT1 cpu_to_le16(0x0001) |
502 | #define SMB3_COMPRESS_LZ77 cpu_to_le16(0x0002) |
503 | #define SMB3_COMPRESS_LZ77_HUFF cpu_to_le16(0x0003) |
504 | /* Pattern scanning algorithm See MS-SMB2 3.1.4.4.1 */ |
505 | #define SMB3_COMPRESS_PATTERN cpu_to_le16(0x0004) /* Pattern_V1 */ |
506 | #define SMB3_COMPRESS_LZ4 cpu_to_le16(0x0005) |
507 | |
508 | /* Compression Flags */ |
509 | #define SMB2_COMPRESSION_CAPABILITIES_FLAG_NONE cpu_to_le32(0x00000000) |
510 | #define SMB2_COMPRESSION_CAPABILITIES_FLAG_CHAINED cpu_to_le32(0x00000001) |
511 | |
512 | struct smb2_compression_capabilities_context { |
513 | __le16 ContextType; /* 3 */ |
514 | __le16 DataLength; |
515 | __le32 Reserved; |
516 | __le16 CompressionAlgorithmCount; |
517 | __le16 Padding; |
518 | __le32 Flags; |
519 | __le16 CompressionAlgorithms[3]; |
520 | __u16 Pad; /* Some servers require pad to DataLen multiple of 8 */ |
521 | /* Check if pad needed */ |
522 | } __packed; |
523 | |
524 | /* |
525 | * For smb2_netname_negotiate_context_id See MS-SMB2 2.2.3.1.4. |
526 | * Its struct simply contains NetName, an array of Unicode characters |
527 | */ |
528 | struct smb2_netname_neg_context { |
529 | __le16 ContextType; /* 5 */ |
530 | __le16 DataLength; |
531 | __le32 Reserved; |
532 | __le16 NetName[]; /* hostname of target converted to UCS-2 */ |
533 | } __packed; |
534 | |
535 | /* |
536 | * For smb2_transport_capabilities context see MS-SMB2 2.2.3.1.5 |
537 | * and 2.2.4.1.5 |
538 | */ |
539 | |
540 | /* Flags */ |
541 | #define SMB2_ACCEPT_TRANSPORT_LEVEL_SECURITY 0x00000001 |
542 | |
543 | struct smb2_transport_capabilities_context { |
544 | __le16 ContextType; /* 6 */ |
545 | __le16 DataLength; |
546 | __u32 Reserved; |
547 | __le32 Flags; |
548 | __u32 Pad; |
549 | } __packed; |
550 | |
551 | /* |
552 | * For rdma transform capabilities context see MS-SMB2 2.2.3.1.6 |
553 | * and 2.2.4.1.6 |
554 | */ |
555 | |
556 | /* RDMA Transform IDs */ |
557 | #define SMB2_RDMA_TRANSFORM_NONE 0x0000 |
558 | #define SMB2_RDMA_TRANSFORM_ENCRYPTION 0x0001 |
559 | #define SMB2_RDMA_TRANSFORM_SIGNING 0x0002 |
560 | |
561 | struct smb2_rdma_transform_capabilities_context { |
562 | __le16 ContextType; /* 7 */ |
563 | __le16 DataLength; |
564 | __u32 Reserved; |
565 | __le16 TransformCount; |
566 | __u16 Reserved1; |
567 | __u32 Reserved2; |
568 | __le16 RDMATransformIds[]; |
569 | } __packed; |
570 | |
571 | /* |
572 | * For signing capabilities context see MS-SMB2 2.2.3.1.7 |
573 | * and 2.2.4.1.7 |
574 | */ |
575 | |
576 | /* Signing algorithms */ |
577 | #define SIGNING_ALG_HMAC_SHA256 0 |
578 | #define SIGNING_ALG_HMAC_SHA256_LE cpu_to_le16(0) |
579 | #define SIGNING_ALG_AES_CMAC 1 |
580 | #define SIGNING_ALG_AES_CMAC_LE cpu_to_le16(1) |
581 | #define SIGNING_ALG_AES_GMAC 2 |
582 | #define SIGNING_ALG_AES_GMAC_LE cpu_to_le16(2) |
583 | |
584 | struct smb2_signing_capabilities { |
585 | __le16 ContextType; /* 8 */ |
586 | __le16 DataLength; |
587 | __le32 Reserved; |
588 | __le16 SigningAlgorithmCount; |
589 | __le16 SigningAlgorithms[]; |
590 | /* Followed by padding to 8 byte boundary (required by some servers) */ |
591 | } __packed; |
592 | |
593 | #define POSIX_CTXT_DATA_LEN 16 |
594 | struct smb2_posix_neg_context { |
595 | __le16 ContextType; /* 0x100 */ |
596 | __le16 DataLength; |
597 | __le32 Reserved; |
598 | __u8 Name[16]; /* POSIX ctxt GUID 93AD25509CB411E7B42383DE968BCD7C */ |
599 | } __packed; |
600 | |
601 | struct smb2_negotiate_req { |
602 | struct smb2_hdr hdr; |
603 | __le16 StructureSize; /* Must be 36 */ |
604 | __le16 DialectCount; |
605 | __le16 SecurityMode; |
606 | __le16 Reserved; /* MBZ */ |
607 | __le32 Capabilities; |
608 | __u8 ClientGUID[SMB2_CLIENT_GUID_SIZE]; |
609 | /* In SMB3.02 and earlier next three were MBZ le64 ClientStartTime */ |
610 | __le32 NegotiateContextOffset; /* SMB3.1.1 only. MBZ earlier */ |
611 | __le16 NegotiateContextCount; /* SMB3.1.1 only. MBZ earlier */ |
612 | __le16 Reserved2; |
613 | __le16 Dialects[]; |
614 | } __packed; |
615 | |
616 | struct smb2_negotiate_rsp { |
617 | struct smb2_hdr hdr; |
618 | __le16 StructureSize; /* Must be 65 */ |
619 | __le16 SecurityMode; |
620 | __le16 DialectRevision; |
621 | __le16 NegotiateContextCount; /* Prior to SMB3.1.1 was Reserved & MBZ */ |
622 | __u8 ServerGUID[16]; |
623 | __le32 Capabilities; |
624 | __le32 MaxTransactSize; |
625 | __le32 MaxReadSize; |
626 | __le32 MaxWriteSize; |
627 | __le64 SystemTime; /* MBZ */ |
628 | __le64 ServerStartTime; |
629 | __le16 SecurityBufferOffset; |
630 | __le16 SecurityBufferLength; |
631 | __le32 NegotiateContextOffset; /* Pre:SMB3.1.1 was reserved/ignored */ |
632 | __u8 Buffer[]; /* variable length GSS security buffer */ |
633 | } __packed; |
634 | |
635 | |
636 | /* |
637 | * SMB2_SESSION_SETUP See MS-SMB2 section 2.2.5 |
638 | */ |
639 | /* Flags */ |
640 | #define SMB2_SESSION_REQ_FLAG_BINDING 0x01 |
641 | #define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA 0x04 |
642 | |
643 | struct smb2_sess_setup_req { |
644 | struct smb2_hdr hdr; |
645 | __le16 StructureSize; /* Must be 25 */ |
646 | __u8 Flags; |
647 | __u8 SecurityMode; |
648 | __le32 Capabilities; |
649 | __le32 Channel; |
650 | __le16 SecurityBufferOffset; |
651 | __le16 SecurityBufferLength; |
652 | __le64 PreviousSessionId; |
653 | __u8 Buffer[]; /* variable length GSS security buffer */ |
654 | } __packed; |
655 | |
656 | /* Currently defined SessionFlags */ |
657 | #define SMB2_SESSION_FLAG_IS_GUEST 0x0001 |
658 | #define SMB2_SESSION_FLAG_IS_GUEST_LE cpu_to_le16(0x0001) |
659 | #define SMB2_SESSION_FLAG_IS_NULL 0x0002 |
660 | #define SMB2_SESSION_FLAG_IS_NULL_LE cpu_to_le16(0x0002) |
661 | #define SMB2_SESSION_FLAG_ENCRYPT_DATA 0x0004 |
662 | #define SMB2_SESSION_FLAG_ENCRYPT_DATA_LE cpu_to_le16(0x0004) |
663 | |
664 | struct smb2_sess_setup_rsp { |
665 | struct smb2_hdr hdr; |
666 | __le16 StructureSize; /* Must be 9 */ |
667 | __le16 SessionFlags; |
668 | __le16 SecurityBufferOffset; |
669 | __le16 SecurityBufferLength; |
670 | __u8 Buffer[]; /* variable length GSS security buffer */ |
671 | } __packed; |
672 | |
673 | |
674 | /* |
675 | * SMB2_LOGOFF See MS-SMB2 section 2.2.7 |
676 | */ |
677 | struct smb2_logoff_req { |
678 | struct smb2_hdr hdr; |
679 | __le16 StructureSize; /* Must be 4 */ |
680 | __le16 Reserved; |
681 | } __packed; |
682 | |
683 | struct smb2_logoff_rsp { |
684 | struct smb2_hdr hdr; |
685 | __le16 StructureSize; /* Must be 4 */ |
686 | __le16 Reserved; |
687 | } __packed; |
688 | |
689 | |
690 | /* |
691 | * SMB2_CLOSE See MS-SMB2 section 2.2.15 |
692 | */ |
693 | /* Currently defined values for close flags */ |
694 | #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001) |
695 | struct smb2_close_req { |
696 | struct smb2_hdr hdr; |
697 | __le16 StructureSize; /* Must be 24 */ |
698 | __le16 Flags; |
699 | __le32 Reserved; |
700 | __u64 PersistentFileId; /* opaque endianness */ |
701 | __u64 VolatileFileId; /* opaque endianness */ |
702 | } __packed; |
703 | |
704 | /* |
705 | * Maximum size of a SMB2_CLOSE response is 64 (smb2 header) + 60 (data) |
706 | */ |
707 | #define MAX_SMB2_CLOSE_RESPONSE_SIZE 124 |
708 | |
709 | struct smb2_close_rsp { |
710 | struct smb2_hdr hdr; |
711 | __le16 StructureSize; /* 60 */ |
712 | __le16 Flags; |
713 | __le32 Reserved; |
714 | struct_group_attr(network_open_info, __packed, |
715 | __le64 CreationTime; |
716 | __le64 LastAccessTime; |
717 | __le64 LastWriteTime; |
718 | __le64 ChangeTime; |
719 | /* Beginning of FILE_STANDARD_INFO equivalent */ |
720 | __le64 AllocationSize; |
721 | __le64 EndOfFile; |
722 | __le32 Attributes; |
723 | ); |
724 | } __packed; |
725 | |
726 | |
727 | /* |
728 | * SMB2_READ See MS-SMB2 section 2.2.19 |
729 | */ |
730 | /* For read request Flags field below, following flag is defined for SMB3.02 */ |
731 | #define SMB2_READFLAG_READ_UNBUFFERED 0x01 |
732 | #define SMB2_READFLAG_REQUEST_COMPRESSED 0x02 /* See MS-SMB2 2.2.19 */ |
733 | |
734 | /* Channel field for read and write: exactly one of following flags can be set*/ |
735 | #define SMB2_CHANNEL_NONE cpu_to_le32(0x00000000) |
736 | #define SMB2_CHANNEL_RDMA_V1 cpu_to_le32(0x00000001) |
737 | #define SMB2_CHANNEL_RDMA_V1_INVALIDATE cpu_to_le32(0x00000002) |
738 | #define SMB2_CHANNEL_RDMA_TRANSFORM cpu_to_le32(0x00000003) |
739 | |
740 | /* SMB2 read request without RFC1001 length at the beginning */ |
741 | struct smb2_read_req { |
742 | struct smb2_hdr hdr; |
743 | __le16 StructureSize; /* Must be 49 */ |
744 | __u8 Padding; /* offset from start of SMB2 header to place read */ |
745 | __u8 Flags; /* MBZ unless SMB3.02 or later */ |
746 | __le32 Length; |
747 | __le64 Offset; |
748 | __u64 PersistentFileId; |
749 | __u64 VolatileFileId; |
750 | __le32 MinimumCount; |
751 | __le32 Channel; /* MBZ except for SMB3 or later */ |
752 | __le32 RemainingBytes; |
753 | __le16 ReadChannelInfoOffset; |
754 | __le16 ReadChannelInfoLength; |
755 | __u8 Buffer[]; |
756 | } __packed; |
757 | |
758 | /* Read flags */ |
759 | #define SMB2_READFLAG_RESPONSE_NONE cpu_to_le32(0x00000000) |
760 | #define SMB2_READFLAG_RESPONSE_RDMA_TRANSFORM cpu_to_le32(0x00000001) |
761 | |
762 | struct smb2_read_rsp { |
763 | struct smb2_hdr hdr; |
764 | __le16 StructureSize; /* Must be 17 */ |
765 | __u8 DataOffset; |
766 | __u8 Reserved; |
767 | __le32 DataLength; |
768 | __le32 DataRemaining; |
769 | __le32 Flags; |
770 | __u8 Buffer[]; |
771 | } __packed; |
772 | |
773 | |
774 | /* |
775 | * SMB2_WRITE See MS-SMB2 section 2.2.21 |
776 | */ |
777 | /* For write request Flags field below the following flags are defined: */ |
778 | #define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001 /* SMB2.1 or later */ |
779 | #define SMB2_WRITEFLAG_WRITE_UNBUFFERED 0x00000002 /* SMB3.02 or later */ |
780 | |
781 | struct smb2_write_req { |
782 | struct smb2_hdr hdr; |
783 | __le16 StructureSize; /* Must be 49 */ |
784 | __le16 DataOffset; /* offset from start of SMB2 header to write data */ |
785 | __le32 Length; |
786 | __le64 Offset; |
787 | __u64 PersistentFileId; /* opaque endianness */ |
788 | __u64 VolatileFileId; /* opaque endianness */ |
789 | __le32 Channel; /* MBZ unless SMB3.02 or later */ |
790 | __le32 RemainingBytes; |
791 | __le16 WriteChannelInfoOffset; |
792 | __le16 WriteChannelInfoLength; |
793 | __le32 Flags; |
794 | __u8 Buffer[]; |
795 | } __packed; |
796 | |
797 | struct smb2_write_rsp { |
798 | struct smb2_hdr hdr; |
799 | __le16 StructureSize; /* Must be 17 */ |
800 | __u8 DataOffset; |
801 | __u8 Reserved; |
802 | __le32 DataLength; |
803 | __le32 DataRemaining; |
804 | __u32 Reserved2; |
805 | __u8 Buffer[]; |
806 | } __packed; |
807 | |
808 | |
809 | /* |
810 | * SMB2_FLUSH See MS-SMB2 section 2.2.17 |
811 | */ |
812 | struct smb2_flush_req { |
813 | struct smb2_hdr hdr; |
814 | __le16 StructureSize; /* Must be 24 */ |
815 | __le16 Reserved1; |
816 | __le32 Reserved2; |
817 | __u64 PersistentFileId; |
818 | __u64 VolatileFileId; |
819 | } __packed; |
820 | |
821 | struct smb2_flush_rsp { |
822 | struct smb2_hdr hdr; |
823 | __le16 StructureSize; |
824 | __le16 Reserved; |
825 | } __packed; |
826 | |
827 | #define SMB2_LOCKFLAG_SHARED 0x0001 |
828 | #define SMB2_LOCKFLAG_EXCLUSIVE 0x0002 |
829 | #define SMB2_LOCKFLAG_UNLOCK 0x0004 |
830 | #define SMB2_LOCKFLAG_FAIL_IMMEDIATELY 0x0010 |
831 | #define SMB2_LOCKFLAG_MASK 0x0007 |
832 | |
833 | struct smb2_lock_element { |
834 | __le64 Offset; |
835 | __le64 Length; |
836 | __le32 Flags; |
837 | __le32 Reserved; |
838 | } __packed; |
839 | |
840 | struct smb2_lock_req { |
841 | struct smb2_hdr hdr; |
842 | __le16 StructureSize; /* Must be 48 */ |
843 | __le16 LockCount; |
844 | /* |
845 | * The least significant four bits are the index, the other 28 bits are |
846 | * the lock sequence number (0 to 64). See MS-SMB2 2.2.26 |
847 | */ |
848 | __le32 LockSequenceNumber; |
849 | __u64 PersistentFileId; |
850 | __u64 VolatileFileId; |
851 | /* Followed by at least one */ |
852 | union { |
853 | struct smb2_lock_element lock; |
854 | DECLARE_FLEX_ARRAY(struct smb2_lock_element, locks); |
855 | }; |
856 | } __packed; |
857 | |
858 | struct smb2_lock_rsp { |
859 | struct smb2_hdr hdr; |
860 | __le16 StructureSize; /* Must be 4 */ |
861 | __le16 Reserved; |
862 | } __packed; |
863 | |
864 | struct smb2_echo_req { |
865 | struct smb2_hdr hdr; |
866 | __le16 StructureSize; /* Must be 4 */ |
867 | __u16 Reserved; |
868 | } __packed; |
869 | |
870 | struct smb2_echo_rsp { |
871 | struct smb2_hdr hdr; |
872 | __le16 StructureSize; /* Must be 4 */ |
873 | __u16 Reserved; |
874 | } __packed; |
875 | |
876 | /* |
877 | * Valid FileInformation classes for query directory |
878 | * |
879 | * Note that these are a subset of the (file) QUERY_INFO levels defined |
880 | * later in this file (but since QUERY_DIRECTORY uses equivalent numbers |
881 | * we do not redefine them here) |
882 | * |
883 | * FileDirectoryInfomation 0x01 |
884 | * FileFullDirectoryInformation 0x02 |
885 | * FileIdFullDirectoryInformation 0x26 |
886 | * FileBothDirectoryInformation 0x03 |
887 | * FileIdBothDirectoryInformation 0x25 |
888 | * FileNamesInformation 0x0C |
889 | * FileIdExtdDirectoryInformation 0x3C |
890 | */ |
891 | |
892 | /* search (query_directory) Flags field */ |
893 | #define SMB2_RESTART_SCANS 0x01 |
894 | #define SMB2_RETURN_SINGLE_ENTRY 0x02 |
895 | #define SMB2_INDEX_SPECIFIED 0x04 |
896 | #define SMB2_REOPEN 0x10 |
897 | |
898 | struct smb2_query_directory_req { |
899 | struct smb2_hdr hdr; |
900 | __le16 StructureSize; /* Must be 33 */ |
901 | __u8 FileInformationClass; |
902 | __u8 Flags; |
903 | __le32 FileIndex; |
904 | __u64 PersistentFileId; |
905 | __u64 VolatileFileId; |
906 | __le16 FileNameOffset; |
907 | __le16 FileNameLength; |
908 | __le32 OutputBufferLength; |
909 | __u8 Buffer[]; |
910 | } __packed; |
911 | |
912 | struct smb2_query_directory_rsp { |
913 | struct smb2_hdr hdr; |
914 | __le16 StructureSize; /* Must be 9 */ |
915 | __le16 OutputBufferOffset; |
916 | __le32 OutputBufferLength; |
917 | __u8 Buffer[]; |
918 | } __packed; |
919 | |
920 | /* |
921 | * Maximum number of iovs we need for a set-info request. |
922 | * The largest one is rename/hardlink |
923 | * [0] : struct smb2_set_info_req + smb2_file_[rename|link]_info |
924 | * [1] : path |
925 | * [2] : compound padding |
926 | */ |
927 | #define SMB2_SET_INFO_IOV_SIZE 3 |
928 | |
929 | struct smb2_set_info_req { |
930 | struct smb2_hdr hdr; |
931 | __le16 StructureSize; /* Must be 33 */ |
932 | __u8 InfoType; |
933 | __u8 FileInfoClass; |
934 | __le32 BufferLength; |
935 | __le16 BufferOffset; |
936 | __u16 Reserved; |
937 | __le32 AdditionalInformation; |
938 | __u64 PersistentFileId; |
939 | __u64 VolatileFileId; |
940 | __u8 Buffer[]; |
941 | } __packed; |
942 | |
943 | struct smb2_set_info_rsp { |
944 | struct smb2_hdr hdr; |
945 | __le16 StructureSize; /* Must be 2 */ |
946 | } __packed; |
947 | |
948 | /* |
949 | * SMB2_NOTIFY See MS-SMB2 section 2.2.35 |
950 | */ |
951 | /* notify flags */ |
952 | #define SMB2_WATCH_TREE 0x0001 |
953 | |
954 | /* notify completion filter flags. See MS-FSCC 2.6 and MS-SMB2 2.2.35 */ |
955 | #define FILE_NOTIFY_CHANGE_FILE_NAME 0x00000001 |
956 | #define FILE_NOTIFY_CHANGE_DIR_NAME 0x00000002 |
957 | #define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x00000004 |
958 | #define FILE_NOTIFY_CHANGE_SIZE 0x00000008 |
959 | #define FILE_NOTIFY_CHANGE_LAST_WRITE 0x00000010 |
960 | #define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x00000020 |
961 | #define FILE_NOTIFY_CHANGE_CREATION 0x00000040 |
962 | #define FILE_NOTIFY_CHANGE_EA 0x00000080 |
963 | #define FILE_NOTIFY_CHANGE_SECURITY 0x00000100 |
964 | #define FILE_NOTIFY_CHANGE_STREAM_NAME 0x00000200 |
965 | #define FILE_NOTIFY_CHANGE_STREAM_SIZE 0x00000400 |
966 | #define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800 |
967 | |
968 | /* SMB2 Notify Action Flags */ |
969 | #define FILE_ACTION_ADDED 0x00000001 |
970 | #define FILE_ACTION_REMOVED 0x00000002 |
971 | #define FILE_ACTION_MODIFIED 0x00000003 |
972 | #define FILE_ACTION_RENAMED_OLD_NAME 0x00000004 |
973 | #define FILE_ACTION_RENAMED_NEW_NAME 0x00000005 |
974 | #define FILE_ACTION_ADDED_STREAM 0x00000006 |
975 | #define FILE_ACTION_REMOVED_STREAM 0x00000007 |
976 | #define FILE_ACTION_MODIFIED_STREAM 0x00000008 |
977 | #define FILE_ACTION_REMOVED_BY_DELETE 0x00000009 |
978 | |
979 | struct smb2_change_notify_req { |
980 | struct smb2_hdr hdr; |
981 | __le16 StructureSize; |
982 | __le16 Flags; |
983 | __le32 OutputBufferLength; |
984 | __u64 PersistentFileId; /* opaque endianness */ |
985 | __u64 VolatileFileId; /* opaque endianness */ |
986 | __le32 CompletionFilter; |
987 | __u32 Reserved; |
988 | } __packed; |
989 | |
990 | struct smb2_change_notify_rsp { |
991 | struct smb2_hdr hdr; |
992 | __le16 StructureSize; /* Must be 9 */ |
993 | __le16 OutputBufferOffset; |
994 | __le32 OutputBufferLength; |
995 | __u8 Buffer[]; /* array of file notify structs */ |
996 | } __packed; |
997 | |
998 | /* |
999 | * SMB2_SERVER_TO_CLIENT_NOTIFICATION: See MS-SMB2 section 2.2.44 |
1000 | */ |
1001 | |
1002 | #define SMB2_NOTIFY_SESSION_CLOSED 0x0000 |
1003 | |
1004 | struct smb2_server_client_notification { |
1005 | struct smb2_hdr hdr; |
1006 | __le16 StructureSize; |
1007 | __u16 Reserved; /* MBZ */ |
1008 | __le32 NotificationType; |
1009 | __u8 NotificationBuffer[4]; /* MBZ */ |
1010 | } __packed; |
1011 | |
1012 | /* |
1013 | * SMB2_CREATE See MS-SMB2 section 2.2.13 |
1014 | */ |
1015 | /* Oplock levels */ |
1016 | #define SMB2_OPLOCK_LEVEL_NONE 0x00 |
1017 | #define SMB2_OPLOCK_LEVEL_II 0x01 |
1018 | #define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08 |
1019 | #define SMB2_OPLOCK_LEVEL_BATCH 0x09 |
1020 | #define SMB2_OPLOCK_LEVEL_LEASE 0xFF |
1021 | /* Non-spec internal type */ |
1022 | #define SMB2_OPLOCK_LEVEL_NOCHANGE 0x99 |
1023 | |
1024 | /* Impersonation Levels. See MS-WPO section 9.7 and MSDN-IMPERS */ |
1025 | #define IL_ANONYMOUS cpu_to_le32(0x00000000) |
1026 | #define IL_IDENTIFICATION cpu_to_le32(0x00000001) |
1027 | #define IL_IMPERSONATION cpu_to_le32(0x00000002) |
1028 | #define IL_DELEGATE cpu_to_le32(0x00000003) |
1029 | |
1030 | /* File Attrubutes */ |
1031 | #define FILE_ATTRIBUTE_READONLY 0x00000001 |
1032 | #define FILE_ATTRIBUTE_HIDDEN 0x00000002 |
1033 | #define FILE_ATTRIBUTE_SYSTEM 0x00000004 |
1034 | #define FILE_ATTRIBUTE_DIRECTORY 0x00000010 |
1035 | #define FILE_ATTRIBUTE_ARCHIVE 0x00000020 |
1036 | #define FILE_ATTRIBUTE_NORMAL 0x00000080 |
1037 | #define FILE_ATTRIBUTE_TEMPORARY 0x00000100 |
1038 | #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200 |
1039 | #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400 |
1040 | #define FILE_ATTRIBUTE_COMPRESSED 0x00000800 |
1041 | #define FILE_ATTRIBUTE_OFFLINE 0x00001000 |
1042 | #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000 |
1043 | #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000 |
1044 | #define FILE_ATTRIBUTE_INTEGRITY_STREAM 0x00008000 |
1045 | #define FILE_ATTRIBUTE_NO_SCRUB_DATA 0x00020000 |
1046 | #define FILE_ATTRIBUTE__MASK 0x00007FB7 |
1047 | |
1048 | #define FILE_ATTRIBUTE_READONLY_LE cpu_to_le32(0x00000001) |
1049 | #define FILE_ATTRIBUTE_HIDDEN_LE cpu_to_le32(0x00000002) |
1050 | #define FILE_ATTRIBUTE_SYSTEM_LE cpu_to_le32(0x00000004) |
1051 | #define FILE_ATTRIBUTE_DIRECTORY_LE cpu_to_le32(0x00000010) |
1052 | #define FILE_ATTRIBUTE_ARCHIVE_LE cpu_to_le32(0x00000020) |
1053 | #define FILE_ATTRIBUTE_NORMAL_LE cpu_to_le32(0x00000080) |
1054 | #define FILE_ATTRIBUTE_TEMPORARY_LE cpu_to_le32(0x00000100) |
1055 | #define FILE_ATTRIBUTE_SPARSE_FILE_LE cpu_to_le32(0x00000200) |
1056 | #define FILE_ATTRIBUTE_REPARSE_POINT_LE cpu_to_le32(0x00000400) |
1057 | #define FILE_ATTRIBUTE_COMPRESSED_LE cpu_to_le32(0x00000800) |
1058 | #define FILE_ATTRIBUTE_OFFLINE_LE cpu_to_le32(0x00001000) |
1059 | #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED_LE cpu_to_le32(0x00002000) |
1060 | #define FILE_ATTRIBUTE_ENCRYPTED_LE cpu_to_le32(0x00004000) |
1061 | #define FILE_ATTRIBUTE_INTEGRITY_STREAM_LE cpu_to_le32(0x00008000) |
1062 | #define FILE_ATTRIBUTE_NO_SCRUB_DATA_LE cpu_to_le32(0x00020000) |
1063 | #define FILE_ATTRIBUTE_MASK_LE cpu_to_le32(0x00007FB7) |
1064 | |
1065 | /* Desired Access Flags */ |
1066 | #define FILE_READ_DATA_LE cpu_to_le32(0x00000001) |
1067 | #define FILE_LIST_DIRECTORY_LE cpu_to_le32(0x00000001) |
1068 | #define FILE_WRITE_DATA_LE cpu_to_le32(0x00000002) |
1069 | #define FILE_APPEND_DATA_LE cpu_to_le32(0x00000004) |
1070 | #define FILE_ADD_SUBDIRECTORY_LE cpu_to_le32(0x00000004) |
1071 | #define FILE_READ_EA_LE cpu_to_le32(0x00000008) |
1072 | #define FILE_WRITE_EA_LE cpu_to_le32(0x00000010) |
1073 | #define FILE_EXECUTE_LE cpu_to_le32(0x00000020) |
1074 | #define FILE_DELETE_CHILD_LE cpu_to_le32(0x00000040) |
1075 | #define FILE_READ_ATTRIBUTES_LE cpu_to_le32(0x00000080) |
1076 | #define FILE_WRITE_ATTRIBUTES_LE cpu_to_le32(0x00000100) |
1077 | #define FILE_DELETE_LE cpu_to_le32(0x00010000) |
1078 | #define FILE_READ_CONTROL_LE cpu_to_le32(0x00020000) |
1079 | #define FILE_WRITE_DAC_LE cpu_to_le32(0x00040000) |
1080 | #define FILE_WRITE_OWNER_LE cpu_to_le32(0x00080000) |
1081 | #define FILE_SYNCHRONIZE_LE cpu_to_le32(0x00100000) |
1082 | #define FILE_ACCESS_SYSTEM_SECURITY_LE cpu_to_le32(0x01000000) |
1083 | #define FILE_MAXIMAL_ACCESS_LE cpu_to_le32(0x02000000) |
1084 | #define FILE_GENERIC_ALL_LE cpu_to_le32(0x10000000) |
1085 | #define FILE_GENERIC_EXECUTE_LE cpu_to_le32(0x20000000) |
1086 | #define FILE_GENERIC_WRITE_LE cpu_to_le32(0x40000000) |
1087 | #define FILE_GENERIC_READ_LE cpu_to_le32(0x80000000) |
1088 | #define DESIRED_ACCESS_MASK cpu_to_le32(0xF21F01FF) |
1089 | |
1090 | |
1091 | #define FILE_READ_DESIRED_ACCESS_LE (FILE_READ_DATA_LE | \ |
1092 | FILE_READ_EA_LE | \ |
1093 | FILE_GENERIC_READ_LE) |
1094 | #define FILE_WRITE_DESIRE_ACCESS_LE (FILE_WRITE_DATA_LE | \ |
1095 | FILE_APPEND_DATA_LE | \ |
1096 | FILE_WRITE_EA_LE | \ |
1097 | FILE_WRITE_ATTRIBUTES_LE | \ |
1098 | FILE_GENERIC_WRITE_LE) |
1099 | |
1100 | /* ShareAccess Flags */ |
1101 | #define FILE_SHARE_READ_LE cpu_to_le32(0x00000001) |
1102 | #define FILE_SHARE_WRITE_LE cpu_to_le32(0x00000002) |
1103 | #define FILE_SHARE_DELETE_LE cpu_to_le32(0x00000004) |
1104 | #define FILE_SHARE_ALL_LE cpu_to_le32(0x00000007) |
1105 | |
1106 | /* CreateDisposition Flags */ |
1107 | #define FILE_SUPERSEDE_LE cpu_to_le32(0x00000000) |
1108 | #define FILE_OPEN_LE cpu_to_le32(0x00000001) |
1109 | #define FILE_CREATE_LE cpu_to_le32(0x00000002) |
1110 | #define FILE_OPEN_IF_LE cpu_to_le32(0x00000003) |
1111 | #define FILE_OVERWRITE_LE cpu_to_le32(0x00000004) |
1112 | #define FILE_OVERWRITE_IF_LE cpu_to_le32(0x00000005) |
1113 | #define FILE_CREATE_MASK_LE cpu_to_le32(0x00000007) |
1114 | |
1115 | #define FILE_READ_RIGHTS (FILE_READ_DATA | FILE_READ_EA \ |
1116 | | FILE_READ_ATTRIBUTES) |
1117 | #define FILE_WRITE_RIGHTS (FILE_WRITE_DATA | FILE_APPEND_DATA \ |
1118 | | FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES) |
1119 | #define FILE_EXEC_RIGHTS (FILE_EXECUTE) |
1120 | |
1121 | /* CreateOptions Flags */ |
1122 | #define FILE_DIRECTORY_FILE_LE cpu_to_le32(0x00000001) |
1123 | /* same as #define CREATE_NOT_FILE_LE cpu_to_le32(0x00000001) */ |
1124 | #define FILE_WRITE_THROUGH_LE cpu_to_le32(0x00000002) |
1125 | #define FILE_SEQUENTIAL_ONLY_LE cpu_to_le32(0x00000004) |
1126 | #define FILE_NO_INTERMEDIATE_BUFFERING_LE cpu_to_le32(0x00000008) |
1127 | /* FILE_SYNCHRONOUS_IO_ALERT_LE cpu_to_le32(0x00000010) should be zero, ignored */ |
1128 | /* FILE_SYNCHRONOUS_IO_NONALERT cpu_to_le32(0x00000020) should be zero, ignored */ |
1129 | #define FILE_NON_DIRECTORY_FILE_LE cpu_to_le32(0x00000040) |
1130 | #define FILE_COMPLETE_IF_OPLOCKED_LE cpu_to_le32(0x00000100) |
1131 | #define FILE_NO_EA_KNOWLEDGE_LE cpu_to_le32(0x00000200) |
1132 | /* FILE_OPEN_REMOTE_INSTANCE cpu_to_le32(0x00000400) should be zero, ignored */ |
1133 | #define FILE_RANDOM_ACCESS_LE cpu_to_le32(0x00000800) |
1134 | #define FILE_DELETE_ON_CLOSE_LE cpu_to_le32(0x00001000) /* MBZ */ |
1135 | #define FILE_OPEN_BY_FILE_ID_LE cpu_to_le32(0x00002000) |
1136 | #define FILE_OPEN_FOR_BACKUP_INTENT_LE cpu_to_le32(0x00004000) |
1137 | #define FILE_NO_COMPRESSION_LE cpu_to_le32(0x00008000) |
1138 | /* FILE_OPEN_REQUIRING_OPLOCK cpu_to_le32(0x00010000) should be zero, ignored */ |
1139 | /* FILE_DISALLOW_EXCLUSIVE cpu_to_le32(0x00020000) should be zero, ignored */ |
1140 | /* FILE_RESERVE_OPFILTER cpu_to_le32(0x00100000) MBZ */ |
1141 | #define FILE_OPEN_REPARSE_POINT_LE cpu_to_le32(0x00200000) |
1142 | #define FILE_OPEN_NO_RECALL_LE cpu_to_le32(0x00400000) |
1143 | /* #define FILE_OPEN_FOR_FREE_SPACE_QUERY cpu_to_le32(0x00800000) should be zero, ignored */ |
1144 | #define CREATE_OPTIONS_MASK_LE cpu_to_le32(0x00FFFFFF) |
1145 | |
1146 | #define FILE_READ_RIGHTS_LE (FILE_READ_DATA_LE | FILE_READ_EA_LE \ |
1147 | | FILE_READ_ATTRIBUTES_LE) |
1148 | #define FILE_WRITE_RIGHTS_LE (FILE_WRITE_DATA_LE | FILE_APPEND_DATA_LE \ |
1149 | | FILE_WRITE_EA_LE | FILE_WRITE_ATTRIBUTES_LE) |
1150 | #define FILE_EXEC_RIGHTS_LE (FILE_EXECUTE_LE) |
1151 | |
1152 | /* Create Context Values */ |
1153 | #define SMB2_CREATE_EA_BUFFER "ExtA" /* extended attributes */ |
1154 | #define SMB2_CREATE_SD_BUFFER "SecD" /* security descriptor */ |
1155 | #define SMB2_CREATE_DURABLE_HANDLE_REQUEST "DHnQ" |
1156 | #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT "DHnC" |
1157 | #define SMB2_CREATE_ALLOCATION_SIZE "AlSi" |
1158 | #define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST "MxAc" |
1159 | #define SMB2_CREATE_TIMEWARP_REQUEST "TWrp" |
1160 | #define SMB2_CREATE_QUERY_ON_DISK_ID "QFid" |
1161 | #define SMB2_CREATE_REQUEST_LEASE "RqLs" |
1162 | #define SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 "DH2Q" |
1163 | #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 "DH2C" |
1164 | #define SMB2_CREATE_TAG_POSIX "\x93\xAD\x25\x50\x9C\xB4\x11\xE7\xB4\x23\x83\xDE\x96\x8B\xCD\x7C" |
1165 | #define SMB2_CREATE_APP_INSTANCE_ID "\x45\xBC\xA6\x6A\xEF\xA7\xF7\x4A\x90\x08\xFA\x46\x2E\x14\x4D\x74" |
1166 | #define SMB2_CREATE_APP_INSTANCE_VERSION "\xB9\x82\xD0\xB7\x3B\x56\x07\x4F\xA0\x7B\x52\x4A\x81\x16\xA0\x10" |
1167 | #define SVHDX_OPEN_DEVICE_CONTEXT "\x9C\xCB\xCF\x9E\x04\xC1\xE6\x43\x98\x0E\x15\x8D\xA1\xF6\xEC\x83" |
1168 | #define SMB2_CREATE_TAG_AAPL "AAPL" |
1169 | |
1170 | /* Flag (SMB3 open response) values */ |
1171 | #define SMB2_CREATE_FLAG_REPARSEPOINT 0x01 |
1172 | |
1173 | struct create_context { |
1174 | __le32 Next; |
1175 | __le16 NameOffset; |
1176 | __le16 NameLength; |
1177 | __le16 Reserved; |
1178 | __le16 DataOffset; |
1179 | __le32 DataLength; |
1180 | __u8 Buffer[]; |
1181 | } __packed; |
1182 | |
1183 | struct smb2_create_req { |
1184 | struct smb2_hdr hdr; |
1185 | __le16 StructureSize; /* Must be 57 */ |
1186 | __u8 SecurityFlags; |
1187 | __u8 RequestedOplockLevel; |
1188 | __le32 ImpersonationLevel; |
1189 | __le64 SmbCreateFlags; |
1190 | __le64 Reserved; |
1191 | __le32 DesiredAccess; |
1192 | __le32 FileAttributes; |
1193 | __le32 ShareAccess; |
1194 | __le32 CreateDisposition; |
1195 | __le32 CreateOptions; |
1196 | __le16 NameOffset; |
1197 | __le16 NameLength; |
1198 | __le32 CreateContextsOffset; |
1199 | __le32 CreateContextsLength; |
1200 | __u8 Buffer[]; |
1201 | } __packed; |
1202 | |
1203 | struct smb2_create_rsp { |
1204 | struct smb2_hdr hdr; |
1205 | __le16 StructureSize; /* Must be 89 */ |
1206 | __u8 OplockLevel; |
1207 | __u8 Flags; /* 0x01 if reparse point */ |
1208 | __le32 CreateAction; |
1209 | __le64 CreationTime; |
1210 | __le64 LastAccessTime; |
1211 | __le64 LastWriteTime; |
1212 | __le64 ChangeTime; |
1213 | __le64 AllocationSize; |
1214 | __le64 EndofFile; |
1215 | __le32 FileAttributes; |
1216 | __le32 Reserved2; |
1217 | __u64 PersistentFileId; |
1218 | __u64 VolatileFileId; |
1219 | __le32 CreateContextsOffset; |
1220 | __le32 CreateContextsLength; |
1221 | __u8 Buffer[]; |
1222 | } __packed; |
1223 | |
1224 | struct create_posix { |
1225 | struct create_context ccontext; |
1226 | __u8 Name[16]; |
1227 | __le32 Mode; |
1228 | __u32 Reserved; |
1229 | } __packed; |
1230 | |
1231 | /* See MS-SMB2 2.2.13.2.3 and MS-SMB2 2.2.13.2.4 */ |
1232 | struct create_durable { |
1233 | struct create_context ccontext; |
1234 | __u8 Name[8]; |
1235 | union { |
1236 | __u8 Reserved[16]; |
1237 | struct { |
1238 | __u64 PersistentFileId; |
1239 | __u64 VolatileFileId; |
1240 | } Fid; |
1241 | } Data; |
1242 | } __packed; |
1243 | |
1244 | /* See MS-SMB2 2.2.13.2.5 */ |
1245 | struct create_mxac_req { |
1246 | struct create_context ccontext; |
1247 | __u8 Name[8]; |
1248 | __le64 Timestamp; |
1249 | } __packed; |
1250 | |
1251 | /* See MS-SMB2 2.2.14.2.5 */ |
1252 | struct create_mxac_rsp { |
1253 | struct create_context ccontext; |
1254 | __u8 Name[8]; |
1255 | __le32 QueryStatus; |
1256 | __le32 MaximalAccess; |
1257 | } __packed; |
1258 | |
1259 | #define SMB2_LEASE_NONE_LE cpu_to_le32(0x00) |
1260 | #define SMB2_LEASE_READ_CACHING_LE cpu_to_le32(0x01) |
1261 | #define SMB2_LEASE_HANDLE_CACHING_LE cpu_to_le32(0x02) |
1262 | #define SMB2_LEASE_WRITE_CACHING_LE cpu_to_le32(0x04) |
1263 | |
1264 | #define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE cpu_to_le32(0x02) |
1265 | #define SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET_LE cpu_to_le32(0x04) |
1266 | |
1267 | #define SMB2_LEASE_KEY_SIZE 16 |
1268 | |
1269 | /* See MS-SMB2 2.2.13.2.8 */ |
1270 | struct lease_context { |
1271 | __u8 LeaseKey[SMB2_LEASE_KEY_SIZE]; |
1272 | __le32 LeaseState; |
1273 | __le32 LeaseFlags; |
1274 | __le64 LeaseDuration; |
1275 | } __packed; |
1276 | |
1277 | /* See MS-SMB2 2.2.13.2.10 */ |
1278 | struct lease_context_v2 { |
1279 | __u8 LeaseKey[SMB2_LEASE_KEY_SIZE]; |
1280 | __le32 LeaseState; |
1281 | __le32 LeaseFlags; |
1282 | __le64 LeaseDuration; |
1283 | __u8 ParentLeaseKey[SMB2_LEASE_KEY_SIZE]; |
1284 | __le16 Epoch; |
1285 | __le16 Reserved; |
1286 | } __packed; |
1287 | |
1288 | struct create_lease { |
1289 | struct create_context ccontext; |
1290 | __u8 Name[8]; |
1291 | struct lease_context lcontext; |
1292 | } __packed; |
1293 | |
1294 | struct create_lease_v2 { |
1295 | struct create_context ccontext; |
1296 | __u8 Name[8]; |
1297 | struct lease_context_v2 lcontext; |
1298 | __u8 Pad[4]; |
1299 | } __packed; |
1300 | |
1301 | /* See MS-SMB2 2.2.14.2.9 */ |
1302 | struct create_disk_id_rsp { |
1303 | struct create_context ccontext; |
1304 | __u8 Name[8]; |
1305 | __le64 DiskFileId; |
1306 | __le64 VolumeId; |
1307 | __u8 Reserved[16]; |
1308 | } __packed; |
1309 | |
1310 | /* See MS-SMB2 2.2.13.2.13 */ |
1311 | struct create_app_inst_id { |
1312 | struct create_context ccontext; |
1313 | __u8 Name[16]; |
1314 | __le32 StructureSize; /* Must be 20 */ |
1315 | __u16 Reserved; |
1316 | __u8 AppInstanceId[16]; |
1317 | } __packed; |
1318 | |
1319 | /* See MS-SMB2 2.2.13.2.15 */ |
1320 | struct create_app_inst_id_vers { |
1321 | struct create_context ccontext; |
1322 | __u8 Name[16]; |
1323 | __le32 StructureSize; /* Must be 24 */ |
1324 | __u16 Reserved; |
1325 | __u32 Padding; |
1326 | __le64 AppInstanceVersionHigh; |
1327 | __le64 AppInstanceVersionLow; |
1328 | } __packed; |
1329 | |
1330 | /* See MS-SMB2 2.2.31 and 2.2.32 */ |
1331 | struct smb2_ioctl_req { |
1332 | struct smb2_hdr hdr; |
1333 | __le16 StructureSize; /* Must be 57 */ |
1334 | __le16 Reserved; /* offset from start of SMB2 header to write data */ |
1335 | __le32 CtlCode; |
1336 | __u64 PersistentFileId; |
1337 | __u64 VolatileFileId; |
1338 | __le32 InputOffset; /* Reserved MBZ */ |
1339 | __le32 InputCount; |
1340 | __le32 MaxInputResponse; |
1341 | __le32 OutputOffset; |
1342 | __le32 OutputCount; |
1343 | __le32 MaxOutputResponse; |
1344 | __le32 Flags; |
1345 | __le32 Reserved2; |
1346 | __u8 Buffer[]; |
1347 | } __packed; |
1348 | |
1349 | struct smb2_ioctl_rsp { |
1350 | struct smb2_hdr hdr; |
1351 | __le16 StructureSize; /* Must be 49 */ |
1352 | __le16 Reserved; |
1353 | __le32 CtlCode; |
1354 | __u64 PersistentFileId; |
1355 | __u64 VolatileFileId; |
1356 | __le32 InputOffset; /* Reserved MBZ */ |
1357 | __le32 InputCount; |
1358 | __le32 OutputOffset; |
1359 | __le32 OutputCount; |
1360 | __le32 Flags; |
1361 | __le32 Reserved2; |
1362 | __u8 Buffer[]; |
1363 | } __packed; |
1364 | |
1365 | /* this goes in the ioctl buffer when doing FSCTL_SET_ZERO_DATA */ |
1366 | struct file_zero_data_information { |
1367 | __le64 FileOffset; |
1368 | __le64 BeyondFinalZero; |
1369 | } __packed; |
1370 | |
1371 | /* See MS-FSCC 2.3.7 */ |
1372 | struct duplicate_extents_to_file { |
1373 | __u64 PersistentFileHandle; /* source file handle, opaque endianness */ |
1374 | __u64 VolatileFileHandle; |
1375 | __le64 SourceFileOffset; |
1376 | __le64 TargetFileOffset; |
1377 | __le64 ByteCount; /* Bytes to be copied */ |
1378 | } __packed; |
1379 | |
1380 | /* See MS-FSCC 2.3.8 */ |
1381 | #define DUPLICATE_EXTENTS_DATA_EX_SOURCE_ATOMIC 0x00000001 |
1382 | struct duplicate_extents_to_file_ex { |
1383 | __u64 PersistentFileHandle; /* source file handle, opaque endianness */ |
1384 | __u64 VolatileFileHandle; |
1385 | __le64 SourceFileOffset; |
1386 | __le64 TargetFileOffset; |
1387 | __le64 ByteCount; /* Bytes to be copied */ |
1388 | __le32 Flags; |
1389 | __le32 Reserved; |
1390 | } __packed; |
1391 | |
1392 | |
1393 | /* See MS-FSCC 2.3.20 */ |
1394 | struct fsctl_get_integrity_information_rsp { |
1395 | __le16 ChecksumAlgorithm; |
1396 | __le16 Reserved; |
1397 | __le32 Flags; |
1398 | __le32 ChecksumChunkSizeInBytes; |
1399 | __le32 ClusterSizeInBytes; |
1400 | } __packed; |
1401 | |
1402 | /* See MS-FSCC 2.3.55 */ |
1403 | struct fsctl_query_file_regions_req { |
1404 | __le64 FileOffset; |
1405 | __le64 Length; |
1406 | __le32 DesiredUsage; |
1407 | __le32 Reserved; |
1408 | } __packed; |
1409 | |
1410 | /* DesiredUsage flags see MS-FSCC 2.3.56.1 */ |
1411 | #define FILE_USAGE_INVALID_RANGE 0x00000000 |
1412 | #define FILE_USAGE_VALID_CACHED_DATA 0x00000001 |
1413 | #define FILE_USAGE_NONCACHED_DATA 0x00000002 |
1414 | |
1415 | struct file_region_info { |
1416 | __le64 FileOffset; |
1417 | __le64 Length; |
1418 | __le32 DesiredUsage; |
1419 | __le32 Reserved; |
1420 | } __packed; |
1421 | |
1422 | /* See MS-FSCC 2.3.56 */ |
1423 | struct fsctl_query_file_region_rsp { |
1424 | __le32 Flags; |
1425 | __le32 TotalRegionEntryCount; |
1426 | __le32 RegionEntryCount; |
1427 | __u32 Reserved; |
1428 | struct file_region_info Regions[]; |
1429 | } __packed; |
1430 | |
1431 | /* See MS-FSCC 2.3.58 */ |
1432 | struct fsctl_query_on_disk_vol_info_rsp { |
1433 | __le64 DirectoryCount; |
1434 | __le64 FileCount; |
1435 | __le16 FsFormatMajVersion; |
1436 | __le16 FsFormatMinVersion; |
1437 | __u8 FsFormatName[24]; |
1438 | __le64 FormatTime; |
1439 | __le64 LastUpdateTime; |
1440 | __u8 CopyrightInfo[68]; |
1441 | __u8 AbstractInfo[68]; |
1442 | __u8 FormatImplInfo[68]; |
1443 | __u8 LastModifyImplInfo[68]; |
1444 | } __packed; |
1445 | |
1446 | /* See MS-FSCC 2.3.73 */ |
1447 | struct fsctl_set_integrity_information_req { |
1448 | __le16 ChecksumAlgorithm; |
1449 | __le16 Reserved; |
1450 | __le32 Flags; |
1451 | } __packed; |
1452 | |
1453 | /* See MS-FSCC 2.3.75 */ |
1454 | struct fsctl_set_integrity_info_ex_req { |
1455 | __u8 EnableIntegrity; |
1456 | __u8 KeepState; |
1457 | __u16 Reserved; |
1458 | __le32 Flags; |
1459 | __u8 Version; |
1460 | __u8 Reserved2[7]; |
1461 | } __packed; |
1462 | |
1463 | /* Integrity ChecksumAlgorithm choices for above */ |
1464 | #define CHECKSUM_TYPE_NONE 0x0000 |
1465 | #define CHECKSUM_TYPE_CRC64 0x0002 |
1466 | #define CHECKSUM_TYPE_UNCHANGED 0xFFFF /* set only */ |
1467 | |
1468 | /* Integrity flags for above */ |
1469 | #define FSCTL_INTEGRITY_FLAG_CHECKSUM_ENFORCEMENT_OFF 0x00000001 |
1470 | |
1471 | /* Reparse structures - see MS-FSCC 2.1.2 */ |
1472 | |
1473 | /* struct fsctl_reparse_info_req is empty, only response structs (see below) */ |
1474 | struct reparse_data_buffer { |
1475 | __le32 ReparseTag; |
1476 | __le16 ReparseDataLength; |
1477 | __u16 Reserved; |
1478 | __u8 DataBuffer[]; /* Variable Length */ |
1479 | } __packed; |
1480 | |
1481 | struct reparse_guid_data_buffer { |
1482 | __le32 ReparseTag; |
1483 | __le16 ReparseDataLength; |
1484 | __u16 Reserved; |
1485 | __u8 ReparseGuid[16]; |
1486 | __u8 DataBuffer[]; /* Variable Length */ |
1487 | } __packed; |
1488 | |
1489 | struct reparse_mount_point_data_buffer { |
1490 | __le32 ReparseTag; |
1491 | __le16 ReparseDataLength; |
1492 | __u16 Reserved; |
1493 | __le16 SubstituteNameOffset; |
1494 | __le16 SubstituteNameLength; |
1495 | __le16 PrintNameOffset; |
1496 | __le16 PrintNameLength; |
1497 | __u8 PathBuffer[]; /* Variable Length */ |
1498 | } __packed; |
1499 | |
1500 | #define SYMLINK_FLAG_RELATIVE 0x00000001 |
1501 | |
1502 | struct reparse_symlink_data_buffer { |
1503 | __le32 ReparseTag; |
1504 | __le16 ReparseDataLength; |
1505 | __u16 Reserved; |
1506 | __le16 SubstituteNameOffset; |
1507 | __le16 SubstituteNameLength; |
1508 | __le16 PrintNameOffset; |
1509 | __le16 PrintNameLength; |
1510 | __le32 Flags; |
1511 | __u8 PathBuffer[]; /* Variable Length */ |
1512 | } __packed; |
1513 | |
1514 | /* See MS-FSCC 2.1.2.6 and cifspdu.h for struct reparse_posix_data */ |
1515 | |
1516 | struct validate_negotiate_info_req { |
1517 | __le32 Capabilities; |
1518 | __u8 Guid[SMB2_CLIENT_GUID_SIZE]; |
1519 | __le16 SecurityMode; |
1520 | __le16 DialectCount; |
1521 | __le16 Dialects[4]; /* BB expand this if autonegotiate > 4 dialects */ |
1522 | } __packed; |
1523 | |
1524 | struct validate_negotiate_info_rsp { |
1525 | __le32 Capabilities; |
1526 | __u8 Guid[SMB2_CLIENT_GUID_SIZE]; |
1527 | __le16 SecurityMode; |
1528 | __le16 Dialect; /* Dialect in use for the connection */ |
1529 | } __packed; |
1530 | |
1531 | |
1532 | /* Possible InfoType values */ |
1533 | #define SMB2_O_INFO_FILE 0x01 |
1534 | #define SMB2_O_INFO_FILESYSTEM 0x02 |
1535 | #define SMB2_O_INFO_SECURITY 0x03 |
1536 | #define SMB2_O_INFO_QUOTA 0x04 |
1537 | |
1538 | /* SMB2 Query Info see MS-SMB2 (2.2.37) or MS-DTYP */ |
1539 | |
1540 | /* List of QUERY INFO levels (those also valid for QUERY_DIR are noted below */ |
1541 | #define FILE_DIRECTORY_INFORMATION 1 /* also for QUERY_DIR */ |
1542 | #define FILE_FULL_DIRECTORY_INFORMATION 2 /* also for QUERY_DIR */ |
1543 | #define FILE_BOTH_DIRECTORY_INFORMATION 3 /* also for QUERY_DIR */ |
1544 | #define FILE_BASIC_INFORMATION 4 |
1545 | #define FILE_STANDARD_INFORMATION 5 |
1546 | #define FILE_INTERNAL_INFORMATION 6 |
1547 | #define FILE_EA_INFORMATION 7 |
1548 | #define FILE_ACCESS_INFORMATION 8 |
1549 | #define FILE_NAME_INFORMATION 9 |
1550 | #define FILE_RENAME_INFORMATION 10 |
1551 | #define FILE_LINK_INFORMATION 11 |
1552 | #define FILE_NAMES_INFORMATION 12 /* also for QUERY_DIR */ |
1553 | #define FILE_DISPOSITION_INFORMATION 13 |
1554 | #define FILE_POSITION_INFORMATION 14 |
1555 | #define FILE_FULL_EA_INFORMATION 15 |
1556 | #define FILE_MODE_INFORMATION 16 |
1557 | #define FILE_ALIGNMENT_INFORMATION 17 |
1558 | #define FILE_ALL_INFORMATION 18 |
1559 | #define FILE_ALLOCATION_INFORMATION 19 |
1560 | #define FILE_END_OF_FILE_INFORMATION 20 |
1561 | #define FILE_ALTERNATE_NAME_INFORMATION 21 |
1562 | #define FILE_STREAM_INFORMATION 22 |
1563 | #define FILE_PIPE_INFORMATION 23 |
1564 | #define FILE_PIPE_LOCAL_INFORMATION 24 |
1565 | #define FILE_PIPE_REMOTE_INFORMATION 25 |
1566 | #define FILE_MAILSLOT_QUERY_INFORMATION 26 |
1567 | #define FILE_MAILSLOT_SET_INFORMATION 27 |
1568 | #define FILE_COMPRESSION_INFORMATION 28 |
1569 | #define FILE_OBJECT_ID_INFORMATION 29 |
1570 | /* Number 30 not defined in documents */ |
1571 | #define FILE_MOVE_CLUSTER_INFORMATION 31 |
1572 | #define FILE_QUOTA_INFORMATION 32 |
1573 | #define FILE_REPARSE_POINT_INFORMATION 33 |
1574 | #define FILE_NETWORK_OPEN_INFORMATION 34 |
1575 | #define FILE_ATTRIBUTE_TAG_INFORMATION 35 |
1576 | #define FILE_TRACKING_INFORMATION 36 |
1577 | #define FILEID_BOTH_DIRECTORY_INFORMATION 37 /* also for QUERY_DIR */ |
1578 | #define FILEID_FULL_DIRECTORY_INFORMATION 38 /* also for QUERY_DIR */ |
1579 | #define FILE_VALID_DATA_LENGTH_INFORMATION 39 |
1580 | #define FILE_SHORT_NAME_INFORMATION 40 |
1581 | #define FILE_SFIO_RESERVE_INFORMATION 44 |
1582 | #define FILE_SFIO_VOLUME_INFORMATION 45 |
1583 | #define FILE_HARD_LINK_INFORMATION 46 |
1584 | #define FILE_NORMALIZED_NAME_INFORMATION 48 |
1585 | #define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50 |
1586 | #define FILE_STANDARD_LINK_INFORMATION 54 |
1587 | #define FILE_ID_INFORMATION 59 |
1588 | #define FILE_ID_EXTD_DIRECTORY_INFORMATION 60 /* also for QUERY_DIR */ |
1589 | /* Used for Query Info and Find File POSIX Info for SMB3.1.1 and SMB1 */ |
1590 | #define SMB_FIND_FILE_POSIX_INFO 0x064 |
1591 | |
1592 | /* Security info type additionalinfo flags. */ |
1593 | #define OWNER_SECINFO 0x00000001 |
1594 | #define GROUP_SECINFO 0x00000002 |
1595 | #define DACL_SECINFO 0x00000004 |
1596 | #define SACL_SECINFO 0x00000008 |
1597 | #define LABEL_SECINFO 0x00000010 |
1598 | #define ATTRIBUTE_SECINFO 0x00000020 |
1599 | #define SCOPE_SECINFO 0x00000040 |
1600 | #define BACKUP_SECINFO 0x00010000 |
1601 | #define UNPROTECTED_SACL_SECINFO 0x10000000 |
1602 | #define UNPROTECTED_DACL_SECINFO 0x20000000 |
1603 | #define PROTECTED_SACL_SECINFO 0x40000000 |
1604 | #define PROTECTED_DACL_SECINFO 0x80000000 |
1605 | |
1606 | /* Flags used for FileFullEAinfo */ |
1607 | #define SL_RESTART_SCAN 0x00000001 |
1608 | #define SL_RETURN_SINGLE_ENTRY 0x00000002 |
1609 | #define SL_INDEX_SPECIFIED 0x00000004 |
1610 | |
1611 | struct smb2_query_info_req { |
1612 | struct smb2_hdr hdr; |
1613 | __le16 StructureSize; /* Must be 41 */ |
1614 | __u8 InfoType; |
1615 | __u8 FileInfoClass; |
1616 | __le32 OutputBufferLength; |
1617 | __le16 InputBufferOffset; |
1618 | __u16 Reserved; |
1619 | __le32 InputBufferLength; |
1620 | __le32 AdditionalInformation; |
1621 | __le32 Flags; |
1622 | __u64 PersistentFileId; |
1623 | __u64 VolatileFileId; |
1624 | __u8 Buffer[]; |
1625 | } __packed; |
1626 | |
1627 | struct smb2_query_info_rsp { |
1628 | struct smb2_hdr hdr; |
1629 | __le16 StructureSize; /* Must be 9 */ |
1630 | __le16 OutputBufferOffset; |
1631 | __le32 OutputBufferLength; |
1632 | __u8 Buffer[]; |
1633 | } __packed; |
1634 | |
1635 | /* |
1636 | * PDU query infolevel structure definitions |
1637 | */ |
1638 | |
1639 | /* See MS-FSCC 2.3.52 */ |
1640 | struct file_allocated_range_buffer { |
1641 | __le64 file_offset; |
1642 | __le64 length; |
1643 | } __packed; |
1644 | |
1645 | struct smb2_file_internal_info { |
1646 | __le64 IndexNumber; |
1647 | } __packed; /* level 6 Query */ |
1648 | |
1649 | struct smb2_file_rename_info { /* encoding of request for level 10 */ |
1650 | __u8 ReplaceIfExists; /* 1 = replace existing target with new */ |
1651 | /* 0 = fail if target already exists */ |
1652 | __u8 Reserved[7]; |
1653 | __u64 RootDirectory; /* MBZ for network operations (why says spec?) */ |
1654 | __le32 FileNameLength; |
1655 | char FileName[]; /* New name to be assigned */ |
1656 | /* padding - overall struct size must be >= 24 so filename + pad >= 6 */ |
1657 | } __packed; /* level 10 Set */ |
1658 | |
1659 | struct smb2_file_link_info { /* encoding of request for level 11 */ |
1660 | __u8 ReplaceIfExists; /* 1 = replace existing link with new */ |
1661 | /* 0 = fail if link already exists */ |
1662 | __u8 Reserved[7]; |
1663 | __u64 RootDirectory; /* MBZ for network operations (why says spec?) */ |
1664 | __le32 FileNameLength; |
1665 | char FileName[]; /* Name to be assigned to new link */ |
1666 | } __packed; /* level 11 Set */ |
1667 | |
1668 | /* |
1669 | * This level 18, although with struct with same name is different from cifs |
1670 | * level 0x107. Level 0x107 has an extra u64 between AccessFlags and |
1671 | * CurrentByteOffset. |
1672 | */ |
1673 | struct smb2_file_all_info { /* data block encoding of response to level 18 */ |
1674 | __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */ |
1675 | __le64 LastAccessTime; |
1676 | __le64 LastWriteTime; |
1677 | __le64 ChangeTime; |
1678 | __le32 Attributes; |
1679 | __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */ |
1680 | __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */ |
1681 | __le64 EndOfFile; /* size ie offset to first free byte in file */ |
1682 | __le32 NumberOfLinks; /* hard links */ |
1683 | __u8 DeletePending; |
1684 | __u8 Directory; |
1685 | __u16 Pad2; /* End of FILE_STANDARD_INFO equivalent */ |
1686 | __le64 IndexNumber; |
1687 | __le32 EASize; |
1688 | __le32 AccessFlags; |
1689 | __le64 CurrentByteOffset; |
1690 | __le32 Mode; |
1691 | __le32 AlignmentRequirement; |
1692 | __le32 FileNameLength; |
1693 | union { |
1694 | char __pad; /* Legacy structure padding */ |
1695 | DECLARE_FLEX_ARRAY(char, FileName); |
1696 | }; |
1697 | } __packed; /* level 18 Query */ |
1698 | |
1699 | struct smb2_file_eof_info { /* encoding of request for level 10 */ |
1700 | __le64 EndOfFile; /* new end of file value */ |
1701 | } __packed; /* level 20 Set */ |
1702 | |
1703 | /* Level 100 query info */ |
1704 | struct smb311_posix_qinfo { |
1705 | __le64 CreationTime; |
1706 | __le64 LastAccessTime; |
1707 | __le64 LastWriteTime; |
1708 | __le64 ChangeTime; |
1709 | __le64 EndOfFile; |
1710 | __le64 AllocationSize; |
1711 | __le32 DosAttributes; |
1712 | __le64 Inode; |
1713 | __le32 DeviceId; |
1714 | __le32 Zero; |
1715 | /* beginning of POSIX Create Context Response */ |
1716 | __le32 HardLinks; |
1717 | __le32 ReparseTag; |
1718 | __le32 Mode; |
1719 | u8 Sids[]; |
1720 | /* |
1721 | * var sized owner SID |
1722 | * var sized group SID |
1723 | * le32 filenamelength |
1724 | * u8 filename[] |
1725 | */ |
1726 | } __packed; |
1727 | |
1728 | /* File System Information Classes */ |
1729 | #define FS_VOLUME_INFORMATION 1 /* Query */ |
1730 | #define FS_LABEL_INFORMATION 2 /* Set */ |
1731 | #define FS_SIZE_INFORMATION 3 /* Query */ |
1732 | #define FS_DEVICE_INFORMATION 4 /* Query */ |
1733 | #define FS_ATTRIBUTE_INFORMATION 5 /* Query */ |
1734 | #define FS_CONTROL_INFORMATION 6 /* Query, Set */ |
1735 | #define FS_FULL_SIZE_INFORMATION 7 /* Query */ |
1736 | #define FS_OBJECT_ID_INFORMATION 8 /* Query, Set */ |
1737 | #define FS_DRIVER_PATH_INFORMATION 9 /* Query */ |
1738 | #define FS_SECTOR_SIZE_INFORMATION 11 /* SMB3 or later. Query */ |
1739 | #define FS_POSIX_INFORMATION 100 /* SMB3.1.1 POSIX. Query */ |
1740 | |
1741 | struct smb2_fs_full_size_info { |
1742 | __le64 TotalAllocationUnits; |
1743 | __le64 CallerAvailableAllocationUnits; |
1744 | __le64 ActualAvailableAllocationUnits; |
1745 | __le32 SectorsPerAllocationUnit; |
1746 | __le32 BytesPerSector; |
1747 | } __packed; |
1748 | |
1749 | #define SSINFO_FLAGS_ALIGNED_DEVICE 0x00000001 |
1750 | #define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE 0x00000002 |
1751 | #define SSINFO_FLAGS_NO_SEEK_PENALTY 0x00000004 |
1752 | #define SSINFO_FLAGS_TRIM_ENABLED 0x00000008 |
1753 | |
1754 | /* sector size info struct */ |
1755 | struct smb3_fs_ss_info { |
1756 | __le32 LogicalBytesPerSector; |
1757 | __le32 PhysicalBytesPerSectorForAtomicity; |
1758 | __le32 PhysicalBytesPerSectorForPerf; |
1759 | __le32 FSEffPhysicalBytesPerSectorForAtomicity; |
1760 | __le32 Flags; |
1761 | __le32 ByteOffsetForSectorAlignment; |
1762 | __le32 ByteOffsetForPartitionAlignment; |
1763 | } __packed; |
1764 | |
1765 | /* File System Control Information */ |
1766 | struct smb2_fs_control_info { |
1767 | __le64 FreeSpaceStartFiltering; |
1768 | __le64 FreeSpaceThreshold; |
1769 | __le64 FreeSpaceStopFiltering; |
1770 | __le64 DefaultQuotaThreshold; |
1771 | __le64 DefaultQuotaLimit; |
1772 | __le32 FileSystemControlFlags; |
1773 | __le32 Padding; |
1774 | } __packed; |
1775 | |
1776 | /* volume info struct - see MS-FSCC 2.5.9 */ |
1777 | #define MAX_VOL_LABEL_LEN 32 |
1778 | struct smb3_fs_vol_info { |
1779 | __le64 VolumeCreationTime; |
1780 | __u32 VolumeSerialNumber; |
1781 | __le32 VolumeLabelLength; /* includes trailing null */ |
1782 | __u8 SupportsObjects; /* True if eg like NTFS, supports objects */ |
1783 | __u8 Reserved; |
1784 | __u8 VolumeLabel[]; /* variable len */ |
1785 | } __packed; |
1786 | |
1787 | /* See MS-SMB2 2.2.23 through 2.2.25 */ |
1788 | struct smb2_oplock_break { |
1789 | struct smb2_hdr hdr; |
1790 | __le16 StructureSize; /* Must be 24 */ |
1791 | __u8 OplockLevel; |
1792 | __u8 Reserved; |
1793 | __le32 Reserved2; |
1794 | __u64 PersistentFid; |
1795 | __u64 VolatileFid; |
1796 | } __packed; |
1797 | |
1798 | #define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01) |
1799 | |
1800 | struct smb2_lease_break { |
1801 | struct smb2_hdr hdr; |
1802 | __le16 StructureSize; /* Must be 44 */ |
1803 | __le16 Epoch; |
1804 | __le32 Flags; |
1805 | __u8 LeaseKey[16]; |
1806 | __le32 CurrentLeaseState; |
1807 | __le32 NewLeaseState; |
1808 | __le32 BreakReason; |
1809 | __le32 AccessMaskHint; |
1810 | __le32 ShareMaskHint; |
1811 | } __packed; |
1812 | |
1813 | struct smb2_lease_ack { |
1814 | struct smb2_hdr hdr; |
1815 | __le16 StructureSize; /* Must be 36 */ |
1816 | __le16 Reserved; |
1817 | __le32 Flags; |
1818 | __u8 LeaseKey[16]; |
1819 | __le32 LeaseState; |
1820 | __le64 LeaseDuration; |
1821 | } __packed; |
1822 | |
1823 | #define OP_BREAK_STRUCT_SIZE_20 24 |
1824 | #define OP_BREAK_STRUCT_SIZE_21 36 |
1825 | #endif /* _COMMON_SMB2PDU_H */ |
1826 | |