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