From f2c4e796af114de7c2776a7070b01687b416b7c7 Mon Sep 17 00:00:00 2001 From: Caleb Case Date: Wed, 23 Dec 2009 18:25:56 -0500 Subject: [PATCH] libsemanage: provide function to get new base module path 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. Signed-off-by: Chad Sellers --- libsemanage/src/semanage_store.c | 61 ++++++++++++++++++++++++++++++++ libsemanage/src/semanage_store.h | 10 ++++++ 2 files changed, 71 insertions(+) diff --git a/libsemanage/src/semanage_store.c b/libsemanage/src/semanage_store.c index 5965aa02..8322b482 100644 --- a/libsemanage/src/semanage_store.c +++ b/libsemanage/src/semanage_store.c @@ -493,6 +493,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 01d87c50..06b52c5e 100644 --- a/libsemanage/src/semanage_store.h +++ b/libsemanage/src/semanage_store.h @@ -153,4 +153,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