From f9943e2ffdbbb2529ec5f7c1ea569fe4ee40a6a7 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 4 Mar 2023 13:37:13 +0000 Subject: [PATCH] term_get_userpass_input: support the prompts->utf8 flag. This continues the programme of UTF-8 support in authentication, begun in commit f4519b6533b089d which arranged for console userpass prompts to function in UTF-8 when the prompts_t asked them to. Since the new line editing setup works properly when it _is_ in UTF-8 mode, I can now also arrange that it puts the terminal into UTF-8 mode in the right circumstances. I've extended the applicability of the '-legacy-charset-handling' flag introduced by the commit mentioned above, so that now it's not specific to the console front end. Now you can give it to GUI PuTTY as well, which restores the previous (wrong) behaviour of accepting username and password prompt input in the main session's configured character set. So if this change breaks someone's workflow, they should be able to have it back. --- cmdline.c | 2 +- putty.h | 6 +++++- stubs/no-console.c | 5 ----- terminal/terminal.c | 8 ++++++++ terminal/terminal.h | 8 ++++++-- unix/console.c | 2 +- windows/console.c | 2 +- 7 files changed, 22 insertions(+), 11 deletions(-) diff --git a/cmdline.c b/cmdline.c index 716a41b3..773fb9b1 100644 --- a/cmdline.c +++ b/cmdline.c @@ -934,7 +934,7 @@ int cmdline_process_param(const char *p, char *value, !strcmp(p, "-legacy_charset_handling")) { RETURN(1); SAVEABLE(0); - if (!console_set_legacy_charset_handling(true)) { + if (!set_legacy_charset_handling(true)) { cmdline_report_unavailable(p); return ret; } diff --git a/putty.h b/putty.h index a6fbeb54..1c42ef03 100644 --- a/putty.h +++ b/putty.h @@ -2516,7 +2516,6 @@ bool have_ssh_host_key(const char *host, int port, const char *keytype); extern bool console_batch_mode, console_antispoof_prompt; extern bool console_set_batch_mode(bool); extern bool console_set_stdio_prompts(bool); -extern bool console_set_legacy_charset_handling(bool); SeatPromptResult console_get_userpass_input(prompts_t *p); bool is_interactive(void); void console_print_error_msg(const char *prefix, const char *msg); @@ -2525,6 +2524,11 @@ void console_print_error_msg_fmt_v( void console_print_error_msg_fmt(const char *prefix, const char *fmt, ...) PRINTF_LIKE(2, 3); +/* + * Exports from either console frontends or terminal.c. + */ +extern bool set_legacy_charset_handling(bool); + /* * Exports from printing.c in platform subdirs. */ diff --git a/stubs/no-console.c b/stubs/no-console.c index 5dde9c89..580cfd70 100644 --- a/stubs/no-console.c +++ b/stubs/no-console.c @@ -13,8 +13,3 @@ bool console_set_stdio_prompts(bool newvalue) { return false; } - -bool console_set_legacy_charset_handling(bool newvalue) -{ - return false; -} diff --git a/terminal/terminal.c b/terminal/terminal.c index a90390b1..a2e1a9e8 100644 --- a/terminal/terminal.c +++ b/terminal/terminal.c @@ -7974,6 +7974,13 @@ static void term_userpass_next_prompt(struct term_userpass_state *s) } } +static bool terminal_use_utf8 = true; +bool set_legacy_charset_handling(bool newvalue) +{ + terminal_use_utf8 = !newvalue; + return true; +} + /* * Process some terminal data in the course of username/password * input. @@ -8000,6 +8007,7 @@ SeatPromptResult term_get_userpass_input(Terminal *term, prompts_t *p) */ p->data = s = term_userpass_state_new(term, p); p->spr = SPR_INCOMPLETE; + term->userpass_utf8_override = p->utf8 && terminal_use_utf8; /* We only print the `name' caption if we have to... */ if (p->name_reqd && p->name) { ptrlen plname = ptrlen_from_asciz(p->name); diff --git a/terminal/terminal.h b/terminal/terminal.h index 95c504ec..51c296bb 100644 --- a/terminal/terminal.h +++ b/terminal/terminal.h @@ -433,14 +433,18 @@ struct terminal_tag { /* * Indicates whether term_get_userpass_input is currently using - * the terminal to present a password prompt or similar. + * the terminal to present a password prompt or similar, and if + * so, whether it's overridden the terminal into UTF-8 mode. */ struct term_userpass_state *userpass_state; + bool userpass_utf8_override; }; static inline bool in_utf(Terminal *term) { - return term->utf || term->ucsdata->line_codepage == CP_UTF8; + return (term->utf || + term->ucsdata->line_codepage == CP_UTF8 || + (term->userpass_state && term->userpass_utf8_override)); } unsigned long term_translate( diff --git a/unix/console.c b/unix/console.c index 00d3f6ac..c92ef34b 100644 --- a/unix/console.c +++ b/unix/console.c @@ -578,7 +578,7 @@ bool console_set_stdio_prompts(bool newvalue) return false; } -bool console_set_legacy_charset_handling(bool newvalue) +bool set_legacy_charset_handling(bool newvalue) { /* This probably _will_ need to be supported, but isn't yet. */ return false; diff --git a/windows/console.c b/windows/console.c index 886d1a69..92e06259 100644 --- a/windows/console.c +++ b/windows/console.c @@ -56,7 +56,7 @@ bool console_set_stdio_prompts(bool newvalue) } static bool conio_use_utf8 = true; -bool console_set_legacy_charset_handling(bool newvalue) +bool set_legacy_charset_handling(bool newvalue) { conio_use_utf8 = !newvalue; return true;