smb.h 6.7 KB

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