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.
This commit is contained in:
Richard W.M. Jones
2017-02-17 10:08:34 +00:00
parent ad3c8fe7f4
commit 1f99251223
2 changed files with 12 additions and 5 deletions

View File

@@ -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) {

View File

@@ -11228,13 +11228,13 @@ C<guestfs_xfs_growfs> 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<guestfs_hivex_value_utf8>." };
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"]]
];