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