X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=daemon%2Fchecksum.c;h=8533ccc324e0d80b32a66f44b2925ac12b3814ed;hb=ab7f296b63280d183b6574c896cab6d6cafb660a;hp=c06a697dfb5e900264c9860308ac8dee2582658f;hpb=6bda071b5cd8393b37653687027c4ae6c6cf3804;p=libguestfs.git diff --git a/daemon/checksum.c b/daemon/checksum.c index c06a697..8533ccc 100644 --- a/daemon/checksum.c +++ b/daemon/checksum.c @@ -27,8 +27,31 @@ #include "daemon.h" #include "actions.h" +static const char * +program_of_csum (const char *csumtype) +{ + if (STRCASEEQ (csumtype, "crc")) + return "cksum"; + else if (STRCASEEQ (csumtype, "md5")) + return "md5sum"; + else if (STRCASEEQ (csumtype, "sha1")) + return "sha1sum"; + else if (STRCASEEQ (csumtype, "sha224")) + return "sha224sum"; + else if (STRCASEEQ (csumtype, "sha256")) + return "sha256sum"; + else if (STRCASEEQ (csumtype, "sha384")) + return "sha384sum"; + else if (STRCASEEQ (csumtype, "sha512")) + return "sha512sum"; + else { + reply_with_error ("unknown checksum type, expecting crc|md5|sha1|sha224|sha256|sha384|sha512"); + return NULL; + } +} + char * -do_checksum (char *csumtype, char *path) +do_checksum (const char *csumtype, const char *path) { const char *program; char *buf; @@ -36,27 +59,9 @@ do_checksum (char *csumtype, char *path) int r; int len; - NEED_ROOT (return NULL); - ABS_PATH (path, return NULL); - - if (strcasecmp (csumtype, "crc") == 0) - program = "cksum"; - else if (strcasecmp (csumtype, "md5") == 0) - program = "md5sum"; - else if (strcasecmp (csumtype, "sha1") == 0) - program = "sha1sum"; - else if (strcasecmp (csumtype, "sha224") == 0) - program = "sha224sum"; - else if (strcasecmp (csumtype, "sha256") == 0) - program = "sha256sum"; - else if (strcasecmp (csumtype, "sha384") == 0) - program = "sha384sum"; - else if (strcasecmp (csumtype, "sha512") == 0) - program = "sha512sum"; - else { - reply_with_error ("unknown checksum type, expecting crc|md5|sha1|sha224|sha256|sha384|sha512"); + program = program_of_csum (csumtype); + if (program == NULL) return NULL; - } /* Make the path relative to /sysroot. */ buf = sysroot_path (path);