-it ssh: Double quote ssh command which tests remote file exists

resolves: RHEL-12105
This commit is contained in:
Richard W.M. Jones 2023-11-10 15:21:13 +00:00
parent ac1270e705
commit 09f3b77799
10 changed files with 384 additions and 16 deletions

View File

@ -15,20 +15,6 @@ Signed-off-by: Laszlo Ersek <lersek@redhat.com>
1 file changed, 1 insertion(+), 1 deletion(-)
Submodule common 38e6988c..b636c3f2:
diff --git a/common/options/options.h b/common/options/options.h
index 94573ee0..94e8b9ee 100644
--- a/common/options/options.h
+++ b/common/options/options.h
@@ -169,7 +169,8 @@ extern struct matching_key *get_keys (struct key_store *ks, const char *device,
const char *uuid, size_t *nr_matches);
extern void free_keys (struct matching_key *keys, size_t nr_matches);
extern struct key_store *key_store_add_from_selector (struct key_store *ks, const char *selector);
-extern struct key_store *key_store_import_key (struct key_store *ks, const struct key_store_key *key);
+extern struct key_store *key_store_import_key (struct key_store *ks,
+ struct key_store_key *key);
extern bool key_store_requires_network (const struct key_store *ks);
extern void free_key_store (struct key_store *ks);
diff --git a/common/options/keys.c b/common/options/keys.c
index 48f1bc7c..52b27369 100644
--- a/common/options/keys.c
@ -150,3 +136,17 @@ index 48f1bc7c..52b27369 100644
ks->keys[ks->nr_keys] = *key;
++ks->nr_keys;
diff --git a/common/options/options.h b/common/options/options.h
index 94573ee0..94e8b9ee 100644
--- a/common/options/options.h
+++ b/common/options/options.h
@@ -169,7 +169,8 @@ extern struct matching_key *get_keys (struct key_store *ks, const char *device,
const char *uuid, size_t *nr_matches);
extern void free_keys (struct matching_key *keys, size_t nr_matches);
extern struct key_store *key_store_add_from_selector (struct key_store *ks, const char *selector);
-extern struct key_store *key_store_import_key (struct key_store *ks, const struct key_store_key *key);
+extern struct key_store *key_store_import_key (struct key_store *ks,
+ struct key_store_key *key);
extern bool key_store_requires_network (const struct key_store *ks);
extern void free_key_store (struct key_store *ks);

View File

@ -0,0 +1,99 @@
From 35c987dcaaca7eb546ca35875f94623cca68c8b4 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Mon, 25 Sep 2023 14:14:18 +0100
Subject: [PATCH] types: Add gcaps_rtc_utc to record if the RTC is set to UTC
or localtime
Almost every Linux guest expects the motherboard Real Time Clock (RTC)
to be set to UTC and they adjust the time displayed based on their
timezone (which may be different for each user).
Most Windows guests expect the RTC to be set to the local time.
Windows can be configured to use a UTC clock. We can detect this by
looking at the Windows registry.
To cope with this difference we need to add a guestcaps flag based on
what we think the guest is expecting. (We might also use the source
hypervisor RTC setting, but it is not thought to be as reliable as
inspecting the guest.)
This change simply adds the flag to guestcaps, and sets it to always
true, so there is no change to the output.
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
(cherry picked from commit 69d73c251a71586c870bf0cb185107f80caee270)
---
convert/convert_linux.ml | 1 +
convert/convert_windows.ml | 1 +
lib/types.ml | 3 +++
lib/types.mli | 5 +++++
4 files changed, 10 insertions(+)
diff --git a/convert/convert_linux.ml b/convert/convert_linux.ml
index 8d702084..bd54568b 100644
--- a/convert/convert_linux.ml
+++ b/convert/convert_linux.ml
@@ -220,6 +220,7 @@ let convert (g : G.guestfs) source inspect i_firmware _ keep_serial_console _ =
gcaps_arch = Utils.kvm_arch inspect.i_arch;
gcaps_arch_min_version = arch_min_version;
gcaps_virtio_1_0 = virtio_1_0;
+ gcaps_rtc_utc = true; (* almost all Linux expect RTC to be UTC *)
} in
guestcaps
diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml
index 122d9546..7e3aa8d7 100644
--- a/convert/convert_windows.ml
+++ b/convert/convert_windows.ml
@@ -275,6 +275,7 @@ let convert (g : G.guestfs) _ inspect i_firmware block_driver _ static_ips =
gcaps_arch = Utils.kvm_arch inspect.i_arch;
gcaps_arch_min_version = 0;
gcaps_virtio_1_0 = virtio_win_installed.Inject_virtio_win.virtio_1_0;
+ gcaps_rtc_utc = true;
} in
guestcaps
diff --git a/lib/types.ml b/lib/types.ml
index 75c14fd4..d6f9a266 100644
--- a/lib/types.ml
+++ b/lib/types.ml
@@ -399,6 +399,7 @@ type guestcaps = {
gcaps_arch : string;
gcaps_arch_min_version : int;
gcaps_virtio_1_0 : bool;
+ gcaps_rtc_utc : bool;
}
and guestcaps_block_type = Virtio_blk | Virtio_SCSI | IDE
and guestcaps_net_type = Virtio_net | E1000 | RTL8139
@@ -429,6 +430,7 @@ let string_of_guestcaps gcaps =
gcaps_arch = %s\n\
gcaps_arch_min_version = %d\n\
gcaps_virtio_1_0 = %b\n\
+ gcaps_rtc_utc = %b\n\
"
(string_of_block_type gcaps.gcaps_block_bus)
(string_of_net_type gcaps.gcaps_net_bus)
@@ -440,6 +442,7 @@ let string_of_guestcaps gcaps =
gcaps.gcaps_arch
gcaps.gcaps_arch_min_version
gcaps.gcaps_virtio_1_0
+ gcaps.gcaps_rtc_utc
type target_buses = {
target_virtio_blk_bus : target_bus_slot array;
diff --git a/lib/types.mli b/lib/types.mli
index 65ef2e35..3446bb64 100644
--- a/lib/types.mli
+++ b/lib/types.mli
@@ -277,6 +277,11 @@ type guestcaps = {
gcaps_virtio_1_0 : bool;
(** The guest supports the virtio devices that it does at the virtio-1.0
protocol level. *)
+
+ gcaps_rtc_utc : bool;
+ (** Is the RTC set to UTC ([true]) or localtime ([false])? For
+ Linux guests this is always true. For Windows we find out
+ what the guest is expecting by looking at the registry. *)
}
(** Guest capabilities after conversion. eg. Was virtio found or installed? *)

View File

@ -0,0 +1,28 @@
From 6964d1efbea560918c07bf99dcac81549947aadf Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Mon, 25 Sep 2023 14:31:17 +0100
Subject: [PATCH] -o kubevirt: Add comment about future support for clock =
localtime
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
(cherry picked from commit dfb44983a801fb57016298c79db6271262f78455)
---
output/create_kubevirt_yaml.ml | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/output/create_kubevirt_yaml.ml b/output/create_kubevirt_yaml.ml
index 689555e4..e3a3f422 100644
--- a/output/create_kubevirt_yaml.ml
+++ b/output/create_kubevirt_yaml.ml
@@ -54,6 +54,11 @@ let create_kubevirt_yaml source inspect
"pit", Assoc [ "tickPolicy", String "delay" ];
"rtc", Assoc [ "tickPolicy", String "catchup" ];
];
+ (* XXX Note that we may need to set "localtime" here
+ * depending on guestcaps.gcaps_rtc_utc. However that
+ * requires the following PR to be merged in Kubevirt:
+ * https://github.com/kubevirt/kubevirt/pull/9587
+ *)
"utc", List []
]
)

View File

@ -0,0 +1,31 @@
From 3e6b4edc09972f311e2561fbac101f2a23001396 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Mon, 25 Sep 2023 16:58:35 +0100
Subject: [PATCH] output/create_libvirt_xml.ml: Refactor os_section
Minor refactoring of how <os> section is generated in XML output.
There is no change in the output.
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
(cherry picked from commit baaeead927eb72e78c7b09fd285427e9b048ee31)
---
output/create_libvirt_xml.ml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/output/create_libvirt_xml.ml b/output/create_libvirt_xml.ml
index 964acd25..12586fde 100644
--- a/output/create_libvirt_xml.ml
+++ b/output/create_libvirt_xml.ml
@@ -292,10 +292,10 @@ let create_libvirt_xml ?pool source inspect
e "nvram" ["template", vars_template] [] ] in
List.push_back_list os loader;
- !os in
+ e "os" [] !os in
List.push_back_list body [
- e "os" [] os_section;
+ os_section;
e "on_poweroff" [] [PCData "destroy"];
e "on_reboot" [] [PCData "restart"];

View File

@ -0,0 +1,44 @@
From f6b05e26cf6622d1010122b56848511b1ecd660e Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Mon, 25 Sep 2023 14:35:37 +0100
Subject: [PATCH] -o libvirt: Add <clock offset="utc|localtime"/> to libvirt
XML
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
(cherry picked from commit 93b86b8634428c1e3210d10cffa548ee5473418a)
---
output/create_libvirt_xml.ml | 6 ++++++
tests/test-v2v-i-ova.xml | 1 +
2 files changed, 7 insertions(+)
diff --git a/output/create_libvirt_xml.ml b/output/create_libvirt_xml.ml
index 12586fde..30119d13 100644
--- a/output/create_libvirt_xml.ml
+++ b/output/create_libvirt_xml.ml
@@ -294,8 +294,14 @@ let create_libvirt_xml ?pool source inspect
List.push_back_list os loader;
e "os" [] !os in
+ (* The <clock> section. *)
+ let clock_section =
+ let offset = if guestcaps.gcaps_rtc_utc then "utc" else "localtime" in
+ e "clock" [ "offset", offset ] [] in
+
List.push_back_list body [
os_section;
+ clock_section;
e "on_poweroff" [] [PCData "destroy"];
e "on_reboot" [] [PCData "restart"];
diff --git a/tests/test-v2v-i-ova.xml b/tests/test-v2v-i-ova.xml
index e5907ea1..a41827bf 100644
--- a/tests/test-v2v-i-ova.xml
+++ b/tests/test-v2v-i-ova.xml
@@ -18,6 +18,7 @@
<os>
<type arch='x86_64' machine='q35'>hvm</type>
</os>
+ <clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>

View File

@ -0,0 +1,28 @@
From dff314e22ba2d5666ba6a4f3440a7c9e1a658bb3 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Mon, 25 Sep 2023 14:41:58 +0100
Subject: [PATCH] -o qemu: Set -rtc base=localtime when guest expects RTC set
to localtime
I didn't set the -rtc flag in the normal (UTC) case as that is the
default.
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
(cherry picked from commit 482d75bbe5cd242576cf3f8cb9062d13d511871e)
---
output/output_qemu.ml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/output/output_qemu.ml b/output/output_qemu.ml
index ae93fb89..ad3eb897 100644
--- a/output/output_qemu.ml
+++ b/output/output_qemu.ml
@@ -161,6 +161,8 @@ module QEMU = struct
arg_list "-device" ["vmgenid"; sprintf "guid=%s" genid; "id=vmgenid0"]
);
+ if not guestcaps.gcaps_rtc_utc then arg "-rtc" "base=localtime";
+
arg_list "-machine" (machine_str ::
(if smm then ["smm=on"] else []) @
["accel=kvm:tcg"]);

View File

@ -0,0 +1,89 @@
From e7fe97447e5abb1f3343dde1710b0cffdd443e00 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Mon, 25 Sep 2023 15:00:12 +0100
Subject: [PATCH] convert: Find out if Windows guest is expecting RTC set to
UTC
Read HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation key
"RealTimeIsUniversal" to see if the Windows guest is expecting RTC
set to localtime (not present) or UTC (present and set to 1).
See: https://wiki.archlinux.org/title/System_time#UTC_in_Microsoft_Windows
See: https://listman.redhat.com/archives/libguestfs/2023-September/thread.html#32556
Reported-by: Lee Garrett
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
(cherry picked from commit 5f58def90a4485627e8207782165db5a2899b72a)
---
convert/convert_windows.ml | 38 +++++++++++++++++++++++++++++++++++++-
tests/test-v2v-i-ova.xml | 2 +-
2 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml
index 7e3aa8d7..34cf341b 100644
--- a/convert/convert_windows.ml
+++ b/convert/convert_windows.ml
@@ -103,6 +103,42 @@ let convert (g : G.guestfs) _ inspect i_firmware block_driver _ static_ips =
(* If the Windows guest has AV installed. *)
let has_antivirus = Windows.detect_antivirus inspect in
+ (* Does the guest expect the RTC to be set to UTC or localtime?
+ * See https://wiki.archlinux.org/title/System_time#UTC_in_Microsoft_Windows
+ * Note this might be a QWORD on 64 bit Windows instances.
+ *)
+ let rtc_utc =
+ Registry.with_hive_readonly g inspect.i_windows_system_hive
+ (fun reg ->
+ try
+ let key_path = [ "Control"; "TimeZoneInformation" ] in
+ let path = inspect.i_windows_current_control_set :: key_path in
+ let node =
+ match Registry.get_node reg path with
+ | None -> raise Not_found
+ | Some node -> node in
+ let valueh = g#hivex_node_get_value node "RealTimeIsUniversal" in
+ if valueh = 0L then raise Not_found;
+ let t = g#hivex_value_type valueh in
+ let data = g#hivex_value_value valueh in
+ let is_utc =
+ match t with
+ | 0_L (* REG_NONE *) -> false (* localtime *)
+ | 4_L (* REG_DWORD *) -> data = "\001\000\000\000"
+ | 11_L (* REG_QWORD *) -> data = "\001\000\000\000\000\000\000\000"
+ | _ (* who knows ... *) ->
+ warning (f_"unknown CurrentControlSet\\Control\\\
+ TimeZoneInformation key RealTimeIsUniversal \
+ type 0x%Lx, assuming RTC set to UTC") t;
+ true in
+ is_utc
+ with Not_found ->
+ (* If the key is not found then by default we assume
+ * that Windows is expecting the RTC to be set to localtime.
+ *)
+ false
+ ) in
+
(* Open the software hive (readonly) and find the Xen PV uninstaller,
* if it exists.
*)
@@ -275,7 +311,7 @@ let convert (g : G.guestfs) _ inspect i_firmware block_driver _ static_ips =
gcaps_arch = Utils.kvm_arch inspect.i_arch;
gcaps_arch_min_version = 0;
gcaps_virtio_1_0 = virtio_win_installed.Inject_virtio_win.virtio_1_0;
- gcaps_rtc_utc = true;
+ gcaps_rtc_utc = rtc_utc;
} in
guestcaps
diff --git a/tests/test-v2v-i-ova.xml b/tests/test-v2v-i-ova.xml
index a41827bf..fa7b4dbf 100644
--- a/tests/test-v2v-i-ova.xml
+++ b/tests/test-v2v-i-ova.xml
@@ -18,7 +18,7 @@
<os>
<type arch='x86_64' machine='q35'>hvm</type>
</os>
- <clock offset='utc'/>
+ <clock offset='localtime'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>

View File

@ -0,0 +1,38 @@
From 450e6c712b65eed91427fb9ac8c8e19b4e8eb9ad Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Mon, 2 Oct 2023 10:00:10 +0100
Subject: [PATCH] -it ssh: Double quote ssh command which tests remote file
exists
Double quoting was removed in
commit e2af12ba69c4463bb73d30db63290a887cdd41eb ("input: -i vmx:
Remove support for openssh scp < 8.8", Nov 2021). However it should
only have been removed from scp commands, not for this ssh command
where it is still required.
See: https://github.com/libguestfs/virt-v2v/issues/35
Thanks: Laszlo Ersek for diagnosis and suggesting the fix
Reported-by: Bill Sanders
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
(cherry picked from commit 22c5b98ab78c734b478c26e14ee62e2a065aaa0c)
---
input/parse_domain_from_vmx.ml | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/input/parse_domain_from_vmx.ml b/input/parse_domain_from_vmx.ml
index 15ee093f..2e75e785 100644
--- a/input/parse_domain_from_vmx.ml
+++ b/input/parse_domain_from_vmx.ml
@@ -97,7 +97,11 @@ let remote_file_exists uri path =
| None -> ""
| Some user -> quote user ^ "@")
(quote (server_of_uri uri))
- (quote path) in
+ (* Double quoting is necessary for 'ssh', first to protect
+ * from the local shell, second to protect from the remote
+ * shell. https://github.com/libguestfs/virt-v2v/issues/35#issuecomment-1741730963
+ *)
+ (quote (quote path)) in
if verbose () then
eprintf "%s\n%!" cmd;
Sys.command cmd = 0

View File

@ -7,7 +7,7 @@ set -e
# ./copy-patches.sh
project=virt-v2v
rhel_version=9.3
rhel_version=9.4
# Check we're in the right directory.
if [ ! -f $project.spec ]; then

View File

@ -16,7 +16,7 @@
Name: virt-v2v
Epoch: 1
Version: 2.3.4
Release: 5%{?dist}
Release: 6%{?dist}
Summary: Convert a virtual machine to run on KVM
License: GPLv2+
@ -56,6 +56,13 @@ Patch0017: 0017-test-data-phony-guests-fix-prerequisite-list-of-fedo.patch
Patch0018: 0018-lib-utils-fix-typo.patch
Patch0019: 0019-lib-utils-make-chown_for_libvirt_rhbz_1045069-fail-h.patch
Patch0020: 0020-docs-virt-v2v-document-libvirt-system-instance-start.patch
Patch0021: 0021-types-Add-gcaps_rtc_utc-to-record-if-the-RTC-is-set-.patch
Patch0022: 0022-o-kubevirt-Add-comment-about-future-support-for-cloc.patch
Patch0023: 0023-output-create_libvirt_xml.ml-Refactor-os_section.patch
Patch0024: 0024-o-libvirt-Add-clock-offset-utc-localtime-to-libvirt-.patch
Patch0025: 0025-o-qemu-Set-rtc-base-localtime-when-guest-expects-RTC.patch
Patch0026: 0026-convert-Find-out-if-Windows-guest-is-expecting-RTC-s.patch
Patch0027: 0027-it-ssh-Double-quote-ssh-command-which-tests-remote-f.patch
%if !0%{?rhel}
# libguestfs hasn't been built on i686 for a while since there is no
@ -359,6 +366,10 @@ make -C tests TESTS=test-v2v-fedora-luks-on-lvm-conversion.sh check
%changelog
* Fri Nov 10 2023 Richard W.M. Jones <rjones@redhat.com> - 1:2.3.4-6
- -it ssh: Double quote ssh command which tests remote file exists
resolves: RHEL-12105
* Mon Jul 03 2023 Laszlo Ersek <lersek@redhat.com> - 1:2.3.4-5
- improve UX when running as root and we can't chown v2v tmpdir or socks
- make the appliance kernel UP in %check, for working around RHBZ#2216496