Skip to content

semodule: add config argument #470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion libsemanage/include/semanage/handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
26 changes: 19 additions & 7 deletions libsemanage/src/handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 4 additions & 0 deletions libsemanage/src/libsemanage.map
Original file line number Diff line number Diff line change
Expand Up @@ -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;
22 changes: 17 additions & 5 deletions policycoreutils/semodule/semodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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}
Expand All @@ -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':
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Loading