blob: c5bc0a5a69c79b3f89a208cd43d9510bd55e9e12 [file] [log] [blame]
Denis Vlasenkod46d3c22007-02-06 19:28:50 +00001/*
2 * setenforce
3 *
4 * Based on libselinux 1.33.1
5 * Port to BusyBox Hiroshi Shinji <shiroshi@my.email.ne.jp>
6 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02007 * Licensed under GPLv2, see file LICENSE in this source tree.
Denis Vlasenkod46d3c22007-02-06 19:28:50 +00008 */
9
Pere Orga5bc8c002011-04-11 03:29:49 +020010//usage:#define setenforce_trivial_usage
11//usage: "[Enforcing | Permissive | 1 | 0]"
12//usage:#define setenforce_full_usage ""
13
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000014#include "libbb.h"
Denis Vlasenkod46d3c22007-02-06 19:28:50 +000015
Denis Vlasenko8c6c6e92007-02-07 22:08:42 +000016/* 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 Vlasenkod46d3c22007-02-06 19:28:50 +000019static const char *const setenforce_cmd[] = {
20 "0",
21 "1",
22 "permissive",
23 "enforcing",
24 NULL,
25};
26
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000027int setenforce_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denys Vlasenko2ec91ae2010-01-04 14:15:38 +010028int setenforce_main(int argc UNUSED_PARAM, char **argv)
Denis Vlasenkod46d3c22007-02-06 19:28:50 +000029{
30 int i, rc;
31
Denys Vlasenko2ec91ae2010-01-04 14:15:38 +010032 if (!argv[1] || argv[2])
Denis Vlasenkod46d3c22007-02-06 19:28:50 +000033 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 Vlasenko8c6c6e92007-02-07 22:08:42 +000040 rc = security_setenforce(i & 1);
Denis Vlasenkod46d3c22007-02-06 19:28:50 +000041 if (rc < 0)
42 bb_perror_msg_and_die("setenforce() failed");
43 return 0;
44 }
45
46 bb_show_usage();
47}