Blame SOURCES/0008-v2v-nbdkit-Don-t-use-password-parameter-RHBZ-1842440.patch

62f9b7
From 89ab50eb404664ac3522294f2f46a1c904a28abd Mon Sep 17 00:00:00 2001
62f9b7
From: "Richard W.M. Jones" <rjones@redhat.com>
62f9b7
Date: Mon, 1 Jun 2020 17:35:58 +0100
62f9b7
Subject: [PATCH] v2v: nbdkit: Don't use password=- parameter (RHBZ#1842440).
62f9b7
62f9b7
This was broken with all nbdkit plugins, some in more ways than others.
62f9b7
62f9b7
Because we start nbdkit in the background and wait 30 seconds for it
62f9b7
to start running, the user had only 30 seconds to type in a password
62f9b7
before we timed out the process.  In addition with the VDDK plugin
62f9b7
password=- had been broken ever since we changed the plugin to use a
62f9b7
reexec
62f9b7
(https://www.redhat.com/archives/libguestfs/2020-June/msg00012.html).
62f9b7
62f9b7
The solution is to read the password ourselves and pass it to nbdkit
62f9b7
as a private file.
62f9b7
62f9b7
(cherry picked from commit 16b551c77c88219a2f68e2fc37daf2dc4d88e4ed)
62f9b7
---
62f9b7
 v2v/nbdkit_sources.ml | 21 ++++++++++++++++++++-
62f9b7
 1 file changed, 20 insertions(+), 1 deletion(-)
62f9b7
62f9b7
diff --git a/v2v/nbdkit_sources.ml b/v2v/nbdkit_sources.ml
62f9b7
index 47832011..f5e91911 100644
62f9b7
--- a/v2v/nbdkit_sources.ml
62f9b7
+++ b/v2v/nbdkit_sources.ml
62f9b7
@@ -142,7 +142,26 @@ let common_create ?bandwidth ?extra_debug ?extra_env password
62f9b7
     match password with
62f9b7
     | NoPassword -> cmd
62f9b7
     | AskForPassword ->
62f9b7
-       Nbdkit.add_arg cmd "password" "-"
62f9b7
+       (* Because we will start nbdkit in the background and then wait
62f9b7
+        * for 30 seconds for it to start up, we cannot use the
62f9b7
+        * password=- feature of nbdkit to read the password
62f9b7
+        * interactively (since in the words of the movie the user has
62f9b7
+        * only "30 seconds to comply").  In any case this feature broke
62f9b7
+        * in the VDDK plugin in nbdkit 1.18 and 1.20.  So in the
62f9b7
+        * AskForPassword case we read the password here.
62f9b7
+        *)
62f9b7
+       printf "password: ";
62f9b7
+       let open Unix in
62f9b7
+       let orig = tcgetattr stdin in
62f9b7
+       let tios = { orig with c_echo = false } in
62f9b7
+       tcsetattr stdin TCSAFLUSH tios; (* Disable echo. *)
62f9b7
+       let password = read_line () in
62f9b7
+       tcsetattr stdin TCSAFLUSH orig; (* Restore echo. *)
62f9b7
+       printf "\n";
62f9b7
+       let password_file = Filename.temp_file "v2vnbdkit" ".txt" in
62f9b7
+       unlink_on_exit password_file;
62f9b7
+       with_open_out password_file (fun chan -> output_string chan password);
62f9b7
+       Nbdkit.add_arg cmd "password" ("+" ^ password_file)
62f9b7
     | PasswordFile password_file ->
62f9b7
        Nbdkit.add_arg cmd "password" ("+" ^ password_file) in
62f9b7