|
Packit Service |
569379 |
/**
|
|
Packit Service |
569379 |
* @file oval_test.c
|
|
Packit Service |
569379 |
* \brief Open Vulnerability and Assessment Language
|
|
Packit Service |
569379 |
*
|
|
Packit Service |
569379 |
* See more details at http://oval.mitre.org/
|
|
Packit Service |
569379 |
*/
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
/*
|
|
Packit Service |
569379 |
* Copyright 2009--2013 Red Hat Inc., Durham, North Carolina.
|
|
Packit Service |
569379 |
* All Rights Reserved.
|
|
Packit Service |
569379 |
*
|
|
Packit Service |
569379 |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
569379 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
569379 |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
569379 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
569379 |
*
|
|
Packit Service |
569379 |
* This library is distributed in the hope that it will be useful,
|
|
Packit Service |
569379 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
569379 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
569379 |
* Lesser General Public License for more details.
|
|
Packit Service |
569379 |
*
|
|
Packit Service |
569379 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
569379 |
* License along with this library; if not, write to the Free Software
|
|
Packit Service |
569379 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit Service |
569379 |
*
|
|
Packit Service |
569379 |
* Authors:
|
|
Packit Service |
569379 |
* "David Niemoller" <David.Niemoller@g2-inc.com>
|
|
Packit Service |
569379 |
*/
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
#ifdef HAVE_CONFIG_H
|
|
Packit Service |
569379 |
#include <config.h>
|
|
Packit Service |
569379 |
#endif
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
#include <stdlib.h>
|
|
Packit Service |
569379 |
#include <stdio.h>
|
|
Packit Service |
569379 |
#include <string.h>
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
#include "public/oval_types.h"
|
|
Packit Service |
569379 |
#include "oval_definitions_impl.h"
|
|
Packit Service |
569379 |
#include "adt/oval_collection_impl.h"
|
|
Packit Service |
569379 |
#include "oval_agent_api_impl.h"
|
|
Packit Service |
569379 |
#include "common/oscap_string.h"
|
|
Packit Service |
569379 |
#include "common/util.h"
|
|
Packit Service |
569379 |
#include "common/debug_priv.h"
|
|
Packit Service |
569379 |
#include "common/elements.h"
|
|
Packit Service |
569379 |
#include "common/_error.h"
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
typedef struct oval_test {
|
|
Packit Service |
569379 |
struct oval_definition_model *model;
|
|
Packit Service |
569379 |
oval_subtype_t subtype;
|
|
Packit Service |
569379 |
struct oval_collection *notes;
|
|
Packit Service |
569379 |
char *comment;
|
|
Packit Service |
569379 |
char *id;
|
|
Packit Service |
569379 |
int deprecated;
|
|
Packit Service |
569379 |
int version;
|
|
Packit Service |
569379 |
oval_existence_t existence;
|
|
Packit Service |
569379 |
oval_check_t check;
|
|
Packit Service |
569379 |
oval_operator_t state_operator;
|
|
Packit Service |
569379 |
struct oval_object *object;
|
|
Packit Service |
569379 |
struct oval_collection *states;
|
|
Packit Service |
569379 |
} oval_test_t;
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
bool oval_test_iterator_has_more(struct oval_test_iterator *oc_test)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
return oval_collection_iterator_has_more((struct oval_iterator *)
|
|
Packit Service |
569379 |
oc_test);
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
struct oval_test *oval_test_iterator_next(struct oval_test_iterator *oc_test)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
return (struct oval_test *)
|
|
Packit Service |
569379 |
oval_collection_iterator_next((struct oval_iterator *)oc_test);
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
void oval_test_iterator_free(struct oval_test_iterator *oc_test)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
oval_collection_iterator_free((struct oval_iterator *)oc_test);
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
oval_family_t oval_test_get_family(struct oval_test *test)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(test);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
return ((test->subtype) / 1000) * 1000;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
oval_subtype_t oval_test_get_subtype(struct oval_test * test)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(test);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
return test->subtype;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
struct oval_string_iterator *oval_test_get_notes(struct oval_test *test)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(test);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
return (struct oval_string_iterator *)oval_collection_iterator(test->notes);
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
char *oval_test_get_comment(struct oval_test *test)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(test);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
return test->comment;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
char *oval_test_get_id(struct oval_test *test)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(test);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
return test->id;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
bool oval_test_get_deprecated(struct oval_test * test)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(test);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
return test->deprecated;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
int oval_test_get_version(struct oval_test *test)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(test);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
return test->version;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
oval_existence_t oval_test_get_existence(struct oval_test * test)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(test);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
return test->existence;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
oval_check_t oval_test_get_check(struct oval_test * test)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(test);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
return test->check;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
oval_operator_t oval_test_get_state_operator(struct oval_test *test)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(test);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
return test->state_operator;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
struct oval_object *oval_test_get_object(struct oval_test *test)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(test);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
return test->object;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
struct oval_state_iterator *oval_test_get_states(struct oval_test *test)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(test);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
return (struct oval_state_iterator *) oval_collection_iterator(test->states);
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
char *oval_test_get_state_names(struct oval_test *test)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(test);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
struct oval_state_iterator *ste_itr = oval_test_get_states(test);
|
|
Packit Service |
569379 |
if (!oval_state_iterator_has_more(ste_itr)) {
|
|
Packit Service |
569379 |
oval_state_iterator_free(ste_itr);
|
|
Packit Service |
569379 |
return NULL;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
struct oscap_string *state_list = oscap_string_new();
|
|
Packit Service |
569379 |
oscap_string_append_char(state_list, '\'');
|
|
Packit Service |
569379 |
while (1) {
|
|
Packit Service |
569379 |
struct oval_state *ste = oval_state_iterator_next(ste_itr);
|
|
Packit Service |
569379 |
const char *ste_id = oval_state_get_id(ste);
|
|
Packit Service |
569379 |
oscap_string_append_string(state_list, ste_id);
|
|
Packit Service |
569379 |
if (!oval_state_iterator_has_more(ste_itr)) {
|
|
Packit Service |
569379 |
break;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
oscap_string_append_string(state_list, "', '");
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
oscap_string_append_char(state_list, '\'');
|
|
Packit Service |
569379 |
char *state_names = oscap_strdup(oscap_string_get_cstr(state_list));
|
|
Packit Service |
569379 |
oscap_string_free(state_list);
|
|
Packit Service |
569379 |
oval_state_iterator_free(ste_itr);
|
|
Packit Service |
569379 |
return state_names;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
struct oval_test *oval_test_new(struct oval_definition_model *model, const char *id)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(model);
|
|
Packit Service |
569379 |
oval_test_t *test;
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
test = (oval_test_t *) malloc(sizeof(oval_test_t));
|
|
Packit Service |
569379 |
if (test == NULL)
|
|
Packit Service |
569379 |
return NULL;
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
test->deprecated = 0;
|
|
Packit Service |
569379 |
test->version = 0;
|
|
Packit Service |
569379 |
test->check = OVAL_CHECK_UNKNOWN;
|
|
Packit Service |
569379 |
test->existence = OVAL_EXISTENCE_UNKNOWN;
|
|
Packit Service |
569379 |
test->state_operator = OVAL_OPERATOR_AND;
|
|
Packit Service |
569379 |
test->subtype = OVAL_SUBTYPE_UNKNOWN;
|
|
Packit Service |
569379 |
test->comment = NULL;
|
|
Packit Service |
569379 |
test->id = oscap_strdup(id);
|
|
Packit Service |
569379 |
test->object = NULL;
|
|
Packit Service |
569379 |
test->states = oval_collection_new();
|
|
Packit Service |
569379 |
test->notes = oval_collection_new();
|
|
Packit Service |
569379 |
test->model = model;
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
oval_definition_model_add_test(model, test);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
return test;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
struct oval_test *oval_test_clone(struct oval_definition_model *new_model, struct oval_test *old_test) {
|
|
Packit Service |
569379 |
__attribute__nonnull__(old_test);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
struct oval_state_iterator *ste_itr;
|
|
Packit Service |
569379 |
struct oval_test *new_test = oval_definition_model_get_test(new_model, old_test->id);
|
|
Packit Service |
569379 |
if (new_test == NULL) {
|
|
Packit Service |
569379 |
new_test = oval_test_new(new_model, old_test->id);
|
|
Packit Service |
569379 |
oval_test_set_deprecated(new_test, old_test->deprecated);
|
|
Packit Service |
569379 |
oval_test_set_version(new_test, old_test->version);
|
|
Packit Service |
569379 |
oval_test_set_check(new_test, old_test->check);
|
|
Packit Service |
569379 |
oval_test_set_existence(new_test, old_test->existence);
|
|
Packit Service |
569379 |
oval_test_set_state_operator(new_test, old_test->state_operator);
|
|
Packit Service |
569379 |
oval_test_set_subtype(new_test, old_test->subtype);
|
|
Packit Service |
569379 |
oval_test_set_comment(new_test, old_test->comment);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
if (old_test->object) {
|
|
Packit Service |
569379 |
struct oval_object *object = oval_object_clone(new_model, old_test->object);
|
|
Packit Service |
569379 |
oval_test_set_object(new_test, object);
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
ste_itr = oval_test_get_states(old_test);
|
|
Packit Service |
569379 |
while (oval_state_iterator_has_more(ste_itr)) {
|
|
Packit Service |
569379 |
struct oval_state *ste;
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
ste = oval_state_iterator_next(ste_itr);
|
|
Packit Service |
569379 |
ste = oval_state_clone(new_model, ste);
|
|
Packit Service |
569379 |
oval_test_add_state(new_test, ste);
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
oval_state_iterator_free(ste_itr);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
struct oval_string_iterator *notes = oval_test_get_notes(old_test);
|
|
Packit Service |
569379 |
while (oval_string_iterator_has_more(notes)) {
|
|
Packit Service |
569379 |
char *note = oval_string_iterator_next(notes);
|
|
Packit Service |
569379 |
oval_test_add_note(new_test, note);
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
oval_string_iterator_free(notes);
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
return new_test;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
void oval_test_free(struct oval_test *test)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
if (test == NULL)
|
|
Packit Service |
569379 |
return;
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
free(test->comment);
|
|
Packit Service |
569379 |
free(test->id);
|
|
Packit Service |
569379 |
oval_collection_free_items(test->notes, free);
|
|
Packit Service |
569379 |
oval_collection_free(test->states);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
free(test);
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
void oval_test_set_deprecated(struct oval_test *test, bool deprecated)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(test);
|
|
Packit Service |
569379 |
test->deprecated = deprecated;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
void oval_test_set_version(struct oval_test *test, int version)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(test);
|
|
Packit Service |
569379 |
test->version = version;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
void oval_test_set_subtype(struct oval_test *test, oval_subtype_t subtype)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(test);
|
|
Packit Service |
569379 |
test->subtype = subtype;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
void oval_test_set_comment(struct oval_test *test, char *comm)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(test);
|
|
Packit Service |
569379 |
if (test->comment != NULL)
|
|
Packit Service |
569379 |
free(test->comment);
|
|
Packit Service |
569379 |
test->comment = oscap_strdup(comm);
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
void oval_test_set_existence(struct oval_test *test, oval_existence_t existence)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(test);
|
|
Packit Service |
569379 |
test->existence = existence;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
void oval_test_set_state_operator(struct oval_test *test, oval_operator_t state_operator)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(test);
|
|
Packit Service |
569379 |
test->state_operator = state_operator;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
void oval_test_set_check(struct oval_test *test, oval_check_t check)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(test);
|
|
Packit Service |
569379 |
test->check = check;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
void oval_test_set_object(struct oval_test *test, struct oval_object *object)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(test);
|
|
Packit Service |
569379 |
test->object = object;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
void oval_test_add_state(struct oval_test *test, struct oval_state *state)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(test);
|
|
Packit Service |
569379 |
oval_collection_add(test->states, state);
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
void oval_test_add_note(struct oval_test *test, char *note)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
__attribute__nonnull__(test);
|
|
Packit Service |
569379 |
oval_collection_add(test->notes, (void *)oscap_strdup(note));
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
static void _oval_test_parse_notes_consumer(char *text, void *test)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
oval_test_add_note(test, text);
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
static int _oval_test_parse_notes(xmlTextReaderPtr reader, struct oval_parser_context *context, void *user)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
struct oval_test *test = (struct oval_test *)user;
|
|
Packit Service |
569379 |
return oscap_parser_text_value(reader, &_oval_test_parse_notes_consumer, test);
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
static int _oval_test_parse_tag(xmlTextReaderPtr reader, struct oval_parser_context *context, void *user)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
struct oval_test *test = (struct oval_test *)user;
|
|
Packit Service |
569379 |
char *tagname = (char *)xmlTextReaderLocalName(reader);
|
|
Packit Service |
569379 |
int return_code = 0;
|
|
Packit Service |
569379 |
if ((strcmp(tagname, "notes") == 0)) {
|
|
Packit Service |
569379 |
return_code = oval_parser_parse_tag(reader, context, &_oval_test_parse_notes, test);
|
|
Packit Service |
569379 |
} else if ((strcmp(tagname, "object") == 0)) {
|
|
Packit Service |
569379 |
char *object_ref = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "object_ref");
|
|
Packit Service |
569379 |
if (object_ref != NULL) {
|
|
Packit Service |
569379 |
struct oval_definition_model *model = context->definition_model;
|
|
Packit Service |
569379 |
struct oval_object *object = oval_definition_model_get_new_object(model, object_ref);
|
|
Packit Service |
569379 |
free(object_ref);
|
|
Packit Service |
569379 |
object_ref = NULL;
|
|
Packit Service |
569379 |
oval_test_set_object(test, object);
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
} else if ((strcmp(tagname, "state") == 0)) {
|
|
Packit Service |
569379 |
char *state_ref = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "state_ref");
|
|
Packit Service |
569379 |
if (state_ref != NULL) {
|
|
Packit Service |
569379 |
struct oval_definition_model *model = context->definition_model;
|
|
Packit Service |
569379 |
struct oval_state *state = oval_definition_model_get_new_state(model, state_ref);
|
|
Packit Service |
569379 |
oval_test_add_state(test, state);
|
|
Packit Service |
569379 |
free(state_ref);
|
|
Packit Service |
569379 |
state_ref = NULL;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
} else {
|
|
Packit Service |
569379 |
dW("Skipping tag <%s>.", tagname);
|
|
Packit Service |
569379 |
return_code = oval_parser_skip_tag(reader, context);
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
free(tagname);
|
|
Packit Service |
569379 |
return return_code;
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
int oval_test_parse_tag(xmlTextReaderPtr reader, struct oval_parser_context *context, void *usr)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
int ret = 0;
|
|
Packit Service |
569379 |
char *comm = NULL;
|
|
Packit Service |
569379 |
char *version = NULL;
|
|
Packit Service |
569379 |
struct oval_definition_model *model = context->definition_model;
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
char *id = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "id");
|
|
Packit Service |
569379 |
if (id == NULL) {
|
|
Packit Service |
569379 |
oscap_seterr(OSCAP_EFAMILY_OVAL, "Found test element without id attribute.");
|
|
Packit Service |
569379 |
return -1;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
struct oval_test *test = oval_definition_model_get_new_test(model, id);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
oval_subtype_t subtype = oval_subtype_parse(reader);
|
|
Packit Service |
569379 |
if ( subtype == OVAL_SUBTYPE_UNKNOWN) {
|
|
Packit Service |
569379 |
oscap_seterr(OSCAP_EFAMILY_OVAL, "Unknown test type %s.", id);
|
|
Packit Service |
569379 |
ret = -1;
|
|
Packit Service |
569379 |
goto cleanup;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
oval_test_set_subtype(test, subtype);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
oval_operator_t ste_operator = oval_operator_parse(reader, "state_operator", OVAL_OPERATOR_AND);
|
|
Packit Service |
569379 |
oval_test_set_state_operator(test, ste_operator);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
oval_check_t check = oval_check_parse(reader, "check", OVAL_CHECK_UNKNOWN);
|
|
Packit Service |
569379 |
if (check == OVAL_CHECK_NONE_EXIST) {
|
|
Packit Service |
569379 |
dW("The 'none exist' CheckEnumeration value has been deprecated. "
|
|
Packit Service |
569379 |
"Converted to check='none satisfy' and check_existence='none exist'.");
|
|
Packit Service |
569379 |
oval_test_set_check(test, OVAL_CHECK_NONE_SATISFY);
|
|
Packit Service |
569379 |
oval_test_set_existence(test, OVAL_NONE_EXIST);
|
|
Packit Service |
569379 |
} else {
|
|
Packit Service |
569379 |
oval_existence_t existence;
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
oval_test_set_check(test, check);
|
|
Packit Service |
569379 |
existence = oval_existence_parse(reader, "check_existence", OVAL_AT_LEAST_ONE_EXISTS);
|
|
Packit Service |
569379 |
oval_test_set_existence(test, existence);
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
comm = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "comment");
|
|
Packit Service |
569379 |
if (comm != NULL) {
|
|
Packit Service |
569379 |
oval_test_set_comment(test, comm);
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
int deprecated = oval_parser_boolean_attribute(reader, "deprecated", 0);
|
|
Packit Service |
569379 |
oval_test_set_deprecated(test, deprecated);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
version = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "version");
|
|
Packit Service |
569379 |
if (version != NULL) {
|
|
Packit Service |
569379 |
oval_test_set_version(test, atoi(version));
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
ret = oval_parser_parse_tag(reader, context, &_oval_test_parse_tag, test);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
cleanup:
|
|
Packit Service |
569379 |
free(version);
|
|
Packit Service |
569379 |
free(comm);
|
|
Packit Service |
569379 |
free(id);
|
|
Packit Service |
569379 |
return ret;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
xmlNode *oval_test_to_dom(struct oval_test *test, xmlDoc * doc, xmlNode * parent)
|
|
Packit Service |
569379 |
{
|
|
Packit Service |
569379 |
xmlNode * test_node=NULL;
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
/* skip unknown test */
|
|
Packit Service |
569379 |
oval_subtype_t subtype = oval_test_get_subtype(test);
|
|
Packit Service |
569379 |
if ( subtype == OVAL_SUBTYPE_UNKNOWN ) {
|
|
Packit Service |
569379 |
dE("Unknown Test %s.", oval_test_get_id(test));
|
|
Packit Service |
569379 |
return test_node;
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
/* get test name */
|
|
Packit Service |
569379 |
const char *subtype_text = oval_subtype_get_text(subtype);
|
|
Packit Service |
569379 |
char *test_name = malloc(strlen(subtype_text) + 6);
|
|
Packit Service |
569379 |
sprintf(test_name, "%s_test", subtype_text);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
oval_family_t family = oval_test_get_family(test);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
/* search namespace & create child */
|
|
Packit Service |
569379 |
xmlNs *ns_family = oval_family_to_namespace(family, (const char *) OVAL_DEFINITIONS_NAMESPACE, doc, parent);
|
|
Packit Service |
569379 |
test_node = xmlNewTextChild(parent, ns_family, BAD_CAST test_name, NULL);
|
|
Packit Service |
569379 |
free(test_name);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
char *id = oval_test_get_id(test);
|
|
Packit Service |
569379 |
xmlNewProp(test_node, BAD_CAST "id", BAD_CAST id);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
char version[10];
|
|
Packit Service |
569379 |
*version = '\0';
|
|
Packit Service |
569379 |
snprintf(version, sizeof(version), "%d", oval_test_get_version(test));
|
|
Packit Service |
569379 |
xmlNewProp(test_node, BAD_CAST "version", BAD_CAST version);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
oval_existence_t existence = oval_test_get_existence(test);
|
|
Packit Service |
569379 |
if (existence != OVAL_AT_LEAST_ONE_EXISTS)
|
|
Packit Service |
569379 |
xmlNewProp(test_node, BAD_CAST "check_existence", BAD_CAST oval_existence_get_text(existence));
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
oval_check_t check = oval_test_get_check(test);
|
|
Packit Service |
569379 |
xmlNewProp(test_node, BAD_CAST "check", BAD_CAST oval_check_get_text(check));
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
oval_operator_t ste_operator = oval_test_get_state_operator(test);
|
|
Packit Service |
569379 |
if (ste_operator != OVAL_OPERATOR_AND)
|
|
Packit Service |
569379 |
xmlNewProp(test_node, BAD_CAST "state_operator", BAD_CAST oval_operator_get_text(ste_operator));
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
char *comm = oval_test_get_comment(test);
|
|
Packit Service |
569379 |
xmlNewProp(test_node, BAD_CAST "comment", BAD_CAST comm);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
bool deprecated = oval_test_get_deprecated(test);
|
|
Packit Service |
569379 |
if (deprecated)
|
|
Packit Service |
569379 |
xmlNewProp(test_node, BAD_CAST "deprecated", BAD_CAST "true");
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
struct oval_string_iterator *notes = oval_test_get_notes(test);
|
|
Packit Service |
569379 |
if (oval_string_iterator_has_more(notes)) {
|
|
Packit Service |
569379 |
xmlNs *ns_definitions = xmlSearchNsByHref(doc, parent, OVAL_DEFINITIONS_NAMESPACE);
|
|
Packit Service |
569379 |
xmlNode *notes_node = xmlNewTextChild(test_node, ns_definitions, BAD_CAST "notes", NULL);
|
|
Packit Service |
569379 |
while (oval_string_iterator_has_more(notes)) {
|
|
Packit Service |
569379 |
char *note = oval_string_iterator_next(notes);
|
|
Packit Service |
569379 |
xmlNewTextChild(notes_node, ns_definitions, BAD_CAST "note", BAD_CAST note);
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
oval_string_iterator_free(notes);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
struct oval_object *object = oval_test_get_object(test);
|
|
Packit Service |
569379 |
if (object) {
|
|
Packit Service |
569379 |
xmlNode *object_node = xmlNewTextChild(test_node, ns_family, BAD_CAST "object", NULL);
|
|
Packit Service |
569379 |
xmlNewProp(object_node, BAD_CAST "object_ref", BAD_CAST oval_object_get_id(object));
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
struct oval_state_iterator *ste_itr = oval_test_get_states(test);
|
|
Packit Service |
569379 |
while (oval_state_iterator_has_more(ste_itr)) {
|
|
Packit Service |
569379 |
struct oval_state *state;
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
state = oval_state_iterator_next(ste_itr);
|
|
Packit Service |
569379 |
xmlNode *state_node = xmlNewTextChild(test_node, ns_family, BAD_CAST "state", NULL);
|
|
Packit Service |
569379 |
xmlNewProp(state_node, BAD_CAST "state_ref", BAD_CAST oval_state_get_id(state));
|
|
Packit Service |
569379 |
}
|
|
Packit Service |
569379 |
oval_state_iterator_free(ste_itr);
|
|
Packit Service |
569379 |
|
|
Packit Service |
569379 |
return test_node;
|
|
Packit Service |
569379 |
}
|