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