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 <csellers@tresys.com>
This commit is contained in:
Caleb Case 2009-12-23 18:25:56 -05:00 committed by Steve Lawrence
parent d4048fa522
commit f2c4e796af
2 changed files with 71 additions and 0 deletions

View File

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

View File

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