コード例 #1
0
    def checksum(self, item):
        if self.algorithm == 'mtime':
            return str(int(item.mtime))

        else:
            method = checksum.new(self.algorithm)
            handle = item.open()
            while True:
                chunk = handle.read(self.blocksize)
                if not chunk:
                    break
                else:
                    method.update(chunk)
            handle.close()

            self.cache[item] = method.hexdigest()
            return self.cache[item]
コード例 #2
0
ファイル: incremental.py プロジェクト: oriordan/classified
    def checksum(self, item):
        if self.algorithm == 'mtime':
            return str(int(item.mtime))

        else:
            method = checksum.new(self.algorithm)
            handle = item.open()
            while True:
                chunk = handle.read(self.blocksize)
                if not chunk:
                    break
                else:
                    method.update(chunk)
            handle.close()

            self.cache[item] = method.hexdigest()
            return self.cache[item]
コード例 #3
0
ファイル: base.py プロジェクト: oriordan/classified
    def ignore_hash(self, item, **kwargs):
        '''
        Check if the match is to be ignored, based on hash. This mechanism is
        used to filter out errors and false positives.
        '''
        context = self.config.getdefault('clean:%s' % self.name, 'context',
            self.config.getdefault('clean', 'context', 'line')
        )

        # Calculate checksum using the selected algorith, and check if it is in
        # the ignore list for this probe
        hashing = checksum.new(self.algorithm)
        if context == 'file':
            for line in item.open('rb'):
                hashing.update(line)

        elif context == 'line':
            try:
                hashing.update(kwargs['raw'])
            except KeyError:
                # The reported item has no "raw" format, therefor we can not
                # provide a line-based hash
                return None, False

        elif context == 'format':
            format = self.config.get('clean:%s' % self.name, 'format')
            hashing.update(format.format(**kwargs))

        else:
            raise TypeError('Probe %s does not support %s context' % \
                (self.name, context))

        digest = hashing.hexdigest()
        if digest in IGNORE[self.name]['hash']:
            logging.debug('ignoring %r in %s: %s' % (item, self.name, digest))
            return digest, True
        else:
            logging.debug('allowing %r in %s: %s' % (item, self.name, digest))
            return digest, False
コード例 #4
0
    def ignore_hash(self, item, **kwargs):
        '''
        Check if the match is to be ignored, based on hash. This mechanism is
        used to filter out errors and false positives.
        '''
        context = self.config.getdefault(
            'clean:%s' % self.name, 'context',
            self.config.getdefault('clean', 'context', 'line'))

        # Calculate checksum using the selected algorith, and check if it is in
        # the ignore list for this probe
        hashing = checksum.new(self.algorithm)
        if context == 'file':
            for line in item.open('rb'):
                hashing.update(line)

        elif context == 'line':
            try:
                hashing.update(kwargs['raw'])
            except KeyError:
                # The reported item has no "raw" format, therefor we can not
                # provide a line-based hash
                return None, False

        elif context == 'format':
            format = self.config.get('clean:%s' % self.name, 'format')
            hashing.update(format.format(**kwargs))

        else:
            raise TypeError('Probe %s does not support %s context' % \
                (self.name, context))

        digest = hashing.hexdigest()
        if digest in IGNORE[self.name]['hash']:
            logging.debug('ignoring %r in %s: %s' % (item, self.name, digest))
            return digest, True
        else:
            logging.debug('allowing %r in %s: %s' % (item, self.name, digest))
            return digest, False