Blame SOURCES/0007-v2v-nbdkit-Handle-password-parameter-in-common_creat.patch

62f9b7
From bcb9f50eee4050e72a532a0b805531dc72105a4f Mon Sep 17 00:00:00 2001
62f9b7
From: "Richard W.M. Jones" <rjones@redhat.com>
62f9b7
Date: Mon, 1 Jun 2020 17:18:59 +0100
62f9b7
Subject: [PATCH] v2v: nbdkit: Handle password= parameter in common_create.
62f9b7
62f9b7
Just refactoring.
62f9b7
62f9b7
(cherry picked from commit 36c008009a601634ec1c1fbc4f619b21988f075c)
62f9b7
---
62f9b7
 v2v/nbdkit_sources.ml | 42 +++++++++++++++++++-----------------------
62f9b7
 1 file changed, 19 insertions(+), 23 deletions(-)
62f9b7
62f9b7
diff --git a/v2v/nbdkit_sources.ml b/v2v/nbdkit_sources.ml
62f9b7
index bfda91a7..47832011 100644
62f9b7
--- a/v2v/nbdkit_sources.ml
62f9b7
+++ b/v2v/nbdkit_sources.ml
62f9b7
@@ -58,7 +58,8 @@ let error_unless_nbdkit_compiled_with_selinux config =
62f9b7
       error (f_"nbdkit was compiled without SELinux support.  You will have to recompile nbdkit with libselinux-devel installed, or else set SELinux to Permissive mode while doing the conversion.")
62f9b7
   )
62f9b7
 
62f9b7
-let common_create ?bandwidth ?extra_debug ?extra_env plugin_name plugin_args =
62f9b7
+let common_create ?bandwidth ?extra_debug ?extra_env password
62f9b7
+      plugin_name plugin_args =
62f9b7
   error_unless_nbdkit_working ();
62f9b7
   let config = Nbdkit.config () in
62f9b7
   error_unless_nbdkit_min_version config;
62f9b7
@@ -136,6 +137,15 @@ let common_create ?bandwidth ?extra_debug ?extra_env plugin_name plugin_args =
62f9b7
     List.fold_left (fun cmd (k, v) -> Nbdkit.add_arg cmd k v)
62f9b7
       cmd (plugin_args @ rate_args) in
62f9b7
 
62f9b7
+  (* Handle the password parameter specially. *)
62f9b7
+  let cmd =
62f9b7
+    match password with
62f9b7
+    | NoPassword -> cmd
62f9b7
+    | AskForPassword ->
62f9b7
+       Nbdkit.add_arg cmd "password" "-"
62f9b7
+    | PasswordFile password_file ->
62f9b7
+       Nbdkit.add_arg cmd "password" ("+" ^ password_file) in
62f9b7
+
62f9b7
   cmd
62f9b7
 
62f9b7
 (* VDDK libraries are located under lib32/ or lib64/ relative to the
62f9b7
@@ -223,20 +233,16 @@ See also the virt-v2v-input-vmware(1) manual.") libNN
62f9b7
     let get_args () = List.rev !args in
62f9b7
     add_arg, get_args in
62f9b7
 
62f9b7
-  let password_param =
62f9b7
-    match password_file with
62f9b7
-    | None ->
62f9b7
-       (* nbdkit asks for the password interactively *)
62f9b7
-       "password", "-"
62f9b7
-    | Some password_file ->
62f9b7
-       (* nbdkit reads the password from the file *)
62f9b7
-       "password", "+" ^ password_file in
62f9b7
   add_arg ("server", server);
62f9b7
   add_arg ("user", user);
62f9b7
-  add_arg password_param;
62f9b7
   add_arg ("vm", sprintf "moref=%s" moref);
62f9b7
   add_arg ("file", path);
62f9b7
 
62f9b7
+  let password =
62f9b7
+    match password_file with
62f9b7
+    | None -> AskForPassword
62f9b7
+    | Some password_file -> PasswordFile password_file in
62f9b7
+
62f9b7
   (* The passthrough parameters. *)
62f9b7
   Option.may (fun s -> add_arg ("config", s)) config;
62f9b7
   Option.may (fun s -> add_arg ("cookie", s)) cookie;
62f9b7
@@ -251,7 +257,7 @@ See also the virt-v2v-input-vmware(1) manual.") libNN
62f9b7
   let debug_flag =
62f9b7
     if version >= (1, 17, 10) then Some ("vddk.datapath", "0") else None in
62f9b7
 
62f9b7
-  common_create ?bandwidth ?extra_debug:debug_flag ?extra_env:env
62f9b7
+  common_create ?bandwidth ?extra_debug:debug_flag ?extra_env:env password
62f9b7
     "vddk" (get_args ())
62f9b7
 
62f9b7
 (* Create an nbdkit module specialized for reading from SSH sources. *)
62f9b7
@@ -267,14 +273,9 @@ let create_ssh ?bandwidth ~password ?port ~server ?user path =
62f9b7
   add_arg ("host", server);
62f9b7
   Option.may (fun s -> add_arg ("port", s)) port;
62f9b7
   Option.may (fun s -> add_arg ("user", s)) user;
62f9b7
-  (match password with
62f9b7
-   | NoPassword -> ()
62f9b7
-   | AskForPassword -> add_arg ("password", "-")
62f9b7
-   | PasswordFile password_file -> add_arg ("password", "+" ^ password_file)
62f9b7
-  );
62f9b7
   add_arg ("path", path);
62f9b7
 
62f9b7
-  common_create ?bandwidth "ssh" (get_args ())
62f9b7
+  common_create ?bandwidth password "ssh" (get_args ())
62f9b7
 
62f9b7
 (* Create an nbdkit module specialized for reading from Curl sources. *)
62f9b7
 let create_curl ?bandwidth ?cookie ~password ?(sslverify=true) ?user url =
62f9b7
@@ -287,18 +288,13 @@ let create_curl ?bandwidth ?cookie ~password ?(sslverify=true) ?user url =
62f9b7
     add_arg, get_args in
62f9b7
 
62f9b7
   Option.may (fun s -> add_arg ("user", s)) user;
62f9b7
-  (match password with
62f9b7
-   | NoPassword -> ()
62f9b7
-   | AskForPassword -> add_arg ("password", "-")
62f9b7
-   | PasswordFile password_file -> add_arg ("password", "+" ^ password_file)
62f9b7
-  );
62f9b7
   (* https://bugzilla.redhat.com/show_bug.cgi?id=1146007#c10 *)
62f9b7
   add_arg ("timeout", "2000");
62f9b7
   Option.may (fun s -> add_arg ("cookie", s)) cookie;
62f9b7
   if not sslverify then add_arg ("sslverify", "false");
62f9b7
   add_arg ("url", url);
62f9b7
 
62f9b7
-  common_create ?bandwidth "curl" (get_args ())
62f9b7
+  common_create ?bandwidth password "curl" (get_args ())
62f9b7
 
62f9b7
 let run cmd =
62f9b7
   let sock, _ = Nbdkit.run_unix cmd in