1 /* SPDX-License-Identifier: LGPL-2.1 */ 2 /* 3 * 4 * Copyright (c) International Business Machines Corp., 2009, 2013 5 * Etersoft, 2012 6 * Author(s): Steve French (sfrench@us.ibm.com) 7 * Pavel Shilovsky (pshilovsky@samba.org) 2012 8 * 9 */ 10 11 #ifndef _SMB2PDU_H 12 #define _SMB2PDU_H 13 14 #include <net/sock.h> 15 #include "cifsacl.h" 16 17 /* 52 transform hdr + 64 hdr + 88 create rsp */ 18 #define SMB2_TRANSFORM_HEADER_SIZE 52 19 #define MAX_SMB2_HDR_SIZE 204 20 21 /* The total header size for SMB2 read and write */ 22 #define SMB2_READWRITE_PDU_HEADER_SIZE (48 + sizeof(struct smb2_hdr)) 23 24 /* 25 * Definitions for SMB2 Protocol Data Units (network frames) 26 * 27 * See MS-SMB2.PDF specification for protocol details. 28 * The Naming convention is the lower case version of the SMB2 29 * command code name for the struct. Note that structures must be packed. 30 * 31 */ 32 33 #define COMPOUND_FID 0xFFFFFFFFFFFFFFFFULL 34 35 #define SMB2_SYMLINK_STRUCT_SIZE \ 36 (sizeof(struct smb2_err_rsp) + sizeof(struct smb2_symlink_err_rsp)) 37 38 #define SYMLINK_ERROR_TAG 0x4c4d5953 39 40 struct smb2_symlink_err_rsp { 41 __le32 SymLinkLength; 42 __le32 SymLinkErrorTag; 43 __le32 ReparseTag; 44 __le16 ReparseDataLength; 45 __le16 UnparsedPathLength; 46 __le16 SubstituteNameOffset; 47 __le16 SubstituteNameLength; 48 __le16 PrintNameOffset; 49 __le16 PrintNameLength; 50 __le32 Flags; 51 __u8 PathBuffer[]; 52 } __packed; 53 54 /* SMB 3.1.1 and later dialects. See MS-SMB2 section 2.2.2.1 */ 55 struct smb2_error_context_rsp { 56 __le32 ErrorDataLength; 57 __le32 ErrorId; 58 __u8 ErrorContextData[] __counted_by_le(ErrorDataLength); 59 } __packed; 60 61 /* ErrorId values */ 62 #define SMB2_ERROR_ID_DEFAULT 0x00000000 63 #define SMB2_ERROR_ID_SHARE_REDIRECT cpu_to_le32(0x72645253) /* "rdRS" */ 64 65 /* Defines for Type field below (see MS-SMB2 2.2.2.2.2.1) */ 66 #define MOVE_DST_IPADDR_V4 cpu_to_le32(0x00000001) 67 #define MOVE_DST_IPADDR_V6 cpu_to_le32(0x00000002) 68 69 struct move_dst_ipaddr { 70 __le32 Type; 71 __u32 Reserved; 72 __u8 address[16]; /* IPv4 followed by 12 bytes rsvd or IPv6 address */ 73 } __packed; 74 75 struct share_redirect_error_context_rsp { 76 __le32 StructureSize; 77 __le32 NotificationType; 78 __le32 ResourceNameOffset; 79 __le32 ResourceNameLength; 80 __le16 Reserved; 81 __le16 TargetType; 82 __le32 IPAddrCount; 83 struct move_dst_ipaddr IpAddrMoveList[]; 84 /* __u8 ResourceName[] */ /* Name of share as counted Unicode string */ 85 } __packed; 86 87 /* 88 * Maximum number of iovs we need for an open/create request. 89 * [0] : struct smb2_create_req 90 * [1] : path 91 * [2] : lease context 92 * [3] : durable context 93 * [4] : posix context 94 * [5] : time warp context 95 * [6] : query id context 96 * [7] : create ea context 97 * [8] : compound padding 98 */ 99 #define SMB2_CREATE_IOV_SIZE 9 100 101 /* 102 * Maximum size of a SMB2_CREATE response is 64 (smb2 header) + 103 * 88 (fixed part of create response) + 520 (path) + 208 (contexts) + 104 * 2 bytes of padding. 105 */ 106 #define MAX_SMB2_CREATE_RESPONSE_SIZE 880 107 108 #define SMB2_LEASE_READ_CACHING_HE 0x01 109 #define SMB2_LEASE_HANDLE_CACHING_HE 0x02 110 #define SMB2_LEASE_WRITE_CACHING_HE 0x04 111 112 /* See MS-SMB2 2.2.13.2.5 */ 113 struct crt_twarp_ctxt { 114 struct create_context_hdr ccontext; 115 __u8 Name[8]; 116 __le64 Timestamp; 117 118 } __packed; 119 120 /* See MS-SMB2 2.2.13.2.9 */ 121 struct crt_query_id_ctxt { 122 struct create_context_hdr ccontext; 123 __u8 Name[8]; 124 } __packed; 125 126 struct crt_sd_ctxt { 127 struct create_context_hdr ccontext; 128 __u8 Name[8]; 129 struct smb3_sd sd; 130 } __packed; 131 132 /* See MS-FSCC 2.3.29 and 2.3.30 */ 133 struct get_retrieval_pointer_count_req { 134 __le64 StartingVcn; /* virtual cluster number (signed) */ 135 } __packed; 136 137 struct get_retrieval_pointer_count_rsp { 138 __le32 ExtentCount; 139 } __packed; 140 141 /* 142 * See MS-FSCC 2.3.33 and 2.3.34 143 * request is the same as get_retrieval_point_count_req struct above 144 */ 145 struct smb3_extents { 146 __le64 NextVcn; 147 __le64 Lcn; /* logical cluster number */ 148 } __packed; 149 150 struct get_retrieval_pointers_refcount_rsp { 151 __le32 ExtentCount; 152 __u32 Reserved; 153 __le64 StartingVcn; 154 struct smb3_extents extents[]; 155 } __packed; 156 157 /* See MS-DFSC 2.2.2 */ 158 struct fsctl_get_dfs_referral_req { 159 __le16 MaxReferralLevel; 160 __u8 RequestFileName[]; 161 } __packed; 162 163 /* DFS response is struct get_dfs_refer_rsp */ 164 165 /* See MS-SMB2 2.2.31.3 */ 166 struct network_resiliency_req { 167 __le32 Timeout; 168 __le32 Reserved; 169 } __packed; 170 /* There is no buffer for the response ie no struct network_resiliency_rsp */ 171 172 #define NO_FILE_ID 0xFFFFFFFFFFFFFFFFULL /* general ioctls to srv not to file */ 173 174 /* 175 * Maximum number of iovs we need for an ioctl request. 176 * [0] : struct smb2_ioctl_req 177 * [1] : in_data 178 */ 179 #define SMB2_IOCTL_IOV_SIZE 2 180 181 /* extra iov for the alignment padding smb2_set_next_command() may add */ 182 #define SMB2_QUERY_INFO_IOV_SIZE 2 183 184 /* 185 * PDU query infolevel structure definitions 186 * BB consider moving to a different header 187 */ 188 189 struct smb2_file_full_ea_info { /* encoding of response for level 15 */ 190 __le32 next_entry_offset; 191 __u8 flags; 192 __u8 ea_name_length; 193 __le16 ea_value_length; 194 char ea_data[]; /* \0 terminated name plus value */ 195 } __packed; /* level 15 Set */ 196 197 struct smb2_file_reparse_point_info { 198 __le64 IndexNumber; 199 __le32 Tag; 200 } __packed; 201 202 /* See MS-FSCC 2.4.26 */ 203 struct smb2_file_id_information { 204 __le64 VolumeSerialNumber; 205 __u64 PersistentFileId; /* opaque endianness */ 206 __u64 VolatileFileId; /* opaque endianness */ 207 } __packed; /* level 59 */ 208 209 /* See MS-FSCC 2.4.18 */ 210 struct smb2_file_id_extd_directory_info { 211 __le32 NextEntryOffset; 212 __u32 FileIndex; 213 __le64 CreationTime; 214 __le64 LastAccessTime; 215 __le64 LastWriteTime; 216 __le64 ChangeTime; 217 __le64 EndOfFile; 218 __le64 AllocationSize; 219 __le32 FileAttributes; 220 __le32 FileNameLength; 221 __le32 EaSize; /* EA size */ 222 __le32 ReparsePointTag; /* valid if FILE_ATTR_REPARSE_POINT set in FileAttributes */ 223 __le64 UniqueId; /* inode num - le since Samba puts ino in low 32 bit */ 224 char FileName[]; 225 } __packed; /* level 60 */ 226 227 extern char smb2_padding[7]; 228 229 /* 230 * See POSIX-SMB2 2.1.3.2.1 231 */ 232 struct create_posix_rsp { 233 u32 nlink; 234 u32 reparse_tag; 235 u32 mode; 236 struct smb_sid owner; /* var-sized on the wire */ 237 struct smb_sid group; /* var-sized on the wire */ 238 } __packed; 239 240 #define SMB2_QUERY_DIRECTORY_IOV_SIZE 2 241 242 /* 243 * See POSIX-FSCC 2.2.1 244 * SMB2-only POSIX info level for query dir 245 * 246 * See posix_info_sid_size(), posix_info_extra_size() and 247 * posix_info_parse() to help with the handling of this struct. 248 */ 249 struct smb2_posix_info { 250 __le32 NextEntryOffset; 251 __u32 Ignored; 252 __le64 CreationTime; 253 __le64 LastAccessTime; 254 __le64 LastWriteTime; 255 __le64 ChangeTime; 256 __le64 EndOfFile; 257 __le64 AllocationSize; 258 __le32 DosAttributes; 259 __le64 Inode; 260 __le32 DeviceId; 261 __le32 Zero; 262 /* 263 * Beginning of POSIX Create Context Response 264 * See POSIX-SMB2 2.1.3.2.1 265 */ 266 __le32 HardLinks; 267 __le32 ReparseTag; 268 __le32 Mode; 269 /* 270 * var sized owner SID 271 * var sized group SID 272 * End of POSIX Create Context Response 273 * le32 filenamelength 274 * u8 filename[] 275 */ 276 } __packed; 277 278 /* 279 * Parsed version of the above struct. Allows direct access to the 280 * variable length fields 281 */ 282 struct smb2_posix_info_parsed { 283 const struct smb2_posix_info *base; 284 size_t size; 285 struct smb_sid owner; 286 struct smb_sid group; 287 int name_len; 288 const u8 *name; 289 }; 290 291 struct smb2_create_ea_ctx { 292 struct create_context_hdr ctx; 293 __u8 name[8]; 294 struct smb2_file_full_ea_info ea; 295 } __packed; 296 297 #define SMB2_WSL_XATTR_UID "$LXUID" 298 #define SMB2_WSL_XATTR_GID "$LXGID" 299 #define SMB2_WSL_XATTR_MODE "$LXMOD" 300 #define SMB2_WSL_XATTR_DEV "$LXDEV" 301 #define SMB2_WSL_XATTR_NAME_LEN 6 302 #define SMB2_WSL_NUM_XATTRS 4 303 304 #define SMB2_WSL_XATTR_UID_SIZE 4 305 #define SMB2_WSL_XATTR_GID_SIZE 4 306 #define SMB2_WSL_XATTR_MODE_SIZE 4 307 #define SMB2_WSL_XATTR_DEV_SIZE 8 308 309 #define SMB2_WSL_MIN_QUERY_EA_RESP_SIZE \ 310 (ALIGN((SMB2_WSL_NUM_XATTRS - 1) * \ 311 (SMB2_WSL_XATTR_NAME_LEN + 1 + \ 312 sizeof(struct smb2_file_full_ea_info)), 4) + \ 313 SMB2_WSL_XATTR_NAME_LEN + 1 + sizeof(struct smb2_file_full_ea_info)) 314 315 #define SMB2_WSL_MAX_QUERY_EA_RESP_SIZE \ 316 (ALIGN(SMB2_WSL_MIN_QUERY_EA_RESP_SIZE + \ 317 SMB2_WSL_XATTR_UID_SIZE + \ 318 SMB2_WSL_XATTR_GID_SIZE + \ 319 SMB2_WSL_XATTR_MODE_SIZE + \ 320 SMB2_WSL_XATTR_DEV_SIZE, 4)) 321 322 #endif /* _SMB2PDU_H */ 323