aboutsummaryrefslogtreecommitdiff
path: root/toys/pending/getenforce.c
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-12-23 19:20:24 -0600
committerElliott Hughes <enh@google.com>2014-12-23 19:20:24 -0600
commitd5c66a9fd36777f80ba05301dcfa6789b103e486 (patch)
treecace1cecad6c5507f1a0efd1911f2393a19e0d81 /toys/pending/getenforce.c
parent627cd0f0d974e9ba25d95cb8f5e23ac6c9c93aaf (diff)
downloadtoybox-d5c66a9fd36777f80ba05301dcfa6789b103e486.tar.gz
getenforce and setenforce
two more easy SELinux commands:
Diffstat (limited to 'toys/pending/getenforce.c')
-rw-r--r--toys/pending/getenforce.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/toys/pending/getenforce.c b/toys/pending/getenforce.c
new file mode 100644
index 00000000..ce43f523
--- /dev/null
+++ b/toys/pending/getenforce.c
@@ -0,0 +1,31 @@
+/* getenforce.c - Get the current SELinux mode
+ *
+ * Copyright 2014 The Android Open Source Project
+
+USE_GETENFORCE(NEWTOY(getenforce, "", TOYFLAG_USR|TOYFLAG_SBIN))
+
+config GETENFORCE
+ bool "getenforce"
+ default n
+ help
+ usage: getenforce
+
+ Shows whether SELinux is disabled, enforcing, or permissive.
+*/
+
+#define FOR_getenforce
+#include "toys.h"
+#include <selinux/selinux.h>
+
+void getenforce_main(void)
+{
+ if (!is_selinux_enabled())
+ printf("Disabled\n");
+ else {
+ int ret = security_getenforce();
+ if (ret == -1)
+ perror_exit("Couldn't get enforcing status");
+ else
+ printf(ret ? "Enforcing\n" : "Permissive\n");
+ }
+}