Print this page
NEX-17289 Minimal SMB 3.0.2 support
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
NEX-5665 SMB2 oplock leases
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
NEX-5665 SMB2 oplock leases
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
NEX-5273 SMB 3 Encryption
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
NEX-3553 SMB2/3 durable handles
Reviewed by: Gordon Ross <gwr@nexenta.com>
Reviewed by: Kevin Crowe <kevin.crowe@nexenta.com>
NEX-3733 Want SMB2 Apple extensions
Reviewed by: Kevin Crowe <kevin.crowe@nexenta.com>
Reviewed by: Matt Barden <Matt.Barden@nexenta.com>
NEX-3610 CLONE NEX-3591 SMB3 signing
Reviewed by: Gordon Ross <gwr@nexenta.com>
Reviewed by: Dan Fields <dan.fields@nexenta.com>
NEX-3080 SMB1 signing problem with Kerberos auth.
Reviewed by: Bayard Bell <bayard.bell@nexenta.com>
Reviewed by: Dan Fields <dan.fields@nexenta.com>
Reviewed by: Kevin Crowe <kevin.crowe@nexenta.com>
Reviewed by: Matt Barden <Matt.Barden@nexenta.com>
NEX-1734 SMB2 oplock break request missing a flag
SMB-79 Codenomicon: SMB2 TC: 4978 - Panic in smb_latency_add_sample
SMB-11 SMB2 message parse & dispatch
SMB-12 SMB2 Negotiate Protocol
SMB-13 SMB2 Session Setup
SMB-14 SMB2 Logoff
SMB-15 SMB2 Tree Connect
SMB-16 SMB2 Tree Disconnect
SMB-17 SMB2 Create
SMB-18 SMB2 Close
SMB-19 SMB2 Flush
SMB-20 SMB2 Read
SMB-21 SMB2 Write
SMB-22 SMB2 Lock/Unlock
SMB-23 SMB2 Ioctl
SMB-24 SMB2 Cancel
SMB-25 SMB2 Echo
SMB-26 SMB2 Query Dir
SMB-27 SMB2 Change Notify
SMB-28 SMB2 Query Info
SMB-29 SMB2 Set Info
SMB-30 SMB2 Oplocks
SMB-53 SMB2 Create Context options
(SMB2 code review cleanup 1, 2, 3)
   1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 
  12 /*
  13  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  14  */
  15 
  16 #ifndef _SMB_SMB2_H
  17 #define _SMB_SMB2_H
  18 
  19 #ifdef __cplusplus
  20 extern "C" {
  21 #endif
  22 
  23 #define SMB2_PROTOCOL_ID        { 0xFE, 'S', 'M', 'B' }
  24 #define SMB2_HDR_SIZE   64

  25 
  26 /*






  27  * SMB2 header command codes.
  28  * These are uint16_t on the wire.
  29  */
  30 typedef enum {
  31         SMB2_NEGOTIATE = 0,
  32         SMB2_SESSION_SETUP,
  33         SMB2_LOGOFF,
  34         SMB2_TREE_CONNECT,
  35         SMB2_TREE_DISCONNECT,
  36         SMB2_CREATE,
  37         SMB2_CLOSE,
  38         SMB2_FLUSH,
  39         SMB2_READ,
  40         SMB2_WRITE,
  41         SMB2_LOCK,
  42         SMB2_IOCTL,
  43         SMB2_CANCEL,
  44         SMB2_ECHO,
  45         SMB2_QUERY_DIRECTORY,
  46         SMB2_CHANGE_NOTIFY,


 132 #define SMB2_CAP_DFS                    0x00000001
 133 #define SMB2_CAP_LEASING                0x00000002
 134 /*
 135  * LARGE_MTU:
 136  * When set, indicates that the client supports multi-credit operations.
 137  */
 138 #define SMB2_CAP_LARGE_MTU              0x00000004
 139 
 140 /* Added with SMB3.0 */
 141 #define SMB2_CAP_MULTI_CHANNEL          0x00000008
 142 #define SMB2_CAP_PERSISTENT_HANDLES     0x00000010
 143 #define SMB2_CAP_DIRECTORY_LEASING      0x00000020
 144 #define SMB2_CAP_ENCRYPTION             0x00000040
 145 
 146 /* SMB2 session flags */
 147 #define SMB2_SESSION_FLAG_IS_GUEST      0x0001
 148 #define SMB2_SESSION_FLAG_IS_NULL       0x0002
 149 #define SMB2_SESSION_FLAG_ENCRYPT_DATA  0x0004
 150 
 151 /*





 152  * SMB2 Tree connect, disconnect
 153  */
 154 
 155 /* SMB2 sharetype flags */
 156 #define SMB2_SHARE_TYPE_DISK            0x1
 157 #define SMB2_SHARE_TYPE_PIPE            0x2
 158 #define SMB2_SHARE_TYPE_PRINT           0x3
 159 
 160 /* SMB2 share flags */
 161 #define SMB2_SHAREFLAG_MANUAL_CACHING                   0x00000000
 162 #define SMB2_SHAREFLAG_AUTO_CACHING                     0x00000010
 163 #define SMB2_SHAREFLAG_VDO_CACHING                      0x00000020
 164 #define SMB2_SHAREFLAG_NO_CACHING                       0x00000030
 165 #define SMB2_SHAREFLAG_DFS                              0x00000001
 166 #define SMB2_SHAREFLAG_DFS_ROOT                         0x00000002
 167 #define SMB2_SHAREFLAG_RESTRICT_EXCLUSIVE_OPENS         0x00000100
 168 #define SMB2_SHAREFLAG_FORCE_SHARED_DELETE              0x00000200
 169 #define SMB2_SHAREFLAG_ALLOW_NAMESPACE_CACHING          0x00000400
 170 #define SMB2_SHAREFLAG_ACCESS_BASED_DIRECTORY_ENUM      0x00000800
 171 #define SMB2_SHAREFLAG_FORCE_LEVELII_OPLOCK             0x00001000
 172 /* SMB 3.0 */
 173 #define SMB2_SHAREFLAG_ENABLE_HASH_V1                   0x00002000
 174 #define SMB2_SHAREFLAG_ENABLE_HASH_V2                   0x00004000
 175 #define SMB2_SHAREFLAG_ENCRYPT_DATA                     0x00008000
 176 
 177 /* SMB2 share capabilities */
 178 #define SMB2_SHARE_CAP_DFS                              0x00000008
 179 /* SMB 3.0 */
 180 #define SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY          0x00000010
 181 #define SMB2_SHARE_CAP_SCALEOUT                         0x00000020
 182 #define SMB2_SHARE_CAP_CLUSTER                          0x00000040
 183 
 184 /*
 185  * SMB2 Create (open)
 186  */
 187 
 188 /* SMB2 requested oplock levels */



 189 #define SMB2_OPLOCK_LEVEL_NONE                          0x00
 190 #define SMB2_OPLOCK_LEVEL_II                            0x01
 191 #define SMB2_OPLOCK_LEVEL_EXCLUSIVE                     0x08
 192 #define SMB2_OPLOCK_LEVEL_BATCH                         0x09
 193 #define SMB2_OPLOCK_LEVEL_LEASE                         0xFF
 194 













 195 /* SMB2 impersonation levels */
 196 #define SMB2_IMPERSONATION_ANONYMOUS                    0x00
 197 #define SMB2_IMPERSONATION_IDENTIFICATION               0x01
 198 #define SMB2_IMPERSONATION_IMPERSONATION                0x02
 199 #define SMB2_IMPERSONATION_DELEGATE                     0x03
 200 
 201 /*
 202  * Note: ShareAccess, CreateDispositon, CreateOptions,
 203  * all use the same definitions as SMB1 (from MS-FSA).
 204  * Ditto FileAccess flags (as with ACLs)
 205  */
 206 
 207 /* SMB2 Create Context tags */
 208 
 209 #define SMB2_CREATE_EA_BUFFER                   0x45787441 /* ("ExtA") */
 210 /*
 211  * The data contains the extended attributes
 212  * that MUST be stored on the created file.
 213  * This value MUST NOT be set for named
 214  * pipes and print files.


 240 #define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQ    0x4d784163 /* ("MxAc") */
 241 /*
 242  * The client is requesting that the server
 243  * return maximal access information.
 244  */
 245 
 246 #define SMB2_CREATE_TIMEWARP_TOKEN              0x54577270 /* ("TWrp") */
 247 /*
 248  * The client is requesting that the server
 249  * open an earlier version of the file identified
 250  * by the provided time stamp.
 251  */
 252 
 253 #define SMB2_CREATE_QUERY_ON_DISK_ID            0x51466964 /* ("QFid") */
 254 /*
 255  * The client is requesting that the server return a 32-byte
 256  * opaque BLOB that uniquely identifies the file being opened
 257  * on disk. No data is passed to the server by the client.
 258  */
 259 
















 260 #define SMB2_CREATE_REQUEST_LEASE               0x52714c73 /* ("RqLs") */
 261 /*
 262  * The client is requesting that the server return a lease.
 263  * This value is only supported for the SMB 2.1 and 3.0 dialects.
 264  */
 265 
 266 /* SMB2 create request lease */
 267 #define SMB2_LEASE_NONE                         0x00
 268 #define SMB2_LEASE_READ_CACHING                 0x01
 269 #define SMB2_LEASE_HANDLE_CACHING               0x02
 270 #define SMB2_LEASE_WRITE_CACHING                0x04
 271 
 272 /* SMB2 lease break notification flags */
 273 #define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED  0x01
 274 
 275 /*
 276  * SMB2 Close
 277  */
 278 #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB        0x0001
 279 
 280 /*





 281  * SMB2 Write
 282  */
 283 #define SMB2_WRITEFLAG_WRITE_THROUGH            0x00000001

 284 
 285 /*
 286  * SMB2 Lock Request
 287  */
 288 
 289 /* SMB2 lock flags */
 290 
 291 /*
 292  * SMB2_LOCKFLAG_SHARED_LOCK
 293  * The range MUST be locked shared, allowing other opens
 294  * to read from or take a shared lock on the range. All opens
 295  * MUST NOT be allowed to write within the range. Other
 296  * locks can be requested and taken on this range.
 297  */
 298 #define SMB2_LOCKFLAG_SHARED_LOCK       0x00000001
 299 
 300 /*
 301  * SMB2_LOCKFLAG_EXCLUSIVE_LOCK
 302  * The range MUST be locked exclusive, not allowing other
 303  * opens to read, write, or lock within the range.


 347 
 348 /*
 349  * SMB2 Query Info Request
 350  */
 351 
 352 /* info type */
 353 #define SMB2_0_INFO_FILE                0x01
 354 /* The file information is requested. */
 355 #define SMB2_0_INFO_FILESYSTEM          0x02
 356 /* The underlying object store information is requested. */
 357 #define SMB2_0_INFO_SECURITY            0x03
 358 /* The security information is requested. */
 359 #define SMB2_0_INFO_QUOTA               0x04
 360 /* The underlying object store quota information is requested. */
 361 
 362 /*
 363  * SMB2 Change Nofity Request
 364  */
 365 #define SMB2_WATCH_TREE                 0x00000001
 366 



 367 #ifdef __cplusplus
 368 }
 369 #endif
 370 
 371 #endif /* _SMB_SMB2_H */
   1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 
  12 /*
  13  * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
  14  */
  15 
  16 #ifndef _SMB_SMB2_H
  17 #define _SMB_SMB2_H
  18 
  19 #ifdef __cplusplus
  20 extern "C" {
  21 #endif
  22 
  23 #define SMB2_PROTOCOL_ID        { 0xFE, 'S', 'M', 'B' }
  24 #define SMB2_HDR_SIZE   64
  25 #define SMB3_TFORM_HDR_SIZE     52
  26 
  27 /*
  28  * Protocol ID as a 32-bit little-endian integer.
  29  */
  30 #define SMB2_PROTOCOL_MAGIC     0x424d53fe
  31 #define SMB3_ENCRYPTED_MAGIC    0x424d53fd
  32 
  33 /*
  34  * SMB2 header command codes.
  35  * These are uint16_t on the wire.
  36  */
  37 typedef enum {
  38         SMB2_NEGOTIATE = 0,
  39         SMB2_SESSION_SETUP,
  40         SMB2_LOGOFF,
  41         SMB2_TREE_CONNECT,
  42         SMB2_TREE_DISCONNECT,
  43         SMB2_CREATE,
  44         SMB2_CLOSE,
  45         SMB2_FLUSH,
  46         SMB2_READ,
  47         SMB2_WRITE,
  48         SMB2_LOCK,
  49         SMB2_IOCTL,
  50         SMB2_CANCEL,
  51         SMB2_ECHO,
  52         SMB2_QUERY_DIRECTORY,
  53         SMB2_CHANGE_NOTIFY,


 139 #define SMB2_CAP_DFS                    0x00000001
 140 #define SMB2_CAP_LEASING                0x00000002
 141 /*
 142  * LARGE_MTU:
 143  * When set, indicates that the client supports multi-credit operations.
 144  */
 145 #define SMB2_CAP_LARGE_MTU              0x00000004
 146 
 147 /* Added with SMB3.0 */
 148 #define SMB2_CAP_MULTI_CHANNEL          0x00000008
 149 #define SMB2_CAP_PERSISTENT_HANDLES     0x00000010
 150 #define SMB2_CAP_DIRECTORY_LEASING      0x00000020
 151 #define SMB2_CAP_ENCRYPTION             0x00000040
 152 
 153 /* SMB2 session flags */
 154 #define SMB2_SESSION_FLAG_IS_GUEST      0x0001
 155 #define SMB2_SESSION_FLAG_IS_NULL       0x0002
 156 #define SMB2_SESSION_FLAG_ENCRYPT_DATA  0x0004
 157 
 158 /*
 159  * Client wants to bind an existing session to a new connection
 160  */
 161 #define SMB2_SESSION_FLAG_BINDING       0x01
 162 
 163 /*
 164  * SMB2 Tree connect, disconnect
 165  */
 166 
 167 /* SMB2 sharetype flags */
 168 #define SMB2_SHARE_TYPE_DISK            0x1
 169 #define SMB2_SHARE_TYPE_PIPE            0x2
 170 #define SMB2_SHARE_TYPE_PRINT           0x3
 171 
 172 /* SMB2 share flags */
 173 #define SMB2_SHAREFLAG_MANUAL_CACHING                   0x00000000
 174 #define SMB2_SHAREFLAG_AUTO_CACHING                     0x00000010
 175 #define SMB2_SHAREFLAG_VDO_CACHING                      0x00000020
 176 #define SMB2_SHAREFLAG_NO_CACHING                       0x00000030
 177 #define SMB2_SHAREFLAG_DFS                              0x00000001
 178 #define SMB2_SHAREFLAG_DFS_ROOT                         0x00000002
 179 #define SMB2_SHAREFLAG_RESTRICT_EXCLUSIVE_OPENS         0x00000100
 180 #define SMB2_SHAREFLAG_FORCE_SHARED_DELETE              0x00000200
 181 #define SMB2_SHAREFLAG_ALLOW_NAMESPACE_CACHING          0x00000400
 182 #define SMB2_SHAREFLAG_ACCESS_BASED_DIRECTORY_ENUM      0x00000800
 183 #define SMB2_SHAREFLAG_FORCE_LEVELII_OPLOCK             0x00001000
 184 /* SMB 3.0 */
 185 #define SMB2_SHAREFLAG_ENABLE_HASH_V1                   0x00002000
 186 #define SMB2_SHAREFLAG_ENABLE_HASH_V2                   0x00004000
 187 #define SMB2_SHAREFLAG_ENCRYPT_DATA                     0x00008000
 188 
 189 /* SMB2 share capabilities */
 190 #define SMB2_SHARE_CAP_DFS                              0x00000008
 191 /* SMB 3.0 */
 192 #define SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY          0x00000010
 193 #define SMB2_SHARE_CAP_SCALEOUT                         0x00000020
 194 #define SMB2_SHARE_CAP_CLUSTER                          0x00000040
 195 
 196 /*
 197  * SMB2 Create (open)
 198  */
 199 
 200 /*
 201  * SMB2 requested oplock levels
 202  * Corresponds to ntifs.h OPLOCK_LEVEL_... but NOT the same!
 203  */
 204 #define SMB2_OPLOCK_LEVEL_NONE                          0x00
 205 #define SMB2_OPLOCK_LEVEL_II                            0x01
 206 #define SMB2_OPLOCK_LEVEL_EXCLUSIVE                     0x08
 207 #define SMB2_OPLOCK_LEVEL_BATCH                         0x09
 208 #define SMB2_OPLOCK_LEVEL_LEASE                         0xFF
 209 
 210 /*
 211  * SMB2 create request lease "type"
 212  * Note: Same as ntifs.h OPLOCK_LEVEL_CACHE...
 213  */
 214 #define SMB2_LEASE_NONE                                 0x00
 215 #define SMB2_LEASE_READ_CACHING                         0x01
 216 #define SMB2_LEASE_HANDLE_CACHING                       0x02
 217 #define SMB2_LEASE_WRITE_CACHING                        0x04
 218 
 219 /* SMB2 create lease flags */
 220 #define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS               0x00000002
 221 #define SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET            0x00000004
 222 
 223 /* SMB2 impersonation levels */
 224 #define SMB2_IMPERSONATION_ANONYMOUS                    0x00
 225 #define SMB2_IMPERSONATION_IDENTIFICATION               0x01
 226 #define SMB2_IMPERSONATION_IMPERSONATION                0x02
 227 #define SMB2_IMPERSONATION_DELEGATE                     0x03
 228 
 229 /*
 230  * Note: ShareAccess, CreateDispositon, CreateOptions,
 231  * all use the same definitions as SMB1 (from MS-FSA).
 232  * Ditto FileAccess flags (as with ACLs)
 233  */
 234 
 235 /* SMB2 Create Context tags */
 236 
 237 #define SMB2_CREATE_EA_BUFFER                   0x45787441 /* ("ExtA") */
 238 /*
 239  * The data contains the extended attributes
 240  * that MUST be stored on the created file.
 241  * This value MUST NOT be set for named
 242  * pipes and print files.


 268 #define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQ    0x4d784163 /* ("MxAc") */
 269 /*
 270  * The client is requesting that the server
 271  * return maximal access information.
 272  */
 273 
 274 #define SMB2_CREATE_TIMEWARP_TOKEN              0x54577270 /* ("TWrp") */
 275 /*
 276  * The client is requesting that the server
 277  * open an earlier version of the file identified
 278  * by the provided time stamp.
 279  */
 280 
 281 #define SMB2_CREATE_QUERY_ON_DISK_ID            0x51466964 /* ("QFid") */
 282 /*
 283  * The client is requesting that the server return a 32-byte
 284  * opaque BLOB that uniquely identifies the file being opened
 285  * on disk. No data is passed to the server by the client.
 286  */
 287 
 288 #define SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2   0x44483251 /* ("DH2Q") */
 289 /*
 290  * The client is requesting the open to be durable.
 291  * This value is only supported for the SMB 3.x dialect family.
 292  */
 293 
 294 #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 0x44483243 /* ("DH2C") */
 295 /*
 296  * The client is requesting to reconnect to a
 297  * durable open after being disconnected.
 298  * This value is only supported for the SMB 3.x dialect family.
 299  */
 300 
 301 #define SMB2_DHANDLE_FLAG_PERSISTENT    0x00000002
 302 /* A persistent handle is requested. */
 303 
 304 #define SMB2_CREATE_REQUEST_LEASE               0x52714c73 /* ("RqLs") */
 305 /*
 306  * The client is requesting that the server return a lease.
 307  * This value is only supported for the SMB 2.1 and 3.0 dialects.
 308  */
 309 
 310 #define SMB2_CREATE_CTX_AAPL                    0x4141504c /* ("AAPL") */
 311 /*
 312  * Client is MacOS X looking for MacOS-specific extensions.
 313  */

 314 



 315 /*
 316  * SMB2 Close
 317  */
 318 #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB        0x0001
 319 
 320 /*
 321  * SMB2 Read
 322  */
 323 #define SMB2_READFLAG_READ_UNBUFFERED           0x00000001
 324 
 325 /*
 326  * SMB2 Write
 327  */
 328 #define SMB2_WRITEFLAG_WRITE_THROUGH            0x00000001
 329 #define SMB2_WRITEFLAG_WRITE_UNBUFFERED         0x00000002
 330 
 331 /*
 332  * SMB2 Lock Request
 333  */
 334 
 335 /* SMB2 lock flags */
 336 
 337 /*
 338  * SMB2_LOCKFLAG_SHARED_LOCK
 339  * The range MUST be locked shared, allowing other opens
 340  * to read from or take a shared lock on the range. All opens
 341  * MUST NOT be allowed to write within the range. Other
 342  * locks can be requested and taken on this range.
 343  */
 344 #define SMB2_LOCKFLAG_SHARED_LOCK       0x00000001
 345 
 346 /*
 347  * SMB2_LOCKFLAG_EXCLUSIVE_LOCK
 348  * The range MUST be locked exclusive, not allowing other
 349  * opens to read, write, or lock within the range.


 393 
 394 /*
 395  * SMB2 Query Info Request
 396  */
 397 
 398 /* info type */
 399 #define SMB2_0_INFO_FILE                0x01
 400 /* The file information is requested. */
 401 #define SMB2_0_INFO_FILESYSTEM          0x02
 402 /* The underlying object store information is requested. */
 403 #define SMB2_0_INFO_SECURITY            0x03
 404 /* The security information is requested. */
 405 #define SMB2_0_INFO_QUOTA               0x04
 406 /* The underlying object store quota information is requested. */
 407 
 408 /*
 409  * SMB2 Change Nofity Request
 410  */
 411 #define SMB2_WATCH_TREE                 0x00000001
 412 
 413 /* SMB2 Oplock Break: lease break notification flags */
 414 #define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED  0x01
 415 
 416 #ifdef __cplusplus
 417 }
 418 #endif
 419 
 420 #endif /* _SMB_SMB2_H */