Signed-off-by: Matteo Cafasso <noxdafox(a)gmail.com>
---
daemon/sleuthkit.c | 79 ++++++++++++++++++++++++++++------------------------
generator/actions.ml | 6 ++--
2 files changed, 47 insertions(+), 38 deletions(-)
diff --git a/daemon/sleuthkit.c b/daemon/sleuthkit.c
index 0fe1250..536febb 100644
--- a/daemon/sleuthkit.c
+++ b/daemon/sleuthkit.c
@@ -29,55 +29,55 @@
#include "actions.h"
#include "optgroups.h"
-static int file_out (const char *cmd);
+int optgroup_sleuthkit_available(void);
+static int send_command_output(const char *cmd);
-GUESTFSD_EXT_CMD(str_sleuthkit_probe, icat);
+GUESTFSD_EXT_CMD(str_icat, icat);
-int
-optgroup_sleuthkit_available (void)
-{
- return prog_exists (str_sleuthkit_probe);
-}
-
-int
-do_icat (const mountable_t *mountable, int64_t inode)
+/* Has one FileOut parameter. */
+int do_download_inode(const mountable_t *mountable, int64_t inode)
{
CLEANUP_FREE char *cmd = NULL;
/* Inode must be greater than 0 */
if (inode < 0) {
- reply_with_error ("inode must be >= 0");
+ reply_with_error("inode must be >= 0");
+
return -1;
}
/* Construct the command. */
- if (asprintf (&cmd, "icat -r %s %" PRIi64, mountable->device, inode)
== -1) {
- reply_with_perror ("asprintf");
+ if (asprintf(&cmd, "%s -r %s %" PRIi64,
+ str_icat, mountable->device, inode) == -1) {
+ reply_with_perror("asprintf");
+
return -1;
}
- return file_out (cmd);
+ return send_command_output(cmd);
}
-static int
-file_out (const char *cmd)
+/* Runs the given command, collects the output and sends it to the appliance.
+ * Return 0 on success, -1 on error.
+ */
+static int send_command_output(const char *cmd)
{
int r;
FILE *fp;
CLEANUP_FREE char *buffer = NULL;
if (verbose)
- fprintf (stderr, "%s\n", cmd);
+ fprintf(stderr, "%s\n", cmd);
+
+ if (!(buffer = malloc(GUESTFS_MAX_CHUNK_SIZE))) {
+ reply_with_perror("malloc");
- buffer = malloc (GUESTFS_MAX_CHUNK_SIZE);
- if (buffer == NULL) {
- reply_with_perror ("malloc");
return -1;
}
- fp = popen (cmd, "r");
- if (fp == NULL) {
- reply_with_perror ("%s", cmd);
+ if (!(fp = popen(cmd, "r"))) {
+ reply_with_perror("%s", cmd);
+
return -1;
}
@@ -85,30 +85,37 @@ file_out (const char *cmd)
* this there is no opportunity in the protocol to send any error
* message back. Instead we can only cancel the transfer.
*/
- reply (NULL, NULL);
+ reply(NULL, NULL);
+
+ while ((r = fread(buffer, 1, sizeof buffer, fp)) > 0)
+ if (send_file_write(buffer, r) < 0) {
+ pclose(fp);
- while ((r = fread (buffer, 1, sizeof buffer, fp)) > 0) {
- if (send_file_write (buffer, r) < 0) {
- pclose (fp);
return -1;
}
- }
- if (ferror (fp)) {
- fprintf (stderr, "fread: %m");
- send_file_end (1); /* Cancel. */
- pclose (fp);
+ if (ferror(fp)) {
+ fprintf(stderr, "fread: %m");
+ send_file_end(1); /* Cancel. */
+ pclose(fp);
+
return -1;
}
- if (pclose (fp) != 0) {
- fprintf (stderr, "pclose: %m");
- send_file_end (1); /* Cancel. */
+ if (pclose(fp) != 0) {
+ fprintf(stderr, "pclose: %m");
+ send_file_end(1); /* Cancel. */
+
return -1;
}
- if (send_file_end (0)) /* Normal end of file. */
+ if (send_file_end(0)) /* Normal end of file. */
return -1;
return 0;
}
+
+int optgroup_sleuthkit_available(void)
+{
+ return prog_exists(str_icat);
+}
diff --git a/generator/actions.ml b/generator/actions.ml
index ff72cfe..f52db58 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -12946,7 +12946,7 @@ The filesystem from which to extract the file must be unmounted,
otherwise the call will fail." };
{ defaults with
- name = "icat"; added = (1, 33, 14);
+ name = "download_inode"; added = (1, 33, 14);
style = RErr, [Mountable "device"; Int64 "inode"; FileOut
"filename"], [];
proc_nr = Some 464;
optional = Some "sleuthkit";
@@ -12956,7 +12956,9 @@ otherwise the call will fail." };
Download a file given its inode from the disk partition (eg. F</dev/sda1>)
and save it as F<filename> on the local machine.
-This allows to download deleted or inaccessible files." };
+It is not required to mount the disk to run this command.
+
+The command allows is capable of downloading deleted or inaccessible files." };
]
--
2.8.0.rc3