X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/2e85c969d67eb14a07314802d4ac5dd63eef660b..edd0cb8aef57080ae884e06731a7892ca8cdba44:/windows/wincons.c diff --git a/windows/wincons.c b/windows/wincons.c index 0106fed0..e0f0215f 100644 --- a/windows/wincons.c +++ b/windows/wincons.c @@ -271,6 +271,22 @@ void old_keyfile_warning(void) fputs(message, stderr); } +/* + * Display the fingerprints of the PGP Master Keys to the user. + */ +void pgp_fingerprints(void) +{ + fputs("These are the fingerprints of the PuTTY PGP Master Keys. They can\n" + "be used to establish a trust path from this executable to another\n" + "one. See the manual for more information.\n" + "(Note: these fingerprints have nothing to do with SSH!)\n" + "\n" + "PuTTY Master Key (RSA), 1024-bit:\n" + " " PGP_RSA_MASTER_KEY_FP "\n" + "PuTTY Master Key (DSA), 1024-bit:\n" + " " PGP_DSA_MASTER_KEY_FP "\n", stdout); +} + void console_provide_logctx(void *logctx) { console_logctx = logctx; @@ -282,48 +298,90 @@ void logevent(void *frontend, const char *string) log_eventlog(console_logctx, string); } -int console_get_line(const char *prompt, char *str, - int maxlen, int is_pw) +static void console_data_untrusted(HANDLE hout, const char *data, int len) +{ + DWORD dummy; + /* FIXME: control-character filtering */ + WriteFile(hout, data, len, &dummy, NULL); +} + +int console_get_userpass_input(prompts_t *p, unsigned char *in, int inlen) { HANDLE hin, hout; - DWORD savemode, newmode, i; + size_t curr_prompt; - if (console_batch_mode) { - if (maxlen > 0) - str[0] = '\0'; + /* + * Zero all the results, in case we abort half-way through. + */ + { + int i; + for (i = 0; i < p->n_prompts; i++) + memset(p->prompts[i]->result, 0, p->prompts[i]->result_len); + } + + if (console_batch_mode) return 0; - } else { - hin = GetStdHandle(STD_INPUT_HANDLE); - hout = GetStdHandle(STD_OUTPUT_HANDLE); - if (hin == INVALID_HANDLE_VALUE || hout == INVALID_HANDLE_VALUE) { - fprintf(stderr, "Cannot get standard input/output handles\n"); - cleanup_exit(1); - } + + hin = GetStdHandle(STD_INPUT_HANDLE); + hout = GetStdHandle(STD_OUTPUT_HANDLE); + if (hin == INVALID_HANDLE_VALUE || hout == INVALID_HANDLE_VALUE) { + fprintf(stderr, "Cannot get standard input/output handles\n"); + cleanup_exit(1); + } + + /* + * Preamble. + */ + /* We only print the `name' caption if we have to... */ + if (p->name_reqd && p->name) { + size_t l = strlen(p->name); + console_data_untrusted(hout, p->name, l); + if (p->name[l-1] != '\n') + console_data_untrusted(hout, "\n", 1); + } + /* ...but we always print any `instruction'. */ + if (p->instruction) { + size_t l = strlen(p->instruction); + console_data_untrusted(hout, p->instruction, l); + if (p->instruction[l-1] != '\n') + console_data_untrusted(hout, "\n", 1); + } + + for (curr_prompt = 0; curr_prompt < p->n_prompts; curr_prompt++) { + + DWORD savemode, newmode, i = 0; + prompt_t *pr = p->prompts[curr_prompt]; + BOOL r; GetConsoleMode(hin, &savemode); newmode = savemode | ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT; - if (is_pw) + if (!pr->echo) newmode &= ~ENABLE_ECHO_INPUT; else newmode |= ENABLE_ECHO_INPUT; SetConsoleMode(hin, newmode); - WriteFile(hout, prompt, strlen(prompt), &i, NULL); - ReadFile(hin, str, maxlen - 1, &i, NULL); + console_data_untrusted(hout, pr->prompt, strlen(pr->prompt)); + + r = ReadFile(hin, pr->result, pr->result_len - 1, &i, NULL); SetConsoleMode(hin, savemode); - if ((int) i > maxlen) - i = maxlen - 1; + if ((int) i > pr->result_len) + i = pr->result_len - 1; else i = i - 2; - str[i] = '\0'; + pr->result[i] = '\0'; - if (is_pw) - WriteFile(hout, "\r\n", 2, &i, NULL); + if (!pr->echo) { + DWORD dummy; + WriteFile(hout, "\r\n", 2, &dummy, NULL); + } - return 1; } + + return 1; /* success */ + } void frontend_keypress(void *handle)