aboutsummaryrefslogtreecommitdiff
path: root/selinux/matchpathcon.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-02-06 19:28:50 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-02-06 19:28:50 +0000
commitd46d3c292e9aff0550f6540ab631d742fe353964 (patch)
tree05f6461f18eba790a90a971c41ddb91163ae7847 /selinux/matchpathcon.c
parentb292264bfd7064b651192b966f30d76b75161c70 (diff)
downloadbusybox-w32-d46d3c292e9aff0550f6540ab631d742fe353964.tar.gz
busybox-w32-d46d3c292e9aff0550f6540ab631d742fe353964.tar.bz2
busybox-w32-d46d3c292e9aff0550f6540ab631d742fe353964.zip
new applets: selinux utils by KaiGai Kohei <kaigai@kaigai.gr.jp>
Diffstat (limited to 'selinux/matchpathcon.c')
-rw-r--r--selinux/matchpathcon.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/selinux/matchpathcon.c b/selinux/matchpathcon.c
new file mode 100644
index 000000000..4fa95b0ef
--- /dev/null
+++ b/selinux/matchpathcon.c
@@ -0,0 +1,85 @@
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>
5 *
6 */
7#include "busybox.h"
8
9static int print_matchpathcon(char *path, int noprint)
10{
11 char *buf;
12 int rc = matchpathcon(path, 0, &buf);
13 if (rc < 0) {
14 bb_perror_msg("matchpathcon(%s) failed", path);
15 return 1;
16 }
17 if (!noprint)
18 printf("%s\t%s\n", path, buf);
19 else
20 printf("%s\n", buf);
21
22 freecon(buf);
23 return 0;
24}
25
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 */
31
32int matchpathcon_main(int argc, char **argv)
33{
34 int error = 0;
35 unsigned opts;
36 char *fcontext, *prefix, *path;
37
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);
41 argv += optind;
42
43 if (opts & OPT_NOT_TRANS) {
44 set_matchpathcon_flags(NOTRANS);
45 }
46 if (opts & OPT_FCONTEXT) {
47 if (matchpathcon_init(fcontext))
48 bb_perror_msg_and_die("error while processing %s", fcontext);
49 }
50 if (opts & OPT_PREFIX) {
51 if (matchpathcon_init_prefix(NULL, prefix))
52 bb_perror_msg_and_die("error while processing %s", prefix);
53 }
54
55 while((path = *argv++) != NULL) {
56 security_context_t con;
57 int rc;
58
59 if (!(opts & OPT_VERIFY)) {
60 error += print_matchpathcon(path, opt & OPT_NOT_PRINT);
61 continue;
62 }
63
64 if (selinux_file_context_verify(path, 0)) {
65 printf("%s verified\n", path);
66 continue;
67 }
68
69 if (opts & OPT_NOT_TRANS)
70 rc = lgetfilecon_raw(path, &con);
71 else
72 rc = lgetfilecon(path, &con);
73
74 if (rc >= 0) {
75 printf("%s has context %s, should be ", path, con);
76 error += print_matchpathcon(path, 1);
77 freecon(con);
78 continue;
79 }
80 printf("actual context unknown: %s, should be ", strerror(errno));
81 error += print_matchpathcon(path, 1);
82 }
83 matchpathcon_fini();
84 return error;
85}