smb2pdu.h 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409
  1. /*
  2. * fs/cifs/smb2pdu.h
  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. * This library is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU Lesser General Public License as published
  11. * by the Free Software Foundation; either version 2.1 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  17. * the GNU Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public License
  20. * along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. #ifndef _SMB2PDU_H
  24. #define _SMB2PDU_H
  25. #include <net/sock.h>
  26. /*
  27. * Note that, due to trying to use names similar to the protocol specifications,
  28. * there are many mixed case field names in the structures below. Although
  29. * this does not match typical Linux kernel style, it is necessary to be
  30. * be able to match against the protocol specfication.
  31. *
  32. * SMB2 commands
  33. * Some commands have minimal (wct=0,bcc=0), or uninteresting, responses
  34. * (ie no useful data other than the SMB error code itself) and are marked such.
  35. * Knowing this helps avoid response buffer allocations and copy in some cases.
  36. */
  37. /* List of commands in host endian */
  38. #define SMB2_NEGOTIATE_HE 0x0000
  39. #define SMB2_SESSION_SETUP_HE 0x0001
  40. #define SMB2_LOGOFF_HE 0x0002 /* trivial request/resp */
  41. #define SMB2_TREE_CONNECT_HE 0x0003
  42. #define SMB2_TREE_DISCONNECT_HE 0x0004 /* trivial req/resp */
  43. #define SMB2_CREATE_HE 0x0005
  44. #define SMB2_CLOSE_HE 0x0006
  45. #define SMB2_FLUSH_HE 0x0007 /* trivial resp */
  46. #define SMB2_READ_HE 0x0008
  47. #define SMB2_WRITE_HE 0x0009
  48. #define SMB2_LOCK_HE 0x000A
  49. #define SMB2_IOCTL_HE 0x000B
  50. #define SMB2_CANCEL_HE 0x000C
  51. #define SMB2_ECHO_HE 0x000D
  52. #define SMB2_QUERY_DIRECTORY_HE 0x000E
  53. #define SMB2_CHANGE_NOTIFY_HE 0x000F
  54. #define SMB2_QUERY_INFO_HE 0x0010
  55. #define SMB2_SET_INFO_HE 0x0011
  56. #define SMB2_OPLOCK_BREAK_HE 0x0012
  57. /* The same list in little endian */
  58. #define SMB2_NEGOTIATE cpu_to_le16(SMB2_NEGOTIATE_HE)
  59. #define SMB2_SESSION_SETUP cpu_to_le16(SMB2_SESSION_SETUP_HE)
  60. #define SMB2_LOGOFF cpu_to_le16(SMB2_LOGOFF_HE)
  61. #define SMB2_TREE_CONNECT cpu_to_le16(SMB2_TREE_CONNECT_HE)
  62. #define SMB2_TREE_DISCONNECT cpu_to_le16(SMB2_TREE_DISCONNECT_HE)
  63. #define SMB2_CREATE cpu_to_le16(SMB2_CREATE_HE)
  64. #define SMB2_CLOSE cpu_to_le16(SMB2_CLOSE_HE)
  65. #define SMB2_FLUSH cpu_to_le16(SMB2_FLUSH_HE)
  66. #define SMB2_READ cpu_to_le16(SMB2_READ_HE)
  67. #define SMB2_WRITE cpu_to_le16(SMB2_WRITE_HE)
  68. #define SMB2_LOCK cpu_to_le16(SMB2_LOCK_HE)
  69. #define SMB2_IOCTL cpu_to_le16(SMB2_IOCTL_HE)
  70. #define SMB2_CANCEL cpu_to_le16(SMB2_CANCEL_HE)
  71. #define SMB2_ECHO cpu_to_le16(SMB2_ECHO_HE)
  72. #define SMB2_QUERY_DIRECTORY cpu_to_le16(SMB2_QUERY_DIRECTORY_HE)
  73. #define SMB2_CHANGE_NOTIFY cpu_to_le16(SMB2_CHANGE_NOTIFY_HE)
  74. #define SMB2_QUERY_INFO cpu_to_le16(SMB2_QUERY_INFO_HE)
  75. #define SMB2_SET_INFO cpu_to_le16(SMB2_SET_INFO_HE)
  76. #define SMB2_OPLOCK_BREAK cpu_to_le16(SMB2_OPLOCK_BREAK_HE)
  77. #define SMB2_INTERNAL_CMD cpu_to_le16(0xFFFF)
  78. #define NUMBER_OF_SMB2_COMMANDS 0x0013
  79. /* 52 transform hdr + 64 hdr + 88 create rsp */
  80. #define MAX_SMB2_HDR_SIZE 204
  81. #define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe)
  82. #define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd)
  83. /*
  84. * SMB2 Header Definition
  85. *
  86. * "MBZ" : Must be Zero
  87. * "BB" : BugBug, Something to check/review/analyze later
  88. * "PDU" : "Protocol Data Unit" (ie a network "frame")
  89. *
  90. */
  91. #define SMB2_HEADER_STRUCTURE_SIZE cpu_to_le16(64)
  92. struct smb2_sync_hdr {
  93. __le32 ProtocolId; /* 0xFE 'S' 'M' 'B' */
  94. __le16 StructureSize; /* 64 */
  95. __le16 CreditCharge; /* MBZ */
  96. __le32 Status; /* Error from server */
  97. __le16 Command;
  98. __le16 CreditRequest; /* CreditResponse */
  99. __le32 Flags;
  100. __le32 NextCommand;
  101. __le64 MessageId;
  102. __le32 ProcessId;
  103. __u32 TreeId; /* opaque - so do not make little endian */
  104. __u64 SessionId; /* opaque - so do not make little endian */
  105. __u8 Signature[16];
  106. } __packed;
  107. struct smb2_sync_pdu {
  108. struct smb2_sync_hdr sync_hdr;
  109. __le16 StructureSize2; /* size of wct area (varies, request specific) */
  110. } __packed;
  111. #define SMB3_AES128CMM_NONCE 11
  112. #define SMB3_AES128GCM_NONCE 12
  113. struct smb2_transform_hdr {
  114. __le32 ProtocolId; /* 0xFD 'S' 'M' 'B' */
  115. __u8 Signature[16];
  116. __u8 Nonce[16];
  117. __le32 OriginalMessageSize;
  118. __u16 Reserved1;
  119. __le16 Flags; /* EncryptionAlgorithm */
  120. __u64 SessionId;
  121. } __packed;
  122. /*
  123. * SMB2 flag definitions
  124. */
  125. #define SMB2_FLAGS_SERVER_TO_REDIR cpu_to_le32(0x00000001)
  126. #define SMB2_FLAGS_ASYNC_COMMAND cpu_to_le32(0x00000002)
  127. #define SMB2_FLAGS_RELATED_OPERATIONS cpu_to_le32(0x00000004)
  128. #define SMB2_FLAGS_SIGNED cpu_to_le32(0x00000008)
  129. #define SMB2_FLAGS_DFS_OPERATIONS cpu_to_le32(0x10000000)
  130. /*
  131. * Definitions for SMB2 Protocol Data Units (network frames)
  132. *
  133. * See MS-SMB2.PDF specification for protocol details.
  134. * The Naming convention is the lower case version of the SMB2
  135. * command code name for the struct. Note that structures must be packed.
  136. *
  137. */
  138. #define COMPOUND_FID 0xFFFFFFFFFFFFFFFFULL
  139. #define SMB2_ERROR_STRUCTURE_SIZE2 cpu_to_le16(9)
  140. struct smb2_err_rsp {
  141. struct smb2_sync_hdr sync_hdr;
  142. __le16 StructureSize;
  143. __le16 Reserved; /* MBZ */
  144. __le32 ByteCount; /* even if zero, at least one byte follows */
  145. __u8 ErrorData[1]; /* variable length */
  146. } __packed;
  147. struct smb2_symlink_err_rsp {
  148. __le32 SymLinkLength;
  149. __le32 SymLinkErrorTag;
  150. __le32 ReparseTag;
  151. __le16 ReparseDataLength;
  152. __le16 UnparsedPathLength;
  153. __le16 SubstituteNameOffset;
  154. __le16 SubstituteNameLength;
  155. __le16 PrintNameOffset;
  156. __le16 PrintNameLength;
  157. __le32 Flags;
  158. __u8 PathBuffer[0];
  159. } __packed;
  160. /* SMB 3.1.1 and later dialects. See MS-SMB2 section 2.2.2.1 */
  161. struct smb2_error_context_rsp {
  162. __le32 ErrorDataLength;
  163. __le32 ErrorId;
  164. __u8 ErrorContextData; /* ErrorDataLength long array */
  165. } __packed;
  166. /* Defines for Type field below (see MS-SMB2 2.2.2.2.2.1) */
  167. #define MOVE_DST_IPADDR_V4 cpu_to_le32(0x00000001)
  168. #define MOVE_DST_IPADDR_V6 cpu_to_le32(0x00000002)
  169. struct move_dst_ipaddr {
  170. __le32 Type;
  171. __u32 Reserved;
  172. __u8 address[16]; /* IPv4 followed by 12 bytes rsvd or IPv6 address */
  173. } __packed;
  174. struct share_redirect_error_context_rsp {
  175. __le32 StructureSize;
  176. __le32 NotificationType;
  177. __le32 ResourceNameOffset;
  178. __le32 ResourceNameLength;
  179. __le16 Flags;
  180. __le16 TargetType;
  181. __le32 IPAddrCount;
  182. struct move_dst_ipaddr IpAddrMoveList[0];
  183. /* __u8 ResourceName[] */ /* Name of share as counted Unicode string */
  184. } __packed;
  185. #define SMB2_CLIENT_GUID_SIZE 16
  186. struct smb2_negotiate_req {
  187. struct smb2_sync_hdr sync_hdr;
  188. __le16 StructureSize; /* Must be 36 */
  189. __le16 DialectCount;
  190. __le16 SecurityMode;
  191. __le16 Reserved; /* MBZ */
  192. __le32 Capabilities;
  193. __u8 ClientGUID[SMB2_CLIENT_GUID_SIZE];
  194. /* In SMB3.02 and earlier next three were MBZ le64 ClientStartTime */
  195. __le32 NegotiateContextOffset; /* SMB3.1.1 only. MBZ earlier */
  196. __le16 NegotiateContextCount; /* SMB3.1.1 only. MBZ earlier */
  197. __le16 Reserved2;
  198. __le16 Dialects[4]; /* BB expand this if autonegotiate > 4 dialects */
  199. } __packed;
  200. /* Dialects */
  201. #define SMB20_PROT_ID 0x0202
  202. #define SMB21_PROT_ID 0x0210
  203. #define SMB30_PROT_ID 0x0300
  204. #define SMB302_PROT_ID 0x0302
  205. #define SMB311_PROT_ID 0x0311
  206. #define BAD_PROT_ID 0xFFFF
  207. /* SecurityMode flags */
  208. #define SMB2_NEGOTIATE_SIGNING_ENABLED 0x0001
  209. #define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002
  210. #define SMB2_SEC_MODE_FLAGS_ALL 0x0003
  211. /* Capabilities flags */
  212. #define SMB2_GLOBAL_CAP_DFS 0x00000001
  213. #define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */
  214. #define SMB2_GLOBAL_CAP_LARGE_MTU 0X00000004 /* Resp only New to SMB2.1 */
  215. #define SMB2_GLOBAL_CAP_MULTI_CHANNEL 0x00000008 /* New to SMB3 */
  216. #define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */
  217. #define SMB2_GLOBAL_CAP_DIRECTORY_LEASING 0x00000020 /* New to SMB3 */
  218. #define SMB2_GLOBAL_CAP_ENCRYPTION 0x00000040 /* New to SMB3 */
  219. /* Internal types */
  220. #define SMB2_NT_FIND 0x00100000
  221. #define SMB2_LARGE_FILES 0x00200000
  222. struct smb2_neg_context {
  223. __le16 ContextType;
  224. __le16 DataLength;
  225. __le32 Reserved;
  226. /* Followed by array of data */
  227. } __packed;
  228. #define SMB311_LINUX_CLIENT_SALT_SIZE 32
  229. /* Hash Algorithm Types */
  230. #define SMB2_PREAUTH_INTEGRITY_SHA512 cpu_to_le16(0x0001)
  231. #define SMB2_PREAUTH_HASH_SIZE 64
  232. /*
  233. * SaltLength that the server send can be zero, so the only three required
  234. * fields (all __le16) end up six bytes total, so the minimum context data len
  235. * in the response is six bytes which accounts for
  236. *
  237. * HashAlgorithmCount, SaltLength, and 1 HashAlgorithm.
  238. */
  239. #define MIN_PREAUTH_CTXT_DATA_LEN 6
  240. struct smb2_preauth_neg_context {
  241. __le16 ContextType; /* 1 */
  242. __le16 DataLength;
  243. __le32 Reserved;
  244. __le16 HashAlgorithmCount; /* 1 */
  245. __le16 SaltLength;
  246. __le16 HashAlgorithms; /* HashAlgorithms[0] since only one defined */
  247. __u8 Salt[SMB311_LINUX_CLIENT_SALT_SIZE];
  248. } __packed;
  249. /* Encryption Algorithms Ciphers */
  250. #define SMB2_ENCRYPTION_AES128_CCM cpu_to_le16(0x0001)
  251. #define SMB2_ENCRYPTION_AES128_GCM cpu_to_le16(0x0002)
  252. /* Min encrypt context data is one cipher so 2 bytes + 2 byte count field */
  253. #define MIN_ENCRYPT_CTXT_DATA_LEN 4
  254. struct smb2_encryption_neg_context {
  255. __le16 ContextType; /* 2 */
  256. __le16 DataLength;
  257. __le32 Reserved;
  258. __le16 CipherCount; /* AES-128-GCM and AES-128-CCM */
  259. __le16 Ciphers[1]; /* Ciphers[0] since only one used now */
  260. } __packed;
  261. #define POSIX_CTXT_DATA_LEN 8
  262. struct smb2_posix_neg_context {
  263. __le16 ContextType; /* 0x100 */
  264. __le16 DataLength;
  265. __le32 Reserved;
  266. __le64 Reserved1; /* In case needed for future (eg version or caps) */
  267. } __packed;
  268. struct smb2_negotiate_rsp {
  269. struct smb2_sync_hdr sync_hdr;
  270. __le16 StructureSize; /* Must be 65 */
  271. __le16 SecurityMode;
  272. __le16 DialectRevision;
  273. __le16 NegotiateContextCount; /* Prior to SMB3.1.1 was Reserved & MBZ */
  274. __u8 ServerGUID[16];
  275. __le32 Capabilities;
  276. __le32 MaxTransactSize;
  277. __le32 MaxReadSize;
  278. __le32 MaxWriteSize;
  279. __le64 SystemTime; /* MBZ */
  280. __le64 ServerStartTime;
  281. __le16 SecurityBufferOffset;
  282. __le16 SecurityBufferLength;
  283. __le32 NegotiateContextOffset; /* Pre:SMB3.1.1 was reserved/ignored */
  284. __u8 Buffer[1]; /* variable length GSS security buffer */
  285. } __packed;
  286. /* Flags */
  287. #define SMB2_SESSION_REQ_FLAG_BINDING 0x01
  288. #define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA 0x04
  289. struct smb2_sess_setup_req {
  290. struct smb2_sync_hdr sync_hdr;
  291. __le16 StructureSize; /* Must be 25 */
  292. __u8 Flags;
  293. __u8 SecurityMode;
  294. __le32 Capabilities;
  295. __le32 Channel;
  296. __le16 SecurityBufferOffset;
  297. __le16 SecurityBufferLength;
  298. __u64 PreviousSessionId;
  299. __u8 Buffer[1]; /* variable length GSS security buffer */
  300. } __packed;
  301. /* Currently defined SessionFlags */
  302. #define SMB2_SESSION_FLAG_IS_GUEST 0x0001
  303. #define SMB2_SESSION_FLAG_IS_NULL 0x0002
  304. #define SMB2_SESSION_FLAG_ENCRYPT_DATA 0x0004
  305. struct smb2_sess_setup_rsp {
  306. struct smb2_sync_hdr sync_hdr;
  307. __le16 StructureSize; /* Must be 9 */
  308. __le16 SessionFlags;
  309. __le16 SecurityBufferOffset;
  310. __le16 SecurityBufferLength;
  311. __u8 Buffer[1]; /* variable length GSS security buffer */
  312. } __packed;
  313. struct smb2_logoff_req {
  314. struct smb2_sync_hdr sync_hdr;
  315. __le16 StructureSize; /* Must be 4 */
  316. __le16 Reserved;
  317. } __packed;
  318. struct smb2_logoff_rsp {
  319. struct smb2_sync_hdr sync_hdr;
  320. __le16 StructureSize; /* Must be 4 */
  321. __le16 Reserved;
  322. } __packed;
  323. /* Flags/Reserved for SMB3.1.1 */
  324. #define SMB2_TREE_CONNECT_FLAG_CLUSTER_RECONNECT cpu_to_le16(0x0001)
  325. #define SMB2_TREE_CONNECT_FLAG_REDIRECT_TO_OWNER cpu_to_le16(0x0002)
  326. #define SMB2_TREE_CONNECT_FLAG_EXTENSION_PRESENT cpu_to_le16(0x0004)
  327. struct smb2_tree_connect_req {
  328. struct smb2_sync_hdr sync_hdr;
  329. __le16 StructureSize; /* Must be 9 */
  330. __le16 Reserved; /* Flags in SMB3.1.1 */
  331. __le16 PathOffset;
  332. __le16 PathLength;
  333. __u8 Buffer[1]; /* variable length */
  334. } __packed;
  335. /* See MS-SMB2 section 2.2.9.2 */
  336. /* Context Types */
  337. #define SMB2_RESERVED_TREE_CONNECT_CONTEXT_ID 0x0000
  338. #define SMB2_REMOTED_IDENTITY_TREE_CONNECT_CONTEXT_ID cpu_to_le16(0x0001)
  339. struct tree_connect_contexts {
  340. __le16 ContextType;
  341. __le16 DataLength;
  342. __le32 Reserved;
  343. __u8 Data[0];
  344. } __packed;
  345. /* Remoted identity tree connect context structures - see MS-SMB2 2.2.9.2.1 */
  346. struct smb3_blob_data {
  347. __le16 BlobSize;
  348. __u8 BlobData[0];
  349. } __packed;
  350. /* Valid values for Attr */
  351. #define SE_GROUP_MANDATORY 0x00000001
  352. #define SE_GROUP_ENABLED_BY_DEFAULT 0x00000002
  353. #define SE_GROUP_ENABLED 0x00000004
  354. #define SE_GROUP_OWNER 0x00000008
  355. #define SE_GROUP_USE_FOR_DENY_ONLY 0x00000010
  356. #define SE_GROUP_INTEGRITY 0x00000020
  357. #define SE_GROUP_INTEGRITY_ENABLED 0x00000040
  358. #define SE_GROUP_RESOURCE 0x20000000
  359. #define SE_GROUP_LOGON_ID 0xC0000000
  360. /* struct sid_attr_data is SidData array in BlobData format then le32 Attr */
  361. struct sid_array_data {
  362. __le16 SidAttrCount;
  363. /* SidAttrList - array of sid_attr_data structs */
  364. } __packed;
  365. struct luid_attr_data {
  366. } __packed;
  367. /*
  368. * struct privilege_data is the same as BLOB_DATA - see MS-SMB2 2.2.9.2.1.5
  369. * but with size of LUID_ATTR_DATA struct and BlobData set to LUID_ATTR DATA
  370. */
  371. struct privilege_array_data {
  372. __le16 PrivilegeCount;
  373. /* array of privilege_data structs */
  374. } __packed;
  375. struct remoted_identity_tcon_context {
  376. __le16 TicketType; /* must be 0x0001 */
  377. __le16 TicketSize; /* total size of this struct */
  378. __le16 User; /* offset to SID_ATTR_DATA struct with user info */
  379. __le16 UserName; /* offset to null terminated Unicode username string */
  380. __le16 Domain; /* offset to null terminated Unicode domain name */
  381. __le16 Groups; /* offset to SID_ARRAY_DATA struct with group info */
  382. __le16 RestrictedGroups; /* similar to above */
  383. __le16 Privileges; /* offset to PRIVILEGE_ARRAY_DATA struct */
  384. __le16 PrimaryGroup; /* offset to SID_ARRAY_DATA struct */
  385. __le16 Owner; /* offset to BLOB_DATA struct */
  386. __le16 DefaultDacl; /* offset to BLOB_DATA struct */
  387. __le16 DeviceGroups; /* offset to SID_ARRAY_DATA struct */
  388. __le16 UserClaims; /* offset to BLOB_DATA struct */
  389. __le16 DeviceClaims; /* offset to BLOB_DATA struct */
  390. __u8 TicketInfo[0]; /* variable length buf - remoted identity data */
  391. } __packed;
  392. struct smb2_tree_connect_req_extension {
  393. __le32 TreeConnectContextOffset;
  394. __le16 TreeConnectContextCount;
  395. __u8 Reserved[10];
  396. __u8 PathName[0]; /* variable sized array */
  397. /* followed by array of TreeConnectContexts */
  398. } __packed;
  399. struct smb2_tree_connect_rsp {
  400. struct smb2_sync_hdr sync_hdr;
  401. __le16 StructureSize; /* Must be 16 */
  402. __u8 ShareType; /* see below */
  403. __u8 Reserved;
  404. __le32 ShareFlags; /* see below */
  405. __le32 Capabilities; /* see below */
  406. __le32 MaximalAccess;
  407. } __packed;
  408. /* Possible ShareType values */
  409. #define SMB2_SHARE_TYPE_DISK 0x01
  410. #define SMB2_SHARE_TYPE_PIPE 0x02
  411. #define SMB2_SHARE_TYPE_PRINT 0x03
  412. /*
  413. * Possible ShareFlags - exactly one and only one of the first 4 caching flags
  414. * must be set (any of the remaining, SHI1005, flags may be set individually
  415. * or in combination.
  416. */
  417. #define SMB2_SHAREFLAG_MANUAL_CACHING 0x00000000
  418. #define SMB2_SHAREFLAG_AUTO_CACHING 0x00000010
  419. #define SMB2_SHAREFLAG_VDO_CACHING 0x00000020
  420. #define SMB2_SHAREFLAG_NO_CACHING 0x00000030
  421. #define SHI1005_FLAGS_DFS 0x00000001
  422. #define SHI1005_FLAGS_DFS_ROOT 0x00000002
  423. #define SHI1005_FLAGS_RESTRICT_EXCLUSIVE_OPENS 0x00000100
  424. #define SHI1005_FLAGS_FORCE_SHARED_DELETE 0x00000200
  425. #define SHI1005_FLAGS_ALLOW_NAMESPACE_CACHING 0x00000400
  426. #define SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM 0x00000800
  427. #define SHI1005_FLAGS_FORCE_LEVELII_OPLOCK 0x00001000
  428. #define SHI1005_FLAGS_ENABLE_HASH_V1 0x00002000
  429. #define SHI1005_FLAGS_ENABLE_HASH_V2 0x00004000
  430. #define SHI1005_FLAGS_ENCRYPT_DATA 0x00008000
  431. #define SMB2_SHAREFLAG_IDENTITY_REMOTING 0x00040000 /* 3.1.1 */
  432. #define SHI1005_FLAGS_ALL 0x0004FF33
  433. /* Possible share capabilities */
  434. #define SMB2_SHARE_CAP_DFS cpu_to_le32(0x00000008) /* all dialects */
  435. #define SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY cpu_to_le32(0x00000010) /* 3.0 */
  436. #define SMB2_SHARE_CAP_SCALEOUT cpu_to_le32(0x00000020) /* 3.0 */
  437. #define SMB2_SHARE_CAP_CLUSTER cpu_to_le32(0x00000040) /* 3.0 */
  438. #define SMB2_SHARE_CAP_ASYMMETRIC cpu_to_le32(0x00000080) /* 3.02 */
  439. #define SMB2_SHARE_CAP_REDIRECT_TO_OWNER cpu_to_le32(0x00000100) /* 3.1.1 */
  440. struct smb2_tree_disconnect_req {
  441. struct smb2_sync_hdr sync_hdr;
  442. __le16 StructureSize; /* Must be 4 */
  443. __le16 Reserved;
  444. } __packed;
  445. struct smb2_tree_disconnect_rsp {
  446. struct smb2_sync_hdr sync_hdr;
  447. __le16 StructureSize; /* Must be 4 */
  448. __le16 Reserved;
  449. } __packed;
  450. /* File Attrubutes */
  451. #define FILE_ATTRIBUTE_READONLY 0x00000001
  452. #define FILE_ATTRIBUTE_HIDDEN 0x00000002
  453. #define FILE_ATTRIBUTE_SYSTEM 0x00000004
  454. #define FILE_ATTRIBUTE_DIRECTORY 0x00000010
  455. #define FILE_ATTRIBUTE_ARCHIVE 0x00000020
  456. #define FILE_ATTRIBUTE_NORMAL 0x00000080
  457. #define FILE_ATTRIBUTE_TEMPORARY 0x00000100
  458. #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
  459. #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
  460. #define FILE_ATTRIBUTE_COMPRESSED 0x00000800
  461. #define FILE_ATTRIBUTE_OFFLINE 0x00001000
  462. #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
  463. #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
  464. #define FILE_ATTRIBUTE_INTEGRITY_STREAM 0x00008000
  465. #define FILE_ATTRIBUTE_NO_SCRUB_DATA 0x00020000
  466. /* Oplock levels */
  467. #define SMB2_OPLOCK_LEVEL_NONE 0x00
  468. #define SMB2_OPLOCK_LEVEL_II 0x01
  469. #define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08
  470. #define SMB2_OPLOCK_LEVEL_BATCH 0x09
  471. #define SMB2_OPLOCK_LEVEL_LEASE 0xFF
  472. /* Non-spec internal type */
  473. #define SMB2_OPLOCK_LEVEL_NOCHANGE 0x99
  474. /* Desired Access Flags */
  475. #define FILE_READ_DATA_LE cpu_to_le32(0x00000001)
  476. #define FILE_WRITE_DATA_LE cpu_to_le32(0x00000002)
  477. #define FILE_APPEND_DATA_LE cpu_to_le32(0x00000004)
  478. #define FILE_READ_EA_LE cpu_to_le32(0x00000008)
  479. #define FILE_WRITE_EA_LE cpu_to_le32(0x00000010)
  480. #define FILE_EXECUTE_LE cpu_to_le32(0x00000020)
  481. #define FILE_READ_ATTRIBUTES_LE cpu_to_le32(0x00000080)
  482. #define FILE_WRITE_ATTRIBUTES_LE cpu_to_le32(0x00000100)
  483. #define FILE_DELETE_LE cpu_to_le32(0x00010000)
  484. #define FILE_READ_CONTROL_LE cpu_to_le32(0x00020000)
  485. #define FILE_WRITE_DAC_LE cpu_to_le32(0x00040000)
  486. #define FILE_WRITE_OWNER_LE cpu_to_le32(0x00080000)
  487. #define FILE_SYNCHRONIZE_LE cpu_to_le32(0x00100000)
  488. #define FILE_ACCESS_SYSTEM_SECURITY_LE cpu_to_le32(0x01000000)
  489. #define FILE_MAXIMAL_ACCESS_LE cpu_to_le32(0x02000000)
  490. #define FILE_GENERIC_ALL_LE cpu_to_le32(0x10000000)
  491. #define FILE_GENERIC_EXECUTE_LE cpu_to_le32(0x20000000)
  492. #define FILE_GENERIC_WRITE_LE cpu_to_le32(0x40000000)
  493. #define FILE_GENERIC_READ_LE cpu_to_le32(0x80000000)
  494. /* ShareAccess Flags */
  495. #define FILE_SHARE_READ_LE cpu_to_le32(0x00000001)
  496. #define FILE_SHARE_WRITE_LE cpu_to_le32(0x00000002)
  497. #define FILE_SHARE_DELETE_LE cpu_to_le32(0x00000004)
  498. #define FILE_SHARE_ALL_LE cpu_to_le32(0x00000007)
  499. /* CreateDisposition Flags */
  500. #define FILE_SUPERSEDE_LE cpu_to_le32(0x00000000)
  501. #define FILE_OPEN_LE cpu_to_le32(0x00000001)
  502. #define FILE_CREATE_LE cpu_to_le32(0x00000002)
  503. #define FILE_OPEN_IF_LE cpu_to_le32(0x00000003)
  504. #define FILE_OVERWRITE_LE cpu_to_le32(0x00000004)
  505. #define FILE_OVERWRITE_IF_LE cpu_to_le32(0x00000005)
  506. /* CreateOptions Flags */
  507. #define FILE_DIRECTORY_FILE_LE cpu_to_le32(0x00000001)
  508. /* same as #define CREATE_NOT_FILE_LE cpu_to_le32(0x00000001) */
  509. #define FILE_WRITE_THROUGH_LE cpu_to_le32(0x00000002)
  510. #define FILE_SEQUENTIAL_ONLY_LE cpu_to_le32(0x00000004)
  511. #define FILE_NO_INTERMEDIATE_BUFFERRING_LE cpu_to_le32(0x00000008)
  512. #define FILE_SYNCHRONOUS_IO_ALERT_LE cpu_to_le32(0x00000010)
  513. #define FILE_SYNCHRONOUS_IO_NON_ALERT_LE cpu_to_le32(0x00000020)
  514. #define FILE_NON_DIRECTORY_FILE_LE cpu_to_le32(0x00000040)
  515. #define FILE_COMPLETE_IF_OPLOCKED_LE cpu_to_le32(0x00000100)
  516. #define FILE_NO_EA_KNOWLEDGE_LE cpu_to_le32(0x00000200)
  517. #define FILE_RANDOM_ACCESS_LE cpu_to_le32(0x00000800)
  518. #define FILE_DELETE_ON_CLOSE_LE cpu_to_le32(0x00001000)
  519. #define FILE_OPEN_BY_FILE_ID_LE cpu_to_le32(0x00002000)
  520. #define FILE_OPEN_FOR_BACKUP_INTENT_LE cpu_to_le32(0x00004000)
  521. #define FILE_NO_COMPRESSION_LE cpu_to_le32(0x00008000)
  522. #define FILE_RESERVE_OPFILTER_LE cpu_to_le32(0x00100000)
  523. #define FILE_OPEN_REPARSE_POINT_LE cpu_to_le32(0x00200000)
  524. #define FILE_OPEN_NO_RECALL_LE cpu_to_le32(0x00400000)
  525. #define FILE_OPEN_FOR_FREE_SPACE_QUERY_LE cpu_to_le32(0x00800000)
  526. #define FILE_READ_RIGHTS_LE (FILE_READ_DATA_LE | FILE_READ_EA_LE \
  527. | FILE_READ_ATTRIBUTES_LE)
  528. #define FILE_WRITE_RIGHTS_LE (FILE_WRITE_DATA_LE | FILE_APPEND_DATA_LE \
  529. | FILE_WRITE_EA_LE | FILE_WRITE_ATTRIBUTES_LE)
  530. #define FILE_EXEC_RIGHTS_LE (FILE_EXECUTE_LE)
  531. /* Impersonation Levels */
  532. #define IL_ANONYMOUS cpu_to_le32(0x00000000)
  533. #define IL_IDENTIFICATION cpu_to_le32(0x00000001)
  534. #define IL_IMPERSONATION cpu_to_le32(0x00000002)
  535. #define IL_DELEGATE cpu_to_le32(0x00000003)
  536. /* Create Context Values */
  537. #define SMB2_CREATE_EA_BUFFER "ExtA" /* extended attributes */
  538. #define SMB2_CREATE_SD_BUFFER "SecD" /* security descriptor */
  539. #define SMB2_CREATE_DURABLE_HANDLE_REQUEST "DHnQ"
  540. #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT "DHnC"
  541. #define SMB2_CREATE_ALLOCATION_SIZE "AISi"
  542. #define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST "MxAc"
  543. #define SMB2_CREATE_TIMEWARP_REQUEST "TWrp"
  544. #define SMB2_CREATE_QUERY_ON_DISK_ID "QFid"
  545. #define SMB2_CREATE_REQUEST_LEASE "RqLs"
  546. #define SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 "DH2Q"
  547. #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 "DH2C"
  548. #define SMB2_CREATE_APP_INSTANCE_ID 0x45BCA66AEFA7F74A9008FA462E144D74
  549. #define SVHDX_OPEN_DEVICE_CONTEX 0x9CCBCF9E04C1E643980E158DA1F6EC83
  550. #define SMB2_CREATE_TAG_POSIX 0x93AD25509CB411E7B42383DE968BCD7C
  551. /*
  552. * Maximum number of iovs we need for an open/create request.
  553. * [0] : struct smb2_create_req
  554. * [1] : path
  555. * [2] : lease context
  556. * [3] : durable context
  557. * [4] : posix context
  558. * [5] : time warp context
  559. * [6] : compound padding
  560. */
  561. #define SMB2_CREATE_IOV_SIZE 7
  562. struct smb2_create_req {
  563. struct smb2_sync_hdr sync_hdr;
  564. __le16 StructureSize; /* Must be 57 */
  565. __u8 SecurityFlags;
  566. __u8 RequestedOplockLevel;
  567. __le32 ImpersonationLevel;
  568. __le64 SmbCreateFlags;
  569. __le64 Reserved;
  570. __le32 DesiredAccess;
  571. __le32 FileAttributes;
  572. __le32 ShareAccess;
  573. __le32 CreateDisposition;
  574. __le32 CreateOptions;
  575. __le16 NameOffset;
  576. __le16 NameLength;
  577. __le32 CreateContextsOffset;
  578. __le32 CreateContextsLength;
  579. __u8 Buffer[0];
  580. } __packed;
  581. struct smb2_create_rsp {
  582. struct smb2_sync_hdr sync_hdr;
  583. __le16 StructureSize; /* Must be 89 */
  584. __u8 OplockLevel;
  585. __u8 Reserved;
  586. __le32 CreateAction;
  587. __le64 CreationTime;
  588. __le64 LastAccessTime;
  589. __le64 LastWriteTime;
  590. __le64 ChangeTime;
  591. __le64 AllocationSize;
  592. __le64 EndofFile;
  593. __le32 FileAttributes;
  594. __le32 Reserved2;
  595. __u64 PersistentFileId; /* opaque endianness */
  596. __u64 VolatileFileId; /* opaque endianness */
  597. __le32 CreateContextsOffset;
  598. __le32 CreateContextsLength;
  599. __u8 Buffer[1];
  600. } __packed;
  601. struct create_context {
  602. __le32 Next;
  603. __le16 NameOffset;
  604. __le16 NameLength;
  605. __le16 Reserved;
  606. __le16 DataOffset;
  607. __le32 DataLength;
  608. __u8 Buffer[0];
  609. } __packed;
  610. #define SMB2_LEASE_READ_CACHING_HE 0x01
  611. #define SMB2_LEASE_HANDLE_CACHING_HE 0x02
  612. #define SMB2_LEASE_WRITE_CACHING_HE 0x04
  613. #define SMB2_LEASE_NONE cpu_to_le32(0x00)
  614. #define SMB2_LEASE_READ_CACHING cpu_to_le32(0x01)
  615. #define SMB2_LEASE_HANDLE_CACHING cpu_to_le32(0x02)
  616. #define SMB2_LEASE_WRITE_CACHING cpu_to_le32(0x04)
  617. #define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS cpu_to_le32(0x02)
  618. #define SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET cpu_to_le32(0x00000004)
  619. #define SMB2_LEASE_KEY_SIZE 16
  620. struct lease_context {
  621. u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
  622. __le32 LeaseState;
  623. __le32 LeaseFlags;
  624. __le64 LeaseDuration;
  625. } __packed;
  626. struct lease_context_v2 {
  627. u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
  628. __le32 LeaseState;
  629. __le32 LeaseFlags;
  630. __le64 LeaseDuration;
  631. __le64 ParentLeaseKeyLow;
  632. __le64 ParentLeaseKeyHigh;
  633. __le16 Epoch;
  634. __le16 Reserved;
  635. } __packed;
  636. struct create_lease {
  637. struct create_context ccontext;
  638. __u8 Name[8];
  639. struct lease_context lcontext;
  640. } __packed;
  641. struct create_lease_v2 {
  642. struct create_context ccontext;
  643. __u8 Name[8];
  644. struct lease_context_v2 lcontext;
  645. __u8 Pad[4];
  646. } __packed;
  647. struct create_durable {
  648. struct create_context ccontext;
  649. __u8 Name[8];
  650. union {
  651. __u8 Reserved[16];
  652. struct {
  653. __u64 PersistentFileId;
  654. __u64 VolatileFileId;
  655. } Fid;
  656. } Data;
  657. } __packed;
  658. struct create_posix {
  659. struct create_context ccontext;
  660. __u8 Name[16];
  661. __le32 Mode;
  662. __u32 Reserved;
  663. } __packed;
  664. /* See MS-SMB2 2.2.13.2.11 */
  665. /* Flags */
  666. #define SMB2_DHANDLE_FLAG_PERSISTENT 0x00000002
  667. struct durable_context_v2 {
  668. __le32 Timeout;
  669. __le32 Flags;
  670. __u64 Reserved;
  671. __u8 CreateGuid[16];
  672. } __packed;
  673. struct create_durable_v2 {
  674. struct create_context ccontext;
  675. __u8 Name[8];
  676. struct durable_context_v2 dcontext;
  677. } __packed;
  678. /* See MS-SMB2 2.2.13.2.12 */
  679. struct durable_reconnect_context_v2 {
  680. struct {
  681. __u64 PersistentFileId;
  682. __u64 VolatileFileId;
  683. } Fid;
  684. __u8 CreateGuid[16];
  685. __le32 Flags; /* see above DHANDLE_FLAG_PERSISTENT */
  686. } __packed;
  687. /* See MS-SMB2 2.2.14.2.12 */
  688. struct durable_reconnect_context_v2_rsp {
  689. __le32 Timeout;
  690. __le32 Flags; /* see above DHANDLE_FLAG_PERSISTENT */
  691. } __packed;
  692. struct create_durable_handle_reconnect_v2 {
  693. struct create_context ccontext;
  694. __u8 Name[8];
  695. struct durable_reconnect_context_v2 dcontext;
  696. __u8 Pad[4];
  697. } __packed;
  698. /* See MS-SMB2 2.2.13.2.5 */
  699. struct crt_twarp_ctxt {
  700. struct create_context ccontext;
  701. __u8 Name[8];
  702. __le64 Timestamp;
  703. } __packed;
  704. #define COPY_CHUNK_RES_KEY_SIZE 24
  705. struct resume_key_req {
  706. char ResumeKey[COPY_CHUNK_RES_KEY_SIZE];
  707. __le32 ContextLength; /* MBZ */
  708. char Context[0]; /* ignored, Windows sets to 4 bytes of zero */
  709. } __packed;
  710. /* this goes in the ioctl buffer when doing a copychunk request */
  711. struct copychunk_ioctl {
  712. char SourceKey[COPY_CHUNK_RES_KEY_SIZE];
  713. __le32 ChunkCount; /* we are only sending 1 */
  714. __le32 Reserved;
  715. /* array will only be one chunk long for us */
  716. __le64 SourceOffset;
  717. __le64 TargetOffset;
  718. __le32 Length; /* how many bytes to copy */
  719. __u32 Reserved2;
  720. } __packed;
  721. /* this goes in the ioctl buffer when doing FSCTL_SET_ZERO_DATA */
  722. struct file_zero_data_information {
  723. __le64 FileOffset;
  724. __le64 BeyondFinalZero;
  725. } __packed;
  726. struct copychunk_ioctl_rsp {
  727. __le32 ChunksWritten;
  728. __le32 ChunkBytesWritten;
  729. __le32 TotalBytesWritten;
  730. } __packed;
  731. struct fsctl_set_integrity_information_req {
  732. __le16 ChecksumAlgorithm;
  733. __le16 Reserved;
  734. __le32 Flags;
  735. } __packed;
  736. struct fsctl_get_integrity_information_rsp {
  737. __le16 ChecksumAlgorithm;
  738. __le16 Reserved;
  739. __le32 Flags;
  740. __le32 ChecksumChunkSizeInBytes;
  741. __le32 ClusterSizeInBytes;
  742. } __packed;
  743. /* Integrity ChecksumAlgorithm choices for above */
  744. #define CHECKSUM_TYPE_NONE 0x0000
  745. #define CHECKSUM_TYPE_CRC64 0x0002
  746. #define CHECKSUM_TYPE_UNCHANGED 0xFFFF /* set only */
  747. /* Integrity flags for above */
  748. #define FSCTL_INTEGRITY_FLAG_CHECKSUM_ENFORCEMENT_OFF 0x00000001
  749. /* See MS-DFSC 2.2.2 */
  750. struct fsctl_get_dfs_referral_req {
  751. __le16 MaxReferralLevel;
  752. __u8 RequestFileName[];
  753. } __packed;
  754. /* DFS response is struct get_dfs_refer_rsp */
  755. /* See MS-SMB2 2.2.31.3 */
  756. struct network_resiliency_req {
  757. __le32 Timeout;
  758. __le32 Reserved;
  759. } __packed;
  760. /* There is no buffer for the response ie no struct network_resiliency_rsp */
  761. struct validate_negotiate_info_req {
  762. __le32 Capabilities;
  763. __u8 Guid[SMB2_CLIENT_GUID_SIZE];
  764. __le16 SecurityMode;
  765. __le16 DialectCount;
  766. __le16 Dialects[3]; /* BB expand this if autonegotiate > 3 dialects */
  767. } __packed;
  768. struct validate_negotiate_info_rsp {
  769. __le32 Capabilities;
  770. __u8 Guid[SMB2_CLIENT_GUID_SIZE];
  771. __le16 SecurityMode;
  772. __le16 Dialect; /* Dialect in use for the connection */
  773. } __packed;
  774. #define RSS_CAPABLE cpu_to_le32(0x00000001)
  775. #define RDMA_CAPABLE cpu_to_le32(0x00000002)
  776. #define INTERNETWORK cpu_to_le16(0x0002)
  777. #define INTERNETWORKV6 cpu_to_le16(0x0017)
  778. struct network_interface_info_ioctl_rsp {
  779. __le32 Next; /* next interface. zero if this is last one */
  780. __le32 IfIndex;
  781. __le32 Capability; /* RSS or RDMA Capable */
  782. __le32 Reserved;
  783. __le64 LinkSpeed;
  784. __le16 Family;
  785. __u8 Buffer[126];
  786. } __packed;
  787. struct iface_info_ipv4 {
  788. __be16 Port;
  789. __be32 IPv4Address;
  790. __be64 Reserved;
  791. } __packed;
  792. struct iface_info_ipv6 {
  793. __be16 Port;
  794. __be32 FlowInfo;
  795. __u8 IPv6Address[16];
  796. __be32 ScopeId;
  797. } __packed;
  798. #define NO_FILE_ID 0xFFFFFFFFFFFFFFFFULL /* general ioctls to srv not to file */
  799. struct compress_ioctl {
  800. __le16 CompressionState; /* See cifspdu.h for possible flag values */
  801. } __packed;
  802. struct duplicate_extents_to_file {
  803. __u64 PersistentFileHandle; /* source file handle, opaque endianness */
  804. __u64 VolatileFileHandle;
  805. __le64 SourceFileOffset;
  806. __le64 TargetFileOffset;
  807. __le64 ByteCount; /* Bytes to be copied */
  808. } __packed;
  809. struct smb2_ioctl_req {
  810. struct smb2_sync_hdr sync_hdr;
  811. __le16 StructureSize; /* Must be 57 */
  812. __u16 Reserved;
  813. __le32 CtlCode;
  814. __u64 PersistentFileId; /* opaque endianness */
  815. __u64 VolatileFileId; /* opaque endianness */
  816. __le32 InputOffset;
  817. __le32 InputCount;
  818. __le32 MaxInputResponse;
  819. __le32 OutputOffset;
  820. __le32 OutputCount;
  821. __le32 MaxOutputResponse;
  822. __le32 Flags;
  823. __u32 Reserved2;
  824. __u8 Buffer[0];
  825. } __packed;
  826. struct smb2_ioctl_rsp {
  827. struct smb2_sync_hdr sync_hdr;
  828. __le16 StructureSize; /* Must be 57 */
  829. __u16 Reserved;
  830. __le32 CtlCode;
  831. __u64 PersistentFileId; /* opaque endianness */
  832. __u64 VolatileFileId; /* opaque endianness */
  833. __le32 InputOffset;
  834. __le32 InputCount;
  835. __le32 OutputOffset;
  836. __le32 OutputCount;
  837. __le32 Flags;
  838. __u32 Reserved2;
  839. /* char * buffer[] */
  840. } __packed;
  841. /* Currently defined values for close flags */
  842. #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001)
  843. struct smb2_close_req {
  844. struct smb2_sync_hdr sync_hdr;
  845. __le16 StructureSize; /* Must be 24 */
  846. __le16 Flags;
  847. __le32 Reserved;
  848. __u64 PersistentFileId; /* opaque endianness */
  849. __u64 VolatileFileId; /* opaque endianness */
  850. } __packed;
  851. struct smb2_close_rsp {
  852. struct smb2_sync_hdr sync_hdr;
  853. __le16 StructureSize; /* 60 */
  854. __le16 Flags;
  855. __le32 Reserved;
  856. __le64 CreationTime;
  857. __le64 LastAccessTime;
  858. __le64 LastWriteTime;
  859. __le64 ChangeTime;
  860. __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
  861. __le64 EndOfFile;
  862. __le32 Attributes;
  863. } __packed;
  864. struct smb2_flush_req {
  865. struct smb2_sync_hdr sync_hdr;
  866. __le16 StructureSize; /* Must be 24 */
  867. __le16 Reserved1;
  868. __le32 Reserved2;
  869. __u64 PersistentFileId; /* opaque endianness */
  870. __u64 VolatileFileId; /* opaque endianness */
  871. } __packed;
  872. struct smb2_flush_rsp {
  873. struct smb2_sync_hdr sync_hdr;
  874. __le16 StructureSize;
  875. __le16 Reserved;
  876. } __packed;
  877. /* For read request Flags field below, following flag is defined for SMB3.02 */
  878. #define SMB2_READFLAG_READ_UNBUFFERED 0x01
  879. /* Channel field for read and write: exactly one of following flags can be set*/
  880. #define SMB2_CHANNEL_NONE cpu_to_le32(0x00000000)
  881. #define SMB2_CHANNEL_RDMA_V1 cpu_to_le32(0x00000001) /* SMB3 or later */
  882. #define SMB2_CHANNEL_RDMA_V1_INVALIDATE cpu_to_le32(0x00000002) /* >= SMB3.02 */
  883. /* SMB2 read request without RFC1001 length at the beginning */
  884. struct smb2_read_plain_req {
  885. struct smb2_sync_hdr sync_hdr;
  886. __le16 StructureSize; /* Must be 49 */
  887. __u8 Padding; /* offset from start of SMB2 header to place read */
  888. __u8 Flags; /* MBZ unless SMB3.02 or later */
  889. __le32 Length;
  890. __le64 Offset;
  891. __u64 PersistentFileId; /* opaque endianness */
  892. __u64 VolatileFileId; /* opaque endianness */
  893. __le32 MinimumCount;
  894. __le32 Channel; /* MBZ except for SMB3 or later */
  895. __le32 RemainingBytes;
  896. __le16 ReadChannelInfoOffset;
  897. __le16 ReadChannelInfoLength;
  898. __u8 Buffer[1];
  899. } __packed;
  900. struct smb2_read_rsp {
  901. struct smb2_sync_hdr sync_hdr;
  902. __le16 StructureSize; /* Must be 17 */
  903. __u8 DataOffset;
  904. __u8 Reserved;
  905. __le32 DataLength;
  906. __le32 DataRemaining;
  907. __u32 Reserved2;
  908. __u8 Buffer[1];
  909. } __packed;
  910. /* For write request Flags field below the following flags are defined: */
  911. #define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001 /* SMB2.1 or later */
  912. #define SMB2_WRITEFLAG_WRITE_UNBUFFERED 0x00000002 /* SMB3.02 or later */
  913. struct smb2_write_req {
  914. struct smb2_sync_hdr sync_hdr;
  915. __le16 StructureSize; /* Must be 49 */
  916. __le16 DataOffset; /* offset from start of SMB2 header to write data */
  917. __le32 Length;
  918. __le64 Offset;
  919. __u64 PersistentFileId; /* opaque endianness */
  920. __u64 VolatileFileId; /* opaque endianness */
  921. __le32 Channel; /* Reserved MBZ */
  922. __le32 RemainingBytes;
  923. __le16 WriteChannelInfoOffset;
  924. __le16 WriteChannelInfoLength;
  925. __le32 Flags;
  926. __u8 Buffer[1];
  927. } __packed;
  928. struct smb2_write_rsp {
  929. struct smb2_sync_hdr sync_hdr;
  930. __le16 StructureSize; /* Must be 17 */
  931. __u8 DataOffset;
  932. __u8 Reserved;
  933. __le32 DataLength;
  934. __le32 DataRemaining;
  935. __u32 Reserved2;
  936. __u8 Buffer[1];
  937. } __packed;
  938. #define SMB2_LOCKFLAG_SHARED_LOCK 0x0001
  939. #define SMB2_LOCKFLAG_EXCLUSIVE_LOCK 0x0002
  940. #define SMB2_LOCKFLAG_UNLOCK 0x0004
  941. #define SMB2_LOCKFLAG_FAIL_IMMEDIATELY 0x0010
  942. struct smb2_lock_element {
  943. __le64 Offset;
  944. __le64 Length;
  945. __le32 Flags;
  946. __le32 Reserved;
  947. } __packed;
  948. struct smb2_lock_req {
  949. struct smb2_sync_hdr sync_hdr;
  950. __le16 StructureSize; /* Must be 48 */
  951. __le16 LockCount;
  952. __le32 Reserved;
  953. __u64 PersistentFileId; /* opaque endianness */
  954. __u64 VolatileFileId; /* opaque endianness */
  955. /* Followed by at least one */
  956. struct smb2_lock_element locks[1];
  957. } __packed;
  958. struct smb2_lock_rsp {
  959. struct smb2_sync_hdr sync_hdr;
  960. __le16 StructureSize; /* Must be 4 */
  961. __le16 Reserved;
  962. } __packed;
  963. struct smb2_echo_req {
  964. struct smb2_sync_hdr sync_hdr;
  965. __le16 StructureSize; /* Must be 4 */
  966. __u16 Reserved;
  967. } __packed;
  968. struct smb2_echo_rsp {
  969. struct smb2_sync_hdr sync_hdr;
  970. __le16 StructureSize; /* Must be 4 */
  971. __u16 Reserved;
  972. } __packed;
  973. /* search (query_directory) Flags field */
  974. #define SMB2_RESTART_SCANS 0x01
  975. #define SMB2_RETURN_SINGLE_ENTRY 0x02
  976. #define SMB2_INDEX_SPECIFIED 0x04
  977. #define SMB2_REOPEN 0x10
  978. struct smb2_query_directory_req {
  979. struct smb2_sync_hdr sync_hdr;
  980. __le16 StructureSize; /* Must be 33 */
  981. __u8 FileInformationClass;
  982. __u8 Flags;
  983. __le32 FileIndex;
  984. __u64 PersistentFileId; /* opaque endianness */
  985. __u64 VolatileFileId; /* opaque endianness */
  986. __le16 FileNameOffset;
  987. __le16 FileNameLength;
  988. __le32 OutputBufferLength;
  989. __u8 Buffer[1];
  990. } __packed;
  991. struct smb2_query_directory_rsp {
  992. struct smb2_sync_hdr sync_hdr;
  993. __le16 StructureSize; /* Must be 9 */
  994. __le16 OutputBufferOffset;
  995. __le32 OutputBufferLength;
  996. __u8 Buffer[1];
  997. } __packed;
  998. /* Possible InfoType values */
  999. #define SMB2_O_INFO_FILE 0x01
  1000. #define SMB2_O_INFO_FILESYSTEM 0x02
  1001. #define SMB2_O_INFO_SECURITY 0x03
  1002. #define SMB2_O_INFO_QUOTA 0x04
  1003. /* Security info type additionalinfo flags. See MS-SMB2 (2.2.37) or MS-DTYP */
  1004. #define OWNER_SECINFO 0x00000001
  1005. #define GROUP_SECINFO 0x00000002
  1006. #define DACL_SECINFO 0x00000004
  1007. #define SACL_SECINFO 0x00000008
  1008. #define LABEL_SECINFO 0x00000010
  1009. #define ATTRIBUTE_SECINFO 0x00000020
  1010. #define SCOPE_SECINFO 0x00000040
  1011. #define BACKUP_SECINFO 0x00010000
  1012. #define UNPROTECTED_SACL_SECINFO 0x10000000
  1013. #define UNPROTECTED_DACL_SECINFO 0x20000000
  1014. #define PROTECTED_SACL_SECINFO 0x40000000
  1015. #define PROTECTED_DACL_SECINFO 0x80000000
  1016. /* Flags used for FileFullEAinfo */
  1017. #define SL_RESTART_SCAN 0x00000001
  1018. #define SL_RETURN_SINGLE_ENTRY 0x00000002
  1019. #define SL_INDEX_SPECIFIED 0x00000004
  1020. struct smb2_query_info_req {
  1021. struct smb2_sync_hdr sync_hdr;
  1022. __le16 StructureSize; /* Must be 41 */
  1023. __u8 InfoType;
  1024. __u8 FileInfoClass;
  1025. __le32 OutputBufferLength;
  1026. __le16 InputBufferOffset;
  1027. __u16 Reserved;
  1028. __le32 InputBufferLength;
  1029. __le32 AdditionalInformation;
  1030. __le32 Flags;
  1031. __u64 PersistentFileId; /* opaque endianness */
  1032. __u64 VolatileFileId; /* opaque endianness */
  1033. __u8 Buffer[1];
  1034. } __packed;
  1035. struct smb2_query_info_rsp {
  1036. struct smb2_sync_hdr sync_hdr;
  1037. __le16 StructureSize; /* Must be 9 */
  1038. __le16 OutputBufferOffset;
  1039. __le32 OutputBufferLength;
  1040. __u8 Buffer[1];
  1041. } __packed;
  1042. struct smb2_set_info_req {
  1043. struct smb2_sync_hdr sync_hdr;
  1044. __le16 StructureSize; /* Must be 33 */
  1045. __u8 InfoType;
  1046. __u8 FileInfoClass;
  1047. __le32 BufferLength;
  1048. __le16 BufferOffset;
  1049. __u16 Reserved;
  1050. __le32 AdditionalInformation;
  1051. __u64 PersistentFileId; /* opaque endianness */
  1052. __u64 VolatileFileId; /* opaque endianness */
  1053. __u8 Buffer[1];
  1054. } __packed;
  1055. struct smb2_set_info_rsp {
  1056. struct smb2_sync_hdr sync_hdr;
  1057. __le16 StructureSize; /* Must be 2 */
  1058. } __packed;
  1059. struct smb2_oplock_break {
  1060. struct smb2_sync_hdr sync_hdr;
  1061. __le16 StructureSize; /* Must be 24 */
  1062. __u8 OplockLevel;
  1063. __u8 Reserved;
  1064. __le32 Reserved2;
  1065. __u64 PersistentFid;
  1066. __u64 VolatileFid;
  1067. } __packed;
  1068. #define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
  1069. struct smb2_lease_break {
  1070. struct smb2_sync_hdr sync_hdr;
  1071. __le16 StructureSize; /* Must be 44 */
  1072. __le16 Epoch;
  1073. __le32 Flags;
  1074. __u8 LeaseKey[16];
  1075. __le32 CurrentLeaseState;
  1076. __le32 NewLeaseState;
  1077. __le32 BreakReason;
  1078. __le32 AccessMaskHint;
  1079. __le32 ShareMaskHint;
  1080. } __packed;
  1081. struct smb2_lease_ack {
  1082. struct smb2_sync_hdr sync_hdr;
  1083. __le16 StructureSize; /* Must be 36 */
  1084. __le16 Reserved;
  1085. __le32 Flags;
  1086. __u8 LeaseKey[16];
  1087. __le32 LeaseState;
  1088. __le64 LeaseDuration;
  1089. } __packed;
  1090. /*
  1091. * PDU infolevel structure definitions
  1092. * BB consider moving to a different header
  1093. */
  1094. /* File System Information Classes */
  1095. #define FS_VOLUME_INFORMATION 1 /* Query */
  1096. #define FS_LABEL_INFORMATION 2 /* Local only */
  1097. #define FS_SIZE_INFORMATION 3 /* Query */
  1098. #define FS_DEVICE_INFORMATION 4 /* Query */
  1099. #define FS_ATTRIBUTE_INFORMATION 5 /* Query */
  1100. #define FS_CONTROL_INFORMATION 6 /* Query, Set */
  1101. #define FS_FULL_SIZE_INFORMATION 7 /* Query */
  1102. #define FS_OBJECT_ID_INFORMATION 8 /* Query, Set */
  1103. #define FS_DRIVER_PATH_INFORMATION 9 /* Local only */
  1104. #define FS_VOLUME_FLAGS_INFORMATION 10 /* Local only */
  1105. #define FS_SECTOR_SIZE_INFORMATION 11 /* SMB3 or later. Query */
  1106. #define FS_POSIX_INFORMATION 100 /* SMB3.1.1 POSIX. Query */
  1107. struct smb2_fs_full_size_info {
  1108. __le64 TotalAllocationUnits;
  1109. __le64 CallerAvailableAllocationUnits;
  1110. __le64 ActualAvailableAllocationUnits;
  1111. __le32 SectorsPerAllocationUnit;
  1112. __le32 BytesPerSector;
  1113. } __packed;
  1114. #define SSINFO_FLAGS_ALIGNED_DEVICE 0x00000001
  1115. #define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE 0x00000002
  1116. #define SSINFO_FLAGS_NO_SEEK_PENALTY 0x00000004
  1117. #define SSINFO_FLAGS_TRIM_ENABLED 0x00000008
  1118. /* sector size info struct */
  1119. struct smb3_fs_ss_info {
  1120. __le32 LogicalBytesPerSector;
  1121. __le32 PhysicalBytesPerSectorForAtomicity;
  1122. __le32 PhysicalBytesPerSectorForPerf;
  1123. __le32 FileSystemEffectivePhysicalBytesPerSectorForAtomicity;
  1124. __le32 Flags;
  1125. __le32 ByteOffsetForSectorAlignment;
  1126. __le32 ByteOffsetForPartitionAlignment;
  1127. } __packed;
  1128. /* volume info struct - see MS-FSCC 2.5.9 */
  1129. #define MAX_VOL_LABEL_LEN 32
  1130. struct smb3_fs_vol_info {
  1131. __le64 VolumeCreationTime;
  1132. __u32 VolumeSerialNumber;
  1133. __le32 VolumeLabelLength; /* includes trailing null */
  1134. __u8 SupportsObjects; /* True if eg like NTFS, supports objects */
  1135. __u8 Reserved;
  1136. __u8 VolumeLabel[0]; /* variable len */
  1137. } __packed;
  1138. /* partial list of QUERY INFO levels */
  1139. #define FILE_DIRECTORY_INFORMATION 1
  1140. #define FILE_FULL_DIRECTORY_INFORMATION 2
  1141. #define FILE_BOTH_DIRECTORY_INFORMATION 3
  1142. #define FILE_BASIC_INFORMATION 4
  1143. #define FILE_STANDARD_INFORMATION 5
  1144. #define FILE_INTERNAL_INFORMATION 6
  1145. #define FILE_EA_INFORMATION 7
  1146. #define FILE_ACCESS_INFORMATION 8
  1147. #define FILE_NAME_INFORMATION 9
  1148. #define FILE_RENAME_INFORMATION 10
  1149. #define FILE_LINK_INFORMATION 11
  1150. #define FILE_NAMES_INFORMATION 12
  1151. #define FILE_DISPOSITION_INFORMATION 13
  1152. #define FILE_POSITION_INFORMATION 14
  1153. #define FILE_FULL_EA_INFORMATION 15
  1154. #define FILE_MODE_INFORMATION 16
  1155. #define FILE_ALIGNMENT_INFORMATION 17
  1156. #define FILE_ALL_INFORMATION 18
  1157. #define FILE_ALLOCATION_INFORMATION 19
  1158. #define FILE_END_OF_FILE_INFORMATION 20
  1159. #define FILE_ALTERNATE_NAME_INFORMATION 21
  1160. #define FILE_STREAM_INFORMATION 22
  1161. #define FILE_PIPE_INFORMATION 23
  1162. #define FILE_PIPE_LOCAL_INFORMATION 24
  1163. #define FILE_PIPE_REMOTE_INFORMATION 25
  1164. #define FILE_MAILSLOT_QUERY_INFORMATION 26
  1165. #define FILE_MAILSLOT_SET_INFORMATION 27
  1166. #define FILE_COMPRESSION_INFORMATION 28
  1167. #define FILE_OBJECT_ID_INFORMATION 29
  1168. /* Number 30 not defined in documents */
  1169. #define FILE_MOVE_CLUSTER_INFORMATION 31
  1170. #define FILE_QUOTA_INFORMATION 32
  1171. #define FILE_REPARSE_POINT_INFORMATION 33
  1172. #define FILE_NETWORK_OPEN_INFORMATION 34
  1173. #define FILE_ATTRIBUTE_TAG_INFORMATION 35
  1174. #define FILE_TRACKING_INFORMATION 36
  1175. #define FILEID_BOTH_DIRECTORY_INFORMATION 37
  1176. #define FILEID_FULL_DIRECTORY_INFORMATION 38
  1177. #define FILE_VALID_DATA_LENGTH_INFORMATION 39
  1178. #define FILE_SHORT_NAME_INFORMATION 40
  1179. #define FILE_SFIO_RESERVE_INFORMATION 44
  1180. #define FILE_SFIO_VOLUME_INFORMATION 45
  1181. #define FILE_HARD_LINK_INFORMATION 46
  1182. #define FILE_NORMALIZED_NAME_INFORMATION 48
  1183. #define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50
  1184. #define FILE_STANDARD_LINK_INFORMATION 54
  1185. struct smb2_file_internal_info {
  1186. __le64 IndexNumber;
  1187. } __packed; /* level 6 Query */
  1188. struct smb2_file_rename_info { /* encoding of request for level 10 */
  1189. __u8 ReplaceIfExists; /* 1 = replace existing target with new */
  1190. /* 0 = fail if target already exists */
  1191. __u8 Reserved[7];
  1192. __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
  1193. __le32 FileNameLength;
  1194. char FileName[0]; /* New name to be assigned */
  1195. } __packed; /* level 10 Set */
  1196. struct smb2_file_link_info { /* encoding of request for level 11 */
  1197. __u8 ReplaceIfExists; /* 1 = replace existing link with new */
  1198. /* 0 = fail if link already exists */
  1199. __u8 Reserved[7];
  1200. __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
  1201. __le32 FileNameLength;
  1202. char FileName[0]; /* Name to be assigned to new link */
  1203. } __packed; /* level 11 Set */
  1204. #define SMB2_MIN_EA_BUF 2048
  1205. #define SMB2_MAX_EA_BUF 65536
  1206. struct smb2_file_full_ea_info { /* encoding of response for level 15 */
  1207. __le32 next_entry_offset;
  1208. __u8 flags;
  1209. __u8 ea_name_length;
  1210. __le16 ea_value_length;
  1211. char ea_data[0]; /* \0 terminated name plus value */
  1212. } __packed; /* level 15 Set */
  1213. /*
  1214. * This level 18, although with struct with same name is different from cifs
  1215. * level 0x107. Level 0x107 has an extra u64 between AccessFlags and
  1216. * CurrentByteOffset.
  1217. */
  1218. struct smb2_file_all_info { /* data block encoding of response to level 18 */
  1219. __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */
  1220. __le64 LastAccessTime;
  1221. __le64 LastWriteTime;
  1222. __le64 ChangeTime;
  1223. __le32 Attributes;
  1224. __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */
  1225. __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
  1226. __le64 EndOfFile; /* size ie offset to first free byte in file */
  1227. __le32 NumberOfLinks; /* hard links */
  1228. __u8 DeletePending;
  1229. __u8 Directory;
  1230. __u16 Pad2; /* End of FILE_STANDARD_INFO equivalent */
  1231. __le64 IndexNumber;
  1232. __le32 EASize;
  1233. __le32 AccessFlags;
  1234. __le64 CurrentByteOffset;
  1235. __le32 Mode;
  1236. __le32 AlignmentRequirement;
  1237. __le32 FileNameLength;
  1238. char FileName[1];
  1239. } __packed; /* level 18 Query */
  1240. struct smb2_file_eof_info { /* encoding of request for level 10 */
  1241. __le64 EndOfFile; /* new end of file value */
  1242. } __packed; /* level 20 Set */
  1243. extern char smb2_padding[7];
  1244. #endif /* _SMB2PDU_H */