[PATCH 09/13] libsemanage: provide function to get new base module path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The base module is being moved in with the other modules so that it can
benefit from the priority framework. This patch provides a utility
function for getting the highest priority base module path.
---
 libsemanage/src/semanage_store.c |   61 ++++++++++++++++++++++++++++++++++++++
 libsemanage/src/semanage_store.h |   10 ++++++
 2 files changed, 71 insertions(+), 0 deletions(-)

diff --git a/libsemanage/src/semanage_store.c b/libsemanage/src/semanage_store.c
index 62779b3..6b4c2e0 100644
--- a/libsemanage/src/semanage_store.c
+++ b/libsemanage/src/semanage_store.c
@@ -491,6 +491,67 @@ const char *semanage_conf_path(void)
 	return "/etc/selinux/semanage.conf";
 }
 
+/* Locates the highest priority enabled base module
+ * and fills @path in with that value. @path must be
+ * pre-allocated with size @len.
+ *
+ * Returns 0 on success and -1 on error.
+ */
+int semanage_base_path(semanage_handle_t *sh,
+		       char *path,
+		       size_t len)
+{
+	assert(sh);
+	assert(path);
+
+	int status = 0;
+	int ret = 0;
+
+	semanage_module_info_t *base = NULL;
+
+	/* set key for getting base module */
+	semanage_module_key_t modkey;
+	ret = semanage_module_key_init(sh, &modkey);
+	if (ret != 0) {
+		status = -1;
+		goto cleanup;
+	}
+
+	ret = semanage_module_key_set_name(sh, &modkey, "_base");
+	if (ret != 0) {
+		status = -1;
+		goto cleanup;
+	}
+
+	/* get highest priority base module */
+	ret = semanage_module_get_module_info(sh, &modkey, &base);
+	if (ret != 0) {
+		/* no base module found */
+		status = -1;
+		goto cleanup;
+	}
+
+	/* get the highest priority base module path */
+	ret = semanage_module_get_path(
+			sh,
+			base,
+			SEMANAGE_MODULE_PATH_HLL,
+			path,
+			len);
+	if (ret != 0) {
+		status = -1;
+		goto cleanup;
+	}
+
+cleanup:
+	semanage_module_key_destroy(sh, &modkey);
+
+	semanage_module_info_destroy(sh, base);
+	free(base);
+
+	return status;
+}
+
 /**************** functions that create module store ***************/
 
 /* Check that the semanage store exists.  If 'create' is non-zero then
diff --git a/libsemanage/src/semanage_store.h b/libsemanage/src/semanage_store.h
index d3fd554..c6711ce 100644
--- a/libsemanage/src/semanage_store.h
+++ b/libsemanage/src/semanage_store.h
@@ -150,4 +150,14 @@ int semanage_nc_sort(semanage_handle_t * sh,
 		     size_t buf_len,
 		     char **sorted_buf, size_t * sorted_buf_len);
 
+/* Locates the highest priority enabled base module
+ * and fills @path in with that value. @path must be
+ * pre-allocated with size @len.
+ *
+ * Returns 0 on success and -1 on error.
+ */
+int semanage_base_path(semanage_handle_t *sh,
+		       char *path,
+		       size_t len);
+
 #endif
-- 
1.6.0.4


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

[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux