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