diff --git a/libsemanage/include/semanage/handle.h b/libsemanage/include/semanage/handle.h index a5ea31deb..601cd9ee9 100644 --- a/libsemanage/include/semanage/handle.h +++ b/libsemanage/include/semanage/handle.h @@ -30,7 +30,11 @@ struct semanage_handle; typedef struct semanage_handle semanage_handle_t; -/* Create and return a semanage handle. +/* Create and return a semanage handle with a specific config path. + The handle is initially in the disconnected state. */ +semanage_handle_t *semanage_handle_create_with_path(const char *conf_name); + +/* Create and return a semanage handle with the default config path. The handle is initially in the disconnected state. */ extern semanage_handle_t *semanage_handle_create(void); diff --git a/libsemanage/src/handle.c b/libsemanage/src/handle.c index faea0606a..ca57702aa 100644 --- a/libsemanage/src/handle.c +++ b/libsemanage/src/handle.c @@ -59,19 +59,14 @@ const char * semanage_root(void) return private_semanage_root; } - -semanage_handle_t *semanage_handle_create(void) +semanage_handle_t *semanage_handle_create_with_path(const char *conf_name) { semanage_handle_t *sh = NULL; - char *conf_name = NULL; /* Allocate handle */ if ((sh = calloc(1, sizeof(semanage_handle_t))) == NULL) goto err; - if ((conf_name = semanage_conf_path()) == NULL) - goto err; - if ((sh->conf = semanage_conf_parse(conf_name)) == NULL) goto err; @@ -106,13 +101,30 @@ semanage_handle_t *semanage_handle_create(void) sh->msg_callback = semanage_msg_default_handler; sh->msg_callback_arg = NULL; + return sh; + + err: + semanage_handle_destroy(sh); + return NULL; +} + +semanage_handle_t *semanage_handle_create(void) +{ + semanage_handle_t *sh = NULL; + char *conf_name = NULL; + + if ((conf_name = semanage_conf_path()) == NULL) + goto err; + + if ((sh = semanage_handle_create_with_path(conf_name)) == NULL) + goto err; + free(conf_name); return sh; err: free(conf_name); - semanage_handle_destroy(sh); return NULL; } diff --git a/libsemanage/src/libsemanage.map b/libsemanage/src/libsemanage.map index c8214b26f..8d7d8b053 100644 --- a/libsemanage/src/libsemanage.map +++ b/libsemanage/src/libsemanage.map @@ -350,3 +350,7 @@ LIBSEMANAGE_3.4 { semanage_module_compute_checksum; semanage_set_check_ext_changes; } LIBSEMANAGE_1.1; + +LIBSEMANAGE_3.9 { + semanage_handle_create_with_path; +} LIBSEMANAGE_3.4; diff --git a/policycoreutils/semodule/semodule.c b/policycoreutils/semodule/semodule.c index ebe062bf4..ab5168ebd 100644 --- a/policycoreutils/semodule/semodule.c +++ b/policycoreutils/semodule/semodule.c @@ -145,6 +145,7 @@ static void usage(char *progname) printf(" -v,--verbose be verbose\n"); printf(" -P,--preserve_tunables Preserve tunables in policy\n"); printf(" -C,--ignore-module-cache Rebuild CIL modules compiled from HLL files\n"); + printf(" -g,--config=PATH use an alternate path for the semanage config\n"); printf(" -p,--path use an alternate path for the policy root\n"); printf(" -S,--store-path use an alternate path for the policy store root\n"); printf(" -c, --cil extract module as cil. This only affects module extraction.\n"); @@ -210,6 +211,7 @@ static void parse_command_line(int argc, char **argv) {"enable", required_argument, NULL, 'e'}, {"disable", required_argument, NULL, 'd'}, {"path", required_argument, NULL, 'p'}, + {"config", required_argument, NULL, 'g'}, {"store-path", required_argument, NULL, 'S'}, {"checksum", 0, NULL, 'm'}, {NULL, 0, NULL, 0} @@ -223,7 +225,7 @@ static void parse_command_line(int argc, char **argv) check_ext_changes = 0; priority = 400; while ((i = - getopt_long(argc, argv, "s:b:hi:l::vr:u:RnNBDCPX:e:d:p:S:E:cHm", + getopt_long(argc, argv, "s:b:hi:l::vr:u:RnNBDCPX:e:d:p:g:S:E:cHm", opts, &longind)) != -1) { switch (i) { case '\0': @@ -304,6 +306,14 @@ static void parse_command_line(int argc, char **argv) case 'C': ignore_module_cache = 1; break; + case 'g': + sh = semanage_handle_create_with_path(optarg); + if (!sh) { + fprintf(stderr, "%s: Could not create semanage handle\n", + argv[0]); + exit(1); + } + break; case 'X': set_mode(PRIORITY_M, optarg); break; @@ -421,11 +431,13 @@ int main(int argc, char *argv[]) if (build || check_ext_changes) commit = 1; - sh = semanage_handle_create(); if (!sh) { - fprintf(stderr, "%s: Could not create semanage handle\n", - argv[0]); - goto cleanup_nohandle; + sh = semanage_handle_create(); + if (!sh) { + fprintf(stderr, "%s: Could not create semanage handle\n", + argv[0]); + goto cleanup_nohandle; + } } if (store) {