mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 10:40:27 +09:00
Improve ssh_userauth_none().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@665 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
@@ -182,23 +182,29 @@ int ssh_userauth_list(SSH_SESSION *session, const char *username) {
|
||||
|
||||
/* use the "none" authentication question */
|
||||
|
||||
/** \brief Try to authenticate through the "none" method
|
||||
* \param session ssh session
|
||||
* \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.
|
||||
* \returns SSH_AUTH_ERROR : a serious error happened\n
|
||||
/**
|
||||
* @brief Try to authenticate through the "none" method.
|
||||
*
|
||||
* @param session The ssh session to use.
|
||||
*
|
||||
* @param username The username to authenticate. You can specify NULL if
|
||||
* ssh_option_set_username() has been used. You cannot try
|
||||
* two different logins in a row.
|
||||
*
|
||||
* @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_PARTIAL: You've been partially authenticated, you still
|
||||
* have to use another method\n
|
||||
* SSH_AUTH_SUCCESS: Authentication success
|
||||
*/
|
||||
|
||||
int ssh_userauth_none(SSH_SESSION *session, const char *username) {
|
||||
STRING *user = NULL;
|
||||
STRING *service = NULL;
|
||||
STRING *method = NULL;
|
||||
STRING *service;
|
||||
STRING *method;
|
||||
int rc = SSH_AUTH_ERROR;
|
||||
|
||||
enter_function();
|
||||
|
||||
#ifdef HAVE_SSH1
|
||||
if (session->version == 1) {
|
||||
ssh_userauth1_none(session, username);
|
||||
@@ -206,22 +212,30 @@ int ssh_userauth_none(SSH_SESSION *session, const char *username){
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
if(!username)
|
||||
if(!(username=session->options->username)){
|
||||
if(ssh_options_default_username(session->options)){
|
||||
leave_function();
|
||||
return rc;
|
||||
} else
|
||||
username=session->options->username;
|
||||
}
|
||||
if (ask_userauth(session)) {
|
||||
|
||||
if (username == NULL) {
|
||||
if (session->options->username == NULL) {
|
||||
if (ssh_options_default_username(session->options) < 0) {
|
||||
leave_function();
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
user = string_from_char(session->options->username);
|
||||
} else {
|
||||
user = string_from_char(username);
|
||||
if (user == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (user == NULL) {
|
||||
leave_function();
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (ask_userauth(session) < 0) {
|
||||
string_free(user);
|
||||
leave_function();
|
||||
return rc;
|
||||
}
|
||||
|
||||
method = string_from_char("none");
|
||||
if (method == NULL) {
|
||||
goto error;
|
||||
@@ -231,16 +245,10 @@ int ssh_userauth_none(SSH_SESSION *session, const char *username){
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (buffer_add_u8(session->out_buffer, SSH2_MSG_USERAUTH_REQUEST) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (buffer_add_ssh_string(session->out_buffer, user) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (buffer_add_ssh_string(session->out_buffer, service) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (buffer_add_ssh_string(session->out_buffer, method) < 0) {
|
||||
if (buffer_add_u8(session->out_buffer, SSH2_MSG_USERAUTH_REQUEST) < 0 ||
|
||||
buffer_add_ssh_string(session->out_buffer, user) < 0 ||
|
||||
buffer_add_ssh_string(session->out_buffer, service) < 0 ||
|
||||
buffer_add_ssh_string(session->out_buffer, method) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user