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 | */ |
| 9 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 10 | #include "libbb.h" |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 11 | |
Denis Vlasenko | 8c6c6e9 | 2007-02-07 22:08:42 +0000 | [diff] [blame] | 12 | /* These strings are arranged so that odd ones |
| 13 | * result in security_setenforce(1) being done, |
| 14 | * the rest will do security_setenforce(0) */ |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 15 | static const char *const setenforce_cmd[] = { |
| 16 | "0", |
| 17 | "1", |
| 18 | "permissive", |
| 19 | "enforcing", |
| 20 | NULL, |
| 21 | }; |
| 22 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 23 | int setenforce_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denys Vlasenko | 2ec91ae | 2010-01-04 14:15:38 +0100 | [diff] [blame] | 24 | int setenforce_main(int argc UNUSED_PARAM, char **argv) |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 25 | { |
| 26 | int i, rc; |
| 27 | |
Denys Vlasenko | 2ec91ae | 2010-01-04 14:15:38 +0100 | [diff] [blame] | 28 | if (!argv[1] || argv[2]) |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 29 | bb_show_usage(); |
| 30 | |
| 31 | selinux_or_die(); |
| 32 | |
| 33 | for (i = 0; setenforce_cmd[i]; i++) { |
| 34 | if (strcasecmp(argv[1], setenforce_cmd[i]) != 0) |
| 35 | continue; |
Denis Vlasenko | 8c6c6e9 | 2007-02-07 22:08:42 +0000 | [diff] [blame] | 36 | rc = security_setenforce(i & 1); |
Denis Vlasenko | d46d3c2 | 2007-02-06 19:28:50 +0000 | [diff] [blame] | 37 | if (rc < 0) |
| 38 | bb_perror_msg_and_die("setenforce() failed"); |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | bb_show_usage(); |
| 43 | } |