static int oval_varref_elm_to_sexp(void *sess, struct oval_variable *var, oval_datatype_t dt, SEXP_t **out_sexp, struct oval_syschar *syschar) { SEXP_t *val_lst; struct oval_value_iterator *val_itr; oval_syschar_collection_flag_t flag; if (oval_probe_query_variable(sess, var) != 0) return -1; flag = oval_variable_get_collection_flag(var); if (flag == SYSCHAR_FLAG_DOES_NOT_EXIST) { char msg[100]; snprintf(msg, sizeof(msg), "Referenced variable has no values (%s).", oval_variable_get_id(var)); dI("%s", msg); if (syschar != NULL) { oval_syschar_add_new_message(syschar, msg, OVAL_MESSAGE_LEVEL_WARNING); oval_syschar_set_flag(syschar, SYSCHAR_FLAG_DOES_NOT_EXIST); } return 1; } if (flag != SYSCHAR_FLAG_COMPLETE && flag != SYSCHAR_FLAG_INCOMPLETE) { *out_sexp = SEXP_list_new(NULL); return 0; } val_lst = SEXP_list_new(NULL); val_itr = oval_variable_get_values(var); while (oval_value_iterator_has_more(val_itr)) { struct oval_value *val; SEXP_t *vs; val = oval_value_iterator_next(val_itr); vs = oval_value_to_sexp(val, dt); if (vs == NULL) { oscap_seterr(OSCAP_EFAMILY_OVAL, "Failed to convert OVAL value to SEXP: " "datatype: %s, text: %s.", oval_datatype_get_text(dt), oval_value_get_text(val)); oval_value_iterator_free(val_itr); SEXP_free(val_lst); return -1; } SEXP_list_add(val_lst, vs); SEXP_free(vs); } oval_value_iterator_free(val_itr); *out_sexp = val_lst; return 0; }
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); }