@@ -82,5 +82,8 @@ extern int sepol_expand_module(sepol_handle_t * handle,
sepol_policydb_t * base,
sepol_policydb_t * out, int verbose, int check);
+char *sepol_module_get_name(sepol_policydb_t *module);
+int sepol_module_check_name_matches_filename(sepol_policydb_t *module, const char *path);
+
__END_DECLS
#endif
@@ -48,5 +48,7 @@ LIBSEPOL_1.1 {
sepol_ppfile_to_module_package;
sepol_module_package_to_cil;
sepol_module_policydb_to_cil;
+ sepol_module_get_name;
+ sepol_module_check_name_matches_filename;
local: *;
} LIBSEPOL_1.0;
@@ -30,6 +30,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
+#include <libgen.h>
#define SEPOL_PACKAGE_SECTION_FC 0xf97cff90
#define SEPOL_PACKAGE_SECTION_SEUSER 0x97cff91
@@ -1006,3 +1007,38 @@ int sepol_expand_module(sepol_handle_t * handle,
{
return expand_module(handle, &base->p, &out->p, verbose, check);
}
+
+char *sepol_module_get_name(sepol_policydb_t *module)
+{
+ return module->p.name;
+}
+
+int sepol_module_check_name_matches_filename(sepol_policydb_t *module, const char *path)
+{
+ char *filepath, *filename, *separator;
+ int rc = -1;
+
+ if (module->p.policy_type == POLICY_BASE)
+ return 0;
+
+ filepath = strdup(path);
+ filename = basename(filepath);
+
+ if (strcmp(module->p.name, filename) != 0) {
+ separator = strrchr(filename, '.');
+ if (separator == NULL)
+ goto exit;
+
+ *separator = '\0';
+
+ if (strcmp(module->p.name, filename) != 0)
+ goto exit;
+ }
+
+ rc = 0;
+
+exit:
+ free(filepath);
+
+ return rc;
+}
The function sepol_module_check_name_matches_filename() compares the module name with a filename (after stripping off path and file extension) and returns 0 if they match. The function sepol_module_get_name() returns the name of the module. Signed-off-by: James Carter <jwcart2@tycho.nsa.gov> --- libsepol/include/sepol/module.h | 3 +++ libsepol/src/libsepol.map.in | 2 ++ libsepol/src/module.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+)