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