Skip to contentSkip to conversation

allow semodule -i to accept list of modules

PATCH In review Karl MacMillan 3 participants 13 messages Jan 8, 2007 – Jan 11, 2007 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 allow semodule -i to accept list of modules

The following patch allows semodule to handle a list of modules for installation (i.e., semodule -i *.pp now works).

policycoreutils/semodule/semodule.c +18 -9
diff -r e37f9d8d6611 policycoreutils/semodule/semodule.c
@@ -225,15 +225,6 @@ static void parse_command_line(int argc,
 			}
 		}
 	}
-	if (optind < argc) {
-		fprintf(stderr, "Extraneous arguments:  ");
-		while (optind < argc)
-			fprintf(stderr, "%s", argv[optind++]);
-		fprintf(stderr, "\n");
-		usage(argv[0]);
-		cleanup();
-		exit(1);
-	}
 	if ((build || reload) && num_commands) {
 		fprintf(stderr,
 			"build or reload should not be used with other commands\n");
@@ -244,6 +235,24 @@ static void parse_command_line(int argc,
 		fprintf(stderr, "At least one mode must be specified.\n");
 		usage(argv[0]);
 		exit(1);
+	}
+
+	if (optind < argc) {
+		/* if -i was the last command treat any remaining
+		 * arguments as modules to allow 'semodule -i *.pp' to
+		 * work as expected.
+		 */
+		if (commands[num_commands - 1].mode == INSTALL_M) {
+			while (optind < argc)
+				set_mode(INSTALL_M, argv[optind++]);
+		} else {
+			fprintf(stderr, "unknown additional arguments:\n");
+			while (optind < argc)
+				fprintf(stderr, " %s", argv[optind++]);
+			fprintf(stderr, "\n\n");
+			usage(argv[0]);
+			exit(1);
+		}
 	}
 }
 

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#1 lore raw
Quoted 4 lines · Karl MacMillan

The following patch allows semodule to handle a list of modules for installation (i.e., semodule -i *.pp now works).

Hrm, while the current syntax isn't ideal I don't think its the best idea to change it abruptly. maybe you could make -I use the rest of the arguments or something otherwise this will break any number of rpm's, portage, the refpolicy makefiles and so on.

Quoted 50 lines

diff -r e37f9d8d6611 policycoreutils/semodule/semodule.c

policycoreutils/semodule/semodule.c +18 -10
@@ -225,15 +225,6 @@ static void parse_command_line(int argc,
 			}
 		}
 	}
-	if (optind < argc) {
-		fprintf(stderr, "Extraneous arguments:  ");
-		while (optind < argc)
-			fprintf(stderr, "%s", argv[optind++]);
-		fprintf(stderr, "\n");
-		usage(argv[0]);
-		cleanup();
-		exit(1);
-	}
 	if ((build || reload) && num_commands) {
 		fprintf(stderr,
 			"build or reload should not be used with other commands\n");
@@ -244,6 +235,24 @@ static void parse_command_line(int argc,
 		fprintf(stderr, "At least one mode must be specified.\n");
 		usage(argv[0]);
 		exit(1);
+	}
+
+	if (optind < argc) {
+		/* if -i was the last command treat any remaining
+		 * arguments as modules to allow 'semodule -i *.pp' to
+		 * work as expected.
+		 */
+		if (commands[num_commands - 1].mode == INSTALL_M) {
+			while (optind < argc)
+				set_mode(INSTALL_M, argv[optind++]);
+		} else {
+			fprintf(stderr, "unknown additional arguments:\n");
+			while (optind < argc)
+				fprintf(stderr, " %s", argv[optind++]);
+			fprintf(stderr, "\n\n");
+			usage(argv[0]);
+			exit(1);
+		}
 	}
 }
 
 
 
 
--
Quoted 5 lines

This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#2 lore raw
Quoted 7 lines · Joshua Brindle
Quoted 4 lines · Karl MacMillan

The following patch allows semodule to handle a list of modules for installation (i.e., semodule -i *.pp now works).

Hrm, while the current syntax isn't ideal I don't think its the best idea to change it abruptly. maybe you could make -I use the rest of the arguments or something otherwise this will break any number of rpm's, portage, the refpolicy makefiles and so on.

I don't see how this could cause breakage as it doesn't change how any currently valid option sequence is processed. Instead, it makes invalid syntax valid (if you look closely at the patch, you can see that I am actually changing a fatal error path - so what I describe is guaranteed to be true).

I prefer this approach because I think it is the least surprising. I constantly try the syntax this patch allows only to remember that it doesn't work.

Karl

Quoted 51 lines
Quoted 51 lines

diff -r e37f9d8d6611 policycoreutils/semodule/semodule.c
--- a/policycoreutils/semodule/semodule.c Mon Jan 08 15:00:14 2007
-0500
+++ b/policycoreutils/semodule/semodule.c Mon Jan 08 16:37:23 2007
-0500

policycoreutils/semodule/semodule.c +18 -9
@@ -225,15 +225,6 @@ static void parse_command_line(int argc,
             }
         }
     }
-    if (optind < argc) {
-        fprintf(stderr, "Extraneous arguments:  ");
-        while (optind < argc)
-            fprintf(stderr, "%s", argv[optind++]);
-        fprintf(stderr, "\n");
-        usage(argv[0]);
-        cleanup();
-        exit(1);
-    }
     if ((build || reload) && num_commands) {
         fprintf(stderr,
             "build or reload should not be used with other commands\n");
@@ -244,6 +235,24 @@ static void parse_command_line(int argc,
         fprintf(stderr, "At least one mode must be specified.\n");
         usage(argv[0]);
         exit(1);
+    }
+
+    if (optind < argc) {
+        /* if -i was the last command treat any remaining
+         * arguments as modules to allow 'semodule -i *.pp' to
+         * work as expected.
+         */
+        if (commands[num_commands - 1].mode == INSTALL_M) {
+            while (optind < argc)
+                set_mode(INSTALL_M, argv[optind++]);
+        } else {
+            fprintf(stderr, "unknown additional arguments:\n");
+            while (optind < argc)
+                fprintf(stderr, " %s", argv[optind++]);
+            fprintf(stderr, "\n\n");
+            usage(argv[0]);
+            exit(1);
+        }
     }
 }
 
Quoted 8 lines
Quoted 6 lines
Signature · 3 lines
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#3 lore raw
Quoted 6 lines · Karl MacMillan
Quoted 5 lines · Joshua Brindle
Quoted 4 lines · Karl MacMillan

The following patch allows semodule to handle a list of modules for installation (i.e., semodule -i *.pp now works).

Quoted 7 lines
Quoted 2 lines

Hrm, while the current syntax isn't ideal I don't think its the best idea to change it abruptly. maybe you could make -I use the rest of the arguments or something otherwise this will break any number of rpm's, portage, the refpolicy makefiles and so on.

I don't see how this could cause breakage as it doesn't change how any currently valid option sequence is processed. Instead, it makes invalid syntax valid (if you look closely at the patch, you can see that I am actually changing a fatal error path - so what I describe is guaranteed to be true).

I prefer this approach because I think it is the least surprising. I constantly try the syntax this patch allows only to remember that it doesn't work.

oops, you are right.. do you think having 2 distinct syntaxes for the same argument will be less surprising than splitting them up?

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#4 lore raw
Quoted 10 lines · Joshua Brindle
Quoted 9 lines · Karl MacMillan
Quoted 7 lines · Joshua Brindle
Quoted 4 lines · Karl MacMillan

The following patch allows semodule to handle a list of modules for installation (i.e., semodule -i *.pp now works).

Hrm, while the current syntax isn't ideal I don't think its the best idea to change it abruptly. maybe you could make -I use the rest of the arguments or something otherwise this will break any number of rpm's, portage, the refpolicy makefiles and so on.

Quoted 7 lines
Quoted 4 lines

I don't see how this could cause breakage as it doesn't change how any currently valid option sequence is processed. Instead, it makes invalid syntax valid (if you look closely at the patch, you can see that I am actually changing a fatal error path - so what I describe is guaranteed to be true).

I prefer this approach because I think it is the least surprising. I constantly try the syntax this patch allows only to remember that it doesn't work.

oops, you are right.. do you think having 2 distinct syntaxes for the same argument will be less surprising than splitting them up?

No. I think that common current usage is 'semodule -i somemodule.pp' and 'semodule -i *.pp' (or some other glob) is very natural. I doubt that many people actually use 'semodule -i foo.pp -i bar.pp' besides some scripts.

Karl

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

Acked-by on v1 1/1
#5 lore raw
In reply to Karl MacMillan
Quoted 6 lines · Karl MacMillan

The following patch allows semodule to handle a list of modules for installation (i.e., semodule -i *.pp now works).

Quoted 48 lines

diff -r e37f9d8d6611 policycoreutils/semodule/semodule.c

policycoreutils/semodule/semodule.c +18 -10
@@ -225,15 +225,6 @@ static void parse_command_line(int argc,
 			}
 		}
 	}
-	if (optind < argc) {
-		fprintf(stderr, "Extraneous arguments:  ");
-		while (optind < argc)
-			fprintf(stderr, "%s", argv[optind++]);
-		fprintf(stderr, "\n");
-		usage(argv[0]);
-		cleanup();
-		exit(1);
-	}
 	if ((build || reload) && num_commands) {
 		fprintf(stderr,
 			"build or reload should not be used with other commands\n");
@@ -244,6 +235,24 @@ static void parse_command_line(int argc,
 		fprintf(stderr, "At least one mode must be specified.\n");
 		usage(argv[0]);
 		exit(1);
+	}
+
+	if (optind < argc) {
+		/* if -i was the last command treat any remaining
+		 * arguments as modules to allow 'semodule -i *.pp' to
+		 * work as expected.
+		 */
+		if (commands[num_commands - 1].mode == INSTALL_M) {
+			while (optind < argc)
+				set_mode(INSTALL_M, argv[optind++]);
+		} else {
+			fprintf(stderr, "unknown additional arguments:\n");
+			while (optind < argc)
+				fprintf(stderr, " %s", argv[optind++]);
+			fprintf(stderr, "\n\n");
+			usage(argv[0]);
+			exit(1);
+		}
 	}
 }
 
 
 
 
--
Quoted 5 lines

This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#6 lore raw
Quoted 8 lines · Joshua Brindle
Quoted 6 lines · Karl MacMillan

The following patch allows semodule to handle a list of modules for installation (i.e., semodule -i *.pp now works).

This means we can also update the semodule man page to remove the gross hack we came up with to workaround the absence of such support,
# Replace all modules with the ones in the current directory $ semodule -b base.pp ‘semodule -l | awk ’{print "-i " $1
".pp"}’‘

Quoted 47 lines
Quoted 47 lines

diff -r e37f9d8d6611 policycoreutils/semodule/semodule.c

policycoreutils/semodule/semodule.c +18 -9
@@ -225,15 +225,6 @@ static void parse_command_line(int argc,
 			}
 		}
 	}
-	if (optind < argc) {
-		fprintf(stderr, "Extraneous arguments:  ");
-		while (optind < argc)
-			fprintf(stderr, "%s", argv[optind++]);
-		fprintf(stderr, "\n");
-		usage(argv[0]);
-		cleanup();
-		exit(1);
-	}
 	if ((build || reload) && num_commands) {
 		fprintf(stderr,
 			"build or reload should not be used with other commands\n");
@@ -244,6 +235,24 @@ static void parse_command_line(int argc,
 		fprintf(stderr, "At least one mode must be specified.\n");
 		usage(argv[0]);
 		exit(1);
+	}
+
+	if (optind < argc) {
+		/* if -i was the last command treat any remaining
+		 * arguments as modules to allow 'semodule -i *.pp' to
+		 * work as expected.
+		 */
+		if (commands[num_commands - 1].mode == INSTALL_M) {
+			while (optind < argc)
+				set_mode(INSTALL_M, argv[optind++]);
+		} else {
+			fprintf(stderr, "unknown additional arguments:\n");
+			while (optind < argc)
+				fprintf(stderr, " %s", argv[optind++]);
+			fprintf(stderr, "\n\n");
+			usage(argv[0]);
+			exit(1);
+		}
 	}
 }
 
Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#7 lore raw
Quoted 10 lines · Stephen Smalley
Quoted 8 lines · Joshua Brindle
Quoted 6 lines · Karl MacMillan

The following patch allows semodule to handle a list of modules for installation (i.e., semodule -i *.pp now works).

Quoted 7 lines

This means we can also update the semodule man page to remove the gross hack we came up with to workaround the absence of such support,
# Replace all modules with the ones in the current directory $ semodule -b base.pp ‘semodule -l | awk ’{print "-i " $1
".pp"}’‘

BTW, any reason we wouldn't support the same thing for -u or -r?

Quoted 49 lines
Quoted 48 lines
Quoted 48 lines

diff -r e37f9d8d6611 policycoreutils/semodule/semodule.c

policycoreutils/semodule/semodule.c +18 -9
@@ -225,15 +225,6 @@ static void parse_command_line(int argc,
 			}
 		}
 	}
-	if (optind < argc) {
-		fprintf(stderr, "Extraneous arguments:  ");
-		while (optind < argc)
-			fprintf(stderr, "%s", argv[optind++]);
-		fprintf(stderr, "\n");
-		usage(argv[0]);
-		cleanup();
-		exit(1);
-	}
 	if ((build || reload) && num_commands) {
 		fprintf(stderr,
 			"build or reload should not be used with other commands\n");
@@ -244,6 +235,24 @@ static void parse_command_line(int argc,
 		fprintf(stderr, "At least one mode must be specified.\n");
 		usage(argv[0]);
 		exit(1);
+	}
+
+	if (optind < argc) {
+		/* if -i was the last command treat any remaining
+		 * arguments as modules to allow 'semodule -i *.pp' to
+		 * work as expected.
+		 */
+		if (commands[num_commands - 1].mode == INSTALL_M) {
+			while (optind < argc)
+				set_mode(INSTALL_M, argv[optind++]);
+		} else {
+			fprintf(stderr, "unknown additional arguments:\n");
+			while (optind < argc)
+				fprintf(stderr, " %s", argv[optind++]);
+			fprintf(stderr, "\n\n");
+			usage(argv[0]);
+			exit(1);
+		}
 	}
 }
 
Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#8 lore raw
Quoted 13 lines · Stephen Smalley
Quoted 12 lines · Stephen Smalley
Quoted 8 lines · Joshua Brindle
Quoted 6 lines · Karl MacMillan

The following patch allows semodule to handle a list of modules for installation (i.e., semodule -i *.pp now works).

Quoted 8 lines
Quoted 5 lines

This means we can also update the semodule man page to remove the gross hack we came up with to workaround the absence of such support,
# Replace all modules with the ones in the current directory $ semodule -b base.pp ‘semodule -l | awk ’{print "-i " $1
".pp"}’‘

BTW, any reason we wouldn't support the same thing for -u or -r?

Patch below. It is less useful for -r, but still potentially easier. As for the man page, that is updated but the command for updating from /usr/share/selinux/policyname still sucks. I came up with:

ls *.pp | grep -Ev "base.pp|enableaudit.pp" | xargs /usr/sbin/semodule -i

Gets rid of awk (so it is potentially easier for many), but it is longer. At some point someone should make semodule just do the right thing for a mixed list of modules and base modules. Of course, even that wouldn't work for the /usr/share/selinux directories because of enableaudit, so I give up.

policycoreutils/semodule/semodule.8 +4 -1
diff -r a70fbd24a437 policycoreutils/semodule/semodule.8
@@ -59,7 +59,10 @@ be verbose
 # List non-base modules.
 $ semodule -l
 # Replace all modules with the ones in the current directory
-$ semodule -b base.pp `semodule -l | awk '{print "-i " $1 ".pp"}'`
+$ semodule -i *.pp
+# Replace all modules with the ones in the current directory
+# excluding base.pp and enableaudit.pp
+$ ls *.pp | grep -Ev "base.pp|enableaudit.pp" | xargs /usr/sbin/semodule -i
 .fi
 
 .SH SEE ALSO
policycoreutils/semodule/semodule.c +10 -4
diff -r a70fbd24a437 policycoreutils/semodule/semodule.c
@@ -238,13 +238,17 @@ static void parse_command_line(int argc,
 	}
 
 	if (optind < argc) {
-		/* if -i was the last command treat any remaining
-		 * arguments as modules to allow 'semodule -i *.pp' to
+		int mode;
+		/* if -i/u/r was the last command treat any remaining
+		 * arguments as args. Will allow 'semodule -i *.pp' to
 		 * work as expected.
 		 */
 		if (commands[num_commands - 1].mode == INSTALL_M) {
-			while (optind < argc)
-				set_mode(INSTALL_M, argv[optind++]);
+			mode = INSTALL_M;
+		} else if (commands[num_commands - 1].mode == UPGRADE_M) {
+			mode = UPGRADE_M;
+		} else if (commands[num_commands - 1].mode == REMOVE_M) {
+			mode = REMOVE_M;
 		} else {
 			fprintf(stderr, "unknown additional arguments:\n");
 			while (optind < argc)
@@ -253,6 +257,8 @@ static void parse_command_line(int argc,
 			usage(argv[0]);
 			exit(1);
 		}
+		while (optind < argc)
+			set_mode(mode, argv[optind++]);
 	}
 }
 

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#9 lore raw
Quoted 23 lines · Karl MacMillan
Quoted 13 lines · Stephen Smalley
Quoted 12 lines · Stephen Smalley
Quoted 8 lines · Joshua Brindle
Quoted 6 lines · Karl MacMillan

The following patch allows semodule to handle a list of modules for installation (i.e., semodule -i *.pp now works).

Quoted 8 lines
Quoted 5 lines

This means we can also update the semodule man page to remove the gross hack we came up with to workaround the absence of such support,
# Replace all modules with the ones in the current directory $ semodule -b base.pp ‘semodule -l | awk ’{print "-i " $1
".pp"}’‘

BTW, any reason we wouldn't support the same thing for -u or -r?

Quoted 6 lines

Patch below. It is less useful for -r, but still potentially easier. As for the man page, that is updated but the command for updating from /usr/share/selinux/policyname still sucks. I came up with:

ls *.pp | grep -Ev "base.pp|enableaudit.pp" | xargs /usr/sbin/semodule -i

That has a different effect. The original command replaces the base module and any already installed module (semodule -l output) with ones from the current directory as a single transaction without installing any new modules, while your command would replace any non-base modules and install any new ones, without updating the base module (which could very well fail due to dependencies on the base). Both actually seem wrong to me - we do want to install all of the non-base modules from the directory as per your command but we need to include the base in the same transaction.

Quoted 59 lines

Gets rid of awk (so it is potentially easier for many), but it is longer. At some point someone should make semodule just do the right thing for a mixed list of modules and base modules. Of course, even that wouldn't work for the /usr/share/selinux directories because of enableaudit, so I give up.

diff -r a70fbd24a437 policycoreutils/semodule/semodule.8

policycoreutils/semodule/semodule.8 +4 -1
@@ -59,7 +59,10 @@ be verbose
 # List non-base modules.
 $ semodule -l
 # Replace all modules with the ones in the current directory
-$ semodule -b base.pp `semodule -l | awk '{print "-i " $1 ".pp"}'`
+$ semodule -i *.pp
+# Replace all modules with the ones in the current directory
+# excluding base.pp and enableaudit.pp
+$ ls *.pp | grep -Ev "base.pp|enableaudit.pp" | xargs /usr/sbin/semodule -i
 .fi
 
 .SH SEE ALSO

diff -r a70fbd24a437 policycoreutils/semodule/semodule.c

policycoreutils/semodule/semodule.c +10 -4
@@ -238,13 +238,17 @@ static void parse_command_line(int argc,
 	}
 
 	if (optind < argc) {
-		/* if -i was the last command treat any remaining
-		 * arguments as modules to allow 'semodule -i *.pp' to
+		int mode;
+		/* if -i/u/r was the last command treat any remaining
+		 * arguments as args. Will allow 'semodule -i *.pp' to
 		 * work as expected.
 		 */
 		if (commands[num_commands - 1].mode == INSTALL_M) {
-			while (optind < argc)
-				set_mode(INSTALL_M, argv[optind++]);
+			mode = INSTALL_M;
+		} else if (commands[num_commands - 1].mode == UPGRADE_M) {
+			mode = UPGRADE_M;
+		} else if (commands[num_commands - 1].mode == REMOVE_M) {
+			mode = REMOVE_M;
 		} else {
 			fprintf(stderr, "unknown additional arguments:\n");
 			while (optind < argc)
@@ -253,6 +257,8 @@ static void parse_command_line(int argc,
 			usage(argv[0]);
 			exit(1);
 		}
+		while (optind < argc)
+			set_mode(mode, argv[optind++]);
 	}
 }
 
Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#10 lore raw
Quoted 90 lines · Stephen Smalley
Quoted 23 lines · Karl MacMillan
Quoted 13 lines · Stephen Smalley
Quoted 12 lines · Stephen Smalley
Quoted 8 lines · Joshua Brindle
Quoted 6 lines · Karl MacMillan

The following patch allows semodule to handle a list of modules for installation (i.e., semodule -i *.pp now works).

Quoted 8 lines
Quoted 5 lines

This means we can also update the semodule man page to remove the gross hack we came up with to workaround the absence of such support,
# Replace all modules with the ones in the current directory $ semodule -b base.pp ‘semodule -l | awk ’{print "-i " $1
".pp"}’‘

BTW, any reason we wouldn't support the same thing for -u or -r?

Quoted 6 lines

Patch below. It is less useful for -r, but still potentially easier. As for the man page, that is updated but the command for updating from /usr/share/selinux/policyname still sucks. I came up with:

ls *.pp | grep -Ev "base.pp|enableaudit.pp" | xargs /usr/sbin/semodule -i

That has a different effect. The original command replaces the base module and any already installed module (semodule -l output) with ones from the current directory as a single transaction without installing any new modules, while your command would replace any non-base modules and install any new ones, without updating the base module (which could very well fail due to dependencies on the base). Both actually seem wrong to me - we do want to install all of the non-base modules from the directory as per your command but we need to include the base in the same transaction.

Quoted 49 lines

Gets rid of awk (so it is potentially easier for many), but it is longer. At some point someone should make semodule just do the right thing for a mixed list of modules and base modules. Of course, even that wouldn't work for the /usr/share/selinux directories because of enableaudit, so I give up.

diff -r a70fbd24a437 policycoreutils/semodule/semodule.8

policycoreutils/semodule/semodule.8 +4 -1
@@ -59,7 +59,10 @@ be verbose
 # List non-base modules.
 $ semodule -l
 # Replace all modules with the ones in the current directory
-$ semodule -b base.pp `semodule -l | awk '{print "-i " $1 ".pp"}'`
+$ semodule -i *.pp
+# Replace all modules with the ones in the current directory
+# excluding base.pp and enableaudit.pp
+$ ls *.pp | grep -Ev "base.pp|enableaudit.pp" | xargs /usr/sbin/semodule -i
 .fi
 
 .SH SEE ALSO

diff -r a70fbd24a437 policycoreutils/semodule/semodule.c

policycoreutils/semodule/semodule.c +8 -4
@@ -238,13 +238,17 @@ static void parse_command_line(int argc,
 	}
 
 	if (optind < argc) {
-		/* if -i was the last command treat any remaining
-		 * arguments as modules to allow 'semodule -i *.pp' to
+		int mode;
+		/* if -i/u/r was the last command treat any remaining
+		 * arguments as args. Will allow 'semodule -i *.pp' to
 		 * work as expected.
 		 */
 		if (commands[num_commands - 1].mode == INSTALL_M) {
-			while (optind < argc)
-				set_mode(INSTALL_M, argv[optind++]);
+			mode = INSTALL_M;
+		} else if (commands[num_commands - 1].mode == UPGRADE_M) {
+			mode = UPGRADE_M;
+		} else if (commands[num_commands - 1].mode == REMOVE_M) {
+			mode = REMOVE_M;
 		} else {
 			fprintf(stderr, "unknown additional arguments:\n");
 			while (optind < argc)
@@ -253,6 +257,8 @@ static void parse_command_line(int argc,
Quoted 8 lines

policycoreutils/semodule/semodule.c static void parse_command_line(int argc, · line 264

Quoted 8 lines
policycoreutils/semodule/semodule.c +2 -0
 			usage(argv[0]);
 			exit(1);
 		}
+		while (optind < argc)
+			set_mode(mode, argv[optind++]);
 	}
 }
 

Merged with some changes to the man page in policycoreutils 1.33.12.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#11 lore raw
In reply to Stephen Smalley
Quoted 15 lines

From: Stephen Smalley [mailto:[email protected]]

Quoted 12 lines · Stephen Smalley
Quoted 8 lines · Joshua Brindle
Quoted 6 lines · Karl MacMillan

The following patch allows semodule to handle a list of modules for installation (i.e., semodule -i *.pp now works).

Quoted 9 lines
Quoted 2 lines

This means we can also update the semodule man page to remove the gross hack we came up with to workaround the absence of

such support,

Quoted 3 lines

# Replace all modules with the ones in the current directory $ semodule -b base.pp 'semodule -l | awk '{print "-i " $1
".pp"}''

BTW, any reason we wouldn't support the same thing for -u or -r?

-r wouldn't work well because it wants the name of the module (eg., apache) instead of the filename (apache.pp)

Quoted 59 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

diff -r e37f9d8d6611 policycoreutils/semodule/semodule.c
--- a/policycoreutils/semodule/semodule.c Mon Jan

08 15:00:14 2007 -0500

Quoted 1 line
Quoted 1 line
Quoted 1 line

+++ b/policycoreutils/semodule/semodule.c Mon Jan

08 16:37:23 2007 -0500

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
policycoreutils/semodule/semodule.c +0 -4
@@ -225,15 +225,6 @@ static void parse_command_line(int argc,
 			}
 		}
 	}
-	if (optind < argc) {
-		fprintf(stderr, "Extraneous arguments:  ");
-		while (optind < argc)
-			fprintf(stderr, "%s", argv[optind++]);
Quoted 8 lines
Quoted 8 lines

policycoreutils/semodule/semodule.c static void parse_command_line(int argc,

Quoted 8 lines
policycoreutils/semodule/semodule.c +0 -5
-		fprintf(stderr, "\n");
-		usage(argv[0]);
-		cleanup();
-		exit(1);
-	}
 	if ((build || reload) && num_commands) {
 		fprintf(stderr,
 			"build or reload should not be 

used with other commands\n");

Quoted 2 lines
Quoted 2 lines

Review static void parse_command_line(int argc, · line 235

Quoted 2 lines
(quoted diff) +0 -0
@@ -244,6 +235,24 @@ static void parse_command_line(int argc,
 		fprintf(stderr, "At least one mode must 

be specified.\n");

Quoted 6 lines
Quoted 6 lines

policycoreutils/semodule/semodule.c static void parse_command_line(int argc,

Quoted 6 lines
policycoreutils/semodule/semodule.c +4 -0
 		usage(argv[0]);
 		exit(1);
+	}
+
+	if (optind < argc) {
+		/* if -i was the last command treat any 

remaining

Quoted 1 line
Quoted 1 line

Review static void parse_command_line(int argc, · line 242

Quoted 1 line
(quoted diff) +1 -0
+		 * arguments as modules to allow 

'semodule -i *.pp' to

Quoted 3 lines
Quoted 3 lines

policycoreutils/semodule/semodule.c static void parse_command_line(int argc,

Quoted 3 lines
policycoreutils/semodule/semodule.c +3 -0
+		 * work as expected.
+		 */
+		if (commands[num_commands - 1].mode == 

INSTALL_M) {

Quoted 2 lines
Quoted 2 lines

Review static void parse_command_line(int argc, · line 247

Quoted 2 lines
(quoted diff) +2 -0
+			while (optind < argc)
+				set_mode(INSTALL_M, 

argv[optind++]);

Quoted 2 lines
Quoted 2 lines

Review static void parse_command_line(int argc, · line 249

Quoted 2 lines
(quoted diff) +2 -0
+		} else {
+			fprintf(stderr, "unknown 

additional arguments:\n");

Quoted 2 lines
Quoted 2 lines

Review static void parse_command_line(int argc, · line 251

Quoted 2 lines
(quoted diff) +2 -0
+			while (optind < argc)
+				fprintf(stderr, " %s", 

argv[optind++]);

Quoted 11 lines
Quoted 10 lines

policycoreutils/semodule/semodule.c static void parse_command_line(int argc, · line 258

Quoted 10 lines
policycoreutils/semodule/semodule.c +4 -0
+			fprintf(stderr, "\n\n");
+			usage(argv[0]);
+			exit(1);
+		}
 	}
 }
 
Quoted 5 lines

--
Stephen Smalley
National Security Agency

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#12 lore raw
Quoted 22 lines · Joshua Brindle
Quoted 22 lines

From: Stephen Smalley [mailto:[email protected]]

Quoted 8 lines · Stephen Smalley
Quoted 7 lines · Joshua Brindle
Quoted 6 lines · Karl MacMillan

The following patch allows semodule to handle a list of modules for installation (i.e., semodule -i *.pp now works).

Quoted 6 lines
Quoted 1 line

This means we can also update the semodule man page to remove the gross hack we came up with to workaround the absence of

such support,

Quoted 3 lines

# Replace all modules with the ones in the current directory $ semodule -b base.pp 'semodule -l | awk '{print "-i " $1
".pp"}''

Quoted 5 lines
Quoted 2 lines

BTW, any reason we wouldn't support the same thing for -u or -r?

-r wouldn't work well because it wants the name of the module (eg., apache) instead of the filename (apache.pp)

Still useful for e.g. removing a list of modules specified in a file, ala semodule -r cat killlist

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.