Example #1
0
int oval_probe_query_test(oval_probe_session_t *sess, struct oval_test *test)
{
	struct oval_object *object;
	struct oval_state_iterator *ste_itr;
	const char *type, *test_id, *comment;
	int ret;

	type = oval_subtype_get_text(oval_test_get_subtype(test));
	test_id = oval_test_get_id(test);
	comment = oval_test_get_comment(test);
	dI("Evaluating %s test '%s': %s.", type, test_id, comment);
	object = oval_test_get_object(test);
	if (object == NULL)
		return 0;
	/* probe object */
	ret = oval_probe_query_object(sess, object, 0, NULL);
	if (ret == -1)
		return ret;
	/* probe objects referenced like this: test->state->variable->object */
	ste_itr = oval_test_get_states(test);
	while (oval_state_iterator_has_more(ste_itr)) {
		struct oval_state *state = oval_state_iterator_next(ste_itr);
		ret = oval_probe_query_var_ref(sess, state);
		if (ret < 1) {
			oval_state_iterator_free(ste_itr);
			return ret;
		}
	}
	oval_state_iterator_free(ste_itr);

	return 0;
}
Example #2
0
oval_result_t oval_result_test_eval(struct oval_result_test *rtest)
{
	__attribute__nonnull__(rtest);

	if (rtest->result == OVAL_RESULT_NOT_EVALUATED) {
		if ((oval_independent_subtype_t)oval_test_get_subtype(oval_result_test_get_test(rtest)) != OVAL_INDEPENDENT_UNKNOWN ) {
			struct oval_string_map *tmp_map = oval_string_map_new();
			void *args[] = { rtest->system, rtest, tmp_map };
			rtest->result = _oval_result_test_result(rtest, args);
			oval_string_map_free(tmp_map, NULL);

			if (!rtest->bindings_initialized) {
				_oval_result_test_initialize_bindings(rtest);
			}
		}
		else
			rtest->result = OVAL_RESULT_UNKNOWN;
	}

        dI("\t%s => %s\n", oval_result_test_get_id(rtest), oval_result_get_text(rtest->result));

	return rtest->result;
}
Example #3
0
int oval_probe_query_test(oval_probe_session_t *sess, struct oval_test *test)
{
	struct oval_object *object;
	struct oval_state_iterator *ste_itr;
	int ret;
	oval_subtype_t test_subtype, object_subtype;

	object = oval_test_get_object(test);
	if (object == NULL)
		return 0;
	test_subtype = oval_test_get_subtype(test);
	object_subtype = oval_object_get_subtype(object);
	if (test_subtype != object_subtype) {
		oscap_seterr(OSCAP_EFAMILY_OVAL, "%s_test '%s' is not compatible with %s_object '%s'.",
				oval_subtype_to_str(test_subtype), oval_test_get_id(test),
				oval_subtype_to_str(object_subtype), oval_object_get_id(object));
		return 0;
	}

	/* probe object */
	ret = oval_probe_query_object(sess, object, 0, NULL);
	if (ret == -1)
		return ret;
	/* probe objects referenced like this: test->state->variable->object */
	ste_itr = oval_test_get_states(test);
	while (oval_state_iterator_has_more(ste_itr)) {
		struct oval_state *state = oval_state_iterator_next(ste_itr);
		ret = oval_probe_query_var_ref(sess, state);
		if (ret < 1) {
			oval_state_iterator_free(ste_itr);
			return ret;
		}
	}
	oval_state_iterator_free(ste_itr);

	return 0;
}
Example #4
0
xmlNode *oval_test_to_dom(struct oval_test *test, xmlDoc * doc, xmlNode * parent)
{
	xmlNode * test_node=NULL;

	/* skip unknown test */
	oval_subtype_t subtype = oval_test_get_subtype(test);
	if ( subtype == OVAL_SUBTYPE_UNKNOWN ) {
		oscap_dlprintf(DBG_E, "Unknown Test %s.\n", oval_test_get_id(test));
		return test_node;
	}

	/* get test name */
	const char *subtype_text = oval_subtype_get_text(subtype);
	char test_name[strlen(subtype_text) + 6];
	sprintf(test_name, "%s_test", subtype_text);

	/* get family URI */
	oval_family_t family = oval_test_get_family(test);
	const char *family_text = oval_family_get_text(family);
	char family_uri[strlen((const char *)OVAL_DEFINITIONS_NAMESPACE) + strlen(family_text) + 2];
	sprintf(family_uri,"%s#%s", OVAL_DEFINITIONS_NAMESPACE, family_text);

	/* search namespace & create child */
	xmlNs *ns_family = xmlSearchNsByHref(doc, parent, BAD_CAST family_uri);
	test_node = xmlNewTextChild(parent, ns_family, BAD_CAST test_name, NULL);

	char *id = oval_test_get_id(test);
	xmlNewProp(test_node, BAD_CAST "id", BAD_CAST id);

	char version[10];
	*version = '\0';
	snprintf(version, sizeof(version), "%d", oval_test_get_version(test));
	xmlNewProp(test_node, BAD_CAST "version", BAD_CAST version);

	oval_existence_t existence = oval_test_get_existence(test);
	if (existence != OVAL_AT_LEAST_ONE_EXISTS)
		xmlNewProp(test_node, BAD_CAST "check_existence", BAD_CAST oval_existence_get_text(existence));

	oval_check_t check = oval_test_get_check(test);
	xmlNewProp(test_node, BAD_CAST "check", BAD_CAST oval_check_get_text(check));

	oval_operator_t ste_operator = oval_test_get_state_operator(test);
	if (ste_operator != OVAL_OPERATOR_AND)
		xmlNewProp(test_node, BAD_CAST "state_operator", BAD_CAST oval_operator_get_text(ste_operator));

	char *comm = oval_test_get_comment(test);
	xmlNewProp(test_node, BAD_CAST "comment", BAD_CAST comm);

	bool deprecated = oval_test_get_deprecated(test);
	if (deprecated)
		xmlNewProp(test_node, BAD_CAST "deprecated", BAD_CAST "true");

	struct oval_string_iterator *notes = oval_test_get_notes(test);
	if (oval_string_iterator_has_more(notes)) {
		xmlNs *ns_definitions = xmlSearchNsByHref(doc, parent, OVAL_DEFINITIONS_NAMESPACE);
		xmlNode *notes_node = xmlNewTextChild(test_node, ns_definitions, BAD_CAST "notes", NULL);
		while (oval_string_iterator_has_more(notes)) {
			char *note = oval_string_iterator_next(notes);
			xmlNewTextChild(notes_node, ns_definitions, BAD_CAST "note", BAD_CAST note);
		}
	}
	oval_string_iterator_free(notes);

	struct oval_object *object = oval_test_get_object(test);
	if (object) {
		xmlNode *object_node = xmlNewTextChild(test_node, ns_family, BAD_CAST "object", NULL);
		xmlNewProp(object_node, BAD_CAST "object_ref", BAD_CAST oval_object_get_id(object));
	}

	struct oval_state_iterator *ste_itr = oval_test_get_states(test);
	while (oval_state_iterator_has_more(ste_itr)) {
		struct oval_state *state;

		state = oval_state_iterator_next(ste_itr);
		xmlNode *state_node = xmlNewTextChild(test_node, ns_family, BAD_CAST "state", NULL);
		xmlNewProp(state_node, BAD_CAST "state_ref", BAD_CAST oval_state_get_id(state));
	}
	oval_state_iterator_free(ste_itr);

	return test_node;
}