1 /* matchpathcon - get the default security context for the specified
2 * path from the file contexts configuration.
3 * based on libselinux-1.32
4 * Port to busybox: KaiGai Kohei <kaigai@kaigai.gr.jp>
9 static int print_matchpathcon(char *path, int noprint)
12 int rc = matchpathcon(path, 0, &buf);
14 bb_perror_msg("matchpathcon(%s) failed", path);
18 printf("%s\t%s\n", path, buf);
26 #define OPT_NOT_PRINT (1<<0) /* -n */
27 #define OPT_NOT_TRANS (1<<1) /* -N */
28 #define OPT_FCONTEXT (1<<2) /* -f */
29 #define OPT_PREFIX (1<<3) /* -p */
30 #define OPT_VERIFY (1<<4) /* -V */
32 int matchpathcon_main(int argc, char **argv)
36 char *fcontext, *prefix, *path;
38 opt_complementary = "-1:" /* at least one param reqd */
39 "f--p:p--f"; /* mutually exclusive */
40 opts = getopt32(argc, argv, "nNf:p:V", &fcontext, &prefix);
43 if (opts & OPT_NOT_TRANS) {
44 set_matchpathcon_flags(NOTRANS);
46 if (opts & OPT_FCONTEXT) {
47 if (matchpathcon_init(fcontext))
48 bb_perror_msg_and_die("error while processing %s", fcontext);
50 if (opts & OPT_PREFIX) {
51 if (matchpathcon_init_prefix(NULL, prefix))
52 bb_perror_msg_and_die("error while processing %s", prefix);
55 while((path = *argv++) != NULL) {
56 security_context_t con;
59 if (!(opts & OPT_VERIFY)) {
60 error += print_matchpathcon(path, opt & OPT_NOT_PRINT);
64 if (selinux_file_context_verify(path, 0)) {
65 printf("%s verified\n", path);
69 if (opts & OPT_NOT_TRANS)
70 rc = lgetfilecon_raw(path, &con);
72 rc = lgetfilecon(path, &con);
75 printf("%s has context %s, should be ", path, con);
76 error += print_matchpathcon(path, 1);
80 printf("actual context unknown: %s, should be ", strerror(errno));
81 error += print_matchpathcon(path, 1);