Debian Codegraph @

libselinux/src/check_context.c

raw symbols SCIP
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
12 int 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 hidden_def(security_check_context_raw)
35
36 int security_check_context(const char * con)
37 {
38 int ret;
39 char * rcon;
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)