diff -u -r a/src/CPE/cpedict_priv.c b/src/CPE/cpedict_priv.c --- a/src/CPE/cpedict_priv.c 2009-11-10 12:50:08 -0500 +++ b/src/CPE/cpedict_priv.c 2009-11-04 09:22:19 -0500 @@ -32,7 +32,7 @@ #include #include "cpedict_priv.h" -#include "cpeuri.h" +#include "public/cpeuri.h" // for functions isspace #include diff -u -r a/src/CPE/cpedict_priv.h b/src/CPE/cpedict_priv.h --- a/src/CPE/cpedict_priv.h 2009-11-10 12:50:08 -0500 +++ b/src/CPE/cpedict_priv.h 2009-11-10 13:57:06 -0500 @@ -40,7 +40,7 @@ #include #include -#include "cpeuri.h" +#include "../CPE/public/cpeuri.h" #include "../common/public/oscap.h" #include "../common/util.h" #include "../common/elements.h" diff -u -r a/src/CPE/cpelang_priv.c b/src/CPE/cpelang_priv.c --- a/src/CPE/cpelang_priv.c 2009-11-10 12:50:08 -0500 +++ b/src/CPE/cpelang_priv.c 2009-11-10 08:45:01 -0500 @@ -35,7 +35,7 @@ #include "cpelang_priv.h" #include -#include "cpelang.h" +#include "public/cpelang.h" #include "../common/util.h" #include "../common/list.h" diff -u -r a/src/CPE/cpelang_priv.h b/src/CPE/cpelang_priv.h --- a/src/CPE/cpelang_priv.h 2009-11-10 12:50:08 -0500 +++ b/src/CPE/cpelang_priv.h 2009-11-10 10:13:52 -0500 @@ -39,7 +39,7 @@ #include #include -#include "cpelang.h" +#include "public/cpelang.h" #include "../common/util.h" #include "../common/elements.h" diff -u -r a/src/CVE/cve_priv.c b/src/CVE/cve_priv.c --- a/src/CVE/cve_priv.c 2009-11-10 12:50:08 -0500 +++ b/src/CVE/cve_priv.c 2009-11-10 14:12:12 -0500 @@ -33,12 +33,9 @@ #include #include "cve_priv.h" -#include "cpelang_priv.h" -#include "cvss_priv.h" -#include "../list.h" - -#include "cvss.h" - +#include "../CPE/cpelang_priv.h" +#include "../CVSS/cvss_priv.h" +#include "../common/list.h" /***************************************************************************/ /* Variable definitions diff -u -r a/src/CVE/public/cve.h b/src/CVE/public/cve.h --- a/src/CVE/public/cve.h 2009-11-10 12:50:08 -0500 +++ b/src/CVE/public/cve.h 2009-11-10 13:58:37 -0500 @@ -38,8 +38,8 @@ #define _CVE_H_ #include -#include "oscap.h" -#include "cpeuri.h" +#include "../common/public/oscap.h" +#include "../CPE/public/cpeuri.h" /** * @struct cve_reference diff -u -r a/src/OVAL/oval_component.c b/src/OVAL/oval_component.c --- a/src/OVAL/oval_component.c 2009-11-10 12:50:08 -0500 +++ b/src/OVAL/oval_component.c 2009-11-10 13:13:33 -0500 @@ -1215,3 +1215,7 @@ return component_node; } + +void oval_component_evaluate(struct oval_component *component, struct oval_string_map *map){ + fprintf(stderr, "TODO: implement oval_component_evaluate"); +} diff -u -r a/src/OVAL/oval_definitions_impl.h b/src/OVAL/oval_definitions_impl.h --- a/src/OVAL/oval_definitions_impl.h 2009-11-10 12:50:08 -0500 +++ b/src/OVAL/oval_definitions_impl.h 2009-11-10 13:14:27 -0500 @@ -35,6 +35,7 @@ #include "public/oval_definitions.h" #include "oval_parser_impl.h" #include "oval_agent_api_impl.h" +#include "oval_string_map_impl.h" #include "../common/util.h" OSCAP_HIDDEN_START; @@ -171,6 +172,7 @@ xmlNode *oval_value_to_dom(struct oval_value *, xmlDoc *, xmlNode *); struct oval_component *oval_component_clone(struct oval_component *, struct oval_definition_model *); +void oval_component_evaluate(struct oval_component *component, struct oval_string_map *map); typedef void (*oval_component_consumer) (struct oval_component *, void *); int oval_component_parse_tag(xmlTextReaderPtr, struct oval_parser_context *, oval_component_consumer, void *); diff -u -r a/src/OVAL/oval_enumerations.c b/src/OVAL/oval_enumerations.c --- a/src/OVAL/oval_enumerations.c 2009-11-10 12:50:08 -0500 +++ b/src/OVAL/oval_enumerations.c 2009-11-10 13:10:03 -0500 @@ -286,6 +286,17 @@ return oval_enumeration_get_text(OVAL_OPERATOR_MAP, operator); } +static const struct oscap_string_map OVAL_VARIABLE_TYPE_MAP[] = { + { OVAL_VARIABLE_CONSTANT, "constant_variable"}, + { OVAL_VARIABLE_EXTERNAL, "external_variable"}, + { OVAL_VARIABLE_LOCAL, "local_variable"}, + { OVAL_ENUMERATION_INVALID, NULL } +}; +const char* oval_variable_type_get_text(oval_variable_type_t type) +{ + return oval_enumeration_get_text(OVAL_VARIABLE_TYPE_MAP, type); +} + static const struct oscap_string_map OVAL_FAMILY_MAP[] = { { OVAL_FAMILY_AIX, "aix" }, { OVAL_FAMILY_APACHE, "apache" }, @@ -304,6 +315,8 @@ { OVAL_ENUMERATION_INVALID, NULL } }; + + oval_family_t oval_family_parse(xmlTextReaderPtr reader) { char *namespace = (char*) xmlTextReaderNamespaceUri(reader); diff -u -r a/src/OVAL/oval_variable.c b/src/OVAL/oval_variable.c --- a/src/OVAL/oval_variable.c 2009-11-10 12:50:08 -0500 +++ b/src/OVAL/oval_variable.c 2009-11-10 12:59:11 -0500 @@ -43,18 +43,8 @@ int deprecated; oval_variable_type_t type; oval_datatype_t datatype; - void *extension; -} oval_variable_t; - -typedef struct oval_variable_CONEXT { - char *id; - char *comment; - int version; - int deprecated; - oval_variable_type_t type; - oval_datatype_t datatype; - struct oval_string_map *values; //type==OVAL_VARIABLE_CONSTANT/EXTERNAL -} oval_variable_CONEXT_t; + struct oval_string_map *values; +} oval_variable_t, oval_variable_CONEXT_t; typedef struct oval_variable_LOCAL { char *id; @@ -63,6 +53,7 @@ int deprecated; oval_variable_type_t type; oval_datatype_t datatype; + struct oval_string_map *values; struct oval_component *component; //type==OVAL_VARIABLE_LOCAL } oval_variable_LOCAL_t; @@ -120,17 +111,20 @@ struct oval_value_iterator *oval_variable_get_values(struct oval_variable *variable) { - //type==OVAL_VARIABLE_CONSTANT or OVAL_VARIABLE_EXTERNAL - struct oval_value_iterator *values = NULL; - oval_variable_type_t type = oval_variable_get_type(variable); - if (type == OVAL_VARIABLE_EXTERNAL || type==OVAL_VARIABLE_CONSTANT) { - oval_variable_CONEXT_t *constant = - (oval_variable_CONEXT_t *) variable; - values = - (struct oval_value_iterator *) - oval_string_map_values(constant->values); + struct oval_string_map *value_map = variable->values; + if(value_map==NULL){//if variable values are NULL this is a LOCAL variable + variable->values = oval_string_map_new(); + struct oval_component *component = oval_variable_get_component(variable); + if(component){ + oval_component_evaluate(component, variable->values); + }else fprintf(stderr, + "WARNING: NULL component bound to variable\n" + " variable type = %s\n" + " variable id = %s\n" + " codeloc = %s(%d)\n", + oval_variable_type_get_text(variable->type), oval_variable_get_id(variable), __FILE__, __LINE__); } - return values; + return (value_map)?(struct oval_value_iterator *)oval_string_map_values(variable->values):NULL; } struct oval_component *oval_variable_get_component(struct oval_variable *variable) @@ -145,9 +139,15 @@ return component; } -static void _set_oval_variable_type - (struct oval_variable *variable, oval_variable_type_t type) + + struct oval_variable *oval_variable_new(char *id, oval_variable_type_t type) { + oval_variable_t *variable = (oval_variable_t *)(type==OVAL_VARIABLE_LOCAL) + ?malloc(sizeof(oval_variable_LOCAL_t)) + :malloc(sizeof(oval_variable_CONEXT_t)); + variable->id = strdup(id); + variable->comment = NULL; + variable->datatype = OVAL_DATATYPE_UNKNOWN; variable->type = type; switch(type) { @@ -157,40 +157,16 @@ = (oval_variable_CONEXT_t *)variable; conext->values = oval_string_map_new(); }break; - default: variable->extension = NULL; + case OVAL_VARIABLE_LOCAL:{ + oval_variable_LOCAL_t *local + = (oval_variable_LOCAL_t *)variable; + local->component = NULL; + local->values = NULL; + } } -} - - struct oval_variable *oval_variable_new(char *id, oval_variable_type_t type) -{ - oval_variable_t *variable = - (oval_variable_t *) malloc(sizeof(oval_variable_t)); - variable->id = strdup(id); - variable->comment = NULL; - variable->datatype = OVAL_DATATYPE_UNKNOWN; - _set_oval_variable_type(variable, type); return variable; } -void _oval_variable_clone_CONEXT - (struct oval_variable *new_variable, struct oval_variable *old_variable) -{ - struct oval_value_iterator *values = oval_variable_get_values(old_variable); - while(oval_value_iterator_has_more(values)){ - struct oval_value *value = oval_value_iterator_next(values); - oval_variable_add_value(new_variable, oval_value_clone(value)); - } - oval_value_iterator_free(values); -} - -void _oval_variable_clone_LOCAL - (struct oval_variable *new_variable, struct oval_variable *old_variable, - struct oval_definition_model *model) -{ - struct oval_component *component = oval_variable_get_component(old_variable); - oval_variable_set_component(new_variable, oval_component_clone(component, model)); -} - struct oval_variable *oval_variable_clone (struct oval_variable *old_variable, struct oval_definition_model *model) { @@ -203,14 +179,21 @@ oval_variable_set_deprecated(new_variable, old_variable->deprecated); oval_variable_set_datatype (new_variable, old_variable->datatype); - switch(new_variable->type) - { - case OVAL_VARIABLE_EXTERNAL: - case OVAL_VARIABLE_CONSTANT: _oval_variable_clone_CONEXT(new_variable, old_variable);break; - case OVAL_VARIABLE_LOCAL : _oval_variable_clone_LOCAL (new_variable, old_variable, model);break; - default: /*NOOP*/break; + if(old_variable->values){ + struct oval_value_iterator *old_values = (struct oval_value_iterator *)oval_string_map_values(old_variable->values); + if(new_variable->values==NULL)new_variable->values = oval_string_map_new(); + while(oval_value_iterator_has_more(old_values)){ + struct oval_value *value = oval_value_iterator_next(old_values); + char *text = oval_value_get_text(value); + oval_string_map_put(new_variable->values, text, (void *)value); + } + oval_value_iterator_free(old_values); } + if(new_variable->type==OVAL_VARIABLE_LOCAL){ + struct oval_component *component = oval_variable_get_component(old_variable); + oval_variable_set_component(new_variable, oval_component_clone(component, model)); + } oval_definition_model_add_variable(model, new_variable); } return new_variable; @@ -222,26 +205,15 @@ if (variable){ if (variable->id)free(variable->id); if (variable->comment)free(variable->comment); - if (variable->extension != NULL) { - switch (variable->type) { - case OVAL_VARIABLE_LOCAL:{ - oval_variable_LOCAL_t *local - = (oval_variable_LOCAL_t *)variable; - if(local->component) - oval_component_free(local->component); - local->component = NULL; - } - break; - case OVAL_VARIABLE_EXTERNAL: - case OVAL_VARIABLE_CONSTANT:{ - oval_variable_CONEXT_t *conext - = (oval_variable_CONEXT_t *)variable; - oval_string_map_free - (conext->values, (oscap_destruct_func)oval_value_free); - conext->values = NULL; - } break; - case OVAL_VARIABLE_UNKNOWN: break; - } + oval_variable_CONEXT_t *conext = (oval_variable_CONEXT_t *)variable; + oval_string_map_free(conext->values, (oscap_destruct_func)oval_value_free); + conext->values = NULL; + if(variable->type==OVAL_VARIABLE_LOCAL){ + oval_variable_LOCAL_t *local + = (oval_variable_LOCAL_t *)variable; + if(local->component) + oval_component_free(local->component); + local->component = NULL; } variable->comment = NULL; variable->id = NULL; @@ -278,10 +250,8 @@ { //type==OVAL_VARIABLE_CONSTANT if (variable->type == OVAL_VARIABLE_CONSTANT || variable->type == OVAL_VARIABLE_EXTERNAL) { - oval_variable_CONEXT_t *conext = - (oval_variable_CONEXT_t *) variable; char *text = oval_value_get_text(value); - oval_string_map_put(conext->values, text, (void *)value); + oval_string_map_put(variable->values, text, (void *)value); } } @@ -369,9 +339,6 @@ } char *id = (char*) xmlTextReaderGetAttribute(reader, BAD_CAST "id"); struct oval_variable *variable = get_oval_variable_new(model, id, type); - if(variable->type==OVAL_VARIABLE_UNKNOWN){ - _set_oval_variable_type(variable, type); - } free(id);id = variable->id; char *comm = (char*) xmlTextReaderGetAttribute(reader, BAD_CAST "comment"); diff -u -r a/src/OVAL/probes/SEAP/public/sexp-manip.h b/src/OVAL/probes/SEAP/public/sexp-manip.h --- a/src/OVAL/probes/SEAP/public/sexp-manip.h 2009-11-10 12:50:08 -0500 +++ b/src/OVAL/probes/SEAP/public/sexp-manip.h 2009-11-09 10:22:00 -0500 @@ -32,11 +32,11 @@ * Daniel Kopecek */ -#ifndef __STUB_PROBE #pragma once #ifndef SEXP_MANIP_H #define SEXP_MANIP_H + #include #include #include @@ -439,9 +439,9 @@ SEXP_t *SEXP_listit_seek (SEXP_it_t *it, uint32_t n); void SEXP_listit_free (SEXP_it_t *it); +# define __XC(a,b) __CONCAT(a,b) #if __STDC_VERSION__ >= 199901L # include -# define __XC(a,b) __CONCAT(a,b) /* TODO: use alloca & softref_r here */ /** @@ -462,6 +462,26 @@ #define SEXP_sublist_foreach(var, list, beg, end) \ for (uint32_t __XC(i,__LINE__) = (beg); __XC(i,__LINE__) <= ((size_t)(end)) && ((var) = SEXP_list_nth (list, __XC(i,__LINE__))) != NULL; ++__XC(i,__LINE__), SEXP_free (var)) +#else + +/** + * Iterate through a list, assigning each element to a variable. + * @param var the var variable is assigned one value from the list in each cycle + * @param list the list the loop iterates through + */ +#define SEXP_list_foreach(var, list) \ + uint32_t __XC(i,__LINE__);for (__XC(i,__LINE__) = 1; ((var) = SEXP_list_nth (list, __XC(i,__LINE__))) != NULL; ++__XC(i,__LINE__), SEXP_free (var)) + +/** + * Iterate through a sublist, assigning each element to a variable. + * @param var the var variable is assigned one value from the list in each cycle + * @param list the list the loop iterates through + * @param beg the index of the first element of the sublist + * @param end the index of the last element of the sublist + */ +#define SEXP_sublist_foreach(var, list, beg, end) \ + uint32_t __XC(i,__LINE__);for (__XC(i,__LINE__) = (beg); __XC(i,__LINE__) <= ((size_t)(end)) && ((var) = SEXP_list_nth (list, __XC(i,__LINE__))) != NULL; ++__XC(i,__LINE__), SEXP_free (var)) + #endif /* __STDC_VERSION__ >= 199901L */ /* @@ -550,4 +570,3 @@ #endif #endif /* SEXP_MANIP_H */ -#endif