summaryrefslogtreecommitdiffstats
path: root/toolbox/setenforce.c
diff options
context:
space:
mode:
authorStephen Smalley <sds@tycho.nsa.gov>2012-01-13 08:53:56 -0500
committerStephen Smalley <sds@tycho.nsa.gov>2012-02-03 11:11:15 -0500
commit8290d1083ec7eee3f32265012f5d6be2774c4afc (patch)
tree6d7e239b2a5b3d4a8faf8c3f404f8d9b3270f61d /toolbox/setenforce.c
parent0458d373261d89979529853fa63cdd998b12e04a (diff)
downloadsystem_core-8290d1083ec7eee3f32265012f5d6be2774c4afc.zip
system_core-8290d1083ec7eee3f32265012f5d6be2774c4afc.tar.gz
system_core-8290d1083ec7eee3f32265012f5d6be2774c4afc.tar.bz2
Extend toolbox with SE Android support.
Add -Z option to ls and ps for displaying security contexts. Modify id to display security context. Add new SELinux commands: chcon, getenforce, getsebool, load_policy, restorecon, runcon, setenforce, setsebool. Change-Id: Ia20941be4a6cd706fe392fed6e38a37d880ec5f1
Diffstat (limited to 'toolbox/setenforce.c')
-rw-r--r--toolbox/setenforce.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/toolbox/setenforce.c b/toolbox/setenforce.c
new file mode 100644
index 0000000..1b0ea5c
--- /dev/null
+++ b/toolbox/setenforce.c
@@ -0,0 +1,44 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <strings.h>
+#include <errno.h>
+#include <selinux/selinux.h>
+
+void usage(const char *progname)
+{
+ fprintf(stderr, "usage: %s [ Enforcing | Permissive | 1 | 0 ]\n",
+ progname);
+ exit(1);
+}
+
+int setenforce_main(int argc, char **argv)
+{
+ int rc = 0;
+ if (argc != 2) {
+ usage(argv[0]);
+ }
+
+ if (is_selinux_enabled() <= 0) {
+ fprintf(stderr, "%s: SELinux is disabled\n", argv[0]);
+ return 1;
+ }
+ if (strlen(argv[1]) == 1 && (argv[1][0] == '0' || argv[1][0] == '1')) {
+ rc = security_setenforce(atoi(argv[1]));
+ } else {
+ if (strcasecmp(argv[1], "enforcing") == 0) {
+ rc = security_setenforce(1);
+ } else if (strcasecmp(argv[1], "permissive") == 0) {
+ rc = security_setenforce(0);
+ } else
+ usage(argv[0]);
+ }
+ if (rc < 0) {
+ fprintf(stderr, "%s: Could not set enforcing status: %s\n",
+ argv[0], strerror(errno));
+ return 2;
+ }
+ return 0;
+}