1 From 9d25ca61603a2eed08d1b58b25c81f878c729474 Mon Sep 17 00:00:00 2001
2 From: James Carter <jwcart2@tycho.nsa.gov>
3 Date: Mon, 3 Oct 2016 14:15:40 -0400
4 Subject: [PATCH] libsemanage: Fixes bug preventing the installation of base
7 Commit 7a728e46 changed module installation so that a module pp would
8 be installed using its module name instead of its filename and a warning
9 would be printed if they were different. With this change, base modules
10 could no longer be installed because of the way error handling was done.
12 This change fixes the error handling, so that when a base module is
13 installed it will be installed using its filename (since it does not
16 Based on bug report by Jason Zaman
18 Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
20 libsemanage/src/direct_api.c | 39 ++++++++++++++-------------------------
21 1 file changed, 14 insertions(+), 25 deletions(-)
23 diff --git a/libsemanage/src/direct_api.c b/libsemanage/src/direct_api.c
24 index 3719cb1..e5c72cd 100644
25 --- libsemanage/src/direct_api.c
26 +++ libsemanage/src/direct_api.c
27 @@ -368,7 +368,7 @@ static int semanage_direct_begintrans(semanage_handle_t * sh)
28 * 'version' to module's version. The caller is responsible for
29 * free()ing 'module_name', and 'version'; they will be
30 * set to NULL upon entering this function. Returns 0 on success, -1
31 - * if out of memory, or -2 if data did not represent a module.
34 static int parse_module_headers(semanage_handle_t * sh, char *module_data,
35 size_t data_len, char **module_name,
36 @@ -384,23 +384,10 @@ static int parse_module_headers(semanage_handle_t * sh, char *module_data,
38 sepol_policy_file_set_mem(pf, module_data, data_len);
39 sepol_policy_file_set_handle(pf, sh->sepolh);
40 - if (module_data == NULL ||
42 + if (module_data != NULL && data_len > 0)
43 sepol_module_package_info(pf, &file_type, module_name,
45 - sepol_policy_file_free(pf);
46 - ERR(sh, "Could not parse module data.");
50 sepol_policy_file_free(pf);
51 - if (file_type != SEPOL_POLICY_MOD) {
52 - if (file_type == SEPOL_POLICY_BASE)
54 - "Received a base module, expected a non-base module.");
56 - ERR(sh, "Data did not represent a module.");
62 @@ -1608,22 +1595,24 @@ static int semanage_direct_install_file(semanage_handle_t * sh,
63 lang_ext = separator + 1;
66 - if (strcmp(lang_ext, "pp") != 0) {
67 + if (strcmp(lang_ext, "pp") == 0) {
68 + retval = parse_module_headers(sh, data, data_len, &module_name, &version);
74 + if (module_name == NULL) {
75 module_name = strdup(filename);
76 if (module_name == NULL) {
77 ERR(sh, "No memory available for module_name.\n");
82 - if ((retval = parse_module_headers(sh, data, data_len, &module_name, &version)) != 0)
85 - if (strcmp(module_name, filename) != 0)
86 - fprintf(stderr, "Warning: SELinux userspace will refer to the module from %s as %s rather than %s\n", install_filename, module_name, filename);
89 + } else if (strcmp(module_name, filename) != 0) {
90 + fprintf(stderr, "Warning: SELinux userspace will refer to the module from %s as %s rather than %s\n", install_filename, module_name, filename);
93 retval = semanage_direct_install(sh, data, data_len, module_name, lang_ext);