X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Fchecksum.c;h=499d19db9c33857ff74e7c4e9d75dbb1c61a31d9;hp=bdbef13b89a9bf037cad96bc66e5906836a4dcdc;hb=088d0c53cfe0dcb20b87707a9055175b2fd6b72f;hpb=aef3d2013fee188c9607f35657c45df88503cd64 diff --git a/daemon/checksum.c b/daemon/checksum.c index bdbef13..499d19d 100644 --- a/daemon/checksum.c +++ b/daemon/checksum.c @@ -1,5 +1,5 @@ /* libguestfs - the guestfsd daemon - * Copyright (C) 2009 Red Hat Inc. + * Copyright (C) 2009 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,24 +33,22 @@ do_checksum (const char *csumtype, const char *path) const char *program; char *buf; char *out, *err; - int r, len; + 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"); @@ -58,13 +56,11 @@ do_checksum (const char *csumtype, const char *path) } /* Make the path relative to /sysroot. */ - len = strlen (path) + 9; - buf = malloc (len); + buf = sysroot_path (path); if (!buf) { reply_with_perror ("malloc"); return NULL; } - snprintf (buf, len, "/sysroot%s", path); r = command (&out, &err, program, buf, NULL); free (buf);