blob: 8d18abd29fef05614037010fb5f9f69d5fa93b55 [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 */
Denys Vlasenkoa8e52da2016-11-23 18:46:40 +01009//config:config SETENFORCE
10//config: bool "setenforce"
11//config: default n
12//config: depends on SELINUX
13//config: help
14//config: Enable support to modify the mode SELinux is running in.
15
16//applet:IF_SETENFORCE(APPLET(setenforce, BB_DIR_USR_SBIN, BB_SUID_DROP))
17
18//kbuild:lib-$(CONFIG_SETENFORCE) += setenforce.o
Denis Vlasenkod46d3c22007-02-06 19:28:50 +000019
Pere Orga5bc8c002011-04-11 03:29:49 +020020//usage:#define setenforce_trivial_usage
21//usage: "[Enforcing | Permissive | 1 | 0]"
22//usage:#define setenforce_full_usage ""
23
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000024#include "libbb.h"
Denis Vlasenkod46d3c22007-02-06 19:28:50 +000025
Denis Vlasenko8c6c6e92007-02-07 22:08:42 +000026/* These strings are arranged so that odd ones
27 * result in security_setenforce(1) being done,
28 * the rest will do security_setenforce(0) */
Denis Vlasenkod46d3c22007-02-06 19:28:50 +000029static const char *const setenforce_cmd[] = {
30 "0",
31 "1",
32 "permissive",
33 "enforcing",
34 NULL,
35};
36
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000037int setenforce_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denys Vlasenko2ec91ae2010-01-04 14:15:38 +010038int setenforce_main(int argc UNUSED_PARAM, char **argv)
Denis Vlasenkod46d3c22007-02-06 19:28:50 +000039{
40 int i, rc;
41
Denys Vlasenko2ec91ae2010-01-04 14:15:38 +010042 if (!argv[1] || argv[2])
Denis Vlasenkod46d3c22007-02-06 19:28:50 +000043 bb_show_usage();
44
45 selinux_or_die();
46
47 for (i = 0; setenforce_cmd[i]; i++) {
48 if (strcasecmp(argv[1], setenforce_cmd[i]) != 0)
49 continue;
Denis Vlasenko8c6c6e92007-02-07 22:08:42 +000050 rc = security_setenforce(i & 1);
Denis Vlasenkod46d3c22007-02-06 19:28:50 +000051 if (rc < 0)
52 bb_perror_msg_and_die("setenforce() failed");
53 return 0;
54 }
55
56 bb_show_usage();
57}