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 security_check_context_raw(const char * con)12int security_check_context_raw(const char * 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 | O_CLOEXEC); 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 security_check_context(const char * con)35int security_check_context(const char * con) 36 { 37 int ret; 38 char * rcon; 39 40 if (selinux_trans_to_raw_context(con, &rcon)) 41 return -1; 42 43 ret = security_check_context_raw(rcon); 44 45 freecon(rcon); 46 47 return ret; 48 } 49 50