X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Fchecksum.c;h=13719fd71b6a9e1354fbbe3860a7b3dc6785b303;hp=bd71182a2a6d19e6e01a16b07518f0d7a9f68133;hb=d054dfb2f948f53188f448d2c7fade83db9bbab8;hpb=78029b529ad98769685d607230b70f71832d5906 diff --git a/daemon/checksum.c b/daemon/checksum.c index bd71182..13719fd 100644 --- a/daemon/checksum.c +++ b/daemon/checksum.c @@ -27,46 +27,34 @@ #include "daemon.h" #include "actions.h" -char * -do_checksum (char *csumtype, char *path) +static char * +checksum (const char *csumtype, const char *path) { const char *program; - char *buf; char *out, *err; int r; int len; - NEED_ROOT (NULL); - ABS_PATH (path, NULL); - - if (strcasecmp (csumtype, "crc") == 0) + if (STRCASEEQ (csumtype, "crc")) program = "cksum"; - else if (strcasecmp (csumtype, "md5") == 0) + else if (STRCASEEQ (csumtype, "md5")) program = "md5sum"; - else if (strcasecmp (csumtype, "sha1") == 0) + else if (STRCASEEQ (csumtype, "sha1")) program = "sha1sum"; - else if (strcasecmp (csumtype, "sha224") == 0) + else if (STRCASEEQ (csumtype, "sha224")) program = "sha224sum"; - else if (strcasecmp (csumtype, "sha256") == 0) + else if (STRCASEEQ (csumtype, "sha256")) program = "sha256sum"; - else if (strcasecmp (csumtype, "sha384") == 0) + else if (STRCASEEQ (csumtype, "sha384")) program = "sha384sum"; - else if (strcasecmp (csumtype, "sha512") == 0) + else if (STRCASEEQ (csumtype, "sha512")) program = "sha512sum"; else { reply_with_error ("unknown checksum type, expecting crc|md5|sha1|sha224|sha256|sha384|sha512"); return NULL; } - /* Make the path relative to /sysroot. */ - buf = sysroot_path (path); - if (!buf) { - reply_with_perror ("malloc"); - return NULL; - } - - r = command (&out, &err, program, buf, NULL); - free (buf); + r = command (&out, &err, program, path, NULL); if (r == -1) { reply_with_error ("%s: %s", program, err); free (out); @@ -82,3 +70,24 @@ do_checksum (char *csumtype, char *path) return out; /* Caller frees. */ } + +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"); + return NULL; + } + + char *r = checksum (csumtype, buf); + free (buf); + return r; +} + +char * +do_checksum_device (const char *csumtype, const char *device) +{ + return checksum (csumtype, device); +}