aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-03-27 22:00:17 -0500
committerRob Landley <rob@landley.net>2015-03-27 22:00:17 -0500
commit960cad18087dd629567b5156331cbb03ef7d28d0 (patch)
tree0d66c53bfc6531438142a8b9fc2f0b091939d6d1
parent3fd794f7416380417cc75d075a26559b80d3059a (diff)
downloadtoybox-960cad18087dd629567b5156331cbb03ef7d28d0.tar.gz
Cleanup setenforce.
-rw-r--r--toys/pending/setenforce.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/toys/pending/setenforce.c b/toys/pending/setenforce.c
index 6953f5ba..7d3d3801 100644
--- a/toys/pending/setenforce.c
+++ b/toys/pending/setenforce.c
@@ -7,6 +7,7 @@ USE_SETENFORCE(NEWTOY(setenforce, "<1", TOYFLAG_USR|TOYFLAG_SBIN))
config SETENFORCE
bool "setenforce"
default n
+ depends on TOYBOX_SELINUX
help
usage: setenforce [enforcing|permissive|1|0]
@@ -15,22 +16,17 @@ config SETENFORCE
#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);
}