|
|
dd446b |
From 7dbcddd5bd5939493db74843593316f7101f8fde Mon Sep 17 00:00:00 2001
|
|
|
dd446b |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
dd446b |
Date: Thu, 1 Dec 2022 10:00:46 +0000
|
|
|
dd446b |
Subject: [PATCH] New API: inspect_get_build_id
|
|
|
dd446b |
|
|
|
dd446b |
Add an API to return the build ID of the guest. This to allow a
|
|
|
dd446b |
future change to be able to distinguish between Windows 10 and Windows 11
|
|
|
dd446b |
which can only be done using the build ID.
|
|
|
dd446b |
|
|
|
dd446b |
For Windows we can read the CurrentBuildNumber key from the registry.
|
|
|
dd446b |
For Linux there happens to be a BUILD_ID field in /etc/os-release.
|
|
|
dd446b |
I've never seen a Linux distro that actually uses this.
|
|
|
dd446b |
|
|
|
dd446b |
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
dd446b |
(cherry picked from commit f3dd67affe3c657af64ee9f6d70a16e965309556)
|
|
|
dd446b |
---
|
|
|
dd446b |
daemon/inspect.ml | 6 ++++++
|
|
|
dd446b |
daemon/inspect_fs_unix.ml | 2 ++
|
|
|
dd446b |
daemon/inspect_fs_windows.ml | 14 ++++++++++++++
|
|
|
dd446b |
daemon/inspect_types.ml | 5 +++++
|
|
|
dd446b |
daemon/inspect_types.mli | 1 +
|
|
|
dd446b |
generator/actions_inspection.ml | 19 +++++++++++++++++++
|
|
|
dd446b |
generator/proc_nr.ml | 3 ++-
|
|
|
dd446b |
lib/MAX_PROC_NR | 2 +-
|
|
|
dd446b |
8 files changed, 50 insertions(+), 2 deletions(-)
|
|
|
dd446b |
|
|
|
dd446b |
diff --git a/daemon/inspect.ml b/daemon/inspect.ml
|
|
|
dd446b |
index fb75b4a6c..20217c025 100644
|
|
|
dd446b |
--- a/daemon/inspect.ml
|
|
|
dd446b |
+++ b/daemon/inspect.ml
|
|
|
dd446b |
@@ -335,6 +335,12 @@ and inspect_get_hostname root =
|
|
|
dd446b |
| Some v -> v
|
|
|
dd446b |
| None -> "unknown"
|
|
|
dd446b |
|
|
|
dd446b |
+and inspect_get_build_id root =
|
|
|
dd446b |
+ let root = search_for_root root in
|
|
|
dd446b |
+ match root.inspection_data.build_id with
|
|
|
dd446b |
+ | Some v -> v
|
|
|
dd446b |
+ | None -> "unknown"
|
|
|
dd446b |
+
|
|
|
dd446b |
and inspect_get_windows_systemroot root =
|
|
|
dd446b |
let root = search_for_root root in
|
|
|
dd446b |
match root.inspection_data.windows_systemroot with
|
|
|
dd446b |
diff --git a/daemon/inspect_fs_unix.ml b/daemon/inspect_fs_unix.ml
|
|
|
dd446b |
index 63cb279d0..009195f80 100644
|
|
|
dd446b |
--- a/daemon/inspect_fs_unix.ml
|
|
|
dd446b |
+++ b/daemon/inspect_fs_unix.ml
|
|
|
dd446b |
@@ -96,6 +96,8 @@ let rec parse_os_release release_file data =
|
|
|
dd446b |
data.product_name <- Some value
|
|
|
dd446b |
else if key = "VERSION_ID" then
|
|
|
dd446b |
parse_os_release_version_id value data
|
|
|
dd446b |
+ else if key = "BUILD_ID" then
|
|
|
dd446b |
+ data.build_id <- Some value
|
|
|
dd446b |
) values;
|
|
|
dd446b |
|
|
|
dd446b |
(* If we haven't got all the fields, exit right away. *)
|
|
|
dd446b |
diff --git a/daemon/inspect_fs_windows.ml b/daemon/inspect_fs_windows.ml
|
|
|
dd446b |
index c4a05bc38..7bc5de7f7 100644
|
|
|
dd446b |
--- a/daemon/inspect_fs_windows.ml
|
|
|
dd446b |
+++ b/daemon/inspect_fs_windows.ml
|
|
|
dd446b |
@@ -263,6 +263,20 @@ and check_windows_software_registry software_hive data =
|
|
|
dd446b |
with
|
|
|
dd446b |
Not_found -> ()
|
|
|
dd446b |
);
|
|
|
dd446b |
+
|
|
|
dd446b |
+ (* CurrentBuildNumber (build_id).
|
|
|
dd446b |
+ *
|
|
|
dd446b |
+ * In modern Windows, the "CurrentBuild" and "CurrentBuildNumber"
|
|
|
dd446b |
+ * keys are the same. But in Windows XP, "CurrentBuild"
|
|
|
dd446b |
+ * contained something quite different. So always use
|
|
|
dd446b |
+ * "CurrentBuildNumber".
|
|
|
dd446b |
+ *)
|
|
|
dd446b |
+ (try
|
|
|
dd446b |
+ let v = List.assoc "CurrentBuildNumber" values in
|
|
|
dd446b |
+ data.build_id <- Some (Hivex.value_string h v)
|
|
|
dd446b |
+ with
|
|
|
dd446b |
+ Not_found -> ()
|
|
|
dd446b |
+ );
|
|
|
dd446b |
with
|
|
|
dd446b |
| Not_found ->
|
|
|
dd446b |
if verbose () then
|
|
|
dd446b |
diff --git a/daemon/inspect_types.ml b/daemon/inspect_types.ml
|
|
|
dd446b |
index 9395c51f9..328a2146b 100644
|
|
|
dd446b |
--- a/daemon/inspect_types.ml
|
|
|
dd446b |
+++ b/daemon/inspect_types.ml
|
|
|
dd446b |
@@ -48,6 +48,7 @@ and inspection_data = {
|
|
|
dd446b |
mutable version : version option;
|
|
|
dd446b |
mutable arch : string option;
|
|
|
dd446b |
mutable hostname : string option;
|
|
|
dd446b |
+ mutable build_id : string option;
|
|
|
dd446b |
mutable fstab : fstab_entry list;
|
|
|
dd446b |
mutable windows_systemroot : string option;
|
|
|
dd446b |
mutable windows_software_hive : string option;
|
|
|
dd446b |
@@ -167,6 +168,8 @@ and string_of_inspection_data data =
|
|
|
dd446b |
data.arch;
|
|
|
dd446b |
Option.may (fun v -> bpf " hostname: %s\n" v)
|
|
|
dd446b |
data.hostname;
|
|
|
dd446b |
+ Option.may (fun v -> bpf " build ID: %s\n" v)
|
|
|
dd446b |
+ data.build_id;
|
|
|
dd446b |
if data.fstab <> [] then (
|
|
|
dd446b |
let v = List.map (
|
|
|
dd446b |
fun (a, b) -> sprintf "(%s, %s)" (Mountable.to_string a) b
|
|
|
dd446b |
@@ -272,6 +275,7 @@ let null_inspection_data = {
|
|
|
dd446b |
version = None;
|
|
|
dd446b |
arch = None;
|
|
|
dd446b |
hostname = None;
|
|
|
dd446b |
+ build_id = None;
|
|
|
dd446b |
fstab = [];
|
|
|
dd446b |
windows_systemroot = None;
|
|
|
dd446b |
windows_software_hive = None;
|
|
|
dd446b |
@@ -294,6 +298,7 @@ let merge_inspection_data child parent =
|
|
|
dd446b |
parent.version <- merge child.version parent.version;
|
|
|
dd446b |
parent.arch <- merge child.arch parent.arch;
|
|
|
dd446b |
parent.hostname <- merge child.hostname parent.hostname;
|
|
|
dd446b |
+ parent.build_id <- merge child.build_id parent.build_id;
|
|
|
dd446b |
parent.fstab <- child.fstab @ parent.fstab;
|
|
|
dd446b |
parent.windows_systemroot <-
|
|
|
dd446b |
merge child.windows_systemroot parent.windows_systemroot;
|
|
|
dd446b |
diff --git a/daemon/inspect_types.mli b/daemon/inspect_types.mli
|
|
|
dd446b |
index 29c76e8ab..05a3ffd4e 100644
|
|
|
dd446b |
--- a/daemon/inspect_types.mli
|
|
|
dd446b |
+++ b/daemon/inspect_types.mli
|
|
|
dd446b |
@@ -51,6 +51,7 @@ and inspection_data = {
|
|
|
dd446b |
mutable version : version option;
|
|
|
dd446b |
mutable arch : string option;
|
|
|
dd446b |
mutable hostname : string option;
|
|
|
dd446b |
+ mutable build_id : string option;
|
|
|
dd446b |
mutable fstab : fstab_entry list;
|
|
|
dd446b |
mutable windows_systemroot : string option;
|
|
|
dd446b |
mutable windows_software_hive : string option;
|
|
|
dd446b |
diff --git a/generator/actions_inspection.ml b/generator/actions_inspection.ml
|
|
|
dd446b |
index f8b744993..70de22ec0 100644
|
|
|
dd446b |
--- a/generator/actions_inspection.ml
|
|
|
dd446b |
+++ b/generator/actions_inspection.ml
|
|
|
dd446b |
@@ -529,6 +529,25 @@ hive is a valid Windows Registry hive.
|
|
|
dd446b |
|
|
|
dd446b |
You can use C<guestfs_hivex_open> to read or write to the hive.
|
|
|
dd446b |
|
|
|
dd446b |
+Please read L<guestfs(3)/INSPECTION> for more details." };
|
|
|
dd446b |
+
|
|
|
dd446b |
+ { defaults with
|
|
|
dd446b |
+ name = "inspect_get_build_id"; added = (1, 49, 8);
|
|
|
dd446b |
+ style = RString (RPlainString, "buildid"), [String (Mountable, "root")], [];
|
|
|
dd446b |
+ impl = OCaml "Inspect.inspect_get_build_id";
|
|
|
dd446b |
+ shortdesc = "get the system build ID";
|
|
|
dd446b |
+ longdesc = "\
|
|
|
dd446b |
+This returns the build ID of the system, or the string
|
|
|
dd446b |
+C<\"unknown\"> if the system does not have a build ID.
|
|
|
dd446b |
+
|
|
|
dd446b |
+For Windows, this gets the build number. Although it is
|
|
|
dd446b |
+returned as a string, it is (so far) always a number. See
|
|
|
dd446b |
+L<https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions>
|
|
|
dd446b |
+for some possible values.
|
|
|
dd446b |
+
|
|
|
dd446b |
+For Linux, this returns the C<BUILD_ID> string from
|
|
|
dd446b |
+F</etc/os-release>, although this is not often used.
|
|
|
dd446b |
+
|
|
|
dd446b |
Please read L<guestfs(3)/INSPECTION> for more details." };
|
|
|
dd446b |
|
|
|
dd446b |
{ defaults with
|
|
|
dd446b |
diff --git a/generator/proc_nr.ml b/generator/proc_nr.ml
|
|
|
dd446b |
index edd9bd99d..0f17b1c06 100644
|
|
|
dd446b |
--- a/generator/proc_nr.ml
|
|
|
dd446b |
+++ b/generator/proc_nr.ml
|
|
|
dd446b |
@@ -514,7 +514,8 @@ let proc_nr = [
|
|
|
dd446b |
509, "cryptsetup_close";
|
|
|
dd446b |
510, "internal_list_rpm_applications";
|
|
|
dd446b |
511, "internal_readdir";
|
|
|
dd446b |
-512, "clevis_luks_unlock"
|
|
|
dd446b |
+512, "clevis_luks_unlock";
|
|
|
dd446b |
+513, "inspect_get_build_id";
|
|
|
dd446b |
]
|
|
|
dd446b |
|
|
|
dd446b |
(* End of list. If adding a new entry, add it at the end of the list
|
|
|
dd446b |
diff --git a/lib/MAX_PROC_NR b/lib/MAX_PROC_NR
|
|
|
dd446b |
index 4d0e90cbc..31cf34b8d 100644
|
|
|
dd446b |
--- a/lib/MAX_PROC_NR
|
|
|
dd446b |
+++ b/lib/MAX_PROC_NR
|
|
|
dd446b |
@@ -1 +1 @@
|
|
|
dd446b |
-512
|
|
|
dd446b |
+513
|
|
|
dd446b |
--
|
|
|
dd446b |
2.31.1
|
|
|
dd446b |
|