[331] | 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 | *
|
---|
| 12 | * This software is licensed as described in the file COPYING, which
|
---|
| 13 | * you should have received as part of this distribution. The terms
|
---|
| 14 | * are also available at https://curl.haxx.se/docs/copyright.html.
|
---|
| 15 | *
|
---|
| 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
---|
| 17 | * copies of the Software, and permit persons to whom the Software is
|
---|
| 18 | * furnished to do so, under the terms of the COPYING file.
|
---|
| 19 | *
|
---|
| 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
---|
| 21 | * KIND, either express or implied.
|
---|
| 22 | *
|
---|
| 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 |
|
---|
| 33 | struct smb_conn {
|
---|
| 34 | enum smb_conn_state state;
|
---|
| 35 | char *user;
|
---|
| 36 | char *domain;
|
---|
| 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 | /*
|
---|
| 48 | * Definitions for SMB protocol data structures
|
---|
| 49 | */
|
---|
| 50 | #ifdef BUILDING_CURL_SMB_C
|
---|
| 51 |
|
---|
| 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 |
|
---|
| 62 | #define SMB_COM_CLOSE 0x04
|
---|
| 63 | #define SMB_COM_READ_ANDX 0x2e
|
---|
| 64 | #define SMB_COM_WRITE_ANDX 0x2f
|
---|
| 65 | #define SMB_COM_TREE_DISCONNECT 0x71
|
---|
| 66 | #define SMB_COM_NEGOTIATE 0x72
|
---|
| 67 | #define SMB_COM_SETUP_ANDX 0x73
|
---|
| 68 | #define SMB_COM_TREE_CONNECT_ANDX 0x75
|
---|
| 69 | #define SMB_COM_NT_CREATE_ANDX 0xa2
|
---|
| 70 | #define SMB_COM_NO_ANDX_COMMAND 0xff
|
---|
| 71 |
|
---|
| 72 | #define SMB_WC_CLOSE 0x03
|
---|
| 73 | #define SMB_WC_READ_ANDX 0x0c
|
---|
| 74 | #define SMB_WC_WRITE_ANDX 0x0e
|
---|
| 75 | #define SMB_WC_SETUP_ANDX 0x0d
|
---|
| 76 | #define SMB_WC_TREE_CONNECT_ANDX 0x04
|
---|
| 77 | #define SMB_WC_NT_CREATE_ANDX 0x18
|
---|
| 78 |
|
---|
| 79 | #define SMB_FLAGS_CANONICAL_PATHNAMES 0x10
|
---|
| 80 | #define SMB_FLAGS_CASELESS_PATHNAMES 0x08
|
---|
| 81 | #define SMB_FLAGS2_UNICODE_STRINGS 0x8000
|
---|
| 82 | #define SMB_FLAGS2_IS_LONG_NAME 0x0040
|
---|
| 83 | #define SMB_FLAGS2_KNOWS_LONG_NAME 0x0001
|
---|
| 84 |
|
---|
| 85 | #define SMB_CAP_LARGE_FILES 0x08
|
---|
| 86 | #define SMB_GENERIC_WRITE 0x40000000
|
---|
| 87 | #define SMB_GENERIC_READ 0x80000000
|
---|
| 88 | #define SMB_FILE_SHARE_ALL 0x07
|
---|
| 89 | #define SMB_FILE_OPEN 0x01
|
---|
| 90 | #define SMB_FILE_OVERWRITE_IF 0x05
|
---|
| 91 |
|
---|
| 92 | #define SMB_ERR_NOACCESS 0x00050001
|
---|
| 93 |
|
---|
| 94 | struct smb_header {
|
---|
| 95 | unsigned char nbt_type;
|
---|
| 96 | unsigned char nbt_flags;
|
---|
| 97 | unsigned short nbt_length;
|
---|
| 98 | unsigned char magic[4];
|
---|
| 99 | unsigned char command;
|
---|
| 100 | unsigned int status;
|
---|
| 101 | unsigned char flags;
|
---|
| 102 | unsigned short flags2;
|
---|
| 103 | unsigned short pid_high;
|
---|
| 104 | unsigned char signature[8];
|
---|
| 105 | unsigned short pad;
|
---|
| 106 | unsigned short tid;
|
---|
| 107 | unsigned short pid;
|
---|
| 108 | unsigned short uid;
|
---|
| 109 | unsigned short mid;
|
---|
| 110 | } PACK;
|
---|
| 111 |
|
---|
| 112 | struct smb_negotiate_response {
|
---|
| 113 | struct smb_header h;
|
---|
| 114 | unsigned char word_count;
|
---|
| 115 | unsigned short dialect_index;
|
---|
| 116 | unsigned char security_mode;
|
---|
| 117 | unsigned short max_mpx_count;
|
---|
| 118 | unsigned short max_number_vcs;
|
---|
| 119 | unsigned int max_buffer_size;
|
---|
| 120 | unsigned int max_raw_size;
|
---|
| 121 | unsigned int session_key;
|
---|
| 122 | unsigned int capabilities;
|
---|
| 123 | unsigned int system_time_low;
|
---|
| 124 | unsigned int system_time_high;
|
---|
| 125 | unsigned short server_time_zone;
|
---|
| 126 | unsigned char encryption_key_length;
|
---|
| 127 | unsigned short byte_count;
|
---|
| 128 | char bytes[1];
|
---|
| 129 | } PACK;
|
---|
| 130 |
|
---|
| 131 | struct andx {
|
---|
| 132 | unsigned char command;
|
---|
| 133 | unsigned char pad;
|
---|
| 134 | unsigned short offset;
|
---|
| 135 | } PACK;
|
---|
| 136 |
|
---|
| 137 | struct smb_setup {
|
---|
| 138 | unsigned char word_count;
|
---|
| 139 | struct andx andx;
|
---|
| 140 | unsigned short max_buffer_size;
|
---|
| 141 | unsigned short max_mpx_count;
|
---|
| 142 | unsigned short vc_number;
|
---|
| 143 | unsigned int session_key;
|
---|
| 144 | unsigned short lengths[2];
|
---|
| 145 | unsigned int pad;
|
---|
| 146 | unsigned int capabilities;
|
---|
| 147 | unsigned short byte_count;
|
---|
| 148 | char bytes[1024];
|
---|
| 149 | } PACK;
|
---|
| 150 |
|
---|
| 151 | struct smb_tree_connect {
|
---|
| 152 | unsigned char word_count;
|
---|
| 153 | struct andx andx;
|
---|
| 154 | unsigned short flags;
|
---|
| 155 | unsigned short pw_len;
|
---|
| 156 | unsigned short byte_count;
|
---|
| 157 | char bytes[1024];
|
---|
| 158 | } PACK;
|
---|
| 159 |
|
---|
| 160 | struct smb_nt_create {
|
---|
| 161 | unsigned char word_count;
|
---|
| 162 | struct andx andx;
|
---|
| 163 | unsigned char pad;
|
---|
| 164 | unsigned short name_length;
|
---|
| 165 | unsigned int flags;
|
---|
| 166 | unsigned int root_fid;
|
---|
| 167 | unsigned int access;
|
---|
| 168 | #ifdef HAVE_LONGLONG
|
---|
| 169 | unsigned long long allocation_size;
|
---|
| 170 | #else
|
---|
| 171 | unsigned __int64 allocation_size;
|
---|
| 172 | #endif
|
---|
| 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 |
|
---|
| 183 | struct 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 | #ifdef HAVE_LONGLONG
|
---|
| 191 | unsigned long long create_time;
|
---|
| 192 | unsigned long long last_access_time;
|
---|
| 193 | unsigned long long last_write_time;
|
---|
| 194 | unsigned long long last_change_time;
|
---|
| 195 | #else
|
---|
| 196 | unsigned __int64 create_time;
|
---|
| 197 | unsigned __int64 last_access_time;
|
---|
| 198 | unsigned __int64 last_write_time;
|
---|
| 199 | unsigned __int64 last_change_time;
|
---|
| 200 | #endif
|
---|
| 201 | unsigned int ext_file_attributes;
|
---|
| 202 | #ifdef HAVE_LONGLONG
|
---|
| 203 | unsigned long long allocation_size;
|
---|
| 204 | unsigned long long end_of_file;
|
---|
| 205 | #else
|
---|
| 206 | unsigned __int64 allocation_size;
|
---|
| 207 | unsigned __int64 end_of_file;
|
---|
| 208 | #endif
|
---|
| 209 | } PACK;
|
---|
| 210 |
|
---|
| 211 | struct smb_read {
|
---|
| 212 | unsigned char word_count;
|
---|
| 213 | struct andx andx;
|
---|
| 214 | unsigned short fid;
|
---|
| 215 | unsigned int offset;
|
---|
| 216 | unsigned short max_bytes;
|
---|
| 217 | unsigned short min_bytes;
|
---|
| 218 | unsigned int timeout;
|
---|
| 219 | unsigned short remaining;
|
---|
| 220 | unsigned int offset_high;
|
---|
| 221 | unsigned short byte_count;
|
---|
| 222 | } PACK;
|
---|
| 223 |
|
---|
| 224 | struct smb_write {
|
---|
| 225 | struct smb_header h;
|
---|
| 226 | unsigned char word_count;
|
---|
| 227 | struct andx andx;
|
---|
| 228 | unsigned short fid;
|
---|
| 229 | unsigned int offset;
|
---|
| 230 | unsigned int timeout;
|
---|
| 231 | unsigned short write_mode;
|
---|
| 232 | unsigned short remaining;
|
---|
| 233 | unsigned short pad;
|
---|
| 234 | unsigned short data_length;
|
---|
| 235 | unsigned short data_offset;
|
---|
| 236 | unsigned int offset_high;
|
---|
| 237 | unsigned short byte_count;
|
---|
| 238 | unsigned char pad2;
|
---|
| 239 | } PACK;
|
---|
| 240 |
|
---|
| 241 | struct smb_close {
|
---|
| 242 | unsigned char word_count;
|
---|
| 243 | unsigned short fid;
|
---|
| 244 | unsigned int last_mtime;
|
---|
| 245 | unsigned short byte_count;
|
---|
| 246 | } PACK;
|
---|
| 247 |
|
---|
| 248 | struct smb_tree_disconnect {
|
---|
| 249 | unsigned char word_count;
|
---|
| 250 | unsigned short byte_count;
|
---|
| 251 | } PACK;
|
---|
| 252 |
|
---|
| 253 | #if defined(_MSC_VER) || defined(__ILEC400__)
|
---|
| 254 | # pragma pack(pop)
|
---|
| 255 | #endif
|
---|
| 256 |
|
---|
| 257 | #endif /* BUILDING_CURL_SMB_C */
|
---|
| 258 |
|
---|
| 259 | #if !defined(CURL_DISABLE_SMB) && defined(USE_NTLM) && \
|
---|
| 260 | (CURL_SIZEOF_CURL_OFF_T > 4)
|
---|
| 261 |
|
---|
| 262 | #if !defined(USE_WINDOWS_SSPI) || defined(USE_WIN32_CRYPTO)
|
---|
| 263 |
|
---|
| 264 | extern const struct Curl_handler Curl_handler_smb;
|
---|
| 265 | extern const struct Curl_handler Curl_handler_smbs;
|
---|
| 266 |
|
---|
| 267 | #endif /* !USE_WINDOWS_SSPI || USE_WIN32_CRYPTO */
|
---|
| 268 |
|
---|
| 269 | #endif /* CURL_DISABLE_SMB && USE_NTLM && CURL_SIZEOF_CURL_OFF_T > 4 */
|
---|
| 270 |
|
---|
| 271 | #endif /* HEADER_CURL_SMB_H */
|
---|