From 1f99251223ccee252ee1259bc2bdb9b64e3df96b Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Fri, 17 Feb 2017 10:08:34 +0000 Subject: [PATCH] hivex: Map new HIVEX_OPEN_UNSAFE flag into the API. In hivex >= 1.3.14, there is a new HIVEX_OPEN_UNSAFE flag allowing heuristics to be used to deal with corrupted hives. Map this flag into the libguestfs API. If the flag is not supported (because libguestfs was compiled with hivex < 1.3.14) then the flag is ignored. This is safe behaviour: opening corrupted hives will give an error, as happened previously. --- daemon/hivex.c | 9 ++++++++- generator/actions.ml | 8 ++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/daemon/hivex.c b/daemon/hivex.c index b47329ecf..95ed7dd28 100644 --- a/daemon/hivex.c +++ b/daemon/hivex.c @@ -68,7 +68,8 @@ hivex_finalize (void) /* Takes optional arguments, consult optargs_bitmask. */ int -do_hivex_open (const char *filename, int verbose, int debug, int write) +do_hivex_open (const char *filename, + int verbose, int debug, int write, int unsafe) { CLEANUP_FREE char *buf = NULL; int flags = 0; @@ -96,6 +97,12 @@ do_hivex_open (const char *filename, int verbose, int debug, int write) if (write) flags |= HIVEX_OPEN_WRITE; } +#ifdef HIVEX_OPEN_UNSAFE + if (optargs_bitmask & GUESTFS_HIVEX_OPEN_UNSAFE_BITMASK) { + if (unsafe) + flags |= HIVEX_OPEN_UNSAFE; + } +#endif h = hivex_open (buf, flags); if (!h) { diff --git a/generator/actions.ml b/generator/actions.ml index ed0e8cc25..67db08c31 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -11228,13 +11228,13 @@ C calls." }; { defaults with name = "hivex_open"; added = (1, 19, 35); - style = RErr, [Pathname "filename"], [OBool "verbose"; OBool "debug"; OBool "write"]; + style = RErr, [Pathname "filename"], [OBool "verbose"; OBool "debug"; OBool "write"; OBool "unsafe"]; proc_nr = Some 350; optional = Some "hivex"; tests = [ InitScratchFS, Always, TestRun ( [["upload"; "$srcdir/../../test-data/files/minimal"; "/hivex_open"]; - ["hivex_open"; "/hivex_open"; ""; ""; "false"]; + ["hivex_open"; "/hivex_open"; ""; ""; "false"; ""]; ["hivex_root"]; (* in this hive, it returns 0x1020 *) ["hivex_node_name"; "0x1020"]; ["hivex_node_children"; "0x1020"]; @@ -11382,11 +11382,11 @@ See also: C." }; tests = [ InitScratchFS, Always, TestRun ( [["upload"; "$srcdir/../../test-data/files/minimal"; "/hivex_commit1"]; - ["hivex_open"; "/hivex_commit1"; ""; ""; "true"]; + ["hivex_open"; "/hivex_commit1"; ""; ""; "true"; ""]; ["hivex_commit"; "NULL"]]), [["hivex_close"]]; InitScratchFS, Always, TestResultTrue ( [["upload"; "$srcdir/../../test-data/files/minimal"; "/hivex_commit2"]; - ["hivex_open"; "/hivex_commit2"; ""; ""; "true"]; + ["hivex_open"; "/hivex_commit2"; ""; ""; "true"; ""]; ["hivex_commit"; "/hivex_commit2_copy"]; ["is_file"; "/hivex_commit2_copy"; "false"]]), [["hivex_close"]] ];