# HG changeset patch # User ck # Date 1385563046 -3600 # Node ID d27473cf6a01c1a80967c8e1b3882c122a0b2d4b # Parent 1f61fe50ab10ebf762f08d4326adf91bdbe9ddd2 Restored scan function using ClamAV as fallback for testing. diff -r 1f61fe50ab10 -r d27473cf6a01 src/OsecFS.py --- a/src/OsecFS.py Tue Nov 26 16:13:18 2013 +0100 +++ b/src/OsecFS.py Wed Nov 27 15:37:26 2013 +0100 @@ -100,14 +100,17 @@ return m -def scanFileIkarus(path, fileobject): +def scanFileIkarus (path, fileobject): + infected = False + LOG.debug ("Scan File: %s" % (path)) + files = {'up_file': (path, fileobject)} try: - #TODO: chance to remote server + #TODO: change to remote server r = requests.post(LOCAL_SCANSERVER_URL, files=files) except requests.exceptions.ConnectionError: - LOG.info("Remote scan server unreachable, using local scan server.") + #LOG.info("Remote scan server unreachable, using local scan server.") # TODO: # Here the local scan server should be contacted. @@ -120,44 +123,40 @@ # r = requests.post(LOCAL_SCANSERVER_URL, files=files) #except requests.exceptions.ConnectionError: # return 2 - return 2 + LOG.error ("Connection to scan server could not be established.") + return False if r.status_code == STATUS_CODE_OK: - return 0 + infected = False elif r.status_code == STATUS_CODE_INFECTED: # Parse xml for info if desired #contentXML = r.content #root = ET.fromstring(contentXML) #status = root[1][2].text - return 1 + infected = True else: - return 2 + LOG.error ("Connection error to scan server.") -def scanFile (path, fileobject): + if (infected == True): + LOG.error ("Virus found, denying access.") + else: + LOG.debug ("No virus found.") + + return infected + +def scanFileClamAV (path): infected = False LOG.debug ("Scan File: %s" % (path)) # ToDo implement ikarus - #result = pyclamav.scanfile (path) - #LOG.debug ("Result of file \"%s\": %s" % (path, result)) - #if (result[0] != 0): - # infected = True - - #if (infected == True): - # LOG.error ("Virus found deny Access %s" % (result,)) - - result = scanFileIkarus(path, fileobject) + result = pyclamav.scanfile (path) LOG.debug ("Result of file \"%s\": %s" % (path, result)) - - if (result == 2): - LOG.error ("Connection to scan server could not be established.") - - if (result == 1): + if (result[0] != 0): infected = True if (infected == True): - LOG.error ("Virus found deny Access %s" % (result)) + LOG.error ("Virus found, deny Access %s" % (result,)) return infected @@ -232,7 +231,8 @@ self.file = os.fdopen (os.open (fixPath (path), flags), flag2mode (flags)) self.fd = self.file.fileno () - infected = scanFile (rootPath(self.__rootpath, path), self.file) + infected = scanFileIkarus (rootPath(self.__rootpath, path), self.file) + #infected = scanFileClamAV (rootPath(self.__rootpath, path)) if (infected == True): self.file.close () return -errno.EACCES