]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Handle more gracefully the possibility of a keyboard-interactive
authorSimon Tatham <anakin@pobox.com>
Tue, 3 Mar 2009 18:35:53 +0000 (18:35 +0000)
committerSimon Tatham <anakin@pobox.com>
Tue, 3 Mar 2009 18:35:53 +0000 (18:35 +0000)
prompts packet containing no actual prompts (perhaps due to odd
server organisation, or perhaps so it can print a banner message and
do nothing else). Previously, the get_userpass_input functions
always returned failure when in '-batch' mode, even in this case
where no actual input would be required.

[originally from svn r8490]

unix/uxcons.c
windows/wincons.c

index f147b35b6c2fe786cb0ec063495bd2b2e803f909..2021f40ebf5a30d2ca441d67b0ad910ff9552c2f 100644 (file)
@@ -344,7 +344,7 @@ int console_get_userpass_input(prompts_t *p, unsigned char *in, int inlen)
            memset(p->prompts[i]->result, 0, p->prompts[i]->result_len);
     }
 
-    if (console_batch_mode)
+    if (p->n_prompts && console_batch_mode)
        return 0;
 
     /*
index 20fda0531c2f5a3386325e8f8492dff14a9fda13..569488404f41fe9de20d5e2b6c223d44162f5893 100644 (file)
@@ -318,14 +318,31 @@ int console_get_userpass_input(prompts_t *p, unsigned char *in, int inlen)
            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);
+       }
     }
 
     /*