diff --git a/src/agent.c b/src/agent.c index 73fef64..f2c31e5 100644 --- a/src/agent.c +++ b/src/agent.c @@ -618,8 +618,8 @@ libssh2_agent_init(LIBSSH2_SESSION *session) agent = LIBSSH2_ALLOC(session, sizeof *agent); if (!agent) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate space for agent connection"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate space for agent connection"); return NULL; } memset(agent, 0, sizeof *agent); diff --git a/src/channel.c b/src/channel.c index 284506f..96602c1 100644 --- a/src/channel.c +++ b/src/channel.c @@ -1,5 +1,5 @@ /* Copyright (c) 2004-2007 Sara Golemon - * Copyright (c) 2008-2009 by Daniel Stenberg + * Copyright (c) 2008-2010 by Daniel Stenberg * * All rights reserved. * @@ -155,8 +155,8 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type, session->open_channel = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_CHANNEL)); if (!session->open_channel) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate space for channel data"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate space for channel data"); return NULL; } memset(session->open_channel, 0, sizeof(LIBSSH2_CHANNEL)); @@ -165,8 +165,8 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type, session->open_channel->channel_type = LIBSSH2_ALLOC(session, channel_type_len); if (!session->open_channel->channel_type) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Failed allocating memory for channel type name"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Failed allocating memory for channel type name"); LIBSSH2_FREE(session, session->open_channel); session->open_channel = NULL; return NULL; @@ -187,8 +187,8 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type, s = session->open_packet = LIBSSH2_ALLOC(session, session->open_packet_len); if (!session->open_packet) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate temporary space for packet"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate temporary space for packet"); goto channel_error; } *(s++) = SSH_MSG_CHANNEL_OPEN; @@ -219,12 +219,12 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type, rc = _libssh2_transport_write(session, session->open_packet, session->open_packet_len); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block sending channel-open request"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block sending channel-open request"); return NULL; } else if (rc) { - libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send channel-open request"); + _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send channel-open request"); goto channel_error; } @@ -239,7 +239,7 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type, channel_type_len, 4, &session->open_packet_requirev_state); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); return NULL; } else if (rc) { goto channel_error; @@ -273,8 +273,8 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type, } if (session->open_data[0] == SSH_MSG_CHANNEL_OPEN_FAILURE) { - libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE, - "Channel open failure"); + _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE, + "Channel open failure"); } } @@ -368,8 +368,8 @@ channel_direct_tcpip(LIBSSH2_SESSION * session, const char *host, s = session->direct_message = LIBSSH2_ALLOC(session, session->direct_message_len); if (!session->direct_message) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for direct-tcpip connection"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for direct-tcpip connection"); return NULL; } _libssh2_htonu32(s, session->direct_host_len); @@ -461,8 +461,8 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host, s = session->fwdLstn_packet = LIBSSH2_ALLOC(session, session->fwdLstn_packet_len); if (!session->fwdLstn_packet) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memeory for setenv packet"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memeory for setenv packet"); return NULL; } @@ -487,14 +487,14 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host, rc = _libssh2_transport_write(session, session->fwdLstn_packet, session->fwdLstn_packet_len); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block sending global-request packet for " - "forward listen request"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block sending global-request packet for " + "forward listen request"); return NULL; } else if (rc) { - libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send global-request packet for forward " - "listen request"); + _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send global-request packet for forward " + "listen request"); LIBSSH2_FREE(session, session->fwdLstn_packet); session->fwdLstn_packet = NULL; session->fwdLstn_state = libssh2_NB_state_idle; @@ -511,10 +511,10 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host, 0, NULL, 0, &session->fwdLstn_packet_requirev_state); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); return NULL; } else if (rc) { - libssh2_error(session, LIBSSH2_ERROR_PROTO, "Unknown"); + _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Unknown"); session->fwdLstn_state = libssh2_NB_state_idle; return NULL; } @@ -524,8 +524,8 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host, listener = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_LISTENER)); if (!listener) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for listener queue"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for listener queue"); LIBSSH2_FREE(session, data); session->fwdLstn_state = libssh2_NB_state_idle; return NULL; @@ -535,8 +535,8 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host, listener->host = LIBSSH2_ALLOC(session, session->fwdLstn_host_len + 1); if (!listener->host) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for listener queue"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for listener queue"); LIBSSH2_FREE(session, listener); LIBSSH2_FREE(session, data); session->fwdLstn_state = libssh2_NB_state_idle; @@ -571,8 +571,8 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host, if (data[0] == SSH_MSG_REQUEST_FAILURE) { LIBSSH2_FREE(session, data); - libssh2_error(session, LIBSSH2_ERROR_REQUEST_DENIED, - "Unable to complete request for forward-listen"); + _libssh2_error(session, LIBSSH2_ERROR_REQUEST_DENIED, + "Unable to complete request for forward-listen"); session->fwdLstn_state = libssh2_NB_state_idle; return NULL; } @@ -626,8 +626,8 @@ static int channel_forward_cancel(LIBSSH2_LISTENER *listener) s = packet = LIBSSH2_ALLOC(session, packet_len); if (!packet) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memeory for setenv packet"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memeory for setenv packet"); return LIBSSH2_ERROR_ALLOC; } @@ -657,9 +657,9 @@ static int channel_forward_cancel(LIBSSH2_LISTENER *listener) return rc; } else if (rc) { - libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send global-request packet for forward " - "listen request"); + _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send global-request packet for forward " + "listen request"); LIBSSH2_FREE(session, packet); listener->chanFwdCncl_state = libssh2_NB_state_idle; return LIBSSH2_ERROR_SOCKET_SEND; @@ -736,12 +736,12 @@ channel_forward_accept(LIBSSH2_LISTENER *listener) } if (rc == PACKET_EAGAIN) { - libssh2_error(listener->session, LIBSSH2_ERROR_EAGAIN, - "Would block waiting for packet"); + _libssh2_error(listener->session, LIBSSH2_ERROR_EAGAIN, + "Would block waiting for packet"); } else - libssh2_error(listener->session, LIBSSH2_ERROR_CHANNEL_UNKNOWN, - "Channel not found"); + _libssh2_error(listener->session, LIBSSH2_ERROR_CHANNEL_UNKNOWN, + "Channel not found"); return NULL; } @@ -793,9 +793,9 @@ static int channel_setenv(LIBSSH2_CHANNEL *channel, s = channel->setenv_packet = LIBSSH2_ALLOC(session, channel->setenv_packet_len); if (!channel->setenv_packet) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memeory " - "for setenv packet"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memeory " + "for setenv packet"); } *(s++) = SSH_MSG_CHANNEL_REQUEST; @@ -830,9 +830,9 @@ static int channel_setenv(LIBSSH2_CHANNEL *channel, LIBSSH2_FREE(session, channel->setenv_packet); channel->setenv_packet = NULL; channel->setenv_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send channel-request packet for " - "setenv request"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send channel-request packet for " + "setenv request"); } LIBSSH2_FREE(session, channel->setenv_packet); channel->setenv_packet = NULL; @@ -865,8 +865,8 @@ static int channel_setenv(LIBSSH2_CHANNEL *channel, } channel->setenv_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED, - "Unable to complete request for channel-setenv"); + return _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED, + "Unable to complete request for channel-setenv"); } /* @@ -920,8 +920,8 @@ static int channel_request_pty(LIBSSH2_CHANNEL *channel, s = channel->reqPTY_packet = LIBSSH2_ALLOC(session, channel->reqPTY_packet_len); if (!channel->reqPTY_packet) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for pty-request"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for pty-request"); } *(s++) = SSH_MSG_CHANNEL_REQUEST; @@ -969,8 +969,8 @@ static int channel_request_pty(LIBSSH2_CHANNEL *channel, LIBSSH2_FREE(session, channel->reqPTY_packet); channel->reqPTY_packet = NULL; channel->reqPTY_state = libssh2_NB_state_idle; - return libssh2_error(session, rc, - "Unable to send pty-request packet"); + return _libssh2_error(session, rc, + "Unable to send pty-request packet"); } LIBSSH2_FREE(session, channel->reqPTY_packet); channel->reqPTY_packet = NULL; @@ -1000,8 +1000,8 @@ static int channel_request_pty(LIBSSH2_CHANNEL *channel, LIBSSH2_FREE(session, data); channel->reqPTY_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED, - "Unable to complete request for channel request-pty"); + return _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED, + "Unable to complete request for channel request-pty"); } /* @@ -1046,8 +1046,8 @@ channel_request_pty_size(LIBSSH2_CHANNEL * channel, int width, LIBSSH2_ALLOC(session, channel->reqPTY_packet_len); if (!channel->reqPTY_packet) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for pty-request"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for pty-request"); } *(s++) = SSH_MSG_CHANNEL_REQUEST; @@ -1080,8 +1080,8 @@ channel_request_pty_size(LIBSSH2_CHANNEL * channel, int width, LIBSSH2_FREE(session, channel->reqPTY_packet); channel->reqPTY_packet = NULL; channel->reqPTY_state = libssh2_NB_state_idle; - return libssh2_error(session, rc, - "Unable to send window-change packet"); + return _libssh2_error(session, rc, + "Unable to send window-change packet"); } LIBSSH2_FREE(session, channel->reqPTY_packet); channel->reqPTY_packet = NULL; @@ -1150,8 +1150,8 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection, s = channel->reqX11_packet = LIBSSH2_ALLOC(session, channel->reqX11_packet_len); if (!channel->reqX11_packet) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for pty-request"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for pty-request"); } *(s++) = SSH_MSG_CHANNEL_REQUEST; @@ -1205,8 +1205,8 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection, LIBSSH2_FREE(session, channel->reqX11_packet); channel->reqX11_packet = NULL; channel->reqX11_state = libssh2_NB_state_idle; - return libssh2_error(session, rc, - "Unable to send x11-req packet"); + return _libssh2_error(session, rc, + "Unable to send x11-req packet"); } LIBSSH2_FREE(session, channel->reqX11_packet); channel->reqX11_packet = NULL; @@ -1224,8 +1224,8 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection, return rc; } else if (rc) { channel->reqX11_state = libssh2_NB_state_idle; - return libssh2_error(session, rc, - "waiting for x11-req response packet"); + return _libssh2_error(session, rc, + "waiting for x11-req response packet"); } if (data[0] == SSH_MSG_CHANNEL_SUCCESS) { @@ -1236,8 +1236,8 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection, } LIBSSH2_FREE(session, data); - return libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED, - "Unable to complete request for channel x11-req"); + return _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED, + "Unable to complete request for channel x11-req"); } /* @@ -1293,9 +1293,9 @@ _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel, s = channel->process_packet = LIBSSH2_ALLOC(session, channel->process_packet_len); if (!channel->process_packet) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory " - "for channel-process request"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory " + "for channel-process request"); } *(s++) = SSH_MSG_CHANNEL_REQUEST; @@ -1328,8 +1328,8 @@ _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel, LIBSSH2_FREE(session, channel->process_packet); channel->process_packet = NULL; channel->process_state = libssh2_NB_state_idle; - return libssh2_error(session, rc, - "Unable to send channel request"); + return _libssh2_error(session, rc, + "Unable to send channel request"); } LIBSSH2_FREE(session, channel->process_packet); channel->process_packet = NULL; @@ -1347,8 +1347,8 @@ _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel, return rc; } else if (rc) { channel->process_state = libssh2_NB_state_idle; - return libssh2_error(session, rc, - "Failed waiting for channel success"); + return _libssh2_error(session, rc, + "Failed waiting for channel success"); } if (data[0] == SSH_MSG_CHANNEL_SUCCESS) { @@ -1360,9 +1360,9 @@ _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel, LIBSSH2_FREE(session, data); channel->process_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED, - "Unable to complete request for " - "channel-process-startup"); + return _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED, + "Unable to complete request for " + "channel-process-startup"); } /* @@ -1550,9 +1550,9 @@ _libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL * channel, } else if (rc) { channel->adjust_queue = adjustment; - return libssh2_error(channel->session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send transfer-window adjustment " - "packet, deferring"); + return _libssh2_error(channel->session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send transfer-window adjustment " + "packet, deferring"); } else { channel->remote.window_size += adjustment; @@ -1715,7 +1715,7 @@ ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id, rc = _libssh2_transport_read(session); if ((rc < 0) && (rc != PACKET_EAGAIN)) - return libssh2_error(session, rc, "transport read"); + return _libssh2_error(session, rc, "transport read"); /* * =============================== NOTE =============================== @@ -1949,14 +1949,14 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id, stream_id); if (channel->local.close) { - return libssh2_error(session, LIBSSH2_ERROR_CHANNEL_CLOSED, - "We've already closed this channel"); + return _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_CLOSED, + "We've already closed this channel"); } if (channel->local.eof) { - return libssh2_error(session, LIBSSH2_ERROR_CHANNEL_EOF_SENT, - "EOF has already been received, " - "data might be ignored"); + return _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_EOF_SENT, + "EOF has already been received, " + "data might be ignored"); } /* [13] 9 = packet_type(1) + channelno(4) [ + streamid(4) ] + @@ -1965,9 +1965,9 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id, channel->write_packet = LIBSSH2_ALLOC(session, channel->write_packet_len); if (!channel->write_packet) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocte space " - "for data transmission packet"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocte space " + "for data transmission packet"); } channel->write_state = libssh2_NB_state_allocated; @@ -2046,14 +2046,14 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id, _libssh2_transport_drain(session); goto _channel_write_done; } - return libssh2_error(session, rc, - "Unable to send channel data"); + return _libssh2_error(session, rc, + "Unable to send channel data"); } else if (rc) { LIBSSH2_FREE(session, channel->write_packet); channel->write_packet = NULL; channel->write_state = libssh2_NB_state_idle; - return libssh2_error(session, rc, + return _libssh2_error(session, rc, "Unable to send channel data"); } /* Shrink local window size */ @@ -2114,8 +2114,8 @@ static int channel_send_eof(LIBSSH2_CHANNEL *channel) return rc; } else if (rc) { - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send EOF on channel"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send EOF on channel"); } channel->local.eof = 1; @@ -2250,8 +2250,8 @@ channel_close(LIBSSH2_CHANNEL * channel) return retcode; } else if (retcode) { channel->close_state = libssh2_NB_state_idle; - return libssh2_error(session, retcode, - "Unable to send close-channel request"); + return _libssh2_error(session, retcode, + "Unable to send close-channel request"); } channel->close_state = libssh2_NB_state_sent; @@ -2307,9 +2307,9 @@ static int channel_wait_closed(LIBSSH2_CHANNEL *channel) int rc; if (!libssh2_channel_eof(channel)) { - return libssh2_error(session, LIBSSH2_ERROR_INVAL, - "libssh2_channel_wait_closed() invoked when " - "channel is not in EOF state"); + return _libssh2_error(session, LIBSSH2_ERROR_INVAL, + "libssh2_channel_wait_closed() invoked when " + "channel is not in EOF state"); } if (channel->wait_closed_state == libssh2_NB_state_idle) { diff --git a/src/comp.c b/src/comp.c index 85edd5b..c323fb2 100644 --- a/src/comp.c +++ b/src/comp.c @@ -43,8 +43,8 @@ #include "comp.h" /* ******** - * none * - ******** */ + * none * + ******** */ /* * comp_method_none_comp @@ -84,8 +84,8 @@ static const LIBSSH2_COMP_METHOD comp_method_none = { #ifdef LIBSSH2_HAVE_ZLIB /* ******** - * zlib * - ******** */ + * zlib * + ******** */ /* Memory management wrappers * Yes, I realize we're doing a callback to a callback, @@ -122,9 +122,9 @@ comp_method_zlib_init(LIBSSH2_SESSION * session, int compress, strm = LIBSSH2_ALLOC(session, sizeof(z_stream)); if (!strm) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "zlib compression/decompression"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for " + "zlib compression/decompression"); } memset(strm, 0, sizeof(z_stream)); @@ -185,9 +185,9 @@ comp_method_zlib_comp(LIBSSH2_SESSION * session, out = (char *) strm->next_out; strm->avail_out = out_maxlen; if (!strm->next_out) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate compression/decompression " - "buffer"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate compression/decompression " + "buffer"); } while (strm->avail_in) { int status; @@ -199,8 +199,8 @@ comp_method_zlib_comp(LIBSSH2_SESSION * session, } if (status != Z_OK) { LIBSSH2_FREE(session, out); - return libssh2_error(session, LIBSSH2_ERROR_ZLIB, - "compress/decompression failure"); + return _libssh2_error(session, LIBSSH2_ERROR_ZLIB, + "compress/decompression failure"); } if (strm->avail_in) { unsigned long out_ofs = out_maxlen - strm->avail_out; @@ -211,16 +211,16 @@ comp_method_zlib_comp(LIBSSH2_SESSION * session, if ((out_maxlen > (int) payload_limit) && !compress && limiter++) { LIBSSH2_FREE(session, out); - return libssh2_error(session, LIBSSH2_ERROR_ZLIB, - "Excessive growth in decompression phase"); + return _libssh2_error(session, LIBSSH2_ERROR_ZLIB, + "Excessive growth in decompression phase"); } newout = LIBSSH2_REALLOC(session, out, out_maxlen); if (!newout) { LIBSSH2_FREE(session, out); - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to expand compress/" - "decompression buffer"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to expand compress/" + "decompression buffer"); } out = newout; strm->next_out = (unsigned char *) out + out_ofs; @@ -237,9 +237,9 @@ comp_method_zlib_comp(LIBSSH2_SESSION * session, if (out_maxlen >= (int) payload_limit) { LIBSSH2_FREE(session, out); - return libssh2_error(session, LIBSSH2_ERROR_ZLIB, - "Excessive growth in decompression " - "phase"); + return _libssh2_error(session, LIBSSH2_ERROR_ZLIB, + "Excessive growth in decompression " + "phase"); } if (grow_size > (int) (payload_limit - out_maxlen)) { @@ -252,9 +252,9 @@ comp_method_zlib_comp(LIBSSH2_SESSION * session, newout = LIBSSH2_REALLOC(session, out, out_maxlen); if (!newout) { LIBSSH2_FREE(session, out); - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to expand final compress/" - "decompress buffer"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to expand final compress/" + "decompress buffer"); } out = newout; strm->next_out = (unsigned char *) out + out_maxlen - @@ -267,8 +267,8 @@ comp_method_zlib_comp(LIBSSH2_SESSION * session, } if (status != Z_OK) { LIBSSH2_FREE(session, out); - return libssh2_error(session, LIBSSH2_ERROR_ZLIB, - "compress/decompression failure"); + return _libssh2_error(session, LIBSSH2_ERROR_ZLIB, + "compress/decompression failure"); } } } @@ -316,8 +316,8 @@ static const LIBSSH2_COMP_METHOD comp_method_zlib = { #endif /* LIBSSH2_HAVE_ZLIB */ /* *********************** - * Compression Methods * - *********************** */ + * Compression Methods * + *********************** */ static const LIBSSH2_COMP_METHOD *comp_methods[] = { &comp_method_none, diff --git a/src/hostkey.c b/src/hostkey.c index da855d6..83b73f8 100644 --- a/src/hostkey.c +++ b/src/hostkey.c @@ -46,8 +46,8 @@ #if LIBSSH2_RSA /* *********** - * ssh-rsa * - *********** */ + * ssh-rsa * + *********** */ static int hostkey_method_ssh_rsa_dtor(LIBSSH2_SESSION * session, void **abstract); @@ -218,8 +218,8 @@ static const LIBSSH2_HOSTKEY_METHOD hostkey_method_ssh_rsa = { #if LIBSSH2_DSA /* *********** - * ssh-dss * - *********** */ + * ssh-dss * + *********** */ static int hostkey_method_ssh_dss_dtor(LIBSSH2_SESSION * session, void **abstract); @@ -324,8 +324,8 @@ hostkey_method_ssh_dss_sig_verify(LIBSSH2_SESSION * session, sig += 15; sig_len -= 15; if (sig_len != 40) { - return libssh2_error(session, LIBSSH2_ERROR_PROTO, - "Invalid DSS signature length"); + return _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "Invalid DSS signature length"); } return _libssh2_dsa_sha1_verify(dsactx, sig, m, m_len); } diff --git a/src/keepalive.c b/src/keepalive.c index 1ae479b..8cdf326 100644 --- a/src/keepalive.c +++ b/src/keepalive.c @@ -80,8 +80,8 @@ libssh2_keepalive_send (LIBSSH2_SESSION *session, /* Silently ignore PACKET_EAGAIN here: if the write buffer is already full, sending another keepalive is not useful. */ if (rc && rc != PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send keepalive message"); + _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send keepalive message"); return rc; } diff --git a/src/kex.c b/src/kex.c index 0a5de42..5f00d36 100644 --- a/src/kex.c +++ b/src/kex.c @@ -44,30 +44,30 @@ /* TODO: Switch this to an inline and handle alloc() failures */ /* Helper macro called from kex_method_diffie_hellman_group1_sha1_key_exchange */ #define LIBSSH2_KEX_METHOD_DIFFIE_HELLMAN_SHA1_HASH(value, reqlen, version) \ -{ \ - libssh2_sha1_ctx hash; \ - unsigned long len = 0; \ - if (!(value)) { \ - value = LIBSSH2_ALLOC(session, reqlen + SHA_DIGEST_LENGTH); \ - } \ - if (value) \ - while (len < (unsigned long)reqlen) { \ - libssh2_sha1_init(&hash); \ - libssh2_sha1_update(hash, exchange_state->k_value, \ - exchange_state->k_value_len); \ - libssh2_sha1_update(hash, exchange_state->h_sig_comp, \ - SHA_DIGEST_LENGTH); \ - if (len > 0) { \ - libssh2_sha1_update(hash, value, len); \ - } else { \ - libssh2_sha1_update(hash, (version), 1); \ - libssh2_sha1_update(hash, session->session_id, \ - session->session_id_len); \ - } \ - libssh2_sha1_final(hash, (value) + len); \ - len += SHA_DIGEST_LENGTH; \ - } \ -} + { \ + libssh2_sha1_ctx hash; \ + unsigned long len = 0; \ + if (!(value)) { \ + value = LIBSSH2_ALLOC(session, reqlen + SHA_DIGEST_LENGTH); \ + } \ + if (value) \ + while (len < (unsigned long)reqlen) { \ + libssh2_sha1_init(&hash); \ + libssh2_sha1_update(hash, exchange_state->k_value, \ + exchange_state->k_value_len); \ + libssh2_sha1_update(hash, exchange_state->h_sig_comp, \ + SHA_DIGEST_LENGTH); \ + if (len > 0) { \ + libssh2_sha1_update(hash, value, len); \ + } else { \ + libssh2_sha1_update(hash, (version), 1); \ + libssh2_sha1_update(hash, session->session_id, \ + session->session_id_len); \ + } \ + libssh2_sha1_final(hash, (value) + len); \ + len += SHA_DIGEST_LENGTH; \ + } \ + } /* * diffie_hellman_sha1 @@ -118,13 +118,13 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session, exchange_state->e_packet = LIBSSH2_ALLOC(session, exchange_state->e_packet_len); if (!exchange_state->e_packet) { - ret = libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Out of memory error"); + ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Out of memory error"); goto clean_exit; } exchange_state->e_packet[0] = packet_type_init; _libssh2_htonu32(exchange_state->e_packet + 1, - exchange_state->e_packet_len - 5); + exchange_state->e_packet_len - 5); if (_libssh2_bn_bits(exchange_state->e) % 8) { _libssh2_bn_to_bin(exchange_state->e, exchange_state->e_packet + 5); @@ -145,8 +145,8 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session, if (rc == PACKET_EAGAIN) { return rc; } else if (rc) { - ret = libssh2_error(session, rc, - "Unable to send KEX init message"); + ret = _libssh2_error(session, rc, + "Unable to send KEX init message"); goto clean_exit; } exchange_state->state = libssh2_NB_state_sent; @@ -190,8 +190,8 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session, return rc; } if (rc) { - ret = libssh2_error(session, LIBSSH2_ERROR_TIMEOUT, - "Timed out waiting for KEX reply"); + ret = _libssh2_error(session, LIBSSH2_ERROR_TIMEOUT, + "Timed out waiting for KEX reply"); goto clean_exit; } @@ -203,9 +203,9 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session, session->server_hostkey = LIBSSH2_ALLOC(session, session->server_hostkey_len); if (!session->server_hostkey) { - ret = libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for a copy " - "of the host key"); + ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for a copy " + "of the host key"); goto clean_exit; } memcpy(session->server_hostkey, exchange_state->s, @@ -260,8 +260,8 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session, if (session->hostkey->init(session, session->server_hostkey, session->server_hostkey_len, &session->server_hostkey_abstract)) { - ret = libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_INIT, - "Unable to initialize hostkey importer"); + ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_INIT, + "Unable to initialize hostkey importer"); goto clean_exit; } @@ -287,12 +287,12 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session, exchange_state->k_value = LIBSSH2_ALLOC(session, exchange_state->k_value_len); if (!exchange_state->k_value) { - ret = libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate buffer for K"); + ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate buffer for K"); goto clean_exit; } _libssh2_htonu32(exchange_state->k_value, - exchange_state->k_value_len - 4); + exchange_state->k_value_len - 4); if (_libssh2_bn_bits(exchange_state->k) % 8) { _libssh2_bn_to_bin(exchange_state->k, exchange_state->k_value + 4); } else { @@ -303,7 +303,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session, libssh2_sha1_init(&exchange_state->exchange_hash); if (session->local.banner) { _libssh2_htonu32(exchange_state->h_sig_comp, - strlen((char *) session->local.banner) - 2); + strlen((char *) session->local.banner) - 2); libssh2_sha1_update(exchange_state->exchange_hash, exchange_state->h_sig_comp, 4); libssh2_sha1_update(exchange_state->exchange_hash, @@ -311,7 +311,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session, strlen((char *) session->local.banner) - 2); } else { _libssh2_htonu32(exchange_state->h_sig_comp, - sizeof(LIBSSH2_SSH_DEFAULT_BANNER) - 1); + sizeof(LIBSSH2_SSH_DEFAULT_BANNER) - 1); libssh2_sha1_update(exchange_state->exchange_hash, exchange_state->h_sig_comp, 4); libssh2_sha1_update(exchange_state->exchange_hash, @@ -320,7 +320,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session, } _libssh2_htonu32(exchange_state->h_sig_comp, - strlen((char *) session->remote.banner)); + strlen((char *) session->remote.banner)); libssh2_sha1_update(exchange_state->exchange_hash, exchange_state->h_sig_comp, 4); libssh2_sha1_update(exchange_state->exchange_hash, @@ -328,7 +328,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session, strlen((char *) session->remote.banner)); _libssh2_htonu32(exchange_state->h_sig_comp, - session->local.kexinit_len); + session->local.kexinit_len); libssh2_sha1_update(exchange_state->exchange_hash, exchange_state->h_sig_comp, 4); libssh2_sha1_update(exchange_state->exchange_hash, @@ -336,7 +336,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session, session->local.kexinit_len); _libssh2_htonu32(exchange_state->h_sig_comp, - session->remote.kexinit_len); + session->remote.kexinit_len); libssh2_sha1_update(exchange_state->exchange_hash, exchange_state->h_sig_comp, 4); libssh2_sha1_update(exchange_state->exchange_hash, @@ -344,7 +344,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session, session->remote.kexinit_len); _libssh2_htonu32(exchange_state->h_sig_comp, - session->server_hostkey_len); + session->server_hostkey_len); libssh2_sha1_update(exchange_state->exchange_hash, exchange_state->h_sig_comp, 4); libssh2_sha1_update(exchange_state->exchange_hash, @@ -355,16 +355,16 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session, /* diffie-hellman-group-exchange hashes additional fields */ #ifdef LIBSSH2_DH_GEX_NEW _libssh2_htonu32(exchange_state->h_sig_comp, - LIBSSH2_DH_GEX_MINGROUP); + LIBSSH2_DH_GEX_MINGROUP); _libssh2_htonu32(exchange_state->h_sig_comp + 4, - LIBSSH2_DH_GEX_OPTGROUP); + LIBSSH2_DH_GEX_OPTGROUP); _libssh2_htonu32(exchange_state->h_sig_comp + 8, - LIBSSH2_DH_GEX_MAXGROUP); + LIBSSH2_DH_GEX_MAXGROUP); libssh2_sha1_update(exchange_state->exchange_hash, exchange_state->h_sig_comp, 12); #else _libssh2_htonu32(exchange_state->h_sig_comp, - LIBSSH2_DH_GEX_OPTGROUP); + LIBSSH2_DH_GEX_OPTGROUP); libssh2_sha1_update(exchange_state->exchange_hash, exchange_state->h_sig_comp, 4); #endif @@ -380,7 +380,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session, exchange_state->e_packet_len - 1); _libssh2_htonu32(exchange_state->h_sig_comp, - exchange_state->f_value_len); + exchange_state->f_value_len); libssh2_sha1_update(exchange_state->exchange_hash, exchange_state->h_sig_comp, 4); libssh2_sha1_update(exchange_state->exchange_hash, @@ -398,8 +398,8 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session, sig_verify(session, exchange_state->h_sig, exchange_state->h_sig_len, exchange_state->h_sig_comp, 20, &session->server_hostkey_abstract)) { - ret = libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_SIGN, - "Unable to verify hostkey signature"); + ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_SIGN, + "Unable to verify hostkey signature"); goto clean_exit; } @@ -414,7 +414,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session, if (rc == PACKET_EAGAIN) { return rc; } else if (rc) { - ret = libssh2_error(session, rc, "Unable to send NEWKEYS message"); + ret = _libssh2_error(session, rc, "Unable to send NEWKEYS message"); goto clean_exit; } @@ -429,7 +429,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session, if (rc == PACKET_EAGAIN) { return rc; } else if (rc) { - ret = libssh2_error(session, rc, "Timed out waiting for NEWKEYS"); + ret = _libssh2_error(session, rc, "Timed out waiting for NEWKEYS"); goto clean_exit; } /* The first key exchange has been performed, @@ -444,8 +444,8 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session, if (!session->session_id) { session->session_id = LIBSSH2_ALLOC(session, SHA_DIGEST_LENGTH); if (!session->session_id) { - ret = libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate buffer for SHA digest"); + ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate buffer for SHA digest"); goto clean_exit; } memcpy(session->session_id, exchange_state->h_sig_comp, @@ -811,12 +811,12 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange if (key_state->state == libssh2_NB_state_created) { rc = _libssh2_transport_write(session, key_state->request, - key_state->request_len); + key_state->request_len); if (rc == PACKET_EAGAIN) { return rc; } else if (rc) { - ret = libssh2_error(session, rc, - "Unable to send Group Exchange Request"); + ret = _libssh2_error(session, rc, + "Unable to send Group Exchange Request"); goto dh_gex_clean_exit; } @@ -830,8 +830,8 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange if (rc == PACKET_EAGAIN) { return rc; } else if (rc) { - ret = libssh2_error(session, rc, - "Timeout waiting for GEX_GROUP reply"); + ret = _libssh2_error(session, rc, + "Timeout waiting for GEX_GROUP reply"); goto dh_gex_clean_exit; } @@ -891,7 +891,7 @@ static const LIBSSH2_KEX_METHOD kex_method_diffie_helman_group14_sha1 = { }; static const LIBSSH2_KEX_METHOD - kex_method_diffie_helman_group_exchange_sha1 = { +kex_method_diffie_helman_group_exchange_sha1 = { "diffie-hellman-group-exchange-sha1", kex_method_diffie_hellman_group_exchange_sha1_key_exchange, LIBSSH2_KEX_METHOD_FLAG_REQ_SIGN_HOSTKEY, @@ -960,13 +960,13 @@ kex_method_list(unsigned char *buf, size_t list_strlen, -#define LIBSSH2_METHOD_PREFS_LEN(prefvar, defaultvar) \ - ((prefvar) ? strlen(prefvar) : \ +#define LIBSSH2_METHOD_PREFS_LEN(prefvar, defaultvar) \ + ((prefvar) ? strlen(prefvar) : \ kex_method_strlen((LIBSSH2_COMMON_METHOD**)(defaultvar))) #define LIBSSH2_METHOD_PREFS_STR(buf, prefvarlen, prefvar, defaultvar) \ if (prefvar) { \ - _libssh2_htonu32((buf), (prefvarlen)); \ + _libssh2_htonu32((buf), (prefvarlen)); \ buf += 4; \ memcpy((buf), (prefvar), (prefvarlen)); \ buf += (prefvarlen); \ @@ -1026,8 +1026,8 @@ static int kexinit(LIBSSH2_SESSION * session) s = data = LIBSSH2_ALLOC(session, data_len); if (!data) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory"); } *(s++) = SSH_MSG_KEXINIT; @@ -1115,8 +1115,8 @@ static int kexinit(LIBSSH2_SESSION * session) else if (rc) { LIBSSH2_FREE(session, data); session->kexinit_state = libssh2_NB_state_idle; - return libssh2_error(session, rc, - "Unable to send KEXINIT packet to remote host"); + return _libssh2_error(session, rc, + "Unable to send KEXINIT packet to remote host"); } @@ -1176,7 +1176,7 @@ kex_agree_instr(unsigned char *haystack, unsigned long haystack_len, */ static const LIBSSH2_COMMON_METHOD * kex_get_method_by_name(const char *name, size_t name_len, - const LIBSSH2_COMMON_METHOD ** methodlist) + const LIBSSH2_COMMON_METHOD ** methodlist) { while (*methodlist) { if ((strlen((*methodlist)->name) == name_len) && @@ -1634,7 +1634,7 @@ static int kex_agree_methods(LIBSSH2_SESSION * session, unsigned char *data, * Exchange keys * Returns 0 on success, non-zero on failure * - * Returns some errors without libssh2_error() + * Returns some errors without _libssh2_error() */ int libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange, @@ -1736,8 +1736,8 @@ libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange, session->state &= ~LIBSSH2_STATE_KEX_ACTIVE; return retcode; } else if (retcode) { - rc = libssh2_error(session, LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE, - "Unrecoverable error exchanging keys"); + rc = _libssh2_error(session, LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE, + "Unrecoverable error exchanging keys"); } } } @@ -1825,14 +1825,14 @@ libssh2_session_method_pref(LIBSSH2_SESSION * session, int method_type, break; default: - return libssh2_error(session, LIBSSH2_ERROR_INVAL, - "Invalid parameter specified for method_type"); + return _libssh2_error(session, LIBSSH2_ERROR_INVAL, + "Invalid parameter specified for method_type"); } s = newprefs = LIBSSH2_ALLOC(session, prefs_len + 1); if (!newprefs) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Error allocated space for method preferences"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Error allocated space for method preferences"); } memcpy(s, prefs, prefs_len + 1); @@ -1858,9 +1858,9 @@ libssh2_session_method_pref(LIBSSH2_SESSION * session, int method_type, if (strlen(newprefs) == 0) { LIBSSH2_FREE(session, newprefs); - return libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, - "The requested method(s) are not currently " - "supported"); + return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, + "The requested method(s) are not currently " + "supported"); } if (*prefvar) { diff --git a/src/knownhost.c b/src/knownhost.c index a26023e..3f2dd02 100644 --- a/src/knownhost.c +++ b/src/knownhost.c @@ -88,9 +88,9 @@ libssh2_knownhost_init(LIBSSH2_SESSION *session) LIBSSH2_ALLOC(session, sizeof(struct _LIBSSH2_KNOWNHOSTS)); if(!knh) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for known-hosts " - "collection"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for known-hosts " + "collection"); return NULL; } @@ -137,14 +137,14 @@ knownhost_add(LIBSSH2_KNOWNHOSTS *hosts, unsigned int ptrlen; if(!entry) - return libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for known host " - "entry"); + return _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for known host " + "entry"); /* make sure we have a key type set */ if(!(typemask & LIBSSH2_KNOWNHOST_KEY_MASK)) { - rc = libssh2_error(hosts->session, LIBSSH2_ERROR_INVAL, - "No key type set"); + rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_INVAL, + "No key type set"); goto error; } @@ -157,8 +157,8 @@ knownhost_add(LIBSSH2_KNOWNHOSTS *hosts, case LIBSSH2_KNOWNHOST_TYPE_CUSTOM: entry->name = LIBSSH2_ALLOC(hosts->session, hostlen+1); if(!entry->name) { - rc = libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for host name"); + rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for host name"); goto error; } memcpy(entry->name, host, hostlen+1); @@ -179,8 +179,8 @@ knownhost_add(LIBSSH2_KNOWNHOSTS *hosts, entry->salt_len = ptrlen; break; default: - rc = libssh2_error(hosts->session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, - "Unknown host name type"); + rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, + "Unknown host name type"); goto error; } @@ -190,8 +190,8 @@ knownhost_add(LIBSSH2_KNOWNHOSTS *hosts, keylen = strlen(key); entry->key = LIBSSH2_ALLOC(hosts->session, keylen+1); if(!entry->key) { - rc = libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for key"); + rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for key"); goto error; } memcpy(entry->key, key, keylen+1); @@ -202,9 +202,9 @@ knownhost_add(LIBSSH2_KNOWNHOSTS *hosts, size_t nlen = _libssh2_base64_encode(hosts->session, key, keylen, &ptr); if(!nlen) { - rc = libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "base64-encoded key"); + rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for " + "base64-encoded key"); goto error; } @@ -214,8 +214,8 @@ knownhost_add(LIBSSH2_KNOWNHOSTS *hosts, if (comment) { entry->comment = LIBSSH2_ALLOC(hosts->session, commentlen+1); if(!entry->comment) { - rc = libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for comment"); + rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for comment"); goto error; } memcpy(entry->comment, comment, commentlen+1); @@ -347,9 +347,9 @@ libssh2_knownhost_check(LIBSSH2_KNOWNHOSTS *hosts, size_t nlen = _libssh2_base64_encode(hosts->session, key, keylen, &keyalloc); if(!nlen) { - libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for base64-encoded " - "key"); + _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for base64-encoded " + "key"); return LIBSSH2_KNOWNHOST_CHECK_FAILURE; } @@ -440,8 +440,8 @@ libssh2_knownhost_del(LIBSSH2_KNOWNHOSTS *hosts, /* check that this was retrieved the right way or get out */ if(!entry || (entry->magic != KNOWNHOST_MAGIC)) - return libssh2_error(hosts->session, LIBSSH2_ERROR_INVAL, - "Invalid host information"); + return _libssh2_error(hosts->session, LIBSSH2_ERROR_INVAL, + "Invalid host information"); /* get the internal node pointer */ node = entry->node; @@ -510,7 +510,7 @@ static int hostline(LIBSSH2_KNOWNHOSTS *hosts, for the sake of simplicity, we add them as two hosts with the same key - */ + */ size_t scan = hostlen; while(scan && (*host != ',')) { @@ -542,10 +542,10 @@ static int hostline(LIBSSH2_KNOWNHOSTS *hosts, const char *hash = NULL; size_t saltlen = p - salt; if(saltlen >= (sizeof(saltbuf)-1)) /* weird length */ - return libssh2_error(hosts->session, - LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, - "Failed to parse known_hosts line " - "(unexpectedly long salt)"); + return _libssh2_error(hosts->session, + LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, + "Failed to parse known_hosts line " + "(unexpectedly long salt)"); memcpy(saltbuf, salt, saltlen); saltbuf[saltlen] = 0; /* zero terminate */ @@ -565,10 +565,10 @@ static int hostline(LIBSSH2_KNOWNHOSTS *hosts, if((keylen < 20) || (seplen >= sizeof(hostbuf)-1) || (hostlen >= sizeof(hostbuf)-1)) - return libssh2_error(hosts->session, - LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, - "Failed to parse known_hosts line " - "(unexpected length)"); + return _libssh2_error(hosts->session, + LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, + "Failed to parse known_hosts line " + "(unexpected length)"); switch(key[0]) { case '0': case '1': case '2': case '3': case '4': @@ -589,9 +589,9 @@ static int hostline(LIBSSH2_KNOWNHOSTS *hosts, type |= LIBSSH2_KNOWNHOST_KEY_SSHRSA; else /* unknown key type */ - return libssh2_error(hosts->session, - LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, - "Unknown key type"); + return _libssh2_error(hosts->session, + LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, + "Unknown key type"); key += 7; keylen -= 7; @@ -628,9 +628,9 @@ static int hostline(LIBSSH2_KNOWNHOSTS *hosts, break; default: /* unknown key format */ - return libssh2_error(hosts->session, - LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, - "Unknown key format"); + return _libssh2_error(hosts->session, + LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, + "Unknown key format"); } if(sep) { @@ -699,10 +699,10 @@ libssh2_knownhost_readline(LIBSSH2_KNOWNHOSTS *hosts, int rc; if(type != LIBSSH2_KNOWNHOST_FILE_OPENSSH) - return libssh2_error(hosts->session, - LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, - "Unsupported type of known-host information " - "store"); + return _libssh2_error(hosts->session, + LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, + "Unsupported type of known-host information " + "store"); cp = line; @@ -734,9 +734,9 @@ libssh2_knownhost_readline(LIBSSH2_KNOWNHOSTS *hosts, } if(!*cp || !len) /* illegal line */ - return libssh2_error(hosts->session, - LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, - "Failed to parse known_hosts line"); + return _libssh2_error(hosts->session, + LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, + "Failed to parse known_hosts line"); keyp = cp; /* the key starts here */ keylen = len; @@ -777,10 +777,10 @@ libssh2_knownhost_readfile(LIBSSH2_KNOWNHOSTS *hosts, char buf[2048]; if(type != LIBSSH2_KNOWNHOST_FILE_OPENSSH) - return libssh2_error(hosts->session, - LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, - "Unsupported type of known-host information " - "store"); + return _libssh2_error(hosts->session, + LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, + "Unsupported type of known-host information " + "store"); file = fopen(filename, "r"); if(file) { @@ -792,8 +792,8 @@ libssh2_knownhost_readfile(LIBSSH2_KNOWNHOSTS *hosts, fclose(file); } else - return libssh2_error(hosts->session, LIBSSH2_ERROR_FILE, - "Failed to open file"); + return _libssh2_error(hosts->session, LIBSSH2_ERROR_FILE, + "Failed to open file"); return num; } @@ -830,10 +830,10 @@ knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts, /* we only support this single file type for now, bail out on all other attempts */ if(type != LIBSSH2_KNOWNHOST_FILE_OPENSSH) - return libssh2_error(hosts->session, - LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, - "Unsupported type of known-host information " - "store"); + return _libssh2_error(hosts->session, + LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, + "Unsupported type of known-host information " + "store"); tindex = (node->typemask & LIBSSH2_KNOWNHOST_KEY_MASK) >> LIBSSH2_KNOWNHOST_KEY_SHIFT; @@ -852,18 +852,18 @@ knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts, nlen = _libssh2_base64_encode(hosts->session, node->name, node->name_len, &namealloc); if(!nlen) - return libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "base64-encoded host name"); + return _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for " + "base64-encoded host name"); nlen = _libssh2_base64_encode(hosts->session, node->salt, node->salt_len, &saltalloc); if(!nlen) { free(namealloc); - return libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "base64-encoded salt"); + return _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for " + "base64-encoded salt"); } nlen = strlen(saltalloc) + strlen(namealloc) + strlen(keytype) + @@ -878,8 +878,8 @@ knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts, sprintf(buf, "|1|%s|%s%s %s\n", saltalloc, namealloc, keytype, node->key); else - rc = libssh2_error(hosts->session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, - "Known-host write buffer too small"); + rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, + "Known-host write buffer too small"); free(namealloc); free(saltalloc); @@ -896,8 +896,8 @@ knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts, else sprintf(buf, "%s%s %s\n", node->name, keytype, node->key); else - rc = libssh2_error(hosts->session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, - "Known-host write buffer too small"); + rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, + "Known-host write buffer too small"); } /* we report the full length of the data with the trailing zero excluded */ @@ -924,8 +924,8 @@ libssh2_knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts, struct known_host *node; if(known->magic != KNOWNHOST_MAGIC) - return libssh2_error(hosts->session, LIBSSH2_ERROR_INVAL, - "Invalid host information"); + return _libssh2_error(hosts->session, LIBSSH2_ERROR_INVAL, + "Invalid host information"); node = known->node; @@ -939,7 +939,7 @@ libssh2_knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts, */ LIBSSH2_API int libssh2_knownhost_writefile(LIBSSH2_KNOWNHOSTS *hosts, - const char *filename, int type) + const char *filename, int type) { struct known_host *node; FILE *file; @@ -949,15 +949,15 @@ libssh2_knownhost_writefile(LIBSSH2_KNOWNHOSTS *hosts, /* we only support this single file type for now, bail out on all other attempts */ if(type != LIBSSH2_KNOWNHOST_FILE_OPENSSH) - return libssh2_error(hosts->session, - LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, - "Unsupported type of known-host information " - "store"); + return _libssh2_error(hosts->session, + LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, + "Unsupported type of known-host information " + "store"); file = fopen(filename, "w"); if(!file) - return libssh2_error(hosts->session, LIBSSH2_ERROR_FILE, - "Failed to open file"); + return _libssh2_error(hosts->session, LIBSSH2_ERROR_FILE, + "Failed to open file"); for(node = _libssh2_list_first(&hosts->head); node; @@ -972,8 +972,8 @@ libssh2_knownhost_writefile(LIBSSH2_KNOWNHOSTS *hosts, nwrote = fwrite(buffer, 1, wrote, file); if(nwrote != wrote) { /* failed to write the whole thing, bail out */ - rc = libssh2_error(hosts->session, LIBSSH2_ERROR_FILE, - "Write failed"); + rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_FILE, + "Write failed"); break; } } diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 3257cc6..da5f67b 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -1041,8 +1041,6 @@ _libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, ...) #endif #endif -int libssh2_error(LIBSSH2_SESSION* session, int errcode, const char* errmsg); - #define LIBSSH2_SOCKET_UNKNOWN 1 #define LIBSSH2_SOCKET_CONNECTED 0 #define LIBSSH2_SOCKET_DISCONNECTED -1 diff --git a/src/misc.c b/src/misc.c index 1935553..dd10a6f 100644 --- a/src/misc.c +++ b/src/misc.c @@ -49,7 +49,7 @@ #include -int libssh2_error(LIBSSH2_SESSION* session, int errcode, const char* errmsg) +int _libssh2_error(LIBSSH2_SESSION* session, int errcode, const char* errmsg) { session->err_msg = errmsg; session->err_code = errcode; @@ -201,8 +201,8 @@ libssh2_base64_decode(LIBSSH2_SESSION *session, char **data, *data = LIBSSH2_ALLOC(session, (3 * src_len / 4) + 1); d = (unsigned char *) *data; if (!d) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for base64 decoding"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for base64 decoding"); } for(s = (unsigned char *) src; ((char *) s) < (src + src_len); s++) { @@ -230,8 +230,8 @@ libssh2_base64_decode(LIBSSH2_SESSION *session, char **data, /* Invalid -- We have a byte which belongs exclusively to a partial octet */ LIBSSH2_FREE(session, *data); - return libssh2_error(session, LIBSSH2_ERROR_INVAL, - "Invalid data (byte belonging to partial octet)"); + return _libssh2_error(session, LIBSSH2_ERROR_INVAL, + "Invalid data (byte belonging to partial octet)"); } *datalen = len; diff --git a/src/misc.h b/src/misc.h index 7d3842c..7771d65 100644 --- a/src/misc.h +++ b/src/misc.h @@ -1,6 +1,6 @@ #ifndef __LIBSSH2_MISC_H #define __LIBSSH2_MISC_H -/* Copyright (c) 2009 by Daniel Stenberg +/* Copyright (c) 2009-2010 by Daniel Stenberg * * All rights reserved. * @@ -49,6 +49,8 @@ struct list_node { struct list_head *head; }; +int _libssh2_error(LIBSSH2_SESSION* session, int errcode, const char* errmsg); + void _libssh2_list_init(struct list_head *head); /* add a node last in the list */ diff --git a/src/packet.c b/src/packet.c index c4267c9..d159cfc 100644 --- a/src/packet.c +++ b/src/packet.c @@ -140,9 +140,9 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data, channel = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_CHANNEL)); if (!channel) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate a channel for " - "new connection"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate a channel for " + "new connection"); failure_code = 4; /* SSH_OPEN_RESOURCE_SHORTAGE */ listen_state->state = libssh2_NB_state_sent; break; @@ -158,9 +158,9 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data, channel_type_len + 1); if (!channel->channel_type) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate a channel for new" - " connection"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate a channel for new" + " connection"); LIBSSH2_FREE(session, channel); failure_code = 4; /* SSH_OPEN_RESOURCE_SHORTAGE */ listen_state->state = libssh2_NB_state_sent; @@ -213,9 +213,9 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data, return rc; else if (rc) { listen_state->state = libssh2_NB_state_idle; - return libssh2_error(session, rc, - "Unable to send channel " - "open confirmation"); + return _libssh2_error(session, rc, + "Unable to send channel " + "open confirmation"); } /* Link the channel into the end of the queue list */ @@ -253,7 +253,7 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data, return rc; } else if (rc) { listen_state->state = libssh2_NB_state_idle; - return libssh2_error(session, rc, "Unable to send open failure"); + return _libssh2_error(session, rc, "Unable to send open failure"); } listen_state->state = libssh2_NB_state_idle; @@ -306,8 +306,8 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data, if (x11open_state->state == libssh2_NB_state_allocated) { channel = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_CHANNEL)); if (!channel) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate a channel for new connection"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate a channel for new connection"); failure_code = 4; /* SSH_OPEN_RESOURCE_SHORTAGE */ goto x11_exit; } @@ -319,8 +319,8 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data, channel->channel_type_len + 1); if (!channel->channel_type) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate a channel for new connection"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate a channel for new connection"); LIBSSH2_FREE(session, channel); failure_code = 4; /* SSH_OPEN_RESOURCE_SHORTAGE */ goto x11_exit; @@ -367,9 +367,9 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data, return rc; } else if (rc) { x11open_state->state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send channel open " - "confirmation"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send channel open " + "confirmation"); } /* Link the channel into the session */ @@ -407,7 +407,7 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data, return rc; } else if (rc) { x11open_state->state = libssh2_NB_state_idle; - return libssh2_error(session, rc, "Unable to send open failure"); + return _libssh2_error(session, rc, "Unable to send open failure"); } x11open_state->state = libssh2_NB_state_idle; return 0; @@ -459,8 +459,8 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, "", 0); } LIBSSH2_FREE(session, data); - return libssh2_error(session, LIBSSH2_ERROR_INVALID_MAC, - "Invalid MAC received"); + return _libssh2_error(session, LIBSSH2_ERROR_INVALID_MAC, + "Invalid MAC received"); } } @@ -492,47 +492,47 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, /* A couple exceptions to the packet adding rule: */ switch (data[0]) { case SSH_MSG_DISCONNECT: - { - char *message, *language; - int reason, message_len, language_len; + { + char *message, *language; + int reason, message_len, language_len; - reason = _libssh2_ntohu32(data + 1); - message_len = _libssh2_ntohu32(data + 5); - /* 9 = packet_type(1) + reason(4) + message_len(4) */ - message = (char *) data + 9; - language_len = _libssh2_ntohu32(data + 9 + message_len); - /* - * This is where we hack on the data a little, - * Use the MSB of language_len to to a terminating NULL - * (In all liklihood it is already) - * Shift the language tag back a byte (In all likelihood - * it's zero length anyway) - * Store a NULL in the last byte of the packet to terminate - * the language string - * With the lengths passed this isn't *REALLY* necessary, - * but it's "kind" - */ - message[message_len] = '\0'; - language = (char *) data + 9 + message_len + 3; - if (language_len) { - memmove(language, language + 1, language_len); - } - language[language_len] = '\0'; - - if (session->ssh_msg_disconnect) { - LIBSSH2_DISCONNECT(session, reason, message, - message_len, language, language_len); - } - _libssh2_debug(session, LIBSSH2_TRACE_TRANS, - "Disconnect(%d): %s(%s)", reason, - message, language); - LIBSSH2_FREE(session, data); - session->socket_state = LIBSSH2_SOCKET_DISCONNECTED; - session->packAdd_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_DISCONNECT, - "socket disconnect"); + reason = _libssh2_ntohu32(data + 1); + message_len = _libssh2_ntohu32(data + 5); + /* 9 = packet_type(1) + reason(4) + message_len(4) */ + message = (char *) data + 9; + language_len = _libssh2_ntohu32(data + 9 + message_len); + /* + * This is where we hack on the data a little, + * Use the MSB of language_len to to a terminating NULL + * (In all liklihood it is already) + * Shift the language tag back a byte (In all likelihood + * it's zero length anyway) + * Store a NULL in the last byte of the packet to terminate + * the language string + * With the lengths passed this isn't *REALLY* necessary, + * but it's "kind" + */ + message[message_len] = '\0'; + language = (char *) data + 9 + message_len + 3; + if (language_len) { + memmove(language, language + 1, language_len); } - break; + language[language_len] = '\0'; + + if (session->ssh_msg_disconnect) { + LIBSSH2_DISCONNECT(session, reason, message, + message_len, language, language_len); + } + _libssh2_debug(session, LIBSSH2_TRACE_TRANS, + "Disconnect(%d): %s(%s)", reason, + message, language); + LIBSSH2_FREE(session, data); + session->socket_state = LIBSSH2_SOCKET_DISCONNECTED; + session->packAdd_state = libssh2_NB_state_idle; + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_DISCONNECT, + "socket disconnect"); + } + break; case SSH_MSG_IGNORE: if (datalen >= 5) { @@ -550,48 +550,48 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, return 0; case SSH_MSG_DEBUG: - { - int always_display = data[0]; - char *message, *language; - int message_len, language_len; + { + int always_display = data[0]; + char *message, *language; + int message_len, language_len; - message_len = _libssh2_ntohu32(data + 2); - /* 6 = packet_type(1) + display(1) + message_len(4) */ - message = (char *) data + 6; - language_len = _libssh2_ntohu32(data + 6 + message_len); - /* - * This is where we hack on the data a little, - * Use the MSB of language_len to to a terminating NULL - * (In all liklihood it is already) - * Shift the language tag back a byte (In all likelihood - * it's zero length anyway) - * Store a NULL in the last byte of the packet to terminate - * the language string - * With the lengths passed this isn't *REALLY* necessary, - * but it's "kind" - */ - message[message_len] = '\0'; - language = (char *) data + 6 + message_len + 3; - if (language_len) { - memmove(language, language + 1, language_len); - } - language[language_len] = '\0'; - - if (session->ssh_msg_debug) { - LIBSSH2_DEBUG(session, always_display, message, - message_len, language, language_len); - } - /* - * _libssh2_debug will actually truncate this for us so - * that it's not an inordinate about of data - */ - _libssh2_debug(session, LIBSSH2_TRACE_TRANS, - "Debug Packet: %s", message); - LIBSSH2_FREE(session, data); - session->packAdd_state = libssh2_NB_state_idle; - return 0; + message_len = _libssh2_ntohu32(data + 2); + /* 6 = packet_type(1) + display(1) + message_len(4) */ + message = (char *) data + 6; + language_len = _libssh2_ntohu32(data + 6 + message_len); + /* + * This is where we hack on the data a little, + * Use the MSB of language_len to to a terminating NULL + * (In all liklihood it is already) + * Shift the language tag back a byte (In all likelihood + * it's zero length anyway) + * Store a NULL in the last byte of the packet to terminate + * the language string + * With the lengths passed this isn't *REALLY* necessary, + * but it's "kind" + */ + message[message_len] = '\0'; + language = (char *) data + 6 + message_len + 3; + if (language_len) { + memmove(language, language + 1, language_len); } - break; + language[language_len] = '\0'; + + if (session->ssh_msg_debug) { + LIBSSH2_DEBUG(session, always_display, message, + message_len, language, language_len); + } + /* + * _libssh2_debug will actually truncate this for us so + * that it's not an inordinate about of data + */ + _libssh2_debug(session, LIBSSH2_TRACE_TRANS, + "Debug Packet: %s", message); + LIBSSH2_FREE(session, data); + session->packAdd_state = libssh2_NB_state_idle; + return 0; + } + break; case SSH_MSG_GLOBAL_REQUEST: { @@ -628,8 +628,8 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, _libssh2_channel_locate(session, _libssh2_ntohu32(data + 1)); if (!session->packAdd_channel) { - libssh2_error(session, LIBSSH2_ERROR_CHANNEL_UNKNOWN, - "Packet received for unknown channel, ignoring"); + _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_UNKNOWN, + "Packet received for unknown channel, ignoring"); LIBSSH2_FREE(session, data); session->packAdd_state = libssh2_NB_state_idle; return 0; @@ -682,10 +682,10 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, * Spec says we MAY ignore bytes sent beyond * packet_size */ - libssh2_error(session, - LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED, - "Packet contains more data than we offered" - " to receive, truncating"); + _libssh2_error(session, + LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED, + "Packet contains more data than we offered" + " to receive, truncating"); datalen = session->packAdd_channel->remote.packet_size + session->packAdd_data_head; @@ -695,10 +695,10 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, * Spec says we MAY ignore bytes sent beyond * window_size */ - libssh2_error(session, - LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED, - "The current receive window is full," - " data ignored"); + _libssh2_error(session, + LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED, + "The current receive window is full," + " data ignored"); LIBSSH2_FREE(session, data); session->packAdd_state = libssh2_NB_state_idle; return 0; @@ -708,10 +708,10 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, if ((datalen - session->packAdd_data_head) > session->packAdd_channel->remote.window_size) { - libssh2_error(session, - LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED, - "Remote sent more data than current " - "window allows, truncating"); + _libssh2_error(session, + LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED, + "Remote sent more data than current " + "window allows, truncating"); datalen = session->packAdd_channel->remote.window_size + session->packAdd_data_head; @@ -792,7 +792,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, return 0; } break; - } + } case SSH_MSG_CHANNEL_CLOSE: session->packAdd_channel = @@ -852,31 +852,31 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, break; case SSH_MSG_CHANNEL_WINDOW_ADJUST: - { - unsigned long bytestoadd = _libssh2_ntohu32(data + 5); - session->packAdd_channel = - _libssh2_channel_locate(session, - _libssh2_ntohu32(data + 1)); + { + unsigned long bytestoadd = _libssh2_ntohu32(data + 5); + session->packAdd_channel = + _libssh2_channel_locate(session, + _libssh2_ntohu32(data + 1)); - if (session->packAdd_channel && bytestoadd) { - session->packAdd_channel->local.window_size += bytestoadd; - } - if(session->packAdd_channel) - _libssh2_debug(session, LIBSSH2_TRACE_CONN, - "Window adjust received for channel %lu/%lu, adding %lu bytes, new window_size=%lu", - session->packAdd_channel->local.id, - session->packAdd_channel->remote.id, - bytestoadd, - session->packAdd_channel->local.window_size); - else - _libssh2_debug(session, LIBSSH2_TRACE_CONN, - "Window adjust for non-existing channel!"); - - LIBSSH2_FREE(session, data); - session->packAdd_state = libssh2_NB_state_idle; - return 0; + if (session->packAdd_channel && bytestoadd) { + session->packAdd_channel->local.window_size += bytestoadd; } - break; + if(session->packAdd_channel) + _libssh2_debug(session, LIBSSH2_TRACE_CONN, + "Window adjust received for channel %lu/%lu, adding %lu bytes, new window_size=%lu", + session->packAdd_channel->local.id, + session->packAdd_channel->remote.id, + bytestoadd, + session->packAdd_channel->local.window_size); + else + _libssh2_debug(session, LIBSSH2_TRACE_CONN, + "Window adjust for non-existing channel!"); + + LIBSSH2_FREE(session, data); + session->packAdd_state = libssh2_NB_state_idle; + return 0; + } + break; } session->packAdd_state = libssh2_NB_state_sent; @@ -885,7 +885,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, if (session->packAdd_state == libssh2_NB_state_sent) { LIBSSH2_PACKET *packAdd_packet; packAdd_packet = - LIBSSH2_ALLOC(session, sizeof(LIBSSH2_PACKET)); + LIBSSH2_ALLOC(session, sizeof(LIBSSH2_PACKET)); if (!packAdd_packet) { _libssh2_debug(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for LIBSSH2_PACKET"); @@ -1034,8 +1034,8 @@ _libssh2_packet_require(LIBSSH2_SESSION * session, unsigned char packet_type, { if (state->start == 0) { if (_libssh2_packet_ask(session, packet_type, data, data_len, - match_ofs, match_buf, - match_len) == 0) { + match_ofs, match_buf, + match_len) == 0) { /* A packet was available in the packet brigade */ return 0; } @@ -1054,7 +1054,7 @@ _libssh2_packet_require(LIBSSH2_SESSION * session, unsigned char packet_type, } else if (ret == packet_type) { /* Be lazy, let packet_ask pull it out of the brigade */ ret = _libssh2_packet_ask(session, packet_type, data, data_len, - match_ofs, match_buf, match_len); + match_ofs, match_buf, match_len); state->start = 0; return ret; } else if (ret == 0) { diff --git a/src/publickey.c b/src/publickey.c index 896764c..2a0330d 100644 --- a/src/publickey.c +++ b/src/publickey.c @@ -118,7 +118,7 @@ publickey_status_error(const LIBSSH2_PUBLICKEY *pkey, msg = publickey_status_codes[status].name; } - libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, msg); + _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, msg); } /* @@ -140,17 +140,17 @@ publickey_packet_receive(LIBSSH2_PUBLICKEY * pkey, if (rc == PACKET_EAGAIN) { return rc; } else if (rc != 4) { - return libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, - "Invalid response from publickey subsystem"); + return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, + "Invalid response from publickey subsystem"); } pkey->receive_packet_len = _libssh2_ntohu32(buffer); pkey->receive_packet = LIBSSH2_ALLOC(session, pkey->receive_packet_len); if (!pkey->receive_packet) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate publickey response " - "buffer"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate publickey response " + "buffer"); } pkey->receive_state = libssh2_NB_state_sent; @@ -165,9 +165,9 @@ publickey_packet_receive(LIBSSH2_PUBLICKEY * pkey, LIBSSH2_FREE(session, pkey->receive_packet); pkey->receive_packet = NULL; pkey->receive_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, - "Timeout waiting for publickey subsystem " - "response packet"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, + "Timeout waiting for publickey subsystem " + "response packet"); } *data = pkey->receive_packet; @@ -233,36 +233,36 @@ publickey_response_success(LIBSSH2_PUBLICKEY * pkey) if (rc == PACKET_EAGAIN) { return rc; } else if (rc) { - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, - "Timeout waiting for response from " - "publickey subsystem"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, + "Timeout waiting for response from " + "publickey subsystem"); } s = data; if ((response = publickey_response_id(&s, data_len)) < 0) { LIBSSH2_FREE(session, data); - return libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, - "Invalid publickey subsystem response code"); + return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, + "Invalid publickey subsystem response code"); } switch (response) { case LIBSSH2_PUBLICKEY_RESPONSE_STATUS: /* Error, or processing complete */ - { - unsigned long status = _libssh2_ntohu32(s); + { + unsigned long status = _libssh2_ntohu32(s); - LIBSSH2_FREE(session, data); + LIBSSH2_FREE(session, data); - if (status == LIBSSH2_PUBLICKEY_SUCCESS) - return 0; + if (status == LIBSSH2_PUBLICKEY_SUCCESS) + return 0; - publickey_status_error(pkey, session, status); - return -1; - } + publickey_status_error(pkey, session, status); + return -1; + } default: /* Unknown/Unexpected */ - libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, - "Unexpected publickey subsystem response, ignoring"); + _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, + "Unexpected publickey subsystem response, ignoring"); LIBSSH2_FREE(session, data); data = NULL; } @@ -272,8 +272,8 @@ publickey_response_success(LIBSSH2_PUBLICKEY * pkey) } /* ***************** - * Publickey API * - ***************** */ + * Publickey API * + ***************** */ /* * libssh2_publickey_init @@ -312,14 +312,14 @@ libssh2_publickey_init(LIBSSH2_SESSION * session) && (libssh2_session_last_errno(session) == LIBSSH2_ERROR_EAGAIN)) { /* The error state is already set, so leave it */ - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block to startup channel"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block to startup channel"); return NULL; } else if (!session->pkeyInit_channel && (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN)) { - libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE, - "Unable to startup channel"); + _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE, + "Unable to startup channel"); goto err_exit; } } while (!session->pkeyInit_channel); @@ -333,12 +333,12 @@ libssh2_publickey_init(LIBSSH2_SESSION * session) sizeof("subsystem") - 1, "publickey", strlen("publickey")); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block starting publickey subsystem"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block starting publickey subsystem"); return NULL; } else if (rc) { - libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE, - "Unable to request publickey subsystem"); + _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE, + "Unable to request publickey subsystem"); goto err_exit; } @@ -349,16 +349,16 @@ libssh2_publickey_init(LIBSSH2_SESSION * session) rc = libssh2_channel_handle_extended_data2(session->pkeyInit_channel, LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block starting publickey subsystem"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block starting publickey subsystem"); return NULL; } session->pkeyInit_pkey = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_PUBLICKEY)); if (!session->pkeyInit_pkey) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate a new publickey structure"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate a new publickey structure"); goto err_exit; } memset(session->pkeyInit_pkey, 0, sizeof(LIBSSH2_PUBLICKEY)); @@ -386,12 +386,12 @@ libssh2_publickey_init(LIBSSH2_SESSION * session) rc = _libssh2_channel_write(session->pkeyInit_channel, 0, (char *) buffer, (s - buffer)); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block sending publickey version packet"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block sending publickey version packet"); return NULL; } else if ((s - buffer) != rc) { - libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send publickey version packet"); + _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send publickey version packet"); goto err_exit; } @@ -404,56 +404,56 @@ libssh2_publickey_init(LIBSSH2_SESSION * session) &session->pkeyInit_data, &session->pkeyInit_data_len); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block waiting for response from " - "publickey subsystem"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block waiting for response from " + "publickey subsystem"); return NULL; } else if (rc) { - libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, - "Timeout waiting for response from " - "publickey subsystem"); + _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, + "Timeout waiting for response from " + "publickey subsystem"); goto err_exit; } s = session->pkeyInit_data; if ((response = publickey_response_id(&s, session->pkeyInit_data_len)) < 0) { - libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, - "Invalid publickey subsystem response code"); + _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, + "Invalid publickey subsystem response code"); goto err_exit; } switch (response) { case LIBSSH2_PUBLICKEY_RESPONSE_STATUS: /* Error */ - { - unsigned long status, descr_len, lang_len; - unsigned char *descr, *lang; + { + unsigned long status, descr_len, lang_len; + unsigned char *descr, *lang; - status = _libssh2_ntohu32(s); - s += 4; - descr_len = _libssh2_ntohu32(s); - s += 4; - descr = s; - s += descr_len; - lang_len = _libssh2_ntohu32(s); - s += 4; - lang = s; - s += lang_len; - - if (s > - session->pkeyInit_data + session->pkeyInit_data_len) { - libssh2_error(session, - LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, - "Malformed publickey subsystem packet"); - goto err_exit; - } - - publickey_status_error(NULL, session, status); + status = _libssh2_ntohu32(s); + s += 4; + descr_len = _libssh2_ntohu32(s); + s += 4; + descr = s; + s += descr_len; + lang_len = _libssh2_ntohu32(s); + s += 4; + lang = s; + s += lang_len; + if (s > + session->pkeyInit_data + session->pkeyInit_data_len) { + _libssh2_error(session, + LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, + "Malformed publickey subsystem packet"); goto err_exit; } + publickey_status_error(NULL, session, status); + + goto err_exit; + } + case LIBSSH2_PUBLICKEY_RESPONSE_VERSION: /* What we want */ session->pkeyInit_pkey->version = _libssh2_ntohu32(s); @@ -475,9 +475,9 @@ libssh2_publickey_init(LIBSSH2_SESSION * session) default: /* Unknown/Unexpected */ - libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, - "Unexpected publickey subsystem response, " - "ignoring"); + _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, + "Unexpected publickey subsystem response, " + "ignoring"); LIBSSH2_FREE(session, session->pkeyInit_data); session->pkeyInit_data = NULL; } @@ -490,8 +490,8 @@ libssh2_publickey_init(LIBSSH2_SESSION * session) if (session->pkeyInit_channel) { rc = libssh2_channel_close(session->pkeyInit_channel); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block closing channel"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block closing channel"); return NULL; } } @@ -555,9 +555,9 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY * pkey, const unsigned char *name, pkey->add_packet = LIBSSH2_ALLOC(session, packet_len); if (!pkey->add_packet) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "publickey \"add\" packet"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for " + "publickey \"add\" packet"); } pkey->add_s = pkey->add_packet; @@ -625,8 +625,8 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY * pkey, const unsigned char *name, } else if ((pkey->add_s - pkey->add_packet) != rc) { LIBSSH2_FREE(session, pkey->add_packet); pkey->add_packet = NULL; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send publickey add packet"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send publickey add packet"); } LIBSSH2_FREE(session, pkey->add_packet); pkey->add_packet = NULL; @@ -663,9 +663,9 @@ libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY * pkey, pkey->remove_packet = LIBSSH2_ALLOC(session, packet_len); if (!pkey->remove_packet) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "publickey \"remove\" packet"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for " + "publickey \"remove\" packet"); } pkey->remove_s = pkey->remove_packet; @@ -700,8 +700,8 @@ libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY * pkey, LIBSSH2_FREE(session, pkey->remove_packet); pkey->remove_packet = NULL; pkey->remove_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send publickey remove packet"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send publickey remove packet"); } LIBSSH2_FREE(session, pkey->remove_packet); pkey->remove_packet = NULL; @@ -760,8 +760,8 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys, return rc; } else if ((pkey->listFetch_s - pkey->listFetch_buffer) != rc) { pkey->listFetch_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send publickey list packet"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send publickey list packet"); } pkey->listFetch_state = libssh2_NB_state_sent; @@ -773,9 +773,9 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys, if (rc == PACKET_EAGAIN) { return rc; } else if (rc) { - libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, - "Timeout waiting for response from " - "publickey subsystem"); + _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, + "Timeout waiting for response from " + "publickey subsystem"); goto err_exit; } @@ -783,48 +783,48 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys, if ((response = publickey_response_id(&pkey->listFetch_s, pkey->listFetch_data_len)) < 0) { - libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, - "Invalid publickey subsystem response code"); + _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, + "Invalid publickey subsystem response code"); goto err_exit; } switch (response) { case LIBSSH2_PUBLICKEY_RESPONSE_STATUS: /* Error, or processing complete */ - { - unsigned long status, descr_len, lang_len; - unsigned char *descr, *lang; + { + unsigned long status, descr_len, lang_len; + unsigned char *descr, *lang; - status = _libssh2_ntohu32(pkey->listFetch_s); - pkey->listFetch_s += 4; - descr_len = _libssh2_ntohu32(pkey->listFetch_s); - pkey->listFetch_s += 4; - descr = pkey->listFetch_s; - pkey->listFetch_s += descr_len; - lang_len = _libssh2_ntohu32(pkey->listFetch_s); - pkey->listFetch_s += 4; - lang = pkey->listFetch_s; - pkey->listFetch_s += lang_len; + status = _libssh2_ntohu32(pkey->listFetch_s); + pkey->listFetch_s += 4; + descr_len = _libssh2_ntohu32(pkey->listFetch_s); + pkey->listFetch_s += 4; + descr = pkey->listFetch_s; + pkey->listFetch_s += descr_len; + lang_len = _libssh2_ntohu32(pkey->listFetch_s); + pkey->listFetch_s += 4; + lang = pkey->listFetch_s; + pkey->listFetch_s += lang_len; - if (pkey->listFetch_s > - pkey->listFetch_data + pkey->listFetch_data_len) { - libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, - "Malformed publickey subsystem packet"); - goto err_exit; - } - - if (status == LIBSSH2_PUBLICKEY_SUCCESS) { - LIBSSH2_FREE(session, pkey->listFetch_data); - pkey->listFetch_data = NULL; - *pkey_list = list; - *num_keys = keys; - pkey->listFetch_state = libssh2_NB_state_idle; - return 0; - } - - publickey_status_error(pkey, session, status); + if (pkey->listFetch_s > + pkey->listFetch_data + pkey->listFetch_data_len) { + _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, + "Malformed publickey subsystem packet"); goto err_exit; } + + if (status == LIBSSH2_PUBLICKEY_SUCCESS) { + LIBSSH2_FREE(session, pkey->listFetch_data); + pkey->listFetch_data = NULL; + *pkey_list = list; + *num_keys = keys; + pkey->listFetch_state = libssh2_NB_state_idle; + return 0; + } + + publickey_status_error(pkey, session, status); + goto err_exit; + } case LIBSSH2_PUBLICKEY_RESPONSE_PUBLICKEY: /* What we want */ if (keys >= max_keys) { @@ -836,9 +836,9 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys, (max_keys + 1) * sizeof(libssh2_publickey_list)); if (!newlist) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "publickey list"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for " + "publickey list"); goto err_exit; } list = newlist; @@ -854,9 +854,9 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys, LIBSSH2_ALLOC(session, sizeof(libssh2_publickey_attribute)); if (!list[keys].attrs) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "publickey attributes"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for " + "publickey attributes"); goto err_exit; } list[keys].attrs[0].name = "comment"; @@ -896,9 +896,9 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys, list[keys].num_attrs * sizeof(libssh2_publickey_attribute)); if (!list[keys].attrs) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "publickey attributes"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for " + "publickey attributes"); goto err_exit; } for(i = 0; i < list[keys].num_attrs; i++) { @@ -926,8 +926,8 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys, break; default: /* Unknown/Unexpected */ - libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, - "Unexpected publickey subsystem response, ignoring"); + _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, + "Unexpected publickey subsystem response, ignoring"); LIBSSH2_FREE(session, pkey->listFetch_data); pkey->listFetch_data = NULL; } diff --git a/src/scp.c b/src/scp.c index 2c1728a..d7745e3 100644 --- a/src/scp.c +++ b/src/scp.c @@ -47,78 +47,78 @@ #define libssh2_shell_quotedsize(s) (3 * strlen(s) + 2) /* - This function quotes a string in a way suitable to be used with a - shell, e.g. the file name - one two - becomes - 'one two' + This function quotes a string in a way suitable to be used with a + shell, e.g. the file name + one two + becomes + 'one two' - The resulting output string is crafted in a way that makes it usable - with the two most common shell types: Bourne Shell derived shells - (sh, ksh, ksh93, bash, zsh) and C-Shell derivates (csh, tcsh). + The resulting output string is crafted in a way that makes it usable + with the two most common shell types: Bourne Shell derived shells + (sh, ksh, ksh93, bash, zsh) and C-Shell derivates (csh, tcsh). - The following special cases are handled: - o If the string contains an apostrophy itself, the apostrophy - character is written in quotation marks, e.g. "'". - The shell cannot handle the syntax 'doesn\'t', so we close the - current argument word, add the apostrophe in quotation marks "", - and open a new argument word instead (_ indicate the input - string characters): - _____ _ _ - 'doesn' "'" 't' + The following special cases are handled: + o If the string contains an apostrophy itself, the apostrophy + character is written in quotation marks, e.g. "'". + The shell cannot handle the syntax 'doesn\'t', so we close the + current argument word, add the apostrophe in quotation marks "", + and open a new argument word instead (_ indicate the input + string characters): + _____ _ _ + 'doesn' "'" 't' - Sequences of apostrophes are combined in one pair of quotation marks: - a'''b - becomes - _ ___ _ - 'a'"'''"'b' + Sequences of apostrophes are combined in one pair of quotation marks: + a'''b + becomes + _ ___ _ + 'a'"'''"'b' - o If the string contains an exclamation mark (!), the C-Shell - interprets it as an event number. Using \! (not within quotation - marks or single quotation marks) is a mechanism understood by - both Bourne Shell and C-Shell. + o If the string contains an exclamation mark (!), the C-Shell + interprets it as an event number. Using \! (not within quotation + marks or single quotation marks) is a mechanism understood by + both Bourne Shell and C-Shell. - If a quotation was already started, the argument word is closed - first: - a!b + If a quotation was already started, the argument word is closed + first: + a!b - become - _ _ _ - 'a'\!'b' + become + _ _ _ + 'a'\!'b' - The result buffer must be large enough for the expanded result. A - bad case regarding expansion is alternating characters and - apostrophes: + The result buffer must be large enough for the expanded result. A + bad case regarding expansion is alternating characters and + apostrophes: - a'b'c'd' (length 8) gets converted to - 'a'"'"'b'"'"'c'"'"'d'"'" (length 24) + a'b'c'd' (length 8) gets converted to + 'a'"'"'b'"'"'c'"'"'d'"'" (length 24) - This is the worst case. + This is the worst case. - Maximum length of the result: - 1 + 6 * (length(input) + 1) / 2) + 1 + Maximum length of the result: + 1 + 6 * (length(input) + 1) / 2) + 1 - => 3 * length(input) + 2 + => 3 * length(input) + 2 - Explanation: - o leading apostrophe - o one character / apostrophe pair (two characters) can get - represented as 6 characters: a' -> a'"'"' - o String terminator (+1) + Explanation: + o leading apostrophe + o one character / apostrophe pair (two characters) can get + represented as 6 characters: a' -> a'"'"' + o String terminator (+1) - A result buffer three times the size of the input buffer + 2 - characters should be safe. + A result buffer three times the size of the input buffer + 2 + characters should be safe. - References: - o csh-compatible quotation (special handling for '!' etc.), see - http://www.grymoire.com/Unix/Csh.html#toc-uh-10 + References: + o csh-compatible quotation (special handling for '!' etc.), see + http://www.grymoire.com/Unix/Csh.html#toc-uh-10 - Return value: - Length of the resulting string (not counting the terminating '\0'), - or 0 in case of errors, e.g. result buffer too small + Return value: + Length of the resulting string (not counting the terminating '\0'), + or 0 in case of errors, e.g. result buffer too small - Note: this function could possible be used elsewhere within libssh2, but - until then it is kept static and in this source file. + Note: this function could possible be used elsewhere within libssh2, but + until then it is kept static and in this source file. */ static unsigned @@ -234,20 +234,20 @@ libssh2_shell_quotearg(const char *path, unsigned char *buf, } switch (state) { - case UQSTRING: - break; - case QSTRING: /* Close quoted string */ - if (dst+1 >= endp) - return 0; - *dst++ = '"'; - break; - case SQSTRING: /* Close single quoted string */ - if (dst+1 >= endp) - return 0; - *dst++ = '\''; - break; - default: - break; + case UQSTRING: + break; + case QSTRING: /* Close quoted string */ + if (dst+1 >= endp) + return 0; + *dst++ = '"'; + break; + case SQSTRING: /* Close single quoted string */ + if (dst+1 >= endp) + return 0; + *dst++ = '\''; + break; + default: + break; } if (dst+1 >= endp) @@ -285,9 +285,9 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb) LIBSSH2_ALLOC(session, session->scpRecv_command_len); if (!session->scpRecv_command) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate a command buffer for " - "SCP session"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate a command buffer for " + "SCP session"); return NULL; } @@ -323,8 +323,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb) session->scpRecv_state = libssh2_NB_state_idle; } else { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block starting up channel"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block starting up channel"); } return NULL; } @@ -339,8 +339,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb) (char *) session->scpRecv_command, session->scpRecv_command_len); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block requesting SCP startup"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block requesting SCP startup"); return NULL; } else if (rc) { LIBSSH2_FREE(session, session->scpRecv_command); @@ -361,8 +361,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb) rc = _libssh2_channel_write(session->scpRecv_channel, 0, (char *) session->scpRecv_response, 1); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block sending initial wakeup"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block sending initial wakeup"); return NULL; } else if (rc != 1) { goto scp_recv_error; @@ -386,13 +386,13 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb) scpRecv_response + session->scpRecv_response_len, 1); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block waiting for SCP response"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block waiting for SCP response"); return NULL; } else if (rc <= 0) { /* Timeout, give up */ - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "Timed out waiting for SCP response"); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "Timed out waiting for SCP response"); goto scp_recv_error; } session->scpRecv_response_len++; @@ -402,8 +402,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb) * Set this as the default error for here, if * we are successful it will be replaced */ - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "Invalid data in SCP response, missing Time data"); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "Invalid data in SCP response, missing Time data"); session->scpRecv_err_len = _libssh2_channel_packet_data_len(session-> @@ -426,12 +426,12 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb) * it is already in the systems so it can't return * PACKET_EAGAIN */ - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "Unknown error" ); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "Unknown error" ); } else - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "SCP protocol error"); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "SCP protocol error"); /* TODO: for debugging purposes, the session->scpRecv_err_msg should be displayed here @@ -458,8 +458,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb) && (session-> scpRecv_response[session->scpRecv_response_len - 1] != '\n')) { - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "Invalid data in SCP response"); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "Invalid data in SCP response"); goto scp_recv_error; } @@ -470,8 +470,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb) if (session->scpRecv_response_len == LIBSSH2_SCP_RESPONSE_BUFLEN) { /* You had your chance */ - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "Unterminated response from SCP server"); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "Unterminated response from SCP server"); goto scp_recv_error; } /* Way too short to be an SCP response, or not done yet, @@ -493,9 +493,9 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb) if (session->scpRecv_response_len < 8) { /* EOL came too soon */ - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "Invalid response from SCP server, " - "too short" ); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "Invalid response from SCP server, " + "too short" ); goto scp_recv_error; } @@ -504,9 +504,9 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb) p = (unsigned char *) strchr((char *) s, ' '); if (!p || ((p - s) <= 0)) { /* No spaces or space in the wrong spot */ - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "Invalid response from SCP server, " - "malformed mtime"); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "Invalid response from SCP server, " + "malformed mtime"); goto scp_recv_error; } @@ -515,15 +515,15 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb) errno = 0; session->scpRecv_mtime = strtol((char *) s, NULL, 10); if (errno) { - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "Invalid response from SCP server, invalid mtime"); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "Invalid response from SCP server, invalid mtime"); goto scp_recv_error; } s = (unsigned char *) strchr((char *) p, ' '); if (!s || ((s - p) <= 0)) { /* No spaces or space in the wrong spot */ - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "Invalid response from SCP server, malformed mtime.usec"); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "Invalid response from SCP server, malformed mtime.usec"); goto scp_recv_error; } @@ -532,8 +532,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb) p = (unsigned char *) strchr((char *) s, ' '); if (!p || ((p - s) <= 0)) { /* No spaces or space in the wrong spot */ - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "Invalid response from SCP server, too short or malformed"); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "Invalid response from SCP server, too short or malformed"); goto scp_recv_error; } @@ -542,8 +542,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb) errno = 0; session->scpRecv_atime = strtol((char *) s, NULL, 10); if (errno) { - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "Invalid response from SCP server, invalid atime"); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "Invalid response from SCP server, invalid atime"); goto scp_recv_error; } @@ -558,8 +558,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb) (char *) session-> scpRecv_response, 1); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block waiting to send SCP ACK"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block waiting to send SCP ACK"); return NULL; } else if (rc != 1) { goto scp_recv_error; @@ -595,20 +595,20 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb) scpRecv_response + session->scpRecv_response_len, 1); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block waiting for SCP response"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block waiting for SCP response"); return NULL; } else if (rc <= 0) { /* Timeout, give up */ - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "Timed out waiting for SCP response"); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "Timed out waiting for SCP response"); goto scp_recv_error; } session->scpRecv_response_len++; if (session->scpRecv_response[0] != 'C') { - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "Invalid response from SCP server"); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "Invalid response from SCP server"); goto scp_recv_error; } @@ -625,8 +625,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb) || (session-> scpRecv_response[session->scpRecv_response_len - 1] > 126))) { - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "Invalid data in SCP response"); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "Invalid data in SCP response"); goto scp_recv_error; } @@ -637,8 +637,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb) if (session->scpRecv_response_len == LIBSSH2_SCP_RESPONSE_BUFLEN) { /* You had your chance */ - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "Unterminated response from SCP server"); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "Unterminated response from SCP server"); goto scp_recv_error; } /* Way too short to be an SCP response, or not done yet, @@ -661,8 +661,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb) if (session->scpRecv_response_len < 6) { /* EOL came too soon */ - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "Invalid response from SCP server, too short"); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "Invalid response from SCP server, too short"); goto scp_recv_error; } @@ -671,8 +671,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb) p = strchr(s, ' '); if (!p || ((p - s) <= 0)) { /* No spaces or space in the wrong spot */ - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "Invalid response from SCP server, malformed mode"); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "Invalid response from SCP server, malformed mode"); goto scp_recv_error; } @@ -681,16 +681,16 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb) errno = 0; session->scpRecv_mode = strtol(s, &e, 8); if ((e && *e) || errno) { - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "Invalid response from SCP server, invalid mode"); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "Invalid response from SCP server, invalid mode"); goto scp_recv_error; } s = strchr(p, ' '); if (!s || ((s - p) <= 0)) { /* No spaces or space in the wrong spot */ - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "Invalid response from SCP server, too short or malformed"); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "Invalid response from SCP server, too short or malformed"); goto scp_recv_error; } @@ -699,8 +699,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb) errno = 0; session->scpRecv_size = scpsize_strtol(p, &e, 10); if ((e && *e) || errno) { - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "Invalid response from SCP server, invalid size"); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "Invalid response from SCP server, invalid size"); goto scp_recv_error; } @@ -715,8 +715,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb) (char *) session-> scpRecv_response, 1); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block sending SCP ACK"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block sending SCP ACK"); return NULL; } else if (rc != 1) { goto scp_recv_error; @@ -789,8 +789,8 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, session->scpSend_command = LIBSSH2_ALLOC(session, session->scpSend_command_len); if (!session->scpSend_command) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate a command buffer for scp session"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate a command buffer for scp session"); return NULL; } @@ -826,8 +826,8 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, session->scpSend_state = libssh2_NB_state_idle; } else { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block starting up channel"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block starting up channel"); } return NULL; } @@ -842,8 +842,8 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, (char *) session->scpSend_command, session->scpSend_command_len); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block requesting SCP startup"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block requesting SCP startup"); return NULL; } else if (rc) { @@ -851,8 +851,8 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, through */ LIBSSH2_FREE(session, session->scpSend_command); session->scpSend_command = NULL; - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "Unknown error while getting error string"); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "Unknown error while getting error string"); goto scp_send_error; } LIBSSH2_FREE(session, session->scpSend_command); @@ -866,12 +866,12 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, rc = _libssh2_channel_read(session->scpSend_channel, 0, (char *) session->scpSend_response, 1); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block waiting for response from remote"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block waiting for response from remote"); return NULL; } else if ((rc <= 0) || (session->scpSend_response[0] != 0)) { - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "Invalid ACK response from remote"); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "Invalid ACK response from remote"); goto scp_send_error; } @@ -895,12 +895,12 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, (char *) session->scpSend_response, session->scpSend_response_len); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block sending time data for SCP file"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block sending time data for SCP file"); return NULL; } else if (rc != (int)session->scpSend_response_len) { - libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send time data for SCP file"); + _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send time data for SCP file"); goto scp_send_error; } @@ -912,12 +912,12 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, rc = _libssh2_channel_read(session->scpSend_channel, 0, (char *) session->scpSend_response, 1); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block waiting for response"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block waiting for response"); return NULL; } else if ((rc <= 0) || (session->scpSend_response[0] != 0)) { - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "Invalid ACK response from remote"); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "Invalid ACK response from remote"); goto scp_send_error; } @@ -953,12 +953,12 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, (char *) session->scpSend_response, session->scpSend_response_len); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block send core file data for SCP file"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block send core file data for SCP file"); return NULL; } else if (rc != (int)session->scpSend_response_len) { - libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send core file data for SCP file"); + _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send core file data for SCP file"); goto scp_send_error; } @@ -970,20 +970,20 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, rc = _libssh2_channel_read(session->scpSend_channel, 0, (char *) session->scpSend_response, 1); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block waiting for response"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block waiting for response"); return NULL; } else if (rc <= 0) { - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "Invalid ACK response from remote"); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "Invalid ACK response from remote"); goto scp_send_error; } else if (session->scpSend_response[0] != 0) { /* * Set this as the default error for here, if * we are successful it will be replaced */ - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "Invalid ACK response from remote"); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "Invalid ACK response from remote"); session->scpSend_err_len = _libssh2_channel_packet_data_len(session->scpSend_channel, 0); @@ -1007,8 +1007,8 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode, session->scpSend_err_msg = NULL; } else - libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, - "failed waiting for ACK"); + _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, + "failed waiting for ACK"); goto scp_send_error; } } diff --git a/src/session.c b/src/session.c index 7baba7d..c45b5ae 100644 --- a/src/session.c +++ b/src/session.c @@ -163,8 +163,8 @@ banner_receive(LIBSSH2_SESSION * session) session->remote.banner = LIBSSH2_ALLOC(session, banner_len + 1); if (!session->remote.banner) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Error allocating space for remote banner"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Error allocating space for remote banner"); } memcpy(session->remote.banner, session->banner_TxRx_banner, banner_len); session->remote.banner[banner_len] = '\0'; @@ -403,8 +403,8 @@ libssh2_banner_set(LIBSSH2_SESSION * session, const char *banner) session->local.banner = LIBSSH2_ALLOC(session, banner_len + 3); if (!session->local.banner) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for local banner"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for local banner"); } memcpy(session->local.banner, banner, banner_len); @@ -592,8 +592,8 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock) "session_startup for socket %d", sock); if (INVALID_SOCKET == sock) { /* Did we forget something? */ - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_NONE, - "Bad socket provided"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_NONE, + "Bad socket provided"); } session->socket_fd = sock; @@ -611,8 +611,8 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock) if (session->startup_state == libssh2_NB_state_created) { rc = banner_send(session); if (rc) { - return libssh2_error(session, rc, - "Failed sending banner"); + return _libssh2_error(session, rc, + "Failed sending banner"); } session->startup_state = libssh2_NB_state_sent; } @@ -620,8 +620,8 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock) if (session->startup_state == libssh2_NB_state_sent) { rc = banner_receive(session); if (rc) { - return libssh2_error(session, rc, - "Failed getting banner"); + return _libssh2_error(session, rc, + "Failed getting banner"); } session->startup_state = libssh2_NB_state_sent1; @@ -630,8 +630,8 @@ 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) { - return libssh2_error(session, rc, - "Unable to exchange encryption keys"); + return _libssh2_error(session, rc, + "Unable to exchange encryption keys"); } session->startup_state = libssh2_NB_state_sent2; @@ -644,7 +644,7 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock) /* Request the userauth service */ session->startup_service[0] = SSH_MSG_SERVICE_REQUEST; _libssh2_htonu32(session->startup_service + 1, - sizeof("ssh-userauth") - 1); + sizeof("ssh-userauth") - 1); memcpy(session->startup_service + 5, "ssh-userauth", sizeof("ssh-userauth") - 1); @@ -655,8 +655,8 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock) rc = _libssh2_transport_write(session, session->startup_service, sizeof("ssh-userauth") + 5 - 1); if (rc) { - return libssh2_error(session, rc, - "Unable to ask for ssh-userauth service"); + return _libssh2_error(session, rc, + "Unable to ask for ssh-userauth service"); } session->startup_state = libssh2_NB_state_sent4; @@ -678,8 +678,8 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock) session->startup_service_length)) { LIBSSH2_FREE(session, session->startup_data); session->startup_data = NULL; - return libssh2_error(session, LIBSSH2_ERROR_PROTO, - "Invalid response received from server"); + return _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "Invalid response received from server"); } LIBSSH2_FREE(session, session->startup_data); session->startup_data = NULL; @@ -1004,9 +1004,9 @@ session_disconnect(LIBSSH2_SESSION *session, int reason, LIBSSH2_ALLOC(session, session->disconnect_data_len); if (!session->disconnect_data) { session->disconnect_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "disconnect packet"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for " + "disconnect packet"); } *(s++) = SSH_MSG_DISCONNECT; @@ -1111,14 +1111,14 @@ libssh2_session_methods(LIBSSH2_SESSION * session, int method_type) return ""; default: - libssh2_error(session, LIBSSH2_ERROR_INVAL, - "Invalid parameter specified for method_type"); + _libssh2_error(session, LIBSSH2_ERROR_INVAL, + "Invalid parameter specified for method_type"); return NULL; } if (!method) { - libssh2_error(session, LIBSSH2_ERROR_METHOD_NONE, - "No method negotiated"); + _libssh2_error(session, LIBSSH2_ERROR_METHOD_NONE, + "No method negotiated"); return NULL; } @@ -1358,8 +1358,8 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout) default: if (session) - libssh2_error(session, LIBSSH2_ERROR_INVALID_POLL_TYPE, - "Invalid descriptor passed to libssh2_poll()"); + _libssh2_error(session, LIBSSH2_ERROR_INVALID_POLL_TYPE, + "Invalid descriptor passed to libssh2_poll()"); return -1; } } @@ -1405,8 +1405,8 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout) default: if (session) - libssh2_error(session, LIBSSH2_ERROR_INVALID_POLL_TYPE, - "Invalid descriptor passed to libssh2_poll()"); + _libssh2_error(session, LIBSSH2_ERROR_INVALID_POLL_TYPE, + "Invalid descriptor passed to libssh2_poll()"); return -1; } } diff --git a/src/sftp.c b/src/sftp.c index dee0ed5..8faaa52 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -122,8 +122,8 @@ sftp_packet_add(LIBSSH2_SFTP *sftp, unsigned char *data, (int) data[0], data_len); packet = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_PACKET)); if (!packet) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate datablock for SFTP packet"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate datablock for SFTP packet"); } memset(packet, 0, sizeof(LIBSSH2_PACKET)); @@ -174,22 +174,22 @@ sftp_packet_read(LIBSSH2_SFTP *sftp) /* TODO: this is stupid since we can in fact get 1-3 bytes in a legitimate working case as well if the connection happens to be super slow or something */ - return libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE, - "Read part of packet"); + return _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE, + "Read part of packet"); } packet_len = _libssh2_ntohu32(buffer); _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Data begin - Packet Length: %lu", packet_len); if (packet_len > LIBSSH2_SFTP_PACKET_MAXLEN) { - return libssh2_error(session, LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED, - "SFTP packet too large"); + return _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED, + "SFTP packet too large"); } packet = LIBSSH2_ALLOC(session, packet_len); if (!packet) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate SFTP packet"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate SFTP packet"); } packet_received = 0; @@ -216,8 +216,8 @@ sftp_packet_read(LIBSSH2_SFTP *sftp) } else if (bytes_received < 0) { LIBSSH2_FREE(session, packet); - return libssh2_error(session, bytes_received, - "Receive error waiting for SFTP packet"); + return _libssh2_error(session, bytes_received, + "Receive error waiting for SFTP packet"); } packet_received += bytes_received; } @@ -484,8 +484,8 @@ sftp_bin2attr(LIBSSH2_SFTP_ATTRIBUTES * attrs, const unsigned char *p) } /* ************ - * SFTP API * - ************ */ + * SFTP API * + ************ */ LIBSSH2_CHANNEL_CLOSE_FUNC(libssh2_sftp_dtor); @@ -554,12 +554,12 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0); if (!session->sftpInit_channel) { if (libssh2_session_last_errno(session) == LIBSSH2_ERROR_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block starting up channel"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block starting up channel"); } else { - libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE, - "Unable to startup channel"); + _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE, + "Unable to startup channel"); session->sftpInit_state = libssh2_NB_state_idle; } return NULL; @@ -574,12 +574,12 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) sizeof("subsystem") - 1, "sftp", strlen("sftp")); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block to request SFTP subsystem"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block to request SFTP subsystem"); return NULL; } else if (rc) { - libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE, - "Unable to request SFTP subsystem"); + _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE, + "Unable to request SFTP subsystem"); goto sftp_init_error; } @@ -590,8 +590,8 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) rc = _libssh2_channel_extended_data(session->sftpInit_channel, LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block requesting handle extended data"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block requesting handle extended data"); return NULL; } @@ -599,8 +599,8 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) session->sftpInit_sftp = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_SFTP)); if (!sftp_handle) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate a new SFTP structure"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate a new SFTP structure"); goto sftp_init_error; } memset(sftp_handle, 0, sizeof(LIBSSH2_SFTP)); @@ -626,13 +626,13 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) session->sftpInit_sent, 9 - session->sftpInit_sent); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block sending SSH_FXP_INIT"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block sending SSH_FXP_INIT"); return NULL; } else if(rc < 0) { - libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send SSH_FXP_INIT"); + _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send SSH_FXP_INIT"); goto sftp_init_error; } else { @@ -650,17 +650,17 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) rc = sftp_packet_require(sftp_handle, SSH_FXP_VERSION, 0, &data, &data_len); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block waiting for response from SFTP subsystem"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block waiting for response from SFTP subsystem"); return NULL; } else if (rc) { - libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, - "Timeout waiting for response from SFTP subsystem"); + _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, + "Timeout waiting for response from SFTP subsystem"); goto sftp_init_error; } if (data_len < 5) { - libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, - "Invalid SSH_FXP_VERSION response"); + _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, + "Invalid SSH_FXP_VERSION response"); goto sftp_init_error; } @@ -810,8 +810,8 @@ libssh2_sftp_shutdown(LIBSSH2_SFTP *sftp) } /* ******************************* - * SFTP File and Directory Ops * - ******************************* */ + * SFTP File and Directory Ops * + ******************************* */ /* sftp_open */ @@ -841,9 +841,9 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename, s = sftp->open_packet = LIBSSH2_ALLOC(session, sftp->open_packet_len); if (!sftp->open_packet) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for FXP_OPEN or " - "FXP_OPENDIR packet"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for FXP_OPEN or " + "FXP_OPENDIR packet"); return NULL; } /* Filetype in SFTP 3 and earlier */ @@ -881,16 +881,16 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename, rc = _libssh2_channel_write(channel, 0, (char *) sftp->open_packet, sftp->open_packet_len); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block sending FXP_OPEN or FXP_OPENDIR command"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block sending FXP_OPEN or FXP_OPENDIR command"); return NULL; } else if (sftp->open_packet_len != rc) { /* TODO: partial writes should be fine too and is not a sign of an error when in non-blocking mode! */ - libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send FXP_OPEN or FXP_OPENDIR command"); + _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send FXP_OPEN or FXP_OPENDIR command"); LIBSSH2_FREE(session, sftp->open_packet); sftp->open_packet = NULL; sftp->open_state = libssh2_NB_state_idle; @@ -907,12 +907,12 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename, sftp->open_request_id, &data, &data_len); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block waiting for status message"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block waiting for status message"); return NULL; } else if (rc) { - libssh2_error(session, rc, "Timeout waiting for status message"); + _libssh2_error(session, rc, "Timeout waiting for status message"); sftp->open_state = libssh2_NB_state_idle; return NULL; } @@ -945,8 +945,8 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename, } if(badness) { - libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, - "Failed opening remote file"); + _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, + "Failed opening remote file"); _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "got FXP_STATUS %d", sftp->last_errno); LIBSSH2_FREE(session, data); @@ -956,8 +956,8 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename, fp = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_SFTP_HANDLE)); if (!fp) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate new SFTP handle structure"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate new SFTP handle structure"); LIBSSH2_FREE(session, data); return NULL; } @@ -1101,8 +1101,8 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer, non-blocking mode! */ sftp->read_packet = NULL; sftp->read_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "_libssh2_channel_write() failed"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "_libssh2_channel_write() failed"); } sftp->read_packet = packet; sftp->read_request_id = request_id; @@ -1115,13 +1115,13 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer, sftp_packet_requirev(sftp, 2, read_responses, request_id, &data, &data_len); if (retcode == PACKET_EAGAIN) { - return libssh2_error(session, retcode, - "Would block waiting for status message"); + return _libssh2_error(session, retcode, + "Would block waiting for status message"); } else if (retcode) { sftp->read_packet = NULL; sftp->read_state = libssh2_NB_state_idle; - return libssh2_error(session, retcode, - "Timeout waiting for status message"); + return _libssh2_error(session, retcode, + "Timeout waiting for status message"); } sftp->read_state = libssh2_NB_state_sent1; @@ -1141,8 +1141,8 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer, return total_read; } else { sftp->last_errno = retcode; - return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, - "SFTP Protocol Error"); + return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, + "SFTP Protocol Error"); } case SSH_FXP_DATA: @@ -1260,9 +1260,9 @@ static int sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer, s = sftp->readdir_packet = LIBSSH2_ALLOC(session, packet_len); if (!sftp->readdir_packet) - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "FXP_READDIR packet"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for " + "FXP_READDIR packet"); _libssh2_htonu32(s, packet_len - 4); s += 4; @@ -1291,8 +1291,8 @@ static int sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer, LIBSSH2_FREE(session, sftp->readdir_packet); sftp->readdir_packet = NULL; sftp->readdir_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "_libssh2_channel_write() failed"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "_libssh2_channel_write() failed"); } LIBSSH2_FREE(session, sftp->readdir_packet); @@ -1308,8 +1308,8 @@ static int sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer, return retcode; else if (retcode) { sftp->readdir_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, - "Timeout waiting for status message"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, + "Timeout waiting for status message"); } if (data[0] == SSH_FXP_STATUS) { @@ -1322,8 +1322,8 @@ static int sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer, else { sftp->last_errno = retcode; sftp->readdir_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, - "SFTP Protocol Error"); + return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, + "SFTP Protocol Error"); } } @@ -1395,8 +1395,8 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer, (unsigned long) count); s = sftp->write_packet = LIBSSH2_ALLOC(session, packet_len); if (!sftp->write_packet) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for FXP_WRITE"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for FXP_WRITE"); } _libssh2_htonu32(s, packet_len - 4); s += 4; @@ -1444,8 +1444,8 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer, } else if (rc) { sftp->write_state = libssh2_NB_state_idle; - return libssh2_error(session, rc, - "Timeout waiting for status message"); + return _libssh2_error(session, rc, + "Timeout waiting for status message"); } sftp->write_state = libssh2_NB_state_idle; @@ -1459,8 +1459,8 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer, } sftp->last_errno = retcode; - return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, - "SFTP Protocol Error"); + return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, + "SFTP Protocol Error"); } /* libssh2_sftp_write @@ -1502,9 +1502,9 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle, setstat ? "set-stat" : "stat"); s = sftp->fstat_packet = LIBSSH2_ALLOC(session, packet_len); if (!sftp->fstat_packet) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "FSTAT/FSETSTAT packet"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for " + "FSTAT/FSETSTAT packet"); } _libssh2_htonu32(s, packet_len - 4); @@ -1533,9 +1533,9 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_FREE(session, sftp->fstat_packet); sftp->fstat_packet = NULL; sftp->fstat_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - (setstat ? "Unable to send FXP_FSETSTAT" - : "Unable to send FXP_FSTAT command")); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + (setstat ? "Unable to send FXP_FSETSTAT" + : "Unable to send FXP_FSTAT command")); } LIBSSH2_FREE(session, sftp->fstat_packet); sftp->fstat_packet = NULL; @@ -1550,8 +1550,8 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle, return rc; } else if (rc) { sftp->fstat_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, - "Timeout waiting for status message"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, + "Timeout waiting for status message"); } sftp->fstat_state = libssh2_NB_state_idle; @@ -1565,8 +1565,8 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle, return 0; } else { sftp->last_errno = retcode; - return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, - "SFTP Protocol Error"); + return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, + "SFTP Protocol Error"); } } @@ -1650,9 +1650,9 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle) _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Closing handle"); s = handle->close_packet = LIBSSH2_ALLOC(session, packet_len); if (!handle->close_packet) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for FXP_CLOSE " - "packet"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for FXP_CLOSE " + "packet"); } _libssh2_htonu32(s, packet_len - 4); @@ -1678,8 +1678,8 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle) LIBSSH2_FREE(session, handle->close_packet); handle->close_packet = NULL; handle->close_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send FXP_CLOSE command"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send FXP_CLOSE command"); } LIBSSH2_FREE(session, handle->close_packet); handle->close_packet = NULL; @@ -1695,8 +1695,8 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle) return rc; } else if (rc) { handle->close_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, - "Timeout waiting for status message"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, + "Timeout waiting for status message"); } handle->close_state = libssh2_NB_state_sent1; @@ -1708,8 +1708,8 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle) if (retcode != LIBSSH2_FX_OK) { sftp->last_errno = retcode; handle->close_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, - "SFTP Protocol Error"); + return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, + "SFTP Protocol Error"); } /* remove this handle from the parent's list */ @@ -1759,9 +1759,9 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename, _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Unlinking %s", filename); s = sftp->unlink_packet = LIBSSH2_ALLOC(session, packet_len); if (!sftp->unlink_packet) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for FXP_REMOVE " - "packet"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for FXP_REMOVE " + "packet"); } _libssh2_htonu32(s, packet_len - 4); @@ -1787,8 +1787,8 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename, LIBSSH2_FREE(session, sftp->unlink_packet); sftp->unlink_packet = NULL; sftp->unlink_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send FXP_REMOVE command"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send FXP_REMOVE command"); } LIBSSH2_FREE(session, sftp->unlink_packet); sftp->unlink_packet = NULL; @@ -1804,8 +1804,8 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename, } else if (rc) { sftp->unlink_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, - "Timeout waiting for status message"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, + "Timeout waiting for status message"); } sftp->unlink_state = libssh2_NB_state_idle; @@ -1817,8 +1817,8 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename, return 0; } else { sftp->last_errno = retcode; - return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, - "SFTP Protocol Error"); + return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, + "SFTP Protocol Error"); } } @@ -1858,8 +1858,8 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename, int rc; if (sftp->version < 2) { - return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, - "Server does not support RENAME"); + return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, + "Server does not support RENAME"); } if (sftp->rename_state == libssh2_NB_state_idle) { @@ -1868,9 +1868,9 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename, sftp->rename_s = sftp->rename_packet = LIBSSH2_ALLOC(session, packet_len); if (!sftp->rename_packet) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for FXP_RENAME " - "packet"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for FXP_RENAME " + "packet"); } _libssh2_htonu32(sftp->rename_s, packet_len - 4); @@ -1905,8 +1905,8 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename, LIBSSH2_FREE(session, sftp->rename_packet); sftp->rename_packet = NULL; sftp->rename_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send FXP_RENAME command"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send FXP_RENAME command"); } LIBSSH2_FREE(session, sftp->rename_packet); sftp->rename_packet = NULL; @@ -1921,8 +1921,8 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename, return rc; } else if (rc) { sftp->rename_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, - "Timeout waiting for status message"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, + "Timeout waiting for status message"); } sftp->rename_state = libssh2_NB_state_idle; @@ -1940,19 +1940,19 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename, break; case LIBSSH2_FX_FILE_ALREADY_EXISTS: - retcode = libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, - "File already exists and " - "SSH_FXP_RENAME_OVERWRITE not specified"); + retcode = _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, + "File already exists and " + "SSH_FXP_RENAME_OVERWRITE not specified"); break; case LIBSSH2_FX_OP_UNSUPPORTED: - retcode = libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, - "Operation Not Supported"); + retcode = _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, + "Operation Not Supported"); break; default: - retcode = libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, - "SFTP Protocol Error"); + retcode = _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, + "SFTP Protocol Error"); break; } @@ -2000,9 +2000,9 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path, "Creating directory %s with mode 0%lo", path, mode); s = packet = LIBSSH2_ALLOC(session, packet_len); if (!packet) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for FXP_MKDIR " - "packet"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for FXP_MKDIR " + "packet"); } /* Filetype in SFTP 3 and earlier */ attrs.permissions = mode | LIBSSH2_SFTP_ATTR_PFILETYPE_DIR; @@ -2034,8 +2034,8 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path, if (packet_len != rc) { LIBSSH2_FREE(session, packet); sftp->mkdir_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "_libssh2_channel_write() failed"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "_libssh2_channel_write() failed"); } LIBSSH2_FREE(session, packet); sftp->mkdir_state = libssh2_NB_state_sent; @@ -2048,8 +2048,8 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path, return rc; } else if (rc) { sftp->mkdir_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, - "Timeout waiting for status message"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, + "Timeout waiting for status message"); } sftp->mkdir_state = libssh2_NB_state_idle; @@ -2062,8 +2062,8 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path, return 0; } else { sftp->last_errno = retcode; - return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, - "SFTP Protocol Error"); + return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, + "SFTP Protocol Error"); } } @@ -2102,9 +2102,9 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path, path); s = sftp->rmdir_packet = LIBSSH2_ALLOC(session, packet_len); if (!sftp->rmdir_packet) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for FXP_RMDIR " - "packet"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for FXP_RMDIR " + "packet"); } _libssh2_htonu32(s, packet_len - 4); @@ -2130,8 +2130,8 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path, LIBSSH2_FREE(session, sftp->rmdir_packet); sftp->rmdir_packet = NULL; sftp->rmdir_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send FXP_RMDIR command"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send FXP_RMDIR command"); } LIBSSH2_FREE(session, sftp->rmdir_packet); sftp->rmdir_packet = NULL; @@ -2145,8 +2145,8 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path, return rc; } else if (rc) { sftp->rmdir_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, - "Timeout waiting for status message"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, + "Timeout waiting for status message"); } sftp->rmdir_state = libssh2_NB_state_idle; @@ -2158,8 +2158,8 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path, return 0; } else { sftp->last_errno = retcode; - return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, - "SFTP Protocol Error"); + return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, + "SFTP Protocol Error"); } } @@ -2203,9 +2203,9 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path, LIBSSH2_SFTP_LSTAT ? "LStatting" : "Statting"), path); s = sftp->stat_packet = LIBSSH2_ALLOC(session, packet_len); if (!sftp->stat_packet) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for FXP_*STAT " - "packet"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for FXP_*STAT " + "packet"); } _libssh2_htonu32(s, packet_len - 4); @@ -2246,8 +2246,8 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path, LIBSSH2_FREE(session, sftp->stat_packet); sftp->stat_packet = NULL; sftp->stat_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send STAT/LSTAT/SETSTAT command"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send STAT/LSTAT/SETSTAT command"); } LIBSSH2_FREE(session, sftp->stat_packet); sftp->stat_packet = NULL; @@ -2261,8 +2261,8 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path, return rc; } else if (rc) { sftp->stat_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, - "Timeout waiting for status message"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, + "Timeout waiting for status message"); } sftp->stat_state = libssh2_NB_state_idle; @@ -2276,8 +2276,8 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path, return 0; } else { sftp->last_errno = retcode; - return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, - "SFTP Protocol Error"); + return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, + "SFTP Protocol Error"); } } @@ -2322,16 +2322,16 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path, int rc; if ((sftp->version < 3) && (link_type != LIBSSH2_SFTP_REALPATH)) { - return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, - "Server does not support SYMLINK or READLINK"); + return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, + "Server does not support SYMLINK or READLINK"); } if (sftp->symlink_state == libssh2_NB_state_idle) { s = sftp->symlink_packet = LIBSSH2_ALLOC(session, packet_len); if (!sftp->symlink_packet) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "SYMLINK/READLINK/REALPATH packet"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for " + "SYMLINK/READLINK/REALPATH packet"); } _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "%s %s on %s", @@ -2381,8 +2381,8 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path, LIBSSH2_FREE(session, sftp->symlink_packet); sftp->symlink_packet = NULL; sftp->symlink_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send SYMLINK/READLINK command"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send SYMLINK/READLINK command"); } LIBSSH2_FREE(session, sftp->symlink_packet); sftp->symlink_packet = NULL; @@ -2398,8 +2398,8 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path, } else if (rc) { sftp->symlink_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, - "Timeout waiting for status message"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, + "Timeout waiting for status message"); } sftp->symlink_state = libssh2_NB_state_idle; @@ -2413,16 +2413,16 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path, return 0; } else { sftp->last_errno = retcode; - return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, - "SFTP Protocol Error"); + return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, + "SFTP Protocol Error"); } } if (_libssh2_ntohu32(data + 5) < 1) { LIBSSH2_FREE(session, data); - return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, - "Invalid READLINK/REALPATH response, " - "no name entries"); + return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, + "Invalid READLINK/REALPATH response, " + "no name entries"); } link_len = _libssh2_ntohu32(data + 9); @@ -2459,5 +2459,3 @@ libssh2_sftp_last_error(LIBSSH2_SFTP *sftp) { return sftp->last_errno; } - - diff --git a/src/transport.c b/src/transport.c index 575a44b..7d96545 100644 --- a/src/transport.c +++ b/src/transport.c @@ -47,7 +47,7 @@ #include "transport.h" -#define MAX_BLOCKSIZE 32 /* MUST fit biggest crypto block size we use/get */ +#define MAX_BLOCKSIZE 32 /* MUST fit biggest crypto block size we use/get */ #define MAX_MACSIZE 20 /* MUST fit biggest MAC length we support */ #ifdef LIBSSH2DEBUG @@ -71,7 +71,8 @@ debugdump(LIBSSH2_SESSION * session, used = snprintf(buffer, sizeof(buffer), "=> %s (%d bytes)\n", desc, (int) size); if (session->tracehandler) - (session->tracehandler)(session, session->tracehandler_context, buffer, used); + (session->tracehandler)(session, session->tracehandler_context, + buffer, used); else write(2 /* stderr */, buffer, used); @@ -106,7 +107,8 @@ debugdump(LIBSSH2_SESSION * session, buffer[used] = 0; if (session->tracehandler) - (session->tracehandler)(session, session->tracehandler_context, buffer, used); + (session->tracehandler)(session, session->tracehandler_context, + buffer, used); else write(2, buffer, used); } @@ -274,7 +276,7 @@ fullpacket(LIBSSH2_SESSION * session, int encrypted /* 1 or 0 */ ) * This function reads the binary stream as specified in chapter 6 of RFC4253 * "The Secure Shell (SSH) Transport Layer Protocol" * - * DOES NOT call libssh2_error() for ANY error case. + * DOES NOT call _libssh2_error() for ANY error case. */ int _libssh2_transport_read(LIBSSH2_SESSION * session) { @@ -693,7 +695,7 @@ send_existing(LIBSSH2_SESSION * session, unsigned char *data, * which is what all implementations should support at least as packet size. * (RFC4253 section 6.1) * - * This function DOES not call libssh2_error() on any errors. + * This function DOES not call _libssh2_error() on any errors. */ int _libssh2_transport_write(LIBSSH2_SESSION * session, unsigned char *data, diff --git a/src/userauth.c b/src/userauth.c index 993bc00..da09927 100644 --- a/src/userauth.c +++ b/src/userauth.c @@ -78,8 +78,8 @@ static char *userauth_list(LIBSSH2_SESSION *session, const char *username, s = session->userauth_list_data = LIBSSH2_ALLOC(session, session->userauth_list_data_len); if (!session->userauth_list_data) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for userauth_list"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for userauth_list"); return NULL; } @@ -108,8 +108,8 @@ static char *userauth_list(LIBSSH2_SESSION *session, const char *username, rc = _libssh2_transport_write(session, session->userauth_list_data, session->userauth_list_data_len); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block requesting userauth list"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block requesting userauth list"); return NULL; } /* now free the packet that was sent */ @@ -117,8 +117,8 @@ static char *userauth_list(LIBSSH2_SESSION *session, const char *username, session->userauth_list_data = NULL; if (rc) { - libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send userauth-none request"); + _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send userauth-none request"); session->userauth_list_state = libssh2_NB_state_idle; return NULL; } @@ -133,18 +133,18 @@ static char *userauth_list(LIBSSH2_SESSION *session, const char *username, NULL, 0, &session->userauth_list_packet_requirev_state); if (rc == PACKET_EAGAIN) { - libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block requesting userauth list"); + _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block requesting userauth list"); return NULL; } else if (rc) { - libssh2_error(session, rc, "Failed getting response"); + _libssh2_error(session, rc, "Failed getting response"); session->userauth_list_state = libssh2_NB_state_idle; return NULL; } if (session->userauth_list_data[0] == SSH_MSG_USERAUTH_SUCCESS) { /* Wow, who'dve thought... */ - libssh2_error(session, LIBSSH2_ERROR_NONE, "No error"); + _libssh2_error(session, LIBSSH2_ERROR_NONE, "No error"); LIBSSH2_FREE(session, session->userauth_list_data); session->userauth_list_data = NULL; session->state |= LIBSSH2_STATE_AUTHENTICATED; @@ -230,9 +230,9 @@ userauth_password(LIBSSH2_SESSION *session, const char *username, s = session->userauth_pswd_data = LIBSSH2_ALLOC(session, session->userauth_pswd_data_len); if (!session->userauth_pswd_data) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "userauth-password request"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for " + "userauth-password request"); } *(s++) = SSH_MSG_USERAUTH_REQUEST; @@ -269,8 +269,8 @@ 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 libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block writing password request"); + return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block writing password request"); } /* now free the sent packet */ @@ -279,8 +279,8 @@ userauth_password(LIBSSH2_SESSION *session, const char *username, if (rc) { session->userauth_pswd_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send userauth-password request"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send userauth-password request"); } session->userauth_pswd_state = libssh2_NB_state_sent; @@ -299,12 +299,12 @@ userauth_password(LIBSSH2_SESSION *session, const char *username, &session-> userauth_pswd_packet_requirev_state); if (rc == PACKET_EAGAIN) { - return libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block waiting"); + return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block waiting"); } else if (rc) { session->userauth_pswd_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_TIMEOUT, - "Would block waiting"); + return _libssh2_error(session, LIBSSH2_ERROR_TIMEOUT, + "Would block waiting"); } if (session->userauth_pswd_data[0] == SSH_MSG_USERAUTH_SUCCESS) { @@ -321,10 +321,10 @@ userauth_password(LIBSSH2_SESSION *session, const char *username, LIBSSH2_FREE(session, session->userauth_pswd_data); session->userauth_pswd_data = NULL; session->userauth_pswd_state = libssh2_NB_state_idle; - return libssh2_error(session, - LIBSSH2_ERROR_AUTHENTICATION_FAILED, - "Authentication failed " - "(username/password)"); + return _libssh2_error(session, + LIBSSH2_ERROR_AUTHENTICATION_FAILED, + "Authentication failed " + "(username/password)"); } session->userauth_pswd_newpw = NULL; @@ -354,10 +354,10 @@ userauth_password(LIBSSH2_SESSION *session, const char *username, &session->userauth_pswd_newpw_len, &session->abstract); if (!session->userauth_pswd_newpw) { - return libssh2_error(session, - LIBSSH2_ERROR_PASSWORD_EXPIRED, - "Password expired, and " - "callback failed"); + return _libssh2_error(session, + LIBSSH2_ERROR_PASSWORD_EXPIRED, + "Password expired, and " + "callback failed"); } /* basic data_len + newpw_len(4) */ @@ -372,10 +372,10 @@ userauth_password(LIBSSH2_SESSION *session, const char *username, LIBSSH2_FREE(session, session->userauth_pswd_newpw); session->userauth_pswd_newpw = NULL; - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory " - "for userauth password " - "change request"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory " + "for userauth password " + "change request"); } *(s++) = SSH_MSG_USERAUTH_REQUEST; @@ -418,8 +418,8 @@ userauth_password(LIBSSH2_SESSION *session, const char *username, session-> userauth_pswd_data_len); if (rc == PACKET_EAGAIN) { - return libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block waiting"); + return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block waiting"); } /* free the allocated packets again */ @@ -429,10 +429,10 @@ userauth_password(LIBSSH2_SESSION *session, const char *username, session->userauth_pswd_newpw = NULL; if (rc) { - return libssh2_error(session, - LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send userauth " - "password-change request"); + return _libssh2_error(session, + LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send userauth " + "password-change request"); } /* @@ -445,9 +445,9 @@ userauth_password(LIBSSH2_SESSION *session, const char *username, } } else { session->userauth_pswd_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_PASSWORD_EXPIRED, - "Password Expired, and no callback " - "specified"); + return _libssh2_error(session, LIBSSH2_ERROR_PASSWORD_EXPIRED, + "Password Expired, and no callback " + "specified"); } } } @@ -457,8 +457,8 @@ userauth_password(LIBSSH2_SESSION *session, const char *username, session->userauth_pswd_data = NULL; session->userauth_pswd_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_AUTHENTICATION_FAILED, - "Authentication failed"); + return _libssh2_error(session, LIBSSH2_ERROR_AUTHENTICATION_FAILED, + "Authentication failed"); } /* @@ -509,8 +509,8 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method, /* Read Public Key */ fd = fopen(pubkeyfile, "r"); if (!fd) { - return libssh2_error(session, LIBSSH2_ERROR_FILE, - "Unable to open public key file"); + return _libssh2_error(session, LIBSSH2_ERROR_FILE, + "Unable to open public key file"); } while (!feof(fd) && (c = fgetc(fd)) != '\r' && c != '\n') pubkey_len++; @@ -522,21 +522,21 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method, if (pubkey_len <= 1) { fclose(fd); - return libssh2_error(session, LIBSSH2_ERROR_FILE, - "Invalid data in public key file"); + return _libssh2_error(session, LIBSSH2_ERROR_FILE, + "Invalid data in public key file"); } pubkey = LIBSSH2_ALLOC(session, pubkey_len); if (!pubkey) { fclose(fd); - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for public key data"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for public key data"); } if (fread(pubkey, 1, pubkey_len, fd) != pubkey_len) { LIBSSH2_FREE(session, pubkey); fclose(fd); - return libssh2_error(session, LIBSSH2_ERROR_FILE, - "Unable to read public key from file"); + return _libssh2_error(session, LIBSSH2_ERROR_FILE, + "Unable to read public key from file"); } fclose(fd); /* @@ -547,14 +547,14 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method, if (!pubkey_len) { LIBSSH2_FREE(session, pubkey); - return libssh2_error(session, LIBSSH2_ERROR_FILE, - "Missing public key data"); + return _libssh2_error(session, LIBSSH2_ERROR_FILE, + "Missing public key data"); } if ((sp1 = memchr(pubkey, ' ', pubkey_len)) == NULL) { LIBSSH2_FREE(session, pubkey); - return libssh2_error(session, LIBSSH2_ERROR_FILE, - "Invalid public key data"); + return _libssh2_error(session, LIBSSH2_ERROR_FILE, + "Invalid public key data"); } sp1++; @@ -567,8 +567,8 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method, if (libssh2_base64_decode(session, (char **) &tmp, &tmp_len, (char *) sp1, sp2 - sp1)) { LIBSSH2_FREE(session, pubkey); - return libssh2_error(session, LIBSSH2_ERROR_FILE, - "Invalid key data, not base64 encoded"); + return _libssh2_error(session, LIBSSH2_ERROR_FILE, + "Invalid key data, not base64 encoded"); } /* Wasting some bytes here (okay, more than some), but since it's likely @@ -612,15 +612,15 @@ file_read_privatekey(LIBSSH2_SESSION * session, hostkey_methods_avail++; } if (!*hostkey_method) { - return libssh2_error(session, LIBSSH2_ERROR_METHOD_NONE, - "No handler for specified private key"); + return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NONE, + "No handler for specified private key"); } if ((*hostkey_method)-> initPEM(session, privkeyfile, (unsigned char *) passphrase, hostkey_abstract)) { - return libssh2_error(session, LIBSSH2_ERROR_FILE, - "Unable to initialize private key from file"); + return _libssh2_error(session, LIBSSH2_ERROR_FILE, + "Unable to initialize private key from file"); } return 0; @@ -700,7 +700,7 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session, &pubkeydata, &pubkeydata_len, publickey); if(rc) - /* Note: file_read_publickey() calls libssh2_error() */ + /* Note: file_read_publickey() calls _libssh2_error() */ return rc; /* @@ -727,8 +727,8 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session, LIBSSH2_FREE(session, session->userauth_host_method); session->userauth_host_method = NULL; LIBSSH2_FREE(session, pubkeydata); - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Out of memory"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Out of memory"); } *(session->userauth_host_s++) = SSH_MSG_USERAUTH_REQUEST; @@ -777,7 +777,7 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session, session->userauth_host_method_len, privatekey, passphrase); if(rc) { - /* Note: file_read_privatekey() calls libssh2_error() */ + /* Note: file_read_privatekey() calls _libssh2_error() */ LIBSSH2_FREE(session, session->userauth_host_method); session->userauth_host_method = NULL; LIBSSH2_FREE(session, session->userauth_host_packet); @@ -821,9 +821,9 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session, session->userauth_host_packet = NULL; LIBSSH2_FREE(session, session->userauth_host_method); session->userauth_host_method = NULL; - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Failed allocating additional space for " - "userauth-hostbased packet"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Failed allocating additional space for " + "userauth-hostbased packet"); } session->userauth_host_packet = newpacket; } @@ -861,14 +861,14 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session, session->userauth_host_s - session->userauth_host_packet); if (rc == PACKET_EAGAIN) { - return libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); + return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); } else if (rc) { LIBSSH2_FREE(session, session->userauth_host_packet); session->userauth_host_packet = NULL; session->userauth_host_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send userauth-hostbased request"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send userauth-hostbased request"); } LIBSSH2_FREE(session, session->userauth_host_packet); session->userauth_host_packet = NULL; @@ -886,13 +886,13 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session, &session-> userauth_host_packet_requirev_state); if (rc == PACKET_EAGAIN) { - return libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); + return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); } session->userauth_host_state = libssh2_NB_state_idle; if (rc) { - return libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, - "Auth failed"); + return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, + "Auth failed"); } if (session->userauth_host_data[0] == SSH_MSG_USERAUTH_SUCCESS) { @@ -909,9 +909,9 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session, /* This public key is not allowed for this user on this server */ LIBSSH2_FREE(session, session->userauth_host_data); session->userauth_host_data = NULL; - return libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, - "Invalid signature for supplied public key, or bad " - "username/public key combination"); + return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, + "Invalid signature for supplied public key, or bad " + "username/public key combination"); } /* libssh2_userauth_hostbased_fromfile_ex @@ -971,9 +971,9 @@ userauth_publickey(LIBSSH2_SESSION *session, session->userauth_pblc_method = LIBSSH2_ALLOC(session, session->userauth_pblc_method_len); if (!session->userauth_pblc_method) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for public key " - "data"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for public key " + "data"); } memcpy(session->userauth_pblc_method, pubkeydata + 4, session->userauth_pblc_method_len); @@ -1004,8 +1004,8 @@ userauth_publickey(LIBSSH2_SESSION *session, if (!session->userauth_pblc_packet) { LIBSSH2_FREE(session, session->userauth_pblc_method); session->userauth_pblc_method = NULL; - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Out of memory"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Out of memory"); } *(session->userauth_pblc_s++) = SSH_MSG_USERAUTH_REQUEST; @@ -1050,15 +1050,15 @@ userauth_publickey(LIBSSH2_SESSION *session, rc = _libssh2_transport_write(session, session->userauth_pblc_packet, session->userauth_pblc_packet_len); if (rc == PACKET_EAGAIN) - return libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); + return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); else if (rc) { LIBSSH2_FREE(session, session->userauth_pblc_packet); session->userauth_pblc_packet = NULL; LIBSSH2_FREE(session, session->userauth_pblc_method); session->userauth_pblc_method = NULL; session->userauth_pblc_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send userauth-publickey request"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send userauth-publickey request"); } session->userauth_pblc_state = libssh2_NB_state_sent; @@ -1072,7 +1072,7 @@ userauth_publickey(LIBSSH2_SESSION *session, &session-> userauth_pblc_packet_requirev_state); if (rc == PACKET_EAGAIN) { - return libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); + return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); } else if (rc) { LIBSSH2_FREE(session, session->userauth_pblc_packet); @@ -1080,8 +1080,8 @@ userauth_publickey(LIBSSH2_SESSION *session, LIBSSH2_FREE(session, session->userauth_pblc_method); session->userauth_pblc_method = NULL; session->userauth_pblc_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, - "Failed waiting"); + return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, + "Failed waiting"); } if (session->userauth_pblc_data[0] == SSH_MSG_USERAUTH_SUCCESS) { @@ -1111,8 +1111,8 @@ userauth_publickey(LIBSSH2_SESSION *session, LIBSSH2_FREE(session, session->userauth_pblc_method); session->userauth_pblc_method = NULL; session->userauth_pblc_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_AUTHENTICATION_FAILED, - "Username/PublicKey combination invalid"); + return _libssh2_error(session, LIBSSH2_ERROR_AUTHENTICATION_FAILED, + "Username/PublicKey combination invalid"); } /* Semi-Success! */ @@ -1131,9 +1131,9 @@ userauth_publickey(LIBSSH2_SESSION *session, s = buf = LIBSSH2_ALLOC(session, 4 + session->session_id_len + session->userauth_pblc_packet_len); if (!buf) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "userauth-publickey signed data"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for " + "userauth-publickey signed data"); } _libssh2_htonu32(s, session->session_id_len); @@ -1147,15 +1147,15 @@ userauth_publickey(LIBSSH2_SESSION *session, rc = sign_callback(session, &sig, &sig_len, buf, s - buf, abstract); LIBSSH2_FREE(session, buf); if (rc == PACKET_EAGAIN) { - return libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); + return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); } else if (rc) { LIBSSH2_FREE(session, session->userauth_pblc_method); session->userauth_pblc_method = NULL; LIBSSH2_FREE(session, session->userauth_pblc_packet); session->userauth_pblc_packet = NULL; session->userauth_pblc_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, - "Callback returned error"); + return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, + "Callback returned error"); } /* @@ -1177,9 +1177,9 @@ userauth_publickey(LIBSSH2_SESSION *session, LIBSSH2_FREE(session, session->userauth_pblc_method); session->userauth_pblc_method = NULL; session->userauth_pblc_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Failed allocating additional space for " - "userauth-publickey packet"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Failed allocating additional space for " + "userauth-publickey packet"); } session->userauth_pblc_packet = newpacket; } @@ -1218,13 +1218,13 @@ userauth_publickey(LIBSSH2_SESSION *session, session->userauth_pblc_s - session->userauth_pblc_packet); if (rc == PACKET_EAGAIN) { - return libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); + return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); } else if (rc) { LIBSSH2_FREE(session, session->userauth_pblc_packet); session->userauth_pblc_packet = NULL; session->userauth_pblc_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send userauth-publickey request"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send userauth-publickey request"); } LIBSSH2_FREE(session, session->userauth_pblc_packet); session->userauth_pblc_packet = NULL; @@ -1240,12 +1240,12 @@ userauth_publickey(LIBSSH2_SESSION *session, &session->userauth_pblc_data_len, 0, NULL, 0, &session->userauth_pblc_packet_requirev_state); if (rc == PACKET_EAGAIN) { - return libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block requesting userauth list"); + return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block requesting userauth list"); } else if (rc) { session->userauth_pblc_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, - "Failed waiting"); + return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, + "Failed waiting"); } if (session->userauth_pblc_data[0] == SSH_MSG_USERAUTH_SUCCESS) { @@ -1263,9 +1263,9 @@ userauth_publickey(LIBSSH2_SESSION *session, LIBSSH2_FREE(session, session->userauth_pblc_data); session->userauth_pblc_data = NULL; session->userauth_pblc_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, - "Invalid signature for supplied public key, or bad " - "username/public key combination"); + return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, + "Invalid signature for supplied public key, or bad " + "username/public key combination"); } /* @@ -1399,9 +1399,9 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session, session->userauth_kybd_data = s = LIBSSH2_ALLOC(session, session->userauth_kybd_packet_len); if (!s) { - return libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "keyboard-interactive authentication"); + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for " + "keyboard-interactive authentication"); } *s++ = SSH_MSG_USERAUTH_REQUEST; @@ -1442,13 +1442,13 @@ 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 libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); + return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); } else if (rc) { LIBSSH2_FREE(session, session->userauth_kybd_data); session->userauth_kybd_data = NULL; session->userauth_kybd_state = libssh2_NB_state_idle; - return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send keyboard-interactive request"); + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send keyboard-interactive request"); } LIBSSH2_FREE(session, session->userauth_kybd_data); session->userauth_kybd_data = NULL; @@ -1465,13 +1465,13 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session, &session-> userauth_kybd_packet_requirev_state); if (rc == PACKET_EAGAIN) { - return libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block"); + return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block"); } else if (rc) { session->userauth_kybd_state = libssh2_NB_state_idle; - return libssh2_error(session, - LIBSSH2_ERROR_AUTHENTICATION_FAILED, - "Failed waiting"); + return _libssh2_error(session, + LIBSSH2_ERROR_AUTHENTICATION_FAILED, + "Failed waiting"); } if (session->userauth_kybd_data[0] == SSH_MSG_USERAUTH_SUCCESS) { @@ -1490,10 +1490,10 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session, LIBSSH2_FREE(session, session->userauth_kybd_data); session->userauth_kybd_data = NULL; session->userauth_kybd_state = libssh2_NB_state_idle; - return libssh2_error(session, - LIBSSH2_ERROR_AUTHENTICATION_FAILED, - "Authentication failed " - "(keyboard-interactive)"); + return _libssh2_error(session, + LIBSSH2_ERROR_AUTHENTICATION_FAILED, + "Authentication failed " + "(keyboard-interactive)"); } /* server requested PAM-like conversation */ @@ -1506,9 +1506,9 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session, session->userauth_kybd_auth_name = LIBSSH2_ALLOC(session, session->userauth_kybd_auth_name_len); if (!session->userauth_kybd_auth_name) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "keyboard-interactive 'name' request field"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for " + "keyboard-interactive 'name' request field"); goto cleanup; } memcpy(session->userauth_kybd_auth_name, s, @@ -1522,10 +1522,10 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session, LIBSSH2_ALLOC(session, session->userauth_kybd_auth_instruction_len); if (!session->userauth_kybd_auth_instruction) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "keyboard-interactive 'instruction' " - "request field"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for " + "keyboard-interactive 'instruction' " + "request field"); goto cleanup; } memcpy(session->userauth_kybd_auth_instruction, s, @@ -1547,9 +1547,9 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session, sizeof(LIBSSH2_USERAUTH_KBDINT_PROMPT) * session->userauth_kybd_num_prompts); if (!session->userauth_kybd_prompts) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "keyboard-interactive prompts array"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for " + "keyboard-interactive prompts array"); goto cleanup; } memset(session->userauth_kybd_prompts, 0, @@ -1561,9 +1561,9 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session, sizeof(LIBSSH2_USERAUTH_KBDINT_RESPONSE) * session->userauth_kybd_num_prompts); if (!session->userauth_kybd_responses) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "keyboard-interactive responses array"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for " + "keyboard-interactive responses array"); goto cleanup; } memset(session->userauth_kybd_responses, 0, @@ -1578,9 +1578,9 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session, LIBSSH2_ALLOC(session, session->userauth_kybd_prompts[i].length); if (!session->userauth_kybd_prompts[i].text) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for " - "keyboard-interactive prompt message"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for " + "keyboard-interactive prompt message"); goto cleanup; } memcpy(session->userauth_kybd_prompts[i].text, s, @@ -1622,9 +1622,9 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session, session->userauth_kybd_data = s = LIBSSH2_ALLOC(session, session->userauth_kybd_packet_len); if (!s) { - libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "Unable to allocate memory for keyboard-" - "interactive response packet"); + _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "Unable to allocate memory for keyboard-" + "interactive response packet"); goto cleanup; } @@ -1648,13 +1648,13 @@ 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 libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block"); + return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, + "Would block"); } if (rc) { - libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, - "Unable to send userauth-keyboard-interactive" - " request"); + _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, + "Unable to send userauth-keyboard-interactive" + " request"); goto cleanup; }