Blame SOURCES/0028-v2v-Replace-broken-VMware-Tools-uninstall-command-ms.patch

7ed5e3
From 2bf5fc815d53e581398e787ae96444c438945ab3 Mon Sep 17 00:00:00 2001
7ed5e3
From: "Richard W.M. Jones" <rjones@redhat.com>
7ed5e3
Date: Tue, 19 Jan 2021 12:17:49 +0000
7ed5e3
Subject: [PATCH] v2v: Replace broken VMware Tools uninstall command msiexec /i
7ed5e3
 with /x.
7ed5e3
7ed5e3
Fixes: https://bugzilla.redhat.com/1917760
7ed5e3
Thanks: Chetan Nagarkar
7ed5e3
(cherry picked from commit f7496b0a7e76a06bda8d7ec1aba36741f8cb295c)
7ed5e3
---
7ed5e3
 v2v/convert_windows.ml | 15 ++++++++++++---
7ed5e3
 1 file changed, 12 insertions(+), 3 deletions(-)
7ed5e3
7ed5e3
diff --git a/v2v/convert_windows.ml b/v2v/convert_windows.ml
7ed5e3
index 84db742f..44cef5ed 100644
7ed5e3
--- a/v2v/convert_windows.ml
7ed5e3
+++ b/v2v/convert_windows.ml
7ed5e3
@@ -135,7 +135,7 @@ let convert (g : G.guestfs) inspect _ output rcaps static_ips =
7ed5e3
   (* Locate and retrieve all the uninstallation commands for installed
7ed5e3
    * applications.
7ed5e3
    *)
7ed5e3
-  let uninstallation_commands pretty_name matchfn extra_uninstall_params =
7ed5e3
+  let uninstallation_commands pretty_name matchfn modfn extra_uninstall_params =
7ed5e3
     let path = ["Microsoft"; "Windows"; "CurrentVersion"; "Uninstall"] in
7ed5e3
     let uninstval = "UninstallString" in
7ed5e3
     let ret = ref [] in
7ed5e3
@@ -155,6 +155,7 @@ let convert (g : G.guestfs) inspect _ output rcaps static_ips =
7ed5e3
                    let valueh = g#hivex_node_get_value uninstnode uninstval in
7ed5e3
                    if valueh <> 0L then (
7ed5e3
                      let reg_cmd = g#hivex_value_string valueh in
7ed5e3
+                     let reg_cmd = modfn reg_cmd in
7ed5e3
                      let cmd =
7ed5e3
                        sprintf "%s /quiet /norestart /l*v+ \"%%~dpn0.log\" REBOOT=ReallySuppress REMOVE=ALL %s"
7ed5e3
                          reg_cmd extra_uninstall_params in
7ed5e3
@@ -183,14 +184,22 @@ let convert (g : G.guestfs) inspect _ output rcaps static_ips =
7ed5e3
      *)
7ed5e3
     let extra_uninstall_params =
7ed5e3
       "PREVENT_REBOOT=Yes LAUNCHED_BY_SETUP_EXE=Yes" in
7ed5e3
-    uninstallation_commands "Parallels Tools" matchfn extra_uninstall_params in
7ed5e3
+    uninstallation_commands "Parallels Tools" matchfn identity
7ed5e3
+      extra_uninstall_params in
7ed5e3
 
7ed5e3
   (* Locate and retrieve all uninstallation commands for VMware Tools. *)
7ed5e3
   let vmwaretools_uninst =
7ed5e3
     let matchfn s =
7ed5e3
       String.find s "VMware Tools" != -1
7ed5e3
     in
7ed5e3
-    uninstallation_commands "VMware Tools" matchfn "" in
7ed5e3
+    (* VMware Tools writes the install command (MsiExec /I) into the
7ed5e3
+     * UninstallString key in the registry, rather than the uninstall
7ed5e3
+     * command.  Try to spot this and rewrite.  (RHBZ#1917760).
7ed5e3
+     *)
7ed5e3
+    let re1 = PCRE.compile ~caseless:true "msiexec" in
7ed5e3
+    let re2 = PCRE.compile ~caseless:true "/i" in
7ed5e3
+    let msifn s = if PCRE.matches re1 s then PCRE.replace re2 "/x" s else s in
7ed5e3
+    uninstallation_commands "VMware Tools" matchfn msifn "" in
7ed5e3
 
7ed5e3
   (*----------------------------------------------------------------------*)
7ed5e3
   (* Perform the conversion of the Windows guest. *)
7ed5e3
-- 
446330
2.27.0
7ed5e3