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,8 +618,8 @@ 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;
} }
memset(agent, 0, sizeof *agent); memset(agent, 0, sizeof *agent);

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,8 +155,8 @@ _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;
} }
memset(session->open_channel, 0, sizeof(LIBSSH2_CHANNEL)); memset(session->open_channel, 0, sizeof(LIBSSH2_CHANNEL));
@ -165,8 +165,8 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type,
session->open_channel->channel_type = 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;
return NULL; return NULL;
@ -187,8 +187,8 @@ _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;
} }
*(s++) = SSH_MSG_CHANNEL_OPEN; *(s++) = SSH_MSG_CHANNEL_OPEN;
@ -219,12 +219,12 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type,
rc = _libssh2_transport_write(session, session->open_packet, 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,8 +273,8 @@ _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,8 +368,8 @@ 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;
} }
_libssh2_htonu32(s, session->direct_host_len); _libssh2_htonu32(s, session->direct_host_len);
@ -461,8 +461,8 @@ 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,14 +487,14 @@ 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);
session->fwdLstn_packet = NULL; session->fwdLstn_packet = NULL;
session->fwdLstn_state = libssh2_NB_state_idle; session->fwdLstn_state = libssh2_NB_state_idle;
@ -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,8 +524,8 @@ 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;
return NULL; return NULL;
@ -535,8 +535,8 @@ 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);
session->fwdLstn_state = libssh2_NB_state_idle; session->fwdLstn_state = libssh2_NB_state_idle;
@ -571,8 +571,8 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
if (data[0] == SSH_MSG_REQUEST_FAILURE) { 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,8 +626,8 @@ 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,9 +657,9 @@ 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);
listener->chanFwdCncl_state = libssh2_NB_state_idle; listener->chanFwdCncl_state = libssh2_NB_state_idle;
return LIBSSH2_ERROR_SOCKET_SEND; return LIBSSH2_ERROR_SOCKET_SEND;
@ -736,12 +736,12 @@ 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,9 +793,9 @@ 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");
} }
*(s++) = SSH_MSG_CHANNEL_REQUEST; *(s++) = SSH_MSG_CHANNEL_REQUEST;
@ -830,9 +830,9 @@ 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");
} }
LIBSSH2_FREE(session, channel->setenv_packet); LIBSSH2_FREE(session, channel->setenv_packet);
channel->setenv_packet = NULL; channel->setenv_packet = NULL;
@ -865,8 +865,8 @@ 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,8 +920,8 @@ 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");
} }
*(s++) = SSH_MSG_CHANNEL_REQUEST; *(s++) = SSH_MSG_CHANNEL_REQUEST;
@ -969,8 +969,8 @@ 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);
channel->reqPTY_packet = NULL; channel->reqPTY_packet = NULL;
@ -1000,8 +1000,8 @@ 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,8 +1046,8 @@ 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");
} }
*(s++) = SSH_MSG_CHANNEL_REQUEST; *(s++) = SSH_MSG_CHANNEL_REQUEST;
@ -1080,8 +1080,8 @@ channel_request_pty_size(LIBSSH2_CHANNEL * channel, int width,
LIBSSH2_FREE(session, channel->reqPTY_packet); 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);
channel->reqPTY_packet = NULL; channel->reqPTY_packet = NULL;
@ -1150,8 +1150,8 @@ 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");
} }
*(s++) = SSH_MSG_CHANNEL_REQUEST; *(s++) = SSH_MSG_CHANNEL_REQUEST;
@ -1205,8 +1205,8 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection,
LIBSSH2_FREE(session, channel->reqX11_packet); 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);
channel->reqX11_packet = NULL; channel->reqX11_packet = NULL;
@ -1224,8 +1224,8 @@ 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");
} }
if (data[0] == SSH_MSG_CHANNEL_SUCCESS) { if (data[0] == SSH_MSG_CHANNEL_SUCCESS) {
@ -1236,8 +1236,8 @@ 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,9 +1293,9 @@ _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");
} }
*(s++) = SSH_MSG_CHANNEL_REQUEST; *(s++) = SSH_MSG_CHANNEL_REQUEST;
@ -1328,8 +1328,8 @@ _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);
channel->process_packet = NULL; channel->process_packet = NULL;
@ -1347,8 +1347,8 @@ _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");
} }
if (data[0] == SSH_MSG_CHANNEL_SUCCESS) { if (data[0] == SSH_MSG_CHANNEL_SUCCESS) {
@ -1360,9 +1360,9 @@ _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,9 +1550,9 @@ _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");
} }
else { else {
channel->remote.window_size += adjustment; channel->remote.window_size += adjustment;
@ -1715,7 +1715,7 @@ ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id,
rc = _libssh2_transport_read(session); 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,14 +1949,14 @@ _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");
} }
/* [13] 9 = packet_type(1) + channelno(4) [ + streamid(4) ] + /* [13] 9 = packet_type(1) + channelno(4) [ + streamid(4) ] +
@ -1965,9 +1965,9 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id,
channel->write_packet = 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");
} }
channel->write_state = libssh2_NB_state_allocated; channel->write_state = libssh2_NB_state_allocated;
@ -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,8 +2114,8 @@ 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,8 +2250,8 @@ 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");
} }
channel->close_state = libssh2_NB_state_sent; channel->close_state = libssh2_NB_state_sent;
@ -2307,9 +2307,9 @@ 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");
} }
if (channel->wait_closed_state == libssh2_NB_state_idle) { if (channel->wait_closed_state == libssh2_NB_state_idle) {

View File

@ -43,8 +43,8 @@
#include "comp.h" #include "comp.h"
/* ******** /* ********
* none * * none *
******** */ ******** */
/* /*
* comp_method_none_comp * comp_method_none_comp
@ -84,8 +84,8 @@ static const LIBSSH2_COMP_METHOD comp_method_none = {
#ifdef LIBSSH2_HAVE_ZLIB #ifdef LIBSSH2_HAVE_ZLIB
/* ******** /* ********
* zlib * * zlib *
******** */ ******** */
/* Memory management wrappers /* Memory management wrappers
* Yes, I realize we're doing a callback to a callback, * Yes, I realize we're doing a callback to a callback,
@ -122,9 +122,9 @@ comp_method_zlib_init(LIBSSH2_SESSION * session, int compress,
strm = LIBSSH2_ALLOC(session, sizeof(z_stream)); 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");
} }
memset(strm, 0, sizeof(z_stream)); memset(strm, 0, sizeof(z_stream));
@ -185,9 +185,9 @@ 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");
} }
while (strm->avail_in) { while (strm->avail_in) {
int status; int status;
@ -199,8 +199,8 @@ 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) {
unsigned long out_ofs = out_maxlen - strm->avail_out; unsigned long out_ofs = out_maxlen - strm->avail_out;
@ -211,16 +211,16 @@ comp_method_zlib_comp(LIBSSH2_SESSION * session,
if ((out_maxlen > (int) payload_limit) && !compress && limiter++) { 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");
} }
out = newout; out = newout;
strm->next_out = (unsigned char *) out + out_ofs; strm->next_out = (unsigned char *) out + out_ofs;
@ -237,9 +237,9 @@ comp_method_zlib_comp(LIBSSH2_SESSION * session,
if (out_maxlen >= (int) payload_limit) { 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");
} }
if (grow_size > (int) (payload_limit - out_maxlen)) { if (grow_size > (int) (payload_limit - out_maxlen)) {
@ -252,9 +252,9 @@ comp_method_zlib_comp(LIBSSH2_SESSION * session,
newout = LIBSSH2_REALLOC(session, out, out_maxlen); 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");
} }
out = newout; out = newout;
strm->next_out = (unsigned char *) out + out_maxlen - strm->next_out = (unsigned char *) out + out_maxlen -
@ -267,8 +267,8 @@ 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");
} }
} }
} }
@ -316,8 +316,8 @@ static const LIBSSH2_COMP_METHOD comp_method_zlib = {
#endif /* LIBSSH2_HAVE_ZLIB */ #endif /* LIBSSH2_HAVE_ZLIB */
/* *********************** /* ***********************
* Compression Methods * * Compression Methods *
*********************** */ *********************** */
static const LIBSSH2_COMP_METHOD *comp_methods[] = { static const LIBSSH2_COMP_METHOD *comp_methods[] = {
&comp_method_none, &comp_method_none,

View File

@ -46,8 +46,8 @@
#if LIBSSH2_RSA #if LIBSSH2_RSA
/* *********** /* ***********
* ssh-rsa * * ssh-rsa *
*********** */ *********** */
static int hostkey_method_ssh_rsa_dtor(LIBSSH2_SESSION * session, static int hostkey_method_ssh_rsa_dtor(LIBSSH2_SESSION * session,
void **abstract); void **abstract);
@ -218,8 +218,8 @@ static const LIBSSH2_HOSTKEY_METHOD hostkey_method_ssh_rsa = {
#if LIBSSH2_DSA #if LIBSSH2_DSA
/* *********** /* ***********
* ssh-dss * * ssh-dss *
*********** */ *********** */
static int hostkey_method_ssh_dss_dtor(LIBSSH2_SESSION * session, static int hostkey_method_ssh_dss_dtor(LIBSSH2_SESSION * session,
void **abstract); void **abstract);
@ -324,8 +324,8 @@ 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,8 +80,8 @@ 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;
} }

160
src/kex.c
View File

@ -44,30 +44,30 @@
/* TODO: Switch this to an inline and handle alloc() failures */ /* TODO: Switch this to an inline and handle alloc() failures */
/* Helper macro called from kex_method_diffie_hellman_group1_sha1_key_exchange */ /* Helper macro called from kex_method_diffie_hellman_group1_sha1_key_exchange */
#define LIBSSH2_KEX_METHOD_DIFFIE_HELLMAN_SHA1_HASH(value, reqlen, version) \ #define LIBSSH2_KEX_METHOD_DIFFIE_HELLMAN_SHA1_HASH(value, reqlen, version) \
{ \ { \
libssh2_sha1_ctx hash; \ libssh2_sha1_ctx hash; \
unsigned long len = 0; \ unsigned long len = 0; \
if (!(value)) { \ if (!(value)) { \
value = LIBSSH2_ALLOC(session, reqlen + SHA_DIGEST_LENGTH); \ value = LIBSSH2_ALLOC(session, reqlen + SHA_DIGEST_LENGTH); \
} \ } \
if (value) \ if (value) \
while (len < (unsigned long)reqlen) { \ while (len < (unsigned long)reqlen) { \
libssh2_sha1_init(&hash); \ libssh2_sha1_init(&hash); \
libssh2_sha1_update(hash, exchange_state->k_value, \ libssh2_sha1_update(hash, exchange_state->k_value, \
exchange_state->k_value_len); \ exchange_state->k_value_len); \
libssh2_sha1_update(hash, exchange_state->h_sig_comp, \ libssh2_sha1_update(hash, exchange_state->h_sig_comp, \
SHA_DIGEST_LENGTH); \ SHA_DIGEST_LENGTH); \
if (len > 0) { \ if (len > 0) { \
libssh2_sha1_update(hash, value, len); \ libssh2_sha1_update(hash, value, len); \
} else { \ } else { \
libssh2_sha1_update(hash, (version), 1); \ libssh2_sha1_update(hash, (version), 1); \
libssh2_sha1_update(hash, session->session_id, \ libssh2_sha1_update(hash, session->session_id, \
session->session_id_len); \ session->session_id_len); \
} \ } \
libssh2_sha1_final(hash, (value) + len); \ libssh2_sha1_final(hash, (value) + len); \
len += SHA_DIGEST_LENGTH; \ len += SHA_DIGEST_LENGTH; \
} \ } \
} }
/* /*
* diffie_hellman_sha1 * diffie_hellman_sha1
@ -118,13 +118,13 @@ 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;
} }
exchange_state->e_packet[0] = packet_type_init; exchange_state->e_packet[0] = packet_type_init;
_libssh2_htonu32(exchange_state->e_packet + 1, _libssh2_htonu32(exchange_state->e_packet + 1,
exchange_state->e_packet_len - 5); exchange_state->e_packet_len - 5);
if (_libssh2_bn_bits(exchange_state->e) % 8) { if (_libssh2_bn_bits(exchange_state->e) % 8) {
_libssh2_bn_to_bin(exchange_state->e, _libssh2_bn_to_bin(exchange_state->e,
exchange_state->e_packet + 5); exchange_state->e_packet + 5);
@ -145,8 +145,8 @@ 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;
} }
exchange_state->state = libssh2_NB_state_sent; exchange_state->state = libssh2_NB_state_sent;
@ -190,8 +190,8 @@ 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,9 +203,9 @@ 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;
} }
memcpy(session->server_hostkey, exchange_state->s, memcpy(session->server_hostkey, exchange_state->s,
@ -260,8 +260,8 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
if (session->hostkey->init(session, session->server_hostkey, 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,12 +287,12 @@ 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;
} }
_libssh2_htonu32(exchange_state->k_value, _libssh2_htonu32(exchange_state->k_value,
exchange_state->k_value_len - 4); exchange_state->k_value_len - 4);
if (_libssh2_bn_bits(exchange_state->k) % 8) { if (_libssh2_bn_bits(exchange_state->k) % 8) {
_libssh2_bn_to_bin(exchange_state->k, exchange_state->k_value + 4); _libssh2_bn_to_bin(exchange_state->k, exchange_state->k_value + 4);
} else { } else {
@ -303,7 +303,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
libssh2_sha1_init(&exchange_state->exchange_hash); libssh2_sha1_init(&exchange_state->exchange_hash);
if (session->local.banner) { if (session->local.banner) {
_libssh2_htonu32(exchange_state->h_sig_comp, _libssh2_htonu32(exchange_state->h_sig_comp,
strlen((char *) session->local.banner) - 2); strlen((char *) session->local.banner) - 2);
libssh2_sha1_update(exchange_state->exchange_hash, libssh2_sha1_update(exchange_state->exchange_hash,
exchange_state->h_sig_comp, 4); exchange_state->h_sig_comp, 4);
libssh2_sha1_update(exchange_state->exchange_hash, libssh2_sha1_update(exchange_state->exchange_hash,
@ -311,7 +311,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
strlen((char *) session->local.banner) - 2); strlen((char *) session->local.banner) - 2);
} else { } else {
_libssh2_htonu32(exchange_state->h_sig_comp, _libssh2_htonu32(exchange_state->h_sig_comp,
sizeof(LIBSSH2_SSH_DEFAULT_BANNER) - 1); sizeof(LIBSSH2_SSH_DEFAULT_BANNER) - 1);
libssh2_sha1_update(exchange_state->exchange_hash, libssh2_sha1_update(exchange_state->exchange_hash,
exchange_state->h_sig_comp, 4); exchange_state->h_sig_comp, 4);
libssh2_sha1_update(exchange_state->exchange_hash, libssh2_sha1_update(exchange_state->exchange_hash,
@ -320,7 +320,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
} }
_libssh2_htonu32(exchange_state->h_sig_comp, _libssh2_htonu32(exchange_state->h_sig_comp,
strlen((char *) session->remote.banner)); strlen((char *) session->remote.banner));
libssh2_sha1_update(exchange_state->exchange_hash, libssh2_sha1_update(exchange_state->exchange_hash,
exchange_state->h_sig_comp, 4); exchange_state->h_sig_comp, 4);
libssh2_sha1_update(exchange_state->exchange_hash, libssh2_sha1_update(exchange_state->exchange_hash,
@ -328,7 +328,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
strlen((char *) session->remote.banner)); strlen((char *) session->remote.banner));
_libssh2_htonu32(exchange_state->h_sig_comp, _libssh2_htonu32(exchange_state->h_sig_comp,
session->local.kexinit_len); session->local.kexinit_len);
libssh2_sha1_update(exchange_state->exchange_hash, libssh2_sha1_update(exchange_state->exchange_hash,
exchange_state->h_sig_comp, 4); exchange_state->h_sig_comp, 4);
libssh2_sha1_update(exchange_state->exchange_hash, libssh2_sha1_update(exchange_state->exchange_hash,
@ -336,7 +336,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
session->local.kexinit_len); session->local.kexinit_len);
_libssh2_htonu32(exchange_state->h_sig_comp, _libssh2_htonu32(exchange_state->h_sig_comp,
session->remote.kexinit_len); session->remote.kexinit_len);
libssh2_sha1_update(exchange_state->exchange_hash, libssh2_sha1_update(exchange_state->exchange_hash,
exchange_state->h_sig_comp, 4); exchange_state->h_sig_comp, 4);
libssh2_sha1_update(exchange_state->exchange_hash, libssh2_sha1_update(exchange_state->exchange_hash,
@ -344,7 +344,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
session->remote.kexinit_len); session->remote.kexinit_len);
_libssh2_htonu32(exchange_state->h_sig_comp, _libssh2_htonu32(exchange_state->h_sig_comp,
session->server_hostkey_len); session->server_hostkey_len);
libssh2_sha1_update(exchange_state->exchange_hash, libssh2_sha1_update(exchange_state->exchange_hash,
exchange_state->h_sig_comp, 4); exchange_state->h_sig_comp, 4);
libssh2_sha1_update(exchange_state->exchange_hash, libssh2_sha1_update(exchange_state->exchange_hash,
@ -355,16 +355,16 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
/* diffie-hellman-group-exchange hashes additional fields */ /* diffie-hellman-group-exchange hashes additional fields */
#ifdef LIBSSH2_DH_GEX_NEW #ifdef LIBSSH2_DH_GEX_NEW
_libssh2_htonu32(exchange_state->h_sig_comp, _libssh2_htonu32(exchange_state->h_sig_comp,
LIBSSH2_DH_GEX_MINGROUP); LIBSSH2_DH_GEX_MINGROUP);
_libssh2_htonu32(exchange_state->h_sig_comp + 4, _libssh2_htonu32(exchange_state->h_sig_comp + 4,
LIBSSH2_DH_GEX_OPTGROUP); LIBSSH2_DH_GEX_OPTGROUP);
_libssh2_htonu32(exchange_state->h_sig_comp + 8, _libssh2_htonu32(exchange_state->h_sig_comp + 8,
LIBSSH2_DH_GEX_MAXGROUP); LIBSSH2_DH_GEX_MAXGROUP);
libssh2_sha1_update(exchange_state->exchange_hash, libssh2_sha1_update(exchange_state->exchange_hash,
exchange_state->h_sig_comp, 12); exchange_state->h_sig_comp, 12);
#else #else
_libssh2_htonu32(exchange_state->h_sig_comp, _libssh2_htonu32(exchange_state->h_sig_comp,
LIBSSH2_DH_GEX_OPTGROUP); LIBSSH2_DH_GEX_OPTGROUP);
libssh2_sha1_update(exchange_state->exchange_hash, libssh2_sha1_update(exchange_state->exchange_hash,
exchange_state->h_sig_comp, 4); exchange_state->h_sig_comp, 4);
#endif #endif
@ -380,7 +380,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
exchange_state->e_packet_len - 1); exchange_state->e_packet_len - 1);
_libssh2_htonu32(exchange_state->h_sig_comp, _libssh2_htonu32(exchange_state->h_sig_comp,
exchange_state->f_value_len); exchange_state->f_value_len);
libssh2_sha1_update(exchange_state->exchange_hash, libssh2_sha1_update(exchange_state->exchange_hash,
exchange_state->h_sig_comp, 4); exchange_state->h_sig_comp, 4);
libssh2_sha1_update(exchange_state->exchange_hash, libssh2_sha1_update(exchange_state->exchange_hash,
@ -398,8 +398,8 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
sig_verify(session, exchange_state->h_sig, 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,8 +444,8 @@ 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;
} }
memcpy(session->session_id, exchange_state->h_sig_comp, memcpy(session->session_id, exchange_state->h_sig_comp,
@ -811,12 +811,12 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange
if (key_state->state == libssh2_NB_state_created) { if (key_state->state == libssh2_NB_state_created) {
rc = _libssh2_transport_write(session, key_state->request, rc = _libssh2_transport_write(session, key_state->request,
key_state->request_len); key_state->request_len);
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,8 +830,8 @@ 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;
} }
@ -891,7 +891,7 @@ static const LIBSSH2_KEX_METHOD kex_method_diffie_helman_group14_sha1 = {
}; };
static const LIBSSH2_KEX_METHOD static const LIBSSH2_KEX_METHOD
kex_method_diffie_helman_group_exchange_sha1 = { kex_method_diffie_helman_group_exchange_sha1 = {
"diffie-hellman-group-exchange-sha1", "diffie-hellman-group-exchange-sha1",
kex_method_diffie_hellman_group_exchange_sha1_key_exchange, kex_method_diffie_hellman_group_exchange_sha1_key_exchange,
LIBSSH2_KEX_METHOD_FLAG_REQ_SIGN_HOSTKEY, LIBSSH2_KEX_METHOD_FLAG_REQ_SIGN_HOSTKEY,
@ -960,13 +960,13 @@ kex_method_list(unsigned char *buf, size_t list_strlen,
#define LIBSSH2_METHOD_PREFS_LEN(prefvar, defaultvar) \ #define LIBSSH2_METHOD_PREFS_LEN(prefvar, defaultvar) \
((prefvar) ? strlen(prefvar) : \ ((prefvar) ? strlen(prefvar) : \
kex_method_strlen((LIBSSH2_COMMON_METHOD**)(defaultvar))) kex_method_strlen((LIBSSH2_COMMON_METHOD**)(defaultvar)))
#define LIBSSH2_METHOD_PREFS_STR(buf, prefvarlen, prefvar, defaultvar) \ #define LIBSSH2_METHOD_PREFS_STR(buf, prefvarlen, prefvar, defaultvar) \
if (prefvar) { \ if (prefvar) { \
_libssh2_htonu32((buf), (prefvarlen)); \ _libssh2_htonu32((buf), (prefvarlen)); \
buf += 4; \ buf += 4; \
memcpy((buf), (prefvar), (prefvarlen)); \ memcpy((buf), (prefvar), (prefvarlen)); \
buf += (prefvarlen); \ buf += (prefvarlen); \
@ -1026,8 +1026,8 @@ 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");
} }
*(s++) = SSH_MSG_KEXINIT; *(s++) = SSH_MSG_KEXINIT;
@ -1115,8 +1115,8 @@ 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");
} }
@ -1176,7 +1176,7 @@ kex_agree_instr(unsigned char *haystack, unsigned long haystack_len,
*/ */
static const LIBSSH2_COMMON_METHOD * static const LIBSSH2_COMMON_METHOD *
kex_get_method_by_name(const char *name, size_t name_len, kex_get_method_by_name(const char *name, size_t name_len,
const LIBSSH2_COMMON_METHOD ** methodlist) const LIBSSH2_COMMON_METHOD ** methodlist)
{ {
while (*methodlist) { while (*methodlist) {
if ((strlen((*methodlist)->name) == name_len) && if ((strlen((*methodlist)->name) == name_len) &&
@ -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,8 +1736,8 @@ 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,14 +1825,14 @@ 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,9 +1858,9 @@ 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");
} }
if (*prefvar) { if (*prefvar) {

View File

@ -88,9 +88,9 @@ 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,14 +137,14 @@ 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,8 +157,8 @@ 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;
} }
memcpy(entry->name, host, hostlen+1); memcpy(entry->name, host, hostlen+1);
@ -179,8 +179,8 @@ 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,8 +190,8 @@ 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;
} }
memcpy(entry->key, key, keylen+1); memcpy(entry->key, key, keylen+1);
@ -202,9 +202,9 @@ knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
size_t nlen = _libssh2_base64_encode(hosts->session, key, keylen, 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,8 +214,8 @@ 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;
} }
memcpy(entry->comment, comment, commentlen+1); memcpy(entry->comment, comment, commentlen+1);
@ -347,9 +347,9 @@ libssh2_knownhost_check(LIBSSH2_KNOWNHOSTS *hosts,
size_t nlen = _libssh2_base64_encode(hosts->session, key, keylen, 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,8 +440,8 @@ 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 */
node = entry->node; node = entry->node;
@ -510,7 +510,7 @@ static int hostline(LIBSSH2_KNOWNHOSTS *hosts,
for the sake of simplicity, we add them as two hosts with the same for the sake of simplicity, we add them as two hosts with the same
key key
*/ */
size_t scan = hostlen; size_t scan = hostlen;
while(scan && (*host != ',')) { while(scan && (*host != ',')) {
@ -542,10 +542,10 @@ 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)");
memcpy(saltbuf, salt, saltlen); memcpy(saltbuf, salt, saltlen);
saltbuf[saltlen] = 0; /* zero terminate */ saltbuf[saltlen] = 0; /* zero terminate */
@ -565,10 +565,10 @@ 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)");
switch(key[0]) { switch(key[0]) {
case '0': case '1': case '2': case '3': case '4': case '0': case '1': case '2': case '3': case '4':
@ -589,9 +589,9 @@ static int hostline(LIBSSH2_KNOWNHOSTS *hosts,
type |= LIBSSH2_KNOWNHOST_KEY_SSHRSA; 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");
key += 7; key += 7;
keylen -= 7; keylen -= 7;
@ -628,9 +628,9 @@ 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");
} }
if(sep) { if(sep) {
@ -699,10 +699,10 @@ 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");
cp = line; cp = line;
@ -734,9 +734,9 @@ 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");
keyp = cp; /* the key starts here */ keyp = cp; /* the key starts here */
keylen = len; keylen = len;
@ -777,10 +777,10 @@ 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");
file = fopen(filename, "r"); file = fopen(filename, "r");
if(file) { if(file) {
@ -792,8 +792,8 @@ 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,10 +830,10 @@ 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");
tindex = (node->typemask & LIBSSH2_KNOWNHOST_KEY_MASK) >> tindex = (node->typemask & LIBSSH2_KNOWNHOST_KEY_MASK) >>
LIBSSH2_KNOWNHOST_KEY_SHIFT; LIBSSH2_KNOWNHOST_KEY_SHIFT;
@ -852,18 +852,18 @@ 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");
nlen = _libssh2_base64_encode(hosts->session, nlen = _libssh2_base64_encode(hosts->session,
node->salt, node->salt_len, node->salt, node->salt_len,
&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");
} }
nlen = strlen(saltalloc) + strlen(namealloc) + strlen(keytype) + nlen = strlen(saltalloc) + strlen(namealloc) + strlen(keytype) +
@ -878,8 +878,8 @@ knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
sprintf(buf, "|1|%s|%s%s %s\n", saltalloc, namealloc, 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);
free(saltalloc); free(saltalloc);
@ -896,8 +896,8 @@ 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");
} }
/* we report the full length of the data with the trailing zero excluded */ /* we report the full length of the data with the trailing zero excluded */
@ -924,8 +924,8 @@ libssh2_knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
struct known_host *node; 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;
@ -939,7 +939,7 @@ libssh2_knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
*/ */
LIBSSH2_API int LIBSSH2_API int
libssh2_knownhost_writefile(LIBSSH2_KNOWNHOSTS *hosts, libssh2_knownhost_writefile(LIBSSH2_KNOWNHOSTS *hosts,
const char *filename, int type) const char *filename, int type)
{ {
struct known_host *node; struct known_host *node;
FILE *file; FILE *file;
@ -949,15 +949,15 @@ libssh2_knownhost_writefile(LIBSSH2_KNOWNHOSTS *hosts,
/* we only support this single file type for now, bail out on all other /* 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);
node; node;
@ -972,8 +972,8 @@ 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,8 +201,8 @@ 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");
} }
for(s = (unsigned char *) src; ((char *) s) < (src + src_len); s++) { for(s = (unsigned char *) src; ((char *) s) < (src + src_len); s++) {
@ -230,8 +230,8 @@ libssh2_base64_decode(LIBSSH2_SESSION *session, char **data,
/* Invalid -- We have a byte which belongs exclusively to a partial /* 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)");
} }
*datalen = len; *datalen = len;

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,9 +140,9 @@ 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 */
listen_state->state = libssh2_NB_state_sent; listen_state->state = libssh2_NB_state_sent;
break; break;
@ -158,9 +158,9 @@ 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);
failure_code = 4; /* SSH_OPEN_RESOURCE_SHORTAGE */ failure_code = 4; /* SSH_OPEN_RESOURCE_SHORTAGE */
listen_state->state = libssh2_NB_state_sent; listen_state->state = libssh2_NB_state_sent;
@ -213,9 +213,9 @@ 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");
} }
/* Link the channel into the end of the queue list */ /* Link the channel into the end of the queue list */
@ -253,7 +253,7 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
return rc; 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,8 +306,8 @@ 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,8 +319,8 @@ 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 */
goto x11_exit; goto x11_exit;
@ -367,9 +367,9 @@ 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");
} }
/* Link the channel into the session */ /* Link the channel into the session */
@ -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,8 +459,8 @@ _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");
} }
} }
@ -492,47 +492,47 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
/* A couple exceptions to the packet adding rule: */ /* A couple exceptions to the packet adding rule: */
switch (data[0]) { switch (data[0]) {
case SSH_MSG_DISCONNECT: case SSH_MSG_DISCONNECT:
{ {
char *message, *language; char *message, *language;
int reason, message_len, language_len; int reason, message_len, language_len;
reason = _libssh2_ntohu32(data + 1); reason = _libssh2_ntohu32(data + 1);
message_len = _libssh2_ntohu32(data + 5); message_len = _libssh2_ntohu32(data + 5);
/* 9 = packet_type(1) + reason(4) + message_len(4) */ /* 9 = packet_type(1) + reason(4) + message_len(4) */
message = (char *) data + 9; message = (char *) data + 9;
language_len = _libssh2_ntohu32(data + 9 + message_len); language_len = _libssh2_ntohu32(data + 9 + message_len);
/* /*
* This is where we hack on the data a little, * This is where we hack on the data a little,
* Use the MSB of language_len to to a terminating NULL * Use the MSB of language_len to to a terminating NULL
* (In all liklihood it is already) * (In all liklihood it is already)
* Shift the language tag back a byte (In all likelihood * Shift the language tag back a byte (In all likelihood
* it's zero length anyway) * it's zero length anyway)
* Store a NULL in the last byte of the packet to terminate * Store a NULL in the last byte of the packet to terminate
* the language string * the language string
* With the lengths passed this isn't *REALLY* necessary, * With the lengths passed this isn't *REALLY* necessary,
* but it's "kind" * but it's "kind"
*/ */
message[message_len] = '\0'; message[message_len] = '\0';
language = (char *) data + 9 + message_len + 3; language = (char *) data + 9 + message_len + 3;
if (language_len) { if (language_len) {
memmove(language, language + 1, language_len); memmove(language, language + 1, language_len);
}
language[language_len] = '\0';
if (session->ssh_msg_disconnect) {
LIBSSH2_DISCONNECT(session, reason, message,
message_len, language, language_len);
}
_libssh2_debug(session, LIBSSH2_TRACE_TRANS,
"Disconnect(%d): %s(%s)", reason,
message, language);
LIBSSH2_FREE(session, data);
session->socket_state = LIBSSH2_SOCKET_DISCONNECTED;
session->packAdd_state = libssh2_NB_state_idle;
return libssh2_error(session, LIBSSH2_ERROR_SOCKET_DISCONNECT,
"socket disconnect");
} }
break; language[language_len] = '\0';
if (session->ssh_msg_disconnect) {
LIBSSH2_DISCONNECT(session, reason, message,
message_len, language, language_len);
}
_libssh2_debug(session, LIBSSH2_TRACE_TRANS,
"Disconnect(%d): %s(%s)", reason,
message, language);
LIBSSH2_FREE(session, data);
session->socket_state = LIBSSH2_SOCKET_DISCONNECTED;
session->packAdd_state = libssh2_NB_state_idle;
return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_DISCONNECT,
"socket disconnect");
}
break;
case SSH_MSG_IGNORE: case SSH_MSG_IGNORE:
if (datalen >= 5) { if (datalen >= 5) {
@ -550,48 +550,48 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
return 0; return 0;
case SSH_MSG_DEBUG: case SSH_MSG_DEBUG:
{ {
int always_display = data[0]; int always_display = data[0];
char *message, *language; char *message, *language;
int message_len, language_len; int message_len, language_len;
message_len = _libssh2_ntohu32(data + 2); message_len = _libssh2_ntohu32(data + 2);
/* 6 = packet_type(1) + display(1) + message_len(4) */ /* 6 = packet_type(1) + display(1) + message_len(4) */
message = (char *) data + 6; message = (char *) data + 6;
language_len = _libssh2_ntohu32(data + 6 + message_len); language_len = _libssh2_ntohu32(data + 6 + message_len);
/* /*
* This is where we hack on the data a little, * This is where we hack on the data a little,
* Use the MSB of language_len to to a terminating NULL * Use the MSB of language_len to to a terminating NULL
* (In all liklihood it is already) * (In all liklihood it is already)
* Shift the language tag back a byte (In all likelihood * Shift the language tag back a byte (In all likelihood
* it's zero length anyway) * it's zero length anyway)
* Store a NULL in the last byte of the packet to terminate * Store a NULL in the last byte of the packet to terminate
* the language string * the language string
* With the lengths passed this isn't *REALLY* necessary, * With the lengths passed this isn't *REALLY* necessary,
* but it's "kind" * but it's "kind"
*/ */
message[message_len] = '\0'; message[message_len] = '\0';
language = (char *) data + 6 + message_len + 3; language = (char *) data + 6 + message_len + 3;
if (language_len) { if (language_len) {
memmove(language, language + 1, language_len); memmove(language, language + 1, language_len);
}
language[language_len] = '\0';
if (session->ssh_msg_debug) {
LIBSSH2_DEBUG(session, always_display, message,
message_len, language, language_len);
}
/*
* _libssh2_debug will actually truncate this for us so
* that it's not an inordinate about of data
*/
_libssh2_debug(session, LIBSSH2_TRACE_TRANS,
"Debug Packet: %s", message);
LIBSSH2_FREE(session, data);
session->packAdd_state = libssh2_NB_state_idle;
return 0;
} }
break; language[language_len] = '\0';
if (session->ssh_msg_debug) {
LIBSSH2_DEBUG(session, always_display, message,
message_len, language, language_len);
}
/*
* _libssh2_debug will actually truncate this for us so
* that it's not an inordinate about of data
*/
_libssh2_debug(session, LIBSSH2_TRACE_TRANS,
"Debug Packet: %s", message);
LIBSSH2_FREE(session, data);
session->packAdd_state = libssh2_NB_state_idle;
return 0;
}
break;
case SSH_MSG_GLOBAL_REQUEST: case SSH_MSG_GLOBAL_REQUEST:
{ {
@ -628,8 +628,8 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
_libssh2_channel_locate(session, _libssh2_ntohu32(data + 1)); _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;
return 0; return 0;
@ -682,10 +682,10 @@ _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");
datalen = datalen =
session->packAdd_channel->remote.packet_size + session->packAdd_channel->remote.packet_size +
session->packAdd_data_head; session->packAdd_data_head;
@ -695,10 +695,10 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
* Spec says we MAY ignore bytes sent beyond * 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");
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
session->packAdd_state = libssh2_NB_state_idle; session->packAdd_state = libssh2_NB_state_idle;
return 0; return 0;
@ -708,10 +708,10 @@ _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");
datalen = datalen =
session->packAdd_channel->remote.window_size + session->packAdd_channel->remote.window_size +
session->packAdd_data_head; session->packAdd_data_head;
@ -792,7 +792,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
return 0; return 0;
} }
break; break;
} }
case SSH_MSG_CHANNEL_CLOSE: case SSH_MSG_CHANNEL_CLOSE:
session->packAdd_channel = session->packAdd_channel =
@ -852,31 +852,31 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
break; break;
case SSH_MSG_CHANNEL_WINDOW_ADJUST: case SSH_MSG_CHANNEL_WINDOW_ADJUST:
{ {
unsigned long bytestoadd = _libssh2_ntohu32(data + 5); unsigned long bytestoadd = _libssh2_ntohu32(data + 5);
session->packAdd_channel = session->packAdd_channel =
_libssh2_channel_locate(session, _libssh2_channel_locate(session,
_libssh2_ntohu32(data + 1)); _libssh2_ntohu32(data + 1));
if (session->packAdd_channel && bytestoadd) { if (session->packAdd_channel && bytestoadd) {
session->packAdd_channel->local.window_size += bytestoadd; session->packAdd_channel->local.window_size += bytestoadd;
}
if(session->packAdd_channel)
_libssh2_debug(session, LIBSSH2_TRACE_CONN,
"Window adjust received for channel %lu/%lu, adding %lu bytes, new window_size=%lu",
session->packAdd_channel->local.id,
session->packAdd_channel->remote.id,
bytestoadd,
session->packAdd_channel->local.window_size);
else
_libssh2_debug(session, LIBSSH2_TRACE_CONN,
"Window adjust for non-existing channel!");
LIBSSH2_FREE(session, data);
session->packAdd_state = libssh2_NB_state_idle;
return 0;
} }
break; if(session->packAdd_channel)
_libssh2_debug(session, LIBSSH2_TRACE_CONN,
"Window adjust received for channel %lu/%lu, adding %lu bytes, new window_size=%lu",
session->packAdd_channel->local.id,
session->packAdd_channel->remote.id,
bytestoadd,
session->packAdd_channel->local.window_size);
else
_libssh2_debug(session, LIBSSH2_TRACE_CONN,
"Window adjust for non-existing channel!");
LIBSSH2_FREE(session, data);
session->packAdd_state = libssh2_NB_state_idle;
return 0;
}
break;
} }
session->packAdd_state = libssh2_NB_state_sent; session->packAdd_state = libssh2_NB_state_sent;
@ -885,7 +885,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
if (session->packAdd_state == libssh2_NB_state_sent) { if (session->packAdd_state == libssh2_NB_state_sent) {
LIBSSH2_PACKET *packAdd_packet; LIBSSH2_PACKET *packAdd_packet;
packAdd_packet = packAdd_packet =
LIBSSH2_ALLOC(session, sizeof(LIBSSH2_PACKET)); LIBSSH2_ALLOC(session, sizeof(LIBSSH2_PACKET));
if (!packAdd_packet) { if (!packAdd_packet) {
_libssh2_debug(session, LIBSSH2_ERROR_ALLOC, _libssh2_debug(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for LIBSSH2_PACKET"); "Unable to allocate memory for LIBSSH2_PACKET");
@ -1034,8 +1034,8 @@ _libssh2_packet_require(LIBSSH2_SESSION * session, unsigned char packet_type,
{ {
if (state->start == 0) { if (state->start == 0) {
if (_libssh2_packet_ask(session, packet_type, data, data_len, if (_libssh2_packet_ask(session, packet_type, data, data_len,
match_ofs, match_buf, match_ofs, match_buf,
match_len) == 0) { match_len) == 0) {
/* A packet was available in the packet brigade */ /* A packet was available in the packet brigade */
return 0; return 0;
} }
@ -1054,7 +1054,7 @@ _libssh2_packet_require(LIBSSH2_SESSION * session, unsigned char packet_type,
} else if (ret == packet_type) { } else if (ret == packet_type) {
/* Be lazy, let packet_ask pull it out of the brigade */ /* Be lazy, let packet_ask pull it out of the brigade */
ret = _libssh2_packet_ask(session, packet_type, data, data_len, ret = _libssh2_packet_ask(session, packet_type, data, data_len,
match_ofs, match_buf, match_len); match_ofs, match_buf, match_len);
state->start = 0; state->start = 0;
return ret; return ret;
} else if (ret == 0) { } else if (ret == 0) {

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,17 +140,17 @@ 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");
} }
pkey->receive_packet_len = _libssh2_ntohu32(buffer); pkey->receive_packet_len = _libssh2_ntohu32(buffer);
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");
} }
pkey->receive_state = libssh2_NB_state_sent; pkey->receive_state = libssh2_NB_state_sent;
@ -165,9 +165,9 @@ 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");
} }
*data = pkey->receive_packet; *data = pkey->receive_packet;
@ -233,36 +233,36 @@ 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");
} }
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");
} }
switch (response) { switch (response) {
case LIBSSH2_PUBLICKEY_RESPONSE_STATUS: case LIBSSH2_PUBLICKEY_RESPONSE_STATUS:
/* Error, or processing complete */ /* Error, or processing complete */
{ {
unsigned long status = _libssh2_ntohu32(s); unsigned long status = _libssh2_ntohu32(s);
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
if (status == LIBSSH2_PUBLICKEY_SUCCESS) if (status == LIBSSH2_PUBLICKEY_SUCCESS)
return 0; return 0;
publickey_status_error(pkey, session, status); publickey_status_error(pkey, session, status);
return -1; return -1;
} }
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;
} }
@ -272,8 +272,8 @@ publickey_response_success(LIBSSH2_PUBLICKEY * pkey)
} }
/* ***************** /* *****************
* Publickey API * * Publickey API *
***************** */ ***************** */
/* /*
* libssh2_publickey_init * libssh2_publickey_init
@ -312,14 +312,14 @@ 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;
} }
} while (!session->pkeyInit_channel); } while (!session->pkeyInit_channel);
@ -333,12 +333,12 @@ 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,16 +349,16 @@ 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;
} }
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;
} }
memset(session->pkeyInit_pkey, 0, sizeof(LIBSSH2_PUBLICKEY)); memset(session->pkeyInit_pkey, 0, sizeof(LIBSSH2_PUBLICKEY));
@ -386,12 +386,12 @@ libssh2_publickey_init(LIBSSH2_SESSION * session)
rc = _libssh2_channel_write(session->pkeyInit_channel, 0, 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,56 +404,56 @@ 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;
} }
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;
} }
switch (response) { switch (response) {
case LIBSSH2_PUBLICKEY_RESPONSE_STATUS: case LIBSSH2_PUBLICKEY_RESPONSE_STATUS:
/* Error */ /* Error */
{ {
unsigned long status, descr_len, lang_len; unsigned long status, descr_len, lang_len;
unsigned char *descr, *lang; unsigned char *descr, *lang;
status = _libssh2_ntohu32(s); status = _libssh2_ntohu32(s);
s += 4; s += 4;
descr_len = _libssh2_ntohu32(s); descr_len = _libssh2_ntohu32(s);
s += 4; s += 4;
descr = s; descr = s;
s += descr_len; s += descr_len;
lang_len = _libssh2_ntohu32(s); lang_len = _libssh2_ntohu32(s);
s += 4; s += 4;
lang = s; lang = s;
s += lang_len; s += lang_len;
if (s >
session->pkeyInit_data + session->pkeyInit_data_len) {
libssh2_error(session,
LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Malformed publickey subsystem packet");
goto err_exit;
}
publickey_status_error(NULL, session, status);
if (s >
session->pkeyInit_data + session->pkeyInit_data_len) {
_libssh2_error(session,
LIBSSH2_ERROR_PUBLICKEY_PROTOCOL,
"Malformed publickey subsystem packet");
goto err_exit; goto err_exit;
} }
publickey_status_error(NULL, session, status);
goto err_exit;
}
case LIBSSH2_PUBLICKEY_RESPONSE_VERSION: case LIBSSH2_PUBLICKEY_RESPONSE_VERSION:
/* What we want */ /* What we want */
session->pkeyInit_pkey->version = _libssh2_ntohu32(s); session->pkeyInit_pkey->version = _libssh2_ntohu32(s);
@ -475,9 +475,9 @@ 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);
session->pkeyInit_data = NULL; session->pkeyInit_data = NULL;
} }
@ -490,8 +490,8 @@ 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,9 +555,9 @@ 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");
} }
pkey->add_s = pkey->add_packet; pkey->add_s = pkey->add_packet;
@ -625,8 +625,8 @@ libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY * pkey, const unsigned char *name,
} else if ((pkey->add_s - pkey->add_packet) != rc) { } 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);
pkey->add_packet = NULL; pkey->add_packet = NULL;
@ -663,9 +663,9 @@ 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");
} }
pkey->remove_s = pkey->remove_packet; pkey->remove_s = pkey->remove_packet;
@ -700,8 +700,8 @@ libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY * pkey,
LIBSSH2_FREE(session, pkey->remove_packet); 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);
pkey->remove_packet = NULL; pkey->remove_packet = NULL;
@ -760,8 +760,8 @@ 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");
} }
pkey->listFetch_state = libssh2_NB_state_sent; pkey->listFetch_state = libssh2_NB_state_sent;
@ -773,9 +773,9 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
if (rc == PACKET_EAGAIN) { 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,48 +783,48 @@ 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;
} }
switch (response) { switch (response) {
case LIBSSH2_PUBLICKEY_RESPONSE_STATUS: case LIBSSH2_PUBLICKEY_RESPONSE_STATUS:
/* Error, or processing complete */ /* Error, or processing complete */
{ {
unsigned long status, descr_len, lang_len; unsigned long status, descr_len, lang_len;
unsigned char *descr, *lang; unsigned char *descr, *lang;
status = _libssh2_ntohu32(pkey->listFetch_s); status = _libssh2_ntohu32(pkey->listFetch_s);
pkey->listFetch_s += 4; pkey->listFetch_s += 4;
descr_len = _libssh2_ntohu32(pkey->listFetch_s); descr_len = _libssh2_ntohu32(pkey->listFetch_s);
pkey->listFetch_s += 4; pkey->listFetch_s += 4;
descr = pkey->listFetch_s; descr = pkey->listFetch_s;
pkey->listFetch_s += descr_len; pkey->listFetch_s += descr_len;
lang_len = _libssh2_ntohu32(pkey->listFetch_s); lang_len = _libssh2_ntohu32(pkey->listFetch_s);
pkey->listFetch_s += 4; pkey->listFetch_s += 4;
lang = pkey->listFetch_s; lang = pkey->listFetch_s;
pkey->listFetch_s += lang_len; pkey->listFetch_s += lang_len;
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;
}
if (status == LIBSSH2_PUBLICKEY_SUCCESS) {
LIBSSH2_FREE(session, pkey->listFetch_data);
pkey->listFetch_data = NULL;
*pkey_list = list;
*num_keys = keys;
pkey->listFetch_state = libssh2_NB_state_idle;
return 0;
}
publickey_status_error(pkey, session, status);
goto err_exit; goto err_exit;
} }
if (status == LIBSSH2_PUBLICKEY_SUCCESS) {
LIBSSH2_FREE(session, pkey->listFetch_data);
pkey->listFetch_data = NULL;
*pkey_list = list;
*num_keys = keys;
pkey->listFetch_state = libssh2_NB_state_idle;
return 0;
}
publickey_status_error(pkey, session, status);
goto err_exit;
}
case LIBSSH2_PUBLICKEY_RESPONSE_PUBLICKEY: case LIBSSH2_PUBLICKEY_RESPONSE_PUBLICKEY:
/* What we want */ /* What we want */
if (keys >= max_keys) { if (keys >= max_keys) {
@ -836,9 +836,9 @@ 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;
} }
list = newlist; list = newlist;
@ -854,9 +854,9 @@ 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;
} }
list[keys].attrs[0].name = "comment"; list[keys].attrs[0].name = "comment";
@ -896,9 +896,9 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
list[keys].num_attrs * 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;
} }
for(i = 0; i < list[keys].num_attrs; i++) { for(i = 0; i < list[keys].num_attrs; i++) {
@ -926,8 +926,8 @@ libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY * pkey, unsigned long *num_keys,
break; 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;
} }

326
src/scp.c
View File

@ -47,78 +47,78 @@
#define libssh2_shell_quotedsize(s) (3 * strlen(s) + 2) #define libssh2_shell_quotedsize(s) (3 * strlen(s) + 2)
/* /*
This function quotes a string in a way suitable to be used with a This function quotes a string in a way suitable to be used with a
shell, e.g. the file name shell, e.g. the file name
one two one two
becomes becomes
'one two' 'one two'
The resulting output string is crafted in a way that makes it usable The resulting output string is crafted in a way that makes it usable
with the two most common shell types: Bourne Shell derived shells with the two most common shell types: Bourne Shell derived shells
(sh, ksh, ksh93, bash, zsh) and C-Shell derivates (csh, tcsh). (sh, ksh, ksh93, bash, zsh) and C-Shell derivates (csh, tcsh).
The following special cases are handled: The following special cases are handled:
o If the string contains an apostrophy itself, the apostrophy o If the string contains an apostrophy itself, the apostrophy
character is written in quotation marks, e.g. "'". character is written in quotation marks, e.g. "'".
The shell cannot handle the syntax 'doesn\'t', so we close the The shell cannot handle the syntax 'doesn\'t', so we close the
current argument word, add the apostrophe in quotation marks "", current argument word, add the apostrophe in quotation marks "",
and open a new argument word instead (_ indicate the input and open a new argument word instead (_ indicate the input
string characters): string characters):
_____ _ _ _____ _ _
'doesn' "'" 't' 'doesn' "'" 't'
Sequences of apostrophes are combined in one pair of quotation marks: Sequences of apostrophes are combined in one pair of quotation marks:
a'''b a'''b
becomes becomes
_ ___ _ _ ___ _
'a'"'''"'b' 'a'"'''"'b'
o If the string contains an exclamation mark (!), the C-Shell o If the string contains an exclamation mark (!), the C-Shell
interprets it as an event number. Using \! (not within quotation interprets it as an event number. Using \! (not within quotation
marks or single quotation marks) is a mechanism understood by marks or single quotation marks) is a mechanism understood by
both Bourne Shell and C-Shell. both Bourne Shell and C-Shell.
If a quotation was already started, the argument word is closed If a quotation was already started, the argument word is closed
first: first:
a!b a!b
become become
_ _ _ _ _ _
'a'\!'b' 'a'\!'b'
The result buffer must be large enough for the expanded result. A The result buffer must be large enough for the expanded result. A
bad case regarding expansion is alternating characters and bad case regarding expansion is alternating characters and
apostrophes: apostrophes:
a'b'c'd' (length 8) gets converted to a'b'c'd' (length 8) gets converted to
'a'"'"'b'"'"'c'"'"'d'"'" (length 24) 'a'"'"'b'"'"'c'"'"'d'"'" (length 24)
This is the worst case. This is the worst case.
Maximum length of the result: Maximum length of the result:
1 + 6 * (length(input) + 1) / 2) + 1 1 + 6 * (length(input) + 1) / 2) + 1
=> 3 * length(input) + 2 => 3 * length(input) + 2
Explanation: Explanation:
o leading apostrophe o leading apostrophe
o one character / apostrophe pair (two characters) can get o one character / apostrophe pair (two characters) can get
represented as 6 characters: a' -> a'"'"' represented as 6 characters: a' -> a'"'"'
o String terminator (+1) o String terminator (+1)
A result buffer three times the size of the input buffer + 2 A result buffer three times the size of the input buffer + 2
characters should be safe. characters should be safe.
References: References:
o csh-compatible quotation (special handling for '!' etc.), see o csh-compatible quotation (special handling for '!' etc.), see
http://www.grymoire.com/Unix/Csh.html#toc-uh-10 http://www.grymoire.com/Unix/Csh.html#toc-uh-10
Return value: Return value:
Length of the resulting string (not counting the terminating '\0'), Length of the resulting string (not counting the terminating '\0'),
or 0 in case of errors, e.g. result buffer too small or 0 in case of errors, e.g. result buffer too small
Note: this function could possible be used elsewhere within libssh2, but Note: this function could possible be used elsewhere within libssh2, but
until then it is kept static and in this source file. until then it is kept static and in this source file.
*/ */
static unsigned static unsigned
@ -234,20 +234,20 @@ libssh2_shell_quotearg(const char *path, unsigned char *buf,
} }
switch (state) { switch (state) {
case UQSTRING: case UQSTRING:
break; break;
case QSTRING: /* Close quoted string */ case QSTRING: /* Close quoted string */
if (dst+1 >= endp) if (dst+1 >= endp)
return 0; return 0;
*dst++ = '"'; *dst++ = '"';
break; break;
case SQSTRING: /* Close single quoted string */ case SQSTRING: /* Close single quoted string */
if (dst+1 >= endp) if (dst+1 >= endp)
return 0; return 0;
*dst++ = '\''; *dst++ = '\'';
break; break;
default: default:
break; break;
} }
if (dst+1 >= endp) if (dst+1 >= endp)
@ -285,9 +285,9 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
LIBSSH2_ALLOC(session, session->scpRecv_command_len); 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,8 +323,8 @@ 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,8 +339,8 @@ 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) {
LIBSSH2_FREE(session, session->scpRecv_command); LIBSSH2_FREE(session, session->scpRecv_command);
@ -361,8 +361,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
rc = _libssh2_channel_write(session->scpRecv_channel, 0, 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) {
goto scp_recv_error; goto scp_recv_error;
@ -386,13 +386,13 @@ 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++;
@ -402,8 +402,8 @@ 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 =
_libssh2_channel_packet_data_len(session-> _libssh2_channel_packet_data_len(session->
@ -426,12 +426,12 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
* it is already in the systems so it can't return * 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
session->scpRecv_err_msg should be displayed here session->scpRecv_err_msg should be displayed here
@ -458,8 +458,8 @@ 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,8 +470,8 @@ 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;
} }
/* Way too short to be an SCP response, or not done yet, /* Way too short to be an SCP response, or not done yet,
@ -493,9 +493,9 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
if (session->scpRecv_response_len < 8) { 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,9 +504,9 @@ 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,15 +515,15 @@ 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,8 +532,8 @@ 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,8 +542,8 @@ 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,8 +558,8 @@ 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) {
goto scp_recv_error; goto scp_recv_error;
@ -595,20 +595,20 @@ 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,8 +625,8 @@ 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,8 +637,8 @@ 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;
} }
/* Way too short to be an SCP response, or not done yet, /* Way too short to be an SCP response, or not done yet,
@ -661,8 +661,8 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
if (session->scpRecv_response_len < 6) { 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,8 +671,8 @@ 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,16 +681,16 @@ 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;
} }
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,8 +699,8 @@ 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,8 +715,8 @@ 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) {
goto scp_recv_error; goto scp_recv_error;
@ -789,8 +789,8 @@ 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,8 +826,8 @@ 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,8 +842,8 @@ 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;
} }
else if (rc) { else if (rc) {
@ -851,8 +851,8 @@ 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;
} }
LIBSSH2_FREE(session, session->scpSend_command); LIBSSH2_FREE(session, session->scpSend_command);
@ -866,12 +866,12 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
rc = _libssh2_channel_read(session->scpSend_channel, 0, 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,12 +895,12 @@ 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,12 +912,12 @@ 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,12 +953,12 @@ 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,20 +970,20 @@ 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) {
/* /*
* 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 =
_libssh2_channel_packet_data_len(session->scpSend_channel, 0); _libssh2_channel_packet_data_len(session->scpSend_channel, 0);
@ -1007,8 +1007,8 @@ scp_send(LIBSSH2_SESSION * session, const char *path, int mode,
session->scpSend_err_msg = NULL; 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,8 +163,8 @@ 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);
session->remote.banner[banner_len] = '\0'; session->remote.banner[banner_len] = '\0';
@ -403,8 +403,8 @@ libssh2_banner_set(LIBSSH2_SESSION * session, const char *banner)
session->local.banner = LIBSSH2_ALLOC(session, banner_len + 3); 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");
} }
memcpy(session->local.banner, banner, banner_len); memcpy(session->local.banner, banner, banner_len);
@ -592,8 +592,8 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock)
"session_startup for socket %d", sock); "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,8 +611,8 @@ 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,8 +620,8 @@ 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");
} }
session->startup_state = libssh2_NB_state_sent1; session->startup_state = libssh2_NB_state_sent1;
@ -630,8 +630,8 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock)
if (session->startup_state == libssh2_NB_state_sent1) { 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");
} }
session->startup_state = libssh2_NB_state_sent2; session->startup_state = libssh2_NB_state_sent2;
@ -644,7 +644,7 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock)
/* Request the userauth service */ /* Request the userauth service */
session->startup_service[0] = SSH_MSG_SERVICE_REQUEST; session->startup_service[0] = SSH_MSG_SERVICE_REQUEST;
_libssh2_htonu32(session->startup_service + 1, _libssh2_htonu32(session->startup_service + 1,
sizeof("ssh-userauth") - 1); sizeof("ssh-userauth") - 1);
memcpy(session->startup_service + 5, "ssh-userauth", memcpy(session->startup_service + 5, "ssh-userauth",
sizeof("ssh-userauth") - 1); sizeof("ssh-userauth") - 1);
@ -655,8 +655,8 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock)
rc = _libssh2_transport_write(session, session->startup_service, 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");
} }
session->startup_state = libssh2_NB_state_sent4; session->startup_state = libssh2_NB_state_sent4;
@ -678,8 +678,8 @@ 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);
session->startup_data = NULL; session->startup_data = NULL;
@ -1004,9 +1004,9 @@ 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");
} }
*(s++) = SSH_MSG_DISCONNECT; *(s++) = SSH_MSG_DISCONNECT;
@ -1111,14 +1111,14 @@ 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,8 +1358,8 @@ 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,8 +1405,8 @@ 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,8 +122,8 @@ 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,22 +174,22 @@ 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");
} }
packet_len = _libssh2_ntohu32(buffer); packet_len = _libssh2_ntohu32(buffer);
_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");
} }
packet_received = 0; packet_received = 0;
@ -216,8 +216,8 @@ 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;
} }
@ -484,8 +484,8 @@ sftp_bin2attr(LIBSSH2_SFTP_ATTRIBUTES * attrs, const unsigned char *p)
} }
/* ************ /* ************
* SFTP API * * SFTP API *
************ */ ************ */
LIBSSH2_CHANNEL_CLOSE_FUNC(libssh2_sftp_dtor); LIBSSH2_CHANNEL_CLOSE_FUNC(libssh2_sftp_dtor);
@ -554,12 +554,12 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0); 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;
} }
return NULL; return NULL;
@ -574,12 +574,12 @@ 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,8 +590,8 @@ 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,8 +599,8 @@ 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;
} }
memset(sftp_handle, 0, sizeof(LIBSSH2_SFTP)); memset(sftp_handle, 0, sizeof(LIBSSH2_SFTP));
@ -626,13 +626,13 @@ 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;
} }
else { else {
@ -650,17 +650,17 @@ 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;
} }
@ -810,8 +810,8 @@ libssh2_sftp_shutdown(LIBSSH2_SFTP *sftp)
} }
/* ******************************* /* *******************************
* SFTP File and Directory Ops * * SFTP File and Directory Ops *
******************************* */ ******************************* */
/* sftp_open /* sftp_open
*/ */
@ -841,9 +841,9 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
s = sftp->open_packet = LIBSSH2_ALLOC(session, sftp->open_packet_len); 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;
} }
/* Filetype in SFTP 3 and earlier */ /* Filetype in SFTP 3 and earlier */
@ -881,16 +881,16 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
rc = _libssh2_channel_write(channel, 0, (char *) sftp->open_packet, 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;
} }
else if (sftp->open_packet_len != rc) { else if (sftp->open_packet_len != rc) {
/* 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;
sftp->open_state = libssh2_NB_state_idle; sftp->open_state = libssh2_NB_state_idle;
@ -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,8 +945,8 @@ 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);
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
@ -956,8 +956,8 @@ 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,8 +1101,8 @@ 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;
sftp->read_request_id = request_id; sftp->read_request_id = request_id;
@ -1115,13 +1115,13 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
sftp_packet_requirev(sftp, 2, read_responses, 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");
} }
sftp->read_state = libssh2_NB_state_sent1; sftp->read_state = libssh2_NB_state_sent1;
@ -1141,8 +1141,8 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
return total_read; 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");
} }
case SSH_FXP_DATA: case SSH_FXP_DATA:
@ -1260,9 +1260,9 @@ static int sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer,
s = sftp->readdir_packet = LIBSSH2_ALLOC(session, packet_len); 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");
_libssh2_htonu32(s, packet_len - 4); _libssh2_htonu32(s, packet_len - 4);
s += 4; s += 4;
@ -1291,8 +1291,8 @@ 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");
} }
LIBSSH2_FREE(session, sftp->readdir_packet); LIBSSH2_FREE(session, sftp->readdir_packet);
@ -1308,8 +1308,8 @@ 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");
} }
if (data[0] == SSH_FXP_STATUS) { if (data[0] == SSH_FXP_STATUS) {
@ -1322,8 +1322,8 @@ 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,8 +1395,8 @@ 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);
s += 4; s += 4;
@ -1444,8 +1444,8 @@ 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");
} }
sftp->write_state = libssh2_NB_state_idle; sftp->write_state = libssh2_NB_state_idle;
@ -1459,8 +1459,8 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
} }
sftp->last_errno = retcode; 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");
} }
/* libssh2_sftp_write /* libssh2_sftp_write
@ -1502,9 +1502,9 @@ 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");
} }
_libssh2_htonu32(s, packet_len - 4); _libssh2_htonu32(s, packet_len - 4);
@ -1533,9 +1533,9 @@ 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"));
} }
LIBSSH2_FREE(session, sftp->fstat_packet); LIBSSH2_FREE(session, sftp->fstat_packet);
sftp->fstat_packet = NULL; sftp->fstat_packet = NULL;
@ -1550,8 +1550,8 @@ 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");
} }
sftp->fstat_state = libssh2_NB_state_idle; sftp->fstat_state = libssh2_NB_state_idle;
@ -1565,8 +1565,8 @@ 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,9 +1650,9 @@ 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");
} }
_libssh2_htonu32(s, packet_len - 4); _libssh2_htonu32(s, packet_len - 4);
@ -1678,8 +1678,8 @@ 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);
handle->close_packet = NULL; handle->close_packet = NULL;
@ -1695,8 +1695,8 @@ 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");
} }
handle->close_state = libssh2_NB_state_sent1; handle->close_state = libssh2_NB_state_sent1;
@ -1708,8 +1708,8 @@ 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");
} }
/* remove this handle from the parent's list */ /* remove this handle from the parent's list */
@ -1759,9 +1759,9 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename,
_libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Unlinking %s", filename); _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");
} }
_libssh2_htonu32(s, packet_len - 4); _libssh2_htonu32(s, packet_len - 4);
@ -1787,8 +1787,8 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename,
LIBSSH2_FREE(session, sftp->unlink_packet); 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);
sftp->unlink_packet = NULL; sftp->unlink_packet = NULL;
@ -1804,8 +1804,8 @@ 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");
} }
sftp->unlink_state = libssh2_NB_state_idle; sftp->unlink_state = libssh2_NB_state_idle;
@ -1817,8 +1817,8 @@ 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,8 +1858,8 @@ 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");
} }
if (sftp->rename_state == libssh2_NB_state_idle) { if (sftp->rename_state == libssh2_NB_state_idle) {
@ -1868,9 +1868,9 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename,
sftp->rename_s = sftp->rename_packet = 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");
} }
_libssh2_htonu32(sftp->rename_s, packet_len - 4); _libssh2_htonu32(sftp->rename_s, packet_len - 4);
@ -1905,8 +1905,8 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename,
LIBSSH2_FREE(session, sftp->rename_packet); 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);
sftp->rename_packet = NULL; sftp->rename_packet = NULL;
@ -1921,8 +1921,8 @@ 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");
} }
sftp->rename_state = libssh2_NB_state_idle; sftp->rename_state = libssh2_NB_state_idle;
@ -1940,19 +1940,19 @@ 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,9 +2000,9 @@ 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");
} }
/* Filetype in SFTP 3 and earlier */ /* Filetype in SFTP 3 and earlier */
attrs.permissions = mode | LIBSSH2_SFTP_ATTR_PFILETYPE_DIR; attrs.permissions = mode | LIBSSH2_SFTP_ATTR_PFILETYPE_DIR;
@ -2034,8 +2034,8 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path,
if (packet_len != rc) { 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);
sftp->mkdir_state = libssh2_NB_state_sent; sftp->mkdir_state = libssh2_NB_state_sent;
@ -2048,8 +2048,8 @@ 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");
} }
sftp->mkdir_state = libssh2_NB_state_idle; sftp->mkdir_state = libssh2_NB_state_idle;
@ -2062,8 +2062,8 @@ 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,9 +2102,9 @@ 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");
} }
_libssh2_htonu32(s, packet_len - 4); _libssh2_htonu32(s, packet_len - 4);
@ -2130,8 +2130,8 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path,
LIBSSH2_FREE(session, sftp->rmdir_packet); 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);
sftp->rmdir_packet = NULL; sftp->rmdir_packet = NULL;
@ -2145,8 +2145,8 @@ 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");
} }
sftp->rmdir_state = libssh2_NB_state_idle; sftp->rmdir_state = libssh2_NB_state_idle;
@ -2158,8 +2158,8 @@ 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,9 +2203,9 @@ 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");
} }
_libssh2_htonu32(s, packet_len - 4); _libssh2_htonu32(s, packet_len - 4);
@ -2246,8 +2246,8 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path,
LIBSSH2_FREE(session, sftp->stat_packet); 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);
sftp->stat_packet = NULL; sftp->stat_packet = NULL;
@ -2261,8 +2261,8 @@ 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");
} }
sftp->stat_state = libssh2_NB_state_idle; sftp->stat_state = libssh2_NB_state_idle;
@ -2276,8 +2276,8 @@ 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,16 +2322,16 @@ 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");
} }
_libssh2_debug(session, LIBSSH2_TRACE_SFTP, "%s %s on %s", _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "%s %s on %s",
@ -2381,8 +2381,8 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path,
LIBSSH2_FREE(session, sftp->symlink_packet); 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);
sftp->symlink_packet = NULL; sftp->symlink_packet = NULL;
@ -2398,8 +2398,8 @@ 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");
} }
sftp->symlink_state = libssh2_NB_state_idle; sftp->symlink_state = libssh2_NB_state_idle;
@ -2413,16 +2413,16 @@ 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");
} }
link_len = _libssh2_ntohu32(data + 9); link_len = _libssh2_ntohu32(data + 9);
@ -2459,5 +2459,3 @@ libssh2_sftp_last_error(LIBSSH2_SFTP *sftp)
{ {
return sftp->last_errno; return sftp->last_errno;
} }

View File

@ -47,7 +47,7 @@
#include "transport.h" #include "transport.h"
#define MAX_BLOCKSIZE 32 /* MUST fit biggest crypto block size we use/get */ #define MAX_BLOCKSIZE 32 /* MUST fit biggest crypto block size we use/get */
#define MAX_MACSIZE 20 /* MUST fit biggest MAC length we support */ #define MAX_MACSIZE 20 /* MUST fit biggest MAC length we support */
#ifdef LIBSSH2DEBUG #ifdef LIBSSH2DEBUG
@ -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,8 +78,8 @@ 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,8 +108,8 @@ 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;
} }
/* now free the packet that was sent */ /* now free the packet that was sent */
@ -117,8 +117,8 @@ static char *userauth_list(LIBSSH2_SESSION *session, const char *username,
session->userauth_list_data = NULL; 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,9 +230,9 @@ 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");
} }
*(s++) = SSH_MSG_USERAUTH_REQUEST; *(s++) = SSH_MSG_USERAUTH_REQUEST;
@ -269,8 +269,8 @@ userauth_password(LIBSSH2_SESSION *session, const char *username,
rc = _libssh2_transport_write(session, session->userauth_pswd_data, 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");
} }
/* now free the sent packet */ /* now free the sent packet */
@ -279,8 +279,8 @@ 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");
} }
session->userauth_pswd_state = libssh2_NB_state_sent; session->userauth_pswd_state = libssh2_NB_state_sent;
@ -299,12 +299,12 @@ 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");
} }
if (session->userauth_pswd_data[0] == SSH_MSG_USERAUTH_SUCCESS) { if (session->userauth_pswd_data[0] == SSH_MSG_USERAUTH_SUCCESS) {
@ -321,10 +321,10 @@ userauth_password(LIBSSH2_SESSION *session, const char *username,
LIBSSH2_FREE(session, session->userauth_pswd_data); 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)");
} }
session->userauth_pswd_newpw = NULL; session->userauth_pswd_newpw = NULL;
@ -354,10 +354,10 @@ 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");
} }
/* basic data_len + newpw_len(4) */ /* basic data_len + newpw_len(4) */
@ -372,10 +372,10 @@ 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");
} }
*(s++) = SSH_MSG_USERAUTH_REQUEST; *(s++) = SSH_MSG_USERAUTH_REQUEST;
@ -418,8 +418,8 @@ 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");
} }
/* free the allocated packets again */ /* free the allocated packets again */
@ -429,10 +429,10 @@ 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,9 +445,9 @@ 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,8 +457,8 @@ 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,8 +509,8 @@ 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')
pubkey_len++; pubkey_len++;
@ -522,21 +522,21 @@ 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,14 +547,14 @@ 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");
} }
sp1++; sp1++;
@ -567,8 +567,8 @@ 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");
} }
/* Wasting some bytes here (okay, more than some), but since it's likely /* Wasting some bytes here (okay, more than some), but since it's likely
@ -612,15 +612,15 @@ file_read_privatekey(LIBSSH2_SESSION * session,
hostkey_methods_avail++; 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");
} }
return 0; return 0;
@ -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,8 +727,8 @@ 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");
} }
*(session->userauth_host_s++) = SSH_MSG_USERAUTH_REQUEST; *(session->userauth_host_s++) = SSH_MSG_USERAUTH_REQUEST;
@ -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,9 +821,9 @@ 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");
} }
session->userauth_host_packet = newpacket; session->userauth_host_packet = newpacket;
} }
@ -861,14 +861,14 @@ 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);
session->userauth_host_packet = NULL; session->userauth_host_packet = NULL;
@ -886,13 +886,13 @@ 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");
} }
if (session->userauth_host_data[0] == SSH_MSG_USERAUTH_SUCCESS) { if (session->userauth_host_data[0] == SSH_MSG_USERAUTH_SUCCESS) {
@ -909,9 +909,9 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session,
/* This public key is not allowed for this user on this server */ /* 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");
} }
/* libssh2_userauth_hostbased_fromfile_ex /* libssh2_userauth_hostbased_fromfile_ex
@ -971,9 +971,9 @@ 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");
} }
memcpy(session->userauth_pblc_method, pubkeydata + 4, memcpy(session->userauth_pblc_method, pubkeydata + 4,
session->userauth_pblc_method_len); session->userauth_pblc_method_len);
@ -1004,8 +1004,8 @@ 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");
} }
*(session->userauth_pblc_s++) = SSH_MSG_USERAUTH_REQUEST; *(session->userauth_pblc_s++) = SSH_MSG_USERAUTH_REQUEST;
@ -1050,15 +1050,15 @@ userauth_publickey(LIBSSH2_SESSION *session,
rc = _libssh2_transport_write(session, session->userauth_pblc_packet, 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");
} }
session->userauth_pblc_state = libssh2_NB_state_sent; session->userauth_pblc_state = libssh2_NB_state_sent;
@ -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,8 +1080,8 @@ 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");
} }
if (session->userauth_pblc_data[0] == SSH_MSG_USERAUTH_SUCCESS) { if (session->userauth_pblc_data[0] == SSH_MSG_USERAUTH_SUCCESS) {
@ -1111,8 +1111,8 @@ userauth_publickey(LIBSSH2_SESSION *session,
LIBSSH2_FREE(session, session->userauth_pblc_method); 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");
} }
/* Semi-Success! */ /* Semi-Success! */
@ -1131,9 +1131,9 @@ 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");
} }
_libssh2_htonu32(s, session->session_id_len); _libssh2_htonu32(s, session->session_id_len);
@ -1147,15 +1147,15 @@ userauth_publickey(LIBSSH2_SESSION *session,
rc = sign_callback(session, &sig, &sig_len, buf, s - buf, abstract); 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,9 +1177,9 @@ 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");
} }
session->userauth_pblc_packet = newpacket; session->userauth_pblc_packet = newpacket;
} }
@ -1218,13 +1218,13 @@ 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);
session->userauth_pblc_packet = NULL; session->userauth_pblc_packet = NULL;
@ -1240,12 +1240,12 @@ userauth_publickey(LIBSSH2_SESSION *session,
&session->userauth_pblc_data_len, 0, NULL, 0, &session->userauth_pblc_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");
} }
if (session->userauth_pblc_data[0] == SSH_MSG_USERAUTH_SUCCESS) { if (session->userauth_pblc_data[0] == SSH_MSG_USERAUTH_SUCCESS) {
@ -1263,9 +1263,9 @@ userauth_publickey(LIBSSH2_SESSION *session,
LIBSSH2_FREE(session, session->userauth_pblc_data); 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,9 +1399,9 @@ 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");
} }
*s++ = SSH_MSG_USERAUTH_REQUEST; *s++ = SSH_MSG_USERAUTH_REQUEST;
@ -1442,13 +1442,13 @@ 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);
session->userauth_kybd_data = NULL; session->userauth_kybd_data = NULL;
@ -1465,13 +1465,13 @@ 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");
} }
if (session->userauth_kybd_data[0] == SSH_MSG_USERAUTH_SUCCESS) { if (session->userauth_kybd_data[0] == SSH_MSG_USERAUTH_SUCCESS) {
@ -1490,10 +1490,10 @@ userauth_keyboard_interactive(LIBSSH2_SESSION * session,
LIBSSH2_FREE(session, session->userauth_kybd_data); 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)");
} }
/* server requested PAM-like conversation */ /* server requested PAM-like conversation */
@ -1506,9 +1506,9 @@ 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;
} }
memcpy(session->userauth_kybd_auth_name, s, memcpy(session->userauth_kybd_auth_name, s,
@ -1522,10 +1522,10 @@ 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");
goto cleanup; goto cleanup;
} }
memcpy(session->userauth_kybd_auth_instruction, s, memcpy(session->userauth_kybd_auth_instruction, s,
@ -1547,9 +1547,9 @@ 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;
} }
memset(session->userauth_kybd_prompts, 0, memset(session->userauth_kybd_prompts, 0,
@ -1561,9 +1561,9 @@ 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;
} }
memset(session->userauth_kybd_responses, 0, memset(session->userauth_kybd_responses, 0,
@ -1578,9 +1578,9 @@ 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;
} }
memcpy(session->userauth_kybd_prompts[i].text, s, memcpy(session->userauth_kybd_prompts[i].text, s,
@ -1622,9 +1622,9 @@ 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,13 +1648,13 @@ 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;
} }