17 # User the existing logger instance
18 __LOG = logging.getLogger("IkarusScanner")
20 __MINOPTS = { "Main" : ["Nothing"]}
21 __CONFIG_NOT_READABLE = "Configfile is not readable"
22 __CONFIG_WRONG = "Something is wrong with the config"
23 __CONFIG_MISSING = "Section: \"%s\" Option: \"%s\" in configfile is missing"
27 def __init__ (self, scanner_config_path):
28 config = self.loadConfig (scanner_config_path)
32 def checkMinimumOptions (self, config):
33 for section, options in self.__MINOPTS.iteritems ():
34 for option in options:
35 if (config.has_option(section, option) == False):
36 self.__LOG.error (self.__CONFIG_MISSING % (section, option))
39 def loadConfig (self, scanner_config_path):
41 configfile = scanner_config_path
42 config = ConfigParser.SafeConfigParser ()
44 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)):
45 self.__LOG.error(self.__CONFIG_NOT_READABLE);
46 raise SystemError(self.__CONFIG_NOT_READABLE)
49 config.read (scanner_config_path)
51 self.__LOG.error("Error: %s" % (e));
52 raise SystemError("Error: %s" % (e))
54 self.checkMinimumOptions (config)
59 def scanFile (self, path, fileobject):
60 return self.scanFileClamAV (path)
62 def scanFileClamAV (self, path):
63 retval = { "infected" : False, "virusname" : "Unknown" }
65 self.__LOG.debug ("Scan File: %s" % (path))
67 result = pyclamav.scanfile (path)
68 self.__LOG.debug ("Result of file \"%s\": %s" % (path, result))
70 retval["infected"] = True
71 retval["virusname"] = result[1]
73 if (retval["infected"] == True):
74 self.__LOG.error ("Virus found, deny Access %s" % (result,))