diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-02-06 19:28:50 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-02-06 19:28:50 +0000 |
commit | d46d3c292e9aff0550f6540ab631d742fe353964 (patch) | |
tree | 05f6461f18eba790a90a971c41ddb91163ae7847 | |
parent | b292264bfd7064b651192b966f30d76b75161c70 (diff) | |
download | busybox-w32-d46d3c292e9aff0550f6540ab631d742fe353964.tar.gz busybox-w32-d46d3c292e9aff0550f6540ab631d742fe353964.tar.bz2 busybox-w32-d46d3c292e9aff0550f6540ab631d742fe353964.zip |
new applets: selinux utils by KaiGai Kohei <kaigai@kaigai.gr.jp>
-rw-r--r-- | Config.in | 1 | ||||
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | Makefile.flags | 4 | ||||
-rw-r--r-- | include/applets.h | 5 | ||||
-rw-r--r-- | include/libbb.h | 1 | ||||
-rw-r--r-- | include/usage.h | 44 | ||||
-rw-r--r-- | libbb/xfuncs.c | 15 | ||||
-rw-r--r-- | selinux/Config.in | 47 | ||||
-rw-r--r-- | selinux/Kbuild | 13 | ||||
-rw-r--r-- | selinux/getenforce.c | 33 | ||||
-rw-r--r-- | selinux/getsebool.c | 65 | ||||
-rw-r--r-- | selinux/matchpathcon.c | 85 | ||||
-rw-r--r-- | selinux/selinuxenabled.c | 13 | ||||
-rw-r--r-- | selinux/setenforce.c | 44 |
14 files changed, 361 insertions, 10 deletions
@@ -493,3 +493,4 @@ source procps/Config.in | |||
493 | source shell/Config.in | 493 | source shell/Config.in |
494 | source sysklogd/Config.in | 494 | source sysklogd/Config.in |
495 | source runit/Config.in | 495 | source runit/Config.in |
496 | source selinux/Config.in | ||
@@ -442,6 +442,7 @@ libs-y := \ | |||
442 | networking/udhcp/ \ | 442 | networking/udhcp/ \ |
443 | procps/ \ | 443 | procps/ \ |
444 | runit/ \ | 444 | runit/ \ |
445 | selinux/ \ | ||
445 | shell/ \ | 446 | shell/ \ |
446 | sysklogd/ \ | 447 | sysklogd/ \ |
447 | util-linux/ \ | 448 | util-linux/ \ |
diff --git a/Makefile.flags b/Makefile.flags index e4ca7c6c5..b7711f698 100644 --- a/Makefile.flags +++ b/Makefile.flags | |||
@@ -54,4 +54,8 @@ endif | |||
54 | ifeq ($(CONFIG_STATIC),y) | 54 | ifeq ($(CONFIG_STATIC),y) |
55 | LDFLAGS += -static | 55 | LDFLAGS += -static |
56 | endif | 56 | endif |
57 | |||
58 | ifeq ($(CONFIG_SELINUX),y) | ||
59 | LDFLAGS += -lselinux -lsepol | ||
60 | endif | ||
57 | #LDFLAGS += -nostdlib | 61 | #LDFLAGS += -nostdlib |
diff --git a/include/applets.h b/include/applets.h index 397a8b789..d1bf0f36b 100644 --- a/include/applets.h +++ b/include/applets.h | |||
@@ -133,7 +133,9 @@ USE_FSCK_MINIX(APPLET_ODDNAME(fsck.minix, fsck_minix, _BB_DIR_SBIN, _BB_SUID_NEV | |||
133 | USE_FTPGET(APPLET_ODDNAME(ftpget, ftpgetput, _BB_DIR_USR_BIN, _BB_SUID_NEVER,ftpget)) | 133 | USE_FTPGET(APPLET_ODDNAME(ftpget, ftpgetput, _BB_DIR_USR_BIN, _BB_SUID_NEVER,ftpget)) |
134 | USE_FTPPUT(APPLET_ODDNAME(ftpput, ftpgetput, _BB_DIR_USR_BIN, _BB_SUID_NEVER,ftpput)) | 134 | USE_FTPPUT(APPLET_ODDNAME(ftpput, ftpgetput, _BB_DIR_USR_BIN, _BB_SUID_NEVER,ftpput)) |
135 | USE_FUSER(APPLET(fuser, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 135 | USE_FUSER(APPLET(fuser, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
136 | USE_GETENFORCE(APPLET(getenforce, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) | ||
136 | USE_GETOPT(APPLET(getopt, _BB_DIR_BIN, _BB_SUID_NEVER)) | 137 | USE_GETOPT(APPLET(getopt, _BB_DIR_BIN, _BB_SUID_NEVER)) |
138 | USE_GETSEBOOL(APPLET(getsebool, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) | ||
137 | USE_GETTY(APPLET(getty, _BB_DIR_SBIN, _BB_SUID_NEVER)) | 139 | USE_GETTY(APPLET(getty, _BB_DIR_SBIN, _BB_SUID_NEVER)) |
138 | USE_GREP(APPLET(grep, _BB_DIR_BIN, _BB_SUID_NEVER)) | 140 | USE_GREP(APPLET(grep, _BB_DIR_BIN, _BB_SUID_NEVER)) |
139 | USE_GUNZIP(APPLET(gunzip, _BB_DIR_BIN, _BB_SUID_NEVER)) | 141 | USE_GUNZIP(APPLET(gunzip, _BB_DIR_BIN, _BB_SUID_NEVER)) |
@@ -187,6 +189,7 @@ USE_LS(APPLET(ls, _BB_DIR_BIN, _BB_SUID_NEVER)) | |||
187 | USE_LSATTR(APPLET(lsattr, _BB_DIR_BIN, _BB_SUID_NEVER)) | 189 | USE_LSATTR(APPLET(lsattr, _BB_DIR_BIN, _BB_SUID_NEVER)) |
188 | USE_LSMOD(APPLET(lsmod, _BB_DIR_SBIN, _BB_SUID_NEVER)) | 190 | USE_LSMOD(APPLET(lsmod, _BB_DIR_SBIN, _BB_SUID_NEVER)) |
189 | USE_UNLZMA(APPLET_ODDNAME(lzmacat, unlzma, _BB_DIR_USR_BIN, _BB_SUID_NEVER, lzmacat)) | 191 | USE_UNLZMA(APPLET_ODDNAME(lzmacat, unlzma, _BB_DIR_USR_BIN, _BB_SUID_NEVER, lzmacat)) |
192 | USE_MATCHPATHCON(APPLET(matchpathcon, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) | ||
190 | USE_MAKEDEVS(APPLET(makedevs, _BB_DIR_SBIN, _BB_SUID_NEVER)) | 193 | USE_MAKEDEVS(APPLET(makedevs, _BB_DIR_SBIN, _BB_SUID_NEVER)) |
191 | USE_MD5SUM(APPLET_ODDNAME(md5sum, md5_sha1_sum, _BB_DIR_USR_BIN, _BB_SUID_NEVER, md5sum)) | 194 | USE_MD5SUM(APPLET_ODDNAME(md5sum, md5_sha1_sum, _BB_DIR_USR_BIN, _BB_SUID_NEVER, md5sum)) |
192 | USE_MDEV(APPLET(mdev, _BB_DIR_SBIN, _BB_SUID_NEVER)) | 195 | USE_MDEV(APPLET(mdev, _BB_DIR_SBIN, _BB_SUID_NEVER)) |
@@ -249,10 +252,12 @@ USE_RUNLEVEL(APPLET(runlevel, _BB_DIR_SBIN, _BB_SUID_NEVER)) | |||
249 | USE_RUNSV(APPLET(runsv, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 252 | USE_RUNSV(APPLET(runsv, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
250 | USE_RUNSVDIR(APPLET(runsvdir, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 253 | USE_RUNSVDIR(APPLET(runsvdir, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
251 | USE_RX(APPLET(rx, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 254 | USE_RX(APPLET(rx, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
255 | USE_SELINUXENABLED(APPLET(selinuxenabled, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) | ||
252 | USE_SED(APPLET(sed, _BB_DIR_BIN, _BB_SUID_NEVER)) | 256 | USE_SED(APPLET(sed, _BB_DIR_BIN, _BB_SUID_NEVER)) |
253 | USE_SEQ(APPLET(seq, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 257 | USE_SEQ(APPLET(seq, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
254 | USE_SETARCH(APPLET(setarch, _BB_DIR_BIN, _BB_SUID_NEVER)) | 258 | USE_SETARCH(APPLET(setarch, _BB_DIR_BIN, _BB_SUID_NEVER)) |
255 | USE_SETCONSOLE(APPLET(setconsole, _BB_DIR_SBIN, _BB_SUID_NEVER)) | 259 | USE_SETCONSOLE(APPLET(setconsole, _BB_DIR_SBIN, _BB_SUID_NEVER)) |
260 | USE_SETENFORCE(APPLET(setenforce, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) | ||
256 | USE_SETKEYCODES(APPLET(setkeycodes, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 261 | USE_SETKEYCODES(APPLET(setkeycodes, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
257 | USE_SETLOGCONS(APPLET(setlogcons, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) | 262 | USE_SETLOGCONS(APPLET(setlogcons, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) |
258 | USE_SETSID(APPLET(setsid, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 263 | USE_SETSID(APPLET(setsid, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
diff --git a/include/libbb.h b/include/libbb.h index babb39ba9..d6f08ff73 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -592,6 +592,7 @@ extern void run_shell(const char *shell, int loginshell, const char *command, co | |||
592 | extern void renew_current_security_context(void); | 592 | extern void renew_current_security_context(void); |
593 | extern void set_current_security_context(security_context_t sid); | 593 | extern void set_current_security_context(security_context_t sid); |
594 | #endif | 594 | #endif |
595 | extern void selinux_or_die(void); | ||
595 | extern int restricted_shell(const char *shell); | 596 | extern int restricted_shell(const char *shell); |
596 | extern void setup_environment(const char *shell, int loginshell, int changeenv, const struct passwd *pw); | 597 | extern void setup_environment(const char *shell, int loginshell, int changeenv, const struct passwd *pw); |
597 | extern int correct_password(const struct passwd *pw); | 598 | extern int correct_password(const struct passwd *pw); |
diff --git a/include/usage.h b/include/usage.h index 4ba540ccb..17dcf9be9 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -1013,6 +1013,9 @@ | |||
1013 | " -6 When using port/proto only search IPv6 space\n" \ | 1013 | " -6 When using port/proto only search IPv6 space\n" \ |
1014 | " -SIGNAL When used with -k, this signal will be used to kill" | 1014 | " -SIGNAL When used with -k, this signal will be used to kill" |
1015 | 1015 | ||
1016 | #define getenforce_trivial_usage | ||
1017 | #define getenforce_full_usage | ||
1018 | |||
1016 | #define getopt_trivial_usage \ | 1019 | #define getopt_trivial_usage \ |
1017 | "[OPTIONS]..." | 1020 | "[OPTIONS]..." |
1018 | #define getopt_full_usage \ | 1021 | #define getopt_full_usage \ |
@@ -1047,6 +1050,11 @@ | |||
1047 | " esac\n" \ | 1050 | " esac\n" \ |
1048 | "done\n" | 1051 | "done\n" |
1049 | 1052 | ||
1053 | #define getsebool_trivial_usage \ | ||
1054 | "-a or getsebool boolean..." | ||
1055 | #define getsebool_full_usage \ | ||
1056 | " -a Show all SELinux booleans" | ||
1057 | |||
1050 | #define getty_trivial_usage \ | 1058 | #define getty_trivial_usage \ |
1051 | "[OPTIONS]... baud_rate,... line [termtype]" | 1059 | "[OPTIONS]... baud_rate,... line [termtype]" |
1052 | #define getty_full_usage \ | 1060 | #define getty_full_usage \ |
@@ -1896,6 +1904,15 @@ | |||
1896 | "/dev/hda[0-15]\n" | 1904 | "/dev/hda[0-15]\n" |
1897 | #endif | 1905 | #endif |
1898 | 1906 | ||
1907 | #define matchpathcon_trivial_usage \ | ||
1908 | "[-n] [-N] [-f file_contexts_file] [-p prefix] [-V]" | ||
1909 | #define matchpathcon_full_usage \ | ||
1910 | " -n Do not display path" \ | ||
1911 | "\n -N Do not use translations" \ | ||
1912 | "\n -f Use alternate file_context file" \ | ||
1913 | "\n -p Use prefix to speed translations" \ | ||
1914 | "\n -V Verify file context on disk matches defaults" | ||
1915 | |||
1899 | #define md5sum_trivial_usage \ | 1916 | #define md5sum_trivial_usage \ |
1900 | "[OPTION] [FILEs...]" \ | 1917 | "[OPTION] [FILEs...]" \ |
1901 | USE_FEATURE_MD5_SHA1_SUM_CHECK("\n or: md5sum [OPTION] -c [FILE]") | 1918 | USE_FEATURE_MD5_SHA1_SUM_CHECK("\n or: md5sum [OPTION] -c [FILE]") |
@@ -2714,6 +2731,9 @@ | |||
2714 | "$ echo \"foo\" | sed -e 's/f[a-zA-Z]o/bar/g'\n" \ | 2731 | "$ echo \"foo\" | sed -e 's/f[a-zA-Z]o/bar/g'\n" \ |
2715 | "bar\n" | 2732 | "bar\n" |
2716 | 2733 | ||
2734 | #define selinuxenabled_trivial_usage | ||
2735 | #define selinuxenabled_full_usage | ||
2736 | |||
2717 | #define seq_trivial_usage \ | 2737 | #define seq_trivial_usage \ |
2718 | "[first [increment]] last" | 2738 | "[first [increment]] last" |
2719 | #define seq_full_usage \ | 2739 | #define seq_full_usage \ |
@@ -2731,6 +2751,10 @@ | |||
2731 | "\n\nOptions:\n" \ | 2751 | "\n\nOptions:\n" \ |
2732 | " -r Reset output to /dev/console" | 2752 | " -r Reset output to /dev/console" |
2733 | 2753 | ||
2754 | #define setenforce_trivial_usage \ | ||
2755 | "[ Enforcing | Permissive | 1 | 0 ]" | ||
2756 | #define setenforce_full_usage | ||
2757 | |||
2734 | #define setkeycodes_trivial_usage \ | 2758 | #define setkeycodes_trivial_usage \ |
2735 | "SCANCODE KEYCODE ..." | 2759 | "SCANCODE KEYCODE ..." |
2736 | #define setkeycodes_full_usage \ | 2760 | #define setkeycodes_full_usage \ |
@@ -3449,12 +3473,12 @@ | |||
3449 | #define vconfig_full_usage \ | 3473 | #define vconfig_full_usage \ |
3450 | "Create and remove virtual ethernet devices" \ | 3474 | "Create and remove virtual ethernet devices" \ |
3451 | "\n\nOptions:\n" \ | 3475 | "\n\nOptions:\n" \ |
3452 | " add [interface-name] [vlan_id]\n" \ | 3476 | " add [interface-name] [vlan_id]\n" \ |
3453 | " rem [vlan-name]\n" \ | 3477 | " rem [vlan-name]\n" \ |
3454 | " set_flag [interface-name] [flag-num] [0 | 1]\n" \ | 3478 | " set_flag [interface-name] [flag-num] [0 | 1]\n" \ |
3455 | " set_egress_map [vlan-name] [skb_priority] [vlan_qos]\n" \ | 3479 | " set_egress_map [vlan-name] [skb_priority] [vlan_qos]\n" \ |
3456 | " set_ingress_map [vlan-name] [skb_priority] [vlan_qos]\n" \ | 3480 | " set_ingress_map [vlan-name] [skb_priority] [vlan_qos]\n" \ |
3457 | " set_name_type [name-type]" | 3481 | " set_name_type [name-type]" |
3458 | 3482 | ||
3459 | #define vi_trivial_usage \ | 3483 | #define vi_trivial_usage \ |
3460 | "[OPTION] [FILE]..." | 3484 | "[OPTION] [FILE]..." |
@@ -3569,9 +3593,9 @@ | |||
3569 | #define zcip_full_usage \ | 3593 | #define zcip_full_usage \ |
3570 | "Manage a ZeroConf IPv4 link-local address" \ | 3594 | "Manage a ZeroConf IPv4 link-local address" \ |
3571 | "\n\nOptions:\n" \ | 3595 | "\n\nOptions:\n" \ |
3572 | " -f foreground mode\n" \ | 3596 | " -f Foreground mode\n" \ |
3573 | " -q quit after address (no daemon)\n" \ | 3597 | " -q Quit after address (no daemon)\n" \ |
3574 | " -r 169.254.x.x request this address first\n" \ | 3598 | " -r 169.254.x.x Request this address first\n" \ |
3575 | " -v verbose" | 3599 | " -v Verbose" |
3576 | 3600 | ||
3577 | #endif /* __BB_USAGE_H__ */ | 3601 | #endif /* __BB_USAGE_H__ */ |
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 3cbb0d3eb..f6444bbc6 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -570,6 +570,21 @@ void xstat(const char *name, struct stat *stat_buf) | |||
570 | bb_perror_msg_and_die("can't stat '%s'", name); | 570 | bb_perror_msg_and_die("can't stat '%s'", name); |
571 | } | 571 | } |
572 | 572 | ||
573 | // selinux_or_die() - die if SELinux is disabled. | ||
574 | void selinux_or_die(void) | ||
575 | { | ||
576 | #if ENABLE_SELINUX | ||
577 | int rc = is_selinux_enabled(); | ||
578 | if (rc == 0) { | ||
579 | bb_error_msg_and_die("SELinux is disabled"); | ||
580 | } else if (rc < 0) { | ||
581 | bb_error_msg_and_die("is_selinux_enabled() failed"); | ||
582 | } | ||
583 | #else | ||
584 | bb_error_msg_and_die("SELinux support is disabled"); | ||
585 | #endif | ||
586 | } | ||
587 | |||
573 | /* It is perfectly ok to pass in a NULL for either width or for | 588 | /* It is perfectly ok to pass in a NULL for either width or for |
574 | * height, in which case that value will not be set. */ | 589 | * height, in which case that value will not be set. */ |
575 | int get_terminal_width_height(const int fd, int *width, int *height) | 590 | int get_terminal_width_height(const int fd, int *width, int *height) |
diff --git a/selinux/Config.in b/selinux/Config.in new file mode 100644 index 000000000..b078ee59e --- /dev/null +++ b/selinux/Config.in | |||
@@ -0,0 +1,47 @@ | |||
1 | # | ||
2 | # For a description of the syntax of this configuration file, | ||
3 | # see scripts/kbuild/config-language.txt. | ||
4 | # | ||
5 | |||
6 | menu "Selinux Utilities" | ||
7 | depends on SELINUX | ||
8 | |||
9 | config GETENFORCE | ||
10 | bool "getenforce" | ||
11 | default n | ||
12 | depends on SELINUX | ||
13 | help | ||
14 | Enable support to get the current mode of SELinux. | ||
15 | |||
16 | config GETSEBOOL | ||
17 | bool "getsebool" | ||
18 | default n | ||
19 | depends on SELINUX | ||
20 | help | ||
21 | Enable support to get SELinux boolean values. | ||
22 | |||
23 | config MATCHPATHCON | ||
24 | bool "matchpathcon" | ||
25 | default n | ||
26 | depends on SELINUX | ||
27 | help | ||
28 | Enable support to get default security context of the | ||
29 | specified path from the file contexts configuration. | ||
30 | |||
31 | config SELINUXENABLED | ||
32 | bool "selinuxenabled" | ||
33 | default n | ||
34 | depends on SELINUX | ||
35 | help | ||
36 | Enable support for this command to be used within shell scripts | ||
37 | to determine if selinux is enabled. | ||
38 | |||
39 | config SETENFORCE | ||
40 | bool "setenforce" | ||
41 | default n | ||
42 | depends on SELINUX | ||
43 | help | ||
44 | Enable support to modify the mode SELinux is running in. | ||
45 | |||
46 | endmenu | ||
47 | |||
diff --git a/selinux/Kbuild b/selinux/Kbuild new file mode 100644 index 000000000..8371df8e4 --- /dev/null +++ b/selinux/Kbuild | |||
@@ -0,0 +1,13 @@ | |||
1 | # Makefile for busybox | ||
2 | # | ||
3 | # Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org> | ||
4 | # Copyright (C) 2007 by KaiGai Kohei <kaigai@kaigai.gr.jp> | ||
5 | # | ||
6 | # Licensed under the GPL v2, see the file LICENSE in this tarball. | ||
7 | |||
8 | lib-y:= | ||
9 | lib-$(CONFIG_GETENFORCE) += getenforce.o | ||
10 | lib-$(CONFIG_GETSEBOOL) += getsebool.o | ||
11 | lib-$(CONFIG_MATCHPATHCON) += matchpathcon.o | ||
12 | lib-$(CONFIG_SELINUXENABLED) += selinuxenabled.o | ||
13 | lib-$(CONFIG_SETENFORCE) += setenforce.o | ||
diff --git a/selinux/getenforce.c b/selinux/getenforce.c new file mode 100644 index 000000000..e240e4dca --- /dev/null +++ b/selinux/getenforce.c | |||
@@ -0,0 +1,33 @@ | |||
1 | /* | ||
2 | * getenforce | ||
3 | * | ||
4 | * Based on libselinux 1.33.1 | ||
5 | * Port to BusyBox Hiroshi Shinji <shiroshi@my.email.ne.jp> | ||
6 | * | ||
7 | */ | ||
8 | |||
9 | #include "busybox.h" | ||
10 | |||
11 | int getenforce_main(int argc, char **argv) | ||
12 | { | ||
13 | int rc; | ||
14 | |||
15 | rc = is_selinux_enabled(); | ||
16 | if (rc < 0) | ||
17 | bb_error_msg_and_die("is_selinux_enabled() failed"); | ||
18 | |||
19 | if (rc == 1) { | ||
20 | rc = security_getenforce(); | ||
21 | if (rc < 0) | ||
22 | bb_error_msg_and_die("getenforce() failed"); | ||
23 | |||
24 | if (rc) | ||
25 | puts("Enforcing"); | ||
26 | else | ||
27 | puts("Permissive"); | ||
28 | } else { | ||
29 | puts("Disabled"); | ||
30 | } | ||
31 | |||
32 | return 0; | ||
33 | } | ||
diff --git a/selinux/getsebool.c b/selinux/getsebool.c new file mode 100644 index 000000000..d593937ba --- /dev/null +++ b/selinux/getsebool.c | |||
@@ -0,0 +1,65 @@ | |||
1 | /* | ||
2 | * getsebool | ||
3 | * | ||
4 | * Based on libselinux 1.33.1 | ||
5 | * Port to BusyBox Hiroshi Shinji <shiroshi@my.email.ne.jp> | ||
6 | * | ||
7 | */ | ||
8 | |||
9 | #include "busybox.h" | ||
10 | |||
11 | int getsebool_main(int argc, char **argv) | ||
12 | { | ||
13 | int i, rc = 0, active, pending, len = 0; | ||
14 | char **names; | ||
15 | unsigned opt; | ||
16 | |||
17 | selinux_or_die(); | ||
18 | opt = getopt32(argc, argv, "a"); | ||
19 | |||
20 | if (opt) { /* -a */ | ||
21 | if (argc > 2) | ||
22 | bb_show_usage(); | ||
23 | |||
24 | rc = security_get_boolean_names(&names, &len); | ||
25 | if (rc) | ||
26 | bb_perror_msg_and_die("cannot get boolean names"); | ||
27 | |||
28 | if (!len) { | ||
29 | puts("No booleans"); | ||
30 | return 0; | ||
31 | } | ||
32 | } | ||
33 | |||
34 | if (!len) { | ||
35 | if (argc < 2) | ||
36 | bb_show_usage(); | ||
37 | len = argc - 1; | ||
38 | names = xmalloc(sizeof(char *) * len); | ||
39 | for (i = 0; i < len; i++) | ||
40 | names[i] = xstrdup(argv[i + 1]); | ||
41 | } | ||
42 | |||
43 | for (i = 0; i < len; i++) { | ||
44 | active = security_get_boolean_active(names[i]); | ||
45 | if (active < 0) { | ||
46 | bb_error_msg_and_die("error getting active value for %s", names[i]); | ||
47 | } | ||
48 | pending = security_get_boolean_pending(names[i]); | ||
49 | if (pending < 0) { | ||
50 | bb_error_msg_and_die("error getting pending value for %s", names[i]); | ||
51 | } | ||
52 | printf("%s --> %s", names[i], (active ? "on" : "off")); | ||
53 | if (pending != active) | ||
54 | printf(" pending: %s", (pending ? "on" : "off")); | ||
55 | putchar('\n'); | ||
56 | } | ||
57 | |||
58 | if (ENABLE_FEATURE_CLEAN_UP) { | ||
59 | for (i = 0; i < len; i++) | ||
60 | free(names[i]); | ||
61 | free(names); | ||
62 | } | ||
63 | |||
64 | return rc; | ||
65 | } | ||
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 | |||
9 | static 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 | |||
32 | int 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 | } | ||
diff --git a/selinux/selinuxenabled.c b/selinux/selinuxenabled.c new file mode 100644 index 000000000..b34228098 --- /dev/null +++ b/selinux/selinuxenabled.c | |||
@@ -0,0 +1,13 @@ | |||
1 | /* | ||
2 | * selinuxenabled | ||
3 | * | ||
4 | * Based on libselinux 1.33.1 | ||
5 | * Port to BusyBox Hiroshi Shinji <shiroshi@my.email.ne.jp> | ||
6 | * | ||
7 | */ | ||
8 | #include "busybox.h" | ||
9 | |||
10 | int selinuxenabled_main(int argc, char **argv) | ||
11 | { | ||
12 | return !is_selinux_enabled(); | ||
13 | } | ||
diff --git a/selinux/setenforce.c b/selinux/setenforce.c new file mode 100644 index 000000000..670e30086 --- /dev/null +++ b/selinux/setenforce.c | |||
@@ -0,0 +1,44 @@ | |||
1 | /* | ||
2 | * setenforce | ||
3 | * | ||
4 | * Based on libselinux 1.33.1 | ||
5 | * Port to BusyBox Hiroshi Shinji <shiroshi@my.email.ne.jp> | ||
6 | * | ||
7 | */ | ||
8 | |||
9 | #include "busybox.h" | ||
10 | |||
11 | static const smallint setenforce_mode[] = { | ||
12 | 0, | ||
13 | 1, | ||
14 | 0, | ||
15 | 1, | ||
16 | }; | ||
17 | static const char *const setenforce_cmd[] = { | ||
18 | "0", | ||
19 | "1", | ||
20 | "permissive", | ||
21 | "enforcing", | ||
22 | NULL, | ||
23 | }; | ||
24 | |||
25 | int setenforce_main(int argc, char **argv) | ||
26 | { | ||
27 | int i, rc; | ||
28 | |||
29 | if (argc != 2) | ||
30 | bb_show_usage(); | ||
31 | |||
32 | selinux_or_die(); | ||
33 | |||
34 | for (i = 0; setenforce_cmd[i]; i++) { | ||
35 | if (strcasecmp(argv[1], setenforce_cmd[i]) != 0) | ||
36 | continue; | ||
37 | rc = security_setenforce(setenforce_mode[i]); | ||
38 | if (rc < 0) | ||
39 | bb_perror_msg_and_die("setenforce() failed"); | ||
40 | return 0; | ||
41 | } | ||
42 | |||
43 | bb_show_usage(); | ||
44 | } | ||