added missing error codes

To allow the libssh2_session_last_error() function to work as
documented, userauth_password() now better makes sure to call
libssh2_error() everywhere before it returns error.

Pointed out by mr anonymous in bug #128
This commit is contained in:
Daniel Stenberg 2010-02-18 00:01:33 +01:00
parent 2149244cfe
commit 72ae0866cb

View File

@ -268,6 +268,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) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block writing password request", 0);
return rc; return rc;
} else if (rc) { } else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
@ -296,8 +298,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) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting", 0);
return rc; return rc;
} else if (rc) { } else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_TIMEOUT,
"Would block waiting", 0);
session->userauth_pswd_state = libssh2_NB_state_idle; session->userauth_pswd_state = libssh2_NB_state_idle;
return -1; return -1;
} }
@ -415,6 +421,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) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting", 0);
return rc; return rc;
} else if (rc) { } else if (rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
@ -454,6 +462,9 @@ 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;
libssh2_error(session, LIBSSH2_ERROR_AUTHENTICATION_FAILED,
"Authentication failed", 0);
return -1; return -1;
} }