获取文件的extend attr: security.selinux属性:(test.c)
#include <selinux/selinux.h>
int main(){
security_context_t sc;
const char* t = "/home/sploving/test";
int ret = getfilecon(t, &sc);
if (ret < 0) printf("error");
else {
printf("%s/n", sc);
}
}
编译出错
undefined reference to 'getfilecon'
原来是少一个库文件
应该如下:
gcc -o test -lselinux test.c
./a
system_u:object_r:unconfined_home_t:s0
OK!