blob: 52063fac6656ae6bef357f4d1275aefd0c78c8ef [file] [log] [blame]
Joshua Brindle13cd4c82008-08-19 15:30:36 -04001#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
Stephen Smalley9eb9c932014-02-19 09:16:17 -050012int security_check_context_raw(const char * con)
Joshua Brindle13cd4c82008-08-19 15:30:36 -040013{
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
34hidden_def(security_check_context_raw)
35
Stephen Smalley9eb9c932014-02-19 09:16:17 -050036int security_check_context(const char * con)
Joshua Brindle13cd4c82008-08-19 15:30:36 -040037{
38 int ret;
Stephen Smalley9eb9c932014-02-19 09:16:17 -050039 char * rcon;
Joshua Brindle13cd4c82008-08-19 15:30:36 -040040
41 if (selinux_trans_to_raw_context(con, &rcon))
42 return -1;
43
44 ret = security_check_context_raw(rcon);
45
46 freecon(rcon);
47
48 return ret;
49}
50
51hidden_def(security_check_context)