mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 10:40:27 +09:00
Improve ssh_userauth_password().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@670 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
@@ -637,20 +637,29 @@ error:
|
|||||||
}
|
}
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
/** \brief Try to authenticate by password
|
/**
|
||||||
* \param session ssh session
|
* @brief Try to authenticate by password.
|
||||||
* \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 password password to use. Take care to clean it after authentication
|
*
|
||||||
* \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 ssh_userauth_kbdint()
|
* @param password The password to use. Take care to clean it after
|
||||||
|
* the authentication.
|
||||||
|
*
|
||||||
|
* @returns SSH_AUTH_ERROR: A serious error happened.\n
|
||||||
|
* 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 ssh_userauth_kbdint()
|
||||||
|
* @see BURN_STRING
|
||||||
*/
|
*/
|
||||||
|
int ssh_userauth_password(SSH_SESSION *session, const char *username,
|
||||||
|
const char *password) {
|
||||||
int ssh_userauth_password(SSH_SESSION *session, const char *username, const char *password){
|
|
||||||
STRING *user = NULL;
|
STRING *user = NULL;
|
||||||
STRING *service = NULL;
|
STRING *service = NULL;
|
||||||
STRING *method = NULL;
|
STRING *method = NULL;
|
||||||
@@ -658,30 +667,38 @@ int ssh_userauth_password(SSH_SESSION *session, const char *username, const char
|
|||||||
int rc = SSH_AUTH_ERROR;
|
int rc = SSH_AUTH_ERROR;
|
||||||
|
|
||||||
enter_function();
|
enter_function();
|
||||||
|
|
||||||
#ifdef HAVE_SSH1
|
#ifdef HAVE_SSH1
|
||||||
if(session->version==1){
|
if (session->version == 1) {
|
||||||
rc = ssh_userauth1_password(session,username,password);
|
rc = ssh_userauth1_password(session, username, password);
|
||||||
leave_function();
|
leave_function();
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if(!username)
|
|
||||||
if(!(username=session->options->username)){
|
if (username == NULL) {
|
||||||
if(ssh_options_default_username(session->options)){
|
if (session->options->username == NULL) {
|
||||||
|
if (ssh_options_default_username(session->options) < 0) {
|
||||||
leave_function();
|
leave_function();
|
||||||
return rc;
|
return rc;
|
||||||
} else
|
|
||||||
username=session->options->username;
|
|
||||||
}
|
}
|
||||||
if(ask_userauth(session)) {
|
}
|
||||||
|
user = string_from_char(session->options->username);
|
||||||
|
} else {
|
||||||
|
user = string_from_char(username);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
@@ -695,22 +712,12 @@ int ssh_userauth_password(SSH_SESSION *session, const char *username, const char
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
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, 0) < 0 ||
|
||||||
}
|
buffer_add_ssh_string(session->out_buffer, pwd) < 0) {
|
||||||
if (buffer_add_ssh_string(session->out_buffer, service) < 0) {
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
if (buffer_add_ssh_string(session->out_buffer, method) < 0) {
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
if (buffer_add_u8(session->out_buffer, 0) < 0) {
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
if (buffer_add_ssh_string(session->out_buffer, pwd) < 0) {
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user