예제 #1
0
int security_compute_av(security_context_t scon,
                        security_context_t tcon,
                        security_class_t tclass,
                        access_vector_t requested,
                        struct av_decision *avd)
{
	int ret;
	security_context_t rscon = scon;
	security_context_t rtcon = tcon;

	if (context_translations) {
		if (trans_to_raw_context(scon, &rscon))
			return -1;
		if (trans_to_raw_context(tcon, &rtcon)) {
			freecon(rscon);
			return -1;
		}
	}

 	ret = security_compute_av_raw(rscon, rtcon, tclass, requested, avd);

	if (context_translations) {
		freecon(rscon);
		freecon(rtcon);
	}

	return ret;
}
예제 #2
0
int setfilecon(const char *path, security_context_t context)
{
	int ret;
	security_context_t rcontext = context;

	if (context_translations && trans_to_raw_context(context, &rcontext))
		return -1;

 	ret = setfilecon_raw(path, rcontext);

	if (context_translations)
		freecon(rcontext);

	return ret;
}
예제 #3
0
int security_compute_relabel(security_context_t scon,
                             security_context_t tcon,
                             security_class_t tclass,
                             security_context_t *newcon)
{
	int ret;
	security_context_t rscon = scon;
	security_context_t rtcon = tcon;
	security_context_t rnewcon;

	if (context_translations) {
		if (trans_to_raw_context(scon, &rscon))
			return -1;
		if (trans_to_raw_context(tcon, &rtcon)) {
			freecon(rscon);
			return -1;
		}
	}

 	ret = security_compute_relabel_raw(rscon, rtcon, tclass, &rnewcon);

	if (context_translations) {
		freecon(rscon);
		freecon(rtcon);
		if (!ret) {
			if (raw_to_trans_context(rnewcon, newcon)) {
				*newcon = NULL;
				ret = -1;
			}
			freecon(rnewcon);
		}
	} else if (!ret)
		*newcon = rnewcon;

	return ret;
}
예제 #4
0
int selinux_trans_to_raw_context(const security_context_t trans,
				 security_context_t * rawp)
{
	if (!trans) {
		*rawp = NULL;
		return 0;
	}

	__selinux_once(once, init_context_translations);

	if (!mls_enabled) {
		*rawp = strdup(trans);
		goto out;
	}

	if (prev_t2r_trans && strcmp(prev_t2r_trans, trans) == 0) {
		*rawp = strdup(prev_t2r_raw);
	} else {
		free(prev_t2r_trans);
		prev_t2r_trans = NULL;
		free(prev_t2r_raw);
		prev_t2r_raw = NULL;
		if (trans_to_raw_context(trans, rawp))
			*rawp = strdup(trans);
		if (*rawp) {
			prev_t2r_trans = strdup(trans);
			if (!prev_t2r_trans)
				goto out;
			prev_t2r_raw = strdup(*rawp);
			if (!prev_t2r_raw) {
				free(prev_t2r_trans);
				prev_t2r_trans = NULL;
			}
		}
	}
      out:
	return *rawp ? 0 : -1;
}