Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 1 | /* |
| 2 | * setenforce |
| 3 | * |
| 4 | * Based on libselinux 1.33.1 |
| 5 | * Port to BusyBox Hiroshi Shinji <shiroshi@my.email.ne.jp> |
| 6 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 7 | * Licensed under GPLv2, see file LICENSE in this source tree. |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 8 | */ |
Denys Vlasenko | a8e52da | 2016-11-23 18:46:40 +0100 | [diff] [blame] | 9 | //config:config SETENFORCE |
| 10 | //config: bool "setenforce" |
| 11 | //config: default n |
| 12 | //config: depends on SELINUX |
| 13 | //config: help |
| 14 | //config: Enable support to modify the mode SELinux is running in. |
| 15 | |
| 16 | //applet:IF_SETENFORCE(APPLET(setenforce, BB_DIR_USR_SBIN, BB_SUID_DROP)) |
| 17 | |
| 18 | //kbuild:lib-$(CONFIG_SETENFORCE) += setenforce.o |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 19 | |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 20 | //usage:#define setenforce_trivial_usage |
| 21 | //usage: "[Enforcing | Permissive | 1 | 0]" |
| 22 | //usage:#define setenforce_full_usage "" |
| 23 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 24 | #include "libbb.h" |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 25 | |
Denis Vlasenko | 8c6c6e9 | 2007-02-07 22:08:42 +0000 | [diff] [blame] | 26 | /* These strings are arranged so that odd ones |
| 27 | * result in security_setenforce(1) being done, |
| 28 | * the rest will do security_setenforce(0) */ |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 29 | static const char *const setenforce_cmd[] = { |
| 30 | "0", |
| 31 | "1", |
| 32 | "permissive", |
| 33 | "enforcing", |
| 34 | NULL, |
| 35 | }; |
| 36 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 37 | int setenforce_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denys Vlasenko | 2ec91ae | 2010-01-04 14:15:38 +0100 | [diff] [blame] | 38 | int setenforce_main(int argc UNUSED_PARAM, char **argv) |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 39 | { |
| 40 | int i, rc; |
| 41 | |
Denys Vlasenko | 2ec91ae | 2010-01-04 14:15:38 +0100 | [diff] [blame] | 42 | if (!argv[1] || argv[2]) |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 43 | bb_show_usage(); |
| 44 | |
| 45 | selinux_or_die(); |
| 46 | |
| 47 | for (i = 0; setenforce_cmd[i]; i++) { |
| 48 | if (strcasecmp(argv[1], setenforce_cmd[i]) != 0) |
| 49 | continue; |
Denis Vlasenko | 8c6c6e9 | 2007-02-07 22:08:42 +0000 | [diff] [blame] | 50 | rc = security_setenforce(i & 1); |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 51 | if (rc < 0) |
| 52 | bb_perror_msg_and_die("setenforce() failed"); |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | bb_show_usage(); |
| 57 | } |