changeset 1763:61166a30ae47

Cleanup setenforce.
author Rob Landley <rob@landley.net>
date Fri, 27 Mar 2015 22:00:17 -0500
parents e65b19c2baf6
children 276664aa5ced
files toys/pending/setenforce.c
diffstat 1 files changed, 10 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/toys/pending/setenforce.c	Fri Mar 27 21:54:58 2015 -0500
+++ b/toys/pending/setenforce.c	Fri Mar 27 22:00:17 2015 -0500
@@ -7,6 +7,7 @@
 config SETENFORCE
   bool "setenforce"
   default n
+  depends on TOYBOX_SELINUX
   help
     usage: setenforce [enforcing|permissive|1|0]
 
@@ -15,22 +16,17 @@
 
 #define FOR_setenforce
 #include "toys.h"
-#include <selinux/selinux.h>
 
 void setenforce_main(void)
 {
-  char *state_str = *toys.optargs;
-  int state;
-  if (!is_selinux_enabled())
-    error_exit("SELinux is disabled");
-  else if (!strcmp(state_str, "1") || !strcasecmp(state_str, "enforcing"))
-    state = 1;
-  else if (!strcmp(state_str, "0") || !strcasecmp(state_str, "permissive"))
-    state = 0;
-  else
-    error_exit("Invalid state: %s", state_str);
+  char *new = *toys.optargs;
+  int state, ret;
 
-  int ret = security_setenforce(state);
-  if (ret == -1)
-    perror_msg("Couldn't set enforcing status to '%s'", state_str);
+  if (!is_selinux_enabled()) error_exit("SELinux is disabled");
+  else if (!strcmp(new, "1") || !strcasecmp(new, "enforcing")) state = 1;
+  else if (!strcmp(new, "0") || !strcasecmp(new, "permissive")) state = 0;
+  else error_exit("Invalid state: %s", new);
+
+  ret = security_setenforce(state);
+  if (ret == -1) perror_msg("Couldn't set enforcing status to '%s'", new);
 }