blob: ac4cb40fe98f191701760db36166306530fc2e43 [file] [log] [blame]
Stephen Smalleyf0740362012-01-04 12:30:47 -05001#include <unistd.h>
2#include <sys/types.h>
3#include <fcntl.h>
4#include <stdlib.h>
5#include <errno.h>
6#include <string.h>
7#include <stdio.h>
8#include "selinux_internal.h"
9#include "policy.h"
10#include <limits.h>
11
12int security_check_context(const security_context_t con)
13{
14 char path[PATH_MAX];
15 int fd, ret;
16
17 if (!selinux_mnt) {
18 errno = ENOENT;
19 return -1;
20 }
21
22 snprintf(path, sizeof path, "%s/context", selinux_mnt);
23 fd = open(path, O_RDWR);
24 if (fd < 0)
25 return -1;
26
27 ret = write(fd, con, strlen(con) + 1);
28 close(fd);
29 if (ret < 0)
30 return -1;
31 return 0;
32}
33