1
1
Этот коммит содержится в:
Andreas Schneider 2011-01-23 20:08:25 +01:00
родитель 50a119dd0a
Коммит f3685f0f73
2 изменённых файлов: 15 добавлений и 5 удалений

Просмотреть файл

@ -80,7 +80,12 @@ int authenticate_kbdint(ssh_session session, const char *password) {
if (password && strstr(prompt, "Password:")) { if (password && strstr(prompt, "Password:")) {
answer = password; answer = password;
} else { } else {
answer = getpass(prompt); buffer[0] = '\0';
if (ssh_getpass(prompt, buffer, sizeof(buffer), 0, 0) < 0) {
return SSH_AUTH_ERROR;
}
answer = buffer;
} }
if (ssh_userauth_kbdint_setanswer(session, i, answer) < 0) { if (ssh_userauth_kbdint_setanswer(session, i, answer) < 0) {
return SSH_AUTH_ERROR; return SSH_AUTH_ERROR;
@ -100,7 +105,7 @@ static void error(ssh_session session){
int authenticate_console(ssh_session session){ int authenticate_console(ssh_session session){
int rc; int rc;
int method; int method;
char *password; char password[128] = {0};
char *banner; char *banner;
// Try to authenticate // Try to authenticate
@ -112,7 +117,6 @@ int authenticate_console(ssh_session session){
method = ssh_auth_list(session); method = ssh_auth_list(session);
while (rc != SSH_AUTH_SUCCESS) { while (rc != SSH_AUTH_SUCCESS) {
// Try to authenticate with public key first // Try to authenticate with public key first
if (method & SSH_AUTH_METHOD_PUBLICKEY) { if (method & SSH_AUTH_METHOD_PUBLICKEY) {
rc = ssh_userauth_autopubkey(session, NULL); rc = ssh_userauth_autopubkey(session, NULL);
@ -135,7 +139,10 @@ int authenticate_console(ssh_session session){
} }
} }
password=getpass("Password: "); if (ssh_getpass("Password: ", password, sizeof(password), 0, 0) < 0) {
return SSH_AUTH_ERROR;
}
// Try to authenticate with password // Try to authenticate with password
if (method & SSH_AUTH_METHOD_PASSWORD) { if (method & SSH_AUTH_METHOD_PASSWORD) {
rc = ssh_userauth_password(session, NULL, password); rc = ssh_userauth_password(session, NULL, password);

Просмотреть файл

@ -58,7 +58,10 @@ static int auth_callback(const char *prompt, char *buf, size_t len,
*ptr = '\0'; *ptr = '\0';
} }
} else { } else {
answer = getpass(prompt); if (ssh_getpass(prompt, buf, len, 0, 0) < 0) {
return -1;
}
return 0;
} }
if (answer == NULL) { if (answer == NULL) {