1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/config/ClamAVScanner.cfg Tue Feb 18 15:39:30 2014 +0100
1.3 @@ -0,0 +1,2 @@
1.4 +[Main]
1.5 +Nothing: placeholder
1.6 \ No newline at end of file
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/src/ClamAVScanner.py Tue Feb 18 15:39:30 2014 +0100
2.3 @@ -0,0 +1,77 @@
2.4 +#!/usr/bin/python
2.5 +
2.6 +import ConfigParser
2.7 +
2.8 +import sys
2.9 +
2.10 +import logging
2.11 +import os
2.12 +import errno
2.13 +import time
2.14 +
2.15 +import pyclamav
2.16 +
2.17 +
2.18 +class ClamAVScanner:
2.19 +
2.20 + # User the existing logger instance
2.21 + __LOG = logging.getLogger("IkarusScanner")
2.22 +
2.23 + __MINOPTS = { "Main" : ["Nothing"]}
2.24 + __CONFIG_NOT_READABLE = "Configfile is not readable"
2.25 + __CONFIG_WRONG = "Something is wrong with the config"
2.26 + __CONFIG_MISSING = "Section: \"%s\" Option: \"%s\" in configfile is missing"
2.27 +
2.28 +
2.29 +
2.30 + def __init__ (self, scanner_config_path):
2.31 + config = self.loadConfig (scanner_config_path)
2.32 +
2.33 +
2.34 +
2.35 + def checkMinimumOptions (self, config):
2.36 + for section, options in self.__MINOPTS.iteritems ():
2.37 + for option in options:
2.38 + if (config.has_option(section, option) == False):
2.39 + self.__LOG.error (self.__CONFIG_MISSING % (section, option))
2.40 + exit (129)
2.41 +
2.42 + def loadConfig (self, scanner_config_path):
2.43 +
2.44 + configfile = scanner_config_path
2.45 + config = ConfigParser.SafeConfigParser ()
2.46 +
2.47 + if ((os.path.exists (scanner_config_path) == False) or (os.path.isfile (scanner_config_path) == False) or (os.access (scanner_config_path, os.R_OK) == False)):
2.48 + self.__LOG.error(self.__CONFIG_NOT_READABLE);
2.49 + raise SystemError(self.__CONFIG_NOT_READABLE)
2.50 +
2.51 + try:
2.52 + config.read (scanner_config_path)
2.53 + except Exception, e:
2.54 + self.__LOG.error("Error: %s" % (e));
2.55 + raise SystemError("Error: %s" % (e))
2.56 +
2.57 + self.checkMinimumOptions (config)
2.58 +
2.59 + return config
2.60 +
2.61 +
2.62 + def scanFile (self, path, fileobject):
2.63 + return self.scanFileClamAV (path)
2.64 +
2.65 + def scanFileClamAV (self, path):
2.66 + retval = { "infected" : False, "virusname" : "Unknown" }
2.67 +
2.68 + self.__LOG.debug ("Scan File: %s" % (path))
2.69 +
2.70 + result = pyclamav.scanfile (path)
2.71 + self.__LOG.debug ("Result of file \"%s\": %s" % (path, result))
2.72 + if (result[0] != 0):
2.73 + retval["infected"] = True
2.74 + retval["virusname"] = result[1]
2.75 +
2.76 + if (retval["infected"] == True):
2.77 + self.__LOG.error ("Virus found, deny Access %s" % (result,))
2.78 +
2.79 + return retval
2.80 +