From 3aed2661030daf5ee04566d5ebc41a354926f62d Mon Sep 17 00:00:00 2001 From: Tom Cort Date: Wed, 28 Nov 2007 13:39:25 -0500 Subject: [PATCH] Add virus_removal_enabled config option. --- config.cxx | 4 ++++ inoclam.cxx | 2 ++ inotify.cxx | 28 +++++++++++++++++++++++----- inotify.hxx | 8 ++++++++ smtp.cxx | 6 +----- 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/config.cxx b/config.cxx index c7e3da8..62233b1 100644 --- a/config.cxx +++ b/config.cxx @@ -33,6 +33,7 @@ #include #include "config.hxx" +#include "inotify.hxx" #include "smtp.hxx" /** @@ -68,6 +69,8 @@ static int config_file_exists() */ void config_free() { + virus_removal_enabled = cfg_true; + smtp_enabled = cfg_true; if (smtp_host != NULL) { @@ -131,6 +134,7 @@ void config_parse() cfg_t *cfg; cfg_opt_t opts[] = { + CFG_SIMPLE_BOOL("virus_removal_enabled", &virus_removal_enabled), CFG_SIMPLE_BOOL("smtp_enabled", &smtp_enabled), CFG_SIMPLE_STR("smtp_host", &smtp_host), CFG_SIMPLE_INT("smtp_port", &smtp_port), diff --git a/inoclam.cxx b/inoclam.cxx index 19a5283..3ee608d 100644 --- a/inoclam.cxx +++ b/inoclam.cxx @@ -35,6 +35,8 @@ int main(int argc, char *argv[], char *envp[]) /* Default Values for Global Variables */ exit_now = 0; + virus_removal_enabled = cfg_true; + smtp_enabled = cfg_true; smtp_host = NULL; smtp_port = 0; diff --git a/inotify.cxx b/inotify.cxx index bc55490..fe3312e 100644 --- a/inotify.cxx +++ b/inotify.cxx @@ -34,7 +34,18 @@ #include "signal.hxx" #include "smtp.hxx" -int __inotify_init(char *basedir) +/** + * Grant permission to inoclam to delete infected files by setting this + * to true or false + */ +cfg_bool_t virus_removal_enabled; + +/** + * Initializes inotify and tells it to 'watch' basedir. + * @param basedir the directory to watch. + * @return 1 for OK, -1 for failure. + */ +static int __inotify_init(char *basedir) { if (!inotifytools_initialize() || !inotifytools_watch_recursively(basedir, IN_ALL_EVENTS)) { daemon_log(LOG_ERR, "(%s:%u) Failed init inotify: %s", __FILE__, __LINE__, strerror(inotifytools_error())); @@ -45,10 +56,12 @@ int __inotify_init(char *basedir) } } -int __inotify_exit() +/** + * Free resources used by inotify + */ +static void __inotify_exit() { inotifytools_cleanup(); - return 1; } /** @@ -96,8 +109,13 @@ void inotify_main(char *basedir) switch (contains_virus(filename)) { case 1: /* virus found */ - unlink(filename); /* remove without prejudice */ - smtp_send(filename); + if (virus_removal_enabled == cfg_true) { + unlink(filename); + } + + if (smtp_enabled == cfg_true) { + smtp_send(filename); + } break; case 0: /* no virus detected */ diff --git a/inotify.hxx b/inotify.hxx index 709ad97..a1c2854 100644 --- a/inotify.hxx +++ b/inotify.hxx @@ -23,6 +23,14 @@ #ifndef __INOTIFY_HXX #define __INOTIFY_HXX +#include + +/** + * Grant permission to inoclam to delete infected files by setting this + * to true or false + */ +extern cfg_bool_t virus_removal_enabled; + /** * Watch the specified directory for changes and call contains_virus() * @param basedir the directory to watch. diff --git a/smtp.cxx b/smtp.cxx index 4859be8..0581190 100644 --- a/smtp.cxx +++ b/smtp.cxx @@ -20,6 +20,7 @@ * Tom Cort */ +#include #include #include #include @@ -70,12 +71,7 @@ void smtp_send(char *smtp_body) return; } - /* TODO: Full Parameter Validation */ - /* TODO: Error Handling */ - /* Why are there no C libraries for sending mail that are this simple? */ jwsmtp::mailer mail(smtp_to, smtp_from, smtp_subject, smtp_body, smtp_host, smtp_port, false); mail.send(); - - daemon_log(LOG_INFO, "(%s:%u) E-Mail Notification Sent to '%s'", __FILE__, __LINE__, smtp_to); } -- 2.11.4.GIT