Esempio n. 1
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;
}
Esempio n. 2
0
int oval_sysent_parse_tag(xmlTextReaderPtr reader, struct oval_parser_context *context,
			  oval_sysent_consumer consumer, void *user)
{
	int ret, mask;
	char *tagname;
	struct oval_sysent *sysent;
	oval_datatype_t datatype;
	oval_syschar_status_t status;

	__attribute__nonnull__(context);

	tagname = (char *) xmlTextReaderLocalName(reader);
	if (!strcmp("#text", tagname)) {
		xmlFree(tagname);
		return 0;
	}

	sysent = oval_sysent_new(context->syschar_model);
	oval_sysent_set_name(sysent, tagname);

	mask = oval_parser_boolean_attribute(reader, "mask", 0);
	oval_sysent_set_mask(sysent, mask);

	datatype = oval_datatype_parse(reader, "datatype", OVAL_DATATYPE_STRING);
	oval_sysent_set_datatype(sysent, datatype);

	status = oval_syschar_status_parse(reader, "status", SYSCHAR_STATUS_EXISTS);
        oval_sysent_set_status(sysent, status);

	if (datatype == OVAL_DATATYPE_RECORD)
		ret = oval_parser_parse_tag(reader, context, &_oval_sysent_parse_record_field, sysent);
	else
		ret = oval_parser_text_value(reader, context, &oval_sysent_value_consumer_, sysent);

	if (ret == 0)
		(*consumer) (sysent, user);

	return ret;
}
Esempio n. 3
0
static struct oval_sysent *oval_sexp_to_sysent(struct oval_syschar_model *model, struct oval_sysitem *item, SEXP_t * sexp, struct oval_string_map *mask_map)
{
	char *key;
	oval_syschar_status_t status;
	oval_datatype_t dt;
	struct oval_sysent *ent;

	key = probe_ent_getname(sexp);
	if (!key)
		return NULL;

	if (strcmp("message", key) == 0 && item != NULL) {
	    struct oval_message *msg;
	    oval_message_level_t lvl;
	    SEXP_t *lvl_sexp, *txt_sexp;
	    char txt[1024];

	    lvl_sexp = probe_obj_getattrval(sexp, "level");
	    lvl = SEXP_number_getu_32(lvl_sexp);

	    txt_sexp = probe_ent_getval(sexp);
	    SEXP_string_cstr_r(txt_sexp, txt, sizeof txt);

	    SEXP_vfree(lvl_sexp, txt_sexp);

	    /* TODO: sanity checks */

	    msg = oval_message_new();

	    oval_message_set_level(msg, lvl);
	    oval_message_set_text(msg, txt);
	    oval_sysitem_add_message(item, msg);

	    return (NULL);
	}

	status = probe_ent_getstatus(sexp);
	dt = probe_ent_getdatatype(sexp);

	ent = oval_sysent_new(model);
	oval_sysent_set_name(ent, key);
	oval_sysent_set_status(ent, status);
	oval_sysent_set_datatype(ent, dt);
	if (mask_map == NULL || oval_string_map_get_value(mask_map, key) == NULL)
		oval_sysent_set_mask(ent, 0);
	else
		oval_sysent_set_mask(ent, 1);

	if (status != SYSCHAR_STATUS_EXISTS)
		return ent;

	if (dt == OVAL_DATATYPE_RECORD) {
		SEXP_t *srf, *srfs;

		probe_ent_getvals(sexp, &srfs);
		SEXP_list_foreach(srf, srfs) {
			struct oval_record_field *rf;

			rf = oval_record_field_ITEM_from_sexp(srf);
			oval_sysent_add_record_field(ent, rf);
		}
		SEXP_free(srfs);
	} else {