smb.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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 - 2020, 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.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. char *share;
  37. unsigned char challenge[8];
  38. unsigned int session_key;
  39. unsigned short uid;
  40. char *recv_buf;
  41. size_t upload_size;
  42. size_t send_size;
  43. size_t sent;
  44. size_t got;
  45. };
  46. /*
  47. * Definitions for SMB protocol data structures
  48. */
  49. #ifdef BUILDING_CURL_SMB_C
  50. #if defined(_MSC_VER) || defined(__ILEC400__)
  51. # define PACK
  52. # pragma pack(push)
  53. # pragma pack(1)
  54. #elif defined(__GNUC__)
  55. # define PACK __attribute__((packed))
  56. #else
  57. # define PACK
  58. #endif
  59. #define SMB_COM_CLOSE 0x04
  60. #define SMB_COM_READ_ANDX 0x2e
  61. #define SMB_COM_WRITE_ANDX 0x2f
  62. #define SMB_COM_TREE_DISCONNECT 0x71
  63. #define SMB_COM_NEGOTIATE 0x72
  64. #define SMB_COM_SETUP_ANDX 0x73
  65. #define SMB_COM_TREE_CONNECT_ANDX 0x75
  66. #define SMB_COM_NT_CREATE_ANDX 0xa2
  67. #define SMB_COM_NO_ANDX_COMMAND 0xff
  68. #define SMB_WC_CLOSE 0x03
  69. #define SMB_WC_READ_ANDX 0x0c
  70. #define SMB_WC_WRITE_ANDX 0x0e
  71. #define SMB_WC_SETUP_ANDX 0x0d
  72. #define SMB_WC_TREE_CONNECT_ANDX 0x04
  73. #define SMB_WC_NT_CREATE_ANDX 0x18
  74. #define SMB_FLAGS_CANONICAL_PATHNAMES 0x10
  75. #define SMB_FLAGS_CASELESS_PATHNAMES 0x08
  76. #define SMB_FLAGS2_UNICODE_STRINGS 0x8000
  77. #define SMB_FLAGS2_IS_LONG_NAME 0x0040
  78. #define SMB_FLAGS2_KNOWS_LONG_NAME 0x0001
  79. #define SMB_CAP_LARGE_FILES 0x08
  80. #define SMB_GENERIC_WRITE 0x40000000
  81. #define SMB_GENERIC_READ 0x80000000
  82. #define SMB_FILE_SHARE_ALL 0x07
  83. #define SMB_FILE_OPEN 0x01
  84. #define SMB_FILE_OVERWRITE_IF 0x05
  85. #define SMB_ERR_NOACCESS 0x00050001
  86. struct smb_header {
  87. unsigned char nbt_type;
  88. unsigned char nbt_flags;
  89. unsigned short nbt_length;
  90. unsigned char magic[4];
  91. unsigned char command;
  92. unsigned int status;
  93. unsigned char flags;
  94. unsigned short flags2;
  95. unsigned short pid_high;
  96. unsigned char signature[8];
  97. unsigned short pad;
  98. unsigned short tid;
  99. unsigned short pid;
  100. unsigned short uid;
  101. unsigned short mid;
  102. } PACK;
  103. struct smb_negotiate_response {
  104. struct smb_header h;
  105. unsigned char word_count;
  106. unsigned short dialect_index;
  107. unsigned char security_mode;
  108. unsigned short max_mpx_count;
  109. unsigned short max_number_vcs;
  110. unsigned int max_buffer_size;
  111. unsigned int max_raw_size;
  112. unsigned int session_key;
  113. unsigned int capabilities;
  114. unsigned int system_time_low;
  115. unsigned int system_time_high;
  116. unsigned short server_time_zone;
  117. unsigned char encryption_key_length;
  118. unsigned short byte_count;
  119. char bytes[1];
  120. } PACK;
  121. struct andx {
  122. unsigned char command;
  123. unsigned char pad;
  124. unsigned short offset;
  125. } PACK;
  126. struct smb_setup {
  127. unsigned char word_count;
  128. struct andx andx;
  129. unsigned short max_buffer_size;
  130. unsigned short max_mpx_count;
  131. unsigned short vc_number;
  132. unsigned int session_key;
  133. unsigned short lengths[2];
  134. unsigned int pad;
  135. unsigned int capabilities;
  136. unsigned short byte_count;
  137. char bytes[1024];
  138. } PACK;
  139. struct smb_tree_connect {
  140. unsigned char word_count;
  141. struct andx andx;
  142. unsigned short flags;
  143. unsigned short pw_len;
  144. unsigned short byte_count;
  145. char bytes[1024];
  146. } PACK;
  147. struct smb_nt_create {
  148. unsigned char word_count;
  149. struct andx andx;
  150. unsigned char pad;
  151. unsigned short name_length;
  152. unsigned int flags;
  153. unsigned int root_fid;
  154. unsigned int access;
  155. curl_off_t allocation_size;
  156. unsigned int ext_file_attributes;
  157. unsigned int share_access;
  158. unsigned int create_disposition;
  159. unsigned int create_options;
  160. unsigned int impersonation_level;
  161. unsigned char security_flags;
  162. unsigned short byte_count;
  163. char bytes[1024];
  164. } PACK;
  165. struct smb_nt_create_response {
  166. struct smb_header h;
  167. unsigned char word_count;
  168. struct andx andx;
  169. unsigned char op_lock_level;
  170. unsigned short fid;
  171. unsigned int create_disposition;
  172. curl_off_t create_time;
  173. curl_off_t last_access_time;
  174. curl_off_t last_write_time;
  175. curl_off_t last_change_time;
  176. unsigned int ext_file_attributes;
  177. curl_off_t allocation_size;
  178. curl_off_t end_of_file;
  179. } PACK;
  180. struct smb_read {
  181. unsigned char word_count;
  182. struct andx andx;
  183. unsigned short fid;
  184. unsigned int offset;
  185. unsigned short max_bytes;
  186. unsigned short min_bytes;
  187. unsigned int timeout;
  188. unsigned short remaining;
  189. unsigned int offset_high;
  190. unsigned short byte_count;
  191. } PACK;
  192. struct smb_write {
  193. struct smb_header h;
  194. unsigned char word_count;
  195. struct andx andx;
  196. unsigned short fid;
  197. unsigned int offset;
  198. unsigned int timeout;
  199. unsigned short write_mode;
  200. unsigned short remaining;
  201. unsigned short pad;
  202. unsigned short data_length;
  203. unsigned short data_offset;
  204. unsigned int offset_high;
  205. unsigned short byte_count;
  206. unsigned char pad2;
  207. } PACK;
  208. struct smb_close {
  209. unsigned char word_count;
  210. unsigned short fid;
  211. unsigned int last_mtime;
  212. unsigned short byte_count;
  213. } PACK;
  214. struct smb_tree_disconnect {
  215. unsigned char word_count;
  216. unsigned short byte_count;
  217. } PACK;
  218. #if defined(_MSC_VER) || defined(__ILEC400__)
  219. # pragma pack(pop)
  220. #endif
  221. #endif /* BUILDING_CURL_SMB_C */
  222. #if !defined(CURL_DISABLE_SMB) && defined(USE_CURL_NTLM_CORE) && \
  223. (CURL_SIZEOF_CURL_OFF_T > 4)
  224. extern const struct Curl_handler Curl_handler_smb;
  225. extern const struct Curl_handler Curl_handler_smbs;
  226. #endif /* CURL_DISABLE_SMB && USE_CURL_NTLM_CORE &&
  227. CURL_SIZEOF_CURL_OFF_T > 4 */
  228. #endif /* HEADER_CURL_SMB_H */