15#define SMB_MAGIC 0x424d53ff
18#define SMB_HDR_SIZE 32
21#define SMB_FLAGS_SERVER_TO_REDIR 0x80
22#define SMB_FLAGS_REQUEST_BATCH_OPLOCK 0x40
23#define SMB_FLAGS_REQUEST_OPLOCK 0x20
24#define SMB_FLAGS_CANONICAL_PATHNAMES 0x10
25#define SMB_FLAGS_CASELESS_PATHNAMES 0x08
26#define SMB_FLAGS_RESERVED 0x04
27#define SMB_FLAGS_CLIENT_BUF_AVAIL 0x02
28#define SMB_FLAGS_SUPPORT_LOCKREAD 0x01
29#define SMB_FLAGS_MASK 0x00
32#define SMB_FLAGS2_UNICODE_STRING 0x8000
33#define SMB_FLAGS2_32BIT_STATUS 0x4000
34#define SMB_FLAGS2_READ_IF_EXECUTE 0x2000
35#define SMB_FLAGS2_DFS_PATHNAME 0x1000
36#define SMB_FLAGS2_EXTENDED_SECURITY 0x0800
37#define SMB_FLAGS2_RESERVED_01 0x0400
38#define SMB_FLAGS2_RESERVED_02 0x0200
39#define SMB_FLAGS2_RESERVED_03 0x0100
40#define SMB_FLAGS2_RESERVED_04 0x0080
41#define SMB_FLAGS2_IS_LONG_NAME 0x0040
42#define SMB_FLAGS2_RESERVED_05 0x0020
43#define SMB_FLAGS2_RESERVED_06 0x0010
44#define SMB_FLAGS2_RESERVED_07 0x0008
45#define SMB_FLAGS2_SECURITY_SIGNATURE 0x0004
46#define SMB_FLAGS2_EAS 0x0002
47#define SMB_FLAGS2_KNOWS_LONG_NAMES 0x0001
48#define SMB_FLAGS2_MASK 0xf847
51#define SMB_OFFSET_CMD 4
52#define SMB_OFFSET_NTSTATUS 5
53#define SMB_OFFSET_ECLASS 5
54#define SMB_OFFSET_ECODE 7
55#define SMB_OFFSET_FLAGS 9
56#define SMB_OFFSET_FLAGS2 10
57#define SMB_OFFSET_EXTRA 12
58#define SMB_OFFSET_TID 24
59#define SMB_OFFSET_PID 26
60#define SMB_OFFSET_UID 28
61#define SMB_OFFSET_MID 30
62#define SMB_OFFSET_WORDCOUNT 32
63#define SMB_OFFSET_ANDX_CMD 33
64#define SMB_OFFSET_ANDX_RESERVED 34
65#define SMB_OFFSET_ANDX_OFFSET 35
68#define SMB_TRANS2_REQ_OFFSET_TOTALPARAMCOUNT 33
69#define SMB_TRANS2_REQ_OFFSET_TOTALDATACOUNT 35
70#define SMB_TRANS2_REQ_OFFSET_MAXPARAMCOUNT 37
71#define SMB_TRANS2_REQ_OFFSET_MAXDATACOUNT 39
72#define SMB_TRANS2_REQ_OFFSET_MAXSETUPCOUNT 41
73#define SMB_TRANS2_REQ_OFFSET_RESERVED 42
74#define SMB_TRANS2_REQ_OFFSET_FLAGS 43
75#define SMB_TRANS2_REQ_OFFSET_TIMEOUT 45
76#define SMB_TRANS2_REQ_OFFSET_RESERVED2 49
77#define SMB_TRANS2_REQ_OFFSET_PARAMCOUNT 51
78#define SMB_TRANS2_REQ_OFFSET_PARAMOFFSET 53
79#define SMB_TRANS2_REQ_OFFSET_DATACOUNT 55
80#define SMB_TRANS2_REQ_OFFSET_DATAOFFSET 57
81#define SMB_TRANS2_REQ_OFFSET_SETUPCOUNT 59
82#define SMB_TRANS2_REQ_OFFSET_RESERVED3 60
83#define SMB_TRANS2_REQ_OFFSET_SETUP0 61
86#define SMB_TRANS2_RSP_OFFSET_TOTALPARAMCOUNT 33
87#define SMB_TRANS2_RSP_OFFSET_TOTALDATACOUNT 35
88#define SMB_TRANS2_RSP_OFFSET_RESERVED 37
89#define SMB_TRANS2_RSP_OFFSET_PARAMCOUNT 39
90#define SMB_TRANS2_RSP_OFFSET_PARAMOFFSET 41
91#define SMB_TRANS2_RSP_OFFSET_PARAMDISPLACEMENT 43
92#define SMB_TRANS2_RSP_OFFSET_DATACOUNT 45
93#define SMB_TRANS2_RSP_OFFSET_DATAOFFSET 47
94#define SMB_TRANS2_RSP_OFFSET_DATADISPLACEMENT 49
95#define SMB_TRANS2_RSP_OFFSET_SETUPCOUNT 51
96#define SMB_TRANS2_RSP_OFFSET_RESERVED2 52
97#define SMB_TRANS2_RSP_OFFSET_BYTECOUNT 53
98#define SMB_TRANS2_RSP_OFFSET_PAD 55
101#define ATTR_READONLY 0x01
102#define ATTR_HIDDEN 0x02
103#define ATTR_SYSTEM 0x04
104#define ATTR_VOLUME 0x08
105#define ATTR_DIRECTORY 0x10
106#define ATTR_ARCHIVE 0x20
109#define EXT_ATTR_READONLY 0x001
110#define EXT_ATTR_HIDDEN 0x002
111#define EXT_ATTR_SYSTEM 0x004
112#define EXT_ATTR_DIRECTORY 0x010
113#define EXT_ATTR_ARCHIVE 0x020
114#define EXT_ATTR_NORMAL 0x080
115#define EXT_ATTR_TEMPORARY 0x100
116#define EXT_ATTR_COMPRESSED 0x800
119#define SMB_INFO_STANDARD 0x001
120#define SMB_INFO_QUERY_EA_SIZE 0x002
121#define SMB_INFO_QUERY_EAS_FROM_LIST 0x003
122#define SMB_QUERY_FILE_BASIC_INFO 0x101
123#define SMB_QUERY_FILE_STANDARD_INFO 0x102
124#define SMB_FIND_FILE_NAMES_INFO 0x103
125#define SMB_FIND_FILE_BOTH_DIRECTORY_INFO 0x104
126#define SMB_FIND_FILE_UNIX 0x202
129#define CLOSE_SEARCH_AFTER_REQUEST 0x01
130#define CLOSE_SEARCH_IF_EOS 0x02
131#define RESUME_SEARCH 0x04
132#define CONTINUE_SEARCH 0x08
133#define BACKUP_INTENT_SEARCH 0x10
136#define SERVER_CAP_EXTENDED_SECURITY 0x80000000
137#define SERVER_CAP_COMPRESSED_DATA 0x40000000
138#define SERVER_CAP_BULK_TRANSFER 0x20000000
139#define SERVER_CAP_UNIX 0x00800000
140#define SERVER_CAP_LARGE_WRITEX 0x00008000
141#define SERVER_CAP_LARGE_READX 0x00004000
142#define SERVER_CAP_INFOLEVEL_PASSTHROUGH 0x00002000
143#define SERVER_CAP_DFS 0x00001000
144#define SERVER_CAP_NT_FIND 0x00000200
145#define SERVER_CAP_LOCK_AND_READ 0x00000100
146#define SERVER_CAP_LEVEL_II_OPLOCKS 0x00000080
147#define SERVER_CAP_STATUS32 0x00000040
148#define SERVER_CAP_RPC_REMOTE_APIS 0x00000020
149#define SERVER_CAP_NT_SMBS 0x00000010
150#define SERVER_CAP_LARGE_FILES 0x00000008
151#define SERVER_CAP_UNICODE 0x00000004
152#define SERVER_CAP_MPX_MODE 0x00000002
153#define SERVER_CAP_RAW_MODE 0x00000001
156#define CLIENT_CAP_EXTENDED_SECURITY SERVER_CAP_EXTENDED_SECURITY
157#define CLIENT_CAP_LARGE_WRITEX SERVER_CAP_LARGE_WRITEX
158#define CLIENT_CAP_LARGE_READX SERVER_CAP_LARGE_READX
159#define CLIENT_CAP_NT_FIND SERVER_CAP_NT_FIND
160#define CLIENT_CAP_LEVEL_II_OPLOCKS SERVER_CAP_LEVEL_II_OPLOCKS
161#define CLIENT_CAP_STATUS32 SERVER_CAP_STATUS32
162#define CLIENT_CAP_NT_SMBS SERVER_CAP_NT_SMBS
163#define CLIENT_CAP_LARGE_FILES SERVER_CAP_LARGE_FILES
164#define CLIENT_CAP_UNICODE SERVER_CAP_UNICODE
167#define NEGOTIATE_SECURITY_SIGNATURES_REQUIRED 0x08
168#define NEGOTIATE_SECURITY_SIGNATURES_ENABLED 0x04
169#define NEGOTIATE_SECURITY_CHALLENGE_RESPONSE 0x02
170#define NEGOTIATE_SECURITY_USER_LEVEL 0x01
173#define SMB_COM_CREATE_DIRECTORY 0x00
174#define SMB_COM_DELETE_DIRECTORY 0x01
175#define SMB_COM_OPEN 0x02
176#define SMB_COM_CREATE 0x03
177#define SMB_COM_CLOSE 0x04
178#define SMB_COM_FLUSH 0x05
179#define SMB_COM_DELETE 0x06
180#define SMB_COM_RENAME 0x07
181#define SMB_COM_QUERY_INFORMATION 0x08
182#define SMB_COM_SET_INFORMATION 0x09
183#define SMB_COM_READ 0x0a
184#define SMB_COM_WRITE 0x0b
185#define SMB_COM_LOCK_BYTE_RANGE 0x0c
186#define SMB_COM_UNLOCK_BYTE_RANGE 0x0d
187#define SMB_COM_CREATE_TEMPORARY 0x0e
188#define SMB_COM_CREATE_NEW 0x0f
189#define SMB_COM_CHECK_DIRECTORY 0x10
190#define SMB_COM_PROCESS_EXIT 0x11
191#define SMB_COM_SEEK 0x12
192#define SMB_COM_LOCK_AND_READ 0x13
193#define SMB_COM_WRITE_AND_UNLOCK 0x14
194#define SMB_COM_READ_RAW 0x1a
195#define SMB_COM_READ_MPX 0x1b
196#define SMB_COM_READ_MPX_SECONDARY 0x1c
197#define SMB_COM_WRITE_RAW 0x1d
198#define SMB_COM_WRITE_MPX 0x1e
199#define SMB_COM_WRITE_MPX_SECONDARY 0x1f
200#define SMB_COM_WRITE_COMPLETE 0x20
201#define SMB_COM_QUERY_SERVER 0x21
202#define SMB_COM_SET_INFORMATION2 0x22
203#define SMB_COM_QUERY_INFORMATION2 0x23
204#define SMB_COM_LOCKING_ANDX 0x24
205#define SMB_COM_TRANSACTION 0x25
206#define SMB_COM_TRANSACTION_SECONDARY 0x26
207#define SMB_COM_IOCTL 0x27
208#define SMB_COM_IOCTL_SECONDARY 0x28
209#define SMB_COM_COPY 0x29
210#define SMB_COM_MOVE 0x2a
211#define SMB_COM_ECHO 0x2b
212#define SMB_COM_WRITE_AND_CLOSE 0x2c
213#define SMB_COM_OPEN_ANDX 0x2d
214#define SMB_COM_READ_ANDX 0x2e
215#define SMB_COM_WRITE_ANDX 0x2f
216#define SMB_COM_NEW_FILE_SIZE 0x30
217#define SMB_COM_CLOSE_AND_TREE_DISC 0x31
218#define SMB_COM_TRANSACTION2 0x32
219#define SMB_COM_TRANSACTION2_SECONDARY 0x33
220#define SMB_COM_FIND_CLOSE2 0x34
221#define SMB_COM_FIND_NOTIFY_CLOSE 0x35
222#define SMB_COM_TREE_CONNECT 0x70
223#define SMB_COM_TREE_DISCONNECT 0x71
224#define SMB_COM_NEGOTIATE 0x72
225#define SMB_COM_SESSION_SETUP_ANDX 0x73
226#define SMB_COM_LOGOFF_ANDX 0x74
227#define SMB_COM_TREE_CONNECT_ANDX 0x75
228#define SMB_COM_QUERY_INFORMATION_DISK 0x80
229#define SMB_COM_SEARCH 0x81
230#define SMB_COM_FIND 0x82
231#define SMB_COM_FIND_UNIQUE 0x83
232#define SMB_COM_FIND_CLOSE 0x84
233#define SMB_COM_NT_TRANSACT 0xa0
234#define SMB_COM_NT_TRANSACT_SECONDARY 0xa1
235#define SMB_COM_NT_CREATE_ANDX 0xa2
236#define SMB_COM_NT_CANCEL 0xa4
237#define SMB_COM_NT_RENAME 0xa5
238#define SMB_COM_OPEN_PRINT_FILE 0xc0
239#define SMB_COM_WRITE_PRINT_FILE 0xc1
240#define SMB_COM_CLOSE_PRINT_FILE 0xc2
241#define SMB_COM_GET_PRINT_QUEUE 0xc3
242#define SMB_COM_READ_BULK 0xd8
243#define SMB_COM_WRITE_BULK 0xd9
244#define SMB_COM_WRITE_BULK_DATA 0xda
245#define SMB_COM_NONE 0xff
248#define TRANS2_OPEN2 0x00
249#define TRANS2_FIND_FIRST2 0x01
250#define TRANS2_FIND_NEXT2 0x02
251#define TRANS2_QUERY_FS_INFORMATION 0x03
252#define TRANS2_SET_FS_INFORMATION 0x04
253#define TRANS2_QUERY_PATH_INFORMATION 0X05
254#define TRANS2_SET_PATH_INFORMATION 0x06
255#define TRANS2_QUERY_FILE_INFORMATION 0x07
256#define TRANS2_SET_FILE_INFORMATION 0x08
257#define TRANS2_FSCTL 0x09
258#define TRANS2_IOCTL2 0x0a
259#define TRANS2_FIND_NOTIFY_FIRST 0x0b
260#define TRANS2_FIND_NOTIFY_NEXT 0x0c
261#define TRANS2_CREATE_DIRECTORY 0x0d
262#define TRANS2_SESSION_SETUP 0x0e
263#define TRANS2_GET_DFS_REFERRAL 0x10
264#define TRANS2_REPORT_DFS_INCONSISTENCY 0x11
267#define DOS_ECLASS_SUCCESS 0x00
270#define STATUS_SUCCESS 0x00000000
271#define STATUS_NO_MEDIA_IN_DEVICE 0xc0000013
272#define STATUS_ACCESS_DENIED 0xc0000022
273#define STATUS_OBJECT_NAME_NOT_FOUND 0xc0000034
274#define STATUS_LOGON_FAILURE 0xc000006d
285 char PrimaryDomainServerName[64];
289#define SERVER_SHARE_SECURITY_LEVEL 0
290#define SERVER_USER_SECURITY_LEVEL 1
291#define SERVER_USE_PLAINTEXT_PASSWORD 0
292#define SERVER_USE_ENCRYPTED_PASSWORD 1
357 u16 ParamDisplacement;
360 u16 DataDisplacement;
404 u16 AnsiPasswordLength;
405 u16 UnicodePasswordLength;
465 SMBTransactionRequest_t smbTrans;
474 SMBTransactionResponse_t smbTrans;
548 SMBTransactionRequest_t smbTrans;
558 SMBTransactionResponse_t smbTrans;
583 u16 SearchAttributes;
588 char SearchPattern[];
598 char SearchPattern[];
605 SMBTransactionRequest_t smbTrans;
633 u16 ShortFileNameLen;
634 u8 ShortFileName[24];
642 SMBTransactionResponse_t smbTrans;
657 u32 RootDirectoryFid;
662 u32 CreateDisposition;
664 u32 ImpersonationLevel;
702 u16 SearchAttributes;
761 u16 DataCompactionMode;
822 u16 SearchAttributes;
841 char DirectoryName[];
855 u16 SearchAttributes;
870extern int smb_Connect(
char *SMBServerIP,
int SMBServerPort);
871extern int smb_Disconnect(
void);
873extern int smb_NegotiateProtocol(u32 *capabilities);
874extern int smb_SessionSetupAndX(
char *User,
char *Password,
int PasswordType, u32 capabilities);
875extern int smb_TreeConnectAndX(
int UID,
char *ShareName,
char *Password,
int PasswordType);
876extern int smb_TreeDisconnect(
int UID,
int TID);
877extern int smb_NetShareEnum(
int UID,
int TID, ShareEntry_t *shareEntries,
int index,
int maxEntries);
878extern int smb_QueryInformationDisk(
int UID,
int TID, smbQueryDiskInfo_out_t *QueryInformationDisk);
879extern int smb_QueryPathInformation(
int UID,
int TID,
PathInformation_t *Info,
char *Path);
880extern int smb_FindFirstNext2(
int UID,
int TID,
char *Path,
int cmd,
SearchInfo_t *info);
881extern int smb_LogOffAndX(
int UID);
882extern int smb_Echo(
void *echo,
int len);
884extern int smb_OpenAndX(
int UID,
int TID,
char *filename, s64 *filesize,
int mode);
885extern int smb_ReadAndX(
int UID,
int TID,
int FID, s64 offset,
void *readbuf,
int nbytes);
886extern int smb_WriteAndX(
int UID,
int TID,
int FID, s64 offset,
void *writebuf,
int nbytes);
887extern int smb_ReadFile(
int UID,
int TID,
int FID, s64 fileoffset,
void *readbuf,
int nbytes);
888extern int smb_WriteFile(
int UID,
int TID,
int FID, s64 fileoffset,
void *writebuf,
int nbytes);
889extern int smb_Close(
int UID,
int TID,
int FID);
890extern int smb_Delete(
int UID,
int TID,
char *Path);
891extern int smb_ManageDirectory(
int UID,
int TID,
char *Path,
int cmd);
892extern int smb_Rename(
int UID,
int TID,
char *oldPath,
char *newPath);
894#define MAX_SMB_BUF 4096
895#define MAX_SMB_BUF_HDR 128