1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-11-29 01:03:57 +03:00

auth: Refactor and fix ssh_userauth_kbdint().

This commit is contained in:
Andreas Schneider
2011-08-26 13:31:23 +02:00
parent f2e08e8d7b
commit d4424b2767

View File

@@ -1465,9 +1465,7 @@ static int ssh_userauth_kbdint_init(ssh_session session,
int rc; int rc;
rc = ssh_userauth_request_service(session); rc = ssh_userauth_request_service(session);
if (rc == SSH_AGAIN) { if (rc != SSH_OK) {
return SSH_AUTH_AGAIN;
} else if (rc == SSH_ERROR) {
return SSH_AUTH_ERROR; return SSH_AUTH_ERROR;
} }
@@ -1518,7 +1516,13 @@ static int ssh_userauth_kbdint_init(ssh_session session,
} }
/* lang string (ignore it) */ /* lang string (ignore it) */
rc = buffer_add_u8(session->out_buffer, 0); str = ssh_string_from_char("");
if (str == NULL) {
goto fail;
}
rc = buffer_add_ssh_string(session->out_buffer, str);
ssh_string_free(str);
if (rc < 0) { if (rc < 0) {
goto fail; goto fail;
} }
@@ -1539,17 +1543,13 @@ static int ssh_userauth_kbdint_init(ssh_session session,
goto fail; goto fail;
} }
session->auth_state = SSH_AUTH_STATE_NONE; session->auth_state = SSH_AUTH_STATE_KBDINT_SENT;
session->pending_call_state = SSH_PENDING_CALL_AUTH_OFFER_PUBKEY;
rc = packet_send(session); rc = packet_send(session);
if (rc == SSH_ERROR) { if (rc == SSH_ERROR) {
return SSH_AUTH_ERROR; return SSH_AUTH_ERROR;
} }
rc = ssh_userauth_get_response(session); rc = ssh_userauth_get_response(session);
if (rc != SSH_AUTH_AGAIN) {
session->pending_call_state = SSH_PENDING_CALL_NONE;
}
return rc; return rc;
fail: fail:
@@ -1782,38 +1782,21 @@ int ssh_userauth_kbdint(ssh_session session, const char *user,
const char *submethods) { const char *submethods) {
int rc = SSH_AUTH_ERROR; int rc = SSH_AUTH_ERROR;
if (session == NULL) {
return SSH_AUTH_ERROR;
}
#ifdef WITH_SSH1
if (session->version == 1) { if (session->version == 1) {
ssh_set_error(session, SSH_NO_ERROR, "No keyboard-interactive for ssh1");
return SSH_AUTH_DENIED; return SSH_AUTH_DENIED;
} }
#endif
enter_function();
if (session->kbdint == NULL) { if (session->kbdint == NULL) {
/* first time we call. we must ask for a challenge */
if (user == NULL) {
if ((user = session->username) == NULL) {
if (ssh_options_apply(session) < 0) {
leave_function();
return SSH_AUTH_ERROR;
} else {
user = session->username;
}
}
}
rc = ssh_userauth_request_service(session);
if (rc != SSH_OK) {
leave_function();
return SSH_AUTH_ERROR;
}
rc = ssh_userauth_kbdint_init(session, user, submethods); rc = ssh_userauth_kbdint_init(session, user, submethods);
leave_function();
return rc; return rc;
} } else {
/* /*
* If we are at this point, it is because session->kbdint exists. * If we are at this point, it is because session->kbdint exists.
* It means the user has set some information there we need to send * It means the user has set some information there we need to send
@@ -1822,10 +1805,12 @@ int ssh_userauth_kbdint(ssh_session session, const char *user,
*/ */
rc = kbdauth_send(session); rc = kbdauth_send(session);
leave_function();
return rc; return rc;
} }
return SSH_AUTH_DENIED;
}
/** /**
* @brief Get the number of prompts (questions) the server has given. * @brief Get the number of prompts (questions) the server has given.
* *