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