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

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