int oval_agent_eval_system(oval_agent_session_t * ag_sess, agent_reporter cb, void *arg) { struct oval_definition *oval_def; struct oval_definition_iterator *oval_def_it; char *id; int ret = 0; dI("OVAL agent started to evaluate OVAL definitions on your system."); oval_def_it = oval_definition_model_get_definitions(ag_sess->def_model); while (oval_definition_iterator_has_more(oval_def_it)) { oval_def = oval_definition_iterator_next(oval_def_it); id = oval_definition_get_id(oval_def); /* probe and eval */ ret = oval_agent_eval_definition(ag_sess, id); if (ret==-1) { goto cleanup; } /* callback */ if (cb != NULL) { struct oval_result_definition * res_def = oval_agent_get_result_definition(ag_sess, id); ret = cb(res_def,arg); /* stop? */ if (ret!=0) goto cleanup; } /* probe evaluation terminated by signal */ if (ret == -2) { ret = 1; break; } } cleanup: oval_definition_iterator_free(oval_def_it); dI("OVAL agent finished evaluation."); return ret; }
xmlNode *oval_definition_model_to_dom(struct oval_definition_model *definition_model, xmlDocPtr doc, xmlNode * parent) { xmlNodePtr root_node = NULL; if (parent) { /* result file */ root_node = xmlNewTextChild(parent, NULL, BAD_CAST OVAL_ROOT_ELM_DEFINITIONS, NULL); } else { /* definitions file, we are the root */ root_node = xmlNewNode(NULL, BAD_CAST OVAL_ROOT_ELM_DEFINITIONS); xmlDocSetRootElement(doc, root_node); } xmlNewNsProp(root_node, lookup_xsi_ns(doc), BAD_CAST "schemaLocation", BAD_CAST definition_model->schema); xmlNs *ns_common = xmlNewNs(root_node, OVAL_COMMON_NAMESPACE, BAD_CAST "oval"); xmlNs *ns_unix = xmlNewNs(root_node, OVAL_DEFINITIONS_UNIX_NS, BAD_CAST "unix-def"); xmlNs *ns_ind = xmlNewNs(root_node, OVAL_DEFINITIONS_IND_NS, BAD_CAST "ind-def"); xmlNs *ns_lin = xmlNewNs(root_node, OVAL_DEFINITIONS_LIN_NS, BAD_CAST "lin-def"); xmlNs *ns_defntns = xmlNewNs(root_node, OVAL_DEFINITIONS_NAMESPACE, NULL); xmlSetNs(root_node, ns_common); xmlSetNs(root_node, ns_unix); xmlSetNs(root_node, ns_ind); xmlSetNs(root_node, ns_lin); xmlSetNs(root_node, ns_defntns); /* Always report the generator */ oval_generator_to_dom(definition_model->generator, doc, root_node); /* Report definitions */ struct oval_definition_iterator *definitions = oval_definition_model_get_definitions(definition_model); if (oval_definition_iterator_has_more(definitions)) { xmlNode *definitions_node = NULL; while(oval_definition_iterator_has_more(definitions)) { struct oval_definition *definition = oval_definition_iterator_next(definitions); if (definitions_node == NULL) { definitions_node = xmlNewTextChild(root_node, ns_defntns, BAD_CAST "definitions", NULL); } oval_definition_to_dom(definition, doc, definitions_node); } } oval_definition_iterator_free(definitions); /* Report tests */ struct oval_test_iterator *tests = oval_definition_model_get_tests(definition_model); if (oval_test_iterator_has_more(tests)) { xmlNode *tests_node = xmlNewTextChild(root_node, ns_defntns, BAD_CAST "tests", NULL); while (oval_test_iterator_has_more(tests)) { struct oval_test *test = oval_test_iterator_next(tests); oval_test_to_dom(test, doc, tests_node); } } oval_test_iterator_free(tests); /* Report objects */ struct oval_object_iterator *objects = oval_definition_model_get_objects(definition_model); if (oval_object_iterator_has_more(objects)) { xmlNode *objects_node = xmlNewTextChild(root_node, ns_defntns, BAD_CAST "objects", NULL); while(oval_object_iterator_has_more(objects)) { struct oval_object *object = oval_object_iterator_next(objects); if (oval_object_get_base_obj(object)) /* Skip internal objects */ continue; oval_object_to_dom(object, doc, objects_node); } } oval_object_iterator_free(objects); /* Report states */ struct oval_state_iterator *states = oval_definition_model_get_states(definition_model); if (oval_state_iterator_has_more(states)) { xmlNode *states_node = xmlNewTextChild(root_node, ns_defntns, BAD_CAST "states", NULL); while (oval_state_iterator_has_more(states)) { struct oval_state *state = oval_state_iterator_next(states); oval_state_to_dom(state, doc, states_node); } } oval_state_iterator_free(states); /* Report variables */ struct oval_variable_iterator *variables = oval_definition_model_get_variables(definition_model); if (oval_variable_iterator_has_more(variables)) { xmlNode *variables_node = xmlNewTextChild(root_node, ns_defntns, BAD_CAST "variables", NULL); while (oval_variable_iterator_has_more(variables)) { struct oval_variable *variable = oval_variable_iterator_next(variables); oval_variable_to_dom(variable, doc, variables_node); } } oval_variable_iterator_free(variables); return root_node; }
int main(int argc, char **argv) { struct oval_definition_model *model = NULL; model = oval_definition_model_import(argv[1]); if (model == NULL) _test_error(); struct oval_definition_iterator *definitions = oval_definition_model_get_definitions(model); if (!oval_definition_iterator_has_more(definitions)) { printf("NO DEFINITIONS FOUND\n"); return 1; } while(oval_definition_iterator_has_more(definitions)) { oval_definition_iterator_next(definitions); /* output is not needed for pusrpuse of this test, is it? */ } oval_definition_iterator_free(definitions); oval_definition_model_free(model); oscap_cleanup(); { #define TEST_CONV(v) \ do { \ oval_version_t V; \ V = oval_version_from_cstr(#v); \ if (V == OVAL_VERSION_INVALID) \ return 1; \ } while(0) #define TEST_VCMP(v1, op, v2) \ do { \ oval_version_t a, b; \ int r; \ a = oval_version_from_cstr(#v1); \ b = oval_version_from_cstr(#v2); \ r = oval_version_cmp(a, b); \ if (!(r op 0)) { \ fprintf(stderr, "%s %s %s: not true\n", \ #v1, #op, #v2); \ return 1; \ } \ } while(0) TEST_CONV(5); TEST_CONV(5.10); TEST_CONV(5.10.1); TEST_CONV(1.2.3); TEST_CONV(11.2.3); TEST_CONV(11.22.3); TEST_CONV(11.22.33); TEST_CONV(255.255.255); TEST_CONV(1.0.0); TEST_VCMP(5.10, ==, 5.10); TEST_VCMP(5.10, < , 5.10.1); TEST_VCMP(5.10.1, > , 5.10); TEST_VCMP(5.10.0, ==, 5.10); TEST_VCMP(5.4, < , 5.10); TEST_VCMP(1.0.0, ==, 1); TEST_VCMP(1.0.1, !=, 1.0.0); } return 0; }