diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2015-06-28 09:16:24 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2015-06-28 09:16:24 +0200 |
commit | 7fabe8c2a28d973b24e7d952562bdfb340cbb541 (patch) | |
tree | 73f175319d3a74d7199e08e23c7622d1746316cd /src | |
parent | d9acb2b97ad91f9c9d4ad4b7f8eb3cd31d773da6 (diff) | |
download | weechat-7fabe8c2a28d973b24e7d952562bdfb340cbb541.zip |
core: allow ctrl-C to exit WeeChat when the passphrase is asked on startup (closes #452)
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-secure.c | 21 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-main.c | 34 | ||||
-rw-r--r-- | src/gui/gui-main.h | 3 |
3 files changed, 39 insertions, 19 deletions
diff --git a/src/core/wee-secure.c b/src/core/wee-secure.c index 4ba69a83c..226fe6e0b 100644 --- a/src/core/wee-secure.c +++ b/src/core/wee-secure.c @@ -566,16 +566,20 @@ secure_decrypt_data_not_decrypted (const char *passphrase) void secure_get_passphrase_from_user (const char *error) { + const char *prompt[5]; char passphrase[1024]; + prompt[0] = _("Please enter your passphrase to decrypt the data secured " + "by WeeChat:"); + prompt[1] = _("(enter just one space to skip the passphrase, but this " + "will DISABLE all secured data!)"); + prompt[2] = _("(press ctrl-C to exit WeeChat now)"); + prompt[3] = error; + prompt[4] = NULL; + while (1) { - gui_main_get_password (_("Please enter your passphrase to decrypt the " - "data secured by WeeChat:"), - _("(enter just one space to skip the passphrase, " - "but this will DISABLE all secured data!)"), - error, - passphrase, sizeof (passphrase)); + gui_main_get_password (prompt, passphrase, sizeof (passphrase)); if (secure_passphrase) { free (secure_passphrase); @@ -590,6 +594,11 @@ secure_get_passphrase_from_user (const char *error) _("To recover your secured data, you can " "use /secure decrypt (see /help secure)")); } + else if (strcmp (passphrase, "\x03") == 0) + { + /* ctrl-C pressed, just exit now */ + exit (1); + } else secure_passphrase = strdup (passphrase); return; diff --git a/src/gui/curses/gui-curses-main.c b/src/gui/curses/gui-curses-main.c index e01fa20bf..f83d8324a 100644 --- a/src/gui/curses/gui-curses-main.c +++ b/src/gui/curses/gui-curses-main.c @@ -74,22 +74,26 @@ int gui_term_lines = 0; /* number of lines in terminal */ */ void -gui_main_get_password (const char *prompt1, const char *prompt2, - const char *prompt3, - char *password, int size) +gui_main_get_password (const char **prompt, char *password, int size) { - int i, ch; + int line, i, ch; initscr (); cbreak (); noecho (); + raw (); clear(); - mvaddstr (0, 0, prompt1); - mvaddstr (1, 0, prompt2); - mvaddstr (2, 0, prompt3); - mvaddstr (3, 0, "=> "); + line = 0; + + while (prompt[line]) + { + mvaddstr (line, 0, prompt[line]); + line++; + } + + mvaddstr (line, 0, "=> "); refresh (); memset (password, '\0', size); @@ -97,22 +101,30 @@ gui_main_get_password (const char *prompt1, const char *prompt2, while (i < size - 1) { ch = getch (); + /* enter */ if (ch == '\n') break; + /* ctrl-C */ + if (ch == 3) + { + password[0] = 3; + i = 1; + break; + } if (ch == 127) { if (i > 0) { i--; password[i] = '\0'; - mvaddstr (3, 3 + i, " "); - move (3, 3 + i); + mvaddstr (line, 3 + i, " "); + move (line, 3 + i); } } else { password[i] = ch; - mvaddstr (3, 3 + i, "*"); + mvaddstr (line, 3 + i, "*"); i++; } refresh (); diff --git a/src/gui/gui-main.h b/src/gui/gui-main.h index 926eee1da..251f8b7dc 100644 --- a/src/gui/gui-main.h +++ b/src/gui/gui-main.h @@ -22,8 +22,7 @@ /* main functions (GUI dependent) */ -extern void gui_main_get_password (const char *prompt1, const char *prompt2, - const char *prompt3, +extern void gui_main_get_password (const char **prompt, char *password, int size); extern void gui_main_debug_libs (); extern void gui_main_end (int clean_exit); |