Blame src/OVAL/oval_object.c

Packit Service 569379
/**
Packit Service 569379
 * @file oval_object.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--2014 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 "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/debug_priv.h"
Packit Service 569379
#include "common/elements.h"
Packit Service 569379
#include "public/oval_schema_version.h"
Packit Service 569379
Packit Service 569379
typedef struct oval_object {
Packit Service 569379
	struct oval_definition_model *model;
Packit Service 569379
	oval_subtype_t subtype;
Packit Service 569379
	struct oval_object *base_obj_ref;
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
	struct oval_collection *object_content;
Packit Service 569379
	struct oval_collection *behaviors;
Packit Service 569379
} oval_object_t;
Packit Service 569379
Packit Service 569379
bool oval_object_iterator_has_more(struct oval_object_iterator *oc_object)
Packit Service 569379
{
Packit Service 569379
	return oval_collection_iterator_has_more((struct oval_iterator *)
Packit Service 569379
						 oc_object);
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
struct oval_object *oval_object_iterator_next(struct oval_object_iterator
Packit Service 569379
					      *oc_object)
Packit Service 569379
{
Packit Service 569379
	return (struct oval_object *)
Packit Service 569379
	    oval_collection_iterator_next((struct oval_iterator *)oc_object);
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
void oval_object_iterator_free(struct oval_object_iterator
Packit Service 569379
			       *oc_object)
Packit Service 569379
{
Packit Service 569379
	oval_collection_iterator_free((struct oval_iterator *)oc_object);
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
oval_family_t oval_object_get_family(struct oval_object *object)
Packit Service 569379
{
Packit Service 569379
	__attribute__nonnull__(object);
Packit Service 569379
Packit Service 569379
	return ((object->subtype) / 1000) * 1000;
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
oval_subtype_t oval_object_get_subtype(struct oval_object * object)
Packit Service 569379
{
Packit Service 569379
	__attribute__nonnull__(object);
Packit Service 569379
Packit Service 569379
	return ((struct oval_object *)object)->subtype;
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
const char *oval_object_get_name(struct oval_object *object)
Packit Service 569379
{
Packit Service 569379
Packit Service 569379
	__attribute__nonnull__(object);
Packit Service 569379
Packit Service 569379
	return oval_subtype_get_text(object->subtype);
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
struct oval_string_iterator *oval_object_get_notes(struct oval_object *object)
Packit Service 569379
{
Packit Service 569379
	__attribute__nonnull__(object);
Packit Service 569379
Packit Service 569379
	return (struct oval_string_iterator *)oval_collection_iterator(object->notes);
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
char *oval_object_get_comment(struct oval_object *object)
Packit Service 569379
{
Packit Service 569379
	__attribute__nonnull__(object);
Packit Service 569379
Packit Service 569379
	return ((struct oval_object *)object)->comment;
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
char *oval_object_get_id(struct oval_object *object)
Packit Service 569379
{
Packit Service 569379
	__attribute__nonnull__(object);
Packit Service 569379
Packit Service 569379
	return ((struct oval_object *)object)->id;
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
bool oval_object_get_deprecated(struct oval_object *object)
Packit Service 569379
{
Packit Service 569379
	__attribute__nonnull__(object);
Packit Service 569379
Packit Service 569379
	return ((struct oval_object *)object)->deprecated;
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
int oval_object_get_version(struct oval_object *object)
Packit Service 569379
{
Packit Service 569379
	__attribute__nonnull__(object);
Packit Service 569379
Packit Service 569379
	return ((struct oval_object *)object)->version;
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
oval_schema_version_t oval_object_get_platform_schema_version(struct oval_object *object)
Packit Service 569379
{
Packit Service 569379
	__attribute__nonnull__(object);
Packit Service 569379
	if (object->model == NULL) {
Packit Service 569379
		return OVAL_SCHEMA_VERSION_INVALID;
Packit Service 569379
	}
Packit Service 569379
	oval_family_t family = oval_object_get_family(object);
Packit Service 569379
	const char *platform = oval_family_get_text(family);
Packit Service 569379
	return oval_definition_model_get_platform_schema_version(object->model, platform);
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
struct oval_object_content_iterator *oval_object_get_object_contents(struct
Packit Service 569379
								     oval_object
Packit Service 569379
								     *object)
Packit Service 569379
{
Packit Service 569379
	__attribute__nonnull__(object);
Packit Service 569379
Packit Service 569379
	return (struct oval_object_content_iterator *)
Packit Service 569379
	    oval_collection_iterator(object->object_content);
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
struct oval_behavior_iterator *oval_object_get_behaviors(struct oval_object *object)
Packit Service 569379
{
Packit Service 569379
	__attribute__nonnull__(object);
Packit Service 569379
Packit Service 569379
	return (struct oval_behavior_iterator *)
Packit Service 569379
	    oval_collection_iterator(object->behaviors);
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
struct oval_object *oval_object_new(struct oval_definition_model *model, const char *id)
Packit Service 569379
{
Packit Service 569379
	__attribute__nonnull__(model);
Packit Service 569379
	oval_object_t *object;
Packit Service 569379
Packit Service 569379
	object = (oval_object_t *) malloc(sizeof(oval_object_t));
Packit Service 569379
	if (object == NULL)
Packit Service 569379
		return NULL;
Packit Service 569379
Packit Service 569379
	object->comment = NULL;
Packit Service 569379
	object->id = oscap_strdup(id);
Packit Service 569379
	object->subtype = OVAL_SUBTYPE_UNKNOWN;
Packit Service 569379
	object->base_obj_ref = NULL;
Packit Service 569379
	object->deprecated = 0;
Packit Service 569379
	object->version = 0;
Packit Service 569379
	object->behaviors = oval_collection_new();
Packit Service 569379
	object->notes = oval_collection_new();
Packit Service 569379
	object->object_content = oval_collection_new();
Packit Service 569379
	object->model = model;
Packit Service 569379
Packit Service 569379
	oval_definition_model_add_object(model, object);
Packit Service 569379
Packit Service 569379
	return object;
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
struct oval_object *oval_object_clone2(struct oval_definition_model *new_model, struct oval_object *old_object, char *new_id)
Packit Service 569379
{
Packit Service 569379
	__attribute__nonnull__(old_object);
Packit Service 569379
Packit Service 569379
	struct oval_object *new_object;
Packit Service 569379
Packit Service 569379
	if (new_id == NULL)
Packit Service 569379
		new_id = old_object->id;
Packit Service 569379
Packit Service 569379
	new_object = oval_definition_model_get_object(new_model, new_id);
Packit Service 569379
	if (new_object == NULL) {
Packit Service 569379
		new_object = oval_object_new(new_model, new_id);
Packit Service 569379
		oval_object_set_comment(new_object, old_object->comment);
Packit Service 569379
		oval_object_set_subtype(new_object, old_object->subtype);
Packit Service 569379
		oval_object_set_deprecated(new_object, old_object->deprecated);
Packit Service 569379
		oval_object_set_version(new_object, old_object->version);
Packit Service 569379
Packit Service 569379
		struct oval_behavior_iterator *behaviors = oval_object_get_behaviors(old_object);
Packit Service 569379
		while (oval_behavior_iterator_has_more(behaviors)) {
Packit Service 569379
			struct oval_behavior *behavior = oval_behavior_iterator_next(behaviors);
Packit Service 569379
			oval_object_add_behavior(new_object, oval_behavior_clone(new_model, behavior));
Packit Service 569379
		}
Packit Service 569379
		oval_behavior_iterator_free(behaviors);
Packit Service 569379
		struct oval_string_iterator *notes = oval_object_get_notes(old_object);
Packit Service 569379
		while (oval_string_iterator_has_more(notes)) {
Packit Service 569379
			char *note = oval_string_iterator_next(notes);
Packit Service 569379
			oval_object_add_note(new_object, note);
Packit Service 569379
		}
Packit Service 569379
		oval_string_iterator_free(notes);
Packit Service 569379
		struct oval_object_content_iterator *object_contents = oval_object_get_object_contents(old_object);
Packit Service 569379
		while (oval_object_content_iterator_has_more(object_contents)) {
Packit Service 569379
			struct oval_object_content *object_content = oval_object_content_iterator_next(object_contents);
Packit Service 569379
			oval_object_add_object_content(new_object,
Packit Service 569379
						       oval_object_content_clone(new_model, object_content));
Packit Service 569379
		}
Packit Service 569379
		oval_object_content_iterator_free(object_contents);
Packit Service 569379
	}
Packit Service 569379
	return new_object;
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
struct oval_object *oval_object_clone(struct oval_definition_model *new_model, struct oval_object *old_object)
Packit Service 569379
{
Packit Service 569379
	return oval_object_clone2(new_model, old_object, NULL);
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
void oval_object_free(struct oval_object *object)
Packit Service 569379
{
Packit Service 569379
	if (object == NULL)
Packit Service 569379
		return;
Packit Service 569379
Packit Service 569379
	if (object->comment != NULL)
Packit Service 569379
		free(object->comment);
Packit Service 569379
	if (object->id != NULL)
Packit Service 569379
		free(object->id);
Packit Service 569379
	oval_collection_free_items(object->behaviors, (oscap_destruct_func) oval_behavior_free);
Packit Service 569379
	oval_collection_free_items(object->notes, (oscap_destruct_func) free);
Packit Service 569379
	oval_collection_free_items(object->object_content, (oscap_destruct_func) oval_object_content_free);
Packit Service 569379
Packit Service 569379
	object->comment = NULL;
Packit Service 569379
	object->id = NULL;
Packit Service 569379
	object->behaviors = NULL;
Packit Service 569379
	object->notes = NULL;
Packit Service 569379
	object->object_content = NULL;
Packit Service 569379
	free(object);
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
void oval_object_set_subtype(struct oval_object *object, oval_subtype_t subtype)
Packit Service 569379
{
Packit Service 569379
	__attribute__nonnull__(object);
Packit Service 569379
	object->subtype = subtype;
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
void oval_object_add_note(struct oval_object *object, char *note)
Packit Service 569379
{
Packit Service 569379
	__attribute__nonnull__(object);
Packit Service 569379
	oval_collection_add(object->notes, (void *)oscap_strdup(note));
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
void oval_object_set_comment(struct oval_object *object, char *comm)
Packit Service 569379
{
Packit Service 569379
	__attribute__nonnull__(object);
Packit Service 569379
	if (object->comment != NULL)
Packit Service 569379
		free(object->comment);
Packit Service 569379
	object->comment = (comm == NULL) ? NULL : oscap_strdup(comm);
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
void oval_object_set_deprecated(struct oval_object *object, bool deprecated)
Packit Service 569379
{
Packit Service 569379
	__attribute__nonnull__(object);
Packit Service 569379
	object->deprecated = deprecated;
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
void oval_object_set_version(struct oval_object *object, int version)
Packit Service 569379
{
Packit Service 569379
	__attribute__nonnull__(object);
Packit Service 569379
	object->version = version;
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
void oval_object_add_object_content(struct oval_object *object, struct oval_object_content *content)
Packit Service 569379
{
Packit Service 569379
	__attribute__nonnull__(object);
Packit Service 569379
	oval_collection_add(object->object_content, (void *)content);
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
void oval_object_add_behavior(struct oval_object *object, struct oval_behavior *behavior)
Packit Service 569379
{
Packit Service 569379
	__attribute__nonnull__(object);
Packit Service 569379
	oval_collection_add(object->behaviors, (void *)behavior);
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
static void oval_note_consume(char *text, void *object)
Packit Service 569379
{
Packit Service 569379
	oval_object_add_note(object, text);
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
static int _oval_object_parse_notes(xmlTextReaderPtr reader, struct oval_parser_context *context, void *user)
Packit Service 569379
{
Packit Service 569379
	struct oval_object *object = (struct oval_object *)user;
Packit Service 569379
	return oscap_parser_text_value(reader, &oval_note_consume, object);
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
static void oval_behavior_consume(struct oval_behavior *behavior, void *object)
Packit Service 569379
{
Packit Service 569379
	oval_object_add_behavior(object, behavior);
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
static void oval_content_consume(struct oval_object_content *content, void *object)
Packit Service 569379
{
Packit Service 569379
	oval_object_add_object_content(object, content);
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
static int _oval_object_parse_tag(xmlTextReaderPtr reader, struct oval_parser_context *context, void *user)
Packit Service 569379
{
Packit Service 569379
	struct oval_object *object = (struct oval_object *)user;
Packit Service 569379
	char *tagname = (char *)xmlTextReaderLocalName(reader);
Packit Service 569379
	xmlChar *namespace = xmlTextReaderNamespaceUri(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_object_parse_notes, object);
Packit Service 569379
	} else if (strcmp(tagname, "behaviors") == 0) {
Packit Service 569379
		return_code = oval_behavior_parse_tag(reader, context, oval_object_get_family(object), &oval_behavior_consume, object);
Packit Service 569379
	} else {
Packit Service 569379
		return_code = oval_object_content_parse_tag(reader, context, &oval_content_consume, object);
Packit Service 569379
	}
Packit Service 569379
Packit Service 569379
	if (return_code != 0) {
Packit Service 569379
		dW("Parsing of <%s> terminated by an error at line %d.", tagname, xmlTextReaderGetParserLineNumber(reader));
Packit Service 569379
	}
Packit Service 569379
Packit Service 569379
	free(tagname);
Packit Service 569379
	free(namespace);
Packit Service 569379
	return return_code;
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
/* -1 = error; 0 = OK; 1 = warning */
Packit Service 569379
int oval_object_parse_tag(xmlTextReaderPtr reader, struct oval_parser_context *context, void *usr)
Packit Service 569379
{
Packit Service 569379
	int ret;
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
	struct oval_object *object = oval_definition_model_get_new_object(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
		dE("Unknown object %s.", id);
Packit Service 569379
		ret = -1;
Packit Service 569379
		goto cleanup;
Packit Service 569379
	}
Packit Service 569379
	oval_object_set_subtype(object, subtype);
Packit Service 569379
Packit Service 569379
	comm = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "comment");
Packit Service 569379
	if (comm != NULL) {
Packit Service 569379
		oval_object_set_comment(object, comm);
Packit Service 569379
	}
Packit Service 569379
Packit Service 569379
	int deprecated = oval_parser_boolean_attribute(reader, "deprecated", 0);
Packit Service 569379
	oval_object_set_deprecated(object, deprecated);
Packit Service 569379
Packit Service 569379
	version = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "version");
Packit Service 569379
	oval_object_set_version(object, atoi(version));
Packit Service 569379
Packit Service 569379
	ret = oval_parser_parse_tag(reader, context, &_oval_object_parse_tag, object);
Packit Service 569379
Packit Service 569379
cleanup:
Packit Service 569379
	free(id);
Packit Service 569379
	free(comm);
Packit Service 569379
	free(version);
Packit Service 569379
	return ret;
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
xmlNode *oval_object_to_dom(struct oval_object *object, xmlDoc * doc, xmlNode * parent)
Packit Service 569379
{
Packit Service 569379
	xmlNode *object_node = NULL;
Packit Service 569379
Packit Service 569379
	/* skip unknown object */
Packit Service 569379
	oval_subtype_t subtype = oval_object_get_subtype(object);
Packit Service 569379
        if ( subtype == OVAL_SUBTYPE_UNKNOWN ) {
Packit Service 569379
                dE("Unknown Object %s.", oval_object_get_id(object));
Packit Service 569379
                return object_node;
Packit Service 569379
        }
Packit Service 569379
Packit Service 569379
	/* get object name */
Packit Service 569379
	const char *subtype_text = oval_subtype_get_text(subtype);
Packit Service 569379
	char *object_name = malloc(strlen(subtype_text) + 8);
Packit Service 569379
	sprintf(object_name, "%s_object", subtype_text);
Packit Service 569379
Packit Service 569379
	oval_family_t family = oval_object_get_family(object);
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
	object_node = xmlNewTextChild(parent, ns_family, BAD_CAST object_name, NULL);
Packit Service 569379
	free(object_name);
Packit Service 569379
Packit Service 569379
	char *id = oval_object_get_id(object);
Packit Service 569379
	xmlNewProp(object_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_object_get_version(object));
Packit Service 569379
	xmlNewProp(object_node, BAD_CAST "version", BAD_CAST version);
Packit Service 569379
Packit Service 569379
	char *comm = oval_object_get_comment(object);
Packit Service 569379
	if (comm)
Packit Service 569379
		xmlNewProp(object_node, BAD_CAST "comment", BAD_CAST comm);
Packit Service 569379
Packit Service 569379
	bool deprecated = oval_object_get_deprecated(object);
Packit Service 569379
	if (deprecated)
Packit Service 569379
		xmlNewProp(object_node, BAD_CAST "deprecated", BAD_CAST "true");
Packit Service 569379
Packit Service 569379
	struct oval_string_iterator *notes = oval_object_get_notes(object);
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(object_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_behavior_iterator *behaviors = oval_object_get_behaviors(object);
Packit Service 569379
	if (oval_behavior_iterator_has_more(behaviors)) {
Packit Service 569379
		xmlNode *behaviors_node = xmlNewTextChild(object_node, ns_family, BAD_CAST "behaviors", NULL);
Packit Service 569379
		while (oval_behavior_iterator_has_more(behaviors)) {
Packit Service 569379
			struct oval_behavior *behavior = oval_behavior_iterator_next(behaviors);
Packit Service 569379
			char *key = oval_behavior_get_key(behavior);
Packit Service 569379
			char *value = oval_behavior_get_value(behavior);
Packit Service 569379
			xmlNewProp(behaviors_node, BAD_CAST key, BAD_CAST value);
Packit Service 569379
		}
Packit Service 569379
	}
Packit Service 569379
	oval_behavior_iterator_free(behaviors);
Packit Service 569379
Packit Service 569379
	struct oval_object_content_iterator *contents = oval_object_get_object_contents(object);
Packit Service 569379
	int i;
Packit Service 569379
	for (i = 0; oval_object_content_iterator_has_more(contents); i++) {
Packit Service 569379
		struct oval_object_content *content = oval_object_content_iterator_next(contents);
Packit Service 569379
		oval_object_content_to_dom(content, doc, object_node);
Packit Service 569379
	}
Packit Service 569379
	oval_object_content_iterator_free(contents);
Packit Service 569379
Packit Service 569379
	return object_node;
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
struct oval_object *oval_object_create_internal(struct oval_object *obj, char *set_id)
Packit Service 569379
{
Packit Service 569379
	struct oval_object *new_obj;
Packit Service 569379
	size_t oid_len, sid_len;
Packit Service 569379
	char *new_obj_id;
Packit Service 569379
Packit Service 569379
	oid_len = strlen(obj->id);
Packit Service 569379
	set_id = strrchr(set_id, ':') + 1;
Packit Service 569379
	sid_len = strlen(set_id);
Packit Service 569379
	new_obj_id = malloc(oid_len + sid_len + 2);
Packit Service 569379
	memcpy(new_obj_id, obj->id, oid_len);
Packit Service 569379
	new_obj_id[oid_len] = 'i';
Packit Service 569379
	memcpy(new_obj_id + oid_len + 1, set_id, sid_len);
Packit Service 569379
	new_obj_id[oid_len + sid_len + 1] = '\0';
Packit Service 569379
	new_obj = oval_object_clone2(obj->model, obj, new_obj_id);
Packit Service 569379
	new_obj->base_obj_ref = obj;
Packit Service 569379
	free(new_obj_id);
Packit Service 569379
Packit Service 569379
	return new_obj;
Packit Service 569379
}
Packit Service 569379
Packit Service 569379
struct oval_object *oval_object_get_base_obj(struct oval_object *obj)
Packit Service 569379
{
Packit Service 569379
	return obj->base_obj_ref;
Packit Service 569379
}