mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-09 18:04:25 +09:00
Improve ssh_userauth_agent_pubkey().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@668 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
@@ -511,21 +511,28 @@ error:
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
/** \brief Try to authenticate through public key with ssh agent
|
/**
|
||||||
* \param session ssh session
|
* @brief Try to authenticate through public key with an ssh agent.
|
||||||
* \param username username to authenticate. You can specify NULL if
|
*
|
||||||
* ssh_option_set_username() has been used. You cannot try two different logins in a row.
|
* @param session The ssh session to use.
|
||||||
* \param publickey the public key provided by the agent
|
*
|
||||||
* \returns SSH_AUTH_ERROR : a serious error happened\n
|
* @param username The username to authenticate. You can specify NULL if
|
||||||
* SSH_AUTH_DENIED : Authentication failed : use another method\n
|
* ssh_option_set_username() has been used. You cannot try
|
||||||
* SSH_AUTH_PARTIAL : You've been partially authenticated, you still have to use another method\n
|
* two different logins in a row.
|
||||||
* SSH_AUTH_SUCCESS : Authentication success
|
*
|
||||||
* \see publickey_from_file()
|
* @param publickey The public key provided by the agent.
|
||||||
* \see privatekey_from_file()
|
*
|
||||||
* \see privatekey_free()
|
* @returns SSH_AUTH_ERROR: A serious error happened.\n
|
||||||
* \see ssh_userauth_offer_pubkey()
|
* SSH_AUTH_DENIED: Authentication failed: use another method.\n
|
||||||
|
* SSH_AUTH_PARTIAL: You've been partially authenticated, you still
|
||||||
|
* have to use another method.\n
|
||||||
|
* SSH_AUTH_SUCCESS: Authentication successful.
|
||||||
|
*
|
||||||
|
* @see publickey_from_file()
|
||||||
|
* @see privatekey_from_file()
|
||||||
|
* @see privatekey_free()
|
||||||
|
* @see ssh_userauth_offer_pubkey()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int ssh_userauth_agent_pubkey(SSH_SESSION *session, const char *username,
|
int ssh_userauth_agent_pubkey(SSH_SESSION *session, const char *username,
|
||||||
PUBLIC_KEY *publickey) {
|
PUBLIC_KEY *publickey) {
|
||||||
STRING *user = NULL;
|
STRING *user = NULL;
|
||||||
@@ -537,29 +544,34 @@ int ssh_userauth_agent_pubkey(SSH_SESSION *session, const char *username,
|
|||||||
int rc = SSH_AUTH_ERROR;
|
int rc = SSH_AUTH_ERROR;
|
||||||
|
|
||||||
enter_function();
|
enter_function();
|
||||||
|
|
||||||
if (! agent_is_running(session)) {
|
if (! agent_is_running(session)) {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(username == NULL) {
|
if (username == NULL) {
|
||||||
if((username = session->options->username) == NULL) {
|
if (session->options->username == NULL) {
|
||||||
if (ssh_options_default_username(session->options)) {
|
if (ssh_options_default_username(session->options) < 0) {
|
||||||
leave_function();
|
leave_function();
|
||||||
return rc;
|
return rc;
|
||||||
} else {
|
|
||||||
username=session->options->username;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
user = string_from_char(session->options->username);
|
||||||
|
} else {
|
||||||
|
user = string_from_char(username);
|
||||||
}
|
}
|
||||||
if (ask_userauth(session)) {
|
|
||||||
|
if (user == NULL) {
|
||||||
leave_function();
|
leave_function();
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
user = string_from_char(username);
|
if (ask_userauth(session) < 0) {
|
||||||
if (user == NULL) {
|
string_free(user);
|
||||||
goto error;
|
leave_function();
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
service = string_from_char("ssh-connection");
|
service = string_from_char("ssh-connection");
|
||||||
if (service == NULL) {
|
if (service == NULL) {
|
||||||
goto error;
|
goto error;
|
||||||
@@ -578,25 +590,13 @@ int ssh_userauth_agent_pubkey(SSH_SESSION *session, const char *username,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* we said previously the public key was accepted */
|
/* we said previously the public key was accepted */
|
||||||
if (buffer_add_u8(session->out_buffer, SSH2_MSG_USERAUTH_REQUEST) < 0) {
|
if (buffer_add_u8(session->out_buffer, SSH2_MSG_USERAUTH_REQUEST) < 0 ||
|
||||||
goto error;
|
buffer_add_ssh_string(session->out_buffer, user) < 0 ||
|
||||||
}
|
buffer_add_ssh_string(session->out_buffer, service) < 0 ||
|
||||||
if (buffer_add_ssh_string(session->out_buffer, user) < 0) {
|
buffer_add_ssh_string(session->out_buffer, method) < 0 ||
|
||||||
goto error;
|
buffer_add_u8(session->out_buffer, 1) < 0 ||
|
||||||
}
|
buffer_add_ssh_string(session->out_buffer, algo) < 0 ||
|
||||||
if (buffer_add_ssh_string(session->out_buffer, service) < 0) {
|
buffer_add_ssh_string(session->out_buffer, key) < 0) {
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
if (buffer_add_ssh_string(session->out_buffer, method) < 0) {
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
if (buffer_add_u8(session->out_buffer, 1) < 0) {
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
if (buffer_add_ssh_string(session->out_buffer, algo) < 0) {
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
if (buffer_add_ssh_string(session->out_buffer, key) < 0) {
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -613,11 +613,13 @@ int ssh_userauth_agent_pubkey(SSH_SESSION *session, const char *username,
|
|||||||
}
|
}
|
||||||
rc = wait_auth_status(session,0);
|
rc = wait_auth_status(session,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
string_free(user);
|
string_free(user);
|
||||||
string_free(service);
|
string_free(service);
|
||||||
string_free(method);
|
string_free(method);
|
||||||
string_free(algo);
|
string_free(algo);
|
||||||
string_free(key);
|
string_free(key);
|
||||||
|
|
||||||
leave_function();
|
leave_function();
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
|
|||||||
Reference in New Issue
Block a user