struct oval_entity *oval_entity_clone(struct oval_definition_model *new_model, struct oval_entity *old_entity) { struct oval_entity *new_entity = oval_entity_new(new_model); oval_datatype_t datatype = oval_entity_get_datatype(old_entity); oval_entity_set_datatype(new_entity, datatype); int mask = oval_entity_get_mask(old_entity); oval_entity_set_mask(new_entity, mask); bool xsi_nil = oval_entity_get_xsi_nil(old_entity); oval_entity_set_xsi_nil(new_entity, xsi_nil); char *name = oval_entity_get_name(old_entity); oval_entity_set_name(new_entity, name); oval_operation_t operation = oval_entity_get_operation(old_entity); oval_entity_set_operation(new_entity, operation); oval_entity_type_t type = oval_entity_get_type(old_entity); oval_entity_set_type(new_entity, type); struct oval_value *value = oval_entity_get_value(old_entity); if (value) { oval_entity_set_value(new_entity, oval_value_clone(value)); } struct oval_variable *old_variable = oval_entity_get_variable(old_entity); if (old_variable) { oval_entity_set_variable(new_entity, oval_variable_clone(new_model, old_variable)); } oval_entity_varref_type_t reftype = oval_entity_get_varref_type(old_entity); oval_entity_set_varref_type(new_entity, reftype); return new_entity; }
//typedef void (*oval_entity_consumer)(struct oval_entity_node*, void*); int oval_entity_parse_tag(xmlTextReaderPtr reader, struct oval_parser_context *context, oscap_consumer_func consumer, void *user) { __attribute__nonnull__(context); struct oval_entity *entity = oval_entity_new(context->definition_model); int return_code = 0; oval_datatype_t datatype = oval_datatype_parse(reader, "datatype", OVAL_DATATYPE_STRING); oval_operation_t operation = oval_operation_parse(reader, "operation", OVAL_OPERATION_EQUALS); int mask = oval_parser_boolean_attribute(reader, "mask", 0); char *nil_attr = (char *) xmlTextReaderGetAttributeNs(reader, BAD_CAST "nil", OSCAP_XMLNS_XSI); int xsi_nil = oscap_streq(nil_attr, "true") != 0; xmlFree(nil_attr); oval_entity_type_t type = OVAL_ENTITY_TYPE_UNKNOWN; //The value of the type field vs. the complexity of extracting type is arguable char *varref = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "var_ref"); struct oval_value *value = NULL; struct oval_variable *variable; char *name = (char *)xmlTextReaderLocalName(reader); oval_entity_varref_type_t varref_type; if (strcmp(name, "var_ref") == 0) { //special case for <var_ref> if (varref == NULL) { struct oval_definition_model *model = context->definition_model; varref_type = OVAL_ENTITY_VARREF_ELEMENT; struct oval_consume_varref_context ctx = {.model = model, .variable = &variable, .value = &value}; return_code = oscap_parser_text_value(reader, &oval_consume_varref, &ctx); } else { varref_type = OVAL_ENTITY_VARREF_ATTRIBUTE; struct oval_definition_model *model = context->definition_model; oval_schema_version_t version = oval_definition_model_get_core_schema_version(model); if (oval_schema_version_cmp(version, OVAL_SCHEMA_VERSION(5.6)) > 0) { oscap_seterr(OSCAP_EFAMILY_OVAL, "The var_ref attribute for the var_ref entity " "of a variable_object is prohibited since OVAL 5.6. Use plain " "var_ref instead."); } variable = oval_definition_model_get_variable(model, varref); if (variable == NULL) { oscap_seterr(OSCAP_EFAMILY_OVAL, "Could not found variable '%s' referenced by var_ref element.", varref); return_code = 1; } else { oscap_free(varref); varref = NULL; value = NULL; } } } else if (varref == NULL) {
static SEXP_t *oval_record_field_STATE_to_sexp(struct oval_record_field *rf) { struct oval_entity *rf_ent; struct oval_variable *var; oval_check_t ochk; oval_datatype_t dt; SEXP_t *rf_sexp, *r0; rf_ent = oval_entity_new(NULL); oval_entity_set_name(rf_ent, oval_record_field_get_name(rf)); oval_entity_set_operation(rf_ent, oval_record_field_get_operation(rf)); dt = oval_record_field_get_datatype(rf); oval_entity_set_datatype(rf_ent, dt); var = oval_record_field_get_variable(rf); if (var != NULL) { oval_entity_set_varref_type(rf_ent, OVAL_ENTITY_VARREF_ATTRIBUTE); oval_entity_set_variable(rf_ent, var); } else { struct oval_value *val; val = oval_value_new(dt, oval_record_field_get_value(rf)); oval_entity_set_value(rf_ent, val); } rf_sexp = oval_entity_to_sexp(rf_ent); ochk = oval_record_field_get_var_check(rf); if (ochk != OVAL_CHECK_UNKNOWN) { probe_ent_attr_add(rf_sexp, "var_check", r0 = SEXP_number_newu_32(ochk)); SEXP_free(r0); } ochk = oval_record_field_get_ent_check(rf); if (ochk != OVAL_CHECK_UNKNOWN) { probe_ent_attr_add(rf_sexp, "entity_check", r0 = SEXP_number_newu_32(ochk)); SEXP_free(r0); } oval_entity_free(rf_ent); return rf_sexp; }