Blame libselinux/src/setexeccon.c
|
Chris PeBenito |
473ea7 |
#include <unistd.h>
|
|
Chris PeBenito |
473ea7 |
#include <fcntl.h>
|
|
Chris PeBenito |
473ea7 |
#include <string.h>
|
|
Chris PeBenito |
473ea7 |
#include "selinux_internal.h"
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
int setexeccon_raw(security_context_t context)
|
|
Chris PeBenito |
473ea7 |
{
|
|
Chris PeBenito |
473ea7 |
int fd;
|
|
Chris PeBenito |
473ea7 |
ssize_t ret;
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
fd = open("/proc/self/attr/exec", O_RDWR);
|
|
Chris PeBenito |
473ea7 |
if (fd < 0)
|
|
Chris PeBenito |
473ea7 |
return -1;
|
|
Chris PeBenito |
473ea7 |
if (context)
|
|
Chris PeBenito |
473ea7 |
ret = write(fd, context, strlen(context)+1);
|
|
Chris PeBenito |
473ea7 |
else
|
|
Chris PeBenito |
473ea7 |
ret = write(fd, NULL, 0); /* clear */
|
|
Chris PeBenito |
473ea7 |
close(fd);
|
|
Chris PeBenito |
473ea7 |
if (ret < 0)
|
|
Chris PeBenito |
473ea7 |
return -1;
|
|
Chris PeBenito |
473ea7 |
else
|
|
Chris PeBenito |
473ea7 |
return 0;
|
|
Chris PeBenito |
473ea7 |
}
|
|
Chris PeBenito |
473ea7 |
hidden_def(setexeccon_raw)
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
int setexeccon(char *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 = setexeccon_raw(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 |
}
|
|
Chris PeBenito |
473ea7 |
hidden_def(setexeccon)
|