lib, tools, v2v: Use unsafe flag when reading (but NOT writing) hives.

Pass the HIVEX_OPEN_UNSAFE flag when opening hives for reading.
Do NOT pass it when opening hives for writing.

This should make inspection, virt-win-reg and virt-v2v more tolerant
about handling Windows Registry corruption, without increasing the
risk of causing new corruption in hives.
This commit is contained in:
Richard W.M. Jones
2017-02-17 10:17:57 +00:00
parent 1f99251223
commit 8ee7da48c5
4 changed files with 13 additions and 5 deletions

View File

@@ -792,7 +792,9 @@ list_applications_windows (guestfs_h *g, struct inspect_fs *fs)
return NULL;
if (guestfs_hivex_open (g, software_path,
GUESTFS_HIVEX_OPEN_VERBOSE, g->verbose, -1) == -1)
GUESTFS_HIVEX_OPEN_VERBOSE, g->verbose,
GUESTFS_HIVEX_OPEN_UNSAFE, 1,
-1) == -1)
return NULL;
/* Allocate apps list. */

View File

@@ -283,7 +283,9 @@ check_windows_software_registry (guestfs_h *g, struct inspect_fs *fs)
bool ignore_currentversion = false;
if (guestfs_hivex_open (g, software_path,
GUESTFS_HIVEX_OPEN_VERBOSE, g->verbose, -1) == -1)
GUESTFS_HIVEX_OPEN_VERBOSE, g->verbose,
GUESTFS_HIVEX_OPEN_UNSAFE, 1,
-1) == -1)
return -1;
node = guestfs_hivex_root (g);
@@ -405,7 +407,9 @@ check_windows_system_registry (guestfs_h *g, struct inspect_fs *fs)
{ NULL /* current control set */, "Services", "Tcpip", "Parameters" };
if (guestfs_hivex_open (g, system_path,
GUESTFS_HIVEX_OPEN_VERBOSE, g->verbose, -1) == -1)
GUESTFS_HIVEX_OPEN_VERBOSE, g->verbose,
GUESTFS_HIVEX_OPEN_UNSAFE, 1,
-1) == -1)
goto out;
root = guestfs_hivex_root (g);

View File

@@ -335,7 +335,8 @@ if (!$merge) { # Export mode.
download_hive ($hivefile, $hiveshortname);
# Open it.
my $h = Win::Hivex->open ("$tmpdir/$hiveshortname", debug => $debug);
my $h = Win::Hivex->open ("$tmpdir/$hiveshortname",
unsafe => 1, debug => $debug);
unless ($name) {
# Export it.

View File

@@ -49,7 +49,8 @@ and (=~) str rex =
let with_hive_readonly (g : Guestfs.guestfs) hive_filename f =
let verbose = verbose () in
g#hivex_open ~write:false ~verbose (* ~debug:verbose *) hive_filename;
g#hivex_open ~write:false ~unsafe:true ~verbose (* ~debug:verbose *)
hive_filename;
protect ~f:(
fun () ->
let root = g#hivex_root () in