|
|
e76f14 |
From e65b2e73ff4f3c6bf692d12c34a0188aa51b552b Mon Sep 17 00:00:00 2001
|
|
|
e76f14 |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
e76f14 |
Date: Thu, 16 Jun 2016 21:22:16 +0100
|
|
|
e76f14 |
Subject: [PATCH] p2v: ssh: Print ssh error if user gives invalid conversion
|
|
|
e76f14 |
server (RHBZ#1167916).
|
|
|
e76f14 |
|
|
|
e76f14 |
Instead of throwing away the ssh error and printing the generic
|
|
|
e76f14 |
message "unexpected end of file waiting for password prompt", we
|
|
|
e76f14 |
capture the ssh error and print it. The user will see the ssh
|
|
|
e76f14 |
diagnostic, eg. "No route to host".
|
|
|
e76f14 |
|
|
|
e76f14 |
(cherry picked from commit 8717a110120f84973f1148adf48e59222cf45e73)
|
|
|
e76f14 |
---
|
|
|
e76f14 |
p2v/ssh.c | 23 ++++++++++++++++++++++-
|
|
|
e76f14 |
1 file changed, 22 insertions(+), 1 deletion(-)
|
|
|
e76f14 |
|
|
|
e76f14 |
diff --git a/p2v/ssh.c b/p2v/ssh.c
|
|
|
e76f14 |
index ce2b17b..d9210f3 100644
|
|
|
e76f14 |
--- a/p2v/ssh.c
|
|
|
e76f14 |
+++ b/p2v/ssh.c
|
|
|
e76f14 |
@@ -97,6 +97,7 @@ static void compile_regexps (void) __attribute__((constructor));
|
|
|
e76f14 |
static void free_regexps (void) __attribute__((destructor));
|
|
|
e76f14 |
|
|
|
e76f14 |
static pcre *password_re;
|
|
|
e76f14 |
+static pcre *ssh_message_re;
|
|
|
e76f14 |
static pcre *prompt_re;
|
|
|
e76f14 |
static pcre *version_re;
|
|
|
e76f14 |
static pcre *feature_libguestfs_rewrite_re;
|
|
|
e76f14 |
@@ -138,6 +139,7 @@ compile_regexps (void)
|
|
|
e76f14 |
} while (0)
|
|
|
e76f14 |
|
|
|
e76f14 |
COMPILE (password_re, "password:", 0);
|
|
|
e76f14 |
+ COMPILE (ssh_message_re, "(ssh: .*)", 0);
|
|
|
e76f14 |
/* The magic synchronization strings all match this expression. See
|
|
|
e76f14 |
* start_ssh function below.
|
|
|
e76f14 |
*/
|
|
|
e76f14 |
@@ -156,6 +158,7 @@ static void
|
|
|
e76f14 |
free_regexps (void)
|
|
|
e76f14 |
{
|
|
|
e76f14 |
pcre_free (password_re);
|
|
|
e76f14 |
+ pcre_free (ssh_message_re);
|
|
|
e76f14 |
pcre_free (prompt_re);
|
|
|
e76f14 |
pcre_free (version_re);
|
|
|
e76f14 |
pcre_free (feature_libguestfs_rewrite_re);
|
|
|
e76f14 |
@@ -350,10 +353,14 @@ start_ssh (struct config *config, char **extra_args, int wait_prompt)
|
|
|
e76f14 |
|
|
|
e76f14 |
if (using_password_auth &&
|
|
|
e76f14 |
config->password && strlen (config->password) > 0) {
|
|
|
e76f14 |
+ CLEANUP_FREE char *ssh_message = NULL;
|
|
|
e76f14 |
+
|
|
|
e76f14 |
/* Wait for the password prompt. */
|
|
|
e76f14 |
+ wait_password_again:
|
|
|
e76f14 |
switch (mexp_expect (h,
|
|
|
e76f14 |
(mexp_regexp[]) {
|
|
|
e76f14 |
{ 100, .re = password_re },
|
|
|
e76f14 |
+ { 101, .re = ssh_message_re },
|
|
|
e76f14 |
{ 0 }
|
|
|
e76f14 |
}, ovector, ovecsize)) {
|
|
|
e76f14 |
case 100: /* Got password prompt. */
|
|
|
e76f14 |
@@ -364,9 +371,23 @@ start_ssh (struct config *config, char **extra_args, int wait_prompt)
|
|
|
e76f14 |
}
|
|
|
e76f14 |
break;
|
|
|
e76f14 |
|
|
|
e76f14 |
+ case 101:
|
|
|
e76f14 |
+ free (ssh_message);
|
|
|
e76f14 |
+ ssh_message = strndup (&h->buffer[ovector[2]], ovector[3]-ovector[2]);
|
|
|
e76f14 |
+ goto wait_password_again;
|
|
|
e76f14 |
+
|
|
|
e76f14 |
case MEXP_EOF:
|
|
|
e76f14 |
mexp_close (h);
|
|
|
e76f14 |
- set_ssh_error ("unexpected end of file waiting for password prompt");
|
|
|
e76f14 |
+ /* This is where we get to if the user enters an incorrect or
|
|
|
e76f14 |
+ * impossible hostname or port number. Hopefully ssh printed an
|
|
|
e76f14 |
+ * error message, and we picked it up and put it in
|
|
|
e76f14 |
+ * 'ssh_message' in case 101 above. If not we have to print a
|
|
|
e76f14 |
+ * generic error instead.
|
|
|
e76f14 |
+ */
|
|
|
e76f14 |
+ if (ssh_message)
|
|
|
e76f14 |
+ set_ssh_error ("%s", ssh_message);
|
|
|
e76f14 |
+ else
|
|
|
e76f14 |
+ set_ssh_error ("unknown ssh error");
|
|
|
e76f14 |
return NULL;
|
|
|
e76f14 |
|
|
|
e76f14 |
case MEXP_TIMEOUT:
|
|
|
e76f14 |
--
|
|
|
e76f14 |
1.8.3.1
|
|
|
e76f14 |
|