# HG changeset patch # User Matt Johnston # Date 1137307404 0 # Node ID 475a818dd6e7687b8978602088be58d13edd532c # Parent 7ce577234a10ccc0c631bc39c4b3fef572a8bb96 Cancel a dbclient password prompt if the user presses ctrl-c. Enter still has to be pressed since glibc blocks ctrl-c in getpass() diff -r 7ce577234a10 -r 475a818dd6e7 auth.h --- a/auth.h Sun Jan 15 06:39:48 2006 +0000 +++ b/auth.h Sun Jan 15 06:43:24 2006 +0000 @@ -52,6 +52,7 @@ void cli_auth_password(); int cli_auth_pubkey(); void cli_auth_interactive(); +char* getpass_or_cancel(); #define MAX_USERNAME_LEN 25 /* arbitrary for the moment */ diff -r 7ce577234a10 -r 475a818dd6e7 cli-auth.c --- a/cli-auth.c Sun Jan 15 06:39:48 2006 +0000 +++ b/cli-auth.c Sun Jan 15 06:43:24 2006 +0000 @@ -278,3 +278,18 @@ 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; +} diff -r 7ce577234a10 -r 475a818dd6e7 cli-authinteract.c --- a/cli-authinteract.c Sun Jan 15 06:39:48 2006 +0000 +++ b/cli-authinteract.c Sun Jan 15 06:43:24 2006 +0000 @@ -115,7 +115,7 @@ echo = buf_getbool(ses.payload); if (!echo) { - unsigned char* p = getpass(prompt); + unsigned char* p = getpass_or_cancel(prompt); response = m_strdup(p); m_burn(p, strlen(p)); } else { diff -r 7ce577234a10 -r 475a818dd6e7 cli-authpasswd.c --- a/cli-authpasswd.c Sun Jan 15 06:39:48 2006 +0000 +++ b/cli-authpasswd.c Sun Jan 15 06:43:24 2006 +0000 @@ -125,10 +125,7 @@ password = gui_getpass("Password: "); else #endif - password = getpass("Password: "); - - if (password == NULL) - return 0; + password = getpass_or_cancel("Password: "); buf_putbyte(ses.writepayload, SSH_MSG_USERAUTH_REQUEST);