blob: a2d04288bd2dd0be7f6473f3efd65b00e698c759 [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 *
Denis Vlasenkodb12d1d2008-12-07 00:52:58 +00007 * Licensed under GPLv2, see file LICENSE in this tarball for details.
Denis Vlasenkod46d3c22007-02-06 19:28:50 +00008 */
9
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000010#include "libbb.h"
Denis Vlasenkod46d3c22007-02-06 19:28:50 +000011
Denis Vlasenko8c6c6e92007-02-07 22:08:42 +000012/* 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 Vlasenkod46d3c22007-02-06 19:28:50 +000015static const char *const setenforce_cmd[] = {
16 "0",
17 "1",
18 "permissive",
19 "enforcing",
20 NULL,
21};
22
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000023int setenforce_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkod46d3c22007-02-06 19:28:50 +000024int setenforce_main(int argc, char **argv)
25{
26 int i, rc;
27
28 if (argc != 2)
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 Vlasenko8c6c6e92007-02-07 22:08:42 +000036 rc = security_setenforce(i & 1);
Denis Vlasenkod46d3c22007-02-06 19:28:50 +000037 if (rc < 0)
38 bb_perror_msg_and_die("setenforce() failed");
39 return 0;
40 }
41
42 bb_show_usage();
43}