daemon: Fix checksum to work on absolute symbolic links (RHBZ#579608).
authorRichard Jones <rjones@redhat.com>
Thu, 6 May 2010 23:11:22 +0000 (00:11 +0100)
committerRichard Jones <rjones@redhat.com>
Fri, 7 May 2010 14:27:28 +0000 (15:27 +0100)
daemon/checksum.c
src/generator.ml

index f7e2d12..e12a8a8 100644 (file)
@@ -22,6 +22,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <fcntl.h>
 #include <sys/stat.h>
 
 #include "../src/guestfs_protocol.h"
 #include <sys/stat.h>
 
 #include "../src/guestfs_protocol.h"
@@ -52,18 +53,19 @@ program_of_csum (const char *csumtype)
 }
 
 static char *
 }
 
 static char *
-checksum (const char *csumtype, const char *path)
+checksum (const char *csumtype, int fd)
 {
   const char *program;
   char *out, *err;
 {
   const char *program;
   char *out, *err;
-  int r;
+  int flags, r;
   int len;
 
   program = program_of_csum (csumtype);
   if (program == NULL)
     return NULL;
 
   int len;
 
   program = program_of_csum (csumtype);
   if (program == NULL)
     return NULL;
 
-  r = command (&out, &err, program, path, NULL);
+  flags = COMMAND_FLAG_CHROOT_COPY_FILE_TO_STDIN | fd;
+  r = commandf (&out, &err, flags, program, NULL);
   if (r == -1) {
     reply_with_error ("%s: %s", program, err);
     free (out);
   if (r == -1) {
     reply_with_error ("%s: %s", program, err);
     free (out);
@@ -83,22 +85,32 @@ checksum (const char *csumtype, const char *path)
 char *
 do_checksum (const char *csumtype, const char *path)
 {
 char *
 do_checksum (const char *csumtype, const char *path)
 {
-  /* Make the path relative to /sysroot. */
-  char *buf = sysroot_path (path);
-  if (!buf) {
-    reply_with_perror ("malloc");
+  int fd;
+
+  CHROOT_IN;
+  fd = open (path, O_RDONLY);
+  CHROOT_OUT;
+
+  if (fd == -1) {
+    reply_with_perror ("%s", path);
     return NULL;
   }
 
     return NULL;
   }
 
-  char *r = checksum (csumtype, buf);
-  free (buf);
-  return r;
+  return checksum (csumtype, fd);
 }
 
 char *
 do_checksum_device (const char *csumtype, const char *device)
 {
 }
 
 char *
 do_checksum_device (const char *csumtype, const char *device)
 {
-  return checksum (csumtype, device);
+  int fd;
+
+  fd = open (device, O_RDONLY);
+  if (fd == -1) {
+    reply_with_perror ("%s", device);
+    return NULL;
+  }
+
+  return checksum (csumtype, fd);
 }
 
 /* Has one FileOut parameter. */
 }
 
 /* Has one FileOut parameter. */
index 5b479e7..9112a48 100755 (executable)
@@ -1991,7 +1991,10 @@ See also C<guestfs_upload>, C<guestfs_cat>.");
     InitISOFS, Always, TestOutput (
       [["checksum"; "sha384"; "/known-3"]], "5fa7883430f357b5d7b7271d3a1d2872b51d73cba72731de6863d3dea55f30646af2799bef44d5ea776a5ec7941ac640");
     InitISOFS, Always, TestOutput (
     InitISOFS, Always, TestOutput (
       [["checksum"; "sha384"; "/known-3"]], "5fa7883430f357b5d7b7271d3a1d2872b51d73cba72731de6863d3dea55f30646af2799bef44d5ea776a5ec7941ac640");
     InitISOFS, Always, TestOutput (
-      [["checksum"; "sha512"; "/known-3"]], "2794062c328c6b216dca90443b7f7134c5f40e56bd0ed7853123275a09982a6f992e6ca682f9d2fba34a4c5e870d8fe077694ff831e3032a004ee077e00603f6")],
+      [["checksum"; "sha512"; "/known-3"]], "2794062c328c6b216dca90443b7f7134c5f40e56bd0ed7853123275a09982a6f992e6ca682f9d2fba34a4c5e870d8fe077694ff831e3032a004ee077e00603f6");
+    (* Test for RHBZ#579608, absolute symbolic links. *)
+    InitISOFS, Always, TestOutput (
+      [["checksum"; "sha512"; "/abssymlink"]], "5f57d0639bc95081c53afc63a449403883818edc64da48930ad6b1a4fb49be90404686877743fbcd7c99811f3def7df7bc22635c885c6a8cf79c806b43451c1a")],
    "compute MD5, SHAx or CRC checksum of file",
    "\
 This call computes the MD5, SHAx or CRC checksum of the
    "compute MD5, SHAx or CRC checksum of file",
    "\
 This call computes the MD5, SHAx or CRC checksum of the