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