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