Version 0.1.2.
[guestfs-browser.git] / slave.ml
index 880a2b1..e27ced7 100644 (file)
--- a/slave.ml
+++ b/slave.ml
@@ -65,6 +65,11 @@ and inspection_os = {
   insp_product_name : string;
   insp_type : string;
   insp_windows_systemroot : string option;
+  insp_winreg_DEFAULT : string option;
+  insp_winreg_SAM : string option;
+  insp_winreg_SECURITY : string option;
+  insp_winreg_SOFTWARE : string option;
+  insp_winreg_SYSTEM : string option;
 }
 
 and source = OS of inspection_os | Volume of string
@@ -515,24 +520,72 @@ and open_disk_images images cb =
         [] in
 
   let oses = List.map (
-    fun root -> {
-      insp_root = root;
-      insp_arch = g#inspect_get_arch root;
-      insp_distro = g#inspect_get_distro root;
-      insp_filesystems = g#inspect_get_filesystems root;
-      insp_hostname = g#inspect_get_hostname root;
-      insp_major_version = g#inspect_get_major_version root;
-      insp_minor_version = g#inspect_get_minor_version root;
-      insp_mountpoints = g#inspect_get_mountpoints root;
-      insp_package_format = g#inspect_get_package_format root;
-      insp_package_management = g#inspect_get_package_management root;
-      insp_product_name = g#inspect_get_product_name root;
-      insp_type = g#inspect_get_type root;
-      insp_windows_systemroot =
-        try Some (g#inspect_get_windows_systemroot root)
-        with Guestfs.Error _ -> None
-    }
+    fun root ->
+      let typ = g#inspect_get_type root in
+      let windows_systemroot =
+        if typ <> "windows" then None
+        else (
+          try Some (g#inspect_get_windows_systemroot root)
+          with Guestfs.Error _ -> None
+        ) in
+
+      (* Create most of the OS object that we're going to return.  We
+       * have to pass this to with_mount_ro below which is why we need
+       * to partially create it here.
+       *)
+      let os = {
+        insp_root = root;
+        insp_arch = g#inspect_get_arch root;
+        insp_distro = g#inspect_get_distro root;
+        insp_filesystems = g#inspect_get_filesystems root;
+        insp_hostname = g#inspect_get_hostname root;
+        insp_major_version = g#inspect_get_major_version root;
+        insp_minor_version = g#inspect_get_minor_version root;
+        insp_mountpoints = g#inspect_get_mountpoints root;
+        insp_package_format = g#inspect_get_package_format root;
+        insp_package_management = g#inspect_get_package_management root;
+        insp_product_name = g#inspect_get_product_name root;
+        insp_type = typ;
+        insp_windows_systemroot = windows_systemroot;
+        insp_winreg_DEFAULT = None; (* incomplete, see below *)
+        insp_winreg_SAM = None;
+        insp_winreg_SECURITY = None;
+        insp_winreg_SOFTWARE = None;
+        insp_winreg_SYSTEM = None;
+      } in
+
+      (* We need to mount the root in order to look for Registry hives. *)
+      let winreg_DEFAULT, winreg_SAM, winreg_SECURITY, winreg_SOFTWARE,
+        winreg_SYSTEM =
+        match windows_systemroot with
+        | None -> None, None, None, None, None
+        | Some sysroot ->
+            with_mount_ro g (OS os) (
+              fun () ->
+                let check_for_hive filename =
+                  let path =
+                    sprintf "%s/system32/config/%s" sysroot filename in
+                  try Some (g#case_sensitive_path path)
+                  with Guestfs.Error _ -> None
+                in
+                check_for_hive "default",
+                check_for_hive "sam",
+                check_for_hive "security",
+                check_for_hive "software",
+                check_for_hive "system"
+            ) in
+
+      (* Fill in the remaining struct fields. *)
+      let os = { os with
+                   insp_winreg_DEFAULT = winreg_DEFAULT;
+                   insp_winreg_SAM = winreg_SAM;
+                   insp_winreg_SECURITY = winreg_SECURITY;
+                   insp_winreg_SOFTWARE = winreg_SOFTWARE;
+                   insp_winreg_SYSTEM = winreg_SYSTEM
+               } in
+      os
   ) roots in
+
   let data = {
     insp_all_filesystems = fses;
     insp_oses = oses;