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) MAIN_EXTERNALLY_VISIBLE;
33 int matchpathcon_main(int argc UNUSED_PARAM, char **argv)
37 char *fcontext, *prefix, *path;
39 opt_complementary = "-1" /* at least one param reqd */
40 ":?:f--p:p--f"; /* mutually exclusive */
41 opts = getopt32(argv, "nNf:p:V", &fcontext, &prefix);
44 if (opts & OPT_NOT_TRANS) {
45 set_matchpathcon_flags(MATCHPATHCON_NOTRANS);
47 if (opts & OPT_FCONTEXT) {
48 if (matchpathcon_init(fcontext))
49 bb_perror_msg_and_die("error while processing %s", fcontext);
51 if (opts & OPT_PREFIX) {
52 if (matchpathcon_init_prefix(NULL, prefix))
53 bb_perror_msg_and_die("error while processing %s", prefix);
56 while ((path = *argv++) != NULL) {
57 security_context_t con;
60 if (!(opts & OPT_VERIFY)) {
61 error += print_matchpathcon(path, opts & OPT_NOT_PRINT);
65 if (selinux_file_context_verify(path, 0)) {
66 printf("%s verified\n", path);
70 if (opts & OPT_NOT_TRANS)
71 rc = lgetfilecon_raw(path, &con);
73 rc = lgetfilecon(path, &con);
76 printf("%s has context %s, should be ", path, con);
77 error += print_matchpathcon(path, 1);
81 printf("actual context unknown: %s, should be ", strerror(errno));
82 error += print_matchpathcon(path, 1);