jpayne@69
|
1 /* Copyright (c) 2004-2009, Sara Golemon <sarag@libssh2.org>
|
jpayne@69
|
2 * Copyright (c) 2009-2015 Daniel Stenberg
|
jpayne@69
|
3 * Copyright (c) 2010 Simon Josefsson <simon@josefsson.org>
|
jpayne@69
|
4 * All rights reserved.
|
jpayne@69
|
5 *
|
jpayne@69
|
6 * Redistribution and use in source and binary forms,
|
jpayne@69
|
7 * with or without modification, are permitted provided
|
jpayne@69
|
8 * that the following conditions are met:
|
jpayne@69
|
9 *
|
jpayne@69
|
10 * Redistributions of source code must retain the above
|
jpayne@69
|
11 * copyright notice, this list of conditions and the
|
jpayne@69
|
12 * following disclaimer.
|
jpayne@69
|
13 *
|
jpayne@69
|
14 * Redistributions in binary form must reproduce the above
|
jpayne@69
|
15 * copyright notice, this list of conditions and the following
|
jpayne@69
|
16 * disclaimer in the documentation and/or other materials
|
jpayne@69
|
17 * provided with the distribution.
|
jpayne@69
|
18 *
|
jpayne@69
|
19 * Neither the name of the copyright holder nor the names
|
jpayne@69
|
20 * of any other contributors may be used to endorse or
|
jpayne@69
|
21 * promote products derived from this software without
|
jpayne@69
|
22 * specific prior written permission.
|
jpayne@69
|
23 *
|
jpayne@69
|
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
jpayne@69
|
25 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
jpayne@69
|
26 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
jpayne@69
|
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
jpayne@69
|
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
jpayne@69
|
29 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
jpayne@69
|
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
jpayne@69
|
31 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
jpayne@69
|
32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
jpayne@69
|
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
jpayne@69
|
34 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
jpayne@69
|
35 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
jpayne@69
|
36 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
jpayne@69
|
37 * OF SUCH DAMAGE.
|
jpayne@69
|
38 */
|
jpayne@69
|
39
|
jpayne@69
|
40 #ifndef LIBSSH2_H
|
jpayne@69
|
41 #define LIBSSH2_H 1
|
jpayne@69
|
42
|
jpayne@69
|
43 #define LIBSSH2_COPYRIGHT "2004-2019 The libssh2 project and its contributors."
|
jpayne@69
|
44
|
jpayne@69
|
45 /* We use underscore instead of dash when appending DEV in dev versions just
|
jpayne@69
|
46 to make the BANNER define (used by src/session.c) be a valid SSH
|
jpayne@69
|
47 banner. Release versions have no appended strings and may of course not
|
jpayne@69
|
48 have dashes either. */
|
jpayne@69
|
49 #define LIBSSH2_VERSION "1.10.0"
|
jpayne@69
|
50
|
jpayne@69
|
51 /* The numeric version number is also available "in parts" by using these
|
jpayne@69
|
52 defines: */
|
jpayne@69
|
53 #define LIBSSH2_VERSION_MAJOR 1
|
jpayne@69
|
54 #define LIBSSH2_VERSION_MINOR 10
|
jpayne@69
|
55 #define LIBSSH2_VERSION_PATCH 0
|
jpayne@69
|
56
|
jpayne@69
|
57 /* This is the numeric version of the libssh2 version number, meant for easier
|
jpayne@69
|
58 parsing and comparions by programs. The LIBSSH2_VERSION_NUM define will
|
jpayne@69
|
59 always follow this syntax:
|
jpayne@69
|
60
|
jpayne@69
|
61 0xXXYYZZ
|
jpayne@69
|
62
|
jpayne@69
|
63 Where XX, YY and ZZ are the main version, release and patch numbers in
|
jpayne@69
|
64 hexadecimal (using 8 bits each). All three numbers are always represented
|
jpayne@69
|
65 using two digits. 1.2 would appear as "0x010200" while version 9.11.7
|
jpayne@69
|
66 appears as "0x090b07".
|
jpayne@69
|
67
|
jpayne@69
|
68 This 6-digit (24 bits) hexadecimal number does not show pre-release number,
|
jpayne@69
|
69 and it is always a greater number in a more recent release. It makes
|
jpayne@69
|
70 comparisons with greater than and less than work.
|
jpayne@69
|
71 */
|
jpayne@69
|
72 #define LIBSSH2_VERSION_NUM 0x010a00
|
jpayne@69
|
73
|
jpayne@69
|
74 /*
|
jpayne@69
|
75 * This is the date and time when the full source package was created. The
|
jpayne@69
|
76 * timestamp is not stored in the source code repo, as the timestamp is
|
jpayne@69
|
77 * properly set in the tarballs by the maketgz script.
|
jpayne@69
|
78 *
|
jpayne@69
|
79 * The format of the date should follow this template:
|
jpayne@69
|
80 *
|
jpayne@69
|
81 * "Mon Feb 12 11:35:33 UTC 2007"
|
jpayne@69
|
82 */
|
jpayne@69
|
83 #define LIBSSH2_TIMESTAMP "Sun 29 Aug 2021 08:37:50 PM UTC"
|
jpayne@69
|
84
|
jpayne@69
|
85 #ifndef RC_INVOKED
|
jpayne@69
|
86
|
jpayne@69
|
87 #ifdef __cplusplus
|
jpayne@69
|
88 extern "C" {
|
jpayne@69
|
89 #endif
|
jpayne@69
|
90 #ifdef _WIN32
|
jpayne@69
|
91 # include <basetsd.h>
|
jpayne@69
|
92 # include <winsock2.h>
|
jpayne@69
|
93 #endif
|
jpayne@69
|
94
|
jpayne@69
|
95 #include <stddef.h>
|
jpayne@69
|
96 #include <string.h>
|
jpayne@69
|
97 #include <sys/stat.h>
|
jpayne@69
|
98 #include <sys/types.h>
|
jpayne@69
|
99
|
jpayne@69
|
100 /* Allow alternate API prefix from CFLAGS or calling app */
|
jpayne@69
|
101 #ifndef LIBSSH2_API
|
jpayne@69
|
102 # ifdef LIBSSH2_WIN32
|
jpayne@69
|
103 # if defined(_WINDLL) || defined(libssh2_EXPORTS)
|
jpayne@69
|
104 # ifdef LIBSSH2_LIBRARY
|
jpayne@69
|
105 # define LIBSSH2_API __declspec(dllexport)
|
jpayne@69
|
106 # else
|
jpayne@69
|
107 # define LIBSSH2_API __declspec(dllimport)
|
jpayne@69
|
108 # endif /* LIBSSH2_LIBRARY */
|
jpayne@69
|
109 # else
|
jpayne@69
|
110 # define LIBSSH2_API
|
jpayne@69
|
111 # endif
|
jpayne@69
|
112 # else /* !LIBSSH2_WIN32 */
|
jpayne@69
|
113 # define LIBSSH2_API
|
jpayne@69
|
114 # endif /* LIBSSH2_WIN32 */
|
jpayne@69
|
115 #endif /* LIBSSH2_API */
|
jpayne@69
|
116
|
jpayne@69
|
117 #ifdef HAVE_SYS_UIO_H
|
jpayne@69
|
118 # include <sys/uio.h>
|
jpayne@69
|
119 #endif
|
jpayne@69
|
120
|
jpayne@69
|
121 #if (defined(NETWARE) && !defined(__NOVELL_LIBC__))
|
jpayne@69
|
122 # include <sys/bsdskt.h>
|
jpayne@69
|
123 typedef unsigned char uint8_t;
|
jpayne@69
|
124 typedef unsigned short int uint16_t;
|
jpayne@69
|
125 typedef unsigned int uint32_t;
|
jpayne@69
|
126 typedef int int32_t;
|
jpayne@69
|
127 typedef unsigned long long uint64_t;
|
jpayne@69
|
128 typedef long long int64_t;
|
jpayne@69
|
129 #endif
|
jpayne@69
|
130
|
jpayne@69
|
131 #ifdef _MSC_VER
|
jpayne@69
|
132 typedef unsigned char uint8_t;
|
jpayne@69
|
133 typedef unsigned short int uint16_t;
|
jpayne@69
|
134 typedef unsigned int uint32_t;
|
jpayne@69
|
135 typedef __int32 int32_t;
|
jpayne@69
|
136 typedef __int64 int64_t;
|
jpayne@69
|
137 typedef unsigned __int64 uint64_t;
|
jpayne@69
|
138 typedef unsigned __int64 libssh2_uint64_t;
|
jpayne@69
|
139 typedef __int64 libssh2_int64_t;
|
jpayne@69
|
140 #if (!defined(HAVE_SSIZE_T) && !defined(ssize_t))
|
jpayne@69
|
141 typedef SSIZE_T ssize_t;
|
jpayne@69
|
142 #define HAVE_SSIZE_T
|
jpayne@69
|
143 #endif
|
jpayne@69
|
144 #else
|
jpayne@69
|
145 #include <stdint.h>
|
jpayne@69
|
146 typedef unsigned long long libssh2_uint64_t;
|
jpayne@69
|
147 typedef long long libssh2_int64_t;
|
jpayne@69
|
148 #endif
|
jpayne@69
|
149
|
jpayne@69
|
150 #ifdef WIN32
|
jpayne@69
|
151 typedef SOCKET libssh2_socket_t;
|
jpayne@69
|
152 #define LIBSSH2_INVALID_SOCKET INVALID_SOCKET
|
jpayne@69
|
153 #else /* !WIN32 */
|
jpayne@69
|
154 typedef int libssh2_socket_t;
|
jpayne@69
|
155 #define LIBSSH2_INVALID_SOCKET -1
|
jpayne@69
|
156 #endif /* WIN32 */
|
jpayne@69
|
157
|
jpayne@69
|
158 /*
|
jpayne@69
|
159 * Determine whether there is small or large file support on windows.
|
jpayne@69
|
160 */
|
jpayne@69
|
161
|
jpayne@69
|
162 #if defined(_MSC_VER) && !defined(_WIN32_WCE)
|
jpayne@69
|
163 # if (_MSC_VER >= 900) && (_INTEGRAL_MAX_BITS >= 64)
|
jpayne@69
|
164 # define LIBSSH2_USE_WIN32_LARGE_FILES
|
jpayne@69
|
165 # else
|
jpayne@69
|
166 # define LIBSSH2_USE_WIN32_SMALL_FILES
|
jpayne@69
|
167 # endif
|
jpayne@69
|
168 #endif
|
jpayne@69
|
169
|
jpayne@69
|
170 #if defined(__MINGW32__) && !defined(LIBSSH2_USE_WIN32_LARGE_FILES)
|
jpayne@69
|
171 # define LIBSSH2_USE_WIN32_LARGE_FILES
|
jpayne@69
|
172 #endif
|
jpayne@69
|
173
|
jpayne@69
|
174 #if defined(__WATCOMC__) && !defined(LIBSSH2_USE_WIN32_LARGE_FILES)
|
jpayne@69
|
175 # define LIBSSH2_USE_WIN32_LARGE_FILES
|
jpayne@69
|
176 #endif
|
jpayne@69
|
177
|
jpayne@69
|
178 #if defined(__POCC__)
|
jpayne@69
|
179 # undef LIBSSH2_USE_WIN32_LARGE_FILES
|
jpayne@69
|
180 #endif
|
jpayne@69
|
181
|
jpayne@69
|
182 #if defined(_WIN32) && !defined(LIBSSH2_USE_WIN32_LARGE_FILES) && \
|
jpayne@69
|
183 !defined(LIBSSH2_USE_WIN32_SMALL_FILES)
|
jpayne@69
|
184 # define LIBSSH2_USE_WIN32_SMALL_FILES
|
jpayne@69
|
185 #endif
|
jpayne@69
|
186
|
jpayne@69
|
187 /*
|
jpayne@69
|
188 * Large file (>2Gb) support using WIN32 functions.
|
jpayne@69
|
189 */
|
jpayne@69
|
190
|
jpayne@69
|
191 #ifdef LIBSSH2_USE_WIN32_LARGE_FILES
|
jpayne@69
|
192 # include <io.h>
|
jpayne@69
|
193 # include <sys/types.h>
|
jpayne@69
|
194 # include <sys/stat.h>
|
jpayne@69
|
195 # define LIBSSH2_STRUCT_STAT_SIZE_FORMAT "%I64d"
|
jpayne@69
|
196 typedef struct _stati64 libssh2_struct_stat;
|
jpayne@69
|
197 typedef __int64 libssh2_struct_stat_size;
|
jpayne@69
|
198 #endif
|
jpayne@69
|
199
|
jpayne@69
|
200 /*
|
jpayne@69
|
201 * Small file (<2Gb) support using WIN32 functions.
|
jpayne@69
|
202 */
|
jpayne@69
|
203
|
jpayne@69
|
204 #ifdef LIBSSH2_USE_WIN32_SMALL_FILES
|
jpayne@69
|
205 # include <sys/types.h>
|
jpayne@69
|
206 # include <sys/stat.h>
|
jpayne@69
|
207 # ifndef _WIN32_WCE
|
jpayne@69
|
208 # define LIBSSH2_STRUCT_STAT_SIZE_FORMAT "%d"
|
jpayne@69
|
209 typedef struct _stat libssh2_struct_stat;
|
jpayne@69
|
210 typedef off_t libssh2_struct_stat_size;
|
jpayne@69
|
211 # endif
|
jpayne@69
|
212 #endif
|
jpayne@69
|
213
|
jpayne@69
|
214 #ifndef LIBSSH2_STRUCT_STAT_SIZE_FORMAT
|
jpayne@69
|
215 # ifdef __VMS
|
jpayne@69
|
216 /* We have to roll our own format here because %z is a C99-ism we don't
|
jpayne@69
|
217 have. */
|
jpayne@69
|
218 # if __USE_OFF64_T || __USING_STD_STAT
|
jpayne@69
|
219 # define LIBSSH2_STRUCT_STAT_SIZE_FORMAT "%Ld"
|
jpayne@69
|
220 # else
|
jpayne@69
|
221 # define LIBSSH2_STRUCT_STAT_SIZE_FORMAT "%d"
|
jpayne@69
|
222 # endif
|
jpayne@69
|
223 # else
|
jpayne@69
|
224 # define LIBSSH2_STRUCT_STAT_SIZE_FORMAT "%zd"
|
jpayne@69
|
225 # endif
|
jpayne@69
|
226 typedef struct stat libssh2_struct_stat;
|
jpayne@69
|
227 typedef off_t libssh2_struct_stat_size;
|
jpayne@69
|
228 #endif
|
jpayne@69
|
229
|
jpayne@69
|
230 /* Part of every banner, user specified or not */
|
jpayne@69
|
231 #define LIBSSH2_SSH_BANNER "SSH-2.0-libssh2_" LIBSSH2_VERSION
|
jpayne@69
|
232
|
jpayne@69
|
233 #define LIBSSH2_SSH_DEFAULT_BANNER LIBSSH2_SSH_BANNER
|
jpayne@69
|
234 #define LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF LIBSSH2_SSH_DEFAULT_BANNER "\r\n"
|
jpayne@69
|
235
|
jpayne@69
|
236 /* Default generate and safe prime sizes for
|
jpayne@69
|
237 diffie-hellman-group-exchange-sha1 */
|
jpayne@69
|
238 #define LIBSSH2_DH_GEX_MINGROUP 2048
|
jpayne@69
|
239 #define LIBSSH2_DH_GEX_OPTGROUP 4096
|
jpayne@69
|
240 #define LIBSSH2_DH_GEX_MAXGROUP 8192
|
jpayne@69
|
241
|
jpayne@69
|
242 #define LIBSSH2_DH_MAX_MODULUS_BITS 16384
|
jpayne@69
|
243
|
jpayne@69
|
244 /* Defaults for pty requests */
|
jpayne@69
|
245 #define LIBSSH2_TERM_WIDTH 80
|
jpayne@69
|
246 #define LIBSSH2_TERM_HEIGHT 24
|
jpayne@69
|
247 #define LIBSSH2_TERM_WIDTH_PX 0
|
jpayne@69
|
248 #define LIBSSH2_TERM_HEIGHT_PX 0
|
jpayne@69
|
249
|
jpayne@69
|
250 /* 1/4 second */
|
jpayne@69
|
251 #define LIBSSH2_SOCKET_POLL_UDELAY 250000
|
jpayne@69
|
252 /* 0.25 * 120 == 30 seconds */
|
jpayne@69
|
253 #define LIBSSH2_SOCKET_POLL_MAXLOOPS 120
|
jpayne@69
|
254
|
jpayne@69
|
255 /* Maximum size to allow a payload to compress to, plays it safe by falling
|
jpayne@69
|
256 short of spec limits */
|
jpayne@69
|
257 #define LIBSSH2_PACKET_MAXCOMP 32000
|
jpayne@69
|
258
|
jpayne@69
|
259 /* Maximum size to allow a payload to deccompress to, plays it safe by
|
jpayne@69
|
260 allowing more than spec requires */
|
jpayne@69
|
261 #define LIBSSH2_PACKET_MAXDECOMP 40000
|
jpayne@69
|
262
|
jpayne@69
|
263 /* Maximum size for an inbound compressed payload, plays it safe by
|
jpayne@69
|
264 overshooting spec limits */
|
jpayne@69
|
265 #define LIBSSH2_PACKET_MAXPAYLOAD 40000
|
jpayne@69
|
266
|
jpayne@69
|
267 /* Malloc callbacks */
|
jpayne@69
|
268 #define LIBSSH2_ALLOC_FUNC(name) void *name(size_t count, void **abstract)
|
jpayne@69
|
269 #define LIBSSH2_REALLOC_FUNC(name) void *name(void *ptr, size_t count, \
|
jpayne@69
|
270 void **abstract)
|
jpayne@69
|
271 #define LIBSSH2_FREE_FUNC(name) void name(void *ptr, void **abstract)
|
jpayne@69
|
272
|
jpayne@69
|
273 typedef struct _LIBSSH2_USERAUTH_KBDINT_PROMPT
|
jpayne@69
|
274 {
|
jpayne@69
|
275 char *text;
|
jpayne@69
|
276 unsigned int length;
|
jpayne@69
|
277 unsigned char echo;
|
jpayne@69
|
278 } LIBSSH2_USERAUTH_KBDINT_PROMPT;
|
jpayne@69
|
279
|
jpayne@69
|
280 typedef struct _LIBSSH2_USERAUTH_KBDINT_RESPONSE
|
jpayne@69
|
281 {
|
jpayne@69
|
282 char *text;
|
jpayne@69
|
283 unsigned int length;
|
jpayne@69
|
284 } LIBSSH2_USERAUTH_KBDINT_RESPONSE;
|
jpayne@69
|
285
|
jpayne@69
|
286 /* 'publickey' authentication callback */
|
jpayne@69
|
287 #define LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC(name) \
|
jpayne@69
|
288 int name(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, \
|
jpayne@69
|
289 const unsigned char *data, size_t data_len, void **abstract)
|
jpayne@69
|
290
|
jpayne@69
|
291 /* 'keyboard-interactive' authentication callback */
|
jpayne@69
|
292 #define LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC(name_) \
|
jpayne@69
|
293 void name_(const char *name, int name_len, const char *instruction, \
|
jpayne@69
|
294 int instruction_len, int num_prompts, \
|
jpayne@69
|
295 const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts, \
|
jpayne@69
|
296 LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses, void **abstract)
|
jpayne@69
|
297
|
jpayne@69
|
298 /* Callbacks for special SSH packets */
|
jpayne@69
|
299 #define LIBSSH2_IGNORE_FUNC(name) \
|
jpayne@69
|
300 void name(LIBSSH2_SESSION *session, const char *message, int message_len, \
|
jpayne@69
|
301 void **abstract)
|
jpayne@69
|
302
|
jpayne@69
|
303 #define LIBSSH2_DEBUG_FUNC(name) \
|
jpayne@69
|
304 void name(LIBSSH2_SESSION *session, int always_display, const char *message, \
|
jpayne@69
|
305 int message_len, const char *language, int language_len, \
|
jpayne@69
|
306 void **abstract)
|
jpayne@69
|
307
|
jpayne@69
|
308 #define LIBSSH2_DISCONNECT_FUNC(name) \
|
jpayne@69
|
309 void name(LIBSSH2_SESSION *session, int reason, const char *message, \
|
jpayne@69
|
310 int message_len, const char *language, int language_len, \
|
jpayne@69
|
311 void **abstract)
|
jpayne@69
|
312
|
jpayne@69
|
313 #define LIBSSH2_PASSWD_CHANGEREQ_FUNC(name) \
|
jpayne@69
|
314 void name(LIBSSH2_SESSION *session, char **newpw, int *newpw_len, \
|
jpayne@69
|
315 void **abstract)
|
jpayne@69
|
316
|
jpayne@69
|
317 #define LIBSSH2_MACERROR_FUNC(name) \
|
jpayne@69
|
318 int name(LIBSSH2_SESSION *session, const char *packet, int packet_len, \
|
jpayne@69
|
319 void **abstract)
|
jpayne@69
|
320
|
jpayne@69
|
321 #define LIBSSH2_X11_OPEN_FUNC(name) \
|
jpayne@69
|
322 void name(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, \
|
jpayne@69
|
323 const char *shost, int sport, void **abstract)
|
jpayne@69
|
324
|
jpayne@69
|
325 #define LIBSSH2_CHANNEL_CLOSE_FUNC(name) \
|
jpayne@69
|
326 void name(LIBSSH2_SESSION *session, void **session_abstract, \
|
jpayne@69
|
327 LIBSSH2_CHANNEL *channel, void **channel_abstract)
|
jpayne@69
|
328
|
jpayne@69
|
329 /* I/O callbacks */
|
jpayne@69
|
330 #define LIBSSH2_RECV_FUNC(name) \
|
jpayne@69
|
331 ssize_t name(libssh2_socket_t socket, \
|
jpayne@69
|
332 void *buffer, size_t length, \
|
jpayne@69
|
333 int flags, void **abstract)
|
jpayne@69
|
334 #define LIBSSH2_SEND_FUNC(name) \
|
jpayne@69
|
335 ssize_t name(libssh2_socket_t socket, \
|
jpayne@69
|
336 const void *buffer, size_t length, \
|
jpayne@69
|
337 int flags, void **abstract)
|
jpayne@69
|
338
|
jpayne@69
|
339 /* libssh2_session_callback_set() constants */
|
jpayne@69
|
340 #define LIBSSH2_CALLBACK_IGNORE 0
|
jpayne@69
|
341 #define LIBSSH2_CALLBACK_DEBUG 1
|
jpayne@69
|
342 #define LIBSSH2_CALLBACK_DISCONNECT 2
|
jpayne@69
|
343 #define LIBSSH2_CALLBACK_MACERROR 3
|
jpayne@69
|
344 #define LIBSSH2_CALLBACK_X11 4
|
jpayne@69
|
345 #define LIBSSH2_CALLBACK_SEND 5
|
jpayne@69
|
346 #define LIBSSH2_CALLBACK_RECV 6
|
jpayne@69
|
347
|
jpayne@69
|
348 /* libssh2_session_method_pref() constants */
|
jpayne@69
|
349 #define LIBSSH2_METHOD_KEX 0
|
jpayne@69
|
350 #define LIBSSH2_METHOD_HOSTKEY 1
|
jpayne@69
|
351 #define LIBSSH2_METHOD_CRYPT_CS 2
|
jpayne@69
|
352 #define LIBSSH2_METHOD_CRYPT_SC 3
|
jpayne@69
|
353 #define LIBSSH2_METHOD_MAC_CS 4
|
jpayne@69
|
354 #define LIBSSH2_METHOD_MAC_SC 5
|
jpayne@69
|
355 #define LIBSSH2_METHOD_COMP_CS 6
|
jpayne@69
|
356 #define LIBSSH2_METHOD_COMP_SC 7
|
jpayne@69
|
357 #define LIBSSH2_METHOD_LANG_CS 8
|
jpayne@69
|
358 #define LIBSSH2_METHOD_LANG_SC 9
|
jpayne@69
|
359
|
jpayne@69
|
360 /* flags */
|
jpayne@69
|
361 #define LIBSSH2_FLAG_SIGPIPE 1
|
jpayne@69
|
362 #define LIBSSH2_FLAG_COMPRESS 2
|
jpayne@69
|
363
|
jpayne@69
|
364 typedef struct _LIBSSH2_SESSION LIBSSH2_SESSION;
|
jpayne@69
|
365 typedef struct _LIBSSH2_CHANNEL LIBSSH2_CHANNEL;
|
jpayne@69
|
366 typedef struct _LIBSSH2_LISTENER LIBSSH2_LISTENER;
|
jpayne@69
|
367 typedef struct _LIBSSH2_KNOWNHOSTS LIBSSH2_KNOWNHOSTS;
|
jpayne@69
|
368 typedef struct _LIBSSH2_AGENT LIBSSH2_AGENT;
|
jpayne@69
|
369
|
jpayne@69
|
370 typedef struct _LIBSSH2_POLLFD {
|
jpayne@69
|
371 unsigned char type; /* LIBSSH2_POLLFD_* below */
|
jpayne@69
|
372
|
jpayne@69
|
373 union {
|
jpayne@69
|
374 libssh2_socket_t socket; /* File descriptors -- examined with
|
jpayne@69
|
375 system select() call */
|
jpayne@69
|
376 LIBSSH2_CHANNEL *channel; /* Examined by checking internal state */
|
jpayne@69
|
377 LIBSSH2_LISTENER *listener; /* Read polls only -- are inbound
|
jpayne@69
|
378 connections waiting to be accepted? */
|
jpayne@69
|
379 } fd;
|
jpayne@69
|
380
|
jpayne@69
|
381 unsigned long events; /* Requested Events */
|
jpayne@69
|
382 unsigned long revents; /* Returned Events */
|
jpayne@69
|
383 } LIBSSH2_POLLFD;
|
jpayne@69
|
384
|
jpayne@69
|
385 /* Poll FD Descriptor Types */
|
jpayne@69
|
386 #define LIBSSH2_POLLFD_SOCKET 1
|
jpayne@69
|
387 #define LIBSSH2_POLLFD_CHANNEL 2
|
jpayne@69
|
388 #define LIBSSH2_POLLFD_LISTENER 3
|
jpayne@69
|
389
|
jpayne@69
|
390 /* Note: Win32 Doesn't actually have a poll() implementation, so some of these
|
jpayne@69
|
391 values are faked with select() data */
|
jpayne@69
|
392 /* Poll FD events/revents -- Match sys/poll.h where possible */
|
jpayne@69
|
393 #define LIBSSH2_POLLFD_POLLIN 0x0001 /* Data available to be read or
|
jpayne@69
|
394 connection available --
|
jpayne@69
|
395 All */
|
jpayne@69
|
396 #define LIBSSH2_POLLFD_POLLPRI 0x0002 /* Priority data available to
|
jpayne@69
|
397 be read -- Socket only */
|
jpayne@69
|
398 #define LIBSSH2_POLLFD_POLLEXT 0x0002 /* Extended data available to
|
jpayne@69
|
399 be read -- Channel only */
|
jpayne@69
|
400 #define LIBSSH2_POLLFD_POLLOUT 0x0004 /* Can may be written --
|
jpayne@69
|
401 Socket/Channel */
|
jpayne@69
|
402 /* revents only */
|
jpayne@69
|
403 #define LIBSSH2_POLLFD_POLLERR 0x0008 /* Error Condition -- Socket */
|
jpayne@69
|
404 #define LIBSSH2_POLLFD_POLLHUP 0x0010 /* HangUp/EOF -- Socket */
|
jpayne@69
|
405 #define LIBSSH2_POLLFD_SESSION_CLOSED 0x0010 /* Session Disconnect */
|
jpayne@69
|
406 #define LIBSSH2_POLLFD_POLLNVAL 0x0020 /* Invalid request -- Socket
|
jpayne@69
|
407 Only */
|
jpayne@69
|
408 #define LIBSSH2_POLLFD_POLLEX 0x0040 /* Exception Condition --
|
jpayne@69
|
409 Socket/Win32 */
|
jpayne@69
|
410 #define LIBSSH2_POLLFD_CHANNEL_CLOSED 0x0080 /* Channel Disconnect */
|
jpayne@69
|
411 #define LIBSSH2_POLLFD_LISTENER_CLOSED 0x0080 /* Listener Disconnect */
|
jpayne@69
|
412
|
jpayne@69
|
413 #define HAVE_LIBSSH2_SESSION_BLOCK_DIRECTION
|
jpayne@69
|
414 /* Block Direction Types */
|
jpayne@69
|
415 #define LIBSSH2_SESSION_BLOCK_INBOUND 0x0001
|
jpayne@69
|
416 #define LIBSSH2_SESSION_BLOCK_OUTBOUND 0x0002
|
jpayne@69
|
417
|
jpayne@69
|
418 /* Hash Types */
|
jpayne@69
|
419 #define LIBSSH2_HOSTKEY_HASH_MD5 1
|
jpayne@69
|
420 #define LIBSSH2_HOSTKEY_HASH_SHA1 2
|
jpayne@69
|
421 #define LIBSSH2_HOSTKEY_HASH_SHA256 3
|
jpayne@69
|
422
|
jpayne@69
|
423 /* Hostkey Types */
|
jpayne@69
|
424 #define LIBSSH2_HOSTKEY_TYPE_UNKNOWN 0
|
jpayne@69
|
425 #define LIBSSH2_HOSTKEY_TYPE_RSA 1
|
jpayne@69
|
426 #define LIBSSH2_HOSTKEY_TYPE_DSS 2
|
jpayne@69
|
427 #define LIBSSH2_HOSTKEY_TYPE_ECDSA_256 3
|
jpayne@69
|
428 #define LIBSSH2_HOSTKEY_TYPE_ECDSA_384 4
|
jpayne@69
|
429 #define LIBSSH2_HOSTKEY_TYPE_ECDSA_521 5
|
jpayne@69
|
430 #define LIBSSH2_HOSTKEY_TYPE_ED25519 6
|
jpayne@69
|
431
|
jpayne@69
|
432 /* Disconnect Codes (defined by SSH protocol) */
|
jpayne@69
|
433 #define SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT 1
|
jpayne@69
|
434 #define SSH_DISCONNECT_PROTOCOL_ERROR 2
|
jpayne@69
|
435 #define SSH_DISCONNECT_KEY_EXCHANGE_FAILED 3
|
jpayne@69
|
436 #define SSH_DISCONNECT_RESERVED 4
|
jpayne@69
|
437 #define SSH_DISCONNECT_MAC_ERROR 5
|
jpayne@69
|
438 #define SSH_DISCONNECT_COMPRESSION_ERROR 6
|
jpayne@69
|
439 #define SSH_DISCONNECT_SERVICE_NOT_AVAILABLE 7
|
jpayne@69
|
440 #define SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED 8
|
jpayne@69
|
441 #define SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE 9
|
jpayne@69
|
442 #define SSH_DISCONNECT_CONNECTION_LOST 10
|
jpayne@69
|
443 #define SSH_DISCONNECT_BY_APPLICATION 11
|
jpayne@69
|
444 #define SSH_DISCONNECT_TOO_MANY_CONNECTIONS 12
|
jpayne@69
|
445 #define SSH_DISCONNECT_AUTH_CANCELLED_BY_USER 13
|
jpayne@69
|
446 #define SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE 14
|
jpayne@69
|
447 #define SSH_DISCONNECT_ILLEGAL_USER_NAME 15
|
jpayne@69
|
448
|
jpayne@69
|
449 /* Error Codes (defined by libssh2) */
|
jpayne@69
|
450 #define LIBSSH2_ERROR_NONE 0
|
jpayne@69
|
451
|
jpayne@69
|
452 /* The library once used -1 as a generic error return value on numerous places
|
jpayne@69
|
453 through the code, which subsequently was converted to
|
jpayne@69
|
454 LIBSSH2_ERROR_SOCKET_NONE uses over time. As this is a generic error code,
|
jpayne@69
|
455 the goal is to never ever return this code but instead make sure that a
|
jpayne@69
|
456 more accurate and descriptive error code is used. */
|
jpayne@69
|
457 #define LIBSSH2_ERROR_SOCKET_NONE -1
|
jpayne@69
|
458
|
jpayne@69
|
459 #define LIBSSH2_ERROR_BANNER_RECV -2
|
jpayne@69
|
460 #define LIBSSH2_ERROR_BANNER_SEND -3
|
jpayne@69
|
461 #define LIBSSH2_ERROR_INVALID_MAC -4
|
jpayne@69
|
462 #define LIBSSH2_ERROR_KEX_FAILURE -5
|
jpayne@69
|
463 #define LIBSSH2_ERROR_ALLOC -6
|
jpayne@69
|
464 #define LIBSSH2_ERROR_SOCKET_SEND -7
|
jpayne@69
|
465 #define LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE -8
|
jpayne@69
|
466 #define LIBSSH2_ERROR_TIMEOUT -9
|
jpayne@69
|
467 #define LIBSSH2_ERROR_HOSTKEY_INIT -10
|
jpayne@69
|
468 #define LIBSSH2_ERROR_HOSTKEY_SIGN -11
|
jpayne@69
|
469 #define LIBSSH2_ERROR_DECRYPT -12
|
jpayne@69
|
470 #define LIBSSH2_ERROR_SOCKET_DISCONNECT -13
|
jpayne@69
|
471 #define LIBSSH2_ERROR_PROTO -14
|
jpayne@69
|
472 #define LIBSSH2_ERROR_PASSWORD_EXPIRED -15
|
jpayne@69
|
473 #define LIBSSH2_ERROR_FILE -16
|
jpayne@69
|
474 #define LIBSSH2_ERROR_METHOD_NONE -17
|
jpayne@69
|
475 #define LIBSSH2_ERROR_AUTHENTICATION_FAILED -18
|
jpayne@69
|
476 #define LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED \
|
jpayne@69
|
477 LIBSSH2_ERROR_AUTHENTICATION_FAILED
|
jpayne@69
|
478 #define LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED -19
|
jpayne@69
|
479 #define LIBSSH2_ERROR_CHANNEL_OUTOFORDER -20
|
jpayne@69
|
480 #define LIBSSH2_ERROR_CHANNEL_FAILURE -21
|
jpayne@69
|
481 #define LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED -22
|
jpayne@69
|
482 #define LIBSSH2_ERROR_CHANNEL_UNKNOWN -23
|
jpayne@69
|
483 #define LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED -24
|
jpayne@69
|
484 #define LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED -25
|
jpayne@69
|
485 #define LIBSSH2_ERROR_CHANNEL_CLOSED -26
|
jpayne@69
|
486 #define LIBSSH2_ERROR_CHANNEL_EOF_SENT -27
|
jpayne@69
|
487 #define LIBSSH2_ERROR_SCP_PROTOCOL -28
|
jpayne@69
|
488 #define LIBSSH2_ERROR_ZLIB -29
|
jpayne@69
|
489 #define LIBSSH2_ERROR_SOCKET_TIMEOUT -30
|
jpayne@69
|
490 #define LIBSSH2_ERROR_SFTP_PROTOCOL -31
|
jpayne@69
|
491 #define LIBSSH2_ERROR_REQUEST_DENIED -32
|
jpayne@69
|
492 #define LIBSSH2_ERROR_METHOD_NOT_SUPPORTED -33
|
jpayne@69
|
493 #define LIBSSH2_ERROR_INVAL -34
|
jpayne@69
|
494 #define LIBSSH2_ERROR_INVALID_POLL_TYPE -35
|
jpayne@69
|
495 #define LIBSSH2_ERROR_PUBLICKEY_PROTOCOL -36
|
jpayne@69
|
496 #define LIBSSH2_ERROR_EAGAIN -37
|
jpayne@69
|
497 #define LIBSSH2_ERROR_BUFFER_TOO_SMALL -38
|
jpayne@69
|
498 #define LIBSSH2_ERROR_BAD_USE -39
|
jpayne@69
|
499 #define LIBSSH2_ERROR_COMPRESS -40
|
jpayne@69
|
500 #define LIBSSH2_ERROR_OUT_OF_BOUNDARY -41
|
jpayne@69
|
501 #define LIBSSH2_ERROR_AGENT_PROTOCOL -42
|
jpayne@69
|
502 #define LIBSSH2_ERROR_SOCKET_RECV -43
|
jpayne@69
|
503 #define LIBSSH2_ERROR_ENCRYPT -44
|
jpayne@69
|
504 #define LIBSSH2_ERROR_BAD_SOCKET -45
|
jpayne@69
|
505 #define LIBSSH2_ERROR_KNOWN_HOSTS -46
|
jpayne@69
|
506 #define LIBSSH2_ERROR_CHANNEL_WINDOW_FULL -47
|
jpayne@69
|
507 #define LIBSSH2_ERROR_KEYFILE_AUTH_FAILED -48
|
jpayne@69
|
508 #define LIBSSH2_ERROR_RANDGEN -49
|
jpayne@69
|
509
|
jpayne@69
|
510 /* this is a define to provide the old (<= 1.2.7) name */
|
jpayne@69
|
511 #define LIBSSH2_ERROR_BANNER_NONE LIBSSH2_ERROR_BANNER_RECV
|
jpayne@69
|
512
|
jpayne@69
|
513 /* Global API */
|
jpayne@69
|
514 #define LIBSSH2_INIT_NO_CRYPTO 0x0001
|
jpayne@69
|
515
|
jpayne@69
|
516 /*
|
jpayne@69
|
517 * libssh2_init()
|
jpayne@69
|
518 *
|
jpayne@69
|
519 * Initialize the libssh2 functions. This typically initialize the
|
jpayne@69
|
520 * crypto library. It uses a global state, and is not thread safe --
|
jpayne@69
|
521 * you must make sure this function is not called concurrently.
|
jpayne@69
|
522 *
|
jpayne@69
|
523 * Flags can be:
|
jpayne@69
|
524 * 0: Normal initialize
|
jpayne@69
|
525 * LIBSSH2_INIT_NO_CRYPTO: Do not initialize the crypto library (ie.
|
jpayne@69
|
526 * OPENSSL_add_cipher_algoritms() for OpenSSL
|
jpayne@69
|
527 *
|
jpayne@69
|
528 * Returns 0 if succeeded, or a negative value for error.
|
jpayne@69
|
529 */
|
jpayne@69
|
530 LIBSSH2_API int libssh2_init(int flags);
|
jpayne@69
|
531
|
jpayne@69
|
532 /*
|
jpayne@69
|
533 * libssh2_exit()
|
jpayne@69
|
534 *
|
jpayne@69
|
535 * Exit the libssh2 functions and free's all memory used internal.
|
jpayne@69
|
536 */
|
jpayne@69
|
537 LIBSSH2_API void libssh2_exit(void);
|
jpayne@69
|
538
|
jpayne@69
|
539 /*
|
jpayne@69
|
540 * libssh2_free()
|
jpayne@69
|
541 *
|
jpayne@69
|
542 * Deallocate memory allocated by earlier call to libssh2 functions.
|
jpayne@69
|
543 */
|
jpayne@69
|
544 LIBSSH2_API void libssh2_free(LIBSSH2_SESSION *session, void *ptr);
|
jpayne@69
|
545
|
jpayne@69
|
546 /*
|
jpayne@69
|
547 * libssh2_session_supported_algs()
|
jpayne@69
|
548 *
|
jpayne@69
|
549 * Fills algs with a list of supported acryptographic algorithms. Returns a
|
jpayne@69
|
550 * non-negative number (number of supported algorithms) on success or a
|
jpayne@69
|
551 * negative number (an error code) on failure.
|
jpayne@69
|
552 *
|
jpayne@69
|
553 * NOTE: on success, algs must be deallocated (by calling libssh2_free) when
|
jpayne@69
|
554 * not needed anymore
|
jpayne@69
|
555 */
|
jpayne@69
|
556 LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session,
|
jpayne@69
|
557 int method_type,
|
jpayne@69
|
558 const char ***algs);
|
jpayne@69
|
559
|
jpayne@69
|
560 /* Session API */
|
jpayne@69
|
561 LIBSSH2_API LIBSSH2_SESSION *
|
jpayne@69
|
562 libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)),
|
jpayne@69
|
563 LIBSSH2_FREE_FUNC((*my_free)),
|
jpayne@69
|
564 LIBSSH2_REALLOC_FUNC((*my_realloc)), void *abstract);
|
jpayne@69
|
565 #define libssh2_session_init() libssh2_session_init_ex(NULL, NULL, NULL, NULL)
|
jpayne@69
|
566
|
jpayne@69
|
567 LIBSSH2_API void **libssh2_session_abstract(LIBSSH2_SESSION *session);
|
jpayne@69
|
568
|
jpayne@69
|
569 LIBSSH2_API void *libssh2_session_callback_set(LIBSSH2_SESSION *session,
|
jpayne@69
|
570 int cbtype, void *callback);
|
jpayne@69
|
571 LIBSSH2_API int libssh2_session_banner_set(LIBSSH2_SESSION *session,
|
jpayne@69
|
572 const char *banner);
|
jpayne@69
|
573 LIBSSH2_API int libssh2_banner_set(LIBSSH2_SESSION *session,
|
jpayne@69
|
574 const char *banner);
|
jpayne@69
|
575
|
jpayne@69
|
576 LIBSSH2_API int libssh2_session_startup(LIBSSH2_SESSION *session, int sock);
|
jpayne@69
|
577 LIBSSH2_API int libssh2_session_handshake(LIBSSH2_SESSION *session,
|
jpayne@69
|
578 libssh2_socket_t sock);
|
jpayne@69
|
579 LIBSSH2_API int libssh2_session_disconnect_ex(LIBSSH2_SESSION *session,
|
jpayne@69
|
580 int reason,
|
jpayne@69
|
581 const char *description,
|
jpayne@69
|
582 const char *lang);
|
jpayne@69
|
583 #define libssh2_session_disconnect(session, description) \
|
jpayne@69
|
584 libssh2_session_disconnect_ex((session), SSH_DISCONNECT_BY_APPLICATION, \
|
jpayne@69
|
585 (description), "")
|
jpayne@69
|
586
|
jpayne@69
|
587 LIBSSH2_API int libssh2_session_free(LIBSSH2_SESSION *session);
|
jpayne@69
|
588
|
jpayne@69
|
589 LIBSSH2_API const char *libssh2_hostkey_hash(LIBSSH2_SESSION *session,
|
jpayne@69
|
590 int hash_type);
|
jpayne@69
|
591
|
jpayne@69
|
592 LIBSSH2_API const char *libssh2_session_hostkey(LIBSSH2_SESSION *session,
|
jpayne@69
|
593 size_t *len, int *type);
|
jpayne@69
|
594
|
jpayne@69
|
595 LIBSSH2_API int libssh2_session_method_pref(LIBSSH2_SESSION *session,
|
jpayne@69
|
596 int method_type,
|
jpayne@69
|
597 const char *prefs);
|
jpayne@69
|
598 LIBSSH2_API const char *libssh2_session_methods(LIBSSH2_SESSION *session,
|
jpayne@69
|
599 int method_type);
|
jpayne@69
|
600 LIBSSH2_API int libssh2_session_last_error(LIBSSH2_SESSION *session,
|
jpayne@69
|
601 char **errmsg,
|
jpayne@69
|
602 int *errmsg_len, int want_buf);
|
jpayne@69
|
603 LIBSSH2_API int libssh2_session_last_errno(LIBSSH2_SESSION *session);
|
jpayne@69
|
604 LIBSSH2_API int libssh2_session_set_last_error(LIBSSH2_SESSION* session,
|
jpayne@69
|
605 int errcode,
|
jpayne@69
|
606 const char *errmsg);
|
jpayne@69
|
607 LIBSSH2_API int libssh2_session_block_directions(LIBSSH2_SESSION *session);
|
jpayne@69
|
608
|
jpayne@69
|
609 LIBSSH2_API int libssh2_session_flag(LIBSSH2_SESSION *session, int flag,
|
jpayne@69
|
610 int value);
|
jpayne@69
|
611 LIBSSH2_API const char *libssh2_session_banner_get(LIBSSH2_SESSION *session);
|
jpayne@69
|
612
|
jpayne@69
|
613 /* Userauth API */
|
jpayne@69
|
614 LIBSSH2_API char *libssh2_userauth_list(LIBSSH2_SESSION *session,
|
jpayne@69
|
615 const char *username,
|
jpayne@69
|
616 unsigned int username_len);
|
jpayne@69
|
617 LIBSSH2_API int libssh2_userauth_authenticated(LIBSSH2_SESSION *session);
|
jpayne@69
|
618
|
jpayne@69
|
619 LIBSSH2_API int
|
jpayne@69
|
620 libssh2_userauth_password_ex(LIBSSH2_SESSION *session,
|
jpayne@69
|
621 const char *username,
|
jpayne@69
|
622 unsigned int username_len,
|
jpayne@69
|
623 const char *password,
|
jpayne@69
|
624 unsigned int password_len,
|
jpayne@69
|
625 LIBSSH2_PASSWD_CHANGEREQ_FUNC
|
jpayne@69
|
626 ((*passwd_change_cb)));
|
jpayne@69
|
627
|
jpayne@69
|
628 #define libssh2_userauth_password(session, username, password) \
|
jpayne@69
|
629 libssh2_userauth_password_ex((session), (username), \
|
jpayne@69
|
630 (unsigned int)strlen(username), \
|
jpayne@69
|
631 (password), (unsigned int)strlen(password), NULL)
|
jpayne@69
|
632
|
jpayne@69
|
633 LIBSSH2_API int
|
jpayne@69
|
634 libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION *session,
|
jpayne@69
|
635 const char *username,
|
jpayne@69
|
636 unsigned int username_len,
|
jpayne@69
|
637 const char *publickey,
|
jpayne@69
|
638 const char *privatekey,
|
jpayne@69
|
639 const char *passphrase);
|
jpayne@69
|
640
|
jpayne@69
|
641 #define libssh2_userauth_publickey_fromfile(session, username, publickey, \
|
jpayne@69
|
642 privatekey, passphrase) \
|
jpayne@69
|
643 libssh2_userauth_publickey_fromfile_ex((session), (username), \
|
jpayne@69
|
644 (unsigned int)strlen(username), \
|
jpayne@69
|
645 (publickey), \
|
jpayne@69
|
646 (privatekey), (passphrase))
|
jpayne@69
|
647
|
jpayne@69
|
648 LIBSSH2_API int
|
jpayne@69
|
649 libssh2_userauth_publickey(LIBSSH2_SESSION *session,
|
jpayne@69
|
650 const char *username,
|
jpayne@69
|
651 const unsigned char *pubkeydata,
|
jpayne@69
|
652 size_t pubkeydata_len,
|
jpayne@69
|
653 LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC
|
jpayne@69
|
654 ((*sign_callback)),
|
jpayne@69
|
655 void **abstract);
|
jpayne@69
|
656
|
jpayne@69
|
657 LIBSSH2_API int
|
jpayne@69
|
658 libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION *session,
|
jpayne@69
|
659 const char *username,
|
jpayne@69
|
660 unsigned int username_len,
|
jpayne@69
|
661 const char *publickey,
|
jpayne@69
|
662 const char *privatekey,
|
jpayne@69
|
663 const char *passphrase,
|
jpayne@69
|
664 const char *hostname,
|
jpayne@69
|
665 unsigned int hostname_len,
|
jpayne@69
|
666 const char *local_username,
|
jpayne@69
|
667 unsigned int local_username_len);
|
jpayne@69
|
668
|
jpayne@69
|
669 #define libssh2_userauth_hostbased_fromfile(session, username, publickey, \
|
jpayne@69
|
670 privatekey, passphrase, hostname) \
|
jpayne@69
|
671 libssh2_userauth_hostbased_fromfile_ex((session), (username), \
|
jpayne@69
|
672 (unsigned int)strlen(username), \
|
jpayne@69
|
673 (publickey), \
|
jpayne@69
|
674 (privatekey), (passphrase), \
|
jpayne@69
|
675 (hostname), \
|
jpayne@69
|
676 (unsigned int)strlen(hostname), \
|
jpayne@69
|
677 (username), \
|
jpayne@69
|
678 (unsigned int)strlen(username))
|
jpayne@69
|
679
|
jpayne@69
|
680 LIBSSH2_API int
|
jpayne@69
|
681 libssh2_userauth_publickey_frommemory(LIBSSH2_SESSION *session,
|
jpayne@69
|
682 const char *username,
|
jpayne@69
|
683 size_t username_len,
|
jpayne@69
|
684 const char *publickeyfiledata,
|
jpayne@69
|
685 size_t publickeyfiledata_len,
|
jpayne@69
|
686 const char *privatekeyfiledata,
|
jpayne@69
|
687 size_t privatekeyfiledata_len,
|
jpayne@69
|
688 const char *passphrase);
|
jpayne@69
|
689
|
jpayne@69
|
690 /*
|
jpayne@69
|
691 * response_callback is provided with filled by library prompts array,
|
jpayne@69
|
692 * but client must allocate and fill individual responses. Responses
|
jpayne@69
|
693 * array is already allocated. Responses data will be freed by libssh2
|
jpayne@69
|
694 * after callback return, but before subsequent callback invocation.
|
jpayne@69
|
695 */
|
jpayne@69
|
696 LIBSSH2_API int
|
jpayne@69
|
697 libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION* session,
|
jpayne@69
|
698 const char *username,
|
jpayne@69
|
699 unsigned int username_len,
|
jpayne@69
|
700 LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC(
|
jpayne@69
|
701 (*response_callback)));
|
jpayne@69
|
702
|
jpayne@69
|
703 #define libssh2_userauth_keyboard_interactive(session, username, \
|
jpayne@69
|
704 response_callback) \
|
jpayne@69
|
705 libssh2_userauth_keyboard_interactive_ex((session), (username), \
|
jpayne@69
|
706 (unsigned int)strlen(username), \
|
jpayne@69
|
707 (response_callback))
|
jpayne@69
|
708
|
jpayne@69
|
709 LIBSSH2_API int libssh2_poll(LIBSSH2_POLLFD *fds, unsigned int nfds,
|
jpayne@69
|
710 long timeout);
|
jpayne@69
|
711
|
jpayne@69
|
712 /* Channel API */
|
jpayne@69
|
713 #define LIBSSH2_CHANNEL_WINDOW_DEFAULT (2*1024*1024)
|
jpayne@69
|
714 #define LIBSSH2_CHANNEL_PACKET_DEFAULT 32768
|
jpayne@69
|
715 #define LIBSSH2_CHANNEL_MINADJUST 1024
|
jpayne@69
|
716
|
jpayne@69
|
717 /* Extended Data Handling */
|
jpayne@69
|
718 #define LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL 0
|
jpayne@69
|
719 #define LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE 1
|
jpayne@69
|
720 #define LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE 2
|
jpayne@69
|
721
|
jpayne@69
|
722 #define SSH_EXTENDED_DATA_STDERR 1
|
jpayne@69
|
723
|
jpayne@69
|
724 /* Returned by any function that would block during a read/write operation */
|
jpayne@69
|
725 #define LIBSSH2CHANNEL_EAGAIN LIBSSH2_ERROR_EAGAIN
|
jpayne@69
|
726
|
jpayne@69
|
727 LIBSSH2_API LIBSSH2_CHANNEL *
|
jpayne@69
|
728 libssh2_channel_open_ex(LIBSSH2_SESSION *session, const char *channel_type,
|
jpayne@69
|
729 unsigned int channel_type_len,
|
jpayne@69
|
730 unsigned int window_size, unsigned int packet_size,
|
jpayne@69
|
731 const char *message, unsigned int message_len);
|
jpayne@69
|
732
|
jpayne@69
|
733 #define libssh2_channel_open_session(session) \
|
jpayne@69
|
734 libssh2_channel_open_ex((session), "session", sizeof("session") - 1, \
|
jpayne@69
|
735 LIBSSH2_CHANNEL_WINDOW_DEFAULT, \
|
jpayne@69
|
736 LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0)
|
jpayne@69
|
737
|
jpayne@69
|
738 LIBSSH2_API LIBSSH2_CHANNEL *
|
jpayne@69
|
739 libssh2_channel_direct_tcpip_ex(LIBSSH2_SESSION *session, const char *host,
|
jpayne@69
|
740 int port, const char *shost, int sport);
|
jpayne@69
|
741 #define libssh2_channel_direct_tcpip(session, host, port) \
|
jpayne@69
|
742 libssh2_channel_direct_tcpip_ex((session), (host), (port), "127.0.0.1", 22)
|
jpayne@69
|
743
|
jpayne@69
|
744 LIBSSH2_API LIBSSH2_LISTENER *
|
jpayne@69
|
745 libssh2_channel_forward_listen_ex(LIBSSH2_SESSION *session, const char *host,
|
jpayne@69
|
746 int port, int *bound_port,
|
jpayne@69
|
747 int queue_maxsize);
|
jpayne@69
|
748 #define libssh2_channel_forward_listen(session, port) \
|
jpayne@69
|
749 libssh2_channel_forward_listen_ex((session), NULL, (port), NULL, 16)
|
jpayne@69
|
750
|
jpayne@69
|
751 LIBSSH2_API int libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener);
|
jpayne@69
|
752
|
jpayne@69
|
753 LIBSSH2_API LIBSSH2_CHANNEL *
|
jpayne@69
|
754 libssh2_channel_forward_accept(LIBSSH2_LISTENER *listener);
|
jpayne@69
|
755
|
jpayne@69
|
756 LIBSSH2_API int libssh2_channel_setenv_ex(LIBSSH2_CHANNEL *channel,
|
jpayne@69
|
757 const char *varname,
|
jpayne@69
|
758 unsigned int varname_len,
|
jpayne@69
|
759 const char *value,
|
jpayne@69
|
760 unsigned int value_len);
|
jpayne@69
|
761
|
jpayne@69
|
762 #define libssh2_channel_setenv(channel, varname, value) \
|
jpayne@69
|
763 libssh2_channel_setenv_ex((channel), (varname), \
|
jpayne@69
|
764 (unsigned int)strlen(varname), (value), \
|
jpayne@69
|
765 (unsigned int)strlen(value))
|
jpayne@69
|
766
|
jpayne@69
|
767 LIBSSH2_API int libssh2_channel_request_auth_agent(LIBSSH2_CHANNEL *channel);
|
jpayne@69
|
768
|
jpayne@69
|
769 LIBSSH2_API int libssh2_channel_request_pty_ex(LIBSSH2_CHANNEL *channel,
|
jpayne@69
|
770 const char *term,
|
jpayne@69
|
771 unsigned int term_len,
|
jpayne@69
|
772 const char *modes,
|
jpayne@69
|
773 unsigned int modes_len,
|
jpayne@69
|
774 int width, int height,
|
jpayne@69
|
775 int width_px, int height_px);
|
jpayne@69
|
776 #define libssh2_channel_request_pty(channel, term) \
|
jpayne@69
|
777 libssh2_channel_request_pty_ex((channel), (term), \
|
jpayne@69
|
778 (unsigned int)strlen(term), \
|
jpayne@69
|
779 NULL, 0, \
|
jpayne@69
|
780 LIBSSH2_TERM_WIDTH, \
|
jpayne@69
|
781 LIBSSH2_TERM_HEIGHT, \
|
jpayne@69
|
782 LIBSSH2_TERM_WIDTH_PX, \
|
jpayne@69
|
783 LIBSSH2_TERM_HEIGHT_PX)
|
jpayne@69
|
784
|
jpayne@69
|
785 LIBSSH2_API int libssh2_channel_request_pty_size_ex(LIBSSH2_CHANNEL *channel,
|
jpayne@69
|
786 int width, int height,
|
jpayne@69
|
787 int width_px,
|
jpayne@69
|
788 int height_px);
|
jpayne@69
|
789 #define libssh2_channel_request_pty_size(channel, width, height) \
|
jpayne@69
|
790 libssh2_channel_request_pty_size_ex((channel), (width), (height), 0, 0)
|
jpayne@69
|
791
|
jpayne@69
|
792 LIBSSH2_API int libssh2_channel_x11_req_ex(LIBSSH2_CHANNEL *channel,
|
jpayne@69
|
793 int single_connection,
|
jpayne@69
|
794 const char *auth_proto,
|
jpayne@69
|
795 const char *auth_cookie,
|
jpayne@69
|
796 int screen_number);
|
jpayne@69
|
797 #define libssh2_channel_x11_req(channel, screen_number) \
|
jpayne@69
|
798 libssh2_channel_x11_req_ex((channel), 0, NULL, NULL, (screen_number))
|
jpayne@69
|
799
|
jpayne@69
|
800 LIBSSH2_API int libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
|
jpayne@69
|
801 const char *request,
|
jpayne@69
|
802 unsigned int request_len,
|
jpayne@69
|
803 const char *message,
|
jpayne@69
|
804 unsigned int message_len);
|
jpayne@69
|
805 #define libssh2_channel_shell(channel) \
|
jpayne@69
|
806 libssh2_channel_process_startup((channel), "shell", sizeof("shell") - 1, \
|
jpayne@69
|
807 NULL, 0)
|
jpayne@69
|
808 #define libssh2_channel_exec(channel, command) \
|
jpayne@69
|
809 libssh2_channel_process_startup((channel), "exec", sizeof("exec") - 1, \
|
jpayne@69
|
810 (command), (unsigned int)strlen(command))
|
jpayne@69
|
811 #define libssh2_channel_subsystem(channel, subsystem) \
|
jpayne@69
|
812 libssh2_channel_process_startup((channel), "subsystem", \
|
jpayne@69
|
813 sizeof("subsystem") - 1, (subsystem), \
|
jpayne@69
|
814 (unsigned int)strlen(subsystem))
|
jpayne@69
|
815
|
jpayne@69
|
816 LIBSSH2_API ssize_t libssh2_channel_read_ex(LIBSSH2_CHANNEL *channel,
|
jpayne@69
|
817 int stream_id, char *buf,
|
jpayne@69
|
818 size_t buflen);
|
jpayne@69
|
819 #define libssh2_channel_read(channel, buf, buflen) \
|
jpayne@69
|
820 libssh2_channel_read_ex((channel), 0, (buf), (buflen))
|
jpayne@69
|
821 #define libssh2_channel_read_stderr(channel, buf, buflen) \
|
jpayne@69
|
822 libssh2_channel_read_ex((channel), SSH_EXTENDED_DATA_STDERR, (buf), (buflen))
|
jpayne@69
|
823
|
jpayne@69
|
824 LIBSSH2_API int libssh2_poll_channel_read(LIBSSH2_CHANNEL *channel,
|
jpayne@69
|
825 int extended);
|
jpayne@69
|
826
|
jpayne@69
|
827 LIBSSH2_API unsigned long
|
jpayne@69
|
828 libssh2_channel_window_read_ex(LIBSSH2_CHANNEL *channel,
|
jpayne@69
|
829 unsigned long *read_avail,
|
jpayne@69
|
830 unsigned long *window_size_initial);
|
jpayne@69
|
831 #define libssh2_channel_window_read(channel) \
|
jpayne@69
|
832 libssh2_channel_window_read_ex((channel), NULL, NULL)
|
jpayne@69
|
833
|
jpayne@69
|
834 /* libssh2_channel_receive_window_adjust is DEPRECATED, do not use! */
|
jpayne@69
|
835 LIBSSH2_API unsigned long
|
jpayne@69
|
836 libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL *channel,
|
jpayne@69
|
837 unsigned long adjustment,
|
jpayne@69
|
838 unsigned char force);
|
jpayne@69
|
839
|
jpayne@69
|
840 LIBSSH2_API int
|
jpayne@69
|
841 libssh2_channel_receive_window_adjust2(LIBSSH2_CHANNEL *channel,
|
jpayne@69
|
842 unsigned long adjustment,
|
jpayne@69
|
843 unsigned char force,
|
jpayne@69
|
844 unsigned int *storewindow);
|
jpayne@69
|
845
|
jpayne@69
|
846 LIBSSH2_API ssize_t libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel,
|
jpayne@69
|
847 int stream_id, const char *buf,
|
jpayne@69
|
848 size_t buflen);
|
jpayne@69
|
849
|
jpayne@69
|
850 #define libssh2_channel_write(channel, buf, buflen) \
|
jpayne@69
|
851 libssh2_channel_write_ex((channel), 0, (buf), (buflen))
|
jpayne@69
|
852 #define libssh2_channel_write_stderr(channel, buf, buflen) \
|
jpayne@69
|
853 libssh2_channel_write_ex((channel), SSH_EXTENDED_DATA_STDERR, \
|
jpayne@69
|
854 (buf), (buflen))
|
jpayne@69
|
855
|
jpayne@69
|
856 LIBSSH2_API unsigned long
|
jpayne@69
|
857 libssh2_channel_window_write_ex(LIBSSH2_CHANNEL *channel,
|
jpayne@69
|
858 unsigned long *window_size_initial);
|
jpayne@69
|
859 #define libssh2_channel_window_write(channel) \
|
jpayne@69
|
860 libssh2_channel_window_write_ex((channel), NULL)
|
jpayne@69
|
861
|
jpayne@69
|
862 LIBSSH2_API void libssh2_session_set_blocking(LIBSSH2_SESSION* session,
|
jpayne@69
|
863 int blocking);
|
jpayne@69
|
864 LIBSSH2_API int libssh2_session_get_blocking(LIBSSH2_SESSION* session);
|
jpayne@69
|
865
|
jpayne@69
|
866 LIBSSH2_API void libssh2_channel_set_blocking(LIBSSH2_CHANNEL *channel,
|
jpayne@69
|
867 int blocking);
|
jpayne@69
|
868
|
jpayne@69
|
869 LIBSSH2_API void libssh2_session_set_timeout(LIBSSH2_SESSION* session,
|
jpayne@69
|
870 long timeout);
|
jpayne@69
|
871 LIBSSH2_API long libssh2_session_get_timeout(LIBSSH2_SESSION* session);
|
jpayne@69
|
872
|
jpayne@69
|
873 /* libssh2_channel_handle_extended_data is DEPRECATED, do not use! */
|
jpayne@69
|
874 LIBSSH2_API void libssh2_channel_handle_extended_data(LIBSSH2_CHANNEL *channel,
|
jpayne@69
|
875 int ignore_mode);
|
jpayne@69
|
876 LIBSSH2_API int libssh2_channel_handle_extended_data2(LIBSSH2_CHANNEL *channel,
|
jpayne@69
|
877 int ignore_mode);
|
jpayne@69
|
878
|
jpayne@69
|
879 /* libssh2_channel_ignore_extended_data() is defined below for BC with version
|
jpayne@69
|
880 * 0.1
|
jpayne@69
|
881 *
|
jpayne@69
|
882 * Future uses should use libssh2_channel_handle_extended_data() directly if
|
jpayne@69
|
883 * LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE is passed, extended data will be read
|
jpayne@69
|
884 * (FIFO) from the standard data channel
|
jpayne@69
|
885 */
|
jpayne@69
|
886 /* DEPRECATED */
|
jpayne@69
|
887 #define libssh2_channel_ignore_extended_data(channel, ignore) \
|
jpayne@69
|
888 libssh2_channel_handle_extended_data((channel), \
|
jpayne@69
|
889 (ignore) ? \
|
jpayne@69
|
890 LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE : \
|
jpayne@69
|
891 LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL)
|
jpayne@69
|
892
|
jpayne@69
|
893 #define LIBSSH2_CHANNEL_FLUSH_EXTENDED_DATA -1
|
jpayne@69
|
894 #define LIBSSH2_CHANNEL_FLUSH_ALL -2
|
jpayne@69
|
895 LIBSSH2_API int libssh2_channel_flush_ex(LIBSSH2_CHANNEL *channel,
|
jpayne@69
|
896 int streamid);
|
jpayne@69
|
897 #define libssh2_channel_flush(channel) libssh2_channel_flush_ex((channel), 0)
|
jpayne@69
|
898 #define libssh2_channel_flush_stderr(channel) \
|
jpayne@69
|
899 libssh2_channel_flush_ex((channel), SSH_EXTENDED_DATA_STDERR)
|
jpayne@69
|
900
|
jpayne@69
|
901 LIBSSH2_API int libssh2_channel_get_exit_status(LIBSSH2_CHANNEL* channel);
|
jpayne@69
|
902 LIBSSH2_API int libssh2_channel_get_exit_signal(LIBSSH2_CHANNEL* channel,
|
jpayne@69
|
903 char **exitsignal,
|
jpayne@69
|
904 size_t *exitsignal_len,
|
jpayne@69
|
905 char **errmsg,
|
jpayne@69
|
906 size_t *errmsg_len,
|
jpayne@69
|
907 char **langtag,
|
jpayne@69
|
908 size_t *langtag_len);
|
jpayne@69
|
909 LIBSSH2_API int libssh2_channel_send_eof(LIBSSH2_CHANNEL *channel);
|
jpayne@69
|
910 LIBSSH2_API int libssh2_channel_eof(LIBSSH2_CHANNEL *channel);
|
jpayne@69
|
911 LIBSSH2_API int libssh2_channel_wait_eof(LIBSSH2_CHANNEL *channel);
|
jpayne@69
|
912 LIBSSH2_API int libssh2_channel_close(LIBSSH2_CHANNEL *channel);
|
jpayne@69
|
913 LIBSSH2_API int libssh2_channel_wait_closed(LIBSSH2_CHANNEL *channel);
|
jpayne@69
|
914 LIBSSH2_API int libssh2_channel_free(LIBSSH2_CHANNEL *channel);
|
jpayne@69
|
915
|
jpayne@69
|
916 /* libssh2_scp_recv is DEPRECATED, do not use! */
|
jpayne@69
|
917 LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session,
|
jpayne@69
|
918 const char *path,
|
jpayne@69
|
919 struct stat *sb);
|
jpayne@69
|
920 /* Use libssh2_scp_recv2 for large (> 2GB) file support on windows */
|
jpayne@69
|
921 LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv2(LIBSSH2_SESSION *session,
|
jpayne@69
|
922 const char *path,
|
jpayne@69
|
923 libssh2_struct_stat *sb);
|
jpayne@69
|
924 LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_send_ex(LIBSSH2_SESSION *session,
|
jpayne@69
|
925 const char *path, int mode,
|
jpayne@69
|
926 size_t size, long mtime,
|
jpayne@69
|
927 long atime);
|
jpayne@69
|
928 LIBSSH2_API LIBSSH2_CHANNEL *
|
jpayne@69
|
929 libssh2_scp_send64(LIBSSH2_SESSION *session, const char *path, int mode,
|
jpayne@69
|
930 libssh2_int64_t size, time_t mtime, time_t atime);
|
jpayne@69
|
931
|
jpayne@69
|
932 #define libssh2_scp_send(session, path, mode, size) \
|
jpayne@69
|
933 libssh2_scp_send_ex((session), (path), (mode), (size), 0, 0)
|
jpayne@69
|
934
|
jpayne@69
|
935 LIBSSH2_API int libssh2_base64_decode(LIBSSH2_SESSION *session, char **dest,
|
jpayne@69
|
936 unsigned int *dest_len,
|
jpayne@69
|
937 const char *src, unsigned int src_len);
|
jpayne@69
|
938
|
jpayne@69
|
939 LIBSSH2_API
|
jpayne@69
|
940 const char *libssh2_version(int req_version_num);
|
jpayne@69
|
941
|
jpayne@69
|
942 #define HAVE_LIBSSH2_KNOWNHOST_API 0x010101 /* since 1.1.1 */
|
jpayne@69
|
943 #define HAVE_LIBSSH2_VERSION_API 0x010100 /* libssh2_version since 1.1 */
|
jpayne@69
|
944
|
jpayne@69
|
945 struct libssh2_knownhost {
|
jpayne@69
|
946 unsigned int magic; /* magic stored by the library */
|
jpayne@69
|
947 void *node; /* handle to the internal representation of this host */
|
jpayne@69
|
948 char *name; /* this is NULL if no plain text host name exists */
|
jpayne@69
|
949 char *key; /* key in base64/printable format */
|
jpayne@69
|
950 int typemask;
|
jpayne@69
|
951 };
|
jpayne@69
|
952
|
jpayne@69
|
953 /*
|
jpayne@69
|
954 * libssh2_knownhost_init
|
jpayne@69
|
955 *
|
jpayne@69
|
956 * Init a collection of known hosts. Returns the pointer to a collection.
|
jpayne@69
|
957 *
|
jpayne@69
|
958 */
|
jpayne@69
|
959 LIBSSH2_API LIBSSH2_KNOWNHOSTS *
|
jpayne@69
|
960 libssh2_knownhost_init(LIBSSH2_SESSION *session);
|
jpayne@69
|
961
|
jpayne@69
|
962 /*
|
jpayne@69
|
963 * libssh2_knownhost_add
|
jpayne@69
|
964 *
|
jpayne@69
|
965 * Add a host and its associated key to the collection of known hosts.
|
jpayne@69
|
966 *
|
jpayne@69
|
967 * The 'type' argument specifies on what format the given host and keys are:
|
jpayne@69
|
968 *
|
jpayne@69
|
969 * plain - ascii "hostname.domain.tld"
|
jpayne@69
|
970 * sha1 - SHA1(<salt> <host>) base64-encoded!
|
jpayne@69
|
971 * custom - another hash
|
jpayne@69
|
972 *
|
jpayne@69
|
973 * If 'sha1' is selected as type, the salt must be provided to the salt
|
jpayne@69
|
974 * argument. This too base64 encoded.
|
jpayne@69
|
975 *
|
jpayne@69
|
976 * The SHA-1 hash is what OpenSSH can be told to use in known_hosts files. If
|
jpayne@69
|
977 * a custom type is used, salt is ignored and you must provide the host
|
jpayne@69
|
978 * pre-hashed when checking for it in the libssh2_knownhost_check() function.
|
jpayne@69
|
979 *
|
jpayne@69
|
980 * The keylen parameter may be omitted (zero) if the key is provided as a
|
jpayne@69
|
981 * NULL-terminated base64-encoded string.
|
jpayne@69
|
982 */
|
jpayne@69
|
983
|
jpayne@69
|
984 /* host format (2 bits) */
|
jpayne@69
|
985 #define LIBSSH2_KNOWNHOST_TYPE_MASK 0xffff
|
jpayne@69
|
986 #define LIBSSH2_KNOWNHOST_TYPE_PLAIN 1
|
jpayne@69
|
987 #define LIBSSH2_KNOWNHOST_TYPE_SHA1 2 /* always base64 encoded */
|
jpayne@69
|
988 #define LIBSSH2_KNOWNHOST_TYPE_CUSTOM 3
|
jpayne@69
|
989
|
jpayne@69
|
990 /* key format (2 bits) */
|
jpayne@69
|
991 #define LIBSSH2_KNOWNHOST_KEYENC_MASK (3<<16)
|
jpayne@69
|
992 #define LIBSSH2_KNOWNHOST_KEYENC_RAW (1<<16)
|
jpayne@69
|
993 #define LIBSSH2_KNOWNHOST_KEYENC_BASE64 (2<<16)
|
jpayne@69
|
994
|
jpayne@69
|
995 /* type of key (4 bits) */
|
jpayne@69
|
996 #define LIBSSH2_KNOWNHOST_KEY_MASK (15<<18)
|
jpayne@69
|
997 #define LIBSSH2_KNOWNHOST_KEY_SHIFT 18
|
jpayne@69
|
998 #define LIBSSH2_KNOWNHOST_KEY_RSA1 (1<<18)
|
jpayne@69
|
999 #define LIBSSH2_KNOWNHOST_KEY_SSHRSA (2<<18)
|
jpayne@69
|
1000 #define LIBSSH2_KNOWNHOST_KEY_SSHDSS (3<<18)
|
jpayne@69
|
1001 #define LIBSSH2_KNOWNHOST_KEY_ECDSA_256 (4<<18)
|
jpayne@69
|
1002 #define LIBSSH2_KNOWNHOST_KEY_ECDSA_384 (5<<18)
|
jpayne@69
|
1003 #define LIBSSH2_KNOWNHOST_KEY_ECDSA_521 (6<<18)
|
jpayne@69
|
1004 #define LIBSSH2_KNOWNHOST_KEY_ED25519 (7<<18)
|
jpayne@69
|
1005 #define LIBSSH2_KNOWNHOST_KEY_UNKNOWN (15<<18)
|
jpayne@69
|
1006
|
jpayne@69
|
1007 LIBSSH2_API int
|
jpayne@69
|
1008 libssh2_knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
|
jpayne@69
|
1009 const char *host,
|
jpayne@69
|
1010 const char *salt,
|
jpayne@69
|
1011 const char *key, size_t keylen, int typemask,
|
jpayne@69
|
1012 struct libssh2_knownhost **store);
|
jpayne@69
|
1013
|
jpayne@69
|
1014 /*
|
jpayne@69
|
1015 * libssh2_knownhost_addc
|
jpayne@69
|
1016 *
|
jpayne@69
|
1017 * Add a host and its associated key to the collection of known hosts.
|
jpayne@69
|
1018 *
|
jpayne@69
|
1019 * Takes a comment argument that may be NULL. A NULL comment indicates
|
jpayne@69
|
1020 * there is no comment and the entry will end directly after the key
|
jpayne@69
|
1021 * when written out to a file. An empty string "" comment will indicate an
|
jpayne@69
|
1022 * empty comment which will cause a single space to be written after the key.
|
jpayne@69
|
1023 *
|
jpayne@69
|
1024 * The 'type' argument specifies on what format the given host and keys are:
|
jpayne@69
|
1025 *
|
jpayne@69
|
1026 * plain - ascii "hostname.domain.tld"
|
jpayne@69
|
1027 * sha1 - SHA1(<salt> <host>) base64-encoded!
|
jpayne@69
|
1028 * custom - another hash
|
jpayne@69
|
1029 *
|
jpayne@69
|
1030 * If 'sha1' is selected as type, the salt must be provided to the salt
|
jpayne@69
|
1031 * argument. This too base64 encoded.
|
jpayne@69
|
1032 *
|
jpayne@69
|
1033 * The SHA-1 hash is what OpenSSH can be told to use in known_hosts files. If
|
jpayne@69
|
1034 * a custom type is used, salt is ignored and you must provide the host
|
jpayne@69
|
1035 * pre-hashed when checking for it in the libssh2_knownhost_check() function.
|
jpayne@69
|
1036 *
|
jpayne@69
|
1037 * The keylen parameter may be omitted (zero) if the key is provided as a
|
jpayne@69
|
1038 * NULL-terminated base64-encoded string.
|
jpayne@69
|
1039 */
|
jpayne@69
|
1040
|
jpayne@69
|
1041 LIBSSH2_API int
|
jpayne@69
|
1042 libssh2_knownhost_addc(LIBSSH2_KNOWNHOSTS *hosts,
|
jpayne@69
|
1043 const char *host,
|
jpayne@69
|
1044 const char *salt,
|
jpayne@69
|
1045 const char *key, size_t keylen,
|
jpayne@69
|
1046 const char *comment, size_t commentlen, int typemask,
|
jpayne@69
|
1047 struct libssh2_knownhost **store);
|
jpayne@69
|
1048
|
jpayne@69
|
1049 /*
|
jpayne@69
|
1050 * libssh2_knownhost_check
|
jpayne@69
|
1051 *
|
jpayne@69
|
1052 * Check a host and its associated key against the collection of known hosts.
|
jpayne@69
|
1053 *
|
jpayne@69
|
1054 * The type is the type/format of the given host name.
|
jpayne@69
|
1055 *
|
jpayne@69
|
1056 * plain - ascii "hostname.domain.tld"
|
jpayne@69
|
1057 * custom - prehashed base64 encoded. Note that this cannot use any salts.
|
jpayne@69
|
1058 *
|
jpayne@69
|
1059 *
|
jpayne@69
|
1060 * 'knownhost' may be set to NULL if you don't care about that info.
|
jpayne@69
|
1061 *
|
jpayne@69
|
1062 * Returns:
|
jpayne@69
|
1063 *
|
jpayne@69
|
1064 * LIBSSH2_KNOWNHOST_CHECK_* values, see below
|
jpayne@69
|
1065 *
|
jpayne@69
|
1066 */
|
jpayne@69
|
1067
|
jpayne@69
|
1068 #define LIBSSH2_KNOWNHOST_CHECK_MATCH 0
|
jpayne@69
|
1069 #define LIBSSH2_KNOWNHOST_CHECK_MISMATCH 1
|
jpayne@69
|
1070 #define LIBSSH2_KNOWNHOST_CHECK_NOTFOUND 2
|
jpayne@69
|
1071 #define LIBSSH2_KNOWNHOST_CHECK_FAILURE 3
|
jpayne@69
|
1072
|
jpayne@69
|
1073 LIBSSH2_API int
|
jpayne@69
|
1074 libssh2_knownhost_check(LIBSSH2_KNOWNHOSTS *hosts,
|
jpayne@69
|
1075 const char *host, const char *key, size_t keylen,
|
jpayne@69
|
1076 int typemask,
|
jpayne@69
|
1077 struct libssh2_knownhost **knownhost);
|
jpayne@69
|
1078
|
jpayne@69
|
1079 /* this function is identital to the above one, but also takes a port
|
jpayne@69
|
1080 argument that allows libssh2 to do a better check */
|
jpayne@69
|
1081 LIBSSH2_API int
|
jpayne@69
|
1082 libssh2_knownhost_checkp(LIBSSH2_KNOWNHOSTS *hosts,
|
jpayne@69
|
1083 const char *host, int port,
|
jpayne@69
|
1084 const char *key, size_t keylen,
|
jpayne@69
|
1085 int typemask,
|
jpayne@69
|
1086 struct libssh2_knownhost **knownhost);
|
jpayne@69
|
1087
|
jpayne@69
|
1088 /*
|
jpayne@69
|
1089 * libssh2_knownhost_del
|
jpayne@69
|
1090 *
|
jpayne@69
|
1091 * Remove a host from the collection of known hosts. The 'entry' struct is
|
jpayne@69
|
1092 * retrieved by a call to libssh2_knownhost_check().
|
jpayne@69
|
1093 *
|
jpayne@69
|
1094 */
|
jpayne@69
|
1095 LIBSSH2_API int
|
jpayne@69
|
1096 libssh2_knownhost_del(LIBSSH2_KNOWNHOSTS *hosts,
|
jpayne@69
|
1097 struct libssh2_knownhost *entry);
|
jpayne@69
|
1098
|
jpayne@69
|
1099 /*
|
jpayne@69
|
1100 * libssh2_knownhost_free
|
jpayne@69
|
1101 *
|
jpayne@69
|
1102 * Free an entire collection of known hosts.
|
jpayne@69
|
1103 *
|
jpayne@69
|
1104 */
|
jpayne@69
|
1105 LIBSSH2_API void
|
jpayne@69
|
1106 libssh2_knownhost_free(LIBSSH2_KNOWNHOSTS *hosts);
|
jpayne@69
|
1107
|
jpayne@69
|
1108 /*
|
jpayne@69
|
1109 * libssh2_knownhost_readline()
|
jpayne@69
|
1110 *
|
jpayne@69
|
1111 * Pass in a line of a file of 'type'. It makes libssh2 read this line.
|
jpayne@69
|
1112 *
|
jpayne@69
|
1113 * LIBSSH2_KNOWNHOST_FILE_OPENSSH is the only supported type.
|
jpayne@69
|
1114 *
|
jpayne@69
|
1115 */
|
jpayne@69
|
1116 LIBSSH2_API int
|
jpayne@69
|
1117 libssh2_knownhost_readline(LIBSSH2_KNOWNHOSTS *hosts,
|
jpayne@69
|
1118 const char *line, size_t len, int type);
|
jpayne@69
|
1119
|
jpayne@69
|
1120 /*
|
jpayne@69
|
1121 * libssh2_knownhost_readfile
|
jpayne@69
|
1122 *
|
jpayne@69
|
1123 * Add hosts+key pairs from a given file.
|
jpayne@69
|
1124 *
|
jpayne@69
|
1125 * Returns a negative value for error or number of successfully added hosts.
|
jpayne@69
|
1126 *
|
jpayne@69
|
1127 * This implementation currently only knows one 'type' (openssh), all others
|
jpayne@69
|
1128 * are reserved for future use.
|
jpayne@69
|
1129 */
|
jpayne@69
|
1130
|
jpayne@69
|
1131 #define LIBSSH2_KNOWNHOST_FILE_OPENSSH 1
|
jpayne@69
|
1132
|
jpayne@69
|
1133 LIBSSH2_API int
|
jpayne@69
|
1134 libssh2_knownhost_readfile(LIBSSH2_KNOWNHOSTS *hosts,
|
jpayne@69
|
1135 const char *filename, int type);
|
jpayne@69
|
1136
|
jpayne@69
|
1137 /*
|
jpayne@69
|
1138 * libssh2_knownhost_writeline()
|
jpayne@69
|
1139 *
|
jpayne@69
|
1140 * Ask libssh2 to convert a known host to an output line for storage.
|
jpayne@69
|
1141 *
|
jpayne@69
|
1142 * Note that this function returns LIBSSH2_ERROR_BUFFER_TOO_SMALL if the given
|
jpayne@69
|
1143 * output buffer is too small to hold the desired output.
|
jpayne@69
|
1144 *
|
jpayne@69
|
1145 * This implementation currently only knows one 'type' (openssh), all others
|
jpayne@69
|
1146 * are reserved for future use.
|
jpayne@69
|
1147 *
|
jpayne@69
|
1148 */
|
jpayne@69
|
1149 LIBSSH2_API int
|
jpayne@69
|
1150 libssh2_knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
|
jpayne@69
|
1151 struct libssh2_knownhost *known,
|
jpayne@69
|
1152 char *buffer, size_t buflen,
|
jpayne@69
|
1153 size_t *outlen, /* the amount of written data */
|
jpayne@69
|
1154 int type);
|
jpayne@69
|
1155
|
jpayne@69
|
1156 /*
|
jpayne@69
|
1157 * libssh2_knownhost_writefile
|
jpayne@69
|
1158 *
|
jpayne@69
|
1159 * Write hosts+key pairs to a given file.
|
jpayne@69
|
1160 *
|
jpayne@69
|
1161 * This implementation currently only knows one 'type' (openssh), all others
|
jpayne@69
|
1162 * are reserved for future use.
|
jpayne@69
|
1163 */
|
jpayne@69
|
1164
|
jpayne@69
|
1165 LIBSSH2_API int
|
jpayne@69
|
1166 libssh2_knownhost_writefile(LIBSSH2_KNOWNHOSTS *hosts,
|
jpayne@69
|
1167 const char *filename, int type);
|
jpayne@69
|
1168
|
jpayne@69
|
1169 /*
|
jpayne@69
|
1170 * libssh2_knownhost_get()
|
jpayne@69
|
1171 *
|
jpayne@69
|
1172 * Traverse the internal list of known hosts. Pass NULL to 'prev' to get
|
jpayne@69
|
1173 * the first one. Or pass a pointer to the previously returned one to get the
|
jpayne@69
|
1174 * next.
|
jpayne@69
|
1175 *
|
jpayne@69
|
1176 * Returns:
|
jpayne@69
|
1177 * 0 if a fine host was stored in 'store'
|
jpayne@69
|
1178 * 1 if end of hosts
|
jpayne@69
|
1179 * [negative] on errors
|
jpayne@69
|
1180 */
|
jpayne@69
|
1181 LIBSSH2_API int
|
jpayne@69
|
1182 libssh2_knownhost_get(LIBSSH2_KNOWNHOSTS *hosts,
|
jpayne@69
|
1183 struct libssh2_knownhost **store,
|
jpayne@69
|
1184 struct libssh2_knownhost *prev);
|
jpayne@69
|
1185
|
jpayne@69
|
1186 #define HAVE_LIBSSH2_AGENT_API 0x010202 /* since 1.2.2 */
|
jpayne@69
|
1187
|
jpayne@69
|
1188 struct libssh2_agent_publickey {
|
jpayne@69
|
1189 unsigned int magic; /* magic stored by the library */
|
jpayne@69
|
1190 void *node; /* handle to the internal representation of key */
|
jpayne@69
|
1191 unsigned char *blob; /* public key blob */
|
jpayne@69
|
1192 size_t blob_len; /* length of the public key blob */
|
jpayne@69
|
1193 char *comment; /* comment in printable format */
|
jpayne@69
|
1194 };
|
jpayne@69
|
1195
|
jpayne@69
|
1196 /*
|
jpayne@69
|
1197 * libssh2_agent_init
|
jpayne@69
|
1198 *
|
jpayne@69
|
1199 * Init an ssh-agent handle. Returns the pointer to the handle.
|
jpayne@69
|
1200 *
|
jpayne@69
|
1201 */
|
jpayne@69
|
1202 LIBSSH2_API LIBSSH2_AGENT *
|
jpayne@69
|
1203 libssh2_agent_init(LIBSSH2_SESSION *session);
|
jpayne@69
|
1204
|
jpayne@69
|
1205 /*
|
jpayne@69
|
1206 * libssh2_agent_connect()
|
jpayne@69
|
1207 *
|
jpayne@69
|
1208 * Connect to an ssh-agent.
|
jpayne@69
|
1209 *
|
jpayne@69
|
1210 * Returns 0 if succeeded, or a negative value for error.
|
jpayne@69
|
1211 */
|
jpayne@69
|
1212 LIBSSH2_API int
|
jpayne@69
|
1213 libssh2_agent_connect(LIBSSH2_AGENT *agent);
|
jpayne@69
|
1214
|
jpayne@69
|
1215 /*
|
jpayne@69
|
1216 * libssh2_agent_list_identities()
|
jpayne@69
|
1217 *
|
jpayne@69
|
1218 * Request an ssh-agent to list identities.
|
jpayne@69
|
1219 *
|
jpayne@69
|
1220 * Returns 0 if succeeded, or a negative value for error.
|
jpayne@69
|
1221 */
|
jpayne@69
|
1222 LIBSSH2_API int
|
jpayne@69
|
1223 libssh2_agent_list_identities(LIBSSH2_AGENT *agent);
|
jpayne@69
|
1224
|
jpayne@69
|
1225 /*
|
jpayne@69
|
1226 * libssh2_agent_get_identity()
|
jpayne@69
|
1227 *
|
jpayne@69
|
1228 * Traverse the internal list of public keys. Pass NULL to 'prev' to get
|
jpayne@69
|
1229 * the first one. Or pass a pointer to the previously returned one to get the
|
jpayne@69
|
1230 * next.
|
jpayne@69
|
1231 *
|
jpayne@69
|
1232 * Returns:
|
jpayne@69
|
1233 * 0 if a fine public key was stored in 'store'
|
jpayne@69
|
1234 * 1 if end of public keys
|
jpayne@69
|
1235 * [negative] on errors
|
jpayne@69
|
1236 */
|
jpayne@69
|
1237 LIBSSH2_API int
|
jpayne@69
|
1238 libssh2_agent_get_identity(LIBSSH2_AGENT *agent,
|
jpayne@69
|
1239 struct libssh2_agent_publickey **store,
|
jpayne@69
|
1240 struct libssh2_agent_publickey *prev);
|
jpayne@69
|
1241
|
jpayne@69
|
1242 /*
|
jpayne@69
|
1243 * libssh2_agent_userauth()
|
jpayne@69
|
1244 *
|
jpayne@69
|
1245 * Do publickey user authentication with the help of ssh-agent.
|
jpayne@69
|
1246 *
|
jpayne@69
|
1247 * Returns 0 if succeeded, or a negative value for error.
|
jpayne@69
|
1248 */
|
jpayne@69
|
1249 LIBSSH2_API int
|
jpayne@69
|
1250 libssh2_agent_userauth(LIBSSH2_AGENT *agent,
|
jpayne@69
|
1251 const char *username,
|
jpayne@69
|
1252 struct libssh2_agent_publickey *identity);
|
jpayne@69
|
1253
|
jpayne@69
|
1254 /*
|
jpayne@69
|
1255 * libssh2_agent_disconnect()
|
jpayne@69
|
1256 *
|
jpayne@69
|
1257 * Close a connection to an ssh-agent.
|
jpayne@69
|
1258 *
|
jpayne@69
|
1259 * Returns 0 if succeeded, or a negative value for error.
|
jpayne@69
|
1260 */
|
jpayne@69
|
1261 LIBSSH2_API int
|
jpayne@69
|
1262 libssh2_agent_disconnect(LIBSSH2_AGENT *agent);
|
jpayne@69
|
1263
|
jpayne@69
|
1264 /*
|
jpayne@69
|
1265 * libssh2_agent_free()
|
jpayne@69
|
1266 *
|
jpayne@69
|
1267 * Free an ssh-agent handle. This function also frees the internal
|
jpayne@69
|
1268 * collection of public keys.
|
jpayne@69
|
1269 */
|
jpayne@69
|
1270 LIBSSH2_API void
|
jpayne@69
|
1271 libssh2_agent_free(LIBSSH2_AGENT *agent);
|
jpayne@69
|
1272
|
jpayne@69
|
1273 /*
|
jpayne@69
|
1274 * libssh2_agent_set_identity_path()
|
jpayne@69
|
1275 *
|
jpayne@69
|
1276 * Allows a custom agent identity socket path beyond SSH_AUTH_SOCK env
|
jpayne@69
|
1277 *
|
jpayne@69
|
1278 */
|
jpayne@69
|
1279 LIBSSH2_API void
|
jpayne@69
|
1280 libssh2_agent_set_identity_path(LIBSSH2_AGENT *agent,
|
jpayne@69
|
1281 const char *path);
|
jpayne@69
|
1282
|
jpayne@69
|
1283 /*
|
jpayne@69
|
1284 * libssh2_agent_get_identity_path()
|
jpayne@69
|
1285 *
|
jpayne@69
|
1286 * Returns the custom agent identity socket path if set
|
jpayne@69
|
1287 *
|
jpayne@69
|
1288 */
|
jpayne@69
|
1289 LIBSSH2_API const char *
|
jpayne@69
|
1290 libssh2_agent_get_identity_path(LIBSSH2_AGENT *agent);
|
jpayne@69
|
1291
|
jpayne@69
|
1292 /*
|
jpayne@69
|
1293 * libssh2_keepalive_config()
|
jpayne@69
|
1294 *
|
jpayne@69
|
1295 * Set how often keepalive messages should be sent. WANT_REPLY
|
jpayne@69
|
1296 * indicates whether the keepalive messages should request a response
|
jpayne@69
|
1297 * from the server. INTERVAL is number of seconds that can pass
|
jpayne@69
|
1298 * without any I/O, use 0 (the default) to disable keepalives. To
|
jpayne@69
|
1299 * avoid some busy-loop corner-cases, if you specify an interval of 1
|
jpayne@69
|
1300 * it will be treated as 2.
|
jpayne@69
|
1301 *
|
jpayne@69
|
1302 * Note that non-blocking applications are responsible for sending the
|
jpayne@69
|
1303 * keepalive messages using libssh2_keepalive_send().
|
jpayne@69
|
1304 */
|
jpayne@69
|
1305 LIBSSH2_API void libssh2_keepalive_config(LIBSSH2_SESSION *session,
|
jpayne@69
|
1306 int want_reply,
|
jpayne@69
|
1307 unsigned interval);
|
jpayne@69
|
1308
|
jpayne@69
|
1309 /*
|
jpayne@69
|
1310 * libssh2_keepalive_send()
|
jpayne@69
|
1311 *
|
jpayne@69
|
1312 * Send a keepalive message if needed. SECONDS_TO_NEXT indicates how
|
jpayne@69
|
1313 * many seconds you can sleep after this call before you need to call
|
jpayne@69
|
1314 * it again. Returns 0 on success, or LIBSSH2_ERROR_SOCKET_SEND on
|
jpayne@69
|
1315 * I/O errors.
|
jpayne@69
|
1316 */
|
jpayne@69
|
1317 LIBSSH2_API int libssh2_keepalive_send(LIBSSH2_SESSION *session,
|
jpayne@69
|
1318 int *seconds_to_next);
|
jpayne@69
|
1319
|
jpayne@69
|
1320 /* NOTE NOTE NOTE
|
jpayne@69
|
1321 libssh2_trace() has no function in builds that aren't built with debug
|
jpayne@69
|
1322 enabled
|
jpayne@69
|
1323 */
|
jpayne@69
|
1324 LIBSSH2_API int libssh2_trace(LIBSSH2_SESSION *session, int bitmask);
|
jpayne@69
|
1325 #define LIBSSH2_TRACE_TRANS (1<<1)
|
jpayne@69
|
1326 #define LIBSSH2_TRACE_KEX (1<<2)
|
jpayne@69
|
1327 #define LIBSSH2_TRACE_AUTH (1<<3)
|
jpayne@69
|
1328 #define LIBSSH2_TRACE_CONN (1<<4)
|
jpayne@69
|
1329 #define LIBSSH2_TRACE_SCP (1<<5)
|
jpayne@69
|
1330 #define LIBSSH2_TRACE_SFTP (1<<6)
|
jpayne@69
|
1331 #define LIBSSH2_TRACE_ERROR (1<<7)
|
jpayne@69
|
1332 #define LIBSSH2_TRACE_PUBLICKEY (1<<8)
|
jpayne@69
|
1333 #define LIBSSH2_TRACE_SOCKET (1<<9)
|
jpayne@69
|
1334
|
jpayne@69
|
1335 typedef void (*libssh2_trace_handler_func)(LIBSSH2_SESSION*,
|
jpayne@69
|
1336 void *,
|
jpayne@69
|
1337 const char *,
|
jpayne@69
|
1338 size_t);
|
jpayne@69
|
1339 LIBSSH2_API int libssh2_trace_sethandler(LIBSSH2_SESSION *session,
|
jpayne@69
|
1340 void *context,
|
jpayne@69
|
1341 libssh2_trace_handler_func callback);
|
jpayne@69
|
1342
|
jpayne@69
|
1343 #ifdef __cplusplus
|
jpayne@69
|
1344 } /* extern "C" */
|
jpayne@69
|
1345 #endif
|
jpayne@69
|
1346
|
jpayne@69
|
1347 #endif /* !RC_INVOKED */
|
jpayne@69
|
1348
|
jpayne@69
|
1349 #endif /* LIBSSH2_H */
|