Skip to content

Commit

Permalink
dismod: print the policy version only in interactive mode
Browse files Browse the repository at this point in the history
Instead, a new action, 'v' for printing the policy (and/or
module) version in batch mode is added.

Signed-off-by: Masatake YAMATO <[email protected]>
Acked-by: James Carter <[email protected]>
  • Loading branch information
masatake authored and bachradsusi committed Jun 30, 2023
1 parent 4c06922 commit 6e077ba
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions checkpolicy/test/dismod.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ static struct command {
{CMD|NOOPT, 'l', "Link in a module"},
{CMD, 'u', "Display the unknown handling setting"},
{CMD, 'F', "Display filename_trans rules"},
{CMD, 'v', "display the version of policy and/or module"},
{HEADER, 0, ""},
{CMD|NOOPT, 'f', "set output file"},
{CMD|NOOPT, 'm', "display menu"},
Expand Down Expand Up @@ -904,6 +905,19 @@ static int menu(void)
return 0;
}

static void print_version_info(policydb_t * p, FILE * fp)
{
if (p->policy_type == POLICY_BASE) {
fprintf(fp, "Binary base policy file loaded.\n");
} else {
fprintf(fp, "Binary policy module file loaded.\n");
fprintf(fp, "Module name: %s\n", p->name);
fprintf(fp, "Module version: %s\n", p->version);
}

fprintf(fp, "Policy version: %d\n\n", p->policyvers);
}

int main(int argc, char **argv)
{
char *ops = NULL;
Expand Down Expand Up @@ -957,17 +971,10 @@ int main(int argc, char **argv)
exit(1);
}

if (policydb.policy_type == POLICY_BASE) {
printf("Binary base policy file loaded.\n");
} else {
printf("Binary policy module file loaded.\n");
printf("Module name: %s\n", policydb.name);
printf("Module version: %s\n", policydb.version);
}

printf("Policy version: %d\n\n", policydb.policyvers);
if (!ops)
if (!ops) {
print_version_info(&policydb, stdout);
menu();
}
for (;;) {
if (ops) {
puts("");
Expand Down Expand Up @@ -1074,6 +1081,9 @@ int main(int argc, char **argv)
case 'l':
link_module(&policydb, out_fp);
break;
case 'v':
print_version_info(&policydb, out_fp);
break;
case 'q':
policydb_destroy(&policydb);
exit(0);
Expand Down

0 comments on commit 6e077ba

Please sign in to comment.