Blame SOURCES/0123-p2v-improve-error-message-for-sudo-with-password.patch

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