+/*
+ * Special functions to read and print to the console for password
+ * prompts and the like. Uses /dev/tty or stdin/stderr, in that order
+ * of preference; also sanitises escape sequences out of the text, on
+ * the basis that it might have been sent by a hostile SSH server
+ * doing malicious keyboard-interactive.
+ */
+static void console_open(FILE **outfp, int *infd)
+{
+ int fd;
+
+ if ((fd = open("/dev/tty", O_RDWR)) >= 0) {
+ *infd = fd;
+ *outfp = fdopen(*infd, "w");
+ } else {
+ *infd = 0;
+ *outfp = stderr;
+ }
+}
+static void console_close(FILE *outfp, int infd)
+{
+ if (outfp != stderr)
+ fclose(outfp); /* will automatically close infd too */
+}
+
+static void console_prompt_text(FILE *outfp, const char *data, int len)