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