smb.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. #ifndef HEADER_CURL_SMB_H
  2. #define HEADER_CURL_SMB_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 2014, Bill Nagel <[email protected]>, Exacq Technologies
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at https://curl.haxx.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. ***************************************************************************/
  24. enum smb_conn_state {
  25. SMB_NOT_CONNECTED = 0,
  26. SMB_CONNECTING,
  27. SMB_NEGOTIATE,
  28. SMB_SETUP,
  29. SMB_CONNECTED
  30. };
  31. struct smb_conn {
  32. enum smb_conn_state state;
  33. char *user;
  34. char *domain;
  35. unsigned char challenge[8];
  36. unsigned int session_key;
  37. unsigned short uid;
  38. char *recv_buf;
  39. size_t upload_size;
  40. size_t send_size;
  41. size_t sent;
  42. size_t got;
  43. };
  44. /*
  45. * Definitions for SMB protocol data structures
  46. */
  47. #ifdef BUILDING_CURL_SMB_C
  48. #if defined(_MSC_VER) || defined(__ILEC400__)
  49. # define PACK
  50. # pragma pack(push)
  51. # pragma pack(1)
  52. #elif defined(__GNUC__)
  53. # define PACK __attribute__((packed))
  54. #else
  55. # define PACK
  56. #endif
  57. #define SMB_COM_CLOSE 0x04
  58. #define SMB_COM_READ_ANDX 0x2e
  59. #define SMB_COM_WRITE_ANDX 0x2f
  60. #define SMB_COM_TREE_DISCONNECT 0x71
  61. #define SMB_COM_NEGOTIATE 0x72
  62. #define SMB_COM_SETUP_ANDX 0x73
  63. #define SMB_COM_TREE_CONNECT_ANDX 0x75
  64. #define SMB_COM_NT_CREATE_ANDX 0xa2
  65. #define SMB_COM_NO_ANDX_COMMAND 0xff
  66. #define SMB_WC_CLOSE 0x03
  67. #define SMB_WC_READ_ANDX 0x0c
  68. #define SMB_WC_WRITE_ANDX 0x0e
  69. #define SMB_WC_SETUP_ANDX 0x0d
  70. #define SMB_WC_TREE_CONNECT_ANDX 0x04
  71. #define SMB_WC_NT_CREATE_ANDX 0x18
  72. #define SMB_FLAGS_CANONICAL_PATHNAMES 0x10
  73. #define SMB_FLAGS_CASELESS_PATHNAMES 0x08
  74. #define SMB_FLAGS2_UNICODE_STRINGS 0x8000
  75. #define SMB_FLAGS2_IS_LONG_NAME 0x0040
  76. #define SMB_FLAGS2_KNOWS_LONG_NAME 0x0001
  77. #define SMB_CAP_LARGE_FILES 0x08
  78. #define SMB_GENERIC_WRITE 0x40000000
  79. #define SMB_GENERIC_READ 0x80000000
  80. #define SMB_FILE_SHARE_ALL 0x07
  81. #define SMB_FILE_OPEN 0x01
  82. #define SMB_FILE_OVERWRITE_IF 0x05
  83. #define SMB_ERR_NOACCESS 0x00050001
  84. struct smb_header {
  85. unsigned char nbt_type;
  86. unsigned char nbt_flags;
  87. unsigned short nbt_length;
  88. unsigned char magic[4];
  89. unsigned char command;
  90. unsigned int status;
  91. unsigned char flags;
  92. unsigned short flags2;
  93. unsigned short pid_high;
  94. unsigned char signature[8];
  95. unsigned short pad;
  96. unsigned short tid;
  97. unsigned short pid;
  98. unsigned short uid;
  99. unsigned short mid;
  100. } PACK;
  101. struct smb_negotiate_response {
  102. struct smb_header h;
  103. unsigned char word_count;
  104. unsigned short dialect_index;
  105. unsigned char security_mode;
  106. unsigned short max_mpx_count;
  107. unsigned short max_number_vcs;
  108. unsigned int max_buffer_size;
  109. unsigned int max_raw_size;
  110. unsigned int session_key;
  111. unsigned int capabilities;
  112. unsigned int system_time_low;
  113. unsigned int system_time_high;
  114. unsigned short server_time_zone;
  115. unsigned char encryption_key_length;
  116. unsigned short byte_count;
  117. char bytes[1];
  118. } PACK;
  119. struct andx {
  120. unsigned char command;
  121. unsigned char pad;
  122. unsigned short offset;
  123. } PACK;
  124. struct smb_setup {
  125. unsigned char word_count;
  126. struct andx andx;
  127. unsigned short max_buffer_size;
  128. unsigned short max_mpx_count;
  129. unsigned short vc_number;
  130. unsigned int session_key;
  131. unsigned short lengths[2];
  132. unsigned int pad;
  133. unsigned int capabilities;
  134. unsigned short byte_count;
  135. char bytes[1024];
  136. } PACK;
  137. struct smb_tree_connect {
  138. unsigned char word_count;
  139. struct andx andx;
  140. unsigned short flags;
  141. unsigned short pw_len;
  142. unsigned short byte_count;
  143. char bytes[1024];
  144. } PACK;
  145. struct smb_nt_create {
  146. unsigned char word_count;
  147. struct andx andx;
  148. unsigned char pad;
  149. unsigned short name_length;
  150. unsigned int flags;
  151. unsigned int root_fid;
  152. unsigned int access;
  153. #ifdef HAVE_LONGLONG
  154. unsigned long long allocation_size;
  155. #else
  156. unsigned __int64 allocation_size;
  157. #endif
  158. unsigned int ext_file_attributes;
  159. unsigned int share_access;
  160. unsigned int create_disposition;
  161. unsigned int create_options;
  162. unsigned int impersonation_level;
  163. unsigned char security_flags;
  164. unsigned short byte_count;
  165. char bytes[1024];
  166. } PACK;
  167. struct smb_nt_create_response {
  168. struct smb_header h;
  169. unsigned char word_count;
  170. struct andx andx;
  171. unsigned char op_lock_level;
  172. unsigned short fid;
  173. unsigned int create_disposition;
  174. #ifdef HAVE_LONGLONG
  175. unsigned long long create_time;
  176. unsigned long long last_access_time;
  177. unsigned long long last_write_time;
  178. unsigned long long last_change_time;
  179. #else
  180. unsigned __int64 create_time;
  181. unsigned __int64 last_access_time;
  182. unsigned __int64 last_write_time;
  183. unsigned __int64 last_change_time;
  184. #endif
  185. unsigned int ext_file_attributes;
  186. #ifdef HAVE_LONGLONG
  187. unsigned long long allocation_size;
  188. unsigned long long end_of_file;
  189. #else
  190. unsigned __int64 allocation_size;
  191. unsigned __int64 end_of_file;
  192. #endif
  193. } PACK;
  194. struct smb_read {
  195. unsigned char word_count;
  196. struct andx andx;
  197. unsigned short fid;
  198. unsigned int offset;
  199. unsigned short max_bytes;
  200. unsigned short min_bytes;
  201. unsigned int timeout;
  202. unsigned short remaining;
  203. unsigned int offset_high;
  204. unsigned short byte_count;
  205. } PACK;
  206. struct smb_write {
  207. struct smb_header h;
  208. unsigned char word_count;
  209. struct andx andx;
  210. unsigned short fid;
  211. unsigned int offset;
  212. unsigned int timeout;
  213. unsigned short write_mode;
  214. unsigned short remaining;
  215. unsigned short pad;
  216. unsigned short data_length;
  217. unsigned short data_offset;
  218. unsigned int offset_high;
  219. unsigned short byte_count;
  220. unsigned char pad2;
  221. } PACK;
  222. struct smb_close {
  223. unsigned char word_count;
  224. unsigned short fid;
  225. unsigned int last_mtime;
  226. unsigned short byte_count;
  227. } PACK;
  228. struct smb_tree_disconnect {
  229. unsigned char word_count;
  230. unsigned short byte_count;
  231. } PACK;
  232. #if defined(_MSC_VER) || defined(__ILEC400__)
  233. # pragma pack(pop)
  234. #endif
  235. #endif /* BUILDING_CURL_SMB_C */
  236. #if !defined(CURL_DISABLE_SMB) && defined(USE_NTLM) && \
  237. (CURL_SIZEOF_CURL_OFF_T > 4)
  238. #if !defined(USE_WINDOWS_SSPI) || defined(USE_WIN32_CRYPTO)
  239. extern const struct Curl_handler Curl_handler_smb;
  240. extern const struct Curl_handler Curl_handler_smbs;
  241. #endif /* !USE_WINDOWS_SSPI || USE_WIN32_CRYPTO */
  242. #endif /* CURL_DISABLE_SMB && USE_NTLM && CURL_SIZEOF_CURL_OFF_T > 4 */
  243. #endif /* HEADER_CURL_SMB_H */