示例#1
0
/*
 * check_wim_integrity():
 *
 * Verifies the integrity of the WIM by making sure the SHA1 message digests of
 * ~10 MiB chunks of the WIM match up with the values given in the integrity
 * table.
 *
 * @wim:
 *	The WIM, opened for reading.
 *
 * Returns:
 *	> 0 (WIMLIB_ERR_INVALID_INTEGRITY_TABLE, WIMLIB_ERR_READ,
 *	     WIMLIB_ERR_UNEXPECTED_END_OF_FILE) on error
 *	0 (WIM_INTEGRITY_OK) if the integrity was checked successfully and there
 *	were no inconsistencies.
 *	-1 (WIM_INTEGRITY_NOT_OK) if the WIM failed the integrity check.
 *	-2 (WIM_INTEGRITY_NONEXISTENT) if the WIM contains no integrity
 *	information.
 */
int
check_wim_integrity(WIMStruct *wim)
{
	int ret;
	u64 bytes_to_check;
	struct integrity_table *table;
	u64 end_lookup_table_offset;

	if (!wim_has_integrity_table(wim)) {
		DEBUG("No integrity information.");
		return WIM_INTEGRITY_NONEXISTENT;
	}

	end_lookup_table_offset = wim->hdr.lookup_table_reshdr.offset_in_wim +
				  wim->hdr.lookup_table_reshdr.size_in_wim;

	if (end_lookup_table_offset < WIM_HEADER_DISK_SIZE) {
		ERROR("WIM lookup table ends before WIM header ends!");
		return WIMLIB_ERR_INVALID_INTEGRITY_TABLE;
	}

	bytes_to_check = end_lookup_table_offset - WIM_HEADER_DISK_SIZE;

	ret = read_integrity_table(wim, bytes_to_check, &table);
	if (ret)
		return ret;
	ret = verify_integrity(&wim->in_fd, wim->filename, table,
			       bytes_to_check, wim->progfunc, wim->progctx);
	FREE(table);
	return ret;
}
示例#2
0
int main() {
    if (verify_integrity())
        return go();
    else
        return 2;
}