예제 #1
0
파일: entcmp.c 프로젝트: swizzley/openscap
static oval_result_t probe_ent_cmp(SEXP_t * ent, SEXP_t * val2)
{
	oval_operation_t op;
	oval_datatype_t dtype;
	SEXP_t *stmp, *val1, *vals, *res_lst, *r0;
	int val_cnt, is_var;
	oval_check_t ochk;
	oval_result_t ores, result;

	ores = OVAL_RESULT_ERROR;
	result = OVAL_RESULT_ERROR;
        vals = NULL;
	val_cnt = probe_ent_getvals(ent, &vals);

	if (probe_ent_attrexists(ent, "var_ref")) {
		is_var = 1;
	} else {
		if (val_cnt != 1) {
                        SEXP_free(vals);
			return OVAL_RESULT_ERROR;
                }

		is_var = 0;
	}

	dtype = probe_ent_getdatatype(ent);
	stmp = probe_ent_getattrval(ent, "operation");
	if (stmp == NULL)
		op = OVAL_OPERATION_EQUALS;
	else
		op = SEXP_number_geti_32(stmp);
        SEXP_free(stmp);
	res_lst = SEXP_list_new(NULL);

	SEXP_list_foreach(val1, vals) {
		if (SEXP_typeof(val1) != SEXP_typeof(val2)) {
			dI("Types of values to compare don't match: val1: %d, val2: %d\n",
			   SEXP_typeof(val1), SEXP_typeof(val2));

                        SEXP_free(vals);
                        SEXP_free(val1);
                        SEXP_free(res_lst);

			return OVAL_RESULT_ERROR;
		}

		ores = probe_ent_cmp_single(val1, dtype, val2, op);

		SEXP_list_add(res_lst, r0 = SEXP_number_newi_32(ores));
                SEXP_free(r0);
	}

	if (is_var) {
		stmp = probe_ent_getattrval(ent, "var_check");
		if (stmp == NULL) {
			ochk = OVAL_CHECK_ALL;
		} else {
			ochk = SEXP_number_geti_32(stmp);
			SEXP_free(stmp);
		}

		result = probe_ent_result_bychk(res_lst, ochk);
	} else {
		result = ores;
	}

	SEXP_free(res_lst);
        SEXP_free(vals);

	return result;
}
예제 #2
0
파일: entcmp.c 프로젝트: swizzley/openscap
static oval_result_t _probe_entste_cmp_record(SEXP_t *ent_ste, SEXP_t *ent_itm)
{
	oval_result_t res;
	oval_operation_t op;
	oval_check_t ochk;
	SEXP_t *stmp, *ste_res, *ste_record_fields, *ste_rf, *itm_record_fields;
	int val_cnt;

	stmp = probe_ent_getattrval(ent_ste, "operation");
	if (stmp == NULL) {
		op = OVAL_OPERATION_EQUALS;
	} else {
		op = SEXP_number_getu(stmp);
		SEXP_free(stmp);
		if (op != OVAL_OPERATION_EQUALS)
			return OVAL_RESULT_ERROR;
	}

	val_cnt = probe_ent_getvals(ent_ste, &ste_record_fields);
	if (val_cnt <= 0) {
		SEXP_free(ste_record_fields);
		return OVAL_RESULT_ERROR;
	}
	val_cnt = probe_ent_getvals(ent_itm, &itm_record_fields);
	if (val_cnt <= 0) {
		SEXP_free(ste_record_fields);
		SEXP_free(itm_record_fields);
		return OVAL_RESULT_ERROR;
	}

	ste_res = SEXP_list_new(NULL);

	SEXP_list_foreach(ste_rf, ste_record_fields) {
		SEXP_t *itm_rf, *itm_res;
		const char *sname;
		bool matched;

		sname = probe_ent_getname(ste_rf);
		itm_res = SEXP_list_new(NULL);
		matched = false;

		SEXP_list_foreach(itm_rf, itm_record_fields) {
			const char *iname;

			iname = probe_ent_getname(itm_rf);
			if (strcmp(sname, iname)) {
				oscap_free(iname);
				continue;
			}
			oscap_free(iname);
			matched = true;

			res = probe_entste_cmp(ste_rf, itm_rf);
			/* todo: _oval_result_to_sexp() */
			stmp = SEXP_number_newu(res);
			SEXP_list_add(itm_res, stmp);
			SEXP_free(stmp);
		}

		oscap_free(sname);

		if (!matched) {
			stmp = SEXP_number_newu(OVAL_RESULT_ERROR);
			SEXP_list_add(itm_res, stmp);
			SEXP_free(stmp);
		}

		stmp = probe_ent_getattrval(ste_rf, "entity_check");
		if (stmp == NULL) {
			ochk = OVAL_CHECK_ALL;
		} else {
			ochk = SEXP_number_getu(stmp);
			SEXP_free(stmp);
		}

		res = probe_ent_result_bychk(itm_res, ochk);
		SEXP_free(itm_res);
		stmp = SEXP_number_newu(res);
		SEXP_list_add(ste_res, stmp);
		SEXP_free(stmp);
	}
예제 #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 {