コード例 #1
0
    def check_checksums():
        for f in status["files"].values():
            f['checksum'] = None

        # checksums field might contain three states:
        # a) None  - This is a legacy snapshot, no checksum file available
        # b) False - No or invalid checksums
        # c) True  - Checksums successfully validated
        if status['type'] == 'legacy':
            status['checksums'] = None
            return

        if 'checksums' not in status['files'].keys():
            status['checksums'] = False
            return

        # Extract all available checksums from the snapshot
        checksums_raw = access_snapshot(
            lambda x: multitar.get_file_content(x, 'checksums'))
        checksums = {}
        for l in checksums_raw.split('\n'):
            line = l.strip()
            if ' ' in line:
                parts = line.split(' ')
                if len(parts) == 3:
                    checksums[parts[0]] = (parts[1], parts[2])

        # now loop all known backup domains and check wheter or not they request
        # checksum validation, there is one available and it is valid
        status['checksums'] = True
        for domain_id, domain in backup_domains.items():
            filename = domain_id + '.tar.gz'
            if not domain.get('checksum',
                              True) or filename not in status['files']:
                continue

            if filename not in checksums:
                continue

            checksum, signed = checksums[filename]

            # Get hashes of file in question
            def handler(x, filename=filename):
                return multitar.get_file_content(x, filename)

            subtar = access_snapshot(handler)
            subtar_hash = sha256(subtar).hexdigest()
            subtar_signed = sha256(
                six.ensure_binary(subtar_hash) +
                _snapshot_secret()).hexdigest()

            status['files'][filename]['checksum'] = (checksum == subtar_hash
                                                     and signed
                                                     == subtar_signed)
            status['checksums'] &= status['files'][filename]['checksum']
コード例 #2
0
    def check_core():
        if "check_mk.tar.gz" not in status["files"]:
            return

        cmk_tar = io.BytesIO(
            access_snapshot(lambda x: multitar.get_file_content(x, 'check_mk.tar.gz')))
        files = multitar.list_tar_content(cmk_tar)
        using_cmc = os.path.exists(cmk.utils.paths.omd_root + '/etc/check_mk/conf.d/microcore.mk')
        snapshot_cmc = 'conf.d/microcore.mk' in files
        if using_cmc and not snapshot_cmc:
            raise MKGeneralException(
                _('You are currently using the Check_MK Micro Core, but this snapshot does not use the '
                  'Check_MK Micro Core. If you need to migrate your data, you could consider changing '
                  'the core, restoring the snapshot and changing the core back again.'))
        elif not using_cmc and snapshot_cmc:
            raise MKGeneralException(
                _('You are currently not using the Check_MK Micro Core, but this snapshot uses the '
                  'Check_MK Micro Core. If you need to migrate your data, you could consider changing '
                  'the core, restoring the snapshot and changing the core back again.'))
コード例 #3
0
 def handler(x, filename=filename):
     return multitar.get_file_content(x, filename)
コード例 #4
0
 def handler(x, entry=entry):
     return multitar.get_file_content(x, entry)