예제 #1
0
static int app_cvrf_export(const struct oscap_action *action) {
	struct oscap_source *import_source = oscap_source_new_from_file(action->cvrf_action->f_cvrf);
	if (import_source == NULL)
		return OSCAP_ERROR;

	int result = OSCAP_OK;
	if (action->cvrf_action->index == 1) {
		struct cvrf_index *index = cvrf_index_import(import_source);
		if (index == NULL) {
			result = OSCAP_ERROR;
			goto cleanup;
		}
		struct oscap_source *export_source = cvrf_index_get_export_source(index);
		if (oscap_source_save_as(export_source, action->cvrf_action->f_output) != 0)
			result = OSCAP_ERROR;
		oscap_source_free(export_source);
		cvrf_index_free(index);
	} else {
		struct cvrf_model *model = cvrf_model_import(import_source);
		if(model == NULL) {
			result = OSCAP_ERROR;
			goto cleanup;
		}
		struct oscap_source *export_source = cvrf_model_get_export_source(model);
		if (oscap_source_save_as(export_source, action->cvrf_action->f_output) != 0)
			result = OSCAP_ERROR;
		oscap_source_free(export_source);
		cvrf_model_free(model);
	}

	cleanup:
		if (oscap_err())
			fprintf(stderr, "%s %s\n", OSCAP_ERR_MSG, oscap_err_desc());

	/* TODO: Refactor, cvrf_index_parse_xml (called by oscap_source_new_from_file) frees its argument as an unexpected side-effect.
	 * oscap_source_free(import_source);
	 */
	free(action->cvrf_action);
	return result;
}
예제 #2
0
int xccdf_benchmark_export(struct xccdf_benchmark *benchmark, const char *file)
{
	__attribute__nonnull__(file);

	LIBXML_TEST_VERSION;

	struct oscap_source *source = xccdf_benchmark_export_source(benchmark, file);
	if (source == NULL) {
		return -1;
	}
	int ret = oscap_source_save_as(source, NULL);
	oscap_source_free(source);;
	return ret;
}
예제 #3
0
int main(int argc, char **argv)
{
	/* test export */
	if (argc == 4 && !strcmp(argv[1], "--export-all")) {
		struct cvrf_model *model = cvrf_model_import(oscap_source_new_from_file(argv[2]));
		if(!model)
			return 1;
		struct oscap_source *export_source = cvrf_model_get_export_source(model);
		int ret = oscap_source_save_as(export_source, argv[3]);
		cvrf_model_free(model);
		oscap_source_free(export_source);
		return ret;
	} else if (argc == 4 && !strcmp(argv[1], "--eval")) {
		const char *cpe = "Managment Agent for RHEL 7 Hosts";
		struct oscap_source *import_source = oscap_source_new_from_file(argv[2]);
		struct oscap_source *export_source = cvrf_model_get_results_source(import_source, cpe);
		int ret = oscap_source_save_as(export_source, argv[3]);
		oscap_source_free(export_source);
		return ret;
	} else if (argc == 3 && !strcmp(argv[1], "--validate")) {
		struct oscap_source *source = oscap_source_new_from_file(argv[2]);
		int ret = oscap_source_validate(source, reporter, NULL);
		oscap_source_free(source);
		return ret;
	}

	fprintf(stdout,
		"Usage: \n\n"
		"  %s --help\n"
		"  %s --export-all input.xml output.xml\n"
		"  %s --eval input.xml results.xml\n"
		"  %s --validate input.xml\n",
		argv[0], argv[0], argv[0], argv[0]);

	return 0;
}
예제 #4
0
int ds_dump_component_sources(struct oscap_htable *component_sources, const char *target_dir)
{
	struct oscap_htable_iterator *hit = oscap_htable_iterator_new(component_sources);
	while (oscap_htable_iterator_has_more(hit)) {
		struct oscap_source *s = oscap_htable_iterator_next_value(hit);
		char *filename = target_dir == NULL ? oscap_strdup(oscap_source_readable_origin(s))
				: oscap_sprintf("%s/%s", target_dir, oscap_source_readable_origin(s));
		int ret = oscap_acquire_ensure_parent_dir(filename);
		if (ret != 0) {
			oscap_htable_iterator_free(hit);
			return ret;
		}
		ret = oscap_source_save_as(s, filename);
		free(filename);
		if (ret != 0) {
			oscap_htable_iterator_free(hit);
			return ret;
		}
	}
	oscap_htable_iterator_free(hit);
	return 0;
}
예제 #5
0
파일: sds.c 프로젝트: radzy/openscap
int ds_sds_compose_add_component(const char *target_datastream, const char *datastream_id, const char *new_component, bool extended)
{
	struct oscap_source *sds_source = oscap_source_new_from_file(target_datastream);
	xmlDoc *doc = oscap_source_get_xmlDoc(sds_source);
	if (doc == NULL) {
		oscap_source_free(sds_source);
		return 1;
	}
	xmlNodePtr datastream = ds_sds_lookup_datastream_in_collection(doc, datastream_id);
	if (datastream == NULL) {
		const char* error = datastream_id ?
			oscap_sprintf("Could not find any datastream of id '%s'", datastream_id) :
			oscap_sprintf("Could not find any datastream inside the file");

		oscap_seterr(OSCAP_EFAMILY_XML, error);
		oscap_free(error);
		oscap_source_free(sds_source);
		return 1;
	}

	char* mangled_path = ds_sds_mangle_filepath(new_component);

	char* cref_id = oscap_sprintf("scap_org.open-scap_cref_%s", mangled_path);
	oscap_free(mangled_path);
	if (ds_sds_compose_add_component_with_ref(doc, datastream, new_component, cref_id) != 0) {
		oscap_free(cref_id);
		oscap_source_free(sds_source);
		return 1;
	}
	oscap_free(cref_id);

	if (oscap_source_save_as(sds_source, NULL) != 0) {
		oscap_seterr(OSCAP_EFAMILY_GLIBC, "Error saving source datastream to '%s'.", target_datastream);
		oscap_source_free(sds_source);
		return 1;
	}
	oscap_source_free(sds_source);
	return 0;
}
예제 #6
0
static int app_cvrf_evaluate(const struct oscap_action *action) {
	int result = OSCAP_OK;
	// Temporary hardcoded CPE until CPE name can be found without input by CVRF functions
	// themselves
	const char *os_name = "Red Hat Enterprise Linux Desktop Supplementary (v. 6)";
	struct oscap_source *import_source = oscap_source_new_from_file(action->cvrf_action->f_cvrf);
	struct oscap_source *export_source = cvrf_model_get_results_source(import_source, os_name);
	if (export_source == NULL)
		return -1;

	if (oscap_source_save_as(export_source, action->cvrf_action->f_results) == -1) {
		result = OSCAP_ERROR;
		goto cleanup;
	}

	cleanup:
		if (oscap_err())
			fprintf(stderr, "%s %s\n", OSCAP_ERR_MSG, oscap_err_desc());

	oscap_source_free(export_source);
	free(action->cvrf_action);
	return result;
}
예제 #7
0
파일: rds.c 프로젝트: msmeissn/openscap
int ds_rds_create(const char* sds_file, const char* xccdf_result_file, const char** oval_result_files, const char* target_file)
{
	struct oscap_source *sds_source = oscap_source_new_from_file(sds_file);
	struct oscap_source *xccdf_result_source = oscap_source_new_from_file(xccdf_result_file);
	struct oscap_htable *oval_result_sources = oscap_htable_new();

	int result = 0;
	// this check is there to allow passing NULL instead of having to allocate
	// an empty array
	if (oval_result_files != NULL)
	{
		while (*oval_result_files != NULL)
		{
			struct oscap_source *oval_source = oscap_source_new_from_file(*oval_result_files);
			if (oscap_source_get_xmlDoc(oval_source) == NULL) {
				result = -1;
				oscap_source_free(oval_source);
			} else {
				oscap_htable_add(oval_result_sources, *oval_result_files, oval_source);
			}
			oval_result_files++;
		}
	}
	if (result == 0) {
		struct oscap_source *target_rds = ds_rds_create_source(sds_source, xccdf_result_source, oval_result_sources, target_file);
		result = target_rds == NULL;
		if (result == 0) {
			result = oscap_source_save_as(target_rds, NULL);
		}
		oscap_source_free(target_rds);
	}
	oscap_htable_free(oval_result_sources, (oscap_destruct_func) oscap_source_free);
	oscap_source_free(sds_source);
	oscap_source_free(xccdf_result_source);

	return result;
}