diff -r 5b9fdcafd0df -r 2422a3542d94 clamavscanner/ClamAVScanner.py --- a/clamavscanner/ClamAVScanner.py Tue Nov 04 16:35:33 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,111 +0,0 @@ -#!/usr/bin/python - -# ------------------------------------------------------------ -# opensecurity package file -# -# Autor: X-Net Services GmbH -# -# Copyright 2013-2014 X-Net and AIT Austrian Institute of Technology -# -# -# X-Net Technologies GmbH -# Elisabethstrasse 1 -# 4020 Linz -# AUSTRIA -# https://www.x-net.at -# -# AIT Austrian Institute of Technology -# Donau City Strasse 1 -# 1220 Wien -# AUSTRIA -# http://www.ait.ac.at -# -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ------------------------------------------------------------ - -import ConfigParser - -import sys - -import logging -import os -import errno -import time - -import pyclamav - - -class ClamAVScanner: - - # User the existing logger instance - __LOG = logging.getLogger("IkarusScanner") - - __MINOPTS = { "Main" : ["Nothing"]} - __CONFIG_NOT_READABLE = "Configfile is not readable" - __CONFIG_WRONG = "Something is wrong with the config" - __CONFIG_MISSING = "Section: \"%s\" Option: \"%s\" in configfile is missing" - - - - def __init__ (self, scanner_config_path): - config = self.loadConfig (scanner_config_path) - - - - def checkMinimumOptions (self, config): - for section, options in self.__MINOPTS.iteritems (): - for option in options: - if (config.has_option(section, option) == False): - self.__LOG.error (self.__CONFIG_MISSING % (section, option)) - exit (129) - - def loadConfig (self, scanner_config_path): - - configfile = scanner_config_path - config = ConfigParser.SafeConfigParser () - - 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)): - self.__LOG.error(self.__CONFIG_NOT_READABLE); - raise SystemError(self.__CONFIG_NOT_READABLE) - - try: - config.read (scanner_config_path) - except Exception, e: - self.__LOG.error("Error: %s" % (e)); - raise SystemError("Error: %s" % (e)) - - self.checkMinimumOptions (config) - - return config - - - def scanFile (self, path, fileobject): - return self.scanFileClamAV (path) - - def scanFileClamAV (self, path): - retval = { "infected" : False, "virusname" : "Unknown" } - - self.__LOG.debug ("Scan File: %s" % (path)) - - result = pyclamav.scanfile (path) - self.__LOG.debug ("Result of file \"%s\": %s" % (path, result)) - if (result[0] != 0): - retval["infected"] = True - retval["virusname"] = result[1] - - if (retval["infected"] == True): - self.__LOG.error ("Virus found, deny Access %s" % (result,)) - - return retval -