This commit is contained in:
Tristan Ross 2025-04-25 18:05:18 +00:00 committed by GitHub
commit 8b22fe35d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 45 additions and 13 deletions

View File

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

View File

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

View File

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

View File

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