Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | /* |
| 3 | * Copyright (C) 2016 Namjae Jeon <linkinjeon@kernel.org> |
| 4 | * Copyright (C) 2018 Samsung Electronics Co., Ltd. |
| 5 | */ |
| 6 | |
| 7 | #ifndef _SMB2PDU_H |
| 8 | #define _SMB2PDU_H |
| 9 | |
| 10 | #include "ntlmssp.h" |
| 11 | #include "smbacl.h" |
| 12 | |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 13 | /*Create Action Flags*/ |
| 14 | #define FILE_SUPERSEDED 0x00000000 |
| 15 | #define FILE_OPENED 0x00000001 |
| 16 | #define FILE_CREATED 0x00000002 |
| 17 | #define FILE_OVERWRITTEN 0x00000003 |
| 18 | |
| 19 | /* |
| 20 | * Size of the session key (crypto key encrypted with the password |
| 21 | */ |
| 22 | #define SMB2_NTLMV2_SESSKEY_SIZE 16 |
| 23 | #define SMB2_SIGNATURE_SIZE 16 |
| 24 | #define SMB2_HMACSHA256_SIZE 32 |
| 25 | #define SMB2_CMACAES_SIZE 16 |
Namjae Jeon | 5a0ca77 | 2021-05-06 11:43:37 +0900 | [diff] [blame] | 26 | #define SMB3_GCM128_CRYPTKEY_SIZE 16 |
| 27 | #define SMB3_GCM256_CRYPTKEY_SIZE 32 |
| 28 | |
| 29 | /* |
| 30 | * Size of the smb3 encryption/decryption keys |
| 31 | */ |
| 32 | #define SMB3_ENC_DEC_KEY_SIZE 32 |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 33 | |
| 34 | /* |
| 35 | * Size of the smb3 signing key |
| 36 | */ |
| 37 | #define SMB3_SIGN_KEY_SIZE 16 |
| 38 | |
| 39 | #define CIFS_CLIENT_CHALLENGE_SIZE 8 |
| 40 | #define SMB_SERVER_CHALLENGE_SIZE 8 |
| 41 | |
| 42 | /* SMB2 Max Credits */ |
| 43 | #define SMB2_MAX_CREDITS 8192 |
| 44 | |
| 45 | #define SMB2_CLIENT_GUID_SIZE 16 |
| 46 | #define SMB2_CREATE_GUID_SIZE 16 |
| 47 | |
| 48 | /* Maximum buffer size value we can send with 1 credit */ |
| 49 | #define SMB2_MAX_BUFFER_SIZE 65536 |
| 50 | |
| 51 | #define NUMBER_OF_SMB2_COMMANDS 0x0013 |
| 52 | |
| 53 | /* BB FIXME - analyze following length BB */ |
| 54 | #define MAX_SMB2_HDR_SIZE 0x78 /* 4 len + 64 hdr + (2*24 wct) + 2 bct + 2 pad */ |
| 55 | |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 56 | #define SMB21_DEFAULT_IOSIZE (1024 * 1024) |
| 57 | #define SMB3_DEFAULT_IOSIZE (4 * 1024 * 1024) |
| 58 | #define SMB3_DEFAULT_TRANS_SIZE (1024 * 1024) |
Namjae Jeon | 4bc5947 | 2021-10-15 17:14:02 +0900 | [diff] [blame] | 59 | #define SMB3_MIN_IOSIZE (64 * 1024) |
| 60 | #define SMB3_MAX_IOSIZE (8 * 1024 * 1024) |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 61 | |
| 62 | /* |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 63 | * Definitions for SMB2 Protocol Data Units (network frames) |
| 64 | * |
| 65 | * See MS-SMB2.PDF specification for protocol details. |
| 66 | * The Naming convention is the lower case version of the SMB2 |
| 67 | * command code name for the struct. Note that structures must be packed. |
| 68 | * |
| 69 | */ |
| 70 | |
| 71 | #define SMB2_ERROR_STRUCTURE_SIZE2 9 |
| 72 | #define SMB2_ERROR_STRUCTURE_SIZE2_LE cpu_to_le16(SMB2_ERROR_STRUCTURE_SIZE2) |
| 73 | |
| 74 | struct smb2_err_rsp { |
| 75 | struct smb2_hdr hdr; |
| 76 | __le16 StructureSize; |
| 77 | __u8 ErrorContextCount; |
| 78 | __u8 Reserved; |
| 79 | __le32 ByteCount; /* even if zero, at least one byte follows */ |
| 80 | __u8 ErrorData[1]; /* variable length */ |
| 81 | } __packed; |
| 82 | |
| 83 | struct smb2_negotiate_req { |
| 84 | struct smb2_hdr hdr; |
| 85 | __le16 StructureSize; /* Must be 36 */ |
| 86 | __le16 DialectCount; |
| 87 | __le16 SecurityMode; |
| 88 | __le16 Reserved; /* MBZ */ |
| 89 | __le32 Capabilities; |
| 90 | __u8 ClientGUID[SMB2_CLIENT_GUID_SIZE]; |
| 91 | /* In SMB3.02 and earlier next three were MBZ le64 ClientStartTime */ |
| 92 | __le32 NegotiateContextOffset; /* SMB3.1.1 only. MBZ earlier */ |
| 93 | __le16 NegotiateContextCount; /* SMB3.1.1 only. MBZ earlier */ |
| 94 | __le16 Reserved2; |
| 95 | __le16 Dialects[1]; /* One dialect (vers=) at a time for now */ |
| 96 | } __packed; |
| 97 | |
| 98 | /* SecurityMode flags */ |
| 99 | #define SMB2_NEGOTIATE_SIGNING_ENABLED_LE cpu_to_le16(0x0001) |
| 100 | #define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002 |
| 101 | #define SMB2_NEGOTIATE_SIGNING_REQUIRED_LE cpu_to_le16(0x0002) |
| 102 | /* Capabilities flags */ |
| 103 | #define SMB2_GLOBAL_CAP_DFS 0x00000001 |
| 104 | #define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */ |
| 105 | #define SMB2_GLOBAL_CAP_LARGE_MTU 0X00000004 /* Resp only New to SMB2.1 */ |
| 106 | #define SMB2_GLOBAL_CAP_MULTI_CHANNEL 0x00000008 /* New to SMB3 */ |
| 107 | #define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */ |
| 108 | #define SMB2_GLOBAL_CAP_DIRECTORY_LEASING 0x00000020 /* New to SMB3 */ |
| 109 | #define SMB2_GLOBAL_CAP_ENCRYPTION 0x00000040 /* New to SMB3 */ |
| 110 | /* Internal types */ |
| 111 | #define SMB2_NT_FIND 0x00100000 |
| 112 | #define SMB2_LARGE_FILES 0x00200000 |
| 113 | |
| 114 | #define SMB311_SALT_SIZE 32 |
| 115 | /* Hash Algorithm Types */ |
| 116 | #define SMB2_PREAUTH_INTEGRITY_SHA512 cpu_to_le16(0x0001) |
| 117 | |
| 118 | #define PREAUTH_HASHVALUE_SIZE 64 |
| 119 | |
| 120 | struct preauth_integrity_info { |
| 121 | /* PreAuth integrity Hash ID */ |
| 122 | __le16 Preauth_HashId; |
| 123 | /* PreAuth integrity Hash Value */ |
| 124 | __u8 Preauth_HashValue[PREAUTH_HASHVALUE_SIZE]; |
| 125 | }; |
| 126 | |
Namjae Jeon | cb45172 | 2021-11-03 08:08:44 +0900 | [diff] [blame] | 127 | /* offset is sizeof smb2_negotiate_rsp but rounded up to 8 bytes. */ |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 128 | #ifdef CONFIG_SMB_SERVER_KERBEROS5 |
Namjae Jeon | cb45172 | 2021-11-03 08:08:44 +0900 | [diff] [blame] | 129 | /* sizeof(struct smb2_negotiate_rsp) = |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 130 | * header(64) + response(64) + GSS_LENGTH(96) + GSS_PADDING(0) |
| 131 | */ |
| 132 | #define OFFSET_OF_NEG_CONTEXT 0xe0 |
| 133 | #else |
Namjae Jeon | cb45172 | 2021-11-03 08:08:44 +0900 | [diff] [blame] | 134 | /* sizeof(struct smb2_negotiate_rsp) = |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 135 | * header(64) + response(64) + GSS_LENGTH(74) + GSS_PADDING(6) |
| 136 | */ |
| 137 | #define OFFSET_OF_NEG_CONTEXT 0xd0 |
| 138 | #endif |
| 139 | |
| 140 | #define SMB2_PREAUTH_INTEGRITY_CAPABILITIES cpu_to_le16(1) |
| 141 | #define SMB2_ENCRYPTION_CAPABILITIES cpu_to_le16(2) |
| 142 | #define SMB2_COMPRESSION_CAPABILITIES cpu_to_le16(3) |
| 143 | #define SMB2_NETNAME_NEGOTIATE_CONTEXT_ID cpu_to_le16(5) |
Namjae Jeon | 378087c | 2021-07-21 10:05:53 +0900 | [diff] [blame] | 144 | #define SMB2_SIGNING_CAPABILITIES cpu_to_le16(8) |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 145 | #define SMB2_POSIX_EXTENSIONS_AVAILABLE cpu_to_le16(0x100) |
| 146 | |
| 147 | struct smb2_neg_context { |
| 148 | __le16 ContextType; |
| 149 | __le16 DataLength; |
| 150 | __le32 Reserved; |
| 151 | /* Followed by array of data */ |
| 152 | } __packed; |
| 153 | |
| 154 | struct smb2_preauth_neg_context { |
| 155 | __le16 ContextType; /* 1 */ |
| 156 | __le16 DataLength; |
| 157 | __le32 Reserved; |
| 158 | __le16 HashAlgorithmCount; /* 1 */ |
| 159 | __le16 SaltLength; |
| 160 | __le16 HashAlgorithms; /* HashAlgorithms[0] since only one defined */ |
| 161 | __u8 Salt[SMB311_SALT_SIZE]; |
| 162 | } __packed; |
| 163 | |
| 164 | /* Encryption Algorithms Ciphers */ |
| 165 | #define SMB2_ENCRYPTION_AES128_CCM cpu_to_le16(0x0001) |
| 166 | #define SMB2_ENCRYPTION_AES128_GCM cpu_to_le16(0x0002) |
Namjae Jeon | 5a0ca77 | 2021-05-06 11:43:37 +0900 | [diff] [blame] | 167 | #define SMB2_ENCRYPTION_AES256_CCM cpu_to_le16(0x0003) |
| 168 | #define SMB2_ENCRYPTION_AES256_GCM cpu_to_le16(0x0004) |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 169 | |
| 170 | struct smb2_encryption_neg_context { |
| 171 | __le16 ContextType; /* 2 */ |
| 172 | __le16 DataLength; |
| 173 | __le32 Reserved; |
Namjae Jeon | 5a0ca77 | 2021-05-06 11:43:37 +0900 | [diff] [blame] | 174 | /* CipherCount usally 2, but can be 3 when AES256-GCM enabled */ |
| 175 | __le16 CipherCount; /* AES-128-GCM and AES-128-CCM by default */ |
Namjae Jeon | af320a7 | 2021-07-21 10:03:19 +0900 | [diff] [blame] | 176 | __le16 Ciphers[]; |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 177 | } __packed; |
| 178 | |
| 179 | #define SMB3_COMPRESS_NONE cpu_to_le16(0x0000) |
| 180 | #define SMB3_COMPRESS_LZNT1 cpu_to_le16(0x0001) |
| 181 | #define SMB3_COMPRESS_LZ77 cpu_to_le16(0x0002) |
| 182 | #define SMB3_COMPRESS_LZ77_HUFF cpu_to_le16(0x0003) |
| 183 | |
| 184 | struct smb2_compression_ctx { |
| 185 | __le16 ContextType; /* 3 */ |
| 186 | __le16 DataLength; |
| 187 | __le32 Reserved; |
| 188 | __le16 CompressionAlgorithmCount; |
| 189 | __u16 Padding; |
| 190 | __le32 Reserved1; |
Namjae Jeon | af320a7 | 2021-07-21 10:03:19 +0900 | [diff] [blame] | 191 | __le16 CompressionAlgorithms[]; |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 192 | } __packed; |
| 193 | |
| 194 | #define POSIX_CTXT_DATA_LEN 16 |
| 195 | struct smb2_posix_neg_context { |
| 196 | __le16 ContextType; /* 0x100 */ |
| 197 | __le16 DataLength; |
| 198 | __le32 Reserved; |
| 199 | __u8 Name[16]; /* POSIX ctxt GUID 93AD25509CB411E7B42383DE968BCD7C */ |
| 200 | } __packed; |
| 201 | |
| 202 | struct smb2_netname_neg_context { |
| 203 | __le16 ContextType; /* 0x100 */ |
| 204 | __le16 DataLength; |
| 205 | __le32 Reserved; |
Namjae Jeon | af320a7 | 2021-07-21 10:03:19 +0900 | [diff] [blame] | 206 | __le16 NetName[]; /* hostname of target converted to UCS-2 */ |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 207 | } __packed; |
| 208 | |
Namjae Jeon | 378087c | 2021-07-21 10:05:53 +0900 | [diff] [blame] | 209 | /* Signing algorithms */ |
| 210 | #define SIGNING_ALG_HMAC_SHA256 cpu_to_le16(0) |
| 211 | #define SIGNING_ALG_AES_CMAC cpu_to_le16(1) |
| 212 | #define SIGNING_ALG_AES_GMAC cpu_to_le16(2) |
| 213 | |
| 214 | struct smb2_signing_capabilities { |
| 215 | __le16 ContextType; /* 8 */ |
| 216 | __le16 DataLength; |
| 217 | __le32 Reserved; |
| 218 | __le16 SigningAlgorithmCount; |
| 219 | __le16 SigningAlgorithms[]; |
| 220 | } __packed; |
| 221 | |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 222 | struct smb2_negotiate_rsp { |
| 223 | struct smb2_hdr hdr; |
| 224 | __le16 StructureSize; /* Must be 65 */ |
| 225 | __le16 SecurityMode; |
| 226 | __le16 DialectRevision; |
| 227 | __le16 NegotiateContextCount; /* Prior to SMB3.1.1 was Reserved & MBZ */ |
| 228 | __u8 ServerGUID[16]; |
| 229 | __le32 Capabilities; |
| 230 | __le32 MaxTransactSize; |
| 231 | __le32 MaxReadSize; |
| 232 | __le32 MaxWriteSize; |
| 233 | __le64 SystemTime; /* MBZ */ |
| 234 | __le64 ServerStartTime; |
| 235 | __le16 SecurityBufferOffset; |
| 236 | __le16 SecurityBufferLength; |
| 237 | __le32 NegotiateContextOffset; /* Pre:SMB3.1.1 was reserved/ignored */ |
| 238 | __u8 Buffer[1]; /* variable length GSS security buffer */ |
| 239 | } __packed; |
| 240 | |
| 241 | /* Flags */ |
| 242 | #define SMB2_SESSION_REQ_FLAG_BINDING 0x01 |
| 243 | #define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA 0x04 |
| 244 | |
| 245 | #define SMB2_SESSION_EXPIRED (0) |
Namjae Jeon | 64b39f4 | 2021-03-30 14:25:35 +0900 | [diff] [blame] | 246 | #define SMB2_SESSION_IN_PROGRESS BIT(0) |
| 247 | #define SMB2_SESSION_VALID BIT(1) |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 248 | |
| 249 | /* Flags */ |
| 250 | #define SMB2_SESSION_REQ_FLAG_BINDING 0x01 |
| 251 | #define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA 0x04 |
| 252 | |
| 253 | struct smb2_sess_setup_req { |
| 254 | struct smb2_hdr hdr; |
| 255 | __le16 StructureSize; /* Must be 25 */ |
| 256 | __u8 Flags; |
| 257 | __u8 SecurityMode; |
| 258 | __le32 Capabilities; |
| 259 | __le32 Channel; |
| 260 | __le16 SecurityBufferOffset; |
| 261 | __le16 SecurityBufferLength; |
| 262 | __le64 PreviousSessionId; |
| 263 | __u8 Buffer[1]; /* variable length GSS security buffer */ |
| 264 | } __packed; |
| 265 | |
| 266 | /* Flags/Reserved for SMB3.1.1 */ |
| 267 | #define SMB2_SHAREFLAG_CLUSTER_RECONNECT 0x0001 |
| 268 | |
| 269 | /* Currently defined SessionFlags */ |
| 270 | #define SMB2_SESSION_FLAG_IS_GUEST_LE cpu_to_le16(0x0001) |
| 271 | #define SMB2_SESSION_FLAG_IS_NULL_LE cpu_to_le16(0x0002) |
| 272 | #define SMB2_SESSION_FLAG_ENCRYPT_DATA_LE cpu_to_le16(0x0004) |
| 273 | struct smb2_sess_setup_rsp { |
| 274 | struct smb2_hdr hdr; |
| 275 | __le16 StructureSize; /* Must be 9 */ |
| 276 | __le16 SessionFlags; |
| 277 | __le16 SecurityBufferOffset; |
| 278 | __le16 SecurityBufferLength; |
| 279 | __u8 Buffer[1]; /* variable length GSS security buffer */ |
| 280 | } __packed; |
| 281 | |
| 282 | struct smb2_logoff_req { |
| 283 | struct smb2_hdr hdr; |
| 284 | __le16 StructureSize; /* Must be 4 */ |
| 285 | __le16 Reserved; |
| 286 | } __packed; |
| 287 | |
| 288 | struct smb2_logoff_rsp { |
| 289 | struct smb2_hdr hdr; |
| 290 | __le16 StructureSize; /* Must be 4 */ |
| 291 | __le16 Reserved; |
| 292 | } __packed; |
| 293 | |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 294 | #define ATTR_READONLY_LE cpu_to_le32(ATTR_READONLY) |
| 295 | #define ATTR_HIDDEN_LE cpu_to_le32(ATTR_HIDDEN) |
| 296 | #define ATTR_SYSTEM_LE cpu_to_le32(ATTR_SYSTEM) |
| 297 | #define ATTR_DIRECTORY_LE cpu_to_le32(ATTR_DIRECTORY) |
| 298 | #define ATTR_ARCHIVE_LE cpu_to_le32(ATTR_ARCHIVE) |
| 299 | #define ATTR_NORMAL_LE cpu_to_le32(ATTR_NORMAL) |
| 300 | #define ATTR_TEMPORARY_LE cpu_to_le32(ATTR_TEMPORARY) |
| 301 | #define ATTR_SPARSE_FILE_LE cpu_to_le32(ATTR_SPARSE) |
| 302 | #define ATTR_REPARSE_POINT_LE cpu_to_le32(ATTR_REPARSE) |
| 303 | #define ATTR_COMPRESSED_LE cpu_to_le32(ATTR_COMPRESSED) |
| 304 | #define ATTR_OFFLINE_LE cpu_to_le32(ATTR_OFFLINE) |
| 305 | #define ATTR_NOT_CONTENT_INDEXED_LE cpu_to_le32(ATTR_NOT_CONTENT_INDEXED) |
| 306 | #define ATTR_ENCRYPTED_LE cpu_to_le32(ATTR_ENCRYPTED) |
| 307 | #define ATTR_INTEGRITY_STREAML_LE cpu_to_le32(0x00008000) |
| 308 | #define ATTR_NO_SCRUB_DATA_LE cpu_to_le32(0x00020000) |
| 309 | #define ATTR_MASK_LE cpu_to_le32(0x00007FB7) |
| 310 | |
| 311 | /* Oplock levels */ |
| 312 | #define SMB2_OPLOCK_LEVEL_NONE 0x00 |
| 313 | #define SMB2_OPLOCK_LEVEL_II 0x01 |
| 314 | #define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08 |
| 315 | #define SMB2_OPLOCK_LEVEL_BATCH 0x09 |
| 316 | #define SMB2_OPLOCK_LEVEL_LEASE 0xFF |
| 317 | /* Non-spec internal type */ |
| 318 | #define SMB2_OPLOCK_LEVEL_NOCHANGE 0x99 |
| 319 | |
| 320 | /* Desired Access Flags */ |
| 321 | #define FILE_READ_DATA_LE cpu_to_le32(0x00000001) |
| 322 | #define FILE_LIST_DIRECTORY_LE cpu_to_le32(0x00000001) |
| 323 | #define FILE_WRITE_DATA_LE cpu_to_le32(0x00000002) |
| 324 | #define FILE_ADD_FILE_LE cpu_to_le32(0x00000002) |
| 325 | #define FILE_APPEND_DATA_LE cpu_to_le32(0x00000004) |
| 326 | #define FILE_ADD_SUBDIRECTORY_LE cpu_to_le32(0x00000004) |
| 327 | #define FILE_READ_EA_LE cpu_to_le32(0x00000008) |
| 328 | #define FILE_WRITE_EA_LE cpu_to_le32(0x00000010) |
| 329 | #define FILE_EXECUTE_LE cpu_to_le32(0x00000020) |
| 330 | #define FILE_TRAVERSE_LE cpu_to_le32(0x00000020) |
| 331 | #define FILE_DELETE_CHILD_LE cpu_to_le32(0x00000040) |
| 332 | #define FILE_READ_ATTRIBUTES_LE cpu_to_le32(0x00000080) |
| 333 | #define FILE_WRITE_ATTRIBUTES_LE cpu_to_le32(0x00000100) |
| 334 | #define FILE_DELETE_LE cpu_to_le32(0x00010000) |
| 335 | #define FILE_READ_CONTROL_LE cpu_to_le32(0x00020000) |
| 336 | #define FILE_WRITE_DAC_LE cpu_to_le32(0x00040000) |
| 337 | #define FILE_WRITE_OWNER_LE cpu_to_le32(0x00080000) |
| 338 | #define FILE_SYNCHRONIZE_LE cpu_to_le32(0x00100000) |
| 339 | #define FILE_ACCESS_SYSTEM_SECURITY_LE cpu_to_le32(0x01000000) |
| 340 | #define FILE_MAXIMAL_ACCESS_LE cpu_to_le32(0x02000000) |
| 341 | #define FILE_GENERIC_ALL_LE cpu_to_le32(0x10000000) |
| 342 | #define FILE_GENERIC_EXECUTE_LE cpu_to_le32(0x20000000) |
| 343 | #define FILE_GENERIC_WRITE_LE cpu_to_le32(0x40000000) |
| 344 | #define FILE_GENERIC_READ_LE cpu_to_le32(0x80000000) |
| 345 | #define DESIRED_ACCESS_MASK cpu_to_le32(0xF21F01FF) |
| 346 | |
| 347 | /* ShareAccess Flags */ |
| 348 | #define FILE_SHARE_READ_LE cpu_to_le32(0x00000001) |
| 349 | #define FILE_SHARE_WRITE_LE cpu_to_le32(0x00000002) |
| 350 | #define FILE_SHARE_DELETE_LE cpu_to_le32(0x00000004) |
| 351 | #define FILE_SHARE_ALL_LE cpu_to_le32(0x00000007) |
| 352 | |
| 353 | /* CreateDisposition Flags */ |
| 354 | #define FILE_SUPERSEDE_LE cpu_to_le32(0x00000000) |
| 355 | #define FILE_OPEN_LE cpu_to_le32(0x00000001) |
| 356 | #define FILE_CREATE_LE cpu_to_le32(0x00000002) |
| 357 | #define FILE_OPEN_IF_LE cpu_to_le32(0x00000003) |
| 358 | #define FILE_OVERWRITE_LE cpu_to_le32(0x00000004) |
| 359 | #define FILE_OVERWRITE_IF_LE cpu_to_le32(0x00000005) |
| 360 | #define FILE_CREATE_MASK_LE cpu_to_le32(0x00000007) |
| 361 | |
| 362 | #define FILE_READ_DESIRED_ACCESS_LE (FILE_READ_DATA_LE | \ |
| 363 | FILE_READ_EA_LE | \ |
| 364 | FILE_GENERIC_READ_LE) |
| 365 | #define FILE_WRITE_DESIRE_ACCESS_LE (FILE_WRITE_DATA_LE | \ |
| 366 | FILE_APPEND_DATA_LE | \ |
| 367 | FILE_WRITE_EA_LE | \ |
| 368 | FILE_WRITE_ATTRIBUTES_LE | \ |
| 369 | FILE_GENERIC_WRITE_LE) |
| 370 | |
| 371 | /* Impersonation Levels */ |
| 372 | #define IL_ANONYMOUS_LE cpu_to_le32(0x00000000) |
| 373 | #define IL_IDENTIFICATION_LE cpu_to_le32(0x00000001) |
| 374 | #define IL_IMPERSONATION_LE cpu_to_le32(0x00000002) |
| 375 | #define IL_DELEGATE_LE cpu_to_le32(0x00000003) |
| 376 | |
| 377 | /* Create Context Values */ |
| 378 | #define SMB2_CREATE_EA_BUFFER "ExtA" /* extended attributes */ |
| 379 | #define SMB2_CREATE_SD_BUFFER "SecD" /* security descriptor */ |
| 380 | #define SMB2_CREATE_DURABLE_HANDLE_REQUEST "DHnQ" |
| 381 | #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT "DHnC" |
| 382 | #define SMB2_CREATE_ALLOCATION_SIZE "AlSi" |
| 383 | #define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST "MxAc" |
| 384 | #define SMB2_CREATE_TIMEWARP_REQUEST "TWrp" |
| 385 | #define SMB2_CREATE_QUERY_ON_DISK_ID "QFid" |
| 386 | #define SMB2_CREATE_REQUEST_LEASE "RqLs" |
| 387 | #define SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 "DH2Q" |
| 388 | #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 "DH2C" |
| 389 | #define SMB2_CREATE_APP_INSTANCE_ID "\x45\xBC\xA6\x6A\xEF\xA7\xF7\x4A\x90\x08\xFA\x46\x2E\x14\x4D\x74" |
| 390 | #define SMB2_CREATE_APP_INSTANCE_VERSION "\xB9\x82\xD0\xB7\x3B\x56\x07\x4F\xA0\x7B\x52\x4A\x81\x16\xA0\x10" |
| 391 | #define SVHDX_OPEN_DEVICE_CONTEXT 0x83CE6F1AD851E0986E34401CC9BCFCE9 |
| 392 | #define SMB2_CREATE_TAG_POSIX "\x93\xAD\x25\x50\x9C\xB4\x11\xE7\xB4\x23\x83\xDE\x96\x8B\xCD\x7C" |
| 393 | |
| 394 | struct smb2_create_req { |
| 395 | struct smb2_hdr hdr; |
| 396 | __le16 StructureSize; /* Must be 57 */ |
| 397 | __u8 SecurityFlags; |
| 398 | __u8 RequestedOplockLevel; |
| 399 | __le32 ImpersonationLevel; |
| 400 | __le64 SmbCreateFlags; |
| 401 | __le64 Reserved; |
| 402 | __le32 DesiredAccess; |
| 403 | __le32 FileAttributes; |
| 404 | __le32 ShareAccess; |
| 405 | __le32 CreateDisposition; |
| 406 | __le32 CreateOptions; |
| 407 | __le16 NameOffset; |
| 408 | __le16 NameLength; |
| 409 | __le32 CreateContextsOffset; |
| 410 | __le32 CreateContextsLength; |
| 411 | __u8 Buffer[0]; |
| 412 | } __packed; |
| 413 | |
| 414 | struct smb2_create_rsp { |
| 415 | struct smb2_hdr hdr; |
| 416 | __le16 StructureSize; /* Must be 89 */ |
| 417 | __u8 OplockLevel; |
| 418 | __u8 Reserved; |
| 419 | __le32 CreateAction; |
| 420 | __le64 CreationTime; |
| 421 | __le64 LastAccessTime; |
| 422 | __le64 LastWriteTime; |
| 423 | __le64 ChangeTime; |
| 424 | __le64 AllocationSize; |
| 425 | __le64 EndofFile; |
| 426 | __le32 FileAttributes; |
| 427 | __le32 Reserved2; |
| 428 | __le64 PersistentFileId; |
| 429 | __le64 VolatileFileId; |
| 430 | __le32 CreateContextsOffset; |
| 431 | __le32 CreateContextsLength; |
| 432 | __u8 Buffer[1]; |
| 433 | } __packed; |
| 434 | |
| 435 | struct create_context { |
| 436 | __le32 Next; |
| 437 | __le16 NameOffset; |
| 438 | __le16 NameLength; |
| 439 | __le16 Reserved; |
| 440 | __le16 DataOffset; |
| 441 | __le32 DataLength; |
| 442 | __u8 Buffer[0]; |
| 443 | } __packed; |
| 444 | |
| 445 | struct create_durable_req_v2 { |
| 446 | struct create_context ccontext; |
| 447 | __u8 Name[8]; |
| 448 | __le32 Timeout; |
| 449 | __le32 Flags; |
| 450 | __u8 Reserved[8]; |
| 451 | __u8 CreateGuid[16]; |
| 452 | } __packed; |
| 453 | |
| 454 | struct create_durable_reconn_req { |
| 455 | struct create_context ccontext; |
| 456 | __u8 Name[8]; |
| 457 | union { |
| 458 | __u8 Reserved[16]; |
| 459 | struct { |
| 460 | __le64 PersistentFileId; |
| 461 | __le64 VolatileFileId; |
| 462 | } Fid; |
| 463 | } Data; |
| 464 | } __packed; |
| 465 | |
| 466 | struct create_durable_reconn_v2_req { |
| 467 | struct create_context ccontext; |
| 468 | __u8 Name[8]; |
| 469 | struct { |
| 470 | __le64 PersistentFileId; |
| 471 | __le64 VolatileFileId; |
| 472 | } Fid; |
| 473 | __u8 CreateGuid[16]; |
| 474 | __le32 Flags; |
| 475 | } __packed; |
| 476 | |
| 477 | struct create_app_inst_id { |
| 478 | struct create_context ccontext; |
| 479 | __u8 Name[8]; |
| 480 | __u8 Reserved[8]; |
| 481 | __u8 AppInstanceId[16]; |
| 482 | } __packed; |
| 483 | |
| 484 | struct create_app_inst_id_vers { |
| 485 | struct create_context ccontext; |
| 486 | __u8 Name[8]; |
| 487 | __u8 Reserved[2]; |
| 488 | __u8 Padding[4]; |
| 489 | __le64 AppInstanceVersionHigh; |
| 490 | __le64 AppInstanceVersionLow; |
| 491 | } __packed; |
| 492 | |
| 493 | struct create_mxac_req { |
| 494 | struct create_context ccontext; |
| 495 | __u8 Name[8]; |
| 496 | __le64 Timestamp; |
| 497 | } __packed; |
| 498 | |
| 499 | struct create_alloc_size_req { |
| 500 | struct create_context ccontext; |
| 501 | __u8 Name[8]; |
| 502 | __le64 AllocationSize; |
| 503 | } __packed; |
| 504 | |
| 505 | struct create_posix { |
| 506 | struct create_context ccontext; |
| 507 | __u8 Name[16]; |
| 508 | __le32 Mode; |
| 509 | __u32 Reserved; |
| 510 | } __packed; |
| 511 | |
| 512 | struct create_durable_rsp { |
| 513 | struct create_context ccontext; |
| 514 | __u8 Name[8]; |
| 515 | union { |
| 516 | __u8 Reserved[8]; |
| 517 | __u64 data; |
| 518 | } Data; |
| 519 | } __packed; |
| 520 | |
| 521 | struct create_durable_v2_rsp { |
| 522 | struct create_context ccontext; |
| 523 | __u8 Name[8]; |
| 524 | __le32 Timeout; |
| 525 | __le32 Flags; |
| 526 | } __packed; |
| 527 | |
| 528 | struct create_mxac_rsp { |
| 529 | struct create_context ccontext; |
| 530 | __u8 Name[8]; |
| 531 | __le32 QueryStatus; |
| 532 | __le32 MaximalAccess; |
| 533 | } __packed; |
| 534 | |
| 535 | struct create_disk_id_rsp { |
| 536 | struct create_context ccontext; |
| 537 | __u8 Name[8]; |
| 538 | __le64 DiskFileId; |
| 539 | __le64 VolumeId; |
| 540 | __u8 Reserved[16]; |
| 541 | } __packed; |
| 542 | |
| 543 | /* equivalent of the contents of SMB3.1.1 POSIX open context response */ |
| 544 | struct create_posix_rsp { |
| 545 | struct create_context ccontext; |
| 546 | __u8 Name[16]; |
| 547 | __le32 nlink; |
| 548 | __le32 reparse_tag; |
| 549 | __le32 mode; |
| 550 | u8 SidBuffer[40]; |
| 551 | } __packed; |
| 552 | |
| 553 | #define SMB2_LEASE_NONE_LE cpu_to_le32(0x00) |
| 554 | #define SMB2_LEASE_READ_CACHING_LE cpu_to_le32(0x01) |
| 555 | #define SMB2_LEASE_HANDLE_CACHING_LE cpu_to_le32(0x02) |
| 556 | #define SMB2_LEASE_WRITE_CACHING_LE cpu_to_le32(0x04) |
| 557 | |
| 558 | #define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE cpu_to_le32(0x02) |
| 559 | |
Namjae Jeon | 2734b69 | 2021-09-09 12:28:18 +0900 | [diff] [blame] | 560 | #define SMB2_LEASE_KEY_SIZE 16 |
| 561 | |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 562 | struct lease_context { |
Namjae Jeon | 2734b69 | 2021-09-09 12:28:18 +0900 | [diff] [blame] | 563 | __u8 LeaseKey[SMB2_LEASE_KEY_SIZE]; |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 564 | __le32 LeaseState; |
| 565 | __le32 LeaseFlags; |
| 566 | __le64 LeaseDuration; |
| 567 | } __packed; |
| 568 | |
Namjae Jeon | ade62d8 | 2021-06-07 09:22:22 +0900 | [diff] [blame] | 569 | struct lease_context_v2 { |
Namjae Jeon | 2734b69 | 2021-09-09 12:28:18 +0900 | [diff] [blame] | 570 | __u8 LeaseKey[SMB2_LEASE_KEY_SIZE]; |
Namjae Jeon | ade62d8 | 2021-06-07 09:22:22 +0900 | [diff] [blame] | 571 | __le32 LeaseState; |
| 572 | __le32 LeaseFlags; |
| 573 | __le64 LeaseDuration; |
Namjae Jeon | 2734b69 | 2021-09-09 12:28:18 +0900 | [diff] [blame] | 574 | __u8 ParentLeaseKey[SMB2_LEASE_KEY_SIZE]; |
Namjae Jeon | ade62d8 | 2021-06-07 09:22:22 +0900 | [diff] [blame] | 575 | __le16 Epoch; |
| 576 | __le16 Reserved; |
| 577 | } __packed; |
| 578 | |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 579 | struct create_lease { |
| 580 | struct create_context ccontext; |
| 581 | __u8 Name[8]; |
| 582 | struct lease_context lcontext; |
| 583 | } __packed; |
| 584 | |
Namjae Jeon | ade62d8 | 2021-06-07 09:22:22 +0900 | [diff] [blame] | 585 | struct create_lease_v2 { |
| 586 | struct create_context ccontext; |
| 587 | __u8 Name[8]; |
| 588 | struct lease_context_v2 lcontext; |
| 589 | __u8 Pad[4]; |
| 590 | } __packed; |
| 591 | |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 592 | /* Currently defined values for close flags */ |
| 593 | #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001) |
| 594 | struct smb2_close_req { |
| 595 | struct smb2_hdr hdr; |
| 596 | __le16 StructureSize; /* Must be 24 */ |
| 597 | __le16 Flags; |
| 598 | __le32 Reserved; |
| 599 | __le64 PersistentFileId; |
| 600 | __le64 VolatileFileId; |
| 601 | } __packed; |
| 602 | |
| 603 | struct smb2_close_rsp { |
| 604 | struct smb2_hdr hdr; |
| 605 | __le16 StructureSize; /* 60 */ |
| 606 | __le16 Flags; |
| 607 | __le32 Reserved; |
| 608 | __le64 CreationTime; |
| 609 | __le64 LastAccessTime; |
| 610 | __le64 LastWriteTime; |
| 611 | __le64 ChangeTime; |
| 612 | __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */ |
| 613 | __le64 EndOfFile; |
| 614 | __le32 Attributes; |
| 615 | } __packed; |
| 616 | |
| 617 | struct smb2_flush_req { |
| 618 | struct smb2_hdr hdr; |
| 619 | __le16 StructureSize; /* Must be 24 */ |
| 620 | __le16 Reserved1; |
| 621 | __le32 Reserved2; |
| 622 | __le64 PersistentFileId; |
| 623 | __le64 VolatileFileId; |
| 624 | } __packed; |
| 625 | |
| 626 | struct smb2_flush_rsp { |
| 627 | struct smb2_hdr hdr; |
| 628 | __le16 StructureSize; |
| 629 | __le16 Reserved; |
| 630 | } __packed; |
| 631 | |
| 632 | struct smb2_buffer_desc_v1 { |
| 633 | __le64 offset; |
| 634 | __le32 token; |
| 635 | __le32 length; |
| 636 | } __packed; |
| 637 | |
| 638 | #define SMB2_CHANNEL_NONE cpu_to_le32(0x00000000) |
| 639 | #define SMB2_CHANNEL_RDMA_V1 cpu_to_le32(0x00000001) |
| 640 | #define SMB2_CHANNEL_RDMA_V1_INVALIDATE cpu_to_le32(0x00000002) |
| 641 | |
| 642 | struct smb2_read_req { |
| 643 | struct smb2_hdr hdr; |
| 644 | __le16 StructureSize; /* Must be 49 */ |
| 645 | __u8 Padding; /* offset from start of SMB2 header to place read */ |
| 646 | __u8 Reserved; |
| 647 | __le32 Length; |
| 648 | __le64 Offset; |
| 649 | __le64 PersistentFileId; |
| 650 | __le64 VolatileFileId; |
| 651 | __le32 MinimumCount; |
| 652 | __le32 Channel; /* Reserved MBZ */ |
| 653 | __le32 RemainingBytes; |
| 654 | __le16 ReadChannelInfoOffset; /* Reserved MBZ */ |
| 655 | __le16 ReadChannelInfoLength; /* Reserved MBZ */ |
| 656 | __u8 Buffer[1]; |
| 657 | } __packed; |
| 658 | |
| 659 | struct smb2_read_rsp { |
| 660 | struct smb2_hdr hdr; |
| 661 | __le16 StructureSize; /* Must be 17 */ |
| 662 | __u8 DataOffset; |
| 663 | __u8 Reserved; |
| 664 | __le32 DataLength; |
| 665 | __le32 DataRemaining; |
| 666 | __u32 Reserved2; |
| 667 | __u8 Buffer[1]; |
| 668 | } __packed; |
| 669 | |
| 670 | /* For write request Flags field below the following flag is defined: */ |
| 671 | #define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001 |
| 672 | |
| 673 | struct smb2_write_req { |
| 674 | struct smb2_hdr hdr; |
| 675 | __le16 StructureSize; /* Must be 49 */ |
| 676 | __le16 DataOffset; /* offset from start of SMB2 header to write data */ |
| 677 | __le32 Length; |
| 678 | __le64 Offset; |
| 679 | __le64 PersistentFileId; |
| 680 | __le64 VolatileFileId; |
| 681 | __le32 Channel; /* Reserved MBZ */ |
| 682 | __le32 RemainingBytes; |
| 683 | __le16 WriteChannelInfoOffset; /* Reserved MBZ */ |
| 684 | __le16 WriteChannelInfoLength; /* Reserved MBZ */ |
| 685 | __le32 Flags; |
| 686 | __u8 Buffer[1]; |
| 687 | } __packed; |
| 688 | |
| 689 | struct smb2_write_rsp { |
| 690 | struct smb2_hdr hdr; |
| 691 | __le16 StructureSize; /* Must be 17 */ |
| 692 | __u8 DataOffset; |
| 693 | __u8 Reserved; |
| 694 | __le32 DataLength; |
| 695 | __le32 DataRemaining; |
| 696 | __u32 Reserved2; |
| 697 | __u8 Buffer[1]; |
| 698 | } __packed; |
| 699 | |
| 700 | #define SMB2_0_IOCTL_IS_FSCTL 0x00000001 |
| 701 | |
Namjae Jeon | eb81736 | 2021-05-18 10:37:59 +0900 | [diff] [blame] | 702 | struct duplicate_extents_to_file { |
| 703 | __u64 PersistentFileHandle; /* source file handle, opaque endianness */ |
| 704 | __u64 VolatileFileHandle; |
| 705 | __le64 SourceFileOffset; |
| 706 | __le64 TargetFileOffset; |
| 707 | __le64 ByteCount; /* Bytes to be copied */ |
| 708 | } __packed; |
| 709 | |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 710 | struct smb2_ioctl_req { |
| 711 | struct smb2_hdr hdr; |
| 712 | __le16 StructureSize; /* Must be 57 */ |
| 713 | __le16 Reserved; /* offset from start of SMB2 header to write data */ |
| 714 | __le32 CntCode; |
| 715 | __le64 PersistentFileId; |
| 716 | __le64 VolatileFileId; |
| 717 | __le32 InputOffset; /* Reserved MBZ */ |
| 718 | __le32 InputCount; |
| 719 | __le32 MaxInputResponse; |
| 720 | __le32 OutputOffset; |
| 721 | __le32 OutputCount; |
| 722 | __le32 MaxOutputResponse; |
| 723 | __le32 Flags; |
| 724 | __le32 Reserved2; |
| 725 | __u8 Buffer[1]; |
| 726 | } __packed; |
| 727 | |
| 728 | struct smb2_ioctl_rsp { |
| 729 | struct smb2_hdr hdr; |
| 730 | __le16 StructureSize; /* Must be 49 */ |
| 731 | __le16 Reserved; /* offset from start of SMB2 header to write data */ |
| 732 | __le32 CntCode; |
| 733 | __le64 PersistentFileId; |
| 734 | __le64 VolatileFileId; |
| 735 | __le32 InputOffset; /* Reserved MBZ */ |
| 736 | __le32 InputCount; |
| 737 | __le32 OutputOffset; |
| 738 | __le32 OutputCount; |
| 739 | __le32 Flags; |
| 740 | __le32 Reserved2; |
| 741 | __u8 Buffer[1]; |
| 742 | } __packed; |
| 743 | |
| 744 | struct validate_negotiate_info_req { |
| 745 | __le32 Capabilities; |
| 746 | __u8 Guid[SMB2_CLIENT_GUID_SIZE]; |
| 747 | __le16 SecurityMode; |
| 748 | __le16 DialectCount; |
| 749 | __le16 Dialects[1]; /* dialect (someday maybe list) client asked for */ |
| 750 | } __packed; |
| 751 | |
| 752 | struct validate_negotiate_info_rsp { |
| 753 | __le32 Capabilities; |
| 754 | __u8 Guid[SMB2_CLIENT_GUID_SIZE]; |
| 755 | __le16 SecurityMode; |
| 756 | __le16 Dialect; /* Dialect in use for the connection */ |
| 757 | } __packed; |
| 758 | |
| 759 | struct smb_sockaddr_in { |
| 760 | __be16 Port; |
| 761 | __be32 IPv4address; |
| 762 | __u8 Reserved[8]; |
| 763 | } __packed; |
| 764 | |
| 765 | struct smb_sockaddr_in6 { |
| 766 | __be16 Port; |
| 767 | __be32 FlowInfo; |
| 768 | __u8 IPv6address[16]; |
| 769 | __be32 ScopeId; |
| 770 | } __packed; |
| 771 | |
| 772 | #define INTERNETWORK 0x0002 |
| 773 | #define INTERNETWORKV6 0x0017 |
| 774 | |
| 775 | struct sockaddr_storage_rsp { |
| 776 | __le16 Family; |
| 777 | union { |
| 778 | struct smb_sockaddr_in addr4; |
| 779 | struct smb_sockaddr_in6 addr6; |
| 780 | }; |
| 781 | } __packed; |
| 782 | |
| 783 | #define RSS_CAPABLE 0x00000001 |
| 784 | #define RDMA_CAPABLE 0x00000002 |
| 785 | |
| 786 | struct network_interface_info_ioctl_rsp { |
| 787 | __le32 Next; /* next interface. zero if this is last one */ |
| 788 | __le32 IfIndex; |
| 789 | __le32 Capability; /* RSS or RDMA Capable */ |
| 790 | __le32 Reserved; |
| 791 | __le64 LinkSpeed; |
| 792 | char SockAddr_Storage[128]; |
| 793 | } __packed; |
| 794 | |
| 795 | struct file_object_buf_type1_ioctl_rsp { |
| 796 | __u8 ObjectId[16]; |
| 797 | __u8 BirthVolumeId[16]; |
| 798 | __u8 BirthObjectId[16]; |
| 799 | __u8 DomainId[16]; |
| 800 | } __packed; |
| 801 | |
| 802 | struct resume_key_ioctl_rsp { |
| 803 | __le64 ResumeKey[3]; |
| 804 | __le32 ContextLength; |
| 805 | __u8 Context[4]; /* ignored, Windows sets to 4 bytes of zero */ |
| 806 | } __packed; |
| 807 | |
| 808 | struct copychunk_ioctl_req { |
| 809 | __le64 ResumeKey[3]; |
| 810 | __le32 ChunkCount; |
| 811 | __le32 Reserved; |
| 812 | __u8 Chunks[1]; /* array of srv_copychunk */ |
| 813 | } __packed; |
| 814 | |
| 815 | struct srv_copychunk { |
| 816 | __le64 SourceOffset; |
| 817 | __le64 TargetOffset; |
| 818 | __le32 Length; |
| 819 | __le32 Reserved; |
| 820 | } __packed; |
| 821 | |
| 822 | struct copychunk_ioctl_rsp { |
| 823 | __le32 ChunksWritten; |
| 824 | __le32 ChunkBytesWritten; |
| 825 | __le32 TotalBytesWritten; |
| 826 | } __packed; |
| 827 | |
| 828 | struct file_sparse { |
| 829 | __u8 SetSparse; |
| 830 | } __packed; |
| 831 | |
| 832 | struct file_zero_data_information { |
| 833 | __le64 FileOffset; |
| 834 | __le64 BeyondFinalZero; |
| 835 | } __packed; |
| 836 | |
| 837 | struct file_allocated_range_buffer { |
| 838 | __le64 file_offset; |
| 839 | __le64 length; |
| 840 | } __packed; |
| 841 | |
| 842 | struct reparse_data_buffer { |
| 843 | __le32 ReparseTag; |
| 844 | __le16 ReparseDataLength; |
| 845 | __u16 Reserved; |
| 846 | __u8 DataBuffer[]; /* Variable Length */ |
| 847 | } __packed; |
| 848 | |
| 849 | /* Completion Filter flags for Notify */ |
| 850 | #define FILE_NOTIFY_CHANGE_FILE_NAME 0x00000001 |
| 851 | #define FILE_NOTIFY_CHANGE_DIR_NAME 0x00000002 |
| 852 | #define FILE_NOTIFY_CHANGE_NAME 0x00000003 |
| 853 | #define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x00000004 |
| 854 | #define FILE_NOTIFY_CHANGE_SIZE 0x00000008 |
| 855 | #define FILE_NOTIFY_CHANGE_LAST_WRITE 0x00000010 |
| 856 | #define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x00000020 |
| 857 | #define FILE_NOTIFY_CHANGE_CREATION 0x00000040 |
| 858 | #define FILE_NOTIFY_CHANGE_EA 0x00000080 |
| 859 | #define FILE_NOTIFY_CHANGE_SECURITY 0x00000100 |
| 860 | #define FILE_NOTIFY_CHANGE_STREAM_NAME 0x00000200 |
| 861 | #define FILE_NOTIFY_CHANGE_STREAM_SIZE 0x00000400 |
| 862 | #define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800 |
| 863 | |
| 864 | /* Flags */ |
| 865 | #define SMB2_WATCH_TREE 0x0001 |
| 866 | |
| 867 | struct smb2_notify_req { |
| 868 | struct smb2_hdr hdr; |
| 869 | __le16 StructureSize; /* Must be 32 */ |
| 870 | __le16 Flags; |
| 871 | __le32 OutputBufferLength; |
| 872 | __le64 PersistentFileId; |
| 873 | __le64 VolatileFileId; |
| 874 | __u32 CompletionFileter; |
| 875 | __u32 Reserved; |
| 876 | } __packed; |
| 877 | |
| 878 | struct smb2_notify_rsp { |
| 879 | struct smb2_hdr hdr; |
| 880 | __le16 StructureSize; /* Must be 9 */ |
| 881 | __le16 OutputBufferOffset; |
| 882 | __le32 OutputBufferLength; |
| 883 | __u8 Buffer[1]; |
| 884 | } __packed; |
| 885 | |
| 886 | /* SMB2 Notify Action Flags */ |
| 887 | #define FILE_ACTION_ADDED 0x00000001 |
| 888 | #define FILE_ACTION_REMOVED 0x00000002 |
| 889 | #define FILE_ACTION_MODIFIED 0x00000003 |
| 890 | #define FILE_ACTION_RENAMED_OLD_NAME 0x00000004 |
| 891 | #define FILE_ACTION_RENAMED_NEW_NAME 0x00000005 |
| 892 | #define FILE_ACTION_ADDED_STREAM 0x00000006 |
| 893 | #define FILE_ACTION_REMOVED_STREAM 0x00000007 |
| 894 | #define FILE_ACTION_MODIFIED_STREAM 0x00000008 |
| 895 | #define FILE_ACTION_REMOVED_BY_DELETE 0x00000009 |
| 896 | |
| 897 | #define SMB2_LOCKFLAG_SHARED 0x0001 |
| 898 | #define SMB2_LOCKFLAG_EXCLUSIVE 0x0002 |
| 899 | #define SMB2_LOCKFLAG_UNLOCK 0x0004 |
| 900 | #define SMB2_LOCKFLAG_FAIL_IMMEDIATELY 0x0010 |
| 901 | #define SMB2_LOCKFLAG_MASK 0x0007 |
| 902 | |
| 903 | struct smb2_lock_element { |
| 904 | __le64 Offset; |
| 905 | __le64 Length; |
| 906 | __le32 Flags; |
| 907 | __le32 Reserved; |
| 908 | } __packed; |
| 909 | |
| 910 | struct smb2_lock_req { |
| 911 | struct smb2_hdr hdr; |
| 912 | __le16 StructureSize; /* Must be 48 */ |
| 913 | __le16 LockCount; |
| 914 | __le32 Reserved; |
| 915 | __le64 PersistentFileId; |
| 916 | __le64 VolatileFileId; |
| 917 | /* Followed by at least one */ |
| 918 | struct smb2_lock_element locks[1]; |
| 919 | } __packed; |
| 920 | |
| 921 | struct smb2_lock_rsp { |
| 922 | struct smb2_hdr hdr; |
| 923 | __le16 StructureSize; /* Must be 4 */ |
| 924 | __le16 Reserved; |
| 925 | } __packed; |
| 926 | |
| 927 | struct smb2_echo_req { |
| 928 | struct smb2_hdr hdr; |
| 929 | __le16 StructureSize; /* Must be 4 */ |
| 930 | __u16 Reserved; |
| 931 | } __packed; |
| 932 | |
| 933 | struct smb2_echo_rsp { |
| 934 | struct smb2_hdr hdr; |
| 935 | __le16 StructureSize; /* Must be 4 */ |
| 936 | __u16 Reserved; |
| 937 | } __packed; |
| 938 | |
| 939 | /* search (query_directory) Flags field */ |
| 940 | #define SMB2_RESTART_SCANS 0x01 |
| 941 | #define SMB2_RETURN_SINGLE_ENTRY 0x02 |
| 942 | #define SMB2_INDEX_SPECIFIED 0x04 |
| 943 | #define SMB2_REOPEN 0x10 |
| 944 | |
| 945 | struct smb2_query_directory_req { |
| 946 | struct smb2_hdr hdr; |
| 947 | __le16 StructureSize; /* Must be 33 */ |
| 948 | __u8 FileInformationClass; |
| 949 | __u8 Flags; |
| 950 | __le32 FileIndex; |
| 951 | __le64 PersistentFileId; |
| 952 | __le64 VolatileFileId; |
| 953 | __le16 FileNameOffset; |
| 954 | __le16 FileNameLength; |
| 955 | __le32 OutputBufferLength; |
| 956 | __u8 Buffer[1]; |
| 957 | } __packed; |
| 958 | |
| 959 | struct smb2_query_directory_rsp { |
| 960 | struct smb2_hdr hdr; |
| 961 | __le16 StructureSize; /* Must be 9 */ |
| 962 | __le16 OutputBufferOffset; |
| 963 | __le32 OutputBufferLength; |
| 964 | __u8 Buffer[1]; |
| 965 | } __packed; |
| 966 | |
| 967 | /* Possible InfoType values */ |
| 968 | #define SMB2_O_INFO_FILE 0x01 |
| 969 | #define SMB2_O_INFO_FILESYSTEM 0x02 |
| 970 | #define SMB2_O_INFO_SECURITY 0x03 |
| 971 | #define SMB2_O_INFO_QUOTA 0x04 |
| 972 | |
| 973 | /* Security info type additionalinfo flags. See MS-SMB2 (2.2.37) or MS-DTYP */ |
| 974 | #define OWNER_SECINFO 0x00000001 |
| 975 | #define GROUP_SECINFO 0x00000002 |
| 976 | #define DACL_SECINFO 0x00000004 |
| 977 | #define SACL_SECINFO 0x00000008 |
| 978 | #define LABEL_SECINFO 0x00000010 |
| 979 | #define ATTRIBUTE_SECINFO 0x00000020 |
| 980 | #define SCOPE_SECINFO 0x00000040 |
| 981 | #define BACKUP_SECINFO 0x00010000 |
| 982 | #define UNPROTECTED_SACL_SECINFO 0x10000000 |
| 983 | #define UNPROTECTED_DACL_SECINFO 0x20000000 |
| 984 | #define PROTECTED_SACL_SECINFO 0x40000000 |
| 985 | #define PROTECTED_DACL_SECINFO 0x80000000 |
| 986 | |
| 987 | struct smb2_query_info_req { |
| 988 | struct smb2_hdr hdr; |
| 989 | __le16 StructureSize; /* Must be 41 */ |
| 990 | __u8 InfoType; |
| 991 | __u8 FileInfoClass; |
| 992 | __le32 OutputBufferLength; |
| 993 | __le16 InputBufferOffset; |
| 994 | __u16 Reserved; |
| 995 | __le32 InputBufferLength; |
| 996 | __le32 AdditionalInformation; |
| 997 | __le32 Flags; |
| 998 | __le64 PersistentFileId; |
| 999 | __le64 VolatileFileId; |
| 1000 | __u8 Buffer[1]; |
| 1001 | } __packed; |
| 1002 | |
| 1003 | struct smb2_query_info_rsp { |
| 1004 | struct smb2_hdr hdr; |
| 1005 | __le16 StructureSize; /* Must be 9 */ |
| 1006 | __le16 OutputBufferOffset; |
| 1007 | __le32 OutputBufferLength; |
| 1008 | __u8 Buffer[1]; |
| 1009 | } __packed; |
| 1010 | |
| 1011 | struct smb2_set_info_req { |
| 1012 | struct smb2_hdr hdr; |
| 1013 | __le16 StructureSize; /* Must be 33 */ |
| 1014 | __u8 InfoType; |
| 1015 | __u8 FileInfoClass; |
| 1016 | __le32 BufferLength; |
| 1017 | __le16 BufferOffset; |
| 1018 | __u16 Reserved; |
| 1019 | __le32 AdditionalInformation; |
| 1020 | __le64 PersistentFileId; |
| 1021 | __le64 VolatileFileId; |
| 1022 | __u8 Buffer[1]; |
| 1023 | } __packed; |
| 1024 | |
| 1025 | struct smb2_set_info_rsp { |
| 1026 | struct smb2_hdr hdr; |
| 1027 | __le16 StructureSize; /* Must be 2 */ |
| 1028 | } __packed; |
| 1029 | |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 1030 | /* FILE Info response size */ |
| 1031 | #define FILE_DIRECTORY_INFORMATION_SIZE 1 |
| 1032 | #define FILE_FULL_DIRECTORY_INFORMATION_SIZE 2 |
| 1033 | #define FILE_BOTH_DIRECTORY_INFORMATION_SIZE 3 |
| 1034 | #define FILE_BASIC_INFORMATION_SIZE 40 |
| 1035 | #define FILE_STANDARD_INFORMATION_SIZE 24 |
| 1036 | #define FILE_INTERNAL_INFORMATION_SIZE 8 |
| 1037 | #define FILE_EA_INFORMATION_SIZE 4 |
| 1038 | #define FILE_ACCESS_INFORMATION_SIZE 4 |
| 1039 | #define FILE_NAME_INFORMATION_SIZE 9 |
| 1040 | #define FILE_RENAME_INFORMATION_SIZE 10 |
| 1041 | #define FILE_LINK_INFORMATION_SIZE 11 |
| 1042 | #define FILE_NAMES_INFORMATION_SIZE 12 |
| 1043 | #define FILE_DISPOSITION_INFORMATION_SIZE 13 |
| 1044 | #define FILE_POSITION_INFORMATION_SIZE 14 |
| 1045 | #define FILE_FULL_EA_INFORMATION_SIZE 15 |
| 1046 | #define FILE_MODE_INFORMATION_SIZE 4 |
| 1047 | #define FILE_ALIGNMENT_INFORMATION_SIZE 4 |
| 1048 | #define FILE_ALL_INFORMATION_SIZE 104 |
| 1049 | #define FILE_ALLOCATION_INFORMATION_SIZE 19 |
| 1050 | #define FILE_END_OF_FILE_INFORMATION_SIZE 20 |
| 1051 | #define FILE_ALTERNATE_NAME_INFORMATION_SIZE 8 |
| 1052 | #define FILE_STREAM_INFORMATION_SIZE 32 |
| 1053 | #define FILE_PIPE_INFORMATION_SIZE 23 |
| 1054 | #define FILE_PIPE_LOCAL_INFORMATION_SIZE 24 |
| 1055 | #define FILE_PIPE_REMOTE_INFORMATION_SIZE 25 |
| 1056 | #define FILE_MAILSLOT_QUERY_INFORMATION_SIZE 26 |
| 1057 | #define FILE_MAILSLOT_SET_INFORMATION_SIZE 27 |
| 1058 | #define FILE_COMPRESSION_INFORMATION_SIZE 16 |
| 1059 | #define FILE_OBJECT_ID_INFORMATION_SIZE 29 |
| 1060 | /* Number 30 not defined in documents */ |
| 1061 | #define FILE_MOVE_CLUSTER_INFORMATION_SIZE 31 |
| 1062 | #define FILE_QUOTA_INFORMATION_SIZE 32 |
| 1063 | #define FILE_REPARSE_POINT_INFORMATION_SIZE 33 |
| 1064 | #define FILE_NETWORK_OPEN_INFORMATION_SIZE 56 |
| 1065 | #define FILE_ATTRIBUTE_TAG_INFORMATION_SIZE 8 |
| 1066 | |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 1067 | /* FS Info response size */ |
| 1068 | #define FS_DEVICE_INFORMATION_SIZE 8 |
| 1069 | #define FS_ATTRIBUTE_INFORMATION_SIZE 16 |
| 1070 | #define FS_VOLUME_INFORMATION_SIZE 24 |
| 1071 | #define FS_SIZE_INFORMATION_SIZE 24 |
| 1072 | #define FS_FULL_SIZE_INFORMATION_SIZE 32 |
| 1073 | #define FS_SECTOR_SIZE_INFORMATION_SIZE 28 |
| 1074 | #define FS_OBJECT_ID_INFORMATION_SIZE 64 |
| 1075 | #define FS_CONTROL_INFORMATION_SIZE 48 |
| 1076 | #define FS_POSIX_INFORMATION_SIZE 56 |
| 1077 | |
| 1078 | /* FS_ATTRIBUTE_File_System_Name */ |
| 1079 | #define FS_TYPE_SUPPORT_SIZE 44 |
| 1080 | struct fs_type_info { |
| 1081 | char *fs_name; |
| 1082 | long magic_number; |
| 1083 | } __packed; |
| 1084 | |
| 1085 | struct smb2_oplock_break { |
| 1086 | struct smb2_hdr hdr; |
| 1087 | __le16 StructureSize; /* Must be 24 */ |
| 1088 | __u8 OplockLevel; |
| 1089 | __u8 Reserved; |
| 1090 | __le32 Reserved2; |
| 1091 | __le64 PersistentFid; |
| 1092 | __le64 VolatileFid; |
| 1093 | } __packed; |
| 1094 | |
| 1095 | #define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01) |
| 1096 | |
| 1097 | struct smb2_lease_break { |
| 1098 | struct smb2_hdr hdr; |
| 1099 | __le16 StructureSize; /* Must be 44 */ |
Namjae Jeon | ade62d8 | 2021-06-07 09:22:22 +0900 | [diff] [blame] | 1100 | __le16 Epoch; |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 1101 | __le32 Flags; |
| 1102 | __u8 LeaseKey[16]; |
| 1103 | __le32 CurrentLeaseState; |
| 1104 | __le32 NewLeaseState; |
| 1105 | __le32 BreakReason; |
| 1106 | __le32 AccessMaskHint; |
| 1107 | __le32 ShareMaskHint; |
| 1108 | } __packed; |
| 1109 | |
| 1110 | struct smb2_lease_ack { |
| 1111 | struct smb2_hdr hdr; |
| 1112 | __le16 StructureSize; /* Must be 36 */ |
| 1113 | __le16 Reserved; |
| 1114 | __le32 Flags; |
| 1115 | __u8 LeaseKey[16]; |
| 1116 | __le32 LeaseState; |
| 1117 | __le64 LeaseDuration; |
| 1118 | } __packed; |
| 1119 | |
| 1120 | /* |
| 1121 | * PDU infolevel structure definitions |
| 1122 | * BB consider moving to a different header |
| 1123 | */ |
| 1124 | |
| 1125 | /* File System Information Classes */ |
| 1126 | #define FS_VOLUME_INFORMATION 1 /* Query */ |
| 1127 | #define FS_LABEL_INFORMATION 2 /* Set */ |
| 1128 | #define FS_SIZE_INFORMATION 3 /* Query */ |
| 1129 | #define FS_DEVICE_INFORMATION 4 /* Query */ |
| 1130 | #define FS_ATTRIBUTE_INFORMATION 5 /* Query */ |
| 1131 | #define FS_CONTROL_INFORMATION 6 /* Query, Set */ |
| 1132 | #define FS_FULL_SIZE_INFORMATION 7 /* Query */ |
| 1133 | #define FS_OBJECT_ID_INFORMATION 8 /* Query, Set */ |
| 1134 | #define FS_DRIVER_PATH_INFORMATION 9 /* Query */ |
| 1135 | #define FS_SECTOR_SIZE_INFORMATION 11 /* SMB3 or later. Query */ |
| 1136 | #define FS_POSIX_INFORMATION 100 /* SMB3.1.1 POSIX. Query */ |
| 1137 | |
| 1138 | struct smb2_fs_full_size_info { |
| 1139 | __le64 TotalAllocationUnits; |
| 1140 | __le64 CallerAvailableAllocationUnits; |
| 1141 | __le64 ActualAvailableAllocationUnits; |
| 1142 | __le32 SectorsPerAllocationUnit; |
| 1143 | __le32 BytesPerSector; |
| 1144 | } __packed; |
| 1145 | |
| 1146 | #define SSINFO_FLAGS_ALIGNED_DEVICE 0x00000001 |
| 1147 | #define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE 0x00000002 |
| 1148 | #define SSINFO_FLAGS_NO_SEEK_PENALTY 0x00000004 |
| 1149 | #define SSINFO_FLAGS_TRIM_ENABLED 0x00000008 |
| 1150 | |
| 1151 | /* sector size info struct */ |
| 1152 | struct smb3_fs_ss_info { |
| 1153 | __le32 LogicalBytesPerSector; |
| 1154 | __le32 PhysicalBytesPerSectorForAtomicity; |
| 1155 | __le32 PhysicalBytesPerSectorForPerf; |
| 1156 | __le32 FSEffPhysicalBytesPerSectorForAtomicity; |
| 1157 | __le32 Flags; |
| 1158 | __le32 ByteOffsetForSectorAlignment; |
| 1159 | __le32 ByteOffsetForPartitionAlignment; |
| 1160 | } __packed; |
| 1161 | |
| 1162 | /* File System Control Information */ |
| 1163 | struct smb2_fs_control_info { |
| 1164 | __le64 FreeSpaceStartFiltering; |
| 1165 | __le64 FreeSpaceThreshold; |
| 1166 | __le64 FreeSpaceStopFiltering; |
| 1167 | __le64 DefaultQuotaThreshold; |
| 1168 | __le64 DefaultQuotaLimit; |
| 1169 | __le32 FileSystemControlFlags; |
| 1170 | __le32 Padding; |
| 1171 | } __packed; |
| 1172 | |
| 1173 | /* partial list of QUERY INFO levels */ |
| 1174 | #define FILE_DIRECTORY_INFORMATION 1 |
| 1175 | #define FILE_FULL_DIRECTORY_INFORMATION 2 |
| 1176 | #define FILE_BOTH_DIRECTORY_INFORMATION 3 |
| 1177 | #define FILE_BASIC_INFORMATION 4 |
| 1178 | #define FILE_STANDARD_INFORMATION 5 |
| 1179 | #define FILE_INTERNAL_INFORMATION 6 |
| 1180 | #define FILE_EA_INFORMATION 7 |
| 1181 | #define FILE_ACCESS_INFORMATION 8 |
| 1182 | #define FILE_NAME_INFORMATION 9 |
| 1183 | #define FILE_RENAME_INFORMATION 10 |
| 1184 | #define FILE_LINK_INFORMATION 11 |
| 1185 | #define FILE_NAMES_INFORMATION 12 |
| 1186 | #define FILE_DISPOSITION_INFORMATION 13 |
| 1187 | #define FILE_POSITION_INFORMATION 14 |
| 1188 | #define FILE_FULL_EA_INFORMATION 15 |
| 1189 | #define FILE_MODE_INFORMATION 16 |
| 1190 | #define FILE_ALIGNMENT_INFORMATION 17 |
| 1191 | #define FILE_ALL_INFORMATION 18 |
| 1192 | #define FILE_ALLOCATION_INFORMATION 19 |
| 1193 | #define FILE_END_OF_FILE_INFORMATION 20 |
| 1194 | #define FILE_ALTERNATE_NAME_INFORMATION 21 |
| 1195 | #define FILE_STREAM_INFORMATION 22 |
| 1196 | #define FILE_PIPE_INFORMATION 23 |
| 1197 | #define FILE_PIPE_LOCAL_INFORMATION 24 |
| 1198 | #define FILE_PIPE_REMOTE_INFORMATION 25 |
| 1199 | #define FILE_MAILSLOT_QUERY_INFORMATION 26 |
| 1200 | #define FILE_MAILSLOT_SET_INFORMATION 27 |
| 1201 | #define FILE_COMPRESSION_INFORMATION 28 |
| 1202 | #define FILE_OBJECT_ID_INFORMATION 29 |
| 1203 | /* Number 30 not defined in documents */ |
| 1204 | #define FILE_MOVE_CLUSTER_INFORMATION 31 |
| 1205 | #define FILE_QUOTA_INFORMATION 32 |
| 1206 | #define FILE_REPARSE_POINT_INFORMATION 33 |
| 1207 | #define FILE_NETWORK_OPEN_INFORMATION 34 |
| 1208 | #define FILE_ATTRIBUTE_TAG_INFORMATION 35 |
| 1209 | #define FILE_TRACKING_INFORMATION 36 |
| 1210 | #define FILEID_BOTH_DIRECTORY_INFORMATION 37 |
| 1211 | #define FILEID_FULL_DIRECTORY_INFORMATION 38 |
| 1212 | #define FILE_VALID_DATA_LENGTH_INFORMATION 39 |
| 1213 | #define FILE_SHORT_NAME_INFORMATION 40 |
| 1214 | #define FILE_SFIO_RESERVE_INFORMATION 44 |
| 1215 | #define FILE_SFIO_VOLUME_INFORMATION 45 |
| 1216 | #define FILE_HARD_LINK_INFORMATION 46 |
| 1217 | #define FILE_NORMALIZED_NAME_INFORMATION 48 |
| 1218 | #define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50 |
| 1219 | #define FILE_STANDARD_LINK_INFORMATION 54 |
| 1220 | |
| 1221 | #define OP_BREAK_STRUCT_SIZE_20 24 |
| 1222 | #define OP_BREAK_STRUCT_SIZE_21 36 |
| 1223 | |
| 1224 | struct smb2_file_access_info { |
| 1225 | __le32 AccessFlags; |
| 1226 | } __packed; |
| 1227 | |
| 1228 | struct smb2_file_alignment_info { |
| 1229 | __le32 AlignmentRequirement; |
| 1230 | } __packed; |
| 1231 | |
| 1232 | struct smb2_file_internal_info { |
| 1233 | __le64 IndexNumber; |
| 1234 | } __packed; /* level 6 Query */ |
| 1235 | |
| 1236 | struct smb2_file_rename_info { /* encoding of request for level 10 */ |
| 1237 | __u8 ReplaceIfExists; /* 1 = replace existing target with new */ |
| 1238 | /* 0 = fail if target already exists */ |
| 1239 | __u8 Reserved[7]; |
| 1240 | __u64 RootDirectory; /* MBZ for network operations (why says spec?) */ |
| 1241 | __le32 FileNameLength; |
| 1242 | char FileName[0]; /* New name to be assigned */ |
| 1243 | } __packed; /* level 10 Set */ |
| 1244 | |
| 1245 | struct smb2_file_link_info { /* encoding of request for level 11 */ |
| 1246 | __u8 ReplaceIfExists; /* 1 = replace existing link with new */ |
| 1247 | /* 0 = fail if link already exists */ |
| 1248 | __u8 Reserved[7]; |
| 1249 | __u64 RootDirectory; /* MBZ for network operations (why says spec?) */ |
| 1250 | __le32 FileNameLength; |
| 1251 | char FileName[0]; /* Name to be assigned to new link */ |
| 1252 | } __packed; /* level 11 Set */ |
| 1253 | |
| 1254 | /* |
| 1255 | * This level 18, although with struct with same name is different from cifs |
| 1256 | * level 0x107. Level 0x107 has an extra u64 between AccessFlags and |
| 1257 | * CurrentByteOffset. |
| 1258 | */ |
| 1259 | struct smb2_file_all_info { /* data block encoding of response to level 18 */ |
| 1260 | __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */ |
| 1261 | __le64 LastAccessTime; |
| 1262 | __le64 LastWriteTime; |
| 1263 | __le64 ChangeTime; |
| 1264 | __le32 Attributes; |
| 1265 | __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */ |
| 1266 | __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */ |
| 1267 | __le64 EndOfFile; /* size ie offset to first free byte in file */ |
| 1268 | __le32 NumberOfLinks; /* hard links */ |
| 1269 | __u8 DeletePending; |
| 1270 | __u8 Directory; |
| 1271 | __u16 Pad2; /* End of FILE_STANDARD_INFO equivalent */ |
| 1272 | __le64 IndexNumber; |
| 1273 | __le32 EASize; |
| 1274 | __le32 AccessFlags; |
| 1275 | __le64 CurrentByteOffset; |
| 1276 | __le32 Mode; |
| 1277 | __le32 AlignmentRequirement; |
| 1278 | __le32 FileNameLength; |
| 1279 | char FileName[1]; |
| 1280 | } __packed; /* level 18 Query */ |
| 1281 | |
Namjae Jeon | 88d3005 | 2021-09-29 15:37:18 +0900 | [diff] [blame] | 1282 | struct smb2_file_basic_info { /* data block encoding of response to level 18 */ |
| 1283 | __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */ |
| 1284 | __le64 LastAccessTime; |
| 1285 | __le64 LastWriteTime; |
| 1286 | __le64 ChangeTime; |
| 1287 | __le32 Attributes; |
| 1288 | __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */ |
| 1289 | } __packed; |
| 1290 | |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 1291 | struct smb2_file_alt_name_info { |
| 1292 | __le32 FileNameLength; |
| 1293 | char FileName[0]; |
| 1294 | } __packed; |
| 1295 | |
| 1296 | struct smb2_file_stream_info { |
| 1297 | __le32 NextEntryOffset; |
| 1298 | __le32 StreamNameLength; |
| 1299 | __le64 StreamSize; |
| 1300 | __le64 StreamAllocationSize; |
| 1301 | char StreamName[0]; |
| 1302 | } __packed; |
| 1303 | |
| 1304 | struct smb2_file_eof_info { /* encoding of request for level 10 */ |
| 1305 | __le64 EndOfFile; /* new end of file value */ |
| 1306 | } __packed; /* level 20 Set */ |
| 1307 | |
| 1308 | struct smb2_file_ntwrk_info { |
| 1309 | __le64 CreationTime; |
| 1310 | __le64 LastAccessTime; |
| 1311 | __le64 LastWriteTime; |
| 1312 | __le64 ChangeTime; |
| 1313 | __le64 AllocationSize; |
| 1314 | __le64 EndOfFile; |
| 1315 | __le32 Attributes; |
| 1316 | __le32 Reserved; |
| 1317 | } __packed; |
| 1318 | |
| 1319 | struct smb2_file_standard_info { |
| 1320 | __le64 AllocationSize; |
| 1321 | __le64 EndOfFile; |
| 1322 | __le32 NumberOfLinks; /* hard links */ |
| 1323 | __u8 DeletePending; |
| 1324 | __u8 Directory; |
| 1325 | __le16 Reserved; |
| 1326 | } __packed; /* level 18 Query */ |
| 1327 | |
| 1328 | struct smb2_file_ea_info { |
| 1329 | __le32 EASize; |
| 1330 | } __packed; |
| 1331 | |
| 1332 | struct smb2_file_alloc_info { |
| 1333 | __le64 AllocationSize; |
| 1334 | } __packed; |
| 1335 | |
| 1336 | struct smb2_file_disposition_info { |
| 1337 | __u8 DeletePending; |
| 1338 | } __packed; |
| 1339 | |
| 1340 | struct smb2_file_pos_info { |
| 1341 | __le64 CurrentByteOffset; |
| 1342 | } __packed; |
| 1343 | |
| 1344 | #define FILE_MODE_INFO_MASK cpu_to_le32(0x0000103e) |
| 1345 | |
| 1346 | struct smb2_file_mode_info { |
| 1347 | __le32 Mode; |
| 1348 | } __packed; |
| 1349 | |
| 1350 | #define COMPRESSION_FORMAT_NONE 0x0000 |
| 1351 | #define COMPRESSION_FORMAT_LZNT1 0x0002 |
| 1352 | |
| 1353 | struct smb2_file_comp_info { |
| 1354 | __le64 CompressedFileSize; |
| 1355 | __le16 CompressionFormat; |
| 1356 | __u8 CompressionUnitShift; |
| 1357 | __u8 ChunkShift; |
| 1358 | __u8 ClusterShift; |
| 1359 | __u8 Reserved[3]; |
| 1360 | } __packed; |
| 1361 | |
| 1362 | struct smb2_file_attr_tag_info { |
| 1363 | __le32 FileAttributes; |
| 1364 | __le32 ReparseTag; |
| 1365 | } __packed; |
| 1366 | |
| 1367 | #define SL_RESTART_SCAN 0x00000001 |
| 1368 | #define SL_RETURN_SINGLE_ENTRY 0x00000002 |
| 1369 | #define SL_INDEX_SPECIFIED 0x00000004 |
| 1370 | |
| 1371 | struct smb2_ea_info_req { |
| 1372 | __le32 NextEntryOffset; |
| 1373 | __u8 EaNameLength; |
| 1374 | char name[1]; |
| 1375 | } __packed; /* level 15 Query */ |
| 1376 | |
| 1377 | struct smb2_ea_info { |
| 1378 | __le32 NextEntryOffset; |
| 1379 | __u8 Flags; |
| 1380 | __u8 EaNameLength; |
| 1381 | __le16 EaValueLength; |
| 1382 | char name[1]; |
| 1383 | /* optionally followed by value */ |
| 1384 | } __packed; /* level 15 Query */ |
| 1385 | |
| 1386 | struct create_ea_buf_req { |
| 1387 | struct create_context ccontext; |
| 1388 | __u8 Name[8]; |
| 1389 | struct smb2_ea_info ea; |
| 1390 | } __packed; |
| 1391 | |
| 1392 | struct create_sd_buf_req { |
| 1393 | struct create_context ccontext; |
| 1394 | __u8 Name[8]; |
| 1395 | struct smb_ntsd ntsd; |
| 1396 | } __packed; |
| 1397 | |
| 1398 | /* Find File infolevels */ |
| 1399 | #define SMB_FIND_FILE_POSIX_INFO 0x064 |
| 1400 | |
| 1401 | /* Level 100 query info */ |
| 1402 | struct smb311_posix_qinfo { |
| 1403 | __le64 CreationTime; |
| 1404 | __le64 LastAccessTime; |
| 1405 | __le64 LastWriteTime; |
| 1406 | __le64 ChangeTime; |
| 1407 | __le64 EndOfFile; |
| 1408 | __le64 AllocationSize; |
| 1409 | __le32 DosAttributes; |
| 1410 | __le64 Inode; |
| 1411 | __le32 DeviceId; |
| 1412 | __le32 Zero; |
| 1413 | /* beginning of POSIX Create Context Response */ |
| 1414 | __le32 HardLinks; |
| 1415 | __le32 ReparseTag; |
| 1416 | __le32 Mode; |
| 1417 | u8 Sids[]; |
| 1418 | /* |
| 1419 | * var sized owner SID |
| 1420 | * var sized group SID |
| 1421 | * le32 filenamelength |
| 1422 | * u8 filename[] |
| 1423 | */ |
| 1424 | } __packed; |
| 1425 | |
| 1426 | struct smb2_posix_info { |
| 1427 | __le32 NextEntryOffset; |
| 1428 | __u32 Ignored; |
| 1429 | __le64 CreationTime; |
| 1430 | __le64 LastAccessTime; |
| 1431 | __le64 LastWriteTime; |
| 1432 | __le64 ChangeTime; |
| 1433 | __le64 EndOfFile; |
| 1434 | __le64 AllocationSize; |
| 1435 | __le32 DosAttributes; |
| 1436 | __le64 Inode; |
| 1437 | __le32 DeviceId; |
| 1438 | __le32 Zero; |
| 1439 | /* beginning of POSIX Create Context Response */ |
| 1440 | __le32 HardLinks; |
| 1441 | __le32 ReparseTag; |
| 1442 | __le32 Mode; |
| 1443 | u8 SidBuffer[40]; |
| 1444 | __le32 name_len; |
| 1445 | u8 name[1]; |
| 1446 | /* |
| 1447 | * var sized owner SID |
| 1448 | * var sized group SID |
| 1449 | * le32 filenamelength |
| 1450 | * u8 filename[] |
| 1451 | */ |
| 1452 | } __packed; |
| 1453 | |
| 1454 | /* functions */ |
Namjae Jeon | 64b39f4 | 2021-03-30 14:25:35 +0900 | [diff] [blame] | 1455 | void init_smb2_1_server(struct ksmbd_conn *conn); |
| 1456 | void init_smb3_0_server(struct ksmbd_conn *conn); |
| 1457 | void init_smb3_02_server(struct ksmbd_conn *conn); |
| 1458 | int init_smb3_11_server(struct ksmbd_conn *conn); |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 1459 | |
Namjae Jeon | 64b39f4 | 2021-03-30 14:25:35 +0900 | [diff] [blame] | 1460 | void init_smb2_max_read_size(unsigned int sz); |
| 1461 | void init_smb2_max_write_size(unsigned int sz); |
| 1462 | void init_smb2_max_trans_size(unsigned int sz); |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 1463 | |
Namjae Jeon | f4228b6 | 2021-08-12 10:16:40 +0900 | [diff] [blame] | 1464 | bool is_smb2_neg_cmd(struct ksmbd_work *work); |
| 1465 | bool is_smb2_rsp(struct ksmbd_work *work); |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 1466 | |
Namjae Jeon | 64b39f4 | 2021-03-30 14:25:35 +0900 | [diff] [blame] | 1467 | u16 get_smb2_cmd_val(struct ksmbd_work *work); |
| 1468 | void set_smb2_rsp_status(struct ksmbd_work *work, __le32 err); |
| 1469 | int init_smb2_rsp_hdr(struct ksmbd_work *work); |
| 1470 | int smb2_allocate_rsp_buf(struct ksmbd_work *work); |
| 1471 | bool is_chained_smb2_message(struct ksmbd_work *work); |
| 1472 | int init_smb2_neg_rsp(struct ksmbd_work *work); |
| 1473 | void smb2_set_err_rsp(struct ksmbd_work *work); |
| 1474 | int smb2_check_user_session(struct ksmbd_work *work); |
| 1475 | int smb2_get_ksmbd_tcon(struct ksmbd_work *work); |
| 1476 | bool smb2_is_sign_req(struct ksmbd_work *work, unsigned int command); |
| 1477 | int smb2_check_sign_req(struct ksmbd_work *work); |
| 1478 | void smb2_set_sign_rsp(struct ksmbd_work *work); |
| 1479 | int smb3_check_sign_req(struct ksmbd_work *work); |
| 1480 | void smb3_set_sign_rsp(struct ksmbd_work *work); |
| 1481 | int find_matching_smb2_dialect(int start_index, __le16 *cli_dialects, |
Hyunchul Lee | d7e5852 | 2021-05-29 09:59:59 +0900 | [diff] [blame] | 1482 | __le16 dialects_count); |
Namjae Jeon | 64b39f4 | 2021-03-30 14:25:35 +0900 | [diff] [blame] | 1483 | struct file_lock *smb_flock_init(struct file *f); |
| 1484 | int setup_async_work(struct ksmbd_work *work, void (*fn)(void **), |
Hyunchul Lee | d7e5852 | 2021-05-29 09:59:59 +0900 | [diff] [blame] | 1485 | void **arg); |
Namjae Jeon | 64b39f4 | 2021-03-30 14:25:35 +0900 | [diff] [blame] | 1486 | void smb2_send_interim_resp(struct ksmbd_work *work, __le32 status); |
Namjae Jeon | f5a544e | 2021-06-18 10:04:19 +0900 | [diff] [blame] | 1487 | struct channel *lookup_chann_list(struct ksmbd_session *sess, |
| 1488 | struct ksmbd_conn *conn); |
Namjae Jeon | 64b39f4 | 2021-03-30 14:25:35 +0900 | [diff] [blame] | 1489 | void smb3_preauth_hash_rsp(struct ksmbd_work *work); |
Namjae Jeon | f4228b6 | 2021-08-12 10:16:40 +0900 | [diff] [blame] | 1490 | bool smb3_is_transform_hdr(void *buf); |
Namjae Jeon | 64b39f4 | 2021-03-30 14:25:35 +0900 | [diff] [blame] | 1491 | int smb3_decrypt_req(struct ksmbd_work *work); |
| 1492 | int smb3_encrypt_resp(struct ksmbd_work *work); |
| 1493 | bool smb3_11_final_sess_setup_resp(struct ksmbd_work *work); |
| 1494 | int smb2_set_rsp_credits(struct ksmbd_work *work); |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 1495 | |
| 1496 | /* smb2 misc functions */ |
Namjae Jeon | 64b39f4 | 2021-03-30 14:25:35 +0900 | [diff] [blame] | 1497 | int ksmbd_smb2_check_message(struct ksmbd_work *work); |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 1498 | |
| 1499 | /* smb2 command handlers */ |
Namjae Jeon | 64b39f4 | 2021-03-30 14:25:35 +0900 | [diff] [blame] | 1500 | int smb2_handle_negotiate(struct ksmbd_work *work); |
| 1501 | int smb2_negotiate_request(struct ksmbd_work *work); |
| 1502 | int smb2_sess_setup(struct ksmbd_work *work); |
| 1503 | int smb2_tree_connect(struct ksmbd_work *work); |
| 1504 | int smb2_tree_disconnect(struct ksmbd_work *work); |
| 1505 | int smb2_session_logoff(struct ksmbd_work *work); |
| 1506 | int smb2_open(struct ksmbd_work *work); |
| 1507 | int smb2_query_info(struct ksmbd_work *work); |
| 1508 | int smb2_query_dir(struct ksmbd_work *work); |
| 1509 | int smb2_close(struct ksmbd_work *work); |
| 1510 | int smb2_echo(struct ksmbd_work *work); |
| 1511 | int smb2_set_info(struct ksmbd_work *work); |
| 1512 | int smb2_read(struct ksmbd_work *work); |
| 1513 | int smb2_write(struct ksmbd_work *work); |
| 1514 | int smb2_flush(struct ksmbd_work *work); |
| 1515 | int smb2_cancel(struct ksmbd_work *work); |
| 1516 | int smb2_lock(struct ksmbd_work *work); |
| 1517 | int smb2_ioctl(struct ksmbd_work *work); |
| 1518 | int smb2_oplock_break(struct ksmbd_work *work); |
| 1519 | int smb2_notify(struct ksmbd_work *ksmbd_work); |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 1520 | |
Namjae Jeon | cb45172 | 2021-11-03 08:08:44 +0900 | [diff] [blame] | 1521 | /* |
| 1522 | * Get the body of the smb2 message excluding the 4 byte rfc1002 headers |
| 1523 | * from request/response buffer. |
| 1524 | */ |
| 1525 | static inline void *smb2_get_msg(void *buf) |
| 1526 | { |
| 1527 | return buf + 4; |
| 1528 | } |
| 1529 | |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 1530 | #endif /* _SMB2PDU_H */ |