X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;ds=sidebyside;f=windows%2Fwincons.c;h=569488404f41fe9de20d5e2b6c223d44162f5893;hb=f14953d9e94c176cfc928bb719d6f613da96717e;hp=e0f0215f6cab416d9197cac4b132fa145b597611;hpb=8719f92c1426609de7ead4a490a15d1d18875f53;p=PuTTY.git diff --git a/windows/wincons.c b/windows/wincons.c index e0f0215f..56948840 100644 --- a/windows/wincons.c +++ b/windows/wincons.c @@ -1,5 +1,5 @@ /* - * console.c: various interactive-prompt routines shared between + * wincons.c - various interactive-prompt routines shared between * the Windows console PuTTY tools */ @@ -294,8 +294,7 @@ void console_provide_logctx(void *logctx) void logevent(void *frontend, const char *string) { - if (console_logctx) - log_eventlog(console_logctx, string); + log_eventlog(console_logctx, string); } static void console_data_untrusted(HANDLE hout, const char *data, int len) @@ -315,18 +314,35 @@ int console_get_userpass_input(prompts_t *p, unsigned char *in, int inlen) */ { int i; - for (i = 0; i < p->n_prompts; i++) + for (i = 0; i < (int)p->n_prompts; i++) memset(p->prompts[i]->result, 0, p->prompts[i]->result_len); } - if (console_batch_mode) - return 0; + /* + * The prompts_t might contain a message to be displayed but no + * actual prompt. More usually, though, it will contain + * questions that the user needs to answer, in which case we + * need to ensure that we're able to get the answers. + */ + if (p->n_prompts) { + if (console_batch_mode) + return 0; + hin = GetStdHandle(STD_INPUT_HANDLE); + if (hin == INVALID_HANDLE_VALUE) { + fprintf(stderr, "Cannot get standard input handle\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); + /* + * And if we have anything to print, we need standard output. + */ + if ((p->name_reqd && p->name) || p->instruction || p->n_prompts) { + hout = GetStdHandle(STD_OUTPUT_HANDLE); + if (hout == INVALID_HANDLE_VALUE) { + fprintf(stderr, "Cannot get standard output handle\n"); + cleanup_exit(1); + } } /*