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