Chris PeBenito 473ea7
#include <unistd.h>
Chris PeBenito 473ea7
#include <fcntl.h>
Chris PeBenito 473ea7
#include <string.h>
Chris PeBenito 473ea7
#include <stdlib.h>
Chris PeBenito 473ea7
#include <errno.h>
Chris PeBenito 473ea7
#include <sys/xattr.h>
Chris PeBenito 473ea7
#include "selinux_internal.h"
Chris PeBenito 473ea7
#include "policy.h"
Chris PeBenito 473ea7
Chris PeBenito 473ea7
int setfilecon_raw(const char *path, security_context_t context)
Chris PeBenito 473ea7
{
Chris PeBenito 473ea7
	return setxattr(path, XATTR_NAME_SELINUX, context, strlen(context)+1, 0);
Chris PeBenito 473ea7
}
Chris PeBenito 473ea7
hidden_def(setfilecon_raw)
Chris PeBenito 473ea7
Chris PeBenito 473ea7
int setfilecon(const char *path, security_context_t context)
Chris PeBenito 473ea7
{
Chris PeBenito 473ea7
	int ret;
Chris PeBenito 473ea7
	security_context_t rcontext = context;
Chris PeBenito 473ea7
Chris PeBenito 473ea7
	if (context_translations && trans_to_raw_context(context, &rcontext))
Chris PeBenito 473ea7
		return -1;
Chris PeBenito 473ea7
Chris PeBenito 473ea7
 	ret = setfilecon_raw(path, rcontext);
Chris PeBenito 473ea7
Chris PeBenito 473ea7
	if (context_translations)
Chris PeBenito 473ea7
		freecon(rcontext);
Chris PeBenito 473ea7
Chris PeBenito 473ea7
	return ret;
Chris PeBenito 473ea7
}