rename libssh2_error to the correct _libssh2_error

We reserve ^libssh2_ for public symbols and we use _libssh2 as
prefix for internal ones. I fixed the intendation of all these
edits with emacs afterwards, which then changed it slightly more
than just _libssh2_error() expressions but I didn't see any
obvious problems.
This commit is contained in:
Daniel Stenberg 2010-04-16 00:18:51 +02:00
parent 9cc824e27b
commit 1adcb5234f
17 changed files with 1083 additions and 1083 deletions

View File

@ -618,7 +618,7 @@ libssh2_agent_init(LIBSSH2_SESSION *session)
agent = LIBSSH2_ALLOC(session, sizeof *agent); agent = LIBSSH2_ALLOC(session, sizeof *agent);
if (!agent) { if (!agent) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate space for agent connection"); "Unable to allocate space for agent connection");
return NULL; return NULL;
} }

View File

@ -1,5 +1,5 @@
/* Copyright (c) 2004-2007 Sara Golemon <sarag@libssh2.org> /* Copyright (c) 2004-2007 Sara Golemon <sarag@libssh2.org>
* Copyright (c) 2008-2009 by Daniel Stenberg * Copyright (c) 2008-2010 by Daniel Stenberg
* *
* All rights reserved. * All rights reserved.
* *
@ -155,7 +155,7 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type,
session->open_channel = session->open_channel =
LIBSSH2_ALLOC(session, sizeof(LIBSSH2_CHANNEL)); LIBSSH2_ALLOC(session, sizeof(LIBSSH2_CHANNEL));
if (!session->open_channel) { if (!session->open_channel) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate space for channel data"); "Unable to allocate space for channel data");
return NULL; return NULL;
} }
@ -165,7 +165,7 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type,
session->open_channel->channel_type = session->open_channel->channel_type =
LIBSSH2_ALLOC(session, channel_type_len); LIBSSH2_ALLOC(session, channel_type_len);
if (!session->open_channel->channel_type) { if (!session->open_channel->channel_type) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Failed allocating memory for channel type name"); "Failed allocating memory for channel type name");
LIBSSH2_FREE(session, session->open_channel); LIBSSH2_FREE(session, session->open_channel);
session->open_channel = NULL; session->open_channel = NULL;
@ -187,7 +187,7 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type,
s = session->open_packet = s = session->open_packet =
LIBSSH2_ALLOC(session, session->open_packet_len); LIBSSH2_ALLOC(session, session->open_packet_len);
if (!session->open_packet) { if (!session->open_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate temporary space for packet"); "Unable to allocate temporary space for packet");
goto channel_error; goto channel_error;
} }
@ -219,11 +219,11 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type,
rc = _libssh2_transport_write(session, session->open_packet, rc = _libssh2_transport_write(session, session->open_packet,
session->open_packet_len); session->open_packet_len);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending channel-open request"); "Would block sending channel-open request");
return NULL; return NULL;
} else if (rc) { } else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send channel-open request"); "Unable to send channel-open request");
goto channel_error; goto channel_error;
} }
@ -239,7 +239,7 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type,
channel_type_len, 4, channel_type_len, 4,
&session->open_packet_requirev_state); &session->open_packet_requirev_state);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block");
return NULL; return NULL;
} else if (rc) { } else if (rc) {
goto channel_error; goto channel_error;
@ -273,7 +273,7 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type,
} }
if (session->open_data[0] == SSH_MSG_CHANNEL_OPEN_FAILURE) { if (session->open_data[0] == SSH_MSG_CHANNEL_OPEN_FAILURE) {
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE, _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE,
"Channel open failure"); "Channel open failure");
} }
} }
@ -368,7 +368,7 @@ channel_direct_tcpip(LIBSSH2_SESSION * session, const char *host,
s = session->direct_message = s = session->direct_message =
LIBSSH2_ALLOC(session, session->direct_message_len); LIBSSH2_ALLOC(session, session->direct_message_len);
if (!session->direct_message) { if (!session->direct_message) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for direct-tcpip connection"); "Unable to allocate memory for direct-tcpip connection");
return NULL; return NULL;
} }
@ -461,7 +461,7 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
s = session->fwdLstn_packet = s = session->fwdLstn_packet =
LIBSSH2_ALLOC(session, session->fwdLstn_packet_len); LIBSSH2_ALLOC(session, session->fwdLstn_packet_len);
if (!session->fwdLstn_packet) { if (!session->fwdLstn_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memeory for setenv packet"); "Unable to allocate memeory for setenv packet");
return NULL; return NULL;
} }
@ -487,12 +487,12 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
rc = _libssh2_transport_write(session, session->fwdLstn_packet, rc = _libssh2_transport_write(session, session->fwdLstn_packet,
session->fwdLstn_packet_len); session->fwdLstn_packet_len);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending global-request packet for " "Would block sending global-request packet for "
"forward listen request"); "forward listen request");
return NULL; return NULL;
} else if (rc) { } else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send global-request packet for forward " "Unable to send global-request packet for forward "
"listen request"); "listen request");
LIBSSH2_FREE(session, session->fwdLstn_packet); LIBSSH2_FREE(session, session->fwdLstn_packet);
@ -511,10 +511,10 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
0, NULL, 0, 0, NULL, 0,
&session->fwdLstn_packet_requirev_state); &session->fwdLstn_packet_requirev_state);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block"); _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block");
return NULL; return NULL;
} else if (rc) { } else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_PROTO, "Unknown"); _libssh2_error(session, LIBSSH2_ERROR_PROTO, "Unknown");
session->fwdLstn_state = libssh2_NB_state_idle; session->fwdLstn_state = libssh2_NB_state_idle;
return NULL; return NULL;
} }
@ -524,7 +524,7 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
listener = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_LISTENER)); listener = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_LISTENER));
if (!listener) { if (!listener) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for listener queue"); "Unable to allocate memory for listener queue");
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
session->fwdLstn_state = libssh2_NB_state_idle; session->fwdLstn_state = libssh2_NB_state_idle;
@ -535,7 +535,7 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
listener->host = listener->host =
LIBSSH2_ALLOC(session, session->fwdLstn_host_len + 1); LIBSSH2_ALLOC(session, session->fwdLstn_host_len + 1);
if (!listener->host) { if (!listener->host) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for listener queue"); "Unable to allocate memory for listener queue");
LIBSSH2_FREE(session, listener); LIBSSH2_FREE(session, listener);
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
@ -571,7 +571,7 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
if (data[0] == SSH_MSG_REQUEST_FAILURE) { if (data[0] == SSH_MSG_REQUEST_FAILURE) {
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
libssh2_error(session, LIBSSH2_ERROR_REQUEST_DENIED, _libssh2_error(session, LIBSSH2_ERROR_REQUEST_DENIED,
"Unable to complete request for forward-listen"); "Unable to complete request for forward-listen");
session->fwdLstn_state = libssh2_NB_state_idle; session->fwdLstn_state = libssh2_NB_state_idle;
return NULL; return NULL;
@ -626,7 +626,7 @@ static int channel_forward_cancel(LIBSSH2_LISTENER *listener)
s = packet = LIBSSH2_ALLOC(session, packet_len); s = packet = LIBSSH2_ALLOC(session, packet_len);
if (!packet) { if (!packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memeory for setenv packet"); "Unable to allocate memeory for setenv packet");
return LIBSSH2_ERROR_ALLOC; return LIBSSH2_ERROR_ALLOC;
} }
@ -657,7 +657,7 @@ static int channel_forward_cancel(LIBSSH2_LISTENER *listener)
return rc; return rc;
} }
else if (rc) { else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send global-request packet for forward " "Unable to send global-request packet for forward "
"listen request"); "listen request");
LIBSSH2_FREE(session, packet); LIBSSH2_FREE(session, packet);
@ -736,11 +736,11 @@ channel_forward_accept(LIBSSH2_LISTENER *listener)
} }
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(listener->session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(listener->session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for packet"); "Would block waiting for packet");
} }
else else
libssh2_error(listener->session, LIBSSH2_ERROR_CHANNEL_UNKNOWN, _libssh2_error(listener->session, LIBSSH2_ERROR_CHANNEL_UNKNOWN,
"Channel not found"); "Channel not found");
return NULL; return NULL;
} }
@ -793,7 +793,7 @@ static int channel_setenv(LIBSSH2_CHANNEL *channel,
s = channel->setenv_packet = s = channel->setenv_packet =
LIBSSH2_ALLOC(session, channel->setenv_packet_len); LIBSSH2_ALLOC(session, channel->setenv_packet_len);
if (!channel->setenv_packet) { if (!channel->setenv_packet) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memeory " "Unable to allocate memeory "
"for setenv packet"); "for setenv packet");
} }
@ -830,7 +830,7 @@ static int channel_setenv(LIBSSH2_CHANNEL *channel,
LIBSSH2_FREE(session, channel->setenv_packet); LIBSSH2_FREE(session, channel->setenv_packet);
channel->setenv_packet = NULL; channel->setenv_packet = NULL;
channel->setenv_state = libssh2_NB_state_idle; channel->setenv_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send channel-request packet for " "Unable to send channel-request packet for "
"setenv request"); "setenv request");
} }
@ -865,7 +865,7 @@ static int channel_setenv(LIBSSH2_CHANNEL *channel,
} }
channel->setenv_state = libssh2_NB_state_idle; channel->setenv_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED, return _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED,
"Unable to complete request for channel-setenv"); "Unable to complete request for channel-setenv");
} }
@ -920,7 +920,7 @@ static int channel_request_pty(LIBSSH2_CHANNEL *channel,
s = channel->reqPTY_packet = s = channel->reqPTY_packet =
LIBSSH2_ALLOC(session, channel->reqPTY_packet_len); LIBSSH2_ALLOC(session, channel->reqPTY_packet_len);
if (!channel->reqPTY_packet) { if (!channel->reqPTY_packet) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for pty-request"); "Unable to allocate memory for pty-request");
} }
@ -969,7 +969,7 @@ static int channel_request_pty(LIBSSH2_CHANNEL *channel,
LIBSSH2_FREE(session, channel->reqPTY_packet); LIBSSH2_FREE(session, channel->reqPTY_packet);
channel->reqPTY_packet = NULL; channel->reqPTY_packet = NULL;
channel->reqPTY_state = libssh2_NB_state_idle; channel->reqPTY_state = libssh2_NB_state_idle;
return libssh2_error(session, rc, return _libssh2_error(session, rc,
"Unable to send pty-request packet"); "Unable to send pty-request packet");
} }
LIBSSH2_FREE(session, channel->reqPTY_packet); LIBSSH2_FREE(session, channel->reqPTY_packet);
@ -1000,7 +1000,7 @@ static int channel_request_pty(LIBSSH2_CHANNEL *channel,
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
channel->reqPTY_state = libssh2_NB_state_idle; channel->reqPTY_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED, return _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED,
"Unable to complete request for channel request-pty"); "Unable to complete request for channel request-pty");
} }
@ -1046,7 +1046,7 @@ channel_request_pty_size(LIBSSH2_CHANNEL * channel, int width,
LIBSSH2_ALLOC(session, channel->reqPTY_packet_len); LIBSSH2_ALLOC(session, channel->reqPTY_packet_len);
if (!channel->reqPTY_packet) { if (!channel->reqPTY_packet) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for pty-request"); "Unable to allocate memory for pty-request");
} }
@ -1080,7 +1080,7 @@ channel_request_pty_size(LIBSSH2_CHANNEL * channel, int width,
LIBSSH2_FREE(session, channel->reqPTY_packet); LIBSSH2_FREE(session, channel->reqPTY_packet);
channel->reqPTY_packet = NULL; channel->reqPTY_packet = NULL;
channel->reqPTY_state = libssh2_NB_state_idle; channel->reqPTY_state = libssh2_NB_state_idle;
return libssh2_error(session, rc, return _libssh2_error(session, rc,
"Unable to send window-change packet"); "Unable to send window-change packet");
} }
LIBSSH2_FREE(session, channel->reqPTY_packet); LIBSSH2_FREE(session, channel->reqPTY_packet);
@ -1150,7 +1150,7 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection,
s = channel->reqX11_packet = s = channel->reqX11_packet =
LIBSSH2_ALLOC(session, channel->reqX11_packet_len); LIBSSH2_ALLOC(session, channel->reqX11_packet_len);
if (!channel->reqX11_packet) { if (!channel->reqX11_packet) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for pty-request"); "Unable to allocate memory for pty-request");
} }
@ -1205,7 +1205,7 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection,
LIBSSH2_FREE(session, channel->reqX11_packet); LIBSSH2_FREE(session, channel->reqX11_packet);
channel->reqX11_packet = NULL; channel->reqX11_packet = NULL;
channel->reqX11_state = libssh2_NB_state_idle; channel->reqX11_state = libssh2_NB_state_idle;
return libssh2_error(session, rc, return _libssh2_error(session, rc,
"Unable to send x11-req packet"); "Unable to send x11-req packet");
} }
LIBSSH2_FREE(session, channel->reqX11_packet); LIBSSH2_FREE(session, channel->reqX11_packet);
@ -1224,7 +1224,7 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection,
return rc; return rc;
} else if (rc) { } else if (rc) {
channel->reqX11_state = libssh2_NB_state_idle; channel->reqX11_state = libssh2_NB_state_idle;
return libssh2_error(session, rc, return _libssh2_error(session, rc,
"waiting for x11-req response packet"); "waiting for x11-req response packet");
} }
@ -1236,7 +1236,7 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection,
} }
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
return libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED, return _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED,
"Unable to complete request for channel x11-req"); "Unable to complete request for channel x11-req");
} }
@ -1293,7 +1293,7 @@ _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
s = channel->process_packet = s = channel->process_packet =
LIBSSH2_ALLOC(session, channel->process_packet_len); LIBSSH2_ALLOC(session, channel->process_packet_len);
if (!channel->process_packet) { if (!channel->process_packet) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory " "Unable to allocate memory "
"for channel-process request"); "for channel-process request");
} }
@ -1328,7 +1328,7 @@ _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
LIBSSH2_FREE(session, channel->process_packet); LIBSSH2_FREE(session, channel->process_packet);
channel->process_packet = NULL; channel->process_packet = NULL;
channel->process_state = libssh2_NB_state_idle; channel->process_state = libssh2_NB_state_idle;
return libssh2_error(session, rc, return _libssh2_error(session, rc,
"Unable to send channel request"); "Unable to send channel request");
} }
LIBSSH2_FREE(session, channel->process_packet); LIBSSH2_FREE(session, channel->process_packet);
@ -1347,7 +1347,7 @@ _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
return rc; return rc;
} else if (rc) { } else if (rc) {
channel->process_state = libssh2_NB_state_idle; channel->process_state = libssh2_NB_state_idle;
return libssh2_error(session, rc, return _libssh2_error(session, rc,
"Failed waiting for channel success"); "Failed waiting for channel success");
} }
@ -1360,7 +1360,7 @@ _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
channel->process_state = libssh2_NB_state_idle; channel->process_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED, return _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED,
"Unable to complete request for " "Unable to complete request for "
"channel-process-startup"); "channel-process-startup");
} }
@ -1550,7 +1550,7 @@ _libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL * channel,
} }
else if (rc) { else if (rc) {
channel->adjust_queue = adjustment; channel->adjust_queue = adjustment;
return libssh2_error(channel->session, LIBSSH2_ERROR_SOCKET_SEND, return _libssh2_error(channel->session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send transfer-window adjustment " "Unable to send transfer-window adjustment "
"packet, deferring"); "packet, deferring");
} }
@ -1715,7 +1715,7 @@ ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id,
rc = _libssh2_transport_read(session); rc = _libssh2_transport_read(session);
if ((rc < 0) && (rc != PACKET_EAGAIN)) if ((rc < 0) && (rc != PACKET_EAGAIN))
return libssh2_error(session, rc, "transport read"); return _libssh2_error(session, rc, "transport read");
/* /*
* =============================== NOTE =============================== * =============================== NOTE ===============================
@ -1949,12 +1949,12 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id,
stream_id); stream_id);
if (channel->local.close) { if (channel->local.close) {
return libssh2_error(session, LIBSSH2_ERROR_CHANNEL_CLOSED, return _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_CLOSED,
"We've already closed this channel"); "We've already closed this channel");
} }
if (channel->local.eof) { if (channel->local.eof) {
return libssh2_error(session, LIBSSH2_ERROR_CHANNEL_EOF_SENT, return _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_EOF_SENT,
"EOF has already been received, " "EOF has already been received, "
"data might be ignored"); "data might be ignored");
} }
@ -1965,7 +1965,7 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id,
channel->write_packet = channel->write_packet =
LIBSSH2_ALLOC(session, channel->write_packet_len); LIBSSH2_ALLOC(session, channel->write_packet_len);
if (!channel->write_packet) { if (!channel->write_packet) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocte space " "Unable to allocte space "
"for data transmission packet"); "for data transmission packet");
} }
@ -2046,14 +2046,14 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id,
_libssh2_transport_drain(session); _libssh2_transport_drain(session);
goto _channel_write_done; goto _channel_write_done;
} }
return libssh2_error(session, rc, return _libssh2_error(session, rc,
"Unable to send channel data"); "Unable to send channel data");
} }
else if (rc) { else if (rc) {
LIBSSH2_FREE(session, channel->write_packet); LIBSSH2_FREE(session, channel->write_packet);
channel->write_packet = NULL; channel->write_packet = NULL;
channel->write_state = libssh2_NB_state_idle; channel->write_state = libssh2_NB_state_idle;
return libssh2_error(session, rc, return _libssh2_error(session, rc,
"Unable to send channel data"); "Unable to send channel data");
} }
/* Shrink local window size */ /* Shrink local window size */
@ -2114,7 +2114,7 @@ static int channel_send_eof(LIBSSH2_CHANNEL *channel)
return rc; return rc;
} }
else if (rc) { else if (rc) {
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send EOF on channel"); "Unable to send EOF on channel");
} }
channel->local.eof = 1; channel->local.eof = 1;
@ -2250,7 +2250,7 @@ channel_close(LIBSSH2_CHANNEL * channel)
return retcode; return retcode;
} else if (retcode) { } else if (retcode) {
channel->close_state = libssh2_NB_state_idle; channel->close_state = libssh2_NB_state_idle;
return libssh2_error(session, retcode, return _libssh2_error(session, retcode,
"Unable to send close-channel request"); "Unable to send close-channel request");
} }
@ -2307,7 +2307,7 @@ static int channel_wait_closed(LIBSSH2_CHANNEL *channel)
int rc; int rc;
if (!libssh2_channel_eof(channel)) { if (!libssh2_channel_eof(channel)) {
return libssh2_error(session, LIBSSH2_ERROR_INVAL, return _libssh2_error(session, LIBSSH2_ERROR_INVAL,
"libssh2_channel_wait_closed() invoked when " "libssh2_channel_wait_closed() invoked when "
"channel is not in EOF state"); "channel is not in EOF state");
} }

View File

@ -122,7 +122,7 @@ comp_method_zlib_init(LIBSSH2_SESSION * session, int compress,
strm = LIBSSH2_ALLOC(session, sizeof(z_stream)); strm = LIBSSH2_ALLOC(session, sizeof(z_stream));
if (!strm) { if (!strm) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for " "Unable to allocate memory for "
"zlib compression/decompression"); "zlib compression/decompression");
} }
@ -185,7 +185,7 @@ comp_method_zlib_comp(LIBSSH2_SESSION * session,
out = (char *) strm->next_out; out = (char *) strm->next_out;
strm->avail_out = out_maxlen; strm->avail_out = out_maxlen;
if (!strm->next_out) { if (!strm->next_out) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate compression/decompression " "Unable to allocate compression/decompression "
"buffer"); "buffer");
} }
@ -199,7 +199,7 @@ comp_method_zlib_comp(LIBSSH2_SESSION * session,
} }
if (status != Z_OK) { if (status != Z_OK) {
LIBSSH2_FREE(session, out); LIBSSH2_FREE(session, out);
return libssh2_error(session, LIBSSH2_ERROR_ZLIB, return _libssh2_error(session, LIBSSH2_ERROR_ZLIB,
"compress/decompression failure"); "compress/decompression failure");
} }
if (strm->avail_in) { if (strm->avail_in) {
@ -211,14 +211,14 @@ comp_method_zlib_comp(LIBSSH2_SESSION * session,
if ((out_maxlen > (int) payload_limit) && !compress && limiter++) { if ((out_maxlen > (int) payload_limit) && !compress && limiter++) {
LIBSSH2_FREE(session, out); LIBSSH2_FREE(session, out);
return libssh2_error(session, LIBSSH2_ERROR_ZLIB, return _libssh2_error(session, LIBSSH2_ERROR_ZLIB,
"Excessive growth in decompression phase"); "Excessive growth in decompression phase");
} }
newout = LIBSSH2_REALLOC(session, out, out_maxlen); newout = LIBSSH2_REALLOC(session, out, out_maxlen);
if (!newout) { if (!newout) {
LIBSSH2_FREE(session, out); LIBSSH2_FREE(session, out);
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to expand compress/" "Unable to expand compress/"
"decompression buffer"); "decompression buffer");
} }
@ -237,7 +237,7 @@ comp_method_zlib_comp(LIBSSH2_SESSION * session,
if (out_maxlen >= (int) payload_limit) { if (out_maxlen >= (int) payload_limit) {
LIBSSH2_FREE(session, out); LIBSSH2_FREE(session, out);
return libssh2_error(session, LIBSSH2_ERROR_ZLIB, return _libssh2_error(session, LIBSSH2_ERROR_ZLIB,
"Excessive growth in decompression " "Excessive growth in decompression "
"phase"); "phase");
} }
@ -252,7 +252,7 @@ comp_method_zlib_comp(LIBSSH2_SESSION * session,
newout = LIBSSH2_REALLOC(session, out, out_maxlen); newout = LIBSSH2_REALLOC(session, out, out_maxlen);
if (!newout) { if (!newout) {
LIBSSH2_FREE(session, out); LIBSSH2_FREE(session, out);
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to expand final compress/" "Unable to expand final compress/"
"decompress buffer"); "decompress buffer");
} }
@ -267,7 +267,7 @@ comp_method_zlib_comp(LIBSSH2_SESSION * session,
} }
if (status != Z_OK) { if (status != Z_OK) {
LIBSSH2_FREE(session, out); LIBSSH2_FREE(session, out);
return libssh2_error(session, LIBSSH2_ERROR_ZLIB, return _libssh2_error(session, LIBSSH2_ERROR_ZLIB,
"compress/decompression failure"); "compress/decompression failure");
} }
} }

View File

@ -324,7 +324,7 @@ hostkey_method_ssh_dss_sig_verify(LIBSSH2_SESSION * session,
sig += 15; sig += 15;
sig_len -= 15; sig_len -= 15;
if (sig_len != 40) { if (sig_len != 40) {
return libssh2_error(session, LIBSSH2_ERROR_PROTO, return _libssh2_error(session, LIBSSH2_ERROR_PROTO,
"Invalid DSS signature length"); "Invalid DSS signature length");
} }
return _libssh2_dsa_sha1_verify(dsactx, sig, m, m_len); return _libssh2_dsa_sha1_verify(dsactx, sig, m, m_len);

View File

@ -80,7 +80,7 @@ libssh2_keepalive_send (LIBSSH2_SESSION *session,
/* Silently ignore PACKET_EAGAIN here: if the write buffer is /* Silently ignore PACKET_EAGAIN here: if the write buffer is
already full, sending another keepalive is not useful. */ already full, sending another keepalive is not useful. */
if (rc && rc != PACKET_EAGAIN) { if (rc && rc != PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send keepalive message"); "Unable to send keepalive message");
return rc; return rc;
} }

View File

@ -118,7 +118,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
exchange_state->e_packet = exchange_state->e_packet =
LIBSSH2_ALLOC(session, exchange_state->e_packet_len); LIBSSH2_ALLOC(session, exchange_state->e_packet_len);
if (!exchange_state->e_packet) { if (!exchange_state->e_packet) {
ret = libssh2_error(session, LIBSSH2_ERROR_ALLOC, ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Out of memory error"); "Out of memory error");
goto clean_exit; goto clean_exit;
} }
@ -145,7 +145,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
return rc; return rc;
} else if (rc) { } else if (rc) {
ret = libssh2_error(session, rc, ret = _libssh2_error(session, rc,
"Unable to send KEX init message"); "Unable to send KEX init message");
goto clean_exit; goto clean_exit;
} }
@ -190,7 +190,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
return rc; return rc;
} }
if (rc) { if (rc) {
ret = libssh2_error(session, LIBSSH2_ERROR_TIMEOUT, ret = _libssh2_error(session, LIBSSH2_ERROR_TIMEOUT,
"Timed out waiting for KEX reply"); "Timed out waiting for KEX reply");
goto clean_exit; goto clean_exit;
} }
@ -203,7 +203,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
session->server_hostkey = session->server_hostkey =
LIBSSH2_ALLOC(session, session->server_hostkey_len); LIBSSH2_ALLOC(session, session->server_hostkey_len);
if (!session->server_hostkey) { if (!session->server_hostkey) {
ret = libssh2_error(session, LIBSSH2_ERROR_ALLOC, ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for a copy " "Unable to allocate memory for a copy "
"of the host key"); "of the host key");
goto clean_exit; goto clean_exit;
@ -260,7 +260,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
if (session->hostkey->init(session, session->server_hostkey, if (session->hostkey->init(session, session->server_hostkey,
session->server_hostkey_len, session->server_hostkey_len,
&session->server_hostkey_abstract)) { &session->server_hostkey_abstract)) {
ret = libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_INIT, ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_INIT,
"Unable to initialize hostkey importer"); "Unable to initialize hostkey importer");
goto clean_exit; goto clean_exit;
} }
@ -287,7 +287,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
exchange_state->k_value = exchange_state->k_value =
LIBSSH2_ALLOC(session, exchange_state->k_value_len); LIBSSH2_ALLOC(session, exchange_state->k_value_len);
if (!exchange_state->k_value) { if (!exchange_state->k_value) {
ret = libssh2_error(session, LIBSSH2_ERROR_ALLOC, ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate buffer for K"); "Unable to allocate buffer for K");
goto clean_exit; goto clean_exit;
} }
@ -398,7 +398,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
sig_verify(session, exchange_state->h_sig, sig_verify(session, exchange_state->h_sig,
exchange_state->h_sig_len, exchange_state->h_sig_comp, exchange_state->h_sig_len, exchange_state->h_sig_comp,
20, &session->server_hostkey_abstract)) { 20, &session->server_hostkey_abstract)) {
ret = libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_SIGN, ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_SIGN,
"Unable to verify hostkey signature"); "Unable to verify hostkey signature");
goto clean_exit; goto clean_exit;
} }
@ -414,7 +414,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
return rc; return rc;
} else if (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; goto clean_exit;
} }
@ -429,7 +429,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
return rc; return rc;
} else if (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; goto clean_exit;
} }
/* The first key exchange has been performed, /* The first key exchange has been performed,
@ -444,7 +444,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
if (!session->session_id) { if (!session->session_id) {
session->session_id = LIBSSH2_ALLOC(session, SHA_DIGEST_LENGTH); session->session_id = LIBSSH2_ALLOC(session, SHA_DIGEST_LENGTH);
if (!session->session_id) { if (!session->session_id) {
ret = libssh2_error(session, LIBSSH2_ERROR_ALLOC, ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate buffer for SHA digest"); "Unable to allocate buffer for SHA digest");
goto clean_exit; goto clean_exit;
} }
@ -815,7 +815,7 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
return rc; return rc;
} else if (rc) { } else if (rc) {
ret = libssh2_error(session, rc, ret = _libssh2_error(session, rc,
"Unable to send Group Exchange Request"); "Unable to send Group Exchange Request");
goto dh_gex_clean_exit; goto dh_gex_clean_exit;
} }
@ -830,7 +830,7 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
return rc; return rc;
} else if (rc) { } else if (rc) {
ret = libssh2_error(session, rc, ret = _libssh2_error(session, rc,
"Timeout waiting for GEX_GROUP reply"); "Timeout waiting for GEX_GROUP reply");
goto dh_gex_clean_exit; goto dh_gex_clean_exit;
} }
@ -1026,7 +1026,7 @@ static int kexinit(LIBSSH2_SESSION * session)
s = data = LIBSSH2_ALLOC(session, data_len); s = data = LIBSSH2_ALLOC(session, data_len);
if (!data) { if (!data) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory"); "Unable to allocate memory");
} }
@ -1115,7 +1115,7 @@ static int kexinit(LIBSSH2_SESSION * session)
else if (rc) { else if (rc) {
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
session->kexinit_state = libssh2_NB_state_idle; session->kexinit_state = libssh2_NB_state_idle;
return libssh2_error(session, rc, return _libssh2_error(session, rc,
"Unable to send KEXINIT packet to remote host"); "Unable to send KEXINIT packet to remote host");
} }
@ -1634,7 +1634,7 @@ static int kex_agree_methods(LIBSSH2_SESSION * session, unsigned char *data,
* Exchange keys * Exchange keys
* Returns 0 on success, non-zero on failure * Returns 0 on success, non-zero on failure
* *
* Returns some errors without libssh2_error() * Returns some errors without _libssh2_error()
*/ */
int int
libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange, libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange,
@ -1736,7 +1736,7 @@ libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange,
session->state &= ~LIBSSH2_STATE_KEX_ACTIVE; session->state &= ~LIBSSH2_STATE_KEX_ACTIVE;
return retcode; return retcode;
} else if (retcode) { } else if (retcode) {
rc = libssh2_error(session, LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE, rc = _libssh2_error(session, LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE,
"Unrecoverable error exchanging keys"); "Unrecoverable error exchanging keys");
} }
} }
@ -1825,13 +1825,13 @@ libssh2_session_method_pref(LIBSSH2_SESSION * session, int method_type,
break; break;
default: default:
return libssh2_error(session, LIBSSH2_ERROR_INVAL, return _libssh2_error(session, LIBSSH2_ERROR_INVAL,
"Invalid parameter specified for method_type"); "Invalid parameter specified for method_type");
} }
s = newprefs = LIBSSH2_ALLOC(session, prefs_len + 1); s = newprefs = LIBSSH2_ALLOC(session, prefs_len + 1);
if (!newprefs) { if (!newprefs) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Error allocated space for method preferences"); "Error allocated space for method preferences");
} }
memcpy(s, prefs, prefs_len + 1); memcpy(s, prefs, prefs_len + 1);
@ -1858,7 +1858,7 @@ libssh2_session_method_pref(LIBSSH2_SESSION * session, int method_type,
if (strlen(newprefs) == 0) { if (strlen(newprefs) == 0) {
LIBSSH2_FREE(session, newprefs); LIBSSH2_FREE(session, newprefs);
return libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"The requested method(s) are not currently " "The requested method(s) are not currently "
"supported"); "supported");
} }

View File

@ -88,7 +88,7 @@ libssh2_knownhost_init(LIBSSH2_SESSION *session)
LIBSSH2_ALLOC(session, sizeof(struct _LIBSSH2_KNOWNHOSTS)); LIBSSH2_ALLOC(session, sizeof(struct _LIBSSH2_KNOWNHOSTS));
if(!knh) { if(!knh) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for known-hosts " "Unable to allocate memory for known-hosts "
"collection"); "collection");
return NULL; return NULL;
@ -137,13 +137,13 @@ knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
unsigned int ptrlen; unsigned int ptrlen;
if(!entry) if(!entry)
return libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for known host " "Unable to allocate memory for known host "
"entry"); "entry");
/* make sure we have a key type set */ /* make sure we have a key type set */
if(!(typemask & LIBSSH2_KNOWNHOST_KEY_MASK)) { if(!(typemask & LIBSSH2_KNOWNHOST_KEY_MASK)) {
rc = libssh2_error(hosts->session, LIBSSH2_ERROR_INVAL, rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_INVAL,
"No key type set"); "No key type set");
goto error; goto error;
} }
@ -157,7 +157,7 @@ knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
case LIBSSH2_KNOWNHOST_TYPE_CUSTOM: case LIBSSH2_KNOWNHOST_TYPE_CUSTOM:
entry->name = LIBSSH2_ALLOC(hosts->session, hostlen+1); entry->name = LIBSSH2_ALLOC(hosts->session, hostlen+1);
if(!entry->name) { if(!entry->name) {
rc = libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC, rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for host name"); "Unable to allocate memory for host name");
goto error; goto error;
} }
@ -179,7 +179,7 @@ knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
entry->salt_len = ptrlen; entry->salt_len = ptrlen;
break; break;
default: default:
rc = libssh2_error(hosts->session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"Unknown host name type"); "Unknown host name type");
goto error; goto error;
} }
@ -190,7 +190,7 @@ knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
keylen = strlen(key); keylen = strlen(key);
entry->key = LIBSSH2_ALLOC(hosts->session, keylen+1); entry->key = LIBSSH2_ALLOC(hosts->session, keylen+1);
if(!entry->key) { if(!entry->key) {
rc = libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC, rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for key"); "Unable to allocate memory for key");
goto error; goto error;
} }
@ -202,7 +202,7 @@ knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
size_t nlen = _libssh2_base64_encode(hosts->session, key, keylen, size_t nlen = _libssh2_base64_encode(hosts->session, key, keylen,
&ptr); &ptr);
if(!nlen) { if(!nlen) {
rc = libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC, rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for " "Unable to allocate memory for "
"base64-encoded key"); "base64-encoded key");
goto error; goto error;
@ -214,7 +214,7 @@ knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
if (comment) { if (comment) {
entry->comment = LIBSSH2_ALLOC(hosts->session, commentlen+1); entry->comment = LIBSSH2_ALLOC(hosts->session, commentlen+1);
if(!entry->comment) { if(!entry->comment) {
rc = libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC, rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for comment"); "Unable to allocate memory for comment");
goto error; goto error;
} }
@ -347,7 +347,7 @@ libssh2_knownhost_check(LIBSSH2_KNOWNHOSTS *hosts,
size_t nlen = _libssh2_base64_encode(hosts->session, key, keylen, size_t nlen = _libssh2_base64_encode(hosts->session, key, keylen,
&keyalloc); &keyalloc);
if(!nlen) { if(!nlen) {
libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC, _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for base64-encoded " "Unable to allocate memory for base64-encoded "
"key"); "key");
return LIBSSH2_KNOWNHOST_CHECK_FAILURE; return LIBSSH2_KNOWNHOST_CHECK_FAILURE;
@ -440,7 +440,7 @@ libssh2_knownhost_del(LIBSSH2_KNOWNHOSTS *hosts,
/* check that this was retrieved the right way or get out */ /* check that this was retrieved the right way or get out */
if(!entry || (entry->magic != KNOWNHOST_MAGIC)) if(!entry || (entry->magic != KNOWNHOST_MAGIC))
return libssh2_error(hosts->session, LIBSSH2_ERROR_INVAL, return _libssh2_error(hosts->session, LIBSSH2_ERROR_INVAL,
"Invalid host information"); "Invalid host information");
/* get the internal node pointer */ /* get the internal node pointer */
@ -542,7 +542,7 @@ static int hostline(LIBSSH2_KNOWNHOSTS *hosts,
const char *hash = NULL; const char *hash = NULL;
size_t saltlen = p - salt; size_t saltlen = p - salt;
if(saltlen >= (sizeof(saltbuf)-1)) /* weird length */ if(saltlen >= (sizeof(saltbuf)-1)) /* weird length */
return libssh2_error(hosts->session, return _libssh2_error(hosts->session,
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"Failed to parse known_hosts line " "Failed to parse known_hosts line "
"(unexpectedly long salt)"); "(unexpectedly long salt)");
@ -565,7 +565,7 @@ static int hostline(LIBSSH2_KNOWNHOSTS *hosts,
if((keylen < 20) || if((keylen < 20) ||
(seplen >= sizeof(hostbuf)-1) || (seplen >= sizeof(hostbuf)-1) ||
(hostlen >= sizeof(hostbuf)-1)) (hostlen >= sizeof(hostbuf)-1))
return libssh2_error(hosts->session, return _libssh2_error(hosts->session,
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"Failed to parse known_hosts line " "Failed to parse known_hosts line "
"(unexpected length)"); "(unexpected length)");
@ -589,7 +589,7 @@ static int hostline(LIBSSH2_KNOWNHOSTS *hosts,
type |= LIBSSH2_KNOWNHOST_KEY_SSHRSA; type |= LIBSSH2_KNOWNHOST_KEY_SSHRSA;
else else
/* unknown key type */ /* unknown key type */
return libssh2_error(hosts->session, return _libssh2_error(hosts->session,
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"Unknown key type"); "Unknown key type");
@ -628,7 +628,7 @@ static int hostline(LIBSSH2_KNOWNHOSTS *hosts,
break; break;
default: /* unknown key format */ default: /* unknown key format */
return libssh2_error(hosts->session, return _libssh2_error(hosts->session,
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"Unknown key format"); "Unknown key format");
} }
@ -699,7 +699,7 @@ libssh2_knownhost_readline(LIBSSH2_KNOWNHOSTS *hosts,
int rc; int rc;
if(type != LIBSSH2_KNOWNHOST_FILE_OPENSSH) if(type != LIBSSH2_KNOWNHOST_FILE_OPENSSH)
return libssh2_error(hosts->session, return _libssh2_error(hosts->session,
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"Unsupported type of known-host information " "Unsupported type of known-host information "
"store"); "store");
@ -734,7 +734,7 @@ libssh2_knownhost_readline(LIBSSH2_KNOWNHOSTS *hosts,
} }
if(!*cp || !len) /* illegal line */ if(!*cp || !len) /* illegal line */
return libssh2_error(hosts->session, return _libssh2_error(hosts->session,
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"Failed to parse known_hosts line"); "Failed to parse known_hosts line");
@ -777,7 +777,7 @@ libssh2_knownhost_readfile(LIBSSH2_KNOWNHOSTS *hosts,
char buf[2048]; char buf[2048];
if(type != LIBSSH2_KNOWNHOST_FILE_OPENSSH) if(type != LIBSSH2_KNOWNHOST_FILE_OPENSSH)
return libssh2_error(hosts->session, return _libssh2_error(hosts->session,
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"Unsupported type of known-host information " "Unsupported type of known-host information "
"store"); "store");
@ -792,7 +792,7 @@ libssh2_knownhost_readfile(LIBSSH2_KNOWNHOSTS *hosts,
fclose(file); fclose(file);
} }
else else
return libssh2_error(hosts->session, LIBSSH2_ERROR_FILE, return _libssh2_error(hosts->session, LIBSSH2_ERROR_FILE,
"Failed to open file"); "Failed to open file");
return num; return num;
@ -830,7 +830,7 @@ knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
/* we only support this single file type for now, bail out on all other /* we only support this single file type for now, bail out on all other
attempts */ attempts */
if(type != LIBSSH2_KNOWNHOST_FILE_OPENSSH) if(type != LIBSSH2_KNOWNHOST_FILE_OPENSSH)
return libssh2_error(hosts->session, return _libssh2_error(hosts->session,
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"Unsupported type of known-host information " "Unsupported type of known-host information "
"store"); "store");
@ -852,7 +852,7 @@ knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
nlen = _libssh2_base64_encode(hosts->session, node->name, nlen = _libssh2_base64_encode(hosts->session, node->name,
node->name_len, &namealloc); node->name_len, &namealloc);
if(!nlen) if(!nlen)
return libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for " "Unable to allocate memory for "
"base64-encoded host name"); "base64-encoded host name");
@ -861,7 +861,7 @@ knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
&saltalloc); &saltalloc);
if(!nlen) { if(!nlen) {
free(namealloc); free(namealloc);
return libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for " "Unable to allocate memory for "
"base64-encoded salt"); "base64-encoded salt");
} }
@ -878,7 +878,7 @@ knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
sprintf(buf, "|1|%s|%s%s %s\n", saltalloc, namealloc, sprintf(buf, "|1|%s|%s%s %s\n", saltalloc, namealloc,
keytype, node->key); keytype, node->key);
else else
rc = libssh2_error(hosts->session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_BUFFER_TOO_SMALL,
"Known-host write buffer too small"); "Known-host write buffer too small");
free(namealloc); free(namealloc);
@ -896,7 +896,7 @@ knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
else else
sprintf(buf, "%s%s %s\n", node->name, keytype, node->key); sprintf(buf, "%s%s %s\n", node->name, keytype, node->key);
else else
rc = libssh2_error(hosts->session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_BUFFER_TOO_SMALL,
"Known-host write buffer too small"); "Known-host write buffer too small");
} }
@ -924,7 +924,7 @@ libssh2_knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
struct known_host *node; struct known_host *node;
if(known->magic != KNOWNHOST_MAGIC) if(known->magic != KNOWNHOST_MAGIC)
return libssh2_error(hosts->session, LIBSSH2_ERROR_INVAL, return _libssh2_error(hosts->session, LIBSSH2_ERROR_INVAL,
"Invalid host information"); "Invalid host information");
node = known->node; node = known->node;
@ -949,14 +949,14 @@ libssh2_knownhost_writefile(LIBSSH2_KNOWNHOSTS *hosts,
/* we only support this single file type for now, bail out on all other /* we only support this single file type for now, bail out on all other
attempts */ attempts */
if(type != LIBSSH2_KNOWNHOST_FILE_OPENSSH) if(type != LIBSSH2_KNOWNHOST_FILE_OPENSSH)
return libssh2_error(hosts->session, return _libssh2_error(hosts->session,
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"Unsupported type of known-host information " "Unsupported type of known-host information "
"store"); "store");
file = fopen(filename, "w"); file = fopen(filename, "w");
if(!file) if(!file)
return libssh2_error(hosts->session, LIBSSH2_ERROR_FILE, return _libssh2_error(hosts->session, LIBSSH2_ERROR_FILE,
"Failed to open file"); "Failed to open file");
for(node = _libssh2_list_first(&hosts->head); for(node = _libssh2_list_first(&hosts->head);
@ -972,7 +972,7 @@ libssh2_knownhost_writefile(LIBSSH2_KNOWNHOSTS *hosts,
nwrote = fwrite(buffer, 1, wrote, file); nwrote = fwrite(buffer, 1, wrote, file);
if(nwrote != wrote) { if(nwrote != wrote) {
/* failed to write the whole thing, bail out */ /* failed to write the whole thing, bail out */
rc = libssh2_error(hosts->session, LIBSSH2_ERROR_FILE, rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_FILE,
"Write failed"); "Write failed");
break; break;
} }

View File

@ -1041,8 +1041,6 @@ _libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, ...)
#endif #endif
#endif #endif
int libssh2_error(LIBSSH2_SESSION* session, int errcode, const char* errmsg);
#define LIBSSH2_SOCKET_UNKNOWN 1 #define LIBSSH2_SOCKET_UNKNOWN 1
#define LIBSSH2_SOCKET_CONNECTED 0 #define LIBSSH2_SOCKET_CONNECTED 0
#define LIBSSH2_SOCKET_DISCONNECTED -1 #define LIBSSH2_SOCKET_DISCONNECTED -1

View File

@ -49,7 +49,7 @@
#include <errno.h> #include <errno.h>
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_msg = errmsg;
session->err_code = errcode; session->err_code = errcode;
@ -201,7 +201,7 @@ libssh2_base64_decode(LIBSSH2_SESSION *session, char **data,
*data = LIBSSH2_ALLOC(session, (3 * src_len / 4) + 1); *data = LIBSSH2_ALLOC(session, (3 * src_len / 4) + 1);
d = (unsigned char *) *data; d = (unsigned char *) *data;
if (!d) { if (!d) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for base64 decoding"); "Unable to allocate memory for base64 decoding");
} }
@ -230,7 +230,7 @@ libssh2_base64_decode(LIBSSH2_SESSION *session, char **data,
/* Invalid -- We have a byte which belongs exclusively to a partial /* Invalid -- We have a byte which belongs exclusively to a partial
octet */ octet */
LIBSSH2_FREE(session, *data); LIBSSH2_FREE(session, *data);
return libssh2_error(session, LIBSSH2_ERROR_INVAL, return _libssh2_error(session, LIBSSH2_ERROR_INVAL,
"Invalid data (byte belonging to partial octet)"); "Invalid data (byte belonging to partial octet)");
} }

View File

@ -1,6 +1,6 @@
#ifndef __LIBSSH2_MISC_H #ifndef __LIBSSH2_MISC_H
#define __LIBSSH2_MISC_H #define __LIBSSH2_MISC_H
/* Copyright (c) 2009 by Daniel Stenberg /* Copyright (c) 2009-2010 by Daniel Stenberg
* *
* All rights reserved. * All rights reserved.
* *
@ -49,6 +49,8 @@ struct list_node {
struct list_head *head; struct list_head *head;
}; };
int _libssh2_error(LIBSSH2_SESSION* session, int errcode, const char* errmsg);
void _libssh2_list_init(struct list_head *head); void _libssh2_list_init(struct list_head *head);
/* add a node last in the list */ /* add a node last in the list */

View File

@ -140,7 +140,7 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
channel = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_CHANNEL)); channel = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_CHANNEL));
if (!channel) { if (!channel) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate a channel for " "Unable to allocate a channel for "
"new connection"); "new connection");
failure_code = 4; /* SSH_OPEN_RESOURCE_SHORTAGE */ failure_code = 4; /* SSH_OPEN_RESOURCE_SHORTAGE */
@ -158,7 +158,7 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
channel_type_len + channel_type_len +
1); 1);
if (!channel->channel_type) { if (!channel->channel_type) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate a channel for new" "Unable to allocate a channel for new"
" connection"); " connection");
LIBSSH2_FREE(session, channel); LIBSSH2_FREE(session, channel);
@ -213,7 +213,7 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
return rc; return rc;
else if (rc) { else if (rc) {
listen_state->state = libssh2_NB_state_idle; listen_state->state = libssh2_NB_state_idle;
return libssh2_error(session, rc, return _libssh2_error(session, rc,
"Unable to send channel " "Unable to send channel "
"open confirmation"); "open confirmation");
} }
@ -253,7 +253,7 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
return rc; return rc;
} else if (rc) { } else if (rc) {
listen_state->state = libssh2_NB_state_idle; 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; listen_state->state = libssh2_NB_state_idle;
@ -306,7 +306,7 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data,
if (x11open_state->state == libssh2_NB_state_allocated) { if (x11open_state->state == libssh2_NB_state_allocated) {
channel = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_CHANNEL)); channel = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_CHANNEL));
if (!channel) { if (!channel) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate a channel for new connection"); "Unable to allocate a channel for new connection");
failure_code = 4; /* SSH_OPEN_RESOURCE_SHORTAGE */ failure_code = 4; /* SSH_OPEN_RESOURCE_SHORTAGE */
goto x11_exit; goto x11_exit;
@ -319,7 +319,7 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data,
channel->channel_type_len + channel->channel_type_len +
1); 1);
if (!channel->channel_type) { if (!channel->channel_type) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate a channel for new connection"); "Unable to allocate a channel for new connection");
LIBSSH2_FREE(session, channel); LIBSSH2_FREE(session, channel);
failure_code = 4; /* SSH_OPEN_RESOURCE_SHORTAGE */ failure_code = 4; /* SSH_OPEN_RESOURCE_SHORTAGE */
@ -367,7 +367,7 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data,
return rc; return rc;
} else if (rc) { } else if (rc) {
x11open_state->state = libssh2_NB_state_idle; x11open_state->state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send channel open " "Unable to send channel open "
"confirmation"); "confirmation");
} }
@ -407,7 +407,7 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data,
return rc; return rc;
} else if (rc) { } else if (rc) {
x11open_state->state = libssh2_NB_state_idle; 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; x11open_state->state = libssh2_NB_state_idle;
return 0; return 0;
@ -459,7 +459,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
"", 0); "", 0);
} }
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
return libssh2_error(session, LIBSSH2_ERROR_INVALID_MAC, return _libssh2_error(session, LIBSSH2_ERROR_INVALID_MAC,
"Invalid MAC received"); "Invalid MAC received");
} }
} }
@ -529,7 +529,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
session->socket_state = LIBSSH2_SOCKET_DISCONNECTED; session->socket_state = LIBSSH2_SOCKET_DISCONNECTED;
session->packAdd_state = libssh2_NB_state_idle; session->packAdd_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_DISCONNECT, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_DISCONNECT,
"socket disconnect"); "socket disconnect");
} }
break; break;
@ -628,7 +628,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
_libssh2_channel_locate(session, _libssh2_ntohu32(data + 1)); _libssh2_channel_locate(session, _libssh2_ntohu32(data + 1));
if (!session->packAdd_channel) { if (!session->packAdd_channel) {
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_UNKNOWN, _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_UNKNOWN,
"Packet received for unknown channel, ignoring"); "Packet received for unknown channel, ignoring");
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
session->packAdd_state = libssh2_NB_state_idle; session->packAdd_state = libssh2_NB_state_idle;
@ -682,7 +682,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
* Spec says we MAY ignore bytes sent beyond * Spec says we MAY ignore bytes sent beyond
* packet_size * packet_size
*/ */
libssh2_error(session, _libssh2_error(session,
LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED, LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED,
"Packet contains more data than we offered" "Packet contains more data than we offered"
" to receive, truncating"); " to receive, truncating");
@ -695,7 +695,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
* Spec says we MAY ignore bytes sent beyond * Spec says we MAY ignore bytes sent beyond
* window_size * window_size
*/ */
libssh2_error(session, _libssh2_error(session,
LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED, LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED,
"The current receive window is full," "The current receive window is full,"
" data ignored"); " data ignored");
@ -708,7 +708,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
if ((datalen - session->packAdd_data_head) > if ((datalen - session->packAdd_data_head) >
session->packAdd_channel->remote.window_size) { session->packAdd_channel->remote.window_size) {
libssh2_error(session, _libssh2_error(session,
LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED, LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED,
"Remote sent more data than current " "Remote sent more data than current "
"window allows, truncating"); "window allows, truncating");

View File

@ -118,7 +118,7 @@ publickey_status_error(const LIBSSH2_PUBLICKEY *pkey,
msg = publickey_status_codes[status].name; msg = publickey_status_codes[status].name;
} }
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, msg); _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, msg);
} }
/* /*
@ -140,7 +140,7 @@ publickey_packet_receive(LIBSSH2_PUBLICKEY * pkey,
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
return rc; return rc;
} else if (rc != 4) { } else if (rc != 4) {
return libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Invalid response from publickey subsystem"); "Invalid response from publickey subsystem");
} }
@ -148,7 +148,7 @@ publickey_packet_receive(LIBSSH2_PUBLICKEY * pkey,
pkey->receive_packet = pkey->receive_packet =
LIBSSH2_ALLOC(session, pkey->receive_packet_len); LIBSSH2_ALLOC(session, pkey->receive_packet_len);
if (!pkey->receive_packet) { if (!pkey->receive_packet) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate publickey response " "Unable to allocate publickey response "
"buffer"); "buffer");
} }
@ -165,7 +165,7 @@ publickey_packet_receive(LIBSSH2_PUBLICKEY * pkey,
LIBSSH2_FREE(session, pkey->receive_packet); LIBSSH2_FREE(session, pkey->receive_packet);
pkey->receive_packet = NULL; pkey->receive_packet = NULL;
pkey->receive_state = libssh2_NB_state_idle; pkey->receive_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for publickey subsystem " "Timeout waiting for publickey subsystem "
"response packet"); "response packet");
} }
@ -233,7 +233,7 @@ publickey_response_success(LIBSSH2_PUBLICKEY * pkey)
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
return rc; return rc;
} else if (rc) { } else if (rc) {
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for response from " "Timeout waiting for response from "
"publickey subsystem"); "publickey subsystem");
} }
@ -241,7 +241,7 @@ publickey_response_success(LIBSSH2_PUBLICKEY * pkey)
s = data; s = data;
if ((response = publickey_response_id(&s, data_len)) < 0) { if ((response = publickey_response_id(&s, data_len)) < 0) {
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
return libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Invalid publickey subsystem response code"); "Invalid publickey subsystem response code");
} }
@ -261,7 +261,7 @@ publickey_response_success(LIBSSH2_PUBLICKEY * pkey)
} }
default: default:
/* Unknown/Unexpected */ /* Unknown/Unexpected */
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Unexpected publickey subsystem response, ignoring"); "Unexpected publickey subsystem response, ignoring");
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
data = NULL; data = NULL;
@ -312,13 +312,13 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
&& (libssh2_session_last_errno(session) == && (libssh2_session_last_errno(session) ==
LIBSSH2_ERROR_EAGAIN)) { LIBSSH2_ERROR_EAGAIN)) {
/* The error state is already set, so leave it */ /* The error state is already set, so leave it */
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block to startup channel"); "Would block to startup channel");
return NULL; return NULL;
} else if (!session->pkeyInit_channel } else if (!session->pkeyInit_channel
&& (libssh2_session_last_errno(session) != && (libssh2_session_last_errno(session) !=
LIBSSH2_ERROR_EAGAIN)) { LIBSSH2_ERROR_EAGAIN)) {
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE, _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE,
"Unable to startup channel"); "Unable to startup channel");
goto err_exit; goto err_exit;
} }
@ -333,11 +333,11 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
sizeof("subsystem") - 1, sizeof("subsystem") - 1,
"publickey", strlen("publickey")); "publickey", strlen("publickey"));
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block starting publickey subsystem"); "Would block starting publickey subsystem");
return NULL; return NULL;
} else if (rc) { } else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE, _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE,
"Unable to request publickey subsystem"); "Unable to request publickey subsystem");
goto err_exit; goto err_exit;
} }
@ -349,7 +349,7 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
rc = libssh2_channel_handle_extended_data2(session->pkeyInit_channel, rc = libssh2_channel_handle_extended_data2(session->pkeyInit_channel,
LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE); LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block starting publickey subsystem"); "Would block starting publickey subsystem");
return NULL; return NULL;
} }
@ -357,7 +357,7 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
session->pkeyInit_pkey = session->pkeyInit_pkey =
LIBSSH2_ALLOC(session, sizeof(LIBSSH2_PUBLICKEY)); LIBSSH2_ALLOC(session, sizeof(LIBSSH2_PUBLICKEY));
if (!session->pkeyInit_pkey) { if (!session->pkeyInit_pkey) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate a new publickey structure"); "Unable to allocate a new publickey structure");
goto err_exit; goto err_exit;
} }
@ -386,11 +386,11 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
rc = _libssh2_channel_write(session->pkeyInit_channel, 0, rc = _libssh2_channel_write(session->pkeyInit_channel, 0,
(char *) buffer, (s - buffer)); (char *) buffer, (s - buffer));
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending publickey version packet"); "Would block sending publickey version packet");
return NULL; return NULL;
} else if ((s - buffer) != rc) { } else if ((s - buffer) != rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send publickey version packet"); "Unable to send publickey version packet");
goto err_exit; goto err_exit;
} }
@ -404,12 +404,12 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
&session->pkeyInit_data, &session->pkeyInit_data,
&session->pkeyInit_data_len); &session->pkeyInit_data_len);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for response from " "Would block waiting for response from "
"publickey subsystem"); "publickey subsystem");
return NULL; return NULL;
} else if (rc) { } else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for response from " "Timeout waiting for response from "
"publickey subsystem"); "publickey subsystem");
goto err_exit; goto err_exit;
@ -418,7 +418,7 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
s = session->pkeyInit_data; s = session->pkeyInit_data;
if ((response = if ((response =
publickey_response_id(&s, session->pkeyInit_data_len)) < 0) { publickey_response_id(&s, session->pkeyInit_data_len)) < 0) {
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Invalid publickey subsystem response code"); "Invalid publickey subsystem response code");
goto err_exit; goto err_exit;
} }
@ -443,7 +443,7 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
if (s > if (s >
session->pkeyInit_data + session->pkeyInit_data_len) { session->pkeyInit_data + session->pkeyInit_data_len) {
libssh2_error(session, _libssh2_error(session,
LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Malformed publickey subsystem packet"); "Malformed publickey subsystem packet");
goto err_exit; goto err_exit;
@ -475,7 +475,7 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
default: default:
/* Unknown/Unexpected */ /* Unknown/Unexpected */
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Unexpected publickey subsystem response, " "Unexpected publickey subsystem response, "
"ignoring"); "ignoring");
LIBSSH2_FREE(session, session->pkeyInit_data); LIBSSH2_FREE(session, session->pkeyInit_data);
@ -490,7 +490,7 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
if (session->pkeyInit_channel) { if (session->pkeyInit_channel) {
rc = libssh2_channel_close(session->pkeyInit_channel); rc = libssh2_channel_close(session->pkeyInit_channel);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block closing channel"); "Would block closing channel");
return NULL; return NULL;
} }
@ -555,7 +555,7 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY * pkey, const unsigned char *name,
pkey->add_packet = LIBSSH2_ALLOC(session, packet_len); pkey->add_packet = LIBSSH2_ALLOC(session, packet_len);
if (!pkey->add_packet) { if (!pkey->add_packet) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for " "Unable to allocate memory for "
"publickey \"add\" packet"); "publickey \"add\" packet");
} }
@ -625,7 +625,7 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY * pkey, const unsigned char *name,
} else if ((pkey->add_s - pkey->add_packet) != rc) { } else if ((pkey->add_s - pkey->add_packet) != rc) {
LIBSSH2_FREE(session, pkey->add_packet); LIBSSH2_FREE(session, pkey->add_packet);
pkey->add_packet = NULL; pkey->add_packet = NULL;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send publickey add packet"); "Unable to send publickey add packet");
} }
LIBSSH2_FREE(session, pkey->add_packet); LIBSSH2_FREE(session, pkey->add_packet);
@ -663,7 +663,7 @@ libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY * pkey,
pkey->remove_packet = LIBSSH2_ALLOC(session, packet_len); pkey->remove_packet = LIBSSH2_ALLOC(session, packet_len);
if (!pkey->remove_packet) { if (!pkey->remove_packet) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for " "Unable to allocate memory for "
"publickey \"remove\" packet"); "publickey \"remove\" packet");
} }
@ -700,7 +700,7 @@ libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY * pkey,
LIBSSH2_FREE(session, pkey->remove_packet); LIBSSH2_FREE(session, pkey->remove_packet);
pkey->remove_packet = NULL; pkey->remove_packet = NULL;
pkey->remove_state = libssh2_NB_state_idle; pkey->remove_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send publickey remove packet"); "Unable to send publickey remove packet");
} }
LIBSSH2_FREE(session, pkey->remove_packet); LIBSSH2_FREE(session, pkey->remove_packet);
@ -760,7 +760,7 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
return rc; return rc;
} else if ((pkey->listFetch_s - pkey->listFetch_buffer) != rc) { } else if ((pkey->listFetch_s - pkey->listFetch_buffer) != rc) {
pkey->listFetch_state = libssh2_NB_state_idle; pkey->listFetch_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send publickey list packet"); "Unable to send publickey list packet");
} }
@ -773,7 +773,7 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
return rc; return rc;
} else if (rc) { } else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for response from " "Timeout waiting for response from "
"publickey subsystem"); "publickey subsystem");
goto err_exit; goto err_exit;
@ -783,7 +783,7 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
if ((response = if ((response =
publickey_response_id(&pkey->listFetch_s, publickey_response_id(&pkey->listFetch_s,
pkey->listFetch_data_len)) < 0) { pkey->listFetch_data_len)) < 0) {
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Invalid publickey subsystem response code"); "Invalid publickey subsystem response code");
goto err_exit; goto err_exit;
} }
@ -808,7 +808,7 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
if (pkey->listFetch_s > if (pkey->listFetch_s >
pkey->listFetch_data + pkey->listFetch_data_len) { pkey->listFetch_data + pkey->listFetch_data_len) {
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Malformed publickey subsystem packet"); "Malformed publickey subsystem packet");
goto err_exit; goto err_exit;
} }
@ -836,7 +836,7 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
(max_keys + (max_keys +
1) * sizeof(libssh2_publickey_list)); 1) * sizeof(libssh2_publickey_list));
if (!newlist) { if (!newlist) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for " "Unable to allocate memory for "
"publickey list"); "publickey list");
goto err_exit; goto err_exit;
@ -854,7 +854,7 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
LIBSSH2_ALLOC(session, LIBSSH2_ALLOC(session,
sizeof(libssh2_publickey_attribute)); sizeof(libssh2_publickey_attribute));
if (!list[keys].attrs) { if (!list[keys].attrs) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for " "Unable to allocate memory for "
"publickey attributes"); "publickey attributes");
goto err_exit; goto err_exit;
@ -896,7 +896,7 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
list[keys].num_attrs * list[keys].num_attrs *
sizeof(libssh2_publickey_attribute)); sizeof(libssh2_publickey_attribute));
if (!list[keys].attrs) { if (!list[keys].attrs) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for " "Unable to allocate memory for "
"publickey attributes"); "publickey attributes");
goto err_exit; goto err_exit;
@ -926,7 +926,7 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
break; break;
default: default:
/* Unknown/Unexpected */ /* Unknown/Unexpected */
libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Unexpected publickey subsystem response, ignoring"); "Unexpected publickey subsystem response, ignoring");
LIBSSH2_FREE(session, pkey->listFetch_data); LIBSSH2_FREE(session, pkey->listFetch_data);
pkey->listFetch_data = NULL; pkey->listFetch_data = NULL;

View File

@ -285,7 +285,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
LIBSSH2_ALLOC(session, session->scpRecv_command_len); LIBSSH2_ALLOC(session, session->scpRecv_command_len);
if (!session->scpRecv_command) { if (!session->scpRecv_command) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate a command buffer for " "Unable to allocate a command buffer for "
"SCP session"); "SCP session");
return NULL; return NULL;
@ -323,7 +323,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
session->scpRecv_state = libssh2_NB_state_idle; session->scpRecv_state = libssh2_NB_state_idle;
} }
else { else {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block starting up channel"); "Would block starting up channel");
} }
return NULL; return NULL;
@ -339,7 +339,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
(char *) session->scpRecv_command, (char *) session->scpRecv_command,
session->scpRecv_command_len); session->scpRecv_command_len);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block requesting SCP startup"); "Would block requesting SCP startup");
return NULL; return NULL;
} else if (rc) { } else if (rc) {
@ -361,7 +361,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
rc = _libssh2_channel_write(session->scpRecv_channel, 0, rc = _libssh2_channel_write(session->scpRecv_channel, 0,
(char *) session->scpRecv_response, 1); (char *) session->scpRecv_response, 1);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending initial wakeup"); "Would block sending initial wakeup");
return NULL; return NULL;
} else if (rc != 1) { } else if (rc != 1) {
@ -386,12 +386,12 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
scpRecv_response + scpRecv_response +
session->scpRecv_response_len, 1); session->scpRecv_response_len, 1);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for SCP response"); "Would block waiting for SCP response");
return NULL; return NULL;
} else if (rc <= 0) { } else if (rc <= 0) {
/* Timeout, give up */ /* Timeout, give up */
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Timed out waiting for SCP response"); "Timed out waiting for SCP response");
goto scp_recv_error; goto scp_recv_error;
} }
@ -402,7 +402,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
* Set this as the default error for here, if * Set this as the default error for here, if
* we are successful it will be replaced * we are successful it will be replaced
*/ */
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid data in SCP response, missing Time data"); "Invalid data in SCP response, missing Time data");
session->scpRecv_err_len = session->scpRecv_err_len =
@ -426,11 +426,11 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
* it is already in the systems so it can't return * it is already in the systems so it can't return
* PACKET_EAGAIN * PACKET_EAGAIN
*/ */
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Unknown error" ); "Unknown error" );
} }
else else
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"SCP protocol error"); "SCP protocol error");
/* TODO: for debugging purposes, the /* TODO: for debugging purposes, the
@ -458,7 +458,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
&& (session-> && (session->
scpRecv_response[session->scpRecv_response_len - 1] != scpRecv_response[session->scpRecv_response_len - 1] !=
'\n')) { '\n')) {
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid data in SCP response"); "Invalid data in SCP response");
goto scp_recv_error; goto scp_recv_error;
} }
@ -470,7 +470,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
if (session->scpRecv_response_len == if (session->scpRecv_response_len ==
LIBSSH2_SCP_RESPONSE_BUFLEN) { LIBSSH2_SCP_RESPONSE_BUFLEN) {
/* You had your chance */ /* You had your chance */
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Unterminated response from SCP server"); "Unterminated response from SCP server");
goto scp_recv_error; goto scp_recv_error;
} }
@ -493,7 +493,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
if (session->scpRecv_response_len < 8) { if (session->scpRecv_response_len < 8) {
/* EOL came too soon */ /* EOL came too soon */
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid response from SCP server, " "Invalid response from SCP server, "
"too short" ); "too short" );
goto scp_recv_error; goto scp_recv_error;
@ -504,7 +504,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
p = (unsigned char *) strchr((char *) s, ' '); p = (unsigned char *) strchr((char *) s, ' ');
if (!p || ((p - s) <= 0)) { if (!p || ((p - s) <= 0)) {
/* No spaces or space in the wrong spot */ /* No spaces or space in the wrong spot */
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid response from SCP server, " "Invalid response from SCP server, "
"malformed mtime"); "malformed mtime");
goto scp_recv_error; goto scp_recv_error;
@ -515,14 +515,14 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
errno = 0; errno = 0;
session->scpRecv_mtime = strtol((char *) s, NULL, 10); session->scpRecv_mtime = strtol((char *) s, NULL, 10);
if (errno) { if (errno) {
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid response from SCP server, invalid mtime"); "Invalid response from SCP server, invalid mtime");
goto scp_recv_error; goto scp_recv_error;
} }
s = (unsigned char *) strchr((char *) p, ' '); s = (unsigned char *) strchr((char *) p, ' ');
if (!s || ((s - p) <= 0)) { if (!s || ((s - p) <= 0)) {
/* No spaces or space in the wrong spot */ /* No spaces or space in the wrong spot */
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid response from SCP server, malformed mtime.usec"); "Invalid response from SCP server, malformed mtime.usec");
goto scp_recv_error; goto scp_recv_error;
} }
@ -532,7 +532,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
p = (unsigned char *) strchr((char *) s, ' '); p = (unsigned char *) strchr((char *) s, ' ');
if (!p || ((p - s) <= 0)) { if (!p || ((p - s) <= 0)) {
/* No spaces or space in the wrong spot */ /* No spaces or space in the wrong spot */
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid response from SCP server, too short or malformed"); "Invalid response from SCP server, too short or malformed");
goto scp_recv_error; goto scp_recv_error;
} }
@ -542,7 +542,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
errno = 0; errno = 0;
session->scpRecv_atime = strtol((char *) s, NULL, 10); session->scpRecv_atime = strtol((char *) s, NULL, 10);
if (errno) { if (errno) {
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid response from SCP server, invalid atime"); "Invalid response from SCP server, invalid atime");
goto scp_recv_error; goto scp_recv_error;
} }
@ -558,7 +558,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
(char *) session-> (char *) session->
scpRecv_response, 1); scpRecv_response, 1);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting to send SCP ACK"); "Would block waiting to send SCP ACK");
return NULL; return NULL;
} else if (rc != 1) { } else if (rc != 1) {
@ -595,19 +595,19 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
scpRecv_response + scpRecv_response +
session->scpRecv_response_len, 1); session->scpRecv_response_len, 1);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for SCP response"); "Would block waiting for SCP response");
return NULL; return NULL;
} else if (rc <= 0) { } else if (rc <= 0) {
/* Timeout, give up */ /* Timeout, give up */
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Timed out waiting for SCP response"); "Timed out waiting for SCP response");
goto scp_recv_error; goto scp_recv_error;
} }
session->scpRecv_response_len++; session->scpRecv_response_len++;
if (session->scpRecv_response[0] != 'C') { if (session->scpRecv_response[0] != 'C') {
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid response from SCP server"); "Invalid response from SCP server");
goto scp_recv_error; goto scp_recv_error;
} }
@ -625,7 +625,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
|| (session-> || (session->
scpRecv_response[session->scpRecv_response_len - 1] > scpRecv_response[session->scpRecv_response_len - 1] >
126))) { 126))) {
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid data in SCP response"); "Invalid data in SCP response");
goto scp_recv_error; goto scp_recv_error;
} }
@ -637,7 +637,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
if (session->scpRecv_response_len == if (session->scpRecv_response_len ==
LIBSSH2_SCP_RESPONSE_BUFLEN) { LIBSSH2_SCP_RESPONSE_BUFLEN) {
/* You had your chance */ /* You had your chance */
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Unterminated response from SCP server"); "Unterminated response from SCP server");
goto scp_recv_error; goto scp_recv_error;
} }
@ -661,7 +661,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
if (session->scpRecv_response_len < 6) { if (session->scpRecv_response_len < 6) {
/* EOL came too soon */ /* EOL came too soon */
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid response from SCP server, too short"); "Invalid response from SCP server, too short");
goto scp_recv_error; goto scp_recv_error;
} }
@ -671,7 +671,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
p = strchr(s, ' '); p = strchr(s, ' ');
if (!p || ((p - s) <= 0)) { if (!p || ((p - s) <= 0)) {
/* No spaces or space in the wrong spot */ /* No spaces or space in the wrong spot */
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid response from SCP server, malformed mode"); "Invalid response from SCP server, malformed mode");
goto scp_recv_error; goto scp_recv_error;
} }
@ -681,7 +681,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
errno = 0; errno = 0;
session->scpRecv_mode = strtol(s, &e, 8); session->scpRecv_mode = strtol(s, &e, 8);
if ((e && *e) || errno) { if ((e && *e) || errno) {
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid response from SCP server, invalid mode"); "Invalid response from SCP server, invalid mode");
goto scp_recv_error; goto scp_recv_error;
} }
@ -689,7 +689,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
s = strchr(p, ' '); s = strchr(p, ' ');
if (!s || ((s - p) <= 0)) { if (!s || ((s - p) <= 0)) {
/* No spaces or space in the wrong spot */ /* No spaces or space in the wrong spot */
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid response from SCP server, too short or malformed"); "Invalid response from SCP server, too short or malformed");
goto scp_recv_error; goto scp_recv_error;
} }
@ -699,7 +699,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
errno = 0; errno = 0;
session->scpRecv_size = scpsize_strtol(p, &e, 10); session->scpRecv_size = scpsize_strtol(p, &e, 10);
if ((e && *e) || errno) { if ((e && *e) || errno) {
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid response from SCP server, invalid size"); "Invalid response from SCP server, invalid size");
goto scp_recv_error; goto scp_recv_error;
} }
@ -715,7 +715,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
(char *) session-> (char *) session->
scpRecv_response, 1); scpRecv_response, 1);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending SCP ACK"); "Would block sending SCP ACK");
return NULL; return NULL;
} else if (rc != 1) { } else if (rc != 1) {
@ -789,7 +789,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
session->scpSend_command = session->scpSend_command =
LIBSSH2_ALLOC(session, session->scpSend_command_len); LIBSSH2_ALLOC(session, session->scpSend_command_len);
if (!session->scpSend_command) { if (!session->scpSend_command) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate a command buffer for scp session"); "Unable to allocate a command buffer for scp session");
return NULL; return NULL;
} }
@ -826,7 +826,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
session->scpSend_state = libssh2_NB_state_idle; session->scpSend_state = libssh2_NB_state_idle;
} }
else { else {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block starting up channel"); "Would block starting up channel");
} }
return NULL; return NULL;
@ -842,7 +842,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
(char *) session->scpSend_command, (char *) session->scpSend_command,
session->scpSend_command_len); session->scpSend_command_len);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block requesting SCP startup"); "Would block requesting SCP startup");
return NULL; return NULL;
} }
@ -851,7 +851,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
through */ through */
LIBSSH2_FREE(session, session->scpSend_command); LIBSSH2_FREE(session, session->scpSend_command);
session->scpSend_command = NULL; session->scpSend_command = NULL;
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Unknown error while getting error string"); "Unknown error while getting error string");
goto scp_send_error; goto scp_send_error;
} }
@ -866,11 +866,11 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
rc = _libssh2_channel_read(session->scpSend_channel, 0, rc = _libssh2_channel_read(session->scpSend_channel, 0,
(char *) session->scpSend_response, 1); (char *) session->scpSend_response, 1);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for response from remote"); "Would block waiting for response from remote");
return NULL; return NULL;
} else if ((rc <= 0) || (session->scpSend_response[0] != 0)) { } else if ((rc <= 0) || (session->scpSend_response[0] != 0)) {
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid ACK response from remote"); "Invalid ACK response from remote");
goto scp_send_error; goto scp_send_error;
} }
@ -895,11 +895,11 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
(char *) session->scpSend_response, (char *) session->scpSend_response,
session->scpSend_response_len); session->scpSend_response_len);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending time data for SCP file"); "Would block sending time data for SCP file");
return NULL; return NULL;
} else if (rc != (int)session->scpSend_response_len) { } else if (rc != (int)session->scpSend_response_len) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send time data for SCP file"); "Unable to send time data for SCP file");
goto scp_send_error; goto scp_send_error;
} }
@ -912,11 +912,11 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
rc = _libssh2_channel_read(session->scpSend_channel, 0, rc = _libssh2_channel_read(session->scpSend_channel, 0,
(char *) session->scpSend_response, 1); (char *) session->scpSend_response, 1);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for response"); "Would block waiting for response");
return NULL; return NULL;
} else if ((rc <= 0) || (session->scpSend_response[0] != 0)) { } else if ((rc <= 0) || (session->scpSend_response[0] != 0)) {
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid ACK response from remote"); "Invalid ACK response from remote");
goto scp_send_error; goto scp_send_error;
} }
@ -953,11 +953,11 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
(char *) session->scpSend_response, (char *) session->scpSend_response,
session->scpSend_response_len); session->scpSend_response_len);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block send core file data for SCP file"); "Would block send core file data for SCP file");
return NULL; return NULL;
} else if (rc != (int)session->scpSend_response_len) { } else if (rc != (int)session->scpSend_response_len) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send core file data for SCP file"); "Unable to send core file data for SCP file");
goto scp_send_error; goto scp_send_error;
} }
@ -970,11 +970,11 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
rc = _libssh2_channel_read(session->scpSend_channel, 0, rc = _libssh2_channel_read(session->scpSend_channel, 0,
(char *) session->scpSend_response, 1); (char *) session->scpSend_response, 1);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for response"); "Would block waiting for response");
return NULL; return NULL;
} else if (rc <= 0) { } else if (rc <= 0) {
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid ACK response from remote"); "Invalid ACK response from remote");
goto scp_send_error; goto scp_send_error;
} else if (session->scpSend_response[0] != 0) { } else if (session->scpSend_response[0] != 0) {
@ -982,7 +982,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
* Set this as the default error for here, if * Set this as the default error for here, if
* we are successful it will be replaced * we are successful it will be replaced
*/ */
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"Invalid ACK response from remote"); "Invalid ACK response from remote");
session->scpSend_err_len = session->scpSend_err_len =
@ -1007,7 +1007,7 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
session->scpSend_err_msg = NULL; session->scpSend_err_msg = NULL;
} }
else else
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
"failed waiting for ACK"); "failed waiting for ACK");
goto scp_send_error; goto scp_send_error;
} }

View File

@ -163,7 +163,7 @@ banner_receive(LIBSSH2_SESSION * session)
session->remote.banner = LIBSSH2_ALLOC(session, banner_len + 1); session->remote.banner = LIBSSH2_ALLOC(session, banner_len + 1);
if (!session->remote.banner) { if (!session->remote.banner) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Error allocating space for remote banner"); "Error allocating space for remote banner");
} }
memcpy(session->remote.banner, session->banner_TxRx_banner, banner_len); memcpy(session->remote.banner, session->banner_TxRx_banner, banner_len);
@ -403,7 +403,7 @@ libssh2_banner_set(LIBSSH2_SESSION * session, const char *banner)
session->local.banner = LIBSSH2_ALLOC(session, banner_len + 3); session->local.banner = LIBSSH2_ALLOC(session, banner_len + 3);
if (!session->local.banner) { if (!session->local.banner) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for local banner"); "Unable to allocate memory for local banner");
} }
@ -592,7 +592,7 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock)
"session_startup for socket %d", sock); "session_startup for socket %d", sock);
if (INVALID_SOCKET == sock) { if (INVALID_SOCKET == sock) {
/* Did we forget something? */ /* Did we forget something? */
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_NONE, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_NONE,
"Bad socket provided"); "Bad socket provided");
} }
session->socket_fd = sock; session->socket_fd = sock;
@ -611,7 +611,7 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock)
if (session->startup_state == libssh2_NB_state_created) { if (session->startup_state == libssh2_NB_state_created) {
rc = banner_send(session); rc = banner_send(session);
if (rc) { if (rc) {
return libssh2_error(session, rc, return _libssh2_error(session, rc,
"Failed sending banner"); "Failed sending banner");
} }
session->startup_state = libssh2_NB_state_sent; session->startup_state = libssh2_NB_state_sent;
@ -620,7 +620,7 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock)
if (session->startup_state == libssh2_NB_state_sent) { if (session->startup_state == libssh2_NB_state_sent) {
rc = banner_receive(session); rc = banner_receive(session);
if (rc) { if (rc) {
return libssh2_error(session, rc, return _libssh2_error(session, rc,
"Failed getting banner"); "Failed getting banner");
} }
@ -630,7 +630,7 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock)
if (session->startup_state == libssh2_NB_state_sent1) { if (session->startup_state == libssh2_NB_state_sent1) {
rc = libssh2_kex_exchange(session, 0, &session->startup_key_state); rc = libssh2_kex_exchange(session, 0, &session->startup_key_state);
if (rc) { if (rc) {
return libssh2_error(session, rc, return _libssh2_error(session, rc,
"Unable to exchange encryption keys"); "Unable to exchange encryption keys");
} }
@ -655,7 +655,7 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock)
rc = _libssh2_transport_write(session, session->startup_service, rc = _libssh2_transport_write(session, session->startup_service,
sizeof("ssh-userauth") + 5 - 1); sizeof("ssh-userauth") + 5 - 1);
if (rc) { if (rc) {
return libssh2_error(session, rc, return _libssh2_error(session, rc,
"Unable to ask for ssh-userauth service"); "Unable to ask for ssh-userauth service");
} }
@ -678,7 +678,7 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock)
session->startup_service_length)) { session->startup_service_length)) {
LIBSSH2_FREE(session, session->startup_data); LIBSSH2_FREE(session, session->startup_data);
session->startup_data = NULL; session->startup_data = NULL;
return libssh2_error(session, LIBSSH2_ERROR_PROTO, return _libssh2_error(session, LIBSSH2_ERROR_PROTO,
"Invalid response received from server"); "Invalid response received from server");
} }
LIBSSH2_FREE(session, session->startup_data); LIBSSH2_FREE(session, session->startup_data);
@ -1004,7 +1004,7 @@ session_disconnect(LIBSSH2_SESSION *session, int reason,
LIBSSH2_ALLOC(session, session->disconnect_data_len); LIBSSH2_ALLOC(session, session->disconnect_data_len);
if (!session->disconnect_data) { if (!session->disconnect_data) {
session->disconnect_state = libssh2_NB_state_idle; session->disconnect_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for " "Unable to allocate memory for "
"disconnect packet"); "disconnect packet");
} }
@ -1111,13 +1111,13 @@ libssh2_session_methods(LIBSSH2_SESSION * session, int method_type)
return ""; return "";
default: default:
libssh2_error(session, LIBSSH2_ERROR_INVAL, _libssh2_error(session, LIBSSH2_ERROR_INVAL,
"Invalid parameter specified for method_type"); "Invalid parameter specified for method_type");
return NULL; return NULL;
} }
if (!method) { if (!method) {
libssh2_error(session, LIBSSH2_ERROR_METHOD_NONE, _libssh2_error(session, LIBSSH2_ERROR_METHOD_NONE,
"No method negotiated"); "No method negotiated");
return NULL; return NULL;
} }
@ -1358,7 +1358,7 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
default: default:
if (session) if (session)
libssh2_error(session, LIBSSH2_ERROR_INVALID_POLL_TYPE, _libssh2_error(session, LIBSSH2_ERROR_INVALID_POLL_TYPE,
"Invalid descriptor passed to libssh2_poll()"); "Invalid descriptor passed to libssh2_poll()");
return -1; return -1;
} }
@ -1405,7 +1405,7 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout)
default: default:
if (session) if (session)
libssh2_error(session, LIBSSH2_ERROR_INVALID_POLL_TYPE, _libssh2_error(session, LIBSSH2_ERROR_INVALID_POLL_TYPE,
"Invalid descriptor passed to libssh2_poll()"); "Invalid descriptor passed to libssh2_poll()");
return -1; return -1;
} }

View File

@ -122,7 +122,7 @@ sftp_packet_add(LIBSSH2_SFTP *sftp, unsigned char *data,
(int) data[0], data_len); (int) data[0], data_len);
packet = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_PACKET)); packet = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_PACKET));
if (!packet) { if (!packet) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate datablock for SFTP packet"); "Unable to allocate datablock for SFTP packet");
} }
memset(packet, 0, sizeof(LIBSSH2_PACKET)); memset(packet, 0, sizeof(LIBSSH2_PACKET));
@ -174,7 +174,7 @@ sftp_packet_read(LIBSSH2_SFTP *sftp)
/* TODO: this is stupid since we can in fact get 1-3 bytes in a /* 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 legitimate working case as well if the connection happens to be
super slow or something */ super slow or something */
return libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE, return _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE,
"Read part of packet"); "Read part of packet");
} }
@ -182,13 +182,13 @@ sftp_packet_read(LIBSSH2_SFTP *sftp)
_libssh2_debug(session, LIBSSH2_TRACE_SFTP, _libssh2_debug(session, LIBSSH2_TRACE_SFTP,
"Data begin - Packet Length: %lu", packet_len); "Data begin - Packet Length: %lu", packet_len);
if (packet_len > LIBSSH2_SFTP_PACKET_MAXLEN) { if (packet_len > LIBSSH2_SFTP_PACKET_MAXLEN) {
return libssh2_error(session, LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED, return _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED,
"SFTP packet too large"); "SFTP packet too large");
} }
packet = LIBSSH2_ALLOC(session, packet_len); packet = LIBSSH2_ALLOC(session, packet_len);
if (!packet) { if (!packet) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate SFTP packet"); "Unable to allocate SFTP packet");
} }
@ -216,7 +216,7 @@ sftp_packet_read(LIBSSH2_SFTP *sftp)
} }
else if (bytes_received < 0) { else if (bytes_received < 0) {
LIBSSH2_FREE(session, packet); LIBSSH2_FREE(session, packet);
return libssh2_error(session, bytes_received, return _libssh2_error(session, bytes_received,
"Receive error waiting for SFTP packet"); "Receive error waiting for SFTP packet");
} }
packet_received += bytes_received; packet_received += bytes_received;
@ -554,11 +554,11 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0); LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0);
if (!session->sftpInit_channel) { if (!session->sftpInit_channel) {
if (libssh2_session_last_errno(session) == LIBSSH2_ERROR_EAGAIN) { if (libssh2_session_last_errno(session) == LIBSSH2_ERROR_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block starting up channel"); "Would block starting up channel");
} }
else { else {
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE, _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE,
"Unable to startup channel"); "Unable to startup channel");
session->sftpInit_state = libssh2_NB_state_idle; session->sftpInit_state = libssh2_NB_state_idle;
} }
@ -574,11 +574,11 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
sizeof("subsystem") - 1, "sftp", sizeof("subsystem") - 1, "sftp",
strlen("sftp")); strlen("sftp"));
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block to request SFTP subsystem"); "Would block to request SFTP subsystem");
return NULL; return NULL;
} else if (rc) { } else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE, _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE,
"Unable to request SFTP subsystem"); "Unable to request SFTP subsystem");
goto sftp_init_error; goto sftp_init_error;
} }
@ -590,7 +590,7 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
rc = _libssh2_channel_extended_data(session->sftpInit_channel, rc = _libssh2_channel_extended_data(session->sftpInit_channel,
LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE); LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block requesting handle extended data"); "Would block requesting handle extended data");
return NULL; return NULL;
} }
@ -599,7 +599,7 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
session->sftpInit_sftp = session->sftpInit_sftp =
LIBSSH2_ALLOC(session, sizeof(LIBSSH2_SFTP)); LIBSSH2_ALLOC(session, sizeof(LIBSSH2_SFTP));
if (!sftp_handle) { if (!sftp_handle) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate a new SFTP structure"); "Unable to allocate a new SFTP structure");
goto sftp_init_error; goto sftp_init_error;
} }
@ -626,12 +626,12 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
session->sftpInit_sent, session->sftpInit_sent,
9 - session->sftpInit_sent); 9 - session->sftpInit_sent);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending SSH_FXP_INIT"); "Would block sending SSH_FXP_INIT");
return NULL; return NULL;
} }
else if(rc < 0) { else if(rc < 0) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send SSH_FXP_INIT"); "Unable to send SSH_FXP_INIT");
goto sftp_init_error; goto sftp_init_error;
} }
@ -650,16 +650,16 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
rc = sftp_packet_require(sftp_handle, SSH_FXP_VERSION, rc = sftp_packet_require(sftp_handle, SSH_FXP_VERSION,
0, &data, &data_len); 0, &data, &data_len);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for response from SFTP subsystem"); "Would block waiting for response from SFTP subsystem");
return NULL; return NULL;
} else if (rc) { } else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for response from SFTP subsystem"); "Timeout waiting for response from SFTP subsystem");
goto sftp_init_error; goto sftp_init_error;
} }
if (data_len < 5) { if (data_len < 5) {
libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Invalid SSH_FXP_VERSION response"); "Invalid SSH_FXP_VERSION response");
goto sftp_init_error; goto sftp_init_error;
} }
@ -841,7 +841,7 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
s = sftp->open_packet = LIBSSH2_ALLOC(session, sftp->open_packet_len); s = sftp->open_packet = LIBSSH2_ALLOC(session, sftp->open_packet_len);
if (!sftp->open_packet) { if (!sftp->open_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_OPEN or " "Unable to allocate memory for FXP_OPEN or "
"FXP_OPENDIR packet"); "FXP_OPENDIR packet");
return NULL; return NULL;
@ -881,7 +881,7 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
rc = _libssh2_channel_write(channel, 0, (char *) sftp->open_packet, rc = _libssh2_channel_write(channel, 0, (char *) sftp->open_packet,
sftp->open_packet_len); sftp->open_packet_len);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending FXP_OPEN or FXP_OPENDIR command"); "Would block sending FXP_OPEN or FXP_OPENDIR command");
return NULL; return NULL;
} }
@ -889,7 +889,7 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
/* TODO: partial writes should be fine too and is not a sign of /* TODO: partial writes should be fine too and is not a sign of
an error when in non-blocking mode! */ an error when in non-blocking mode! */
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send FXP_OPEN or FXP_OPENDIR command"); "Unable to send FXP_OPEN or FXP_OPENDIR command");
LIBSSH2_FREE(session, sftp->open_packet); LIBSSH2_FREE(session, sftp->open_packet);
sftp->open_packet = NULL; sftp->open_packet = NULL;
@ -907,12 +907,12 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
sftp->open_request_id, &data, sftp->open_request_id, &data,
&data_len); &data_len);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for status message"); "Would block waiting for status message");
return NULL; return NULL;
} }
else if (rc) { 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; sftp->open_state = libssh2_NB_state_idle;
return NULL; return NULL;
} }
@ -945,7 +945,7 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
} }
if(badness) { if(badness) {
libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Failed opening remote file"); "Failed opening remote file");
_libssh2_debug(session, LIBSSH2_TRACE_SFTP, "got FXP_STATUS %d", _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "got FXP_STATUS %d",
sftp->last_errno); sftp->last_errno);
@ -956,7 +956,7 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
fp = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_SFTP_HANDLE)); fp = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_SFTP_HANDLE));
if (!fp) { if (!fp) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate new SFTP handle structure"); "Unable to allocate new SFTP handle structure");
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
return NULL; return NULL;
@ -1101,7 +1101,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
non-blocking mode! */ non-blocking mode! */
sftp->read_packet = NULL; sftp->read_packet = NULL;
sftp->read_state = libssh2_NB_state_idle; sftp->read_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"_libssh2_channel_write() failed"); "_libssh2_channel_write() failed");
} }
sftp->read_packet = packet; sftp->read_packet = packet;
@ -1115,12 +1115,12 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
sftp_packet_requirev(sftp, 2, read_responses, sftp_packet_requirev(sftp, 2, read_responses,
request_id, &data, &data_len); request_id, &data, &data_len);
if (retcode == PACKET_EAGAIN) { if (retcode == PACKET_EAGAIN) {
return libssh2_error(session, retcode, return _libssh2_error(session, retcode,
"Would block waiting for status message"); "Would block waiting for status message");
} else if (retcode) { } else if (retcode) {
sftp->read_packet = NULL; sftp->read_packet = NULL;
sftp->read_state = libssh2_NB_state_idle; sftp->read_state = libssh2_NB_state_idle;
return libssh2_error(session, retcode, return _libssh2_error(session, retcode,
"Timeout waiting for status message"); "Timeout waiting for status message");
} }
@ -1141,7 +1141,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
return total_read; return total_read;
} else { } else {
sftp->last_errno = retcode; sftp->last_errno = retcode;
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error"); "SFTP Protocol Error");
} }
@ -1260,7 +1260,7 @@ static int sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer,
s = sftp->readdir_packet = LIBSSH2_ALLOC(session, packet_len); s = sftp->readdir_packet = LIBSSH2_ALLOC(session, packet_len);
if (!sftp->readdir_packet) if (!sftp->readdir_packet)
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for " "Unable to allocate memory for "
"FXP_READDIR packet"); "FXP_READDIR packet");
@ -1291,7 +1291,7 @@ static int sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer,
LIBSSH2_FREE(session, sftp->readdir_packet); LIBSSH2_FREE(session, sftp->readdir_packet);
sftp->readdir_packet = NULL; sftp->readdir_packet = NULL;
sftp->readdir_state = libssh2_NB_state_idle; sftp->readdir_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"_libssh2_channel_write() failed"); "_libssh2_channel_write() failed");
} }
@ -1308,7 +1308,7 @@ static int sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer,
return retcode; return retcode;
else if (retcode) { else if (retcode) {
sftp->readdir_state = libssh2_NB_state_idle; sftp->readdir_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message"); "Timeout waiting for status message");
} }
@ -1322,7 +1322,7 @@ static int sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer,
else { else {
sftp->last_errno = retcode; sftp->last_errno = retcode;
sftp->readdir_state = libssh2_NB_state_idle; sftp->readdir_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error"); "SFTP Protocol Error");
} }
} }
@ -1395,7 +1395,7 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
(unsigned long) count); (unsigned long) count);
s = sftp->write_packet = LIBSSH2_ALLOC(session, packet_len); s = sftp->write_packet = LIBSSH2_ALLOC(session, packet_len);
if (!sftp->write_packet) { if (!sftp->write_packet) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_WRITE"); "Unable to allocate memory for FXP_WRITE");
} }
_libssh2_htonu32(s, packet_len - 4); _libssh2_htonu32(s, packet_len - 4);
@ -1444,7 +1444,7 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
} }
else if (rc) { else if (rc) {
sftp->write_state = libssh2_NB_state_idle; sftp->write_state = libssh2_NB_state_idle;
return libssh2_error(session, rc, return _libssh2_error(session, rc,
"Timeout waiting for status message"); "Timeout waiting for status message");
} }
@ -1459,7 +1459,7 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
} }
sftp->last_errno = retcode; sftp->last_errno = retcode;
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error"); "SFTP Protocol Error");
} }
@ -1502,7 +1502,7 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle,
setstat ? "set-stat" : "stat"); setstat ? "set-stat" : "stat");
s = sftp->fstat_packet = LIBSSH2_ALLOC(session, packet_len); s = sftp->fstat_packet = LIBSSH2_ALLOC(session, packet_len);
if (!sftp->fstat_packet) { if (!sftp->fstat_packet) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for " "Unable to allocate memory for "
"FSTAT/FSETSTAT packet"); "FSTAT/FSETSTAT packet");
} }
@ -1533,7 +1533,7 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle,
LIBSSH2_FREE(session, sftp->fstat_packet); LIBSSH2_FREE(session, sftp->fstat_packet);
sftp->fstat_packet = NULL; sftp->fstat_packet = NULL;
sftp->fstat_state = libssh2_NB_state_idle; sftp->fstat_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
(setstat ? "Unable to send FXP_FSETSTAT" (setstat ? "Unable to send FXP_FSETSTAT"
: "Unable to send FXP_FSTAT command")); : "Unable to send FXP_FSTAT command"));
} }
@ -1550,7 +1550,7 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle,
return rc; return rc;
} else if (rc) { } else if (rc) {
sftp->fstat_state = libssh2_NB_state_idle; sftp->fstat_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message"); "Timeout waiting for status message");
} }
@ -1565,7 +1565,7 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle,
return 0; return 0;
} else { } else {
sftp->last_errno = retcode; sftp->last_errno = retcode;
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error"); "SFTP Protocol Error");
} }
} }
@ -1650,7 +1650,7 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle)
_libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Closing handle"); _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Closing handle");
s = handle->close_packet = LIBSSH2_ALLOC(session, packet_len); s = handle->close_packet = LIBSSH2_ALLOC(session, packet_len);
if (!handle->close_packet) { if (!handle->close_packet) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_CLOSE " "Unable to allocate memory for FXP_CLOSE "
"packet"); "packet");
} }
@ -1678,7 +1678,7 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle)
LIBSSH2_FREE(session, handle->close_packet); LIBSSH2_FREE(session, handle->close_packet);
handle->close_packet = NULL; handle->close_packet = NULL;
handle->close_state = libssh2_NB_state_idle; handle->close_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send FXP_CLOSE command"); "Unable to send FXP_CLOSE command");
} }
LIBSSH2_FREE(session, handle->close_packet); LIBSSH2_FREE(session, handle->close_packet);
@ -1695,7 +1695,7 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle)
return rc; return rc;
} else if (rc) { } else if (rc) {
handle->close_state = libssh2_NB_state_idle; handle->close_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message"); "Timeout waiting for status message");
} }
@ -1708,7 +1708,7 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle)
if (retcode != LIBSSH2_FX_OK) { if (retcode != LIBSSH2_FX_OK) {
sftp->last_errno = retcode; sftp->last_errno = retcode;
handle->close_state = libssh2_NB_state_idle; handle->close_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error"); "SFTP Protocol Error");
} }
@ -1759,7 +1759,7 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename,
_libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Unlinking %s", filename); _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Unlinking %s", filename);
s = sftp->unlink_packet = LIBSSH2_ALLOC(session, packet_len); s = sftp->unlink_packet = LIBSSH2_ALLOC(session, packet_len);
if (!sftp->unlink_packet) { if (!sftp->unlink_packet) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_REMOVE " "Unable to allocate memory for FXP_REMOVE "
"packet"); "packet");
} }
@ -1787,7 +1787,7 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename,
LIBSSH2_FREE(session, sftp->unlink_packet); LIBSSH2_FREE(session, sftp->unlink_packet);
sftp->unlink_packet = NULL; sftp->unlink_packet = NULL;
sftp->unlink_state = libssh2_NB_state_idle; sftp->unlink_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send FXP_REMOVE command"); "Unable to send FXP_REMOVE command");
} }
LIBSSH2_FREE(session, sftp->unlink_packet); LIBSSH2_FREE(session, sftp->unlink_packet);
@ -1804,7 +1804,7 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename,
} }
else if (rc) { else if (rc) {
sftp->unlink_state = libssh2_NB_state_idle; sftp->unlink_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message"); "Timeout waiting for status message");
} }
@ -1817,7 +1817,7 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename,
return 0; return 0;
} else { } else {
sftp->last_errno = retcode; sftp->last_errno = retcode;
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error"); "SFTP Protocol Error");
} }
} }
@ -1858,7 +1858,7 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename,
int rc; int rc;
if (sftp->version < 2) { if (sftp->version < 2) {
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Server does not support RENAME"); "Server does not support RENAME");
} }
@ -1868,7 +1868,7 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename,
sftp->rename_s = sftp->rename_packet = sftp->rename_s = sftp->rename_packet =
LIBSSH2_ALLOC(session, packet_len); LIBSSH2_ALLOC(session, packet_len);
if (!sftp->rename_packet) { if (!sftp->rename_packet) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_RENAME " "Unable to allocate memory for FXP_RENAME "
"packet"); "packet");
} }
@ -1905,7 +1905,7 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename,
LIBSSH2_FREE(session, sftp->rename_packet); LIBSSH2_FREE(session, sftp->rename_packet);
sftp->rename_packet = NULL; sftp->rename_packet = NULL;
sftp->rename_state = libssh2_NB_state_idle; sftp->rename_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send FXP_RENAME command"); "Unable to send FXP_RENAME command");
} }
LIBSSH2_FREE(session, sftp->rename_packet); LIBSSH2_FREE(session, sftp->rename_packet);
@ -1921,7 +1921,7 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename,
return rc; return rc;
} else if (rc) { } else if (rc) {
sftp->rename_state = libssh2_NB_state_idle; sftp->rename_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message"); "Timeout waiting for status message");
} }
@ -1940,18 +1940,18 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename,
break; break;
case LIBSSH2_FX_FILE_ALREADY_EXISTS: case LIBSSH2_FX_FILE_ALREADY_EXISTS:
retcode = libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, retcode = _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"File already exists and " "File already exists and "
"SSH_FXP_RENAME_OVERWRITE not specified"); "SSH_FXP_RENAME_OVERWRITE not specified");
break; break;
case LIBSSH2_FX_OP_UNSUPPORTED: case LIBSSH2_FX_OP_UNSUPPORTED:
retcode = libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, retcode = _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Operation Not Supported"); "Operation Not Supported");
break; break;
default: default:
retcode = libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, retcode = _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error"); "SFTP Protocol Error");
break; break;
} }
@ -2000,7 +2000,7 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path,
"Creating directory %s with mode 0%lo", path, mode); "Creating directory %s with mode 0%lo", path, mode);
s = packet = LIBSSH2_ALLOC(session, packet_len); s = packet = LIBSSH2_ALLOC(session, packet_len);
if (!packet) { if (!packet) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_MKDIR " "Unable to allocate memory for FXP_MKDIR "
"packet"); "packet");
} }
@ -2034,7 +2034,7 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path,
if (packet_len != rc) { if (packet_len != rc) {
LIBSSH2_FREE(session, packet); LIBSSH2_FREE(session, packet);
sftp->mkdir_state = libssh2_NB_state_idle; sftp->mkdir_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"_libssh2_channel_write() failed"); "_libssh2_channel_write() failed");
} }
LIBSSH2_FREE(session, packet); LIBSSH2_FREE(session, packet);
@ -2048,7 +2048,7 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path,
return rc; return rc;
} else if (rc) { } else if (rc) {
sftp->mkdir_state = libssh2_NB_state_idle; sftp->mkdir_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message"); "Timeout waiting for status message");
} }
@ -2062,7 +2062,7 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path,
return 0; return 0;
} else { } else {
sftp->last_errno = retcode; sftp->last_errno = retcode;
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error"); "SFTP Protocol Error");
} }
} }
@ -2102,7 +2102,7 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path,
path); path);
s = sftp->rmdir_packet = LIBSSH2_ALLOC(session, packet_len); s = sftp->rmdir_packet = LIBSSH2_ALLOC(session, packet_len);
if (!sftp->rmdir_packet) { if (!sftp->rmdir_packet) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_RMDIR " "Unable to allocate memory for FXP_RMDIR "
"packet"); "packet");
} }
@ -2130,7 +2130,7 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path,
LIBSSH2_FREE(session, sftp->rmdir_packet); LIBSSH2_FREE(session, sftp->rmdir_packet);
sftp->rmdir_packet = NULL; sftp->rmdir_packet = NULL;
sftp->rmdir_state = libssh2_NB_state_idle; sftp->rmdir_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send FXP_RMDIR command"); "Unable to send FXP_RMDIR command");
} }
LIBSSH2_FREE(session, sftp->rmdir_packet); LIBSSH2_FREE(session, sftp->rmdir_packet);
@ -2145,7 +2145,7 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path,
return rc; return rc;
} else if (rc) { } else if (rc) {
sftp->rmdir_state = libssh2_NB_state_idle; sftp->rmdir_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message"); "Timeout waiting for status message");
} }
@ -2158,7 +2158,7 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path,
return 0; return 0;
} else { } else {
sftp->last_errno = retcode; sftp->last_errno = retcode;
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error"); "SFTP Protocol Error");
} }
} }
@ -2203,7 +2203,7 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path,
LIBSSH2_SFTP_LSTAT ? "LStatting" : "Statting"), path); LIBSSH2_SFTP_LSTAT ? "LStatting" : "Statting"), path);
s = sftp->stat_packet = LIBSSH2_ALLOC(session, packet_len); s = sftp->stat_packet = LIBSSH2_ALLOC(session, packet_len);
if (!sftp->stat_packet) { if (!sftp->stat_packet) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_*STAT " "Unable to allocate memory for FXP_*STAT "
"packet"); "packet");
} }
@ -2246,7 +2246,7 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path,
LIBSSH2_FREE(session, sftp->stat_packet); LIBSSH2_FREE(session, sftp->stat_packet);
sftp->stat_packet = NULL; sftp->stat_packet = NULL;
sftp->stat_state = libssh2_NB_state_idle; sftp->stat_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send STAT/LSTAT/SETSTAT command"); "Unable to send STAT/LSTAT/SETSTAT command");
} }
LIBSSH2_FREE(session, sftp->stat_packet); LIBSSH2_FREE(session, sftp->stat_packet);
@ -2261,7 +2261,7 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path,
return rc; return rc;
} else if (rc) { } else if (rc) {
sftp->stat_state = libssh2_NB_state_idle; sftp->stat_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message"); "Timeout waiting for status message");
} }
@ -2276,7 +2276,7 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path,
return 0; return 0;
} else { } else {
sftp->last_errno = retcode; sftp->last_errno = retcode;
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error"); "SFTP Protocol Error");
} }
} }
@ -2322,14 +2322,14 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path,
int rc; int rc;
if ((sftp->version < 3) && (link_type != LIBSSH2_SFTP_REALPATH)) { if ((sftp->version < 3) && (link_type != LIBSSH2_SFTP_REALPATH)) {
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Server does not support SYMLINK or READLINK"); "Server does not support SYMLINK or READLINK");
} }
if (sftp->symlink_state == libssh2_NB_state_idle) { if (sftp->symlink_state == libssh2_NB_state_idle) {
s = sftp->symlink_packet = LIBSSH2_ALLOC(session, packet_len); s = sftp->symlink_packet = LIBSSH2_ALLOC(session, packet_len);
if (!sftp->symlink_packet) { if (!sftp->symlink_packet) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for " "Unable to allocate memory for "
"SYMLINK/READLINK/REALPATH packet"); "SYMLINK/READLINK/REALPATH packet");
} }
@ -2381,7 +2381,7 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path,
LIBSSH2_FREE(session, sftp->symlink_packet); LIBSSH2_FREE(session, sftp->symlink_packet);
sftp->symlink_packet = NULL; sftp->symlink_packet = NULL;
sftp->symlink_state = libssh2_NB_state_idle; sftp->symlink_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send SYMLINK/READLINK command"); "Unable to send SYMLINK/READLINK command");
} }
LIBSSH2_FREE(session, sftp->symlink_packet); LIBSSH2_FREE(session, sftp->symlink_packet);
@ -2398,7 +2398,7 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path,
} }
else if (rc) { else if (rc) {
sftp->symlink_state = libssh2_NB_state_idle; sftp->symlink_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
"Timeout waiting for status message"); "Timeout waiting for status message");
} }
@ -2413,14 +2413,14 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path,
return 0; return 0;
} else { } else {
sftp->last_errno = retcode; sftp->last_errno = retcode;
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error"); "SFTP Protocol Error");
} }
} }
if (_libssh2_ntohu32(data + 5) < 1) { if (_libssh2_ntohu32(data + 5) < 1) {
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
return libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Invalid READLINK/REALPATH response, " "Invalid READLINK/REALPATH response, "
"no name entries"); "no name entries");
} }
@ -2459,5 +2459,3 @@ libssh2_sftp_last_error(LIBSSH2_SFTP *sftp)
{ {
return sftp->last_errno; return sftp->last_errno;
} }

View File

@ -71,7 +71,8 @@ debugdump(LIBSSH2_SESSION * session,
used = snprintf(buffer, sizeof(buffer), "=> %s (%d bytes)\n", used = snprintf(buffer, sizeof(buffer), "=> %s (%d bytes)\n",
desc, (int) size); desc, (int) size);
if (session->tracehandler) if (session->tracehandler)
(session->tracehandler)(session, session->tracehandler_context, buffer, used); (session->tracehandler)(session, session->tracehandler_context,
buffer, used);
else else
write(2 /* stderr */, buffer, used); write(2 /* stderr */, buffer, used);
@ -106,7 +107,8 @@ debugdump(LIBSSH2_SESSION * session,
buffer[used] = 0; buffer[used] = 0;
if (session->tracehandler) if (session->tracehandler)
(session->tracehandler)(session, session->tracehandler_context, buffer, used); (session->tracehandler)(session, session->tracehandler_context,
buffer, used);
else else
write(2, buffer, used); 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 * This function reads the binary stream as specified in chapter 6 of RFC4253
* "The Secure Shell (SSH) Transport Layer Protocol" * "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) 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. * which is what all implementations should support at least as packet size.
* (RFC4253 section 6.1) * (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 int
_libssh2_transport_write(LIBSSH2_SESSION * session, unsigned char *data, _libssh2_transport_write(LIBSSH2_SESSION * session, unsigned char *data,

View File

@ -78,7 +78,7 @@ static char *userauth_list(LIBSSH2_SESSION *session, const char *username,
s = session->userauth_list_data = s = session->userauth_list_data =
LIBSSH2_ALLOC(session, session->userauth_list_data_len); LIBSSH2_ALLOC(session, session->userauth_list_data_len);
if (!session->userauth_list_data) { if (!session->userauth_list_data) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for userauth_list"); "Unable to allocate memory for userauth_list");
return NULL; return NULL;
} }
@ -108,7 +108,7 @@ static char *userauth_list(LIBSSH2_SESSION *session, const char *username,
rc = _libssh2_transport_write(session, session->userauth_list_data, rc = _libssh2_transport_write(session, session->userauth_list_data,
session->userauth_list_data_len); session->userauth_list_data_len);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block requesting userauth list"); "Would block requesting userauth list");
return NULL; return NULL;
} }
@ -117,7 +117,7 @@ static char *userauth_list(LIBSSH2_SESSION *session, const char *username,
session->userauth_list_data = NULL; session->userauth_list_data = NULL;
if (rc) { if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send userauth-none request"); "Unable to send userauth-none request");
session->userauth_list_state = libssh2_NB_state_idle; session->userauth_list_state = libssh2_NB_state_idle;
return NULL; return NULL;
@ -133,18 +133,18 @@ static char *userauth_list(LIBSSH2_SESSION *session, const char *username,
NULL, 0, NULL, 0,
&session->userauth_list_packet_requirev_state); &session->userauth_list_packet_requirev_state);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block requesting userauth list"); "Would block requesting userauth list");
return NULL; return NULL;
} else if (rc) { } 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; session->userauth_list_state = libssh2_NB_state_idle;
return NULL; return NULL;
} }
if (session->userauth_list_data[0] == SSH_MSG_USERAUTH_SUCCESS) { if (session->userauth_list_data[0] == SSH_MSG_USERAUTH_SUCCESS) {
/* Wow, who'dve thought... */ /* 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); LIBSSH2_FREE(session, session->userauth_list_data);
session->userauth_list_data = NULL; session->userauth_list_data = NULL;
session->state |= LIBSSH2_STATE_AUTHENTICATED; session->state |= LIBSSH2_STATE_AUTHENTICATED;
@ -230,7 +230,7 @@ userauth_password(LIBSSH2_SESSION *session, const char *username,
s = session->userauth_pswd_data = s = session->userauth_pswd_data =
LIBSSH2_ALLOC(session, session->userauth_pswd_data_len); LIBSSH2_ALLOC(session, session->userauth_pswd_data_len);
if (!session->userauth_pswd_data) { if (!session->userauth_pswd_data) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for " "Unable to allocate memory for "
"userauth-password request"); "userauth-password request");
} }
@ -269,7 +269,7 @@ userauth_password(LIBSSH2_SESSION *session, const char *username,
rc = _libssh2_transport_write(session, session->userauth_pswd_data, rc = _libssh2_transport_write(session, session->userauth_pswd_data,
session->userauth_pswd_data_len); session->userauth_pswd_data_len);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
return libssh2_error(session, LIBSSH2_ERROR_EAGAIN, return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block writing password request"); "Would block writing password request");
} }
@ -279,7 +279,7 @@ userauth_password(LIBSSH2_SESSION *session, const char *username,
if (rc) { if (rc) {
session->userauth_pswd_state = libssh2_NB_state_idle; session->userauth_pswd_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send userauth-password request"); "Unable to send userauth-password request");
} }
@ -299,11 +299,11 @@ userauth_password(LIBSSH2_SESSION *session, const char *username,
&session-> &session->
userauth_pswd_packet_requirev_state); userauth_pswd_packet_requirev_state);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
return libssh2_error(session, LIBSSH2_ERROR_EAGAIN, return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting"); "Would block waiting");
} else if (rc) { } else if (rc) {
session->userauth_pswd_state = libssh2_NB_state_idle; session->userauth_pswd_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_TIMEOUT, return _libssh2_error(session, LIBSSH2_ERROR_TIMEOUT,
"Would block waiting"); "Would block waiting");
} }
@ -321,7 +321,7 @@ userauth_password(LIBSSH2_SESSION *session, const char *username,
LIBSSH2_FREE(session, session->userauth_pswd_data); LIBSSH2_FREE(session, session->userauth_pswd_data);
session->userauth_pswd_data = NULL; session->userauth_pswd_data = NULL;
session->userauth_pswd_state = libssh2_NB_state_idle; session->userauth_pswd_state = libssh2_NB_state_idle;
return libssh2_error(session, return _libssh2_error(session,
LIBSSH2_ERROR_AUTHENTICATION_FAILED, LIBSSH2_ERROR_AUTHENTICATION_FAILED,
"Authentication failed " "Authentication failed "
"(username/password)"); "(username/password)");
@ -354,7 +354,7 @@ userauth_password(LIBSSH2_SESSION *session, const char *username,
&session->userauth_pswd_newpw_len, &session->userauth_pswd_newpw_len,
&session->abstract); &session->abstract);
if (!session->userauth_pswd_newpw) { if (!session->userauth_pswd_newpw) {
return libssh2_error(session, return _libssh2_error(session,
LIBSSH2_ERROR_PASSWORD_EXPIRED, LIBSSH2_ERROR_PASSWORD_EXPIRED,
"Password expired, and " "Password expired, and "
"callback failed"); "callback failed");
@ -372,7 +372,7 @@ userauth_password(LIBSSH2_SESSION *session, const char *username,
LIBSSH2_FREE(session, LIBSSH2_FREE(session,
session->userauth_pswd_newpw); session->userauth_pswd_newpw);
session->userauth_pswd_newpw = NULL; session->userauth_pswd_newpw = NULL;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory " "Unable to allocate memory "
"for userauth password " "for userauth password "
"change request"); "change request");
@ -418,7 +418,7 @@ userauth_password(LIBSSH2_SESSION *session, const char *username,
session-> session->
userauth_pswd_data_len); userauth_pswd_data_len);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
return libssh2_error(session, LIBSSH2_ERROR_EAGAIN, return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting"); "Would block waiting");
} }
@ -429,7 +429,7 @@ userauth_password(LIBSSH2_SESSION *session, const char *username,
session->userauth_pswd_newpw = NULL; session->userauth_pswd_newpw = NULL;
if (rc) { if (rc) {
return libssh2_error(session, return _libssh2_error(session,
LIBSSH2_ERROR_SOCKET_SEND, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send userauth " "Unable to send userauth "
"password-change request"); "password-change request");
@ -445,7 +445,7 @@ userauth_password(LIBSSH2_SESSION *session, const char *username,
} }
} else { } else {
session->userauth_pswd_state = libssh2_NB_state_idle; session->userauth_pswd_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_PASSWORD_EXPIRED, return _libssh2_error(session, LIBSSH2_ERROR_PASSWORD_EXPIRED,
"Password Expired, and no callback " "Password Expired, and no callback "
"specified"); "specified");
} }
@ -457,7 +457,7 @@ userauth_password(LIBSSH2_SESSION *session, const char *username,
session->userauth_pswd_data = NULL; session->userauth_pswd_data = NULL;
session->userauth_pswd_state = libssh2_NB_state_idle; session->userauth_pswd_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_AUTHENTICATION_FAILED, return _libssh2_error(session, LIBSSH2_ERROR_AUTHENTICATION_FAILED,
"Authentication failed"); "Authentication failed");
} }
@ -509,7 +509,7 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
/* Read Public Key */ /* Read Public Key */
fd = fopen(pubkeyfile, "r"); fd = fopen(pubkeyfile, "r");
if (!fd) { if (!fd) {
return libssh2_error(session, LIBSSH2_ERROR_FILE, return _libssh2_error(session, LIBSSH2_ERROR_FILE,
"Unable to open public key file"); "Unable to open public key file");
} }
while (!feof(fd) && (c = fgetc(fd)) != '\r' && c != '\n') while (!feof(fd) && (c = fgetc(fd)) != '\r' && c != '\n')
@ -522,20 +522,20 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
if (pubkey_len <= 1) { if (pubkey_len <= 1) {
fclose(fd); fclose(fd);
return libssh2_error(session, LIBSSH2_ERROR_FILE, return _libssh2_error(session, LIBSSH2_ERROR_FILE,
"Invalid data in public key file"); "Invalid data in public key file");
} }
pubkey = LIBSSH2_ALLOC(session, pubkey_len); pubkey = LIBSSH2_ALLOC(session, pubkey_len);
if (!pubkey) { if (!pubkey) {
fclose(fd); fclose(fd);
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for public key data"); "Unable to allocate memory for public key data");
} }
if (fread(pubkey, 1, pubkey_len, fd) != pubkey_len) { if (fread(pubkey, 1, pubkey_len, fd) != pubkey_len) {
LIBSSH2_FREE(session, pubkey); LIBSSH2_FREE(session, pubkey);
fclose(fd); fclose(fd);
return libssh2_error(session, LIBSSH2_ERROR_FILE, return _libssh2_error(session, LIBSSH2_ERROR_FILE,
"Unable to read public key from file"); "Unable to read public key from file");
} }
fclose(fd); fclose(fd);
@ -547,13 +547,13 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
if (!pubkey_len) { if (!pubkey_len) {
LIBSSH2_FREE(session, pubkey); LIBSSH2_FREE(session, pubkey);
return libssh2_error(session, LIBSSH2_ERROR_FILE, return _libssh2_error(session, LIBSSH2_ERROR_FILE,
"Missing public key data"); "Missing public key data");
} }
if ((sp1 = memchr(pubkey, ' ', pubkey_len)) == NULL) { if ((sp1 = memchr(pubkey, ' ', pubkey_len)) == NULL) {
LIBSSH2_FREE(session, pubkey); LIBSSH2_FREE(session, pubkey);
return libssh2_error(session, LIBSSH2_ERROR_FILE, return _libssh2_error(session, LIBSSH2_ERROR_FILE,
"Invalid public key data"); "Invalid public key data");
} }
@ -567,7 +567,7 @@ file_read_publickey(LIBSSH2_SESSION * session, unsigned char **method,
if (libssh2_base64_decode(session, (char **) &tmp, &tmp_len, if (libssh2_base64_decode(session, (char **) &tmp, &tmp_len,
(char *) sp1, sp2 - sp1)) { (char *) sp1, sp2 - sp1)) {
LIBSSH2_FREE(session, pubkey); LIBSSH2_FREE(session, pubkey);
return libssh2_error(session, LIBSSH2_ERROR_FILE, return _libssh2_error(session, LIBSSH2_ERROR_FILE,
"Invalid key data, not base64 encoded"); "Invalid key data, not base64 encoded");
} }
@ -612,14 +612,14 @@ file_read_privatekey(LIBSSH2_SESSION * session,
hostkey_methods_avail++; hostkey_methods_avail++;
} }
if (!*hostkey_method) { if (!*hostkey_method) {
return libssh2_error(session, LIBSSH2_ERROR_METHOD_NONE, return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NONE,
"No handler for specified private key"); "No handler for specified private key");
} }
if ((*hostkey_method)-> if ((*hostkey_method)->
initPEM(session, privkeyfile, (unsigned char *) passphrase, initPEM(session, privkeyfile, (unsigned char *) passphrase,
hostkey_abstract)) { hostkey_abstract)) {
return libssh2_error(session, LIBSSH2_ERROR_FILE, return _libssh2_error(session, LIBSSH2_ERROR_FILE,
"Unable to initialize private key from file"); "Unable to initialize private key from file");
} }
@ -700,7 +700,7 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session,
&pubkeydata, &pubkeydata_len, &pubkeydata, &pubkeydata_len,
publickey); publickey);
if(rc) if(rc)
/* Note: file_read_publickey() calls libssh2_error() */ /* Note: file_read_publickey() calls _libssh2_error() */
return rc; return rc;
/* /*
@ -727,7 +727,7 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session,
LIBSSH2_FREE(session, session->userauth_host_method); LIBSSH2_FREE(session, session->userauth_host_method);
session->userauth_host_method = NULL; session->userauth_host_method = NULL;
LIBSSH2_FREE(session, pubkeydata); LIBSSH2_FREE(session, pubkeydata);
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Out of memory"); "Out of memory");
} }
@ -777,7 +777,7 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session,
session->userauth_host_method_len, session->userauth_host_method_len,
privatekey, passphrase); privatekey, passphrase);
if(rc) { if(rc) {
/* Note: file_read_privatekey() calls libssh2_error() */ /* Note: file_read_privatekey() calls _libssh2_error() */
LIBSSH2_FREE(session, session->userauth_host_method); LIBSSH2_FREE(session, session->userauth_host_method);
session->userauth_host_method = NULL; session->userauth_host_method = NULL;
LIBSSH2_FREE(session, session->userauth_host_packet); LIBSSH2_FREE(session, session->userauth_host_packet);
@ -821,7 +821,7 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session,
session->userauth_host_packet = NULL; session->userauth_host_packet = NULL;
LIBSSH2_FREE(session, session->userauth_host_method); LIBSSH2_FREE(session, session->userauth_host_method);
session->userauth_host_method = NULL; session->userauth_host_method = NULL;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Failed allocating additional space for " "Failed allocating additional space for "
"userauth-hostbased packet"); "userauth-hostbased packet");
} }
@ -861,13 +861,13 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session,
session->userauth_host_s - session->userauth_host_s -
session->userauth_host_packet); session->userauth_host_packet);
if (rc == PACKET_EAGAIN) { 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) { else if (rc) {
LIBSSH2_FREE(session, session->userauth_host_packet); LIBSSH2_FREE(session, session->userauth_host_packet);
session->userauth_host_packet = NULL; session->userauth_host_packet = NULL;
session->userauth_host_state = libssh2_NB_state_idle; session->userauth_host_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send userauth-hostbased request"); "Unable to send userauth-hostbased request");
} }
LIBSSH2_FREE(session, session->userauth_host_packet); LIBSSH2_FREE(session, session->userauth_host_packet);
@ -886,12 +886,12 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session,
&session-> &session->
userauth_host_packet_requirev_state); userauth_host_packet_requirev_state);
if (rc == PACKET_EAGAIN) { 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; session->userauth_host_state = libssh2_NB_state_idle;
if (rc) { if (rc) {
return libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED,
"Auth failed"); "Auth failed");
} }
@ -909,7 +909,7 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session,
/* This public key is not allowed for this user on this server */ /* This public key is not allowed for this user on this server */
LIBSSH2_FREE(session, session->userauth_host_data); LIBSSH2_FREE(session, session->userauth_host_data);
session->userauth_host_data = NULL; session->userauth_host_data = NULL;
return libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED,
"Invalid signature for supplied public key, or bad " "Invalid signature for supplied public key, or bad "
"username/public key combination"); "username/public key combination");
} }
@ -971,7 +971,7 @@ userauth_publickey(LIBSSH2_SESSION *session,
session->userauth_pblc_method = session->userauth_pblc_method =
LIBSSH2_ALLOC(session, session->userauth_pblc_method_len); LIBSSH2_ALLOC(session, session->userauth_pblc_method_len);
if (!session->userauth_pblc_method) { if (!session->userauth_pblc_method) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for public key " "Unable to allocate memory for public key "
"data"); "data");
} }
@ -1004,7 +1004,7 @@ userauth_publickey(LIBSSH2_SESSION *session,
if (!session->userauth_pblc_packet) { if (!session->userauth_pblc_packet) {
LIBSSH2_FREE(session, session->userauth_pblc_method); LIBSSH2_FREE(session, session->userauth_pblc_method);
session->userauth_pblc_method = NULL; session->userauth_pblc_method = NULL;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Out of memory"); "Out of memory");
} }
@ -1050,14 +1050,14 @@ userauth_publickey(LIBSSH2_SESSION *session,
rc = _libssh2_transport_write(session, session->userauth_pblc_packet, rc = _libssh2_transport_write(session, session->userauth_pblc_packet,
session->userauth_pblc_packet_len); session->userauth_pblc_packet_len);
if (rc == PACKET_EAGAIN) 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) { else if (rc) {
LIBSSH2_FREE(session, session->userauth_pblc_packet); LIBSSH2_FREE(session, session->userauth_pblc_packet);
session->userauth_pblc_packet = NULL; session->userauth_pblc_packet = NULL;
LIBSSH2_FREE(session, session->userauth_pblc_method); LIBSSH2_FREE(session, session->userauth_pblc_method);
session->userauth_pblc_method = NULL; session->userauth_pblc_method = NULL;
session->userauth_pblc_state = libssh2_NB_state_idle; session->userauth_pblc_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send userauth-publickey request"); "Unable to send userauth-publickey request");
} }
@ -1072,7 +1072,7 @@ userauth_publickey(LIBSSH2_SESSION *session,
&session-> &session->
userauth_pblc_packet_requirev_state); userauth_pblc_packet_requirev_state);
if (rc == PACKET_EAGAIN) { 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) { else if (rc) {
LIBSSH2_FREE(session, session->userauth_pblc_packet); LIBSSH2_FREE(session, session->userauth_pblc_packet);
@ -1080,7 +1080,7 @@ userauth_publickey(LIBSSH2_SESSION *session,
LIBSSH2_FREE(session, session->userauth_pblc_method); LIBSSH2_FREE(session, session->userauth_pblc_method);
session->userauth_pblc_method = NULL; session->userauth_pblc_method = NULL;
session->userauth_pblc_state = libssh2_NB_state_idle; session->userauth_pblc_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED,
"Failed waiting"); "Failed waiting");
} }
@ -1111,7 +1111,7 @@ userauth_publickey(LIBSSH2_SESSION *session,
LIBSSH2_FREE(session, session->userauth_pblc_method); LIBSSH2_FREE(session, session->userauth_pblc_method);
session->userauth_pblc_method = NULL; session->userauth_pblc_method = NULL;
session->userauth_pblc_state = libssh2_NB_state_idle; session->userauth_pblc_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_AUTHENTICATION_FAILED, return _libssh2_error(session, LIBSSH2_ERROR_AUTHENTICATION_FAILED,
"Username/PublicKey combination invalid"); "Username/PublicKey combination invalid");
} }
@ -1131,7 +1131,7 @@ userauth_publickey(LIBSSH2_SESSION *session,
s = buf = LIBSSH2_ALLOC(session, 4 + session->session_id_len s = buf = LIBSSH2_ALLOC(session, 4 + session->session_id_len
+ session->userauth_pblc_packet_len); + session->userauth_pblc_packet_len);
if (!buf) { if (!buf) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for " "Unable to allocate memory for "
"userauth-publickey signed data"); "userauth-publickey signed data");
} }
@ -1147,14 +1147,14 @@ userauth_publickey(LIBSSH2_SESSION *session,
rc = sign_callback(session, &sig, &sig_len, buf, s - buf, abstract); rc = sign_callback(session, &sig, &sig_len, buf, s - buf, abstract);
LIBSSH2_FREE(session, buf); LIBSSH2_FREE(session, buf);
if (rc == PACKET_EAGAIN) { 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) { } else if (rc) {
LIBSSH2_FREE(session, session->userauth_pblc_method); LIBSSH2_FREE(session, session->userauth_pblc_method);
session->userauth_pblc_method = NULL; session->userauth_pblc_method = NULL;
LIBSSH2_FREE(session, session->userauth_pblc_packet); LIBSSH2_FREE(session, session->userauth_pblc_packet);
session->userauth_pblc_packet = NULL; session->userauth_pblc_packet = NULL;
session->userauth_pblc_state = libssh2_NB_state_idle; session->userauth_pblc_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED,
"Callback returned error"); "Callback returned error");
} }
@ -1177,7 +1177,7 @@ userauth_publickey(LIBSSH2_SESSION *session,
LIBSSH2_FREE(session, session->userauth_pblc_method); LIBSSH2_FREE(session, session->userauth_pblc_method);
session->userauth_pblc_method = NULL; session->userauth_pblc_method = NULL;
session->userauth_pblc_state = libssh2_NB_state_idle; session->userauth_pblc_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Failed allocating additional space for " "Failed allocating additional space for "
"userauth-publickey packet"); "userauth-publickey packet");
} }
@ -1218,12 +1218,12 @@ userauth_publickey(LIBSSH2_SESSION *session,
session->userauth_pblc_s - session->userauth_pblc_s -
session->userauth_pblc_packet); session->userauth_pblc_packet);
if (rc == PACKET_EAGAIN) { 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) { } else if (rc) {
LIBSSH2_FREE(session, session->userauth_pblc_packet); LIBSSH2_FREE(session, session->userauth_pblc_packet);
session->userauth_pblc_packet = NULL; session->userauth_pblc_packet = NULL;
session->userauth_pblc_state = libssh2_NB_state_idle; session->userauth_pblc_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send userauth-publickey request"); "Unable to send userauth-publickey request");
} }
LIBSSH2_FREE(session, session->userauth_pblc_packet); LIBSSH2_FREE(session, session->userauth_pblc_packet);
@ -1240,11 +1240,11 @@ userauth_publickey(LIBSSH2_SESSION *session,
&session->userauth_pblc_data_len, 0, NULL, 0, &session->userauth_pblc_data_len, 0, NULL, 0,
&session->userauth_pblc_packet_requirev_state); &session->userauth_pblc_packet_requirev_state);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
return libssh2_error(session, LIBSSH2_ERROR_EAGAIN, return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block requesting userauth list"); "Would block requesting userauth list");
} else if (rc) { } else if (rc) {
session->userauth_pblc_state = libssh2_NB_state_idle; session->userauth_pblc_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED,
"Failed waiting"); "Failed waiting");
} }
@ -1263,7 +1263,7 @@ userauth_publickey(LIBSSH2_SESSION *session,
LIBSSH2_FREE(session, session->userauth_pblc_data); LIBSSH2_FREE(session, session->userauth_pblc_data);
session->userauth_pblc_data = NULL; session->userauth_pblc_data = NULL;
session->userauth_pblc_state = libssh2_NB_state_idle; session->userauth_pblc_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED,
"Invalid signature for supplied public key, or bad " "Invalid signature for supplied public key, or bad "
"username/public key combination"); "username/public key combination");
} }
@ -1399,7 +1399,7 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
session->userauth_kybd_data = s = session->userauth_kybd_data = s =
LIBSSH2_ALLOC(session, session->userauth_kybd_packet_len); LIBSSH2_ALLOC(session, session->userauth_kybd_packet_len);
if (!s) { if (!s) {
return libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for " "Unable to allocate memory for "
"keyboard-interactive authentication"); "keyboard-interactive authentication");
} }
@ -1442,12 +1442,12 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
rc = _libssh2_transport_write(session, session->userauth_kybd_data, rc = _libssh2_transport_write(session, session->userauth_kybd_data,
session->userauth_kybd_packet_len); session->userauth_kybd_packet_len);
if (rc == PACKET_EAGAIN) { 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) { } else if (rc) {
LIBSSH2_FREE(session, session->userauth_kybd_data); LIBSSH2_FREE(session, session->userauth_kybd_data);
session->userauth_kybd_data = NULL; session->userauth_kybd_data = NULL;
session->userauth_kybd_state = libssh2_NB_state_idle; session->userauth_kybd_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send keyboard-interactive request"); "Unable to send keyboard-interactive request");
} }
LIBSSH2_FREE(session, session->userauth_kybd_data); LIBSSH2_FREE(session, session->userauth_kybd_data);
@ -1465,11 +1465,11 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
&session-> &session->
userauth_kybd_packet_requirev_state); userauth_kybd_packet_requirev_state);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
return libssh2_error(session, LIBSSH2_ERROR_EAGAIN, return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block"); "Would block");
} else if (rc) { } else if (rc) {
session->userauth_kybd_state = libssh2_NB_state_idle; session->userauth_kybd_state = libssh2_NB_state_idle;
return libssh2_error(session, return _libssh2_error(session,
LIBSSH2_ERROR_AUTHENTICATION_FAILED, LIBSSH2_ERROR_AUTHENTICATION_FAILED,
"Failed waiting"); "Failed waiting");
} }
@ -1490,7 +1490,7 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
LIBSSH2_FREE(session, session->userauth_kybd_data); LIBSSH2_FREE(session, session->userauth_kybd_data);
session->userauth_kybd_data = NULL; session->userauth_kybd_data = NULL;
session->userauth_kybd_state = libssh2_NB_state_idle; session->userauth_kybd_state = libssh2_NB_state_idle;
return libssh2_error(session, return _libssh2_error(session,
LIBSSH2_ERROR_AUTHENTICATION_FAILED, LIBSSH2_ERROR_AUTHENTICATION_FAILED,
"Authentication failed " "Authentication failed "
"(keyboard-interactive)"); "(keyboard-interactive)");
@ -1506,7 +1506,7 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
session->userauth_kybd_auth_name = session->userauth_kybd_auth_name =
LIBSSH2_ALLOC(session, session->userauth_kybd_auth_name_len); LIBSSH2_ALLOC(session, session->userauth_kybd_auth_name_len);
if (!session->userauth_kybd_auth_name) { if (!session->userauth_kybd_auth_name) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for " "Unable to allocate memory for "
"keyboard-interactive 'name' request field"); "keyboard-interactive 'name' request field");
goto cleanup; goto cleanup;
@ -1522,7 +1522,7 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
LIBSSH2_ALLOC(session, LIBSSH2_ALLOC(session,
session->userauth_kybd_auth_instruction_len); session->userauth_kybd_auth_instruction_len);
if (!session->userauth_kybd_auth_instruction) { if (!session->userauth_kybd_auth_instruction) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for " "Unable to allocate memory for "
"keyboard-interactive 'instruction' " "keyboard-interactive 'instruction' "
"request field"); "request field");
@ -1547,7 +1547,7 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
sizeof(LIBSSH2_USERAUTH_KBDINT_PROMPT) * sizeof(LIBSSH2_USERAUTH_KBDINT_PROMPT) *
session->userauth_kybd_num_prompts); session->userauth_kybd_num_prompts);
if (!session->userauth_kybd_prompts) { if (!session->userauth_kybd_prompts) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for " "Unable to allocate memory for "
"keyboard-interactive prompts array"); "keyboard-interactive prompts array");
goto cleanup; goto cleanup;
@ -1561,7 +1561,7 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
sizeof(LIBSSH2_USERAUTH_KBDINT_RESPONSE) * sizeof(LIBSSH2_USERAUTH_KBDINT_RESPONSE) *
session->userauth_kybd_num_prompts); session->userauth_kybd_num_prompts);
if (!session->userauth_kybd_responses) { if (!session->userauth_kybd_responses) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for " "Unable to allocate memory for "
"keyboard-interactive responses array"); "keyboard-interactive responses array");
goto cleanup; goto cleanup;
@ -1578,7 +1578,7 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
LIBSSH2_ALLOC(session, LIBSSH2_ALLOC(session,
session->userauth_kybd_prompts[i].length); session->userauth_kybd_prompts[i].length);
if (!session->userauth_kybd_prompts[i].text) { if (!session->userauth_kybd_prompts[i].text) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for " "Unable to allocate memory for "
"keyboard-interactive prompt message"); "keyboard-interactive prompt message");
goto cleanup; goto cleanup;
@ -1622,7 +1622,7 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
session->userauth_kybd_data = s = session->userauth_kybd_data = s =
LIBSSH2_ALLOC(session, session->userauth_kybd_packet_len); LIBSSH2_ALLOC(session, session->userauth_kybd_packet_len);
if (!s) { if (!s) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for keyboard-" "Unable to allocate memory for keyboard-"
"interactive response packet"); "interactive response packet");
goto cleanup; goto cleanup;
@ -1648,11 +1648,11 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
rc = _libssh2_transport_write(session, session->userauth_kybd_data, rc = _libssh2_transport_write(session, session->userauth_kybd_data,
session->userauth_kybd_packet_len); session->userauth_kybd_packet_len);
if (rc == PACKET_EAGAIN) { if (rc == PACKET_EAGAIN) {
return libssh2_error(session, LIBSSH2_ERROR_EAGAIN, return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block"); "Would block");
} }
if (rc) { if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send userauth-keyboard-interactive" "Unable to send userauth-keyboard-interactive"
" request"); " request");
goto cleanup; goto cleanup;