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>
6 * Licensed under GPLv2, see file LICENSE in this source tree.
10 static int print_matchpathcon(char *path
, int noprint
)
13 int rc
= matchpathcon(path
, 0, &buf
);
15 bb_perror_msg("matchpathcon(%s) failed", path
);
19 printf("%s\t%s\n", path
, buf
);
27 #define OPT_NOT_PRINT (1<<0) /* -n */
28 #define OPT_NOT_TRANS (1<<1) /* -N */
29 #define OPT_FCONTEXT (1<<2) /* -f */
30 #define OPT_PREFIX (1<<3) /* -p */
31 #define OPT_VERIFY (1<<4) /* -V */
33 int matchpathcon_main(int argc
, char **argv
) MAIN_EXTERNALLY_VISIBLE
;
34 int matchpathcon_main(int argc UNUSED_PARAM
, char **argv
)
38 char *fcontext
, *prefix
, *path
;
40 opt_complementary
= "-1" /* at least one param reqd */
41 ":?:f--p:p--f"; /* mutually exclusive */
42 opts
= getopt32(argv
, "nNf:p:V", &fcontext
, &prefix
);
45 if (opts
& OPT_NOT_TRANS
) {
46 set_matchpathcon_flags(MATCHPATHCON_NOTRANS
);
48 if (opts
& OPT_FCONTEXT
) {
49 if (matchpathcon_init(fcontext
))
50 bb_perror_msg_and_die("error while processing %s", fcontext
);
52 if (opts
& OPT_PREFIX
) {
53 if (matchpathcon_init_prefix(NULL
, prefix
))
54 bb_perror_msg_and_die("error while processing %s", prefix
);
57 while ((path
= *argv
++) != NULL
) {
58 security_context_t con
;
61 if (!(opts
& OPT_VERIFY
)) {
62 error
+= print_matchpathcon(path
, opts
& OPT_NOT_PRINT
);
66 if (selinux_file_context_verify(path
, 0)) {
67 printf("%s verified\n", path
);
71 if (opts
& OPT_NOT_TRANS
)
72 rc
= lgetfilecon_raw(path
, &con
);
74 rc
= lgetfilecon(path
, &con
);
77 printf("%s has context %s, should be ", path
, con
);
78 error
+= print_matchpathcon(path
, 1);
82 printf("actual context unknown: %s, should be ", strerror(errno
));
83 error
+= print_matchpathcon(path
, 1);