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

auth: Refactor kbdauth_init().

Rename it to ssh_userauth_kbdint_init.
This commit is contained in:
Andreas Schneider
2011-08-25 16:41:14 +02:00
parent 892cb92f57
commit a51d377afe

View File

@@ -1451,71 +1451,105 @@ void ssh_kbdint_clean(ssh_kbdint kbd) {
kbd->nanswers = 0; kbd->nanswers = 0;
} }
/* this function sends the first packet as explained in section 3.1 /*
* of the draft */ * This function sends the first packet as explained in RFC 3066 section 3.1.
static int kbdauth_init(ssh_session session, const char *user, */
const char *submethods) { static int ssh_userauth_kbdint_init(ssh_session session,
ssh_string usr = NULL; const char *username,
ssh_string sub = NULL; const char *submethods)
ssh_string service = NULL; {
ssh_string method = NULL; ssh_string str;
int rc = SSH_AUTH_ERROR; int rc;
enter_function(); rc = ssh_userauth_request_service(session);
if (rc == SSH_AGAIN) {
return SSH_AUTH_AGAIN;
} else if (rc == SSH_ERROR) {
return SSH_AUTH_ERROR;
}
usr = ssh_string_from_char(user); /* request */
if (usr == NULL) { rc = buffer_add_u8(session->out_buffer, SSH2_MSG_USERAUTH_REQUEST);
ssh_set_error_oom(session); if (rc < 0) {
goto error; goto fail;
} }
sub = (submethods ? ssh_string_from_char(submethods) : ssh_string_from_char(""));
if (sub == NULL) {
ssh_set_error_oom(session);
goto error;
}
service = ssh_string_from_char("ssh-connection");
if (service == NULL) {
ssh_set_error_oom(session);
goto error;
}
method = ssh_string_from_char("keyboard-interactive");
if (method == NULL) {
ssh_set_error_oom(session);
goto error;
}
if (buffer_add_u8(session->out_buffer, SSH2_MSG_USERAUTH_REQUEST) < 0 || /* username */
buffer_add_ssh_string(session->out_buffer, usr) < 0 || if (username) {
buffer_add_ssh_string(session->out_buffer, service) < 0 || str = ssh_string_from_char(username);
buffer_add_ssh_string(session->out_buffer, method) < 0 || } else {
buffer_add_u32(session->out_buffer, 0) < 0 || str = ssh_string_from_char(session->username);
buffer_add_ssh_string(session->out_buffer, sub) < 0) { }
ssh_set_error_oom(session); if (str == NULL) {
goto error; goto fail;
} }
rc = buffer_add_ssh_string(session->out_buffer, str);
ssh_string_free(str);
if (rc < 0) {
goto fail;
}
/* service */
str = ssh_string_from_char("ssh-connection");
if (str == NULL) {
goto fail;
}
rc = buffer_add_ssh_string(session->out_buffer, str);
ssh_string_free(str);
if (rc < 0) {
goto fail;
}
/* method */
str = ssh_string_from_char("keyboard-interactive");
if (str == NULL) {
goto fail;
}
rc = buffer_add_ssh_string(session->out_buffer, str);
ssh_string_free(str);
if (rc < 0) {
goto fail;
}
/* lang string (ignore it) */
rc = buffer_add_u8(session->out_buffer, 0);
if (rc < 0) {
goto fail;
}
/* submethods */
str = ssh_string_from_char(submethods);
if (rc < 0) {
goto fail;
}
rc = buffer_add_ssh_string(session->out_buffer, str);
ssh_string_free(str);
if (rc < 0) {
goto fail;
}
session->auth_state = SSH_AUTH_STATE_NONE;
session->pending_call_state = SSH_PENDING_CALL_AUTH_OFFER_PUBKEY;
rc = packet_send(session);
if (rc == SSH_ERROR) {
return SSH_AUTH_ERROR;
}
rc = ssh_userauth_get_response(session);
if (rc != SSH_AUTH_AGAIN) {
session->pending_call_state = SSH_PENDING_CALL_NONE;
}
ssh_string_free(usr);
ssh_string_free(service);
ssh_string_free(method);
ssh_string_free(sub);
session->auth_state=SSH_AUTH_STATE_KBDINT_SENT;
if (packet_send(session) == SSH_ERROR) {
leave_function();
return rc; return rc;
} fail:
rc = ssh_userauth_get_response(session); ssh_set_error_oom(session);
buffer_reinit(session->out_buffer);
leave_function(); return SSH_AUTH_ERROR;
return rc;
error:
buffer_reinit(session->out_buffer);
ssh_string_free(usr);
ssh_string_free(service);
ssh_string_free(method);
ssh_string_free(sub);
leave_function();
return rc;
} }
/** /**
@@ -1767,7 +1801,7 @@ int ssh_userauth_kbdint(ssh_session session, const char *user,
return SSH_AUTH_ERROR; return SSH_AUTH_ERROR;
} }
rc = kbdauth_init(session, user, submethods); rc = ssh_userauth_kbdint_init(session, user, submethods);
leave_function(); leave_function();
return rc; return rc;