/* Copyright (c) 2004-2009, Sara Golemon <sarag@libssh2.org> * Copyright (c) 2009-2012 Daniel Stenberg * Copyright (c) 2010 Simon Josefsson <simon@josefsson.org> * All rights reserved. * * Redistribution and use in source and binary forms, * with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above * copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials * provided with the distribution. * * Neither the name of the copyright holder nor the names * of any other contributors may be used to endorse or * promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. */ #ifndef LIBSSH2_H#define LIBSSH2_H 1 #define LIBSSH2_COPYRIGHT "2004-2012 The libssh2 project and its contributors." /* We use underscore instead of dash when appending DEV in dev versions just to make the BANNER define (used by src/session.c) be a valid SSH banner. Release versions have no appended strings and may of course not have dashes either. */#define LIBSSH2_VERSION "1.4.3" /* The numeric version number is also available "in parts" by using these defines: */#define LIBSSH2_VERSION_MAJOR 1#define LIBSSH2_VERSION_MINOR 4#define LIBSSH2_VERSION_PATCH 3 /* This is the numeric version of the libssh2 version number, meant for easier parsing and comparions by programs. The LIBSSH2_VERSION_NUM define will always follow this syntax: 0xXXYYZZ Where XX, YY and ZZ are the main version, release and patch numbers in hexadecimal (using 8 bits each). All three numbers are always represented using two digits. 1.2 would appear as "0x010200" while version 9.11.7 appears as "0x090b07". This 6-digit (24 bits) hexadecimal number does not show pre-release number, and it is always a greater number in a more recent release. It makes comparisons with greater than and less than work.*/#define LIBSSH2_VERSION_NUM 0x010403 /* * This is the date and time when the full source package was created. The * timestamp is not stored in the source code repo, as the timestamp is * properly set in the tarballs by the maketgz script. * * The format of the date should follow this template: * * "Mon Feb 12 11:35:33 UTC 2007" */#define LIBSSH2_TIMESTAMP "Tue Nov 27 21:45:20 UTC 2012" #ifndef RC_INVOKED #ifdef __cplusplusextern "C" {#endif#ifdef _WIN32# include <basetsd.h># include <winsock2.h>#endif #include <stddef.h>#include <string.h>#include <sys/stat.h>#include <sys/types.h> /* Allow alternate API prefix from CFLAGS or calling app */#ifndef LIBSSH2_API# ifdef LIBSSH2_WIN32# ifdef LIBSSH2_LIBRARY# define LIBSSH2_API __declspec(dllexport)# else# define LIBSSH2_API __declspec(dllimport)# endif /* LIBSSH2_LIBRARY */# else /* !LIBSSH2_WIN32 */# define LIBSSH2_API# endif /* LIBSSH2_WIN32 */#endif /* LIBSSH2_API */ #if defined(LIBSSH2_DARWIN)# include <sys/uio.h>#endif #if (defined(NETWARE) && !defined(__NOVELL_LIBC__))# include <sys/bsdskt.h>typedef unsigned char uint8_t;typedef unsigned int uint32_t;#endif #ifdef _MSC_VERtypedef unsigned char uint8_t;typedef unsigned int uint32_t;typedef unsigned __int64 libssh2_uint64_t;typedef __int64 libssh2_int64_t;#ifndef ssize_ttypedef SSIZE_T ssize_t;#endif#elsetypedef unsigned long long libssh2_uint64_t;typedef long long libssh2_int64_t;#endif #ifdef WIN32typedef SOCKET libssh2_socket_t;#define LIBSSH2_INVALID_SOCKET INVALID_SOCKET#else /* !WIN32 */typedef int libssh2_socket_t;#define LIBSSH2_INVALID_SOCKET -1#endif /* WIN32 */ /* Part of every banner, user specified or not */#define LIBSSH2_SSH_BANNER "SSH-2.0-libssh2_" LIBSSH2_VERSION /* We *could* add a comment here if we so chose */#define LIBSSH2_SSH_DEFAULT_BANNER LIBSSH2_SSH_BANNER#define LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF LIBSSH2_SSH_DEFAULT_BANNER "\r\n" /* Default generate and safe prime sizes for diffie-hellman-group-exchange-sha1 */#define LIBSSH2_DH_GEX_MINGROUP 1024#define LIBSSH2_DH_GEX_OPTGROUP 1536#define LIBSSH2_DH_GEX_MAXGROUP 2048 /* Defaults for pty requests */#define LIBSSH2_TERM_WIDTH 80#define LIBSSH2_TERM_HEIGHT 24#define LIBSSH2_TERM_WIDTH_PX 0#define LIBSSH2_TERM_HEIGHT_PX 0 /* 1/4 second */#define LIBSSH2_SOCKET_POLL_UDELAY 250000/* 0.25 * 120 == 30 seconds */#define LIBSSH2_SOCKET_POLL_MAXLOOPS 120 /* Maximum size to allow a payload to compress to, plays it safe by falling short of spec limits */#define LIBSSH2_PACKET_MAXCOMP 32000 /* Maximum size to allow a payload to deccompress to, plays it safe by allowing more than spec requires */#define LIBSSH2_PACKET_MAXDECOMP 40000 /* Maximum size for an inbound compressed payload, plays it safe by overshooting spec limits */#define LIBSSH2_PACKET_MAXPAYLOAD 40000 /* Malloc callbacks */#define LIBSSH2_ALLOC_FUNC(name) void *name(size_t count, void **abstract)#define LIBSSH2_REALLOC_FUNC(name) void *name(void *ptr, size_t count, \ void **abstract)#define LIBSSH2_FREE_FUNC(name) void name(void *ptr, void **abstract) typedef struct _LIBSSH2_USERAUTH_KBDINT_PROMPT{ char* text; unsigned int length; unsigned char echo;} LIBSSH2_USERAUTH_KBDINT_PROMPT; typedef struct _LIBSSH2_USERAUTH_KBDINT_RESPONSE{ char* text; unsigned int length;} LIBSSH2_USERAUTH_KBDINT_RESPONSE; /* 'publickey' authentication callback */#define LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC(name) \ int name(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, \ const unsigned char *data, size_t data_len, void **abstract) /* 'keyboard-interactive' authentication callback */#define LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC(name_) \ void name_(const char* name, int name_len, const char* instruction, \ int instruction_len, int num_prompts, \ const LIBSSH2_USERAUTH_KBDINT_PROMPT* prompts, \ LIBSSH2_USERAUTH_KBDINT_RESPONSE* responses, void **abstract) /* Callbacks for special SSH packets */#define LIBSSH2_IGNORE_FUNC(name) \ void name(LIBSSH2_SESSION *session, const char *message, int message_len, \ void **abstract) #define LIBSSH2_DEBUG_FUNC(name) \ void name(LIBSSH2_SESSION *session, int always_display, const char *message, \ int message_len, const char *language, int language_len, \ void **abstract) #define LIBSSH2_DISCONNECT_FUNC(name) \ void name(LIBSSH2_SESSION *session, int reason, const char *message, \ int message_len, const char *language, int language_len, \ void **abstract) #define LIBSSH2_PASSWD_CHANGEREQ_FUNC(name) \ void name(LIBSSH2_SESSION *session, char **newpw, int *newpw_len, \ void **abstract) #define LIBSSH2_MACERROR_FUNC(name) \ int name(LIBSSH2_SESSION *session, const char *packet, int packet_len, \ void **abstract) #define LIBSSH2_X11_OPEN_FUNC(name) \ void name(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, \ const char *shost, int sport, void **abstract) #define LIBSSH2_CHANNEL_CLOSE_FUNC(name) \ void name(LIBSSH2_SESSION *session, void **session_abstract, \ LIBSSH2_CHANNEL *channel, void **channel_abstract) /* I/O callbacks */#define LIBSSH2_RECV_FUNC(name) ssize_t name(libssh2_socket_t socket, \ void *buffer, size_t length, \ int flags, void **abstract)#define LIBSSH2_SEND_FUNC(name) ssize_t name(libssh2_socket_t socket, \ const void *buffer, size_t length,\ int flags, void **abstract) /* libssh2_session_callback_set() constants */#define LIBSSH2_CALLBACK_IGNORE 0#define LIBSSH2_CALLBACK_DEBUG 1#define LIBSSH2_CALLBACK_DISCONNECT 2#define LIBSSH2_CALLBACK_MACERROR 3#define LIBSSH2_CALLBACK_X11 4#define LIBSSH2_CALLBACK_SEND 5#define LIBSSH2_CALLBACK_RECV 6 /* libssh2_session_method_pref() constants */#define LIBSSH2_METHOD_KEX 0#define LIBSSH2_METHOD_HOSTKEY 1#define LIBSSH2_METHOD_CRYPT_CS 2#define LIBSSH2_METHOD_CRYPT_SC 3#define LIBSSH2_METHOD_MAC_CS 4#define LIBSSH2_METHOD_MAC_SC 5#define LIBSSH2_METHOD_COMP_CS 6#define LIBSSH2_METHOD_COMP_SC 7#define LIBSSH2_METHOD_LANG_CS 8#define LIBSSH2_METHOD_LANG_SC 9 /* flags */#define LIBSSH2_FLAG_SIGPIPE 1#define LIBSSH2_FLAG_COMPRESS 2 typedef struct _LIBSSH2_SESSION LIBSSH2_SESSION;typedef struct _LIBSSH2_CHANNEL LIBSSH2_CHANNEL;typedef struct _LIBSSH2_LISTENER LIBSSH2_LISTENER;typedef struct _LIBSSH2_KNOWNHOSTS LIBSSH2_KNOWNHOSTS;typedef struct _LIBSSH2_AGENT LIBSSH2_AGENT; typedef struct _LIBSSH2_POLLFD { unsigned char type; /* LIBSSH2_POLLFD_* below */ union { int socket; /* File descriptors -- examined with system select() call */ LIBSSH2_CHANNEL *channel; /* Examined by checking internal state */ LIBSSH2_LISTENER *listener; /* Read polls only -- are inbound connections waiting to be accepted? */ } fd; unsigned long events; /* Requested Events */ unsigned long revents; /* Returned Events */} LIBSSH2_POLLFD; /* Poll FD Descriptor Types */#define LIBSSH2_POLLFD_SOCKET 1#define LIBSSH2_POLLFD_CHANNEL 2#define LIBSSH2_POLLFD_LISTENER 3 /* Note: Win32 Doesn't actually have a poll() implementation, so some of these values are faked with select() data *//* Poll FD events/revents -- Match sys/poll.h where possible */#define LIBSSH2_POLLFD_POLLIN 0x0001 /* Data available to be read or connection available -- All */#define LIBSSH2_POLLFD_POLLPRI 0x0002 /* Priority data available to be read -- Socket only */#define LIBSSH2_POLLFD_POLLEXT 0x0002 /* Extended data available to be read -- Channel only */#define LIBSSH2_POLLFD_POLLOUT 0x0004 /* Can may be written -- Socket/Channel *//* revents only */#define LIBSSH2_POLLFD_POLLERR 0x0008 /* Error Condition -- Socket */#define LIBSSH2_POLLFD_POLLHUP 0x0010 /* HangUp/EOF -- Socket */#define LIBSSH2_POLLFD_SESSION_CLOSED 0x0010 /* Session Disconnect */#define LIBSSH2_POLLFD_POLLNVAL 0x0020 /* Invalid request -- Socket Only */#define LIBSSH2_POLLFD_POLLEX 0x0040 /* Exception Condition -- Socket/Win32 */#define LIBSSH2_POLLFD_CHANNEL_CLOSED 0x0080 /* Channel Disconnect */#define LIBSSH2_POLLFD_LISTENER_CLOSED 0x0080 /* Listener Disconnect */ #define HAVE_LIBSSH2_SESSION_BLOCK_DIRECTION/* Block Direction Types */#define LIBSSH2_SESSION_BLOCK_INBOUND 0x0001#define LIBSSH2_SESSION_BLOCK_OUTBOUND 0x0002 /* Hash Types */#define LIBSSH2_HOSTKEY_HASH_MD5 1#define LIBSSH2_HOSTKEY_HASH_SHA1 2 /* Hostkey Types */#define LIBSSH2_HOSTKEY_TYPE_UNKNOWN 0#define LIBSSH2_HOSTKEY_TYPE_RSA 1#define LIBSSH2_HOSTKEY_TYPE_DSS 2 /* Disconnect Codes (defined by SSH protocol) */#define SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT 1#define SSH_DISCONNECT_PROTOCOL_ERROR 2#define SSH_DISCONNECT_KEY_EXCHANGE_FAILED 3#define SSH_DISCONNECT_RESERVED 4#define SSH_DISCONNECT_MAC_ERROR 5#define SSH_DISCONNECT_COMPRESSION_ERROR 6#define SSH_DISCONNECT_SERVICE_NOT_AVAILABLE 7#define SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED 8#define SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE 9#define SSH_DISCONNECT_CONNECTION_LOST 10#define SSH_DISCONNECT_BY_APPLICATION 11#define SSH_DISCONNECT_TOO_MANY_CONNECTIONS 12#define SSH_DISCONNECT_AUTH_CANCELLED_BY_USER 13#define SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE 14#define SSH_DISCONNECT_ILLEGAL_USER_NAME 15 /* Error Codes (defined by libssh2) */#define LIBSSH2_ERROR_NONE 0 /* The library once used -1 as a generic error return value on numerous places through the code, which subsequently was converted to LIBSSH2_ERROR_SOCKET_NONE uses over time. As this is a generic error code, the goal is to never ever return this code but instead make sure that a more accurate and descriptive error code is used. */#define LIBSSH2_ERROR_SOCKET_NONE -1 #define LIBSSH2_ERROR_BANNER_RECV -2#define LIBSSH2_ERROR_BANNER_SEND -3#define LIBSSH2_ERROR_INVALID_MAC -4#define LIBSSH2_ERROR_KEX_FAILURE -5#define LIBSSH2_ERROR_ALLOC -6#define LIBSSH2_ERROR_SOCKET_SEND -7#define LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE -8#define LIBSSH2_ERROR_TIMEOUT -9#define LIBSSH2_ERROR_HOSTKEY_INIT -10#define LIBSSH2_ERROR_HOSTKEY_SIGN -11#define LIBSSH2_ERROR_DECRYPT -12#define LIBSSH2_ERROR_SOCKET_DISCONNECT -13#define LIBSSH2_ERROR_PROTO -14#define LIBSSH2_ERROR_PASSWORD_EXPIRED -15#define LIBSSH2_ERROR_FILE -16#define LIBSSH2_ERROR_METHOD_NONE -17#define LIBSSH2_ERROR_AUTHENTICATION_FAILED -18#define LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED LIBSSH2_ERROR_AUTHENTICATION_FAILED#define LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED -19#define LIBSSH2_ERROR_CHANNEL_OUTOFORDER -20#define LIBSSH2_ERROR_CHANNEL_FAILURE -21#define LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED -22#define LIBSSH2_ERROR_CHANNEL_UNKNOWN -23#define LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED -24#define LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED -25#define LIBSSH2_ERROR_CHANNEL_CLOSED -26#define LIBSSH2_ERROR_CHANNEL_EOF_SENT -27#define LIBSSH2_ERROR_SCP_PROTOCOL -28#define LIBSSH2_ERROR_ZLIB -29#define LIBSSH2_ERROR_SOCKET_TIMEOUT -30#define LIBSSH2_ERROR_SFTP_PROTOCOL -31#define LIBSSH2_ERROR_REQUEST_DENIED -32#define LIBSSH2_ERROR_METHOD_NOT_SUPPORTED -33#define LIBSSH2_ERROR_INVAL -34#define LIBSSH2_ERROR_INVALID_POLL_TYPE -35#define LIBSSH2_ERROR_PUBLICKEY_PROTOCOL -36#define LIBSSH2_ERROR_EAGAIN -37#define LIBSSH2_ERROR_BUFFER_TOO_SMALL -38#define LIBSSH2_ERROR_BAD_USE -39#define LIBSSH2_ERROR_COMPRESS -40#define LIBSSH2_ERROR_OUT_OF_BOUNDARY -41#define LIBSSH2_ERROR_AGENT_PROTOCOL -42#define LIBSSH2_ERROR_SOCKET_RECV -43#define LIBSSH2_ERROR_ENCRYPT -44#define LIBSSH2_ERROR_BAD_SOCKET -45#define LIBSSH2_ERROR_KNOWN_HOSTS -46 /* this is a define to provide the old (<= 1.2.7) name */#define LIBSSH2_ERROR_BANNER_NONE LIBSSH2_ERROR_BANNER_RECV /* Global API */#define LIBSSH2_INIT_NO_CRYPTO 0x0001 /* * libssh2_init() * * Initialize the libssh2 functions. This typically initialize the * crypto library. It uses a global state, and is not thread safe -- * you must make sure this function is not called concurrently. * * Flags can be: * 0: Normal initialize * LIBSSH2_INIT_NO_CRYPTO: Do not initialize the crypto library (ie. * OPENSSL_add_cipher_algoritms() for OpenSSL * * Returns 0 if succeeded, or a negative value for error. */LIBSSH2_API int libssh2_init(int flags); /* * libssh2_exit() * * Exit the libssh2 functions and free's all memory used internal. */LIBSSH2_API void libssh2_exit(void); /* * libssh2_free() * * Deallocate memory allocated by earlier call to libssh2 functions. */LIBSSH2_API void libssh2_free(LIBSSH2_SESSION *session, void *ptr); /* * libssh2_session_supported_algs() * * Fills algs with a list of supported acryptographic algorithms. Returns a * non-negative number (number of supported algorithms) on success or a * negative number (an eror code) on failure. * * NOTE: on success, algs must be deallocated (by calling libssh2_free) when * not needed anymore */LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session, int method_type, const char*** algs); /* Session API */LIBSSH2_API LIBSSH2_SESSION *libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)), LIBSSH2_FREE_FUNC((*my_free)), LIBSSH2_REALLOC_FUNC((*my_realloc)), void *abstract);#define libssh2_session_init() libssh2_session_init_ex(NULL, NULL, NULL, NULL) LIBSSH2_API void **libssh2_session_abstract(LIBSSH2_SESSION *session); LIBSSH2_API void *libssh2_session_callback_set(LIBSSH2_SESSION *session, int cbtype, void *callback);LIBSSH2_API int libssh2_session_banner_set(LIBSSH2_SESSION *session, const char *banner);LIBSSH2_API int libssh2_banner_set(LIBSSH2_SESSION *session, const char *banner); LIBSSH2_API int libssh2_session_startup(LIBSSH2_SESSION *session, int sock);LIBSSH2_API int libssh2_session_handshake(LIBSSH2_SESSION *session, libssh2_socket_t sock);LIBSSH2_API int libssh2_session_disconnect_ex(LIBSSH2_SESSION *session, int reason, const char *description, const char *lang);#define libssh2_session_disconnect(session, description) \ libssh2_session_disconnect_ex((session), SSH_DISCONNECT_BY_APPLICATION, \ (description), "") LIBSSH2_API int libssh2_session_free(LIBSSH2_SESSION *session); LIBSSH2_API const char *libssh2_hostkey_hash(LIBSSH2_SESSION *session, int hash_type); LIBSSH2_API const char *libssh2_session_hostkey(LIBSSH2_SESSION *session, size_t *len, int *type); LIBSSH2_API int libssh2_session_method_pref(LIBSSH2_SESSION *session, int method_type, const char *prefs);LIBSSH2_API const char *libssh2_session_methods(LIBSSH2_SESSION *session, int method_type);LIBSSH2_API int libssh2_session_last_error(LIBSSH2_SESSION *session,Lines 1–500 of 1189. Load more
/* Copyright (c) 2004-2009, Sara Golemon <sarag@libssh2.org> * Copyright (c) 2009-2012 Daniel Stenberg * Copyright (c) 2010 Simon Josefsson <simon@josefsson.org> * All rights reserved. * * Redistribution and use in source and binary forms, * with or without modification, are permitted provided * that the following conditions are met: * * Redistributions of source code must retain the above * copyright notice, this list of conditions and the * following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials * provided with the distribution. * * Neither the name of the copyright holder nor the names * of any other contributors may be used to endorse or * promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. */ #ifndef LIBSSH2_H #define LIBSSH2_H 1 #define LIBSSH2_COPYRIGHT "2004-2012 The libssh2 project and its contributors." /* We use underscore instead of dash when appending DEV in dev versions just to make the BANNER define (used by src/session.c) be a valid SSH banner. Release versions have no appended strings and may of course not have dashes either. */ #define LIBSSH2_VERSION "1.4.3" /* The numeric version number is also available "in parts" by using these defines: */ #define LIBSSH2_VERSION_MAJOR 1 #define LIBSSH2_VERSION_MINOR 4 #define LIBSSH2_VERSION_PATCH 3 /* This is the numeric version of the libssh2 version number, meant for easier parsing and comparions by programs. The LIBSSH2_VERSION_NUM define will always follow this syntax: 0xXXYYZZ Where XX, YY and ZZ are the main version, release and patch numbers in hexadecimal (using 8 bits each). All three numbers are always represented using two digits. 1.2 would appear as "0x010200" while version 9.11.7 appears as "0x090b07". This 6-digit (24 bits) hexadecimal number does not show pre-release number, and it is always a greater number in a more recent release. It makes comparisons with greater than and less than work. */ #define LIBSSH2_VERSION_NUM 0x010403 /* * This is the date and time when the full source package was created. The * timestamp is not stored in the source code repo, as the timestamp is * properly set in the tarballs by the maketgz script. * * The format of the date should follow this template: * * "Mon Feb 12 11:35:33 UTC 2007" */ #define LIBSSH2_TIMESTAMP "Tue Nov 27 21:45:20 UTC 2012" #ifndef RC_INVOKED #ifdef __cplusplus extern "C" { #endif #ifdef _WIN32 # include <basetsd.h> # include <winsock2.h> #endif #include <stddef.h> #include <string.h> #include <sys/stat.h> #include <sys/types.h> /* Allow alternate API prefix from CFLAGS or calling app */ #ifndef LIBSSH2_API # ifdef LIBSSH2_WIN32 # ifdef LIBSSH2_LIBRARY # define LIBSSH2_API __declspec(dllexport) # else # define LIBSSH2_API __declspec(dllimport) # endif /* LIBSSH2_LIBRARY */ # else /* !LIBSSH2_WIN32 */ # define LIBSSH2_API # endif /* LIBSSH2_WIN32 */ #endif /* LIBSSH2_API */ #if defined(LIBSSH2_DARWIN) # include <sys/uio.h> #endif #if (defined(NETWARE) && !defined(__NOVELL_LIBC__)) # include <sys/bsdskt.h> typedef unsigned char uint8_t; typedef unsigned int uint32_t; #endif #ifdef _MSC_VER typedef unsigned char uint8_t; typedef unsigned int uint32_t; typedef unsigned __int64 libssh2_uint64_t; typedef __int64 libssh2_int64_t; #ifndef ssize_t typedef SSIZE_T ssize_t; #endif #else typedef unsigned long long libssh2_uint64_t; typedef long long libssh2_int64_t; #endif #ifdef WIN32 typedef SOCKET libssh2_socket_t; #define LIBSSH2_INVALID_SOCKET INVALID_SOCKET #else /* !WIN32 */ typedef int libssh2_socket_t; #define LIBSSH2_INVALID_SOCKET -1 #endif /* WIN32 */ /* Part of every banner, user specified or not */ #define LIBSSH2_SSH_BANNER "SSH-2.0-libssh2_" LIBSSH2_VERSION /* We *could* add a comment here if we so chose */ #define LIBSSH2_SSH_DEFAULT_BANNER LIBSSH2_SSH_BANNER #define LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF LIBSSH2_SSH_DEFAULT_BANNER "\r\n" /* Default generate and safe prime sizes for diffie-hellman-group-exchange-sha1 */ #define LIBSSH2_DH_GEX_MINGROUP 1024 #define LIBSSH2_DH_GEX_OPTGROUP 1536 #define LIBSSH2_DH_GEX_MAXGROUP 2048 /* Defaults for pty requests */ #define LIBSSH2_TERM_WIDTH 80 #define LIBSSH2_TERM_HEIGHT 24 #define LIBSSH2_TERM_WIDTH_PX 0 #define LIBSSH2_TERM_HEIGHT_PX 0 /* 1/4 second */ #define LIBSSH2_SOCKET_POLL_UDELAY 250000 /* 0.25 * 120 == 30 seconds */ #define LIBSSH2_SOCKET_POLL_MAXLOOPS 120 /* Maximum size to allow a payload to compress to, plays it safe by falling short of spec limits */ #define LIBSSH2_PACKET_MAXCOMP 32000 /* Maximum size to allow a payload to deccompress to, plays it safe by allowing more than spec requires */ #define LIBSSH2_PACKET_MAXDECOMP 40000 /* Maximum size for an inbound compressed payload, plays it safe by overshooting spec limits */ #define LIBSSH2_PACKET_MAXPAYLOAD 40000 /* Malloc callbacks */ #define LIBSSH2_ALLOC_FUNC(name) void *name(size_t count, void **abstract) #define LIBSSH2_REALLOC_FUNC(name) void *name(void *ptr, size_t count, \ void **abstract) #define LIBSSH2_FREE_FUNC(name) void name(void *ptr, void **abstract) typedef struct _LIBSSH2_USERAUTH_KBDINT_PROMPT { char* text; unsigned int length; unsigned char echo; } LIBSSH2_USERAUTH_KBDINT_PROMPT; typedef struct _LIBSSH2_USERAUTH_KBDINT_RESPONSE { char* text; unsigned int length; } LIBSSH2_USERAUTH_KBDINT_RESPONSE; /* 'publickey' authentication callback */ #define LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC(name) \ int name(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, \ const unsigned char *data, size_t data_len, void **abstract) /* 'keyboard-interactive' authentication callback */ #define LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC(name_) \ void name_(const char* name, int name_len, const char* instruction, \ int instruction_len, int num_prompts, \ const LIBSSH2_USERAUTH_KBDINT_PROMPT* prompts, \ LIBSSH2_USERAUTH_KBDINT_RESPONSE* responses, void **abstract) /* Callbacks for special SSH packets */ #define LIBSSH2_IGNORE_FUNC(name) \ void name(LIBSSH2_SESSION *session, const char *message, int message_len, \ void **abstract) #define LIBSSH2_DEBUG_FUNC(name) \ void name(LIBSSH2_SESSION *session, int always_display, const char *message, \ int message_len, const char *language, int language_len, \ void **abstract) #define LIBSSH2_DISCONNECT_FUNC(name) \ void name(LIBSSH2_SESSION *session, int reason, const char *message, \ int message_len, const char *language, int language_len, \ void **abstract) #define LIBSSH2_PASSWD_CHANGEREQ_FUNC(name) \ void name(LIBSSH2_SESSION *session, char **newpw, int *newpw_len, \ void **abstract) #define LIBSSH2_MACERROR_FUNC(name) \ int name(LIBSSH2_SESSION *session, const char *packet, int packet_len, \ void **abstract) #define LIBSSH2_X11_OPEN_FUNC(name) \ void name(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, \ const char *shost, int sport, void **abstract) #define LIBSSH2_CHANNEL_CLOSE_FUNC(name) \ void name(LIBSSH2_SESSION *session, void **session_abstract, \ LIBSSH2_CHANNEL *channel, void **channel_abstract) /* I/O callbacks */ #define LIBSSH2_RECV_FUNC(name) ssize_t name(libssh2_socket_t socket, \ void *buffer, size_t length, \ int flags, void **abstract) #define LIBSSH2_SEND_FUNC(name) ssize_t name(libssh2_socket_t socket, \ const void *buffer, size_t length,\ int flags, void **abstract) /* libssh2_session_callback_set() constants */ #define LIBSSH2_CALLBACK_IGNORE 0 #define LIBSSH2_CALLBACK_DEBUG 1 #define LIBSSH2_CALLBACK_DISCONNECT 2 #define LIBSSH2_CALLBACK_MACERROR 3 #define LIBSSH2_CALLBACK_X11 4 #define LIBSSH2_CALLBACK_SEND 5 #define LIBSSH2_CALLBACK_RECV 6 /* libssh2_session_method_pref() constants */ #define LIBSSH2_METHOD_KEX 0 #define LIBSSH2_METHOD_HOSTKEY 1 #define LIBSSH2_METHOD_CRYPT_CS 2 #define LIBSSH2_METHOD_CRYPT_SC 3 #define LIBSSH2_METHOD_MAC_CS 4 #define LIBSSH2_METHOD_MAC_SC 5 #define LIBSSH2_METHOD_COMP_CS 6 #define LIBSSH2_METHOD_COMP_SC 7 #define LIBSSH2_METHOD_LANG_CS 8 #define LIBSSH2_METHOD_LANG_SC 9 /* flags */ #define LIBSSH2_FLAG_SIGPIPE 1 #define LIBSSH2_FLAG_COMPRESS 2 typedef struct _LIBSSH2_SESSION LIBSSH2_SESSION; typedef struct _LIBSSH2_CHANNEL LIBSSH2_CHANNEL; typedef struct _LIBSSH2_LISTENER LIBSSH2_LISTENER; typedef struct _LIBSSH2_KNOWNHOSTS LIBSSH2_KNOWNHOSTS; typedef struct _LIBSSH2_AGENT LIBSSH2_AGENT; typedef struct _LIBSSH2_POLLFD { unsigned char type; /* LIBSSH2_POLLFD_* below */ union { int socket; /* File descriptors -- examined with system select() call */ LIBSSH2_CHANNEL *channel; /* Examined by checking internal state */ LIBSSH2_LISTENER *listener; /* Read polls only -- are inbound connections waiting to be accepted? */ } fd; unsigned long events; /* Requested Events */ unsigned long revents; /* Returned Events */ } LIBSSH2_POLLFD; /* Poll FD Descriptor Types */ #define LIBSSH2_POLLFD_SOCKET 1 #define LIBSSH2_POLLFD_CHANNEL 2 #define LIBSSH2_POLLFD_LISTENER 3 /* Note: Win32 Doesn't actually have a poll() implementation, so some of these values are faked with select() data */ /* Poll FD events/revents -- Match sys/poll.h where possible */ #define LIBSSH2_POLLFD_POLLIN 0x0001 /* Data available to be read or connection available -- All */ #define LIBSSH2_POLLFD_POLLPRI 0x0002 /* Priority data available to be read -- Socket only */ #define LIBSSH2_POLLFD_POLLEXT 0x0002 /* Extended data available to be read -- Channel only */ #define LIBSSH2_POLLFD_POLLOUT 0x0004 /* Can may be written -- Socket/Channel */ /* revents only */ #define LIBSSH2_POLLFD_POLLERR 0x0008 /* Error Condition -- Socket */ #define LIBSSH2_POLLFD_POLLHUP 0x0010 /* HangUp/EOF -- Socket */ #define LIBSSH2_POLLFD_SESSION_CLOSED 0x0010 /* Session Disconnect */ #define LIBSSH2_POLLFD_POLLNVAL 0x0020 /* Invalid request -- Socket Only */ #define LIBSSH2_POLLFD_POLLEX 0x0040 /* Exception Condition -- Socket/Win32 */ #define LIBSSH2_POLLFD_CHANNEL_CLOSED 0x0080 /* Channel Disconnect */ #define LIBSSH2_POLLFD_LISTENER_CLOSED 0x0080 /* Listener Disconnect */ #define HAVE_LIBSSH2_SESSION_BLOCK_DIRECTION /* Block Direction Types */ #define LIBSSH2_SESSION_BLOCK_INBOUND 0x0001 #define LIBSSH2_SESSION_BLOCK_OUTBOUND 0x0002 /* Hash Types */ #define LIBSSH2_HOSTKEY_HASH_MD5 1 #define LIBSSH2_HOSTKEY_HASH_SHA1 2 /* Hostkey Types */ #define LIBSSH2_HOSTKEY_TYPE_UNKNOWN 0 #define LIBSSH2_HOSTKEY_TYPE_RSA 1 #define LIBSSH2_HOSTKEY_TYPE_DSS 2 /* Disconnect Codes (defined by SSH protocol) */ #define SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT 1 #define SSH_DISCONNECT_PROTOCOL_ERROR 2 #define SSH_DISCONNECT_KEY_EXCHANGE_FAILED 3 #define SSH_DISCONNECT_RESERVED 4 #define SSH_DISCONNECT_MAC_ERROR 5 #define SSH_DISCONNECT_COMPRESSION_ERROR 6 #define SSH_DISCONNECT_SERVICE_NOT_AVAILABLE 7 #define SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED 8 #define SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE 9 #define SSH_DISCONNECT_CONNECTION_LOST 10 #define SSH_DISCONNECT_BY_APPLICATION 11 #define SSH_DISCONNECT_TOO_MANY_CONNECTIONS 12 #define SSH_DISCONNECT_AUTH_CANCELLED_BY_USER 13 #define SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE 14 #define SSH_DISCONNECT_ILLEGAL_USER_NAME 15 /* Error Codes (defined by libssh2) */ #define LIBSSH2_ERROR_NONE 0 /* The library once used -1 as a generic error return value on numerous places through the code, which subsequently was converted to LIBSSH2_ERROR_SOCKET_NONE uses over time. As this is a generic error code, the goal is to never ever return this code but instead make sure that a more accurate and descriptive error code is used. */ #define LIBSSH2_ERROR_SOCKET_NONE -1 #define LIBSSH2_ERROR_BANNER_RECV -2 #define LIBSSH2_ERROR_BANNER_SEND -3 #define LIBSSH2_ERROR_INVALID_MAC -4 #define LIBSSH2_ERROR_KEX_FAILURE -5 #define LIBSSH2_ERROR_ALLOC -6 #define LIBSSH2_ERROR_SOCKET_SEND -7 #define LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE -8 #define LIBSSH2_ERROR_TIMEOUT -9 #define LIBSSH2_ERROR_HOSTKEY_INIT -10 #define LIBSSH2_ERROR_HOSTKEY_SIGN -11 #define LIBSSH2_ERROR_DECRYPT -12 #define LIBSSH2_ERROR_SOCKET_DISCONNECT -13 #define LIBSSH2_ERROR_PROTO -14 #define LIBSSH2_ERROR_PASSWORD_EXPIRED -15 #define LIBSSH2_ERROR_FILE -16 #define LIBSSH2_ERROR_METHOD_NONE -17 #define LIBSSH2_ERROR_AUTHENTICATION_FAILED -18 #define LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED LIBSSH2_ERROR_AUTHENTICATION_FAILED #define LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED -19 #define LIBSSH2_ERROR_CHANNEL_OUTOFORDER -20 #define LIBSSH2_ERROR_CHANNEL_FAILURE -21 #define LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED -22 #define LIBSSH2_ERROR_CHANNEL_UNKNOWN -23 #define LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED -24 #define LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED -25 #define LIBSSH2_ERROR_CHANNEL_CLOSED -26 #define LIBSSH2_ERROR_CHANNEL_EOF_SENT -27 #define LIBSSH2_ERROR_SCP_PROTOCOL -28 #define LIBSSH2_ERROR_ZLIB -29 #define LIBSSH2_ERROR_SOCKET_TIMEOUT -30 #define LIBSSH2_ERROR_SFTP_PROTOCOL -31 #define LIBSSH2_ERROR_REQUEST_DENIED -32 #define LIBSSH2_ERROR_METHOD_NOT_SUPPORTED -33 #define LIBSSH2_ERROR_INVAL -34 #define LIBSSH2_ERROR_INVALID_POLL_TYPE -35 #define LIBSSH2_ERROR_PUBLICKEY_PROTOCOL -36 #define LIBSSH2_ERROR_EAGAIN -37 #define LIBSSH2_ERROR_BUFFER_TOO_SMALL -38 #define LIBSSH2_ERROR_BAD_USE -39 #define LIBSSH2_ERROR_COMPRESS -40 #define LIBSSH2_ERROR_OUT_OF_BOUNDARY -41 #define LIBSSH2_ERROR_AGENT_PROTOCOL -42 #define LIBSSH2_ERROR_SOCKET_RECV -43 #define LIBSSH2_ERROR_ENCRYPT -44 #define LIBSSH2_ERROR_BAD_SOCKET -45 #define LIBSSH2_ERROR_KNOWN_HOSTS -46 /* this is a define to provide the old (<= 1.2.7) name */ #define LIBSSH2_ERROR_BANNER_NONE LIBSSH2_ERROR_BANNER_RECV /* Global API */ #define LIBSSH2_INIT_NO_CRYPTO 0x0001 /* * libssh2_init() * * Initialize the libssh2 functions. This typically initialize the * crypto library. It uses a global state, and is not thread safe -- * you must make sure this function is not called concurrently. * * Flags can be: * 0: Normal initialize * LIBSSH2_INIT_NO_CRYPTO: Do not initialize the crypto library (ie. * OPENSSL_add_cipher_algoritms() for OpenSSL * * Returns 0 if succeeded, or a negative value for error. */ LIBSSH2_API int libssh2_init(int flags); /* * libssh2_exit() * * Exit the libssh2 functions and free's all memory used internal. */ LIBSSH2_API void libssh2_exit(void); /* * libssh2_free() * * Deallocate memory allocated by earlier call to libssh2 functions. */ LIBSSH2_API void libssh2_free(LIBSSH2_SESSION *session, void *ptr); /* * libssh2_session_supported_algs() * * Fills algs with a list of supported acryptographic algorithms. Returns a * non-negative number (number of supported algorithms) on success or a * negative number (an eror code) on failure. * * NOTE: on success, algs must be deallocated (by calling libssh2_free) when * not needed anymore */ LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session, int method_type, const char*** algs); /* Session API */ LIBSSH2_API LIBSSH2_SESSION * libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)), LIBSSH2_FREE_FUNC((*my_free)), LIBSSH2_REALLOC_FUNC((*my_realloc)), void *abstract); #define libssh2_session_init() libssh2_session_init_ex(NULL, NULL, NULL, NULL) LIBSSH2_API void **libssh2_session_abstract(LIBSSH2_SESSION *session); LIBSSH2_API void *libssh2_session_callback_set(LIBSSH2_SESSION *session, int cbtype, void *callback); LIBSSH2_API int libssh2_session_banner_set(LIBSSH2_SESSION *session, const char *banner); LIBSSH2_API int libssh2_banner_set(LIBSSH2_SESSION *session, const char *banner); LIBSSH2_API int libssh2_session_startup(LIBSSH2_SESSION *session, int sock); LIBSSH2_API int libssh2_session_handshake(LIBSSH2_SESSION *session, libssh2_socket_t sock); LIBSSH2_API int libssh2_session_disconnect_ex(LIBSSH2_SESSION *session, int reason, const char *description, const char *lang); #define libssh2_session_disconnect(session, description) \ libssh2_session_disconnect_ex((session), SSH_DISCONNECT_BY_APPLICATION, \ (description), "") LIBSSH2_API int libssh2_session_free(LIBSSH2_SESSION *session); LIBSSH2_API const char *libssh2_hostkey_hash(LIBSSH2_SESSION *session, int hash_type); LIBSSH2_API const char *libssh2_session_hostkey(LIBSSH2_SESSION *session, size_t *len, int *type); LIBSSH2_API int libssh2_session_method_pref(LIBSSH2_SESSION *session, int method_type, const char *prefs); LIBSSH2_API const char *libssh2_session_methods(LIBSSH2_SESSION *session, int method_type); LIBSSH2_API int libssh2_session_last_error(LIBSSH2_SESSION *session,