smb.h 6.6 KB

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