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 fsetfilecon_raw(int fd, security_context_t context)
Chris PeBenito 473ea7
{
Chris PeBenito 473ea7
	return fsetxattr(fd, 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 fsetfilecon(int fd, 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 = fsetfilecon_raw(fd, 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
}