1 /* libguestfs - the guestfsd daemon
2 * Copyright (C) 2009 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include "../src/guestfs_protocol.h"
31 program_of_csum (const char *csumtype)
33 if (STRCASEEQ (csumtype, "crc"))
35 else if (STRCASEEQ (csumtype, "md5"))
37 else if (STRCASEEQ (csumtype, "sha1"))
39 else if (STRCASEEQ (csumtype, "sha224"))
41 else if (STRCASEEQ (csumtype, "sha256"))
43 else if (STRCASEEQ (csumtype, "sha384"))
45 else if (STRCASEEQ (csumtype, "sha512"))
48 reply_with_error ("unknown checksum type, expecting crc|md5|sha1|sha224|sha256|sha384|sha512");
54 do_checksum (const char *csumtype, const char *path)
62 program = program_of_csum (csumtype);
66 /* Make the path relative to /sysroot. */
67 buf = sysroot_path (path);
69 reply_with_perror ("malloc");
73 r = command (&out, &err, program, buf, NULL);
76 reply_with_error ("%s: %s", program, err);
84 /* Split it at the first whitespace. */
85 len = strcspn (out, " \t\n");
88 return out; /* Caller frees. */