diff options
Diffstat (limited to 'libs/libssh2/src/session.c')
-rw-r--r-- | libs/libssh2/src/session.c | 142 |
1 files changed, 92 insertions, 50 deletions
diff --git a/libs/libssh2/src/session.c b/libs/libssh2/src/session.c index 4d9edc5c8c..9d89ade8ec 100644 --- a/libs/libssh2/src/session.c +++ b/libs/libssh2/src/session.c @@ -41,7 +41,7 @@ #include "libssh2_priv.h" -#ifdef WIN32 +#ifdef _WIN32 #include <ws2tcpip.h> /* for socklen_t */ #endif #ifdef HAVE_UNISTD_H @@ -60,7 +60,7 @@ #include "channel.h" #include "mac.h" -#if defined(WIN32) +#if defined(_WIN32) #define libssh2_usec_t long #elif defined(__APPLE__) #define libssh2_usec_t suseconds_t @@ -132,11 +132,11 @@ banner_receive(LIBSSH2_SESSION * session) if(session->api_block_mode || (ret != -EAGAIN)) /* ignore EAGAIN when non-blocking */ _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, - "Error recving %d bytes: %d", 1, (int)-ret)); + "Error recving %d bytes: %ld", 1, (long)-ret)); } else _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, - "Recved %d bytes banner", (int)ret)); + "Recved %ld bytes banner", (long)ret)); if(ret < 0) { if(ret == -EAGAIN) { @@ -253,13 +253,14 @@ banner_send(LIBSSH2_SESSION * session) LIBSSH2_SOCKET_SEND_FLAGS(session)); if(ret < 0) _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, - "Error sending %d bytes: %d", - banner_len - session->banner_TxRx_total_send, -ret)); + "Error sending %ld bytes: %ld", + (long)(banner_len - session->banner_TxRx_total_send), + (long)-ret)); else _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, - "Sent %d/%d bytes at %p+%d", ret, - banner_len - session->banner_TxRx_total_send, - banner, session->banner_TxRx_total_send)); + "Sent %ld/%ld bytes at %p+%ld", (long)ret, + (long)(banner_len - session->banner_TxRx_total_send), + (void *)banner, (long)session->banner_TxRx_total_send)); if(ret != (ssize_t)(banner_len - session->banner_TxRx_total_send)) { if(ret >= 0 || ret == -EAGAIN) { @@ -313,7 +314,7 @@ session_nonblock(libssh2_socket_t sockfd, /* operate on this */ /* BeOS */ long b = nonblock ? 1 : 0; return setsockopt(sockfd, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b)); -#elif defined(WIN32) +#elif defined(_WIN32) unsigned long flags; flags = nonblock; @@ -366,7 +367,7 @@ get_socket_nonblocking(libssh2_socket_t sockfd) return 1; } return 0; -#elif defined(WIN32) +#elif defined(_WIN32) unsigned int option_value; socklen_t option_len = sizeof(option_value); @@ -417,6 +418,7 @@ libssh2_session_banner_set(LIBSSH2_SESSION * session, const char *banner) return 0; } +#ifndef LIBSSH2_NO_DEPRECATED /* libssh2_banner_set * Set the local banner. DEPRECATED VERSION */ @@ -425,6 +427,7 @@ libssh2_banner_set(LIBSSH2_SESSION * session, const char *banner) { return libssh2_session_banner_set(session, banner); } +#endif /* * libssh2_session_init_ex @@ -466,6 +469,8 @@ libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)), session->abstract = abstract; session->api_timeout = 0; /* timeout-free API by default */ session->api_block_mode = 1; /* blocking API by default */ + session->state = LIBSSH2_STATE_INITIAL_KEX; + session->fullpacket_required_type = 0; session->packet_read_timeout = LIBSSH2_DEFAULT_READ_TIMEOUT; session->flag.quote_paths = 1; /* default behavior is to quote paths for the scp subsystem */ @@ -477,77 +482,68 @@ libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)), } /* - * libssh2_session_callback_set + * libssh2_session_callback_set2 * * Set (or reset) a callback function * Returns the prior address - * - * ALERT: this function relies on that we can typecast function pointers - * to void pointers, which isn't allowed in ISO C! */ -#ifdef _MSC_VER -#pragma warning(push) -/* nonstandard extension, function/data pointer conversion in expression */ -#pragma warning(disable:4152) -#else -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wpedantic" -#endif -LIBSSH2_API void * -libssh2_session_callback_set(LIBSSH2_SESSION * session, - int cbtype, void *callback) +LIBSSH2_API libssh2_cb_generic * +libssh2_session_callback_set2(LIBSSH2_SESSION *session, int cbtype, + libssh2_cb_generic *callback) { - void *oldcb; + libssh2_cb_generic *oldcb; switch(cbtype) { case LIBSSH2_CALLBACK_IGNORE: - oldcb = session->ssh_msg_ignore; - session->ssh_msg_ignore = callback; + oldcb = (libssh2_cb_generic *)session->ssh_msg_ignore; + session->ssh_msg_ignore = (LIBSSH2_IGNORE_FUNC((*)))callback; return oldcb; case LIBSSH2_CALLBACK_DEBUG: - oldcb = session->ssh_msg_debug; - session->ssh_msg_debug = callback; + oldcb = (libssh2_cb_generic *)session->ssh_msg_debug; + session->ssh_msg_debug = (LIBSSH2_DEBUG_FUNC((*)))callback; return oldcb; case LIBSSH2_CALLBACK_DISCONNECT: - oldcb = session->ssh_msg_disconnect; - session->ssh_msg_disconnect = callback; + oldcb = (libssh2_cb_generic *)session->ssh_msg_disconnect; + session->ssh_msg_disconnect = (LIBSSH2_DISCONNECT_FUNC((*)))callback; return oldcb; case LIBSSH2_CALLBACK_MACERROR: - oldcb = session->macerror; - session->macerror = callback; + oldcb = (libssh2_cb_generic *)session->macerror; + session->macerror = (LIBSSH2_MACERROR_FUNC((*)))callback; return oldcb; case LIBSSH2_CALLBACK_X11: - oldcb = session->x11; - session->x11 = callback; + oldcb = (libssh2_cb_generic *)session->x11; + session->x11 = (LIBSSH2_X11_OPEN_FUNC((*)))callback; return oldcb; case LIBSSH2_CALLBACK_SEND: - oldcb = session->send; - session->send = callback; + oldcb = (libssh2_cb_generic *)session->send; + session->send = (LIBSSH2_SEND_FUNC((*)))callback; return oldcb; case LIBSSH2_CALLBACK_RECV: - oldcb = session->recv; - session->recv = callback; + oldcb = (libssh2_cb_generic *)session->recv; + session->recv = (LIBSSH2_RECV_FUNC((*)))callback; return oldcb; case LIBSSH2_CALLBACK_AUTHAGENT: - oldcb = session->authagent; - session->authagent = callback; + oldcb = (libssh2_cb_generic *)session->authagent; + session->authagent = (LIBSSH2_AUTHAGENT_FUNC((*)))callback; return oldcb; case LIBSSH2_CALLBACK_AUTHAGENT_IDENTITIES: - oldcb = session->addLocalIdentities; - session->addLocalIdentities = callback; + oldcb = (libssh2_cb_generic *)session->addLocalIdentities; + session->addLocalIdentities = + (LIBSSH2_ADD_IDENTITIES_FUNC((*)))callback; return oldcb; case LIBSSH2_CALLBACK_AUTHAGENT_SIGN: - oldcb = session->agentSignCallback; - session->agentSignCallback = callback; + oldcb = (libssh2_cb_generic *)session->agentSignCallback; + session->agentSignCallback = + (LIBSSH2_AUTHAGENT_SIGN_FUNC((*)))callback; return oldcb; } _libssh2_debug((session, LIBSSH2_TRACE_TRANS, "Setting Callback %d", @@ -555,6 +551,33 @@ libssh2_session_callback_set(LIBSSH2_SESSION * session, return NULL; } + +/* + * libssh2_session_callback_set (DEPRECATED, DO NOT USE!) + * + * Set (or reset) a callback function + * Returns the prior address + * + * ALERT: this function relies on that we can typecast function pointers + * to void pointers, which isn't allowed in ISO C! + */ +#ifdef _MSC_VER +#pragma warning(push) +/* 'type cast': from data pointer to function pointer */ +#pragma warning(disable:4054) +/* 'type cast': from function pointer to data pointer */ +#pragma warning(disable:4055) +#else +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpedantic" +#endif +LIBSSH2_API void * +libssh2_session_callback_set(LIBSSH2_SESSION * session, + int cbtype, void *callback) +{ + return (void *)libssh2_session_callback_set2(session, cbtype, + (libssh2_cb_generic *)callback); +} #ifdef _MSC_VER #pragma warning(pop) #else @@ -670,6 +693,18 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session, time_t start_time) "Timed out waiting on socket"); } if(rc < 0) { + int err; +#ifdef _WIN32 + err = _libssh2_wsa2errno(); +#else + err = errno; +#endif + /* Profiling tools that use SIGPROF can cause EINTR responses. + poll() / select() do not set any descriptor states on EINTR, + but some fds may be ready, so the caller should try again */ + if(err == EINTR) + return 0; + return _libssh2_error(session, LIBSSH2_ERROR_TIMEOUT, "Error waiting on socket"); } @@ -684,7 +719,7 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock) if(session->startup_state == libssh2_NB_state_idle) { _libssh2_debug((session, LIBSSH2_TRACE_TRANS, - "session_startup for socket %d", sock)); + "session_startup for socket %ld", (long)sock)); if(LIBSSH2_INVALID_SOCKET == sock) { /* Did we forget something? */ return _libssh2_error(session, LIBSSH2_ERROR_BAD_SOCKET, @@ -830,6 +865,7 @@ libssh2_session_handshake(LIBSSH2_SESSION *session, libssh2_socket_t sock) return rc; } +#ifndef LIBSSH2_NO_DEPRECATED /* * libssh2_session_startup * @@ -846,6 +882,7 @@ libssh2_session_startup(LIBSSH2_SESSION *session, int sock) { return libssh2_session_handshake(session, (libssh2_socket_t) sock); } +#endif /* * session_free @@ -864,8 +901,8 @@ session_free(LIBSSH2_SESSION *session) if(session->free_state == libssh2_NB_state_idle) { _libssh2_debug((session, LIBSSH2_TRACE_TRANS, - "Freeing session resource", - session->remote.banner)); + "Freeing session resource %p", + (void *)session->remote.banner)); session->free_state = libssh2_NB_state_created; } @@ -1188,6 +1225,7 @@ libssh2_session_disconnect_ex(LIBSSH2_SESSION *session, int reason, const char *desc, const char *lang) { int rc; + session->state &= ~LIBSSH2_STATE_INITIAL_KEX; session->state &= ~LIBSSH2_STATE_EXCHANGING_KEYS; BLOCK_ADJUST(rc, session, session_disconnect(session, reason, desc, lang)); @@ -1773,7 +1811,11 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout) } #elif defined(HAVE_SELECT) tv.tv_sec = timeout_remaining / 1000; +#ifdef libssh2_usec_t + tv.tv_usec = (libssh2_usec_t)((timeout_remaining % 1000) * 1000); +#else tv.tv_usec = (timeout_remaining % 1000) * 1000; +#endif { struct timeval tv_begin, tv_end; |