Discussion:
[PATCH] policycoreutils/semodule: Allow enabling/disabling multiple modules at once
Vit Mojzis
2018-03-14 12:34:22 UTC
Permalink
From: Vit Mojzis <***@localhost.localdomain>

Unify behaviour for all module actions.
The same behavoiour is already present for -i/-u/-r/-e switches.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1545218

Signed-off-by: Vit Mojzis <***@localhost.localdomain>
---
policycoreutils/semodule/semodule.c | 33 +++++++++++++++++----------------
1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/policycoreutils/semodule/semodule.c b/policycoreutils/semodule/semodule.c
index 504247d3..c6953cb1 100644
--- a/policycoreutils/semodule/semodule.c
+++ b/policycoreutils/semodule/semodule.c
@@ -311,28 +311,29 @@ static void parse_command_line(int argc, char **argv)
}

if (optind < argc) {
- int mode;
+ int mode = commands ? commands[num_commands - 1].mode : -1;
/* if -i/u/r/E was the last command treat any remaining
* arguments as args. Will allow 'semodule -i *.pp' to
* work as expected.
*/

- if (commands && commands[num_commands - 1].mode == INSTALL_M) {
- mode = INSTALL_M;
- } else if (commands && commands[num_commands - 1].mode == REMOVE_M) {
- mode = REMOVE_M;
- } else if (commands && commands[num_commands - 1].mode == EXTRACT_M) {
- mode = EXTRACT_M;
- } else {
- fprintf(stderr, "unknown additional arguments:\n");
- while (optind < argc)
- fprintf(stderr, " %s", argv[optind++]);
- fprintf(stderr, "\n\n");
- usage(argv[0]);
- exit(1);
+ switch (mode) {
+ case INSTALL_M:
+ case REMOVE_M:
+ case EXTRACT_M:
+ case ENABLE_M:
+ case DISABLE_M:
+ while (optind < argc)
+ set_mode(mode, argv[optind++]);
+ break;
+ default:
+ fprintf(stderr, "unknown additional arguments:\n");
+ while (optind < argc)
+ fprintf(stderr, " %s", argv[optind++]);
+ fprintf(stderr, "\n\n");
+ usage(argv[0]);
+ exit(1);
}
- while (optind < argc)
- set_mode(mode, argv[optind++]);
}
}
--
2.14.3
Vit Mojzis
2018-03-15 10:27:11 UTC
Permalink
From: Vit Mojzis <***@localhost.localdomain>

Unify behaviour for all module actions.
The same behaviour is already present for -i/-u/-r/-e switches.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1545218

Signed-off-by: Vit Mojzis <***@redhat.com>
---
policycoreutils/semodule/semodule.c | 33 +++++++++++++++++----------------
1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/policycoreutils/semodule/semodule.c b/policycoreutils/semodule/semodule.c
index 504247d3..c6953cb1 100644
--- a/policycoreutils/semodule/semodule.c
+++ b/policycoreutils/semodule/semodule.c
@@ -311,28 +311,29 @@ static void parse_command_line(int argc, char **argv)
}

if (optind < argc) {
- int mode;
+ int mode = commands ? commands[num_commands - 1].mode : -1;
/* if -i/u/r/E was the last command treat any remaining
* arguments as args. Will allow 'semodule -i *.pp' to
* work as expected.
*/

- if (commands && commands[num_commands - 1].mode == INSTALL_M) {
- mode = INSTALL_M;
- } else if (commands && commands[num_commands - 1].mode == REMOVE_M) {
- mode = REMOVE_M;
- } else if (commands && commands[num_commands - 1].mode == EXTRACT_M) {
- mode = EXTRACT_M;
- } else {
- fprintf(stderr, "unknown additional arguments:\n");
- while (optind < argc)
- fprintf(stderr, " %s", argv[optind++]);
- fprintf(stderr, "\n\n");
- usage(argv[0]);
- exit(1);
+ switch (mode) {
+ case INSTALL_M:
+ case REMOVE_M:
+ case EXTRACT_M:
+ case ENABLE_M:
+ case DISABLE_M:
+ while (optind < argc)
+ set_mode(mode, argv[optind++]);
+ break;
+ default:
+ fprintf(stderr, "unknown additional arguments:\n");
+ while (optind < argc)
+ fprintf(stderr, " %s", argv[optind++]);
+ fprintf(stderr, "\n\n");
+ usage(argv[0]);
+ exit(1);
}
- while (optind < argc)
- set_mode(mode, argv[optind++]);
}
}
--
2.14.3
Vit Mojzis
2018-03-19 11:08:11 UTC
Permalink
Please ignore the last two attempts at this patch.
Sorry for the noise.
Vit Mojzis
2018-03-19 11:08:12 UTC
Permalink
From: Vit Mojzis <***@localhost.localdomain>

Unify behaviour for all module actions.
The same behaviour is already present for -i/-u/-r/-e switches.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1545218

Signed-off-by: Vit Mojzis <***@redhat.com>
---
policycoreutils/semodule/semodule.c | 33 +++++++++++++++++----------------
1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/policycoreutils/semodule/semodule.c b/policycoreutils/semodule/semodule.c
index 504247d3..a76797f5 100644
--- a/policycoreutils/semodule/semodule.c
+++ b/policycoreutils/semodule/semodule.c
@@ -311,28 +311,29 @@ static void parse_command_line(int argc, char **argv)
}

if (optind < argc) {
- int mode;
+ int mode = commands ? (int) commands[num_commands - 1].mode : -1;
/* if -i/u/r/E was the last command treat any remaining
* arguments as args. Will allow 'semodule -i *.pp' to
* work as expected.
*/

- if (commands && commands[num_commands - 1].mode == INSTALL_M) {
- mode = INSTALL_M;
- } else if (commands && commands[num_commands - 1].mode == REMOVE_M) {
- mode = REMOVE_M;
- } else if (commands && commands[num_commands - 1].mode == EXTRACT_M) {
- mode = EXTRACT_M;
- } else {
- fprintf(stderr, "unknown additional arguments:\n");
- while (optind < argc)
- fprintf(stderr, " %s", argv[optind++]);
- fprintf(stderr, "\n\n");
- usage(argv[0]);
- exit(1);
+ switch (mode) {
+ case INSTALL_M:
+ case REMOVE_M:
+ case EXTRACT_M:
+ case ENABLE_M:
+ case DISABLE_M:
+ while (optind < argc)
+ set_mode(mode, argv[optind++]);
+ break;
+ default:
+ fprintf(stderr, "unknown additional arguments:\n");
+ while (optind < argc)
+ fprintf(stderr, " %s", argv[optind++]);
+ fprintf(stderr, "\n\n");
+ usage(argv[0]);
+ exit(1);
}
- while (optind < argc)
- set_mode(mode, argv[optind++]);
}
}
--
2.14.3
Stephen Smalley
2018-03-26 14:01:48 UTC
Permalink
Post by Vit Mojzis
Unify behaviour for all module actions.
The same behaviour is already present for -i/-u/-r/-e switches.
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1545218
I've put up a PR for this one and your earlier patch for semodule man page / --help usage; assuming no problems, we can merge them anytime. Sorry for the delay.

https://github.com/SELinuxProject/selinux/pull/88
Post by Vit Mojzis
---
policycoreutils/semodule/semodule.c | 33 +++++++++++++++++----------------
1 file changed, 17 insertions(+), 16 deletions(-)
diff --git a/policycoreutils/semodule/semodule.c b/policycoreutils/semodule/semodule.c
index 504247d3..a76797f5 100644
--- a/policycoreutils/semodule/semodule.c
+++ b/policycoreutils/semodule/semodule.c
@@ -311,28 +311,29 @@ static void parse_command_line(int argc, char **argv)
}
if (optind < argc) {
- int mode;
+ int mode = commands ? (int) commands[num_commands - 1].mode : -1;
/* if -i/u/r/E was the last command treat any remaining
* arguments as args. Will allow 'semodule -i *.pp' to
* work as expected.
*/
- if (commands && commands[num_commands - 1].mode == INSTALL_M) {
- mode = INSTALL_M;
- } else if (commands && commands[num_commands - 1].mode == REMOVE_M) {
- mode = REMOVE_M;
- } else if (commands && commands[num_commands - 1].mode == EXTRACT_M) {
- mode = EXTRACT_M;
- } else {
- fprintf(stderr, "unknown additional arguments:\n");
- while (optind < argc)
- fprintf(stderr, " %s", argv[optind++]);
- fprintf(stderr, "\n\n");
- usage(argv[0]);
- exit(1);
+ switch (mode) {
+ while (optind < argc)
+ set_mode(mode, argv[optind++]);
+ break;
+ fprintf(stderr, "unknown additional arguments:\n");
+ while (optind < argc)
+ fprintf(stderr, " %s", argv[optind++]);
+ fprintf(stderr, "\n\n");
+ usage(argv[0]);
+ exit(1);
}
- while (optind < argc)
- set_mode(mode, argv[optind++]);
}
}
Loading...