Skip to contentSkip to conversation

Last attempt at upstreaming semodule_disable patch.

PATCH Daniel J Walsh 4 participants 7 messages Feb 24, 2010 – Mar 6, 2010 SELinux security module

lore
Share & tools
lore
#0 lore raw

This patch allows you to disable/Enable policy modules.

It never seems to get upstreamed. :^(

libsemanage/include/semanage/modules.h +4 -1
index e169279..349a50e 100644
@@ -40,10 +40,12 @@ int semanage_module_install_base(semanage_handle_t *,
 				 char *module_data, size_t data_len);
 int semanage_module_install_base_file(semanage_handle_t *,
 				      const char *module_name);
+int semanage_module_enable(semanage_handle_t *, char *module_name);
+int semanage_module_disable(semanage_handle_t *, char *module_name);
 int semanage_module_remove(semanage_handle_t *, char *module_name);
 
 /* semanage_module_info is for getting information on installed
-   modules, only name and version at this time */
+   modules, only name and version, and enabled/disabled flag at this time */
 typedef struct semanage_module_info semanage_module_info_t;
 
 int semanage_module_list(semanage_handle_t *,
@@ -53,5 +55,6 @@ semanage_module_info_t *semanage_module_list_nth(semanage_module_info_t * list,
 						 int n);
 const char *semanage_module_get_name(semanage_module_info_t *);
 const char *semanage_module_get_version(semanage_module_info_t *);
+int semanage_module_get_enabled(semanage_module_info_t *);
 
 #endif
libsemanage/src/direct_api.c +116 -3

164 lines not on this page · raw message

libsemanage/src/libsemanage.map +3 -0
index d15f69d..762e20e 100644
@@ -6,10 +6,13 @@ LIBSEMANAGE_1.0 {
 	  semanage_module_install; semanage_module_install_file;
 	  semanage_module_upgrade; semanage_module_upgrade_file;
 	  semanage_module_install_base; semanage_module_install_base_file;
+	  semanage_module_enable;
+	  semanage_module_disable;
 	  semanage_module_remove;
 	  semanage_module_list; semanage_module_info_datum_destroy;
 	  semanage_module_list_nth; semanage_module_get_name;
 	  semanage_module_get_version; semanage_select_store;
+	  semanage_module_get_enabled;
 	  semanage_reload_policy; semanage_set_reload; semanage_set_rebuild;
 	  semanage_user_*; semanage_bool_*; semanage_seuser_*;
 	  semanage_iface_*; semanage_port_*; semanage_context_*;
libsemanage/src/module_internal.h +1 -0
index f074a3a..04f767b 100644
@@ -6,6 +6,7 @@
 
 hidden_proto(semanage_module_get_name)
     hidden_proto(semanage_module_get_version)
+    hidden_proto(semanage_module_get_enabled)
     hidden_proto(semanage_module_info_datum_destroy)
     hidden_proto(semanage_module_list_nth)
 #endif
libsemanage/src/modules.c +41 -0

53 lines not on this page · raw message

libsemanage/src/modules.h +1 -0
index 381b108..8d2e60c 100644
@@ -26,6 +26,7 @@
 struct semanage_module_info {
 	char *name;		/* Key */
 	char *version;
+	int enabled;
 };
 
 #endif
libsemanage/src/policy.h +6 -0
index ebefc02..627b526 100644
@@ -58,6 +58,12 @@ struct semanage_policy_table {
 	/* Upgrade a policy module */
 	int (*upgrade_file) (struct semanage_handle *, const char *);
 
+	/* Enable a policy module */
+	int (*enable) (struct semanage_handle *, char *);
+
+	/* Disable a policy module */
+	int (*disable) (struct semanage_handle *, char *);
+
 	/* Remove a policy module */
 	int (*remove) (struct semanage_handle *, char *);
 
libsemanage/src/semanage_store.c +49 -11

96 lines not on this page · raw message

libsemanage/src/semanage_store.h +2 -0
index 112edb6..9e8b1fd 100644
@@ -128,4 +128,6 @@ int semanage_nc_sort(semanage_handle_t * sh,
 		     size_t buf_len,
 		     char **sorted_buf, size_t * sorted_buf_len);
 
+extern const char *DISABLESTR;
+
 #endif
policycoreutils/semodule/semodule.8 +6 -0
index 1c1d206..12191f6 100644
@@ -35,6 +35,12 @@ upgrade an existing module package, or install if the module does not exist
 .B  \-b,\-\-base=MODULE_PKG   
 install/replace base module package
 .TP
+.B  \-d,\-\-disable=MODULE_NAME
+disable existing module
+.TP
+.B  \-e,\-\-enable=MODULE_NAME
+enable existing module
+.TP
 .B  \-r,\-\-remove=MODULE_NAME
 remove existing module
 .TP
policycoreutils/semodule/semodule.c +46 -7

109 lines not on this page · raw message

#1 lore raw
Quoted 3 lines · Daniel J Walsh

This patch allows you to disable/Enable policy modules.

It never seems to get upstreamed. :^(

This is a wonderful feature. It allows me to replace existing modules and to easily modify existing policy.

#2 lore raw
In reply to Daniel J Walsh
Quoted 3 lines · Daniel J Walsh

This patch allows you to disable/Enable policy modules.

It never seems to get upstreamed. :^(

Caleb's patch set in December not only moves the policy store and adds priority support, it also allows modules to be enabled and disabled.

The hope is that that patch set as well as the one adding support for source policy modules can be upstreamed sometime in the near future.

Signature · 8 lines
James Carter <[email protected]>
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.
#3 lore raw
Quoted 4 lines · James Carter
Quoted 2 lines · Daniel J Walsh

This patch allows you to disable/Enable policy modules.

Quoted 9 lines
Quoted 2 lines

It never seems to get upstreamed. :^(

Caleb's patch set in December not only moves the policy store and adds priority support, it also allows modules to be enabled and disabled.

The hope is that that patch set as well as the one adding support for source policy modules can be upstreamed sometime in the near future.

Yes I look forward to that patch but that is not going to be used until Fedora 14 at the earliest. Anyone distros working off the current code, could use this patch. But if it is not wanted, I can leave it as a patch for the next 7 years. :^)

--
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
In reply to James Carter
Quoted 4 lines · James Carter
Quoted 2 lines · Daniel J Walsh

This patch allows you to disable/Enable policy modules.

Quoted 10 lines
Quoted 2 lines

It never seems to get upstreamed. :^(

Caleb's patch set in December not only moves the policy store and adds priority support, it also allows modules to be enabled and disabled.

The hope is that that patch set as well as the one adding support for source policy modules can be upstreamed sometime in the near future.

As long as the user interface stays the same I'm fine with the concept of this patch (the stuff under the covers will change but that is not a problem).

I'll review it and ack or give feedback soon.

#5 lore raw
In reply to Daniel J Walsh
Quoted 3 lines · Daniel J Walsh

This patch allows you to disable/Enable policy modules.

It never seems to get upstreamed. :^(

Applied the attached patch on top of it, it fixes an implicit declaration warning, makes the errors for disabling or enabling an already disabled or enabled module nicer and fixes a comment.

libsemanage/src/direct_api.c +28 -17
index 2acfeca..399d740 100644
@@ -1304,8 +1304,14 @@ static int semanage_direct_enable(semanage_handle_t * sh, char *module_name)
 			goto cleanup;
 		}
 		base++;
-		if (memcmp(module_name, base, name_len) == 0 &&
-		    strcmp(base + name_len + 3, DISABLESTR) == 0) {
+		if (memcmp(module_name, base, name_len) == 0) {
+
+			if(strcmp(base + name_len + 3, DISABLESTR) != 0) {
+				ERR(sh, "Module %s is already enabled.", module_name);
+				retval = -2;
+				goto cleanup;
+			}
+
 			int len = strlen(module_filenames[i]) - strlen(DISABLESTR);
 			char *enabled_name = calloc(1, len+1);
 			if (!enabled_name) {
@@ -1336,7 +1342,7 @@ static int semanage_direct_enable(semanage_handle_t * sh, char *module_name)
 	return retval;
 }
 
-/* Enables a module from the sandbox.  Returns 0 on success, -1 if out
+/* Disables a module from the sandbox.  Returns 0 on success, -1 if out
  * of memory, -2 if module not found or could not be enabled. */
 static int semanage_direct_disable(semanage_handle_t * sh, char *module_name)
 {
@@ -1356,23 +1362,28 @@ static int semanage_direct_disable(semanage_handle_t * sh, char *module_name)
 			goto cleanup;
 		}
 		base++;
-		if (memcmp(module_name, base, name_len) == 0 &&
-		    strcmp(base + name_len, ".pp") == 0) {
-			char disabled_name[PATH_MAX];
-			if (snprintf(disabled_name, PATH_MAX, "%s%s", 
-				     module_filenames[i], DISABLESTR) == PATH_MAX) {
-				ERR(sh, "Could not disable module file %s.",
-				    module_filenames[i]);
+		if (memcmp(module_name, base, name_len) == 0) {
+			if (strcmp(base + name_len + 3, DISABLESTR) == 0) {
+				ERR(sh, "Module %s is already disabled.", module_name);
 				retval = -2;
 				goto cleanup;
+			} else if (strcmp(base + name_len, ".pp") == 0) {
+				char disabled_name[PATH_MAX];
+				if (snprintf(disabled_name, PATH_MAX, "%s%s", 
+							module_filenames[i], DISABLESTR) == PATH_MAX) {
+					ERR(sh, "Could not disable module file %s.",
+							module_filenames[i]);
+					retval = -2;
+					goto cleanup;
+				}
+				if (rename(module_filenames[i], disabled_name) == -1) {
+					ERR(sh, "Could not disable module file %s.",
+							module_filenames[i]);
+					retval = -2;
+				}
+				retval = 0;
+				goto cleanup;
 			}
-			if (rename(module_filenames[i], disabled_name) == -1) {
-				ERR(sh, "Could not disable module file %s.",
-				    module_filenames[i]);
-				retval = -2;
-			}
-			retval = 0;
-			goto cleanup;
 		}
 	}
 	ERR(sh, "Module %s was not found.", module_name);
libsemanage/src/semanage_store.h +1 -0
index 9e8b1fd..6abb2ee 100644
@@ -84,6 +84,7 @@ int semanage_make_sandbox(semanage_handle_t * sh);
 int semanage_get_modules_names(semanage_handle_t * sh,
 			       char ***filenames, int *len);
 
+int semanage_module_enabled(const char *file);
 /* lock file routines */
 int semanage_get_trans_lock(semanage_handle_t * sh);
 int semanage_get_active_lock(semanage_handle_t * sh);
#6 lore raw
Quoted 11 lines · Joshua Brindle
Quoted 3 lines · Daniel J Walsh

This patch allows you to disable/Enable policy modules.

It never seems to get upstreamed. :^(

Applied the attached patch on top of it, it fixes an implicit declaration warning, makes the errors for disabling or enabling an already disabled or enabled module nicer and fixes a comment.

Merged in libsemanage 2.0.45

--
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.