diff options
Diffstat (limited to 'libselinux/src/check_context.c')
-rw-r--r-- | libselinux/src/check_context.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/libselinux/src/check_context.c b/libselinux/src/check_context.c new file mode 100644 index 00000000..0e8fb864 --- /dev/null +++ b/libselinux/src/check_context.c @@ -0,0 +1,51 @@ +#include <unistd.h> +#include <sys/types.h> +#include <fcntl.h> +#include <stdlib.h> +#include <errno.h> +#include <string.h> +#include <stdio.h> +#include "selinux_internal.h" +#include "policy.h" +#include <limits.h> + +int security_check_context_raw(security_context_t con) +{ + char path[PATH_MAX]; + int fd, ret; + + if (!selinux_mnt) { + errno = ENOENT; + return -1; + } + + snprintf(path, sizeof path, "%s/context", selinux_mnt); + fd = open(path, O_RDWR); + if (fd < 0) + return -1; + + ret = write(fd, con, strlen(con) + 1); + close(fd); + if (ret < 0) + return -1; + return 0; +} + +hidden_def(security_check_context_raw) + +int security_check_context(security_context_t con) +{ + int ret; + security_context_t rcon = con; + + if (selinux_trans_to_raw_context(con, &rcon)) + return -1; + + ret = security_check_context_raw(rcon); + + freecon(rcon); + + return ret; +} + +hidden_def(security_check_context) |