void oval_sysent_to_dom(struct oval_sysent *sysent, xmlDoc * doc, xmlNode * parent) { struct oval_record_field_iterator *rf_itr; xmlNsPtr ent_ns = parent->ns; xmlNodePtr root_node = xmlDocGetRootElement(doc); xmlNode *sysent_tag = NULL; char *tagname = oval_sysent_get_name(sysent); char *content = oval_sysent_get_value(sysent); bool mask = oval_sysent_get_mask(sysent); /* omit the value in oval_results if mask=true */ if (mask && !xmlStrcmp(root_node->name, BAD_CAST OVAL_ROOT_ELM_RESULTS)) { sysent_tag = xmlNewTextChild(parent, ent_ns, BAD_CAST tagname, BAD_CAST ""); } else { sysent_tag = xmlNewTextChild(parent, ent_ns, BAD_CAST tagname, BAD_CAST content); } if (mask) { xmlNewProp(sysent_tag, BAD_CAST "mask", BAD_CAST "true"); } oval_datatype_t datatype_index = oval_sysent_get_datatype(sysent); if (datatype_index != OVAL_DATATYPE_STRING) { xmlNewProp(sysent_tag, BAD_CAST "datatype", BAD_CAST oval_datatype_get_text(datatype_index)); } oval_syschar_status_t status_index = oval_sysent_get_status(sysent); if (status_index != SYSCHAR_STATUS_EXISTS) { xmlNewProp(sysent_tag, BAD_CAST "status", BAD_CAST oval_syschar_status_get_text(status_index)); } rf_itr = oval_sysent_get_record_fields(sysent); if (oval_record_field_iterator_has_more(rf_itr)) { xmlNsPtr field_ns = xmlSearchNsByHref(doc, xmlDocGetRootElement(doc), OVAL_SYSCHAR_NAMESPACE); if (field_ns == NULL) { field_ns = xmlNewNs(xmlDocGetRootElement(doc), OVAL_SYSCHAR_NAMESPACE, NULL); } while (oval_record_field_iterator_has_more(rf_itr)) { struct oval_record_field *rf; rf = oval_record_field_iterator_next(rf_itr); oval_record_field_to_dom(rf, mask, doc, sysent_tag, field_ns); } } oval_record_field_iterator_free(rf_itr); }
struct oval_sysent *oval_sysent_clone(struct oval_syschar_model *new_model, struct oval_sysent *old_item) { struct oval_sysent *new_item = oval_sysent_new(new_model); char *old_value = oval_sysent_get_value(old_item); if (old_value) { oval_sysent_set_value(new_item, oscap_strdup(old_value)); } char *old_name = oval_sysent_get_name(old_item); if (old_name) { oval_sysent_set_name(new_item, oscap_strdup(old_name)); } oval_sysent_set_datatype(new_item, oval_sysent_get_datatype(old_item)); oval_sysent_set_mask(new_item, oval_sysent_get_mask(old_item)); oval_sysent_set_status(new_item, oval_sysent_get_status(old_item)); return new_item; }
static struct oval_record_field *oval_record_field_ITEM_from_sexp(SEXP_t *sexp) { struct oval_sysent *sysent; struct oval_record_field *rf; sysent = oval_sexp_to_sysent(NULL, NULL, sexp, NULL); if (sysent == NULL) return NULL; rf = oval_record_field_new(OVAL_RECORD_FIELD_ITEM); oval_record_field_set_name(rf, oval_sysent_get_name(sysent)); oval_record_field_set_value(rf, oval_sysent_get_value(sysent)); oval_record_field_set_datatype(rf, oval_sysent_get_datatype(sysent)); oval_record_field_set_mask(rf, oval_sysent_get_mask(sysent)); oval_record_field_set_status(rf, oval_sysent_get_status(sysent)); oval_sysent_free(sysent); return rf; }
static oval_result_t eval_item(struct oval_syschar_model *syschar_model, struct oval_sysitem *cur_sysitem, struct oval_state *state) { struct oval_state_content_iterator *state_contents_itr; struct oresults ste_ores; oval_operator_t operator; oval_result_t result = OVAL_RESULT_ERROR; ores_clear(&ste_ores); state_contents_itr = oval_state_get_contents(state); while (oval_state_content_iterator_has_more(state_contents_itr)) { struct oval_state_content *content; struct oval_entity *state_entity; char *state_entity_name; oval_operation_t state_entity_operation; oval_check_t entity_check; oval_existence_t check_existence; oval_result_t ste_ent_res; struct oval_sysent_iterator *item_entities_itr; struct oresults ent_ores; struct oval_status_counter counter; bool found_matching_item; if ((content = oval_state_content_iterator_next(state_contents_itr)) == NULL) { oscap_seterr(OSCAP_EFAMILY_OVAL, "OVAL internal error: found NULL state content"); goto fail; } if ((state_entity = oval_state_content_get_entity(content)) == NULL) { oscap_seterr(OSCAP_EFAMILY_OVAL, "OVAL internal error: found NULL entity"); goto fail; } if ((state_entity_name = oval_entity_get_name(state_entity)) == NULL) { oscap_seterr(OSCAP_EFAMILY_OVAL, "OVAL internal error: found NULL entity name"); goto fail; } if (oscap_streq(state_entity_name, "line") && oval_state_get_subtype(state) == (oval_subtype_t) OVAL_INDEPENDENT_TEXT_FILE_CONTENT) { /* Hack: textfilecontent_state/line shall be compared against textfilecontent_item/text. * * textfilecontent_test and textfilecontent54_test share the same syschar * (textfilecontent_item). In OVAL 5.3 and below this syschar did not hold any usable * information ('text' ent). In OVAL 5.4 textfilecontent_test was deprecated. But the * 'text' ent has been added to textfilecontent_item, making it potentially usable. */ oval_schema_version_t over = oval_state_get_platform_schema_version(state); if (oval_schema_version_cmp(over, OVAL_SCHEMA_VERSION(5.4)) >= 0) { /* The OVAL-5.3 does not have textfilecontent_item/text */ state_entity_name = "text"; } } entity_check = oval_state_content_get_ent_check(content); check_existence = oval_state_content_get_check_existence(content); state_entity_operation = oval_entity_get_operation(state_entity); ores_clear(&ent_ores); found_matching_item = false; oval_status_counter_clear(&counter); item_entities_itr = oval_sysitem_get_sysents(cur_sysitem); while (oval_sysent_iterator_has_more(item_entities_itr)) { struct oval_sysent *item_entity; oval_result_t ent_val_res; char *item_entity_name; oval_syschar_status_t item_status; item_entity = oval_sysent_iterator_next(item_entities_itr); if (item_entity == NULL) { oscap_seterr(OSCAP_EFAMILY_OVAL, "OVAL internal error: found NULL sysent"); oval_sysent_iterator_free(item_entities_itr); goto fail; } item_status = oval_sysent_get_status(item_entity); oval_status_counter_add_status(&counter, item_status); item_entity_name = oval_sysent_get_name(item_entity); if (strcmp(item_entity_name, state_entity_name)) continue; found_matching_item = true; /* copy mask attribute from state to item */ if (oval_entity_get_mask(state_entity)) oval_sysent_set_mask(item_entity,1); ent_val_res = _evaluate_sysent(syschar_model, item_entity, state_entity, state_entity_operation, content); if (ent_val_res == OVAL_RESULT_TRUE) { dI("Entity '%s'='%s' of item '%s' matches corresponding entity in state '%s'.", oval_sysent_get_name(item_entity), oval_sysent_get_value(item_entity), oval_sysitem_get_id(cur_sysitem), oval_state_get_id(state)); } if (((signed) ent_val_res) == -1) { oval_sysent_iterator_free(item_entities_itr); goto fail; } ores_add_res(&ent_ores, ent_val_res); } oval_sysent_iterator_free(item_entities_itr); if (!found_matching_item) dW("Entity name '%s' from state (id: '%s') not found in item (id: '%s').", state_entity_name, oval_state_get_id(state), oval_sysitem_get_id(cur_sysitem)); ste_ent_res = ores_get_result_bychk(&ent_ores, entity_check); ores_add_res(&ste_ores, ste_ent_res); oval_result_t cres = oval_status_counter_get_result(&counter, check_existence); ores_add_res(&ste_ores, cres); } oval_state_content_iterator_free(state_contents_itr); operator = oval_state_get_operator(state); result = ores_get_result_byopr(&ste_ores, operator); dI("Item '%s' compared to state '%s' with result %s.", oval_sysitem_get_id(cur_sysitem), oval_state_get_id(state), oval_result_get_text(result)); return result; fail: oval_state_content_iterator_free(state_contents_itr); return OVAL_RESULT_ERROR; }
static inline oval_result_t _evaluate_sysent_with_variable(struct oval_syschar_model *syschar_model, struct oval_entity *state_entity, struct oval_sysent *item_entity, oval_operation_t state_entity_operation, struct oval_state_content *content) { oval_syschar_collection_flag_t flag; oval_result_t ent_val_res; struct oval_variable *state_entity_var; if ((state_entity_var = oval_entity_get_variable(state_entity)) == NULL) { oscap_seterr(OSCAP_EFAMILY_OVAL, "OVAL internal error: found NULL variable"); return -1; } if (0 != oval_syschar_model_compute_variable(syschar_model, state_entity_var)) { return -1; } flag = oval_variable_get_collection_flag(state_entity_var); switch (flag) { case SYSCHAR_FLAG_COMPLETE: case SYSCHAR_FLAG_INCOMPLETE:{ struct oresults var_ores; struct oval_value_iterator *val_itr; ores_clear(&var_ores); val_itr = oval_variable_get_values(state_entity_var); while (oval_value_iterator_has_more(val_itr)) { struct oval_value *var_val; char *state_entity_val_text = NULL; oval_result_t var_val_res; var_val = oval_value_iterator_next(val_itr); state_entity_val_text = oval_value_get_text(var_val); if (state_entity_val_text == NULL) { dE("Found NULL variable value text."); ores_add_res(&var_ores, OVAL_RESULT_ERROR); break; } oval_datatype_t state_entity_val_datatype = oval_value_get_datatype(var_val); var_val_res = oval_ent_cmp_str(state_entity_val_text, state_entity_val_datatype, item_entity, state_entity_operation); if (var_val_res == OVAL_RESULT_ERROR) { dE("Error occured when comparing a variable '%s' value '%s' with collected item entity = '%s'", oval_variable_get_id(state_entity_var), state_entity_val_text, oval_sysent_get_value(item_entity)); } ores_add_res(&var_ores, var_val_res); } oval_value_iterator_free(val_itr); oval_check_t var_check = oval_state_content_get_var_check(content); ent_val_res = ores_get_result_bychk(&var_ores, var_check); } break; case SYSCHAR_FLAG_ERROR: case SYSCHAR_FLAG_DOES_NOT_EXIST: case SYSCHAR_FLAG_NOT_COLLECTED: case SYSCHAR_FLAG_NOT_APPLICABLE: ent_val_res = OVAL_RESULT_ERROR; break; default: ent_val_res = -1; } return ent_val_res; }