/** * SMB2/3 Protocol Constants and Enumerations * Based on MS-SMB2 specification */ // SMB2 Protocol Magic Number export const SMB2_PROTOCOL_ID = 0x424D53FE; // "\xfeSMB" in little endian // SMB2 Header Size export const SMB2_HEADER_SIZE = 64; // SMB2 Dialect Revisions export enum SMB2_DIALECTS { SMB2_0_2 = 0x0202, SMB2_1_0 = 0x0210, SMB3_0_0 = 0x0300, SMB3_0_2 = 0x0302, SMB3_1_1 = 0x0311, } // SMB2 Command Codes export enum SMB2_COMMANDS { NEGOTIATE = 0x0000, SESSION_SETUP = 0x0001, LOGOFF = 0x0002, TREE_CONNECT = 0x0003, TREE_DISCONNECT = 0x0004, CREATE = 0x0005, CLOSE = 0x0006, FLUSH = 0x0007, READ = 0x0008, WRITE = 0x0009, LOCK = 0x000A, IOCTL = 0x000B, CANCEL = 0x000C, ECHO = 0x000D, QUERY_DIRECTORY = 0x000E, CHANGE_NOTIFY = 0x000F, QUERY_INFO = 0x0010, SET_INFO = 0x0011, OPLOCK_BREAK = 0x0012, } // SMB2 Status Codes export enum SMB2_STATUS { SUCCESS = 0x00000000, INVALID_PARAMETER = 0xC000000D, NO_SUCH_FILE = 0xC000000F, ACCESS_DENIED = 0xC0000022, BUFFER_TOO_SMALL = 0xC0000023, OBJECT_NAME_INVALID = 0xC0000033, OBJECT_NAME_NOT_FOUND = 0xC0000034, OBJECT_NAME_COLLISION = 0xC0000035, OBJECT_PATH_INVALID = 0xC0000039, OBJECT_PATH_NOT_FOUND = 0xC000003A, SHARING_VIOLATION = 0xC0000043, DELETE_PENDING = 0xC0000056, DIRECTORY_NOT_EMPTY = 0xC0000066, NOT_A_DIRECTORY = 0xC0000103, FILE_IS_A_DIRECTORY = 0xC00000BA, NETWORK_NAME_DELETED = 0xC00000C9, BAD_NETWORK_NAME = 0xC00000CC, REQUEST_NOT_ACCEPTED = 0xC00000D0, MORE_PROCESSING_REQUIRED = 0xC0000016, LOGON_FAILURE = 0xC000006D, LOGON_TYPE_NOT_GRANTED = 0xC000015B, } // SMB2 Header Flags export enum SMB2_FLAGS { SERVER_TO_REDIR = 0x00000001, ASYNC_COMMAND = 0x00000002, RELATED_OPERATIONS = 0x00000004, SIGNED = 0x00000008, PRIORITY_MASK = 0x00000070, DFS_OPERATIONS = 0x10000000, REPLAY_OPERATION = 0x20000000, } // SMB2 Security Modes export enum SMB2_NEGOTIATE_SIGNING { ENABLED = 0x0001, REQUIRED = 0x0002, } // SMB2 Capabilities export enum SMB2_GLOBAL_CAP { DFS = 0x00000001, LEASING = 0x00000002, LARGE_MTU = 0x00000004, MULTI_CHANNEL = 0x00000008, PERSISTENT_HANDLES = 0x00000010, DIRECTORY_LEASING = 0x00000020, ENCRYPTION = 0x00000040, } // File Attributes export enum FILE_ATTRIBUTES { READONLY = 0x00000001, HIDDEN = 0x00000002, SYSTEM = 0x00000004, DIRECTORY = 0x00000010, ARCHIVE = 0x00000020, NORMAL = 0x00000080, TEMPORARY = 0x00000100, SPARSE_FILE = 0x00000200, REPARSE_POINT = 0x00000400, COMPRESSED = 0x00000800, OFFLINE = 0x00001000, NOT_CONTENT_INDEXED = 0x00002000, ENCRYPTED = 0x00004000, INTEGRITY_STREAM = 0x00008000, NO_SCRUB_DATA = 0x00020000, } // Access Rights export enum ACCESS_MASK { FILE_READ_DATA = 0x00000001, FILE_WRITE_DATA = 0x00000002, FILE_APPEND_DATA = 0x00000004, FILE_READ_EA = 0x00000008, FILE_WRITE_EA = 0x00000010, FILE_EXECUTE = 0x00000020, FILE_READ_ATTRIBUTES = 0x00000080, FILE_WRITE_ATTRIBUTES = 0x00000100, DELETE = 0x00010000, READ_CONTROL = 0x00020000, WRITE_DAC = 0x00040000, WRITE_OWNER = 0x00080000, SYNCHRONIZE = 0x00100000, ACCESS_SYSTEM_SECURITY = 0x01000000, MAXIMUM_ALLOWED = 0x02000000, GENERIC_ALL = 0x10000000, GENERIC_EXECUTE = 0x20000000, GENERIC_WRITE = 0x40000000, GENERIC_READ = 0x80000000, } // Share Access Rights export enum SHARE_ACCESS { NONE = 0x00000000, READ = 0x00000001, WRITE = 0x00000002, DELETE = 0x00000004, } // Create Disposition export enum CREATE_DISPOSITION { SUPERSEDE = 0x00000000, OPEN = 0x00000001, CREATE = 0x00000002, OPEN_IF = 0x00000003, OVERWRITE = 0x00000004, OVERWRITE_IF = 0x00000005, } // Create Options export enum CREATE_OPTIONS { DIRECTORY_FILE = 0x00000001, WRITE_THROUGH = 0x00000002, SEQUENTIAL_ONLY = 0x00000004, NO_INTERMEDIATE_BUFFERING = 0x00000008, SYNCHRONOUS_IO_ALERT = 0x00000010, SYNCHRONOUS_IO_NONALERT = 0x00000020, NON_DIRECTORY_FILE = 0x00000040, COMPLETE_IF_OPLOCKED = 0x00000100, NO_EA_KNOWLEDGE = 0x00000200, RANDOM_ACCESS = 0x00000800, DELETE_ON_CLOSE = 0x00001000, OPEN_BY_FILE_ID = 0x00002000, OPEN_FOR_BACKUP_INTENT = 0x00004000, NO_COMPRESSION = 0x00008000, OPEN_REMOTE_INSTANCE = 0x00000400, OPEN_REQUIRING_OPLOCK = 0x00010000, DISALLOW_EXCLUSIVE = 0x00020000, RESERVE_OPFILTER = 0x00100000, OPEN_REPARSE_POINT = 0x00200000, OPEN_NO_RECALL = 0x00400000, OPEN_FOR_FREE_SPACE_QUERY = 0x00800000, } // Oplock Levels export enum OPLOCK_LEVEL { NONE = 0x00, II = 0x01, EXCLUSIVE = 0x08, BATCH = 0x09, LEASE = 0xFF, } // Information Classes export enum FILE_INFORMATION_CLASS { FileDirectoryInformation = 1, FileFullDirectoryInformation = 2, FileBothDirectoryInformation = 3, FileBasicInformation = 4, FileStandardInformation = 5, FileInternalInformation = 6, FileEaInformation = 7, FileAccessInformation = 8, FileNameInformation = 9, FileRenameInformation = 10, FileLinkInformation = 11, FileNamesInformation = 12, FileDispositionInformation = 13, FilePositionInformation = 14, FileFullEaInformation = 15, FileModeInformation = 16, FileAlignmentInformation = 17, FileAllInformation = 18, FileAllocationInformation = 19, FileEndOfFileInformation = 20, FileAlternateNameInformation = 21, FileStreamInformation = 22, FilePipeInformation = 23, FilePipeLocalInformation = 24, FilePipeRemoteInformation = 25, FileMailslotQueryInformation = 26, FileMailslotSetInformation = 27, FileCompressionInformation = 28, FileObjectIdInformation = 29, FileCompletionInformation = 30, FileMoveClusterInformation = 31, FileQuotaInformation = 32, FileReparsePointInformation = 33, FileNetworkOpenInformation = 34, FileAttributeTagInformation = 35, FileTrackingInformation = 36, FileIdBothDirectoryInformation = 37, FileIdFullDirectoryInformation = 38, FileValidDataLengthInformation = 39, FileShortNameInformation = 40, FileIoCompletionNotificationInformation = 41, FileIoStatusBlockRangeInformation = 42, FileIoPriorityHintInformation = 43, FileSfioReserveInformation = 44, FileSfioVolumeInformation = 45, FileHardLinkInformation = 46, FileProcessIdsUsingFileInformation = 47, FileNormalizedNameInformation = 48, FileNetworkPhysicalNameInformation = 49, FileIdGlobalTxDirectoryInformation = 50, FileIsRemoteDeviceInformation = 51, FileUnusedInformation = 52, FileNumaNodeInformation = 53, FileStandardLinkInformation = 54, FileRemoteProtocolInformation = 55, FileRenameInformationBypassAccessCheck = 56, FileLinkInformationBypassAccessCheck = 57, FileVolumeNameInformation = 58, FileIdInformation = 59, FileIdExtdDirectoryInformation = 60, FileReplaceCompletionInformation = 61, FileHardLinkFullIdInformation = 62, FileIdExtdBothDirectoryInformation = 63, } // Security Information export enum SECURITY_INFORMATION { OWNER = 0x00000001, GROUP = 0x00000002, DACL = 0x00000004, SACL = 0x00000008, LABEL = 0x00000010, ATTRIBUTE = 0x00000020, SCOPE = 0x00000040, BACKUP = 0x00010000, } // Tree Connect Flags export enum TREE_CONNECT_FLAGS { CLUSTER_RECONNECT = 0x0001, REDIRECT_TO_OWNER = 0x0002, EXTENSION_PRESENT = 0x0004, } // Share Type export enum SHARE_TYPE { DISK = 0x01, PIPE = 0x02, PRINT = 0x03, } // Share Flags export enum SHARE_FLAGS { MANUAL_CACHING = 0x00000000, AUTO_CACHING = 0x00000010, VDO_CACHING = 0x00000020, NO_CACHING = 0x00000030, DFS = 0x00000001, DFS_ROOT = 0x00000002, RESTRICT_EXCLUSIVE_OPENS = 0x00000100, FORCE_SHARED_DELETE = 0x00000200, ALLOW_NAMESPACE_CACHING = 0x00000400, ACCESS_BASED_DIRECTORY_ENUM = 0x00000800, FORCE_LEVELII_OPLOCK = 0x00001000, ENABLE_HASH_V1 = 0x00002000, ENABLE_HASH_V2 = 0x00004000, ENCRYPT_DATA = 0x00008000, } // Share Capabilities export enum SHARE_CAPABILITIES { DFS = 0x00000008, CONTINUOUS_AVAILABILITY = 0x00000010, SCALEOUT = 0x00000020, CLUSTER = 0x00000040, ASYMMETRIC = 0x00000080, REDIRECT_TO_OWNER = 0x00000100, } // SMB2 Transform Header export const SMB2_TRANSFORM_PROTOCOL_ID = 0x424D53FD; // "\xfdSMB" export const SMB2_TRANSFORM_HEADER_SIZE = 52; // Encryption Algorithms export enum SMB2_ENCRYPTION_ALGORITHMS { AES128_CCM = 0x0001, AES128_GCM = 0x0002, AES256_CCM = 0x0003, AES256_GCM = 0x0004, } // Signing Algorithms export enum SMB2_SIGNING_ALGORITHMS { HMAC_SHA256 = 0x0000, AES_CMAC = 0x0001, AES_GMAC = 0x0002, } // Preauth Integrity Hash IDs export enum SMB2_PREAUTH_INTEGRITY_HASH_ID { SHA512 = 0x0001, } // Compression Algorithms export enum SMB2_COMPRESSION_ALGORITHMS { NONE = 0x0000, LZNT1 = 0x0001, LZ77 = 0x0002, LZ77_HUFFMAN = 0x0003, PATTERN_V1 = 0x0004, } // Default Values export const DEFAULT_MAX_TRANSACT_SIZE = 65536; export const DEFAULT_MAX_READ_SIZE = 65536; export const DEFAULT_MAX_WRITE_SIZE = 65536; export const DEFAULT_SESSION_TIMEOUT = 60; // seconds export const DEFAULT_CREDIT_CHARGE = 1; export const MIN_CREDIT_CHARGE = 1; export const MAX_CREDIT_CHARGE = 65535; // Buffer sizes export const MAX_BUFFER_SIZE = 16 * 1024 * 1024; // 16MB export const MIN_BUFFER_SIZE = 512; export const PREFERRED_BUFFER_SIZE = 64 * 1024; // 64KB // Timeouts export const NETWORK_TIMEOUT = 30000; // 30 seconds export const SESSION_TIMEOUT = 300000; // 5 minutes export const TREE_CONNECT_TIMEOUT = 60000; // 1 minute