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 /* 182 * PDU query infolevel structure definitions 183 * BB consider moving to a different header 184 */ 185 186 struct smb2_file_full_ea_info { /* encoding of response for level 15 */ 187 __le32 next_entry_offset; 188 __u8 flags; 189 __u8 ea_name_length; 190 __le16 ea_value_length; 191 char ea_data[]; /* \0 terminated name plus value */ 192 } __packed; /* level 15 Set */ 193 194 struct smb2_file_reparse_point_info { 195 __le64 IndexNumber; 196 __le32 Tag; 197 } __packed; 198 199 /* See MS-FSCC 2.4.26 */ 200 struct smb2_file_id_information { 201 __le64 VolumeSerialNumber; 202 __u64 PersistentFileId; /* opaque endianness */ 203 __u64 VolatileFileId; /* opaque endianness */ 204 } __packed; /* level 59 */ 205 206 /* See MS-FSCC 2.4.18 */ 207 struct smb2_file_id_extd_directory_info { 208 __le32 NextEntryOffset; 209 __u32 FileIndex; 210 __le64 CreationTime; 211 __le64 LastAccessTime; 212 __le64 LastWriteTime; 213 __le64 ChangeTime; 214 __le64 EndOfFile; 215 __le64 AllocationSize; 216 __le32 FileAttributes; 217 __le32 FileNameLength; 218 __le32 EaSize; /* EA size */ 219 __le32 ReparsePointTag; /* valid if FILE_ATTR_REPARSE_POINT set in FileAttributes */ 220 __le64 UniqueId; /* inode num - le since Samba puts ino in low 32 bit */ 221 char FileName[]; 222 } __packed; /* level 60 */ 223 224 extern char smb2_padding[7]; 225 226 /* 227 * See POSIX-SMB2 2.2.14.2.16 228 * Link: https://gitlab.com/samba-team/smb3-posix-spec/-/blob/master/smb3_posix_extensions.md 229 */ 230 struct create_posix_rsp { 231 u32 nlink; 232 u32 reparse_tag; 233 u32 mode; 234 struct smb_sid owner; /* var-sized on the wire */ 235 struct smb_sid group; /* var-sized on the wire */ 236 } __packed; 237 238 #define SMB2_QUERY_DIRECTORY_IOV_SIZE 2 239 240 /* 241 * SMB2-only POSIX info level for query dir 242 * 243 * See posix_info_sid_size(), posix_info_extra_size() and 244 * posix_info_parse() to help with the handling of this struct. 245 */ 246 struct smb2_posix_info { 247 __le32 NextEntryOffset; 248 __u32 Ignored; 249 __le64 CreationTime; 250 __le64 LastAccessTime; 251 __le64 LastWriteTime; 252 __le64 ChangeTime; 253 __le64 EndOfFile; 254 __le64 AllocationSize; 255 __le32 DosAttributes; 256 __le64 Inode; 257 __le32 DeviceId; 258 __le32 Zero; 259 /* beginning of POSIX Create Context Response */ 260 __le32 HardLinks; 261 __le32 ReparseTag; 262 __le32 Mode; 263 /* 264 * var sized owner SID 265 * var sized group SID 266 * le32 filenamelength 267 * u8 filename[] 268 */ 269 } __packed; 270 271 /* 272 * Parsed version of the above struct. Allows direct access to the 273 * variable length fields 274 */ 275 struct smb2_posix_info_parsed { 276 const struct smb2_posix_info *base; 277 size_t size; 278 struct smb_sid owner; 279 struct smb_sid group; 280 int name_len; 281 const u8 *name; 282 }; 283 284 struct smb2_create_ea_ctx { 285 struct create_context_hdr ctx; 286 __u8 name[8]; 287 struct smb2_file_full_ea_info ea; 288 } __packed; 289 290 #define SMB2_WSL_XATTR_UID "$LXUID" 291 #define SMB2_WSL_XATTR_GID "$LXGID" 292 #define SMB2_WSL_XATTR_MODE "$LXMOD" 293 #define SMB2_WSL_XATTR_DEV "$LXDEV" 294 #define SMB2_WSL_XATTR_NAME_LEN 6 295 #define SMB2_WSL_NUM_XATTRS 4 296 297 #define SMB2_WSL_XATTR_UID_SIZE 4 298 #define SMB2_WSL_XATTR_GID_SIZE 4 299 #define SMB2_WSL_XATTR_MODE_SIZE 4 300 #define SMB2_WSL_XATTR_DEV_SIZE 8 301 302 #define SMB2_WSL_MIN_QUERY_EA_RESP_SIZE \ 303 (ALIGN((SMB2_WSL_NUM_XATTRS - 1) * \ 304 (SMB2_WSL_XATTR_NAME_LEN + 1 + \ 305 sizeof(struct smb2_file_full_ea_info)), 4) + \ 306 SMB2_WSL_XATTR_NAME_LEN + 1 + sizeof(struct smb2_file_full_ea_info)) 307 308 #define SMB2_WSL_MAX_QUERY_EA_RESP_SIZE \ 309 (ALIGN(SMB2_WSL_MIN_QUERY_EA_RESP_SIZE + \ 310 SMB2_WSL_XATTR_UID_SIZE + \ 311 SMB2_WSL_XATTR_GID_SIZE + \ 312 SMB2_WSL_XATTR_MODE_SIZE + \ 313 SMB2_WSL_XATTR_DEV_SIZE, 4)) 314 315 #endif /* _SMB2PDU_H */ 316