summaryrefslogtreecommitdiffstats
path: root/toolbox/setsebool.c
diff options
context:
space:
mode:
Diffstat (limited to 'toolbox/setsebool.c')
-rw-r--r--toolbox/setsebool.c39
1 files changed, 24 insertions, 15 deletions
diff --git a/toolbox/setsebool.c b/toolbox/setsebool.c
index f79a612..4a3d87d 100644
--- a/toolbox/setsebool.c
+++ b/toolbox/setsebool.c
@@ -9,26 +9,35 @@
#include <errno.h>
static int do_setsebool(int nargs, char **args) {
- const char *name = args[1];
- const char *value = args[2];
- SELboolean b;
+ SELboolean *b = alloca(nargs * sizeof(SELboolean));
+ char *v;
+ int i;
if (is_selinux_enabled() <= 0)
return 0;
- b.name = name;
- if (!strcmp(value, "1") || !strcasecmp(value, "true") || !strcasecmp(value, "on"))
- b.value = 1;
- else if (!strcmp(value, "0") || !strcasecmp(value, "false") || !strcasecmp(value, "off"))
- b.value = 0;
- else {
- fprintf(stderr, "setsebool: invalid value %s\n", value);
- return -1;
+ for (i = 1; i < nargs; i++) {
+ char *name = args[i];
+ v = strchr(name, '=');
+ if (!v) {
+ fprintf(stderr, "setsebool: argument %s had no =\n", name);
+ return -1;
+ }
+ *v++ = 0;
+ b[i-1].name = name;
+ if (!strcmp(v, "1") || !strcasecmp(v, "true") || !strcasecmp(v, "on"))
+ b[i-1].value = 1;
+ else if (!strcmp(v, "0") || !strcasecmp(v, "false") || !strcasecmp(v, "off"))
+ b[i-1].value = 0;
+ else {
+ fprintf(stderr, "setsebool: invalid value %s\n", v);
+ return -1;
+ }
}
- if (security_set_boolean_list(1, &b, 0) < 0)
+ if (security_set_boolean_list(nargs - 1, b, 0) < 0)
{
- fprintf(stderr, "setsebool: could not set %s to %s: %s", name, value, strerror(errno));
+ fprintf(stderr, "setsebool: unable to set booleans: %s", strerror(errno));
return -1;
}
@@ -37,8 +46,8 @@ static int do_setsebool(int nargs, char **args) {
int setsebool_main(int argc, char **argv)
{
- if (argc != 3) {
- fprintf(stderr, "Usage: %s name value\n", argv[0]);
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s name=value...\n", argv[0]);
exit(1);
}