merge back from tizen_2.1_smack
[framework/security/security-server.git] / src / util / smack-check.c
1 #include <sys/types.h>
2 #include <sys/stat.h>
3 #include <fcntl.h>
4 #include <unistd.h>
5
6 #include <security-server-common.h>
7 #include <smack-check.h>
8
9 int smack_runtime_check(void)
10 {
11     static int smack_present = -1;
12     if (-1 == smack_present) {
13         int fd = open("/smack/load2", O_WRONLY);
14         if (-1 == fd) {
15             SEC_SVR_DBG("%s","security-server: no smack found on device");
16             smack_present = 0;
17         } else {
18             SEC_SVR_DBG("%s","security-server: found smack on device");
19             close(fd);
20             smack_present = 1;
21         }
22     }
23     return smack_present;
24 }
25
26 int smack_check(void)
27 {
28 #ifndef SMACK_ENABLED
29     return 0;
30 #else
31     return smack_runtime_check();
32 #endif
33
34 }