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

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