blob: 59b1b0fca85efc70db1d77ad535e9f04ccf879fb [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 *
7 */
8
Denis Vlasenkob6adbf12007-05-26 19:00:18 +00009#include "libbb.h"
Denis Vlasenkod46d3c22007-02-06 19:28:50 +000010
Denis Vlasenko8c6c6e92007-02-07 22:08:42 +000011/* 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 Vlasenkod46d3c22007-02-06 19:28:50 +000014static const char *const setenforce_cmd[] = {
15 "0",
16 "1",
17 "permissive",
18 "enforcing",
19 NULL,
20};
21
Denis Vlasenko8c6c6e92007-02-07 22:08:42 +000022int setenforce_main(int argc, char **argv);
Denis Vlasenkod46d3c22007-02-06 19:28:50 +000023int 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 Vlasenko8c6c6e92007-02-07 22:08:42 +000035 rc = security_setenforce(i & 1);
Denis Vlasenkod46d3c22007-02-06 19:28:50 +000036 if (rc < 0)
37 bb_perror_msg_and_die("setenforce() failed");
38 return 0;
39 }
40
41 bb_show_usage();
42}