Esempio n. 1
0
def getMountPoint(device):
    '''
    Mounts device given as a first argument and returns
    mount point of the device
    '''
    subprocessPipesCall(['mount', device], stdout=False, retVal=False)
    proc = Popen(["lsblk", device], stdout=PIPE, stderr=DEVNULL)
    streamData = proc.communicate()
    if proc.returncode != 0:
        logger.error(msg.MOUNT_CALL_ERROR)
    mountPoint = streamData[0].decode(locale.getpreferredencoding()).split(" /")[-1][:-1]
    if not '/' in mountPoint:
        logger.error(msg.notMounted(device))
        raise NoMountPointException("Can't get mount point of device {}".format(device))
    return '/'+ mountPoint
Esempio n. 2
0
 def scanDisc(self, device, mountPoint):
     '''
     Runs scanning disc given as a first argument and prints
     clamscan output
     '''
     logger.info(msg.deviceScanning(device, mountPoint))
     return subprocessPipesCall(['clamscan', '-r', mountPoint], getFiles=True)
Esempio n. 3
0
 def scanDiscHead(self, disc):
     '''
     Store first 200 000 bytes of disc to file, scan it and remove the file
     '''
     logger.info(msg.headScanning(disc))
     with tempfile.NamedTemporaryFile(mode='wb') as tempFile:
         makeHead = Popen(['head', '-c', '200000', disc], stdout=tempFile,
                 stderr=PIPE)
         logger.info(makeHead.stderr.read().decode(locale.getpreferredencoding()))
         headResult = subprocessPipesCall(['clamscan', tempFile.name], stdout=False)
     return headResult
Esempio n. 4
0
 def scanSelectedFiles(self, newDevice, files):
     fullPathFiles = [x[0] + x[1] for x in files]
     self.handleNewDevice(newDevice, full=False)
     for partition in newDevice['partitions']:
         device = getDeviceName(partition)
         self.processPartition(device, full=False)
     logger.info(msg.scanningSelected(device))
     files, found = subprocessPipesCall(['clamscan', '-r'] + fullPathFiles, getFiles=True)
     for infectedFile in found:  # finds out to which paritition file belong
         for part in self.partitions.values():
             if part.mountPoint in infectedFile:
                 part.found += [(part.mountPoint + '/', os.path.relpath(infectedFile, part.mountPoint))]
                 part.files = files
                 continue