Restored scan function using ClamAV as fallback for testing.
authorck
Wed, 27 Nov 2013 15:37:26 +0100
changeset 2d27473cf6a01
parent 1 1f61fe50ab10
child 3 5c45c43de56e
child 22 23028352807f
Restored scan function using ClamAV as fallback for testing.
src/OsecFS.py
     1.1 --- a/src/OsecFS.py	Tue Nov 26 16:13:18 2013 +0100
     1.2 +++ b/src/OsecFS.py	Wed Nov 27 15:37:26 2013 +0100
     1.3 @@ -100,14 +100,17 @@
     1.4  
     1.5      return m
     1.6  
     1.7 -def scanFileIkarus(path, fileobject):
     1.8 +def scanFileIkarus (path, fileobject):
     1.9 +    infected = False
    1.10 +    LOG.debug ("Scan File: %s" % (path))
    1.11 +    
    1.12      files = {'up_file': (path, fileobject)}
    1.13      
    1.14      try:
    1.15 -        #TODO: chance to remote server
    1.16 +        #TODO: change to remote server
    1.17          r = requests.post(LOCAL_SCANSERVER_URL, files=files)
    1.18      except requests.exceptions.ConnectionError:
    1.19 -        LOG.info("Remote scan server unreachable, using local scan server.")
    1.20 +        #LOG.info("Remote scan server unreachable, using local scan server.")
    1.21  
    1.22          # TODO:
    1.23          # Here the local scan server should be contacted.
    1.24 @@ -120,44 +123,40 @@
    1.25          #    r = requests.post(LOCAL_SCANSERVER_URL, files=files)
    1.26          #except requests.exceptions.ConnectionError:
    1.27          #    return 2
    1.28 -        return 2
    1.29 +        LOG.error ("Connection to scan server could not be established.")
    1.30 +        return False
    1.31  
    1.32      if r.status_code == STATUS_CODE_OK:
    1.33 -        return 0
    1.34 +        infected = False
    1.35      elif r.status_code == STATUS_CODE_INFECTED:
    1.36          # Parse xml for info if desired
    1.37          #contentXML = r.content
    1.38          #root = ET.fromstring(contentXML)
    1.39          #status = root[1][2].text
    1.40 -        return 1
    1.41 +        infected = True
    1.42      else:
    1.43 -        return 2
    1.44 +        LOG.error ("Connection error to scan server.")
    1.45  
    1.46 -def scanFile (path, fileobject):
    1.47 +    if (infected == True):
    1.48 +        LOG.error ("Virus found, denying access.")
    1.49 +    else:
    1.50 +        LOG.debug ("No virus found.")
    1.51 +
    1.52 +    return infected
    1.53 +
    1.54 +def scanFileClamAV (path):
    1.55      infected = False
    1.56  
    1.57      LOG.debug ("Scan File: %s" % (path))
    1.58  
    1.59      # ToDo implement ikarus
    1.60 -    #result = pyclamav.scanfile (path)
    1.61 -    #LOG.debug ("Result of file \"%s\": %s" % (path, result))
    1.62 -    #if (result[0] != 0):
    1.63 -    #    infected = True
    1.64 -
    1.65 -    #if (infected == True):
    1.66 -    #    LOG.error ("Virus found deny Access %s" % (result,))
    1.67 -
    1.68 -    result = scanFileIkarus(path, fileobject)
    1.69 +    result = pyclamav.scanfile (path)
    1.70      LOG.debug ("Result of file \"%s\": %s" % (path, result))
    1.71 -
    1.72 -    if (result == 2):
    1.73 -        LOG.error ("Connection to scan server could not be established.")
    1.74 -
    1.75 -    if (result == 1):
    1.76 +    if (result[0] != 0):
    1.77          infected = True
    1.78  
    1.79      if (infected == True):
    1.80 -        LOG.error ("Virus found deny Access %s" % (result))
    1.81 +        LOG.error ("Virus found, deny Access %s" % (result,))
    1.82  
    1.83      return infected
    1.84  
    1.85 @@ -232,7 +231,8 @@
    1.86          self.file = os.fdopen (os.open (fixPath (path), flags), flag2mode (flags))
    1.87          self.fd = self.file.fileno ()
    1.88  
    1.89 -        infected = scanFile (rootPath(self.__rootpath, path), self.file)
    1.90 +        infected = scanFileIkarus (rootPath(self.__rootpath, path), self.file)
    1.91 +        #infected = scanFileClamAV (rootPath(self.__rootpath, path))
    1.92          if (infected == True):
    1.93              self.file.close ()
    1.94              return -errno.EACCES