Joshua Brindle | 13cd4c8 | 2008-08-19 15:30:36 -0400 | [diff] [blame] | 1 | #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 Smalley | 9eb9c93 | 2014-02-19 09:16:17 -0500 | [diff] [blame] | 12 | int security_check_context_raw(const char * con) |
Joshua Brindle | 13cd4c8 | 2008-08-19 15:30:36 -0400 | [diff] [blame] | 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 | |
| 34 | hidden_def(security_check_context_raw) |
| 35 | |
Stephen Smalley | 9eb9c93 | 2014-02-19 09:16:17 -0500 | [diff] [blame] | 36 | int security_check_context(const char * con) |
Joshua Brindle | 13cd4c8 | 2008-08-19 15:30:36 -0400 | [diff] [blame] | 37 | { |
| 38 | int ret; |
Stephen Smalley | 9eb9c93 | 2014-02-19 09:16:17 -0500 | [diff] [blame] | 39 | char * rcon; |
Joshua Brindle | 13cd4c8 | 2008-08-19 15:30:36 -0400 | [diff] [blame] | 40 | |
| 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 | |
| 51 | hidden_def(security_check_context) |