From 112cec4ab7334c92aaea99f11ce4a669d0691839 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Thu, 23 Jun 2016 11:07:18 +0200 Subject: [PATCH] p2v: improve error message for sudo with password Print a better error message when the non-root user on the conversion server requires a password to use sudo, and p2v is told to use sudo. See also RHZ#1340809. (cherry picked from commit 5b6a8e086264c85fb048c0eadff6c34351663133) --- p2v/ssh.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/p2v/ssh.c b/p2v/ssh.c index a8c762d..f2c849f 100644 --- a/p2v/ssh.c +++ b/p2v/ssh.c @@ -98,6 +98,7 @@ static void free_regexps (void) __attribute__((destructor)); static pcre *password_re; static pcre *ssh_message_re; +static pcre *sudo_password_re; static pcre *prompt_re; static pcre *version_re; static pcre *feature_libguestfs_rewrite_re; @@ -141,6 +142,7 @@ compile_regexps (void) COMPILE (password_re, "password:", 0); COMPILE (ssh_message_re, "(ssh: .*)", 0); + COMPILE (sudo_password_re, "sudo: a password is required", 0); /* The magic synchronization strings all match this expression. See * start_ssh function below. */ @@ -161,6 +163,7 @@ free_regexps (void) { pcre_free (password_re); pcre_free (ssh_message_re); + pcre_free (sudo_password_re); pcre_free (prompt_re); pcre_free (version_re); pcre_free (feature_libguestfs_rewrite_re); @@ -546,6 +549,7 @@ test_connection (struct config *config) (mexp_regexp[]) { { 100, .re = version_re }, { 101, .re = prompt_re }, + { 102, .re = sudo_password_re }, { 0 } }, ovector, ovecsize)) { case 100: /* Got version string. */ @@ -560,6 +564,11 @@ test_connection (struct config *config) case 101: /* Got the prompt. */ goto end_of_version; + case 102: + mexp_close (h); + set_ssh_error ("sudo for user '%s' requires a password", config->username); + return -1; + case MEXP_EOF: mexp_close (h); set_ssh_error ("unexpected end of file waiting virt-v2v --version output"); -- 1.8.3.1