[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libguestfs] [PATCH 3/3] hivex: Replace non-portable ENOKEY constant



On Fri, May 13, 2011 at 01:33:17PM +0200, Hilko Bengen wrote:
> * Richard W.M. Jones:
> 
> > Unfortunately this is documented in the API and therefore can't
> > be changed.
> 
> Do you mean that my patch was incomplete because I did not also change
> the documentation? Or do you mean that it can't be changed at all?

It means we're really serious about full ABI and source compatibility.
That means we can't ever break programs that wrote:

  if (hivex_root (h) == 0 && errno == ENOKEY) {
    //... do something based on no root key
  }

> > A bigger problem is that some platforms lack ENOKEY (it's not defined
> > by POSIX).  I think Mac OS X was one.  However that's a separate
> > problem for those platforms.
> 
> Apparently, ENOKEY is not defined on FreeBSD either. Debian's
> kfreebsd-*[1][2] and hurd-i386[3] autobuilders refused to build because
> of this. And it was mentioned on this list that Cygwin doesn't define
> ENOKEY, either.
> 
> If hivex can't be used on MacOSX and Cygwin without patches, this is
> going to be a pity for those users who want to use it for computer
> forensics purposes.

It can be used, just some has to fix it.  Luckily I've done that.  See
the attached patch.

This maintains binary compatibility with existing platforms (or should
do assuming I didn't make any mistake).

Note that after applying the patch you will need to rerun the
generator by hand:

  ./generator/generator.ml

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top
>From ebd2ff37a9eba9412456c42398f64a3cb107b79c Mon Sep 17 00:00:00 2001
From: Richard W.M. Jones <rjones redhat com>
Date: Fri, 13 May 2011 18:19:22 +0100
Subject: [PATCH] hivex_root: Return errno == HIVEX_NO_KEY when root key is
 missing.

Previously we returned errno == ENOKEY.  However this was an
unfortunate choice of error code since it is not defined in POSIX.  As
a result it is missing on several platforms.

HIVEX_NO_KEY is defined as ENOKEY on platforms where this symbol
exists (thus maintaining backwards ABI compatibility), and defined as
another POSIX error code otherwise.
---
 generator/generator.ml |    9 ++++++++-
 lib/hivex.c            |    2 +-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/generator/generator.ml b/generator/generator.ml
index 9722312..117781a 100755
--- a/generator/generator.ml
+++ b/generator/generator.ml
@@ -701,6 +701,13 @@ typedef struct hive_h hive_h;
 typedef size_t hive_node_h;
 typedef size_t hive_value_h;
 
+#include <errno.h>
+#ifdef ENOKEY
+# define HIVEX_NO_KEY ENOKEY
+#else
+# define HIVEX_NO_KEY ENOENT
+#endif
+
 /* Pre-defined types. */
 enum hive_type {
 ";
@@ -1273,7 +1280,7 @@ exhaustive):
 
 Corrupt or unsupported Registry file format.
 
-=item ENOKEY
+=item HIVEX_NO_KEY
 
 Missing root key.
 
diff --git a/lib/hivex.c b/lib/hivex.c
index 7715520..d042f4f 100644
--- a/lib/hivex.c
+++ b/lib/hivex.c
@@ -559,7 +559,7 @@ hivex_root (hive_h *h)
 {
   hive_node_h ret = h->rootoffs;
   if (!IS_VALID_BLOCK (h, ret)) {
-    errno = ENOKEY;
+    errno = HIVEX_NO_KEY;
     return 0;
   }
   return ret;
-- 
1.7.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]