|
Packit Service |
10cefc |
#include <unistd.h>
|
|
Packit Service |
10cefc |
#include <fcntl.h>
|
|
Packit Service |
10cefc |
#include <string.h>
|
|
Packit Service |
10cefc |
#include <stdlib.h>
|
|
Packit Service |
10cefc |
#include <errno.h>
|
|
Packit Service |
10cefc |
#include <sys/xattr.h>
|
|
Packit Service |
10cefc |
#include "selinux_internal.h"
|
|
Packit Service |
10cefc |
#include "policy.h"
|
|
Packit Service |
10cefc |
|
|
Packit Service |
10cefc |
int fsetfilecon_raw(int fd, const char * context)
|
|
Packit Service |
10cefc |
{
|
|
Packit Service |
10cefc |
int rc;
|
|
Packit Service |
10cefc |
if (! context) {
|
|
Packit Service |
10cefc |
errno=EINVAL;
|
|
Packit Service |
10cefc |
return -1;
|
|
Packit Service |
10cefc |
}
|
|
Packit Service |
10cefc |
rc = fsetxattr(fd, XATTR_NAME_SELINUX, context, strlen(context) + 1, 0);
|
|
Packit Service |
10cefc |
if (rc < 0 && errno == ENOTSUP) {
|
|
Packit Service |
10cefc |
char * ccontext = NULL;
|
|
Packit Service |
10cefc |
int err = errno;
|
|
Packit Service |
10cefc |
if ((fgetfilecon_raw(fd, &ccontext) >= 0) &&
|
|
Packit Service |
10cefc |
(strcmp(context,ccontext) == 0)) {
|
|
Packit Service |
10cefc |
rc = 0;
|
|
Packit Service |
10cefc |
} else {
|
|
Packit Service |
10cefc |
errno = err;
|
|
Packit Service |
10cefc |
}
|
|
Packit Service |
10cefc |
freecon(ccontext);
|
|
Packit Service |
10cefc |
}
|
|
Packit Service |
10cefc |
return rc;
|
|
Packit Service |
10cefc |
}
|
|
Packit Service |
10cefc |
|
|
Packit Service |
10cefc |
hidden_def(fsetfilecon_raw)
|
|
Packit Service |
10cefc |
|
|
Packit Service |
10cefc |
int fsetfilecon(int fd, const char *context)
|
|
Packit Service |
10cefc |
{
|
|
Packit Service |
10cefc |
int ret;
|
|
Packit Service |
10cefc |
char * rcontext;
|
|
Packit Service |
10cefc |
|
|
Packit Service |
10cefc |
if (selinux_trans_to_raw_context(context, &rcontext))
|
|
Packit Service |
10cefc |
return -1;
|
|
Packit Service |
10cefc |
|
|
Packit Service |
10cefc |
ret = fsetfilecon_raw(fd, rcontext);
|
|
Packit Service |
10cefc |
|
|
Packit Service |
10cefc |
freecon(rcontext);
|
|
Packit Service |
10cefc |
|
|
Packit Service |
10cefc |
return ret;
|
|
Packit Service |
10cefc |
}
|