Example #1
0
struct xccdf_ident * xccdf_ident_clone(const struct xccdf_ident * ident)
{
	struct xccdf_ident * clone = xccdf_ident_new();
	clone->id = oscap_strdup(ident->id);
	clone->system = oscap_strdup(ident->system);
	return clone;
}
Example #2
0
void oval_behavior_set_keyval(struct oval_behavior *behavior, const char *key, const char *value)
{
	__attribute__nonnull__(behavior);

	behavior->key = oscap_strdup(key);
	behavior->value = oscap_strdup(value);
}
Example #3
0
/* Performs a deep copy of a provided xccdf_check_export, returns a pointer to that copy */
struct xccdf_check_export *xccdf_check_export_clone(const struct xccdf_check_export* old_export)
{
	struct xccdf_check_export *new_export = xccdf_check_export_new();
	new_export->name = oscap_strdup(old_export->name);
	new_export->value = oscap_strdup(old_export->value);
	return new_export;
}
Example #4
0
/* Performs a deep copy of a provided xcdf_check_content_ref, returns a pointer to that copy */
struct xccdf_check_content_ref *xccdf_check_content_ref_clone(const struct xccdf_check_content_ref* old_ref)
{
	struct xccdf_check_content_ref *new_ref = xccdf_check_content_ref_new();
	new_ref->name = oscap_strdup(old_ref->name);
	new_ref->href = oscap_strdup(old_ref->href);
	return new_ref;
}
Example #5
0
char *oscap_path_join(const char *path1, const char *path2)
{
	if (path1 == NULL) {
		return oscap_strdup(path2);
	}
	if (path2 == NULL) {
		return oscap_strdup(path1);
	}
	size_t path1_len = strlen(path1);
	size_t path2_len = strlen(path2);
	size_t path2_shift = 0;
	while (path1_len >= 1 && path1[path1_len - 1] == PATH_SEPARATOR) {
		path1_len--;
	}
	while (path2_shift < path2_len && path2[path2_shift] == PATH_SEPARATOR) {
		path2_shift++;
	}
	path2_len -= path2_shift;
	const size_t joined_path_len = path1_len + 1 + path2_len;
	char *joined_path = malloc(joined_path_len + 1);
	strncpy(joined_path, path1, path1_len);
	joined_path[path1_len++] = PATH_SEPARATOR;
	strncpy(joined_path + path1_len, path2 + path2_shift, path2_len);
	joined_path[joined_path_len] = '\0';
	return joined_path;
}
Example #6
0
/* Performs a deep copy of a provided xccdf_check_import, returns a pointer to that copy */
struct xccdf_check_import *xccdf_check_import_clone(const struct xccdf_check_import* old_import)
{
	struct xccdf_check_import *new_import = xccdf_check_import_new();
	new_import->name = oscap_strdup(old_import->name);
	if (old_import->xpath)
		new_import->xpath = oscap_strdup(old_import->xpath);
	new_import->content = oscap_strdup(old_import->content);
	return new_import;
}
Example #7
0
struct cvss_metrics *cvss_metrics_clone(const struct cvss_metrics* met)
{
    if (met == NULL) return NULL;
    struct cvss_metrics *ret = cvss_metrics_new(met->category);
    if (ret == NULL) return NULL;
    ret->score = met->score;
    ret->source = oscap_strdup(met->source);
    ret->upgraded_from_version = oscap_strdup(met->upgraded_from_version);
    ret->generated_on_datetime = oscap_strdup(met->generated_on_datetime);
    for (size_t i = 0; i < cvss_metrics_component_num(met); ++i)
        ret->metrics.ANY[i] = met->metrics.ANY[i];
    return ret;
}
Example #8
0
void oval_entity_set_name(struct oval_entity *entity, char *name)
{
	__attribute__nonnull__(entity);
	if (entity->name != NULL)
		oscap_free(entity->name);
	entity->name = (name == NULL) ? NULL : oscap_strdup(name);
}
Example #9
0
static bool xccdf_item_parse_deps(xmlTextReaderPtr reader, struct xccdf_item *item)
{
	struct oscap_list *conflicts = NULL;
	struct oscap_list *requires = NULL;
	xccdf_deps_get(item, &conflicts, &requires);

	switch (xccdf_element_get(reader)) {
	case XCCDFE_REQUIRES:{
			struct oscap_list *reqs = oscap_list_new();
			char *ids = xccdf_attribute_copy(reader, XCCDFA_IDREF), *idsstr = ids, *id;

			while ((id = strsep(&ids, " ")) != NULL) {
				if (strcmp(id, "") == 0) continue;
				oscap_list_add(reqs, oscap_strdup(id));
			}
			if (reqs->itemcount == 0) {
				oscap_list_free(reqs, NULL);
				return false;
			}

			oscap_list_add(requires, reqs);
			free(idsstr);
			break;
		}
	case XCCDFE_CONFLICTS:
		oscap_list_add(conflicts, xccdf_attribute_copy(reader, XCCDFA_IDREF));
		break;
	default:
		assert(false);
	}

	return true;
}
Example #10
0
/* Creates a deep copy of a provided xccdf_fix, returns a pointer to that copy */
struct xccdf_fix *xccdf_fix_clone(const struct xccdf_fix *old_fix)
{
	struct xccdf_fix *new_fix = calloc(1, sizeof(struct xccdf_fix));

	new_fix->reboot = old_fix->reboot;
	new_fix->strategy = old_fix->strategy;
	new_fix->disruption = old_fix->disruption;
	new_fix->complexity = old_fix->complexity;

	new_fix->id = oscap_strdup(old_fix->id);
	new_fix->content = oscap_strdup(old_fix->content);
	new_fix->system = oscap_strdup(old_fix->system);
	new_fix->platform = oscap_strdup(old_fix->platform);

	return new_fix;
}
Example #11
0
struct xccdf_profile_note * xccdf_profile_note_clone(const struct xccdf_profile_note * note)
{
	struct xccdf_profile_note * clone = xccdf_profile_note_new();
	clone->reftag = oscap_strdup(note->reftag);
	clone->text = oscap_text_clone(note->text);
	return clone;
}
Example #12
0
struct oval_test *oval_test_new(struct oval_definition_model *model, const char *id)
{
	__attribute__nonnull__(model);
	oval_test_t *test;

	test = (oval_test_t *) oscap_alloc(sizeof(oval_test_t));
	if (test == NULL)
		return NULL;

	test->deprecated = 0;
	test->version = 0;
	test->check = OVAL_CHECK_UNKNOWN;
	test->existence = OVAL_EXISTENCE_UNKNOWN;
	test->state_operator = OVAL_OPERATOR_AND;
	test->subtype = OVAL_SUBTYPE_UNKNOWN;
	test->comment = NULL;
	test->id = oscap_strdup(id);
	test->object = NULL;
	test->states = oval_collection_new();
	test->notes = oval_collection_new();
	test->model = model;

	oval_definition_model_add_test(model, test);

	return test;
}
Example #13
0
void oval_sysent_set_value(struct oval_sysent *sysent, char *value)
{
	__attribute__nonnull__(sysent);
	if (sysent->value != NULL)
		oscap_free(sysent->value);
	sysent->value = oscap_strdup(value);
}
Example #14
0
void oval_test_set_comment(struct oval_test *test, char *comm)
{
	__attribute__nonnull__(test);
	if (test->comment != NULL)
		oscap_free(test->comment);
	test->comment = oscap_strdup(comm);
}
Example #15
0
static void _syschar_add_bindings(struct oval_syschar *sc, struct oval_string_map *vm)
{
	struct oval_iterator *var_itr;

	var_itr = oval_string_map_values(vm);
	while (oval_collection_iterator_has_more(var_itr)) {
		struct oval_variable *var;
		struct oval_value_iterator *val_itr;
		struct oval_variable_binding *binding;

		var = oval_collection_iterator_next(var_itr);
		binding = oval_variable_binding_new(var, NULL);

		val_itr = oval_variable_get_values(var);
		while (oval_value_iterator_has_more(val_itr)) {
			struct oval_value *val;
			char *txt;

			val = oval_value_iterator_next(val_itr);
			txt = oval_value_get_text(val);
			txt = oscap_strdup(txt);
			oval_variable_binding_add_value(binding, txt);
		}
		oval_value_iterator_free(val_itr);

		oval_syschar_add_variable_binding(sc, binding);
	}
	oval_collection_iterator_free(var_itr);
}
Example #16
0
void oval_message_set_text(struct oval_message *message, char *text)
{
	__attribute__nonnull__(message);
	if (message->text != NULL)
		oscap_free(message->text);
	message->text = (text == NULL) ? NULL : oscap_strdup(text);
}
Example #17
0
struct oval_record_field *oval_record_field_clone(struct oval_record_field *old_rf)
{
	struct oval_record_field *new_rf;

	switch (old_rf->record_field_type) {
	case OVAL_RECORD_FIELD_STATE:
	{
		struct oval_record_field_STATE *new_rfs, *old_rfs;

		new_rfs = oscap_alloc(sizeof(*new_rfs));
		if (new_rfs == NULL)
			return NULL;

		old_rfs = (struct oval_record_field_STATE *) old_rf;
		new_rfs->operation = old_rfs->operation;
		new_rfs->variable = old_rfs->variable;
		new_rfs->var_check = old_rfs->var_check;
		new_rfs->ent_check = old_rfs->ent_check;
		new_rf = (struct oval_record_field *) new_rfs;
		break;
	}
	case OVAL_RECORD_FIELD_ITEM:
	{
		struct oval_record_field_ITEM *new_rfi, *old_rfi;

		new_rfi = oscap_alloc(sizeof(*new_rfi));
		if (new_rfi == NULL)
			return NULL;

		old_rfi = (struct oval_record_field_ITEM *) old_rf;
		new_rfi->status = old_rfi->status;
		new_rf = (struct oval_record_field *) new_rfi;
		break;
	}
	default:
		dE("Unsupported record field type: %d.\n", old_rf->record_field_type);
		return NULL;
	}

	new_rf->record_field_type = old_rf->record_field_type;
	new_rf->name = oscap_strdup(old_rf->name);
	new_rf->value = oscap_strdup(old_rf->value);
	new_rf->datatype = old_rf->datatype;
	new_rf->mask = old_rf->mask;

	return new_rf;
}
Example #18
0
/* Performs a deep copy of a provided xccdf_check, returns a pointer to that copy */
struct xccdf_check *xccdf_check_clone(const struct xccdf_check* old_check)
{
	struct xccdf_check *new_check = calloc(1, sizeof(struct xccdf_check));

	new_check->id = oscap_strdup(old_check->id);
	new_check->system = oscap_strdup(old_check->system);
	new_check->selector = oscap_strdup(old_check->selector);
	new_check->content =  oscap_strdup(old_check->content);
	new_check->oper = old_check->oper;
	new_check->flags = old_check->flags;

	new_check->imports = oscap_list_clone(old_check->imports, (oscap_clone_func) xccdf_check_import_clone);
	new_check->exports = oscap_list_clone(old_check->exports, (oscap_clone_func) xccdf_check_export_clone);
	new_check->content_refs = oscap_list_clone(old_check->content_refs, (oscap_clone_func) xccdf_check_content_ref_clone);
	new_check->children = oscap_list_clone(old_check->children, (oscap_clone_func) xccdf_check_clone);

	return new_check;
}
Example #19
0
char *xccdf_detect_version_priv(xmlTextReader *reader)
{
	while (xmlTextReaderRead(reader) == 1 && xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT);
	const struct xccdf_version_info *ver_info = xccdf_detect_version_parser(reader);
	if (ver_info == NULL) {
		return NULL;
	}
	return oscap_strdup(xccdf_version_info_get_version(ver_info));
}
Example #20
0
struct oval_message *oval_message_clone(struct oval_message *old_message)
{
	struct oval_message *new_message = oval_message_new();
	oval_message_level_t level = oval_message_get_level(old_message);
	oval_message_set_level(new_message, level);
	char *text = oval_message_get_text(old_message);
	oval_message_set_text(new_message, oscap_strdup(text));
	return new_message;
}
Example #21
0
struct oval_value *oval_value_new(oval_datatype_t datatype, char *text_value)
{
	oval_value_t *value = (oval_value_t *) oscap_alloc(sizeof(oval_value_t));
	if (value == NULL)
		return NULL;

	value->datatype = datatype;
	value->text = oscap_strdup(text_value);
	return value;
}
Example #22
0
char *oscap_acquire_temp_dir()
{
	char *temp_dir = oscap_strdup(TEMP_DIR_TEMPLATE);
	if (mkdtemp(temp_dir) == NULL) {
		free(temp_dir);
		oscap_seterr(OSCAP_EFAMILY_GLIBC, "Could not create temp directory " TEMP_DIR_TEMPLATE ". %s", strerror(errno));
		return NULL;
	}
	return temp_dir;
}
/**
 * Allocate memory for new struct and init it with refine-rule values
 * @param rr Refine rule from profile
 * @return allocated internal refine-rule
 */
static inline struct xccdf_refine_rule_internal* _xccdf_refine_rule_internal_new_from_refine_rule(const struct xccdf_refine_rule* rr)
{
	struct xccdf_refine_rule_internal* new_rr = oscap_calloc(1, sizeof(struct xccdf_refine_rule_internal));
	if (new_rr != NULL) {
		new_rr->selector = oscap_strdup(xccdf_refine_rule_get_selector(rr));
		new_rr->weight = rr->weight;
		new_rr->role = rr->role;
		new_rr->severity = rr->severity;
	}
	return new_rr;
}
Example #24
0
struct oval_sysent *oval_sysent_clone(struct oval_syschar_model *new_model, struct oval_sysent *old_item)
{
	struct oval_sysent *new_item = oval_sysent_new(new_model);

	char *old_value = oval_sysent_get_value(old_item);
	if (old_value) {
		oval_sysent_set_value(new_item, oscap_strdup(old_value));
	}

	char *old_name = oval_sysent_get_name(old_item);
	if (old_name) {
		oval_sysent_set_name(new_item, oscap_strdup(old_name));
	}

	oval_sysent_set_datatype(new_item, oval_sysent_get_datatype(old_item));
	oval_sysent_set_mask(new_item, oval_sysent_get_mask(old_item));
	oval_sysent_set_status(new_item, oval_sysent_get_status(old_item));

	return new_item;
}
Example #25
0
struct xccdf_fixtext * xccdf_fixtext_clone(const struct xccdf_fixtext * fixtext)
{
	struct xccdf_fixtext * clone = xccdf_fixtext_new();
	clone->reboot = fixtext->reboot;
	clone->strategy = fixtext->strategy;
	clone->disruption = fixtext->disruption;
	clone->complexity = fixtext->complexity;
	clone->fixref = oscap_strdup(fixtext->fixref);
	clone->text = oscap_text_clone(fixtext->text);
	return clone;	
}
Example #26
0
void oval_agent_set_product_name(oval_agent_session_t *ag_sess, char * product_name)
{
	struct oval_generator *generator;
	ag_sess->product_name = oscap_strdup(product_name);

	generator = oval_syschar_model_get_generator(ag_sess->sys_models[0]);
	oval_generator_set_product_name(generator, product_name);

#if defined(OVAL_PROBES_ENABLED)
	generator = oval_results_model_get_generator(ag_sess->res_model);
	oval_generator_set_product_name(generator, product_name);
#endif
}
Example #27
0
oval_agent_session_t * oval_agent_new_session(struct oval_definition_model *model, const char * name) {
	oval_agent_session_t *ag_sess;
	struct oval_sysinfo *sysinfo;
	struct oval_generator *generator;
	int ret;

	dI("Started new OVAL agent.", name);

        /* Optimalization */
        oval_definition_model_optimize_by_filter_propagation(model);

	ag_sess = oscap_talloc(oval_agent_session_t);
        ag_sess->filename = oscap_strdup(name);
	ag_sess->def_model = model;
	ag_sess->cur_var_model = NULL;
	ag_sess->sys_model = oval_syschar_model_new(model);
#if defined(OVAL_PROBES_ENABLED)
	ag_sess->psess     = oval_probe_session_new(ag_sess->sys_model);
#endif

#if defined(OVAL_PROBES_ENABLED)
	/* probe sysinfo */
	ret = oval_probe_query_sysinfo(ag_sess->psess, &sysinfo);
	if (ret != 0) {
		oval_probe_session_destroy(ag_sess->psess);
		oval_syschar_model_free(ag_sess->sys_model);
		oscap_free(ag_sess);
		return NULL;
	}
#else
	/* TODO */
	sysinfo = oval_sysinfo_new(ag_sess->sys_model);
#endif /* OVAL_PROBES_ENABLED */
	oval_syschar_model_set_sysinfo(ag_sess->sys_model, sysinfo);
	oval_sysinfo_free(sysinfo);

	/* one system only */
	ag_sess->sys_models[0] = ag_sess->sys_model;
	ag_sess->sys_models[1] = NULL;
#if defined(OVAL_PROBES_ENABLED)
	ag_sess->res_model = oval_results_model_new_with_probe_session(
			model, ag_sess->sys_models, ag_sess->psess);
	generator = oval_results_model_get_generator(ag_sess->res_model);
	oval_generator_set_product_version(generator, oscap_get_version());
#endif

	ag_sess->product_name = NULL;

	return ag_sess;
}
Example #28
0
char *oscap_dirname(char *path)
{
	if (path == NULL || *path == '\0' || (strchr(path, '/') == NULL && strchr(path, '\\') == NULL)) {
		return strdup(".");
	}
	char dir[_MAX_DIR];
	char drive[_MAX_DRIVE];
	char dirname[_MAX_PATH];
	_splitpath_s(path, drive, _MAX_DRIVE, dir, _MAX_DIR, NULL, 0, NULL, 0);
	_makepath_s(dirname, _MAX_PATH, drive, dir, NULL, NULL);
	oscap_rtrim(dirname, '/');
	oscap_rtrim(dirname, '\\');
	return oscap_strdup(dirname);
}
Example #29
0
struct cpe_testexpr * cpe_testexpr_clone(struct cpe_testexpr * old_expr)
{
	struct cpe_testexpr * new_expr = cpe_testexpr_new();
	new_expr->oper = old_expr->oper;

	switch (new_expr->oper & CPE_LANG_OPER_MASK) {
	case CPE_LANG_OPER_AND:
	case CPE_LANG_OPER_OR:
		new_expr->meta.expr = oscap_list_clone(old_expr->meta.expr, (oscap_clone_func) cpe_testexpr_clone);
		break;
	case CPE_LANG_OPER_MATCH:
		new_expr->meta.cpe = cpe_name_clone(old_expr->meta.cpe);
		break;
	case CPE_LANG_OPER_CHECK:
		new_expr->meta.check.system = oscap_strdup(old_expr->meta.check.system);
		new_expr->meta.check.href = oscap_strdup(old_expr->meta.check.href);
		new_expr->meta.check.id = oscap_strdup(old_expr->meta.check.id);
		break;
	default:
		break;
	}

	return new_expr;
}
Example #30
0
char *oscap_basename(char *path)
{
#ifdef OS_WINDOWS
	char fname[_MAX_FNAME];
	char ext[_MAX_EXT];
	_splitpath_s(path, NULL, 0, NULL, 0, fname, _MAX_FNAME, ext, _MAX_EXT);
	size_t base_len = strlen(fname) + strlen(ext) + 1;
	char *base = malloc(base_len);
	strncpy(base, fname, base_len);
	strncat(base, ext, base_len - strlen(base) - 1);
	return base;
#else
	char *base = basename(path);
	return oscap_strdup(base);
#endif
}