Skip to content
Snippets Groups Projects
Commit fd0f873a authored by Matt Johnston's avatar Matt Johnston
Browse files

Cancel a dbclient password prompt if the user presses ctrl-c.

Enter still has to be pressed since glibc blocks ctrl-c in getpass()

--HG--
extra : convert_revision : 1c8128fba89431f2460dd5914f0614850d529b76
parent d8e61e51
Branches
Tags
No related merge requests found
...@@ -52,6 +52,7 @@ void cli_pubkeyfail(); ...@@ -52,6 +52,7 @@ void cli_pubkeyfail();
void cli_auth_password(); void cli_auth_password();
int cli_auth_pubkey(); int cli_auth_pubkey();
void cli_auth_interactive(); void cli_auth_interactive();
char* getpass_or_cancel();
#define MAX_USERNAME_LEN 25 /* arbitrary for the moment */ #define MAX_USERNAME_LEN 25 /* arbitrary for the moment */
......
...@@ -278,3 +278,18 @@ void cli_auth_try() { ...@@ -278,3 +278,18 @@ void cli_auth_try() {
TRACE(("leave cli_auth_try")) TRACE(("leave cli_auth_try"))
} }
/* A helper for getpass() that exits if the user cancels. The returned
* password is statically allocated by getpass() */
char* getpass_or_cancel()
{
char* password = NULL;
password = getpass("Password: ");
/* 0x03 is a ctrl-c character in the buffer. */
if (password == NULL || strchr(password, '\3') != NULL) {
dropbear_close("Interrupted.");
}
return password;
}
...@@ -115,7 +115,7 @@ void recv_msg_userauth_info_request() { ...@@ -115,7 +115,7 @@ void recv_msg_userauth_info_request() {
echo = buf_getbool(ses.payload); echo = buf_getbool(ses.payload);
if (!echo) { if (!echo) {
unsigned char* p = getpass(prompt); unsigned char* p = getpass_or_cancel(prompt);
response = m_strdup(p); response = m_strdup(p);
m_burn(p, strlen(p)); m_burn(p, strlen(p));
} else { } else {
......
...@@ -125,10 +125,7 @@ void cli_auth_password() { ...@@ -125,10 +125,7 @@ void cli_auth_password() {
password = gui_getpass("Password: "); password = gui_getpass("Password: ");
else else
#endif #endif
password = getpass("Password: "); password = getpass_or_cancel("Password: ");
if (password == NULL)
return 0;
buf_putbyte(ses.writepayload, SSH_MSG_USERAUTH_REQUEST); buf_putbyte(ses.writepayload, SSH_MSG_USERAUTH_REQUEST);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment