From face4750ca78fc69f667f82e2baaa5d233c35e6c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 25 Aug 2009 00:54:47 +0200 Subject: [PATCH] changed all return EAGAIN to return the variable instead I made this change just to easier grep for "return .*EAGAIN" cases as they should be very rare or done wrongly. Already worked to find a flaw, marked with "TODO FIXME THIS IS WRONG" in channel.c. I also fixed a few cases to become more general returns now when we have more unified return codes internally. --- src/channel.c | 86 +++++++++++++++++++++++-------------------------- src/kex.c | 40 +++++++++++------------ src/packet.c | 32 +++++++++--------- src/publickey.c | 25 +++++++------- src/session.c | 64 ++++++++++++------------------------ src/sftp.c | 52 +++++++++++++++--------------- src/transport.c | 10 +++--- src/userauth.c | 24 +++++++------- 8 files changed, 153 insertions(+), 180 deletions(-) diff --git a/src/channel.c b/src/channel.c index d0ba022..d1c5906 100644 --- a/src/channel.c +++ b/src/channel.c @@ -681,7 +681,7 @@ static int channel_forward_cancel(LIBSSH2_LISTENER *listener) rc = libssh2_channel_free(queued); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } queued = next; } @@ -831,7 +831,7 @@ static int channel_setenv(LIBSSH2_CHANNEL *channel, rc = _libssh2_transport_write(session, channel->setenv_packet, channel->setenv_packet_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send channel-request packet for " @@ -856,7 +856,7 @@ static int channel_setenv(LIBSSH2_CHANNEL *channel, &channel-> setenv_packet_requirev_state); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } if (rc) { channel->setenv_state = libssh2_NB_state_idle; @@ -974,14 +974,14 @@ static int channel_request_pty(LIBSSH2_CHANNEL *channel, rc = _libssh2_transport_write(session, channel->reqPTY_packet, channel->reqPTY_packet_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { - libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + libssh2_error(session, rc, "Unable to send pty-request packet", 0); LIBSSH2_FREE(session, channel->reqPTY_packet); channel->reqPTY_packet = NULL; channel->reqPTY_state = libssh2_NB_state_idle; - return -1; + return rc; } LIBSSH2_FREE(session, channel->reqPTY_packet); channel->reqPTY_packet = NULL; @@ -996,7 +996,7 @@ static int channel_request_pty(LIBSSH2_CHANNEL *channel, 1, channel->reqPTY_local_channel, 4, &channel->reqPTY_packet_requirev_state); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { channel->reqPTY_state = libssh2_NB_state_idle; return -1; @@ -1013,7 +1013,7 @@ static int channel_request_pty(LIBSSH2_CHANNEL *channel, libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED, "Unable to complete request for channel request-pty", 0); channel->reqPTY_state = libssh2_NB_state_idle; - return -1; + return LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED; } /* @@ -1088,14 +1088,14 @@ channel_request_pty_size(LIBSSH2_CHANNEL * channel, int width, rc = _libssh2_transport_write(session, channel->reqPTY_packet, channel->reqPTY_packet_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { - libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + libssh2_error(session, rc, "Unable to send window-change packet", 0); LIBSSH2_FREE(session, channel->reqPTY_packet); channel->reqPTY_packet = NULL; channel->reqPTY_state = libssh2_NB_state_idle; - return -1; + return rc; } LIBSSH2_FREE(session, channel->reqPTY_packet); channel->reqPTY_packet = NULL; @@ -1214,15 +1214,15 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection, rc = _libssh2_transport_write(session, channel->reqX11_packet, channel->reqX11_packet_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } if (rc) { - libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + libssh2_error(session, rc, "Unable to send x11-req packet", 0); LIBSSH2_FREE(session, channel->reqX11_packet); channel->reqX11_packet = NULL; channel->reqX11_state = libssh2_NB_state_idle; - return -1; + return rc; } LIBSSH2_FREE(session, channel->reqX11_packet); channel->reqX11_packet = NULL; @@ -1237,10 +1237,11 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection, 1, channel->reqX11_local_channel, 4, &channel->reqX11_packet_requirev_state); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { + /* TODO: call libssh2_error() here! */ channel->reqX11_state = libssh2_NB_state_idle; - return -1; + return rc; } if (data[0] == SSH_MSG_CHANNEL_SUCCESS) { @@ -1339,7 +1340,7 @@ _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel, rc = _libssh2_transport_write(session, channel->process_packet, channel->process_packet_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { libssh2_error(session, rc, @@ -1362,7 +1363,7 @@ _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel, 1, channel->process_local_channel, 4, &channel->process_packet_requirev_state); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { channel->process_state = libssh2_NB_state_idle; libssh2_error(session, rc, @@ -1477,9 +1478,8 @@ _libssh2_channel_flush(LIBSSH2_CHANNEL *channel, int streamid) rc = _libssh2_channel_receive_window_adjust(channel, channel->flush_refund_bytes, 0, NULL); - if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; - } + if (rc == PACKET_EAGAIN) + return rc; } channel->flush_state = libssh2_NB_state_idle; @@ -1566,7 +1566,7 @@ _libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL * channel, rc = _libssh2_transport_write(channel->session, channel->adjust_adjust, 9); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { libssh2_error(channel->session, LIBSSH2_ERROR_SOCKET_SEND, @@ -1589,6 +1589,8 @@ _libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL * channel, /* * libssh2_channel_receive_window_adjust * + * DEPRECATED + * * Adjust the receive window for a channel by adjustment bytes. If the amount * to be adjusted is less than LIBSSH2_CHANNEL_MINADJUST and force is 0 the * adjustment amount will be queued for a later packet. @@ -1652,11 +1654,11 @@ _libssh2_channel_extended_data(LIBSSH2_CHANNEL *channel, int ignore_mode) if (channel->extData2_state == libssh2_NB_state_idle) { if (ignore_mode == LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE) { - if (_libssh2_channel_flush(channel, - LIBSSH2_CHANNEL_FLUSH_EXTENDED_DATA) == - PACKET_EAGAIN) { - return PACKET_EAGAIN; - } + int rc = + _libssh2_channel_flush(channel, + LIBSSH2_CHANNEL_FLUSH_EXTENDED_DATA); + if(PACKET_EAGAIN == rc) + return rc; } } @@ -1836,6 +1838,7 @@ static ssize_t channel_read(LIBSSH2_CHANNEL *channel, int stream_id, * completed reading the channel */ if (!libssh2_channel_eof(channel)) { + /* TODO FIXME THIS IS WRONG */ return PACKET_EAGAIN; } return 0; @@ -1856,9 +1859,9 @@ static ssize_t channel_read(LIBSSH2_CHANNEL *channel, int stream_id, this special state here */ rc = _libssh2_channel_receive_window_adjust(channel, (LIBSSH2_CHANNEL_WINDOW_DEFAULT*600), 0, NULL); - if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; - } + if (rc == PACKET_EAGAIN) + return rc; + _libssh2_debug(session, LIBSSH2_DBG_CONN, "channel_read() filled %d adjusted %d", bytes_read, buflen); @@ -2059,15 +2062,15 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id, if (rc == PACKET_EAGAIN) { _libssh2_debug(session, LIBSSH2_DBG_CONN, "libssh2_transport_write returned EAGAIN"); - return PACKET_EAGAIN; + return rc; } else if (rc) { - libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + libssh2_error(session, rc, "Unable to send channel data", 0); LIBSSH2_FREE(session, channel->write_packet); channel->write_packet = NULL; channel->write_state = libssh2_NB_state_idle; - return LIBSSH2_ERROR_SOCKET_SEND; + return rc; } /* Shrink local window size */ channel->local.window_size -= channel->write_bufwrite; @@ -2122,7 +2125,7 @@ static int channel_send_eof(LIBSSH2_CHANNEL *channel) _libssh2_htonu32(packet + 1, channel->remote.id); rc = _libssh2_transport_write(session, packet, 5); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, @@ -2199,7 +2202,7 @@ static int channel_wait_eof(LIBSSH2_CHANNEL *channel) } rc = _libssh2_transport_read(session); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc < 0) { channel->wait_eof_state = libssh2_NB_state_idle; @@ -2252,12 +2255,12 @@ channel_close(LIBSSH2_CHANNEL * channel) if (channel->close_state == libssh2_NB_state_created) { retcode = _libssh2_transport_write(session, channel->close_packet, 5); if (retcode == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return retcode; } else if (retcode) { - libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + libssh2_error(session, retcode, "Unable to send close-channel request", 0); channel->close_state = libssh2_NB_state_idle; - return -1; + return retcode; } channel->close_state = libssh2_NB_state_sent; @@ -2268,13 +2271,6 @@ channel_close(LIBSSH2_CHANNEL * channel) while (!channel->remote.close && !rc) { rc = _libssh2_transport_read(session); - if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; - } - else if (rc < 0) - rc = -1; - else - rc = 0; } } diff --git a/src/kex.c b/src/kex.c index ccaf5d8..edcf1b6 100644 --- a/src/kex.c +++ b/src/kex.c @@ -144,11 +144,11 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session, rc = _libssh2_transport_write(session, exchange_state->e_packet, exchange_state->e_packet_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { - libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + libssh2_error(session, rc, "Unable to send KEX init message", 0); - ret = -1; + ret = rc; goto clean_exit; } exchange_state->state = libssh2_NB_state_sent; @@ -166,7 +166,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session, burn_type = _libssh2_packet_burn(session, &exchange_state->burn_state); if (burn_type == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return burn_type; } else if (burn_type <= 0) { /* Failed to receive a packet */ ret = burn_type; @@ -189,7 +189,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session, &exchange_state->s_packet_len, 0, NULL, 0, &exchange_state->req_state); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } if (rc) { libssh2_error(session, LIBSSH2_ERROR_TIMEOUT, @@ -419,7 +419,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session, if (exchange_state->state == libssh2_NB_state_sent2) { rc = _libssh2_transport_write(session, &exchange_state->c, 1); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { libssh2_error(session, rc, "Unable to send NEWKEYS message", 0); ret = rc; @@ -435,7 +435,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session, &exchange_state->tmp_len, 0, NULL, 0, &exchange_state->req_state); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { libssh2_error(session, rc, "Timed out waiting for NEWKEYS", 0); ret = rc; @@ -693,7 +693,7 @@ kex_method_diffie_hellman_group1_sha1_key_exchange(LIBSSH2_SESSION *session, SSH_MSG_KEXDH_INIT, SSH_MSG_KEXDH_REPLY, NULL, 0, &key_state->exchange_state); if (ret == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return ret; } _libssh2_bn_free(key_state->p); @@ -769,7 +769,7 @@ kex_method_diffie_hellman_group14_sha1_key_exchange(LIBSSH2_SESSION *session, 256, SSH_MSG_KEXDH_INIT, SSH_MSG_KEXDH_REPLY, NULL, 0, &key_state->exchange_state); if (ret == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return ret; } key_state->state = libssh2_NB_state_idle; @@ -823,11 +823,11 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange rc = _libssh2_transport_write(session, key_state->request, key_state->request_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { - libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + libssh2_error(session, rc, "Unable to send Group Exchange Request", 0); - ret = -1; + ret = rc; goto dh_gex_clean_exit; } @@ -839,11 +839,11 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange &key_state->data, &key_state->data_len, 0, NULL, 0, &key_state->req_state); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { - libssh2_error(session, LIBSSH2_ERROR_TIMEOUT, + libssh2_error(session, rc, "Timeout waiting for GEX_GROUP reply", 0); - ret = -1; + ret = rc; goto dh_gex_clean_exit; } @@ -869,7 +869,7 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange key_state->data_len - 1, &key_state->exchange_state); if (ret == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return ret; } LIBSSH2_FREE(session, key_state->data); @@ -1123,7 +1123,7 @@ static int kexinit(LIBSSH2_SESSION * session) if (rc == PACKET_EAGAIN) { session->kexinit_data = data; session->kexinit_data_len = data_len; - return PACKET_EAGAIN; + return rc; } else if (rc) { LIBSSH2_FREE(session, data); @@ -1690,7 +1690,7 @@ libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange, retcode = kexinit(session); if (retcode == PACKET_EAGAIN) { session->state &= ~LIBSSH2_STATE_KEX_ACTIVE; - return PACKET_EAGAIN; + return retcode; } else if (retcode) { session->local.kexinit = key_state->oldlocal; session->local.kexinit_len = key_state->oldlocal_len; @@ -1711,7 +1711,7 @@ libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange, &key_state->req_state); if (retcode == PACKET_EAGAIN) { session->state &= ~LIBSSH2_STATE_KEX_ACTIVE; - return PACKET_EAGAIN; + return retcode; } else if (retcode) { if (session->local.kexinit) { @@ -1747,7 +1747,7 @@ libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange, &key_state->key_state_low); if (retcode == PACKET_EAGAIN) { session->state &= ~LIBSSH2_STATE_KEX_ACTIVE; - return PACKET_EAGAIN; + return retcode; } else if (retcode) { libssh2_error(session, LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE, "Unrecoverable error exchanging keys", 0); diff --git a/src/packet.c b/src/packet.c index be50cc4..0e50e2b 100644 --- a/src/packet.c +++ b/src/packet.c @@ -207,7 +207,7 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data, rc = _libssh2_transport_write(session, listen_state->packet, 17); if (rc == PACKET_EAGAIN) - return PACKET_EAGAIN; + return rc; else if (rc) { libssh2_error(session, rc, "Unable to send channel " @@ -248,7 +248,7 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data, rc = _libssh2_transport_write(session, listen_state->packet, packet_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { libssh2_error(session, rc, "Unable to send open failure", 0); listen_state->state = libssh2_NB_state_idle; @@ -364,7 +364,7 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data, if (x11open_state->state == libssh2_NB_state_created) { rc = _libssh2_transport_write(session, x11open_state->packet, 17); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send channel open confirmation", 0); @@ -404,7 +404,7 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data, rc = _libssh2_transport_write(session, x11open_state->packet, packet_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { libssh2_error(session, rc, "Unable to send open failure", 0); x11open_state->state = libssh2_NB_state_idle; @@ -760,7 +760,6 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, session->packAdd_channel->remote.close = 1; session->packAdd_channel->remote.eof = 1; - /* TODO: Add a callback for this */ LIBSSH2_FREE(session, data); session->packAdd_state = libssh2_NB_state_idle; @@ -778,7 +777,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, rc = packet_queue_listener(session, data, datalen, &session->packAdd_Qlstn_state); if (rc == PACKET_EAGAIN) - return PACKET_EAGAIN; + return rc; LIBSSH2_FREE(session, data); session->packAdd_state = libssh2_NB_state_idle; @@ -793,7 +792,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, rc = packet_x11_open(session, data, datalen, &session->packAdd_x11open_state); if (rc == PACKET_EAGAIN) - return PACKET_EAGAIN; + return rc; LIBSSH2_FREE(session, data); session->packAdd_state = libssh2_NB_state_idle; @@ -888,7 +887,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, */ rc = libssh2_kex_exchange(session, 1, &session->startup_key_state); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } } @@ -991,12 +990,9 @@ _libssh2_packet_require(LIBSSH2_SESSION * session, unsigned char packet_type, while (session->socket_state == LIBSSH2_SOCKET_CONNECTED) { int ret = _libssh2_transport_read(session); - if (ret == PACKET_EAGAIN) { - return PACKET_EAGAIN; - } else if (ret == 0) { - /* There is no data, return that. TODO: is this really correct? */ - return PACKET_EAGAIN; - } else if (ret < 0) { + if (ret == PACKET_EAGAIN) + return ret; + else if (ret < 0) { state->start = 0; /* an error which is not just because of blocking */ return ret; @@ -1014,6 +1010,7 @@ _libssh2_packet_require(LIBSSH2_SESSION * session, unsigned char packet_type, state->start = 0; return PACKET_TIMEOUT; } + return -1; /* no packet available yet */ } } @@ -1057,8 +1054,9 @@ _libssh2_packet_burn(LIBSSH2_SESSION * session, } while (session->socket_state == LIBSSH2_SOCKET_CONNECTED) { - if ((ret = _libssh2_transport_read(session)) == PACKET_EAGAIN) { - return PACKET_EAGAIN; + ret = _libssh2_transport_read(session); + if (ret == PACKET_EAGAIN) { + return ret; } else if (ret < 0) { *state = libssh2_NB_state_idle; return ret; @@ -1124,7 +1122,7 @@ _libssh2_packet_requirev(LIBSSH2_SESSION * session, return PACKET_TIMEOUT; } else if (ret == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return ret; } } diff --git a/src/publickey.c b/src/publickey.c index 5a6fa2a..6f087aa 100644 --- a/src/publickey.c +++ b/src/publickey.c @@ -170,7 +170,7 @@ publickey_packet_receive(LIBSSH2_PUBLICKEY * pkey, if (pkey->receive_state == libssh2_NB_state_idle) { rc = libssh2_channel_read_ex(channel, 0, (char *) buffer, 4); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc != 4) { libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, "Invalid response from publickey subsystem", 0); @@ -193,7 +193,7 @@ publickey_packet_receive(LIBSSH2_PUBLICKEY * pkey, rc = libssh2_channel_read_ex(channel, 0, (char *) pkey->receive_packet, pkey->receive_packet_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc != (int)pkey->receive_packet_len) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, "Timeout waiting for publickey subsystem response packet", @@ -265,7 +265,7 @@ publickey_response_success(LIBSSH2_PUBLICKEY * pkey) while (1) { rc = publickey_packet_receive(pkey, &data, &data_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, "Timeout waiting for response from publickey subsystem", @@ -681,7 +681,7 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY * pkey, const unsigned char *name, rc = libssh2_channel_write_ex(channel, 0, (char *) pkey->add_packet, (pkey->add_s - pkey->add_packet)); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if ((pkey->add_s - pkey->add_packet) != rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send publickey add packet", 0); @@ -697,7 +697,7 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY * pkey, const unsigned char *name, rc = publickey_response_success(pkey); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } pkey->add_state = libssh2_NB_state_idle; @@ -757,7 +757,7 @@ libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY * pkey, rc = libssh2_channel_write_ex(channel, 0, (char *) pkey->remove_packet, (pkey->remove_s - pkey->remove_packet)); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if ((pkey->remove_s - pkey->remove_packet) != rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send publickey remove packet", 0); @@ -774,7 +774,7 @@ libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY * pkey, rc = publickey_response_success(pkey); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } pkey->remove_state = libssh2_NB_state_idle; @@ -820,7 +820,7 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys, (pkey->listFetch_s - pkey->listFetch_buffer)); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if ((pkey->listFetch_s - pkey->listFetch_buffer) != rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send publickey list packet", 0); @@ -835,7 +835,7 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys, rc = publickey_packet_receive(pkey, &pkey->listFetch_data, &pkey->listFetch_data_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, "Timeout waiting for response from publickey subsystem", @@ -1040,6 +1040,7 @@ LIBSSH2_API int libssh2_publickey_shutdown(LIBSSH2_PUBLICKEY * pkey) { LIBSSH2_SESSION *session = pkey->channel->session; + int rc; /* * Make sure all memory used in the state variables are free @@ -1061,9 +1062,9 @@ libssh2_publickey_shutdown(LIBSSH2_PUBLICKEY * pkey) pkey->listFetch_data = NULL; } - if (libssh2_channel_free(pkey->channel) == PACKET_EAGAIN) { - return PACKET_EAGAIN; - } + rc = libssh2_channel_free(pkey->channel); + if (rc == PACKET_EAGAIN) + return rc; LIBSSH2_FREE(session, pkey); return 0; diff --git a/src/session.c b/src/session.c index 48ec91f..b222798 100644 --- a/src/session.c +++ b/src/session.c @@ -562,35 +562,22 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock) session->startup_state = libssh2_NB_state_created; } - /* TODO: Liveness check */ - if (session->startup_state == libssh2_NB_state_created) { rc = banner_send(session); - if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block sending banner to remote host", 0); - return LIBSSH2_ERROR_EAGAIN; - } else if (rc) { - /* Unable to send banner? */ - libssh2_error(session, LIBSSH2_ERROR_BANNER_SEND, - "Error sending banner to remote host", 0); - return LIBSSH2_ERROR_BANNER_SEND; + if (rc) { + libssh2_error(session, rc, + "Failed sending banner", 0); + return rc; } - session->startup_state = libssh2_NB_state_sent; } if (session->startup_state == libssh2_NB_state_sent) { rc = banner_receive(session); - if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block waiting for banner", 0); - return LIBSSH2_ERROR_EAGAIN; - } else if (rc) { - /* Unable to receive banner from remote */ - libssh2_error(session, LIBSSH2_ERROR_BANNER_NONE, - "Timeout waiting for banner", 0); - return LIBSSH2_ERROR_BANNER_NONE; + if (rc) { + libssh2_error(session, rc, + "Failed getting banner", 0); + return rc; } session->startup_state = libssh2_NB_state_sent1; @@ -598,14 +585,10 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock) if (session->startup_state == libssh2_NB_state_sent1) { rc = libssh2_kex_exchange(session, 0, &session->startup_key_state); - if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block exchanging encryption keys", 0); - return LIBSSH2_ERROR_EAGAIN; - } else if (rc) { - libssh2_error(session, LIBSSH2_ERROR_KEX_FAILURE, + if (rc) { + libssh2_error(session, rc, "Unable to exchange encryption keys", 0); - return LIBSSH2_ERROR_KEX_FAILURE; + return rc; } session->startup_state = libssh2_NB_state_sent2; @@ -628,15 +611,10 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock) if (session->startup_state == libssh2_NB_state_sent3) { rc = _libssh2_transport_write(session, session->startup_service, sizeof("ssh-userauth") + 5 - 1); - if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block asking for ssh-userauth service", 0); - return LIBSSH2_ERROR_EAGAIN; - } - else if (rc) { - libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + if (rc) { + libssh2_error(session, rc, "Unable to ask for ssh-userauth service", 0); - return LIBSSH2_ERROR_SOCKET_SEND; + return rc; } session->startup_state = libssh2_NB_state_sent4; @@ -647,11 +625,9 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock) &session->startup_data, &session->startup_data_len, 0, NULL, 0, &session->startup_req_state); - if (rc == PACKET_EAGAIN) { - return LIBSSH2_ERROR_EAGAIN; - } else if (rc) { - return LIBSSH2_ERROR_SOCKET_DISCONNECT; - } + if (rc) + return rc; + session->startup_service_length = _libssh2_ntohu32(session->startup_data + 1); @@ -721,7 +697,7 @@ session_free(LIBSSH2_SESSION *session) rc = libssh2_channel_free(ch); if (rc == PACKET_EAGAIN) - return PACKET_EAGAIN; + return rc; #if 0 /* Daniel's note: I'm leaving this code here right now since it looks so weird I'm stumped. Why would libssh2_channel_free() @@ -749,7 +725,7 @@ session_free(LIBSSH2_SESSION *session) while ((l = _libssh2_list_first(&session->listeners))) { rc = libssh2_channel_forward_cancel(l); if (rc == PACKET_EAGAIN) - return PACKET_EAGAIN; + return rc; } session->state = libssh2_NB_state_sent1; @@ -1016,7 +992,7 @@ session_disconnect(LIBSSH2_SESSION *session, int reason, rc = _libssh2_transport_write(session, session->disconnect_data, session->disconnect_data_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } LIBSSH2_FREE(session, session->disconnect_data); diff --git a/src/sftp.c b/src/sftp.c index 3b030c3..33ae87f 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -169,7 +169,7 @@ sftp_packet_read(LIBSSH2_SFTP *sftp) else { rc = libssh2_channel_read_ex(channel, 0, (char *) buffer, 4); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (4 != rc) { /* TODO: this is stupid since we can in fact get 1-3 bytes in a @@ -216,7 +216,7 @@ sftp_packet_read(LIBSSH2_SFTP *sftp) sftp->partial_received = packet_received; packet = NULL; - return PACKET_EAGAIN; + return bytes_received; } else if (bytes_received < 0) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, @@ -306,7 +306,7 @@ sftp_packet_require(LIBSSH2_SFTP *sftp, unsigned char packet_type, while (session->socket_state == LIBSSH2_SOCKET_CONNECTED) { ret = sftp_packet_read(sftp); if (ret == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return ret; } else if (ret <= 0) { return -1; } @@ -368,7 +368,7 @@ sftp_packet_requirev(LIBSSH2_SFTP *sftp, int num_valid_responses, return PACKET_TIMEOUT; } else if (ret == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return ret; } } } @@ -1092,7 +1092,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer, sftp->read_packet = packet; sftp->read_request_id = request_id; sftp->read_total_read = total_read; - return PACKET_EAGAIN; + return retcode; } else if (packet_len != retcode) { /* TODO: a partial write is not a critical error when in non-blocking mode! */ @@ -1115,7 +1115,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer, if (retcode == PACKET_EAGAIN) { libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block waiting for status message", 0); - return PACKET_EAGAIN; + return retcode; } else if (retcode) { libssh2_error(session, retcode, "Timeout waiting for status message", 0); @@ -1295,7 +1295,7 @@ static int sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer, (char *) sftp->readdir_packet, packet_len); if (retcode == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return retcode; } else if (packet_len != retcode) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, @@ -1317,7 +1317,7 @@ static int sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer, sftp->readdir_request_id, &data, &data_len); if (retcode == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return retcode; } else if (retcode) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, "Timeout waiting for status message", 0); @@ -1482,10 +1482,10 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer, rc = sftp_packet_require(sftp, SSH_FXP_STATUS, sftp->write_request_id, &data, &data_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { - libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, + libssh2_error(session, rc, "Timeout waiting for status message", 0); sftp->write_state = libssh2_NB_state_idle; return rc; @@ -1573,7 +1573,7 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle, rc = _libssh2_channel_write(channel, 0, (char *) sftp->fstat_packet, packet_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (packet_len != rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, (setstat ? "Unable to send FXP_FSETSTAT" @@ -1593,7 +1593,7 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle, sftp->fstat_request_id, &data, &data_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, "Timeout waiting for status message", 0); @@ -1719,7 +1719,7 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle) rc = _libssh2_channel_write(channel, 0, (char *) handle->close_packet, packet_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (packet_len != rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send FXP_CLOSE command", 0); @@ -1739,7 +1739,7 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle) handle->close_request_id, &data, &data_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, "Timeout waiting for status message", 0); @@ -1831,7 +1831,7 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename, rc = _libssh2_channel_write(channel, 0, (char *) sftp->unlink_packet, packet_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (packet_len != rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send FXP_REMOVE command", 0); @@ -1850,7 +1850,7 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename, sftp->unlink_request_id, &data, &data_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, @@ -1954,7 +1954,7 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename, rc = _libssh2_channel_write(channel, 0, (char *) sftp->rename_packet, sftp->rename_s - sftp->rename_packet); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (packet_len != rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send FXP_RENAME command", 0); @@ -1973,7 +1973,7 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename, sftp->rename_request_id, &data, &data_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, "Timeout waiting for status message", 0); @@ -2085,7 +2085,7 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path, rc = _libssh2_channel_write(channel, 0, (char *) packet, packet_len); if (rc == PACKET_EAGAIN) { sftp->mkdir_packet = packet; - return PACKET_EAGAIN; + return rc; } if (packet_len != rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, @@ -2102,7 +2102,7 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path, rc = sftp_packet_require(sftp, SSH_FXP_STATUS, sftp->mkdir_request_id, &data, &data_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, "Timeout waiting for status message", 0); @@ -2183,7 +2183,7 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path, rc = _libssh2_channel_write(channel, 0, (char *) sftp->rmdir_packet, packet_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (packet_len != rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send FXP_RMDIR command", 0); @@ -2201,7 +2201,7 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path, rc = sftp_packet_require(sftp, SSH_FXP_STATUS, sftp->rmdir_request_id, &data, &data_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, "Timeout waiting for status message", 0); @@ -2302,7 +2302,7 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path, rc = _libssh2_channel_write(channel, 0, (char *) sftp->stat_packet, packet_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (packet_len != rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send STAT/LSTAT/SETSTAT command", 0); @@ -2320,7 +2320,7 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path, rc = sftp_packet_requirev(sftp, 2, stat_responses, sftp->stat_request_id, &data, &data_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, "Timeout waiting for status message", 0); @@ -2442,7 +2442,7 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path, rc = _libssh2_channel_write(channel, 0, (char *) sftp->symlink_packet, packet_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (packet_len != rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send SYMLINK/READLINK command", 0); @@ -2461,7 +2461,7 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path, sftp->symlink_request_id, &data, &data_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, diff --git a/src/transport.c b/src/transport.c index 294293a..19efdf2 100644 --- a/src/transport.c +++ b/src/transport.c @@ -359,7 +359,7 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) /* check if this is due to EAGAIN and return the special return code if so, error out normally otherwise */ if ((nread < 0) && (errno == EAGAIN)) { - session->socket_block_directions = + session->socket_block_directions |= LIBSSH2_SESSION_BLOCK_INBOUND; return PACKET_EAGAIN; } @@ -388,6 +388,8 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) check is only done for the initial block since once we have got the start of a block we can in fact deal with fractions */ + session->socket_block_directions |= + LIBSSH2_SESSION_BLOCK_INBOUND; return PACKET_EAGAIN; } @@ -558,7 +560,7 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) session->readPack_state = libssh2_NB_state_jump1; } - return PACKET_EAGAIN; + return rc; } p->total_num = 0; /* no packet buffer available */ @@ -618,7 +620,7 @@ send_existing(LIBSSH2_SESSION * session, unsigned char *data, /* send failure! */ return PACKET_FAIL; } - session->socket_block_directions = LIBSSH2_SESSION_BLOCK_OUTBOUND; + session->socket_block_directions |= LIBSSH2_SESSION_BLOCK_OUTBOUND; return PACKET_EAGAIN; } @@ -781,7 +783,7 @@ _libssh2_transport_write(LIBSSH2_SESSION * session, unsigned char *data, if (ret != total_length) { if ((ret > 0) || ((ret == -1) && (errno == EAGAIN))) { /* the whole packet could not be sent, save the rest */ - session->socket_block_directions = LIBSSH2_SESSION_BLOCK_OUTBOUND; + session->socket_block_directions |= LIBSSH2_SESSION_BLOCK_OUTBOUND; p->odata = orgdata; p->olen = orgdata_len; p->osent = (ret == -1) ? 0 : ret; diff --git a/src/userauth.c b/src/userauth.c index c4e0c4f..b921caa 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -266,7 +266,7 @@ userauth_password(LIBSSH2_SESSION *session, const char *username, rc = _libssh2_transport_write(session, session->userauth_pswd_data, session->userauth_pswd_data_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send userauth-password request", 0); @@ -294,7 +294,7 @@ userauth_password(LIBSSH2_SESSION *session, const char *username, &session-> userauth_pswd_packet_requirev_state); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { session->userauth_pswd_state = libssh2_NB_state_idle; return -1; @@ -402,7 +402,7 @@ userauth_password(LIBSSH2_SESSION *session, const char *username, session-> userauth_pswd_data_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send userauth-password-change request", @@ -808,7 +808,7 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session, session->userauth_host_s - session->userauth_host_packet); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send userauth-hostbased request", 0); @@ -831,7 +831,7 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session, &session-> userauth_host_packet_requirev_state); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } session->userauth_host_state = libssh2_NB_state_idle; @@ -987,7 +987,7 @@ userauth_publickey_fromfile(LIBSSH2_SESSION *session, rc = _libssh2_transport_write(session, session->userauth_pblc_packet, session->userauth_pblc_packet_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send userauth-publickey request", 0); @@ -1017,7 +1017,7 @@ userauth_publickey_fromfile(LIBSSH2_SESSION *session, &session-> userauth_pblc_packet_requirev_state); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { LIBSSH2_FREE(session, session->userauth_pblc_packet); session->userauth_pblc_packet = NULL; @@ -1163,7 +1163,7 @@ userauth_publickey_fromfile(LIBSSH2_SESSION *session, session->userauth_pblc_s - session->userauth_pblc_packet); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send userauth-publickey request", 0); @@ -1186,7 +1186,7 @@ userauth_publickey_fromfile(LIBSSH2_SESSION *session, &session->userauth_pblc_data_len, 0, NULL, 0, &session->userauth_pblc_packet_requirev_state); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { session->userauth_pblc_state = libssh2_NB_state_idle; return -1; @@ -1326,7 +1326,7 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session, rc = _libssh2_transport_write(session, session->userauth_kybd_data, session->userauth_kybd_packet_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send keyboard-interactive request", 0); @@ -1350,7 +1350,7 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session, &session-> userauth_kybd_packet_requirev_state); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } else if (rc) { session->userauth_kybd_state = libssh2_NB_state_idle; return -1; @@ -1527,7 +1527,7 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session, rc = _libssh2_transport_write(session, session->userauth_kybd_data, session->userauth_kybd_packet_len); if (rc == PACKET_EAGAIN) { - return PACKET_EAGAIN; + return rc; } if (rc) { libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,