selinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] dismod: print the policy version only in interactive mode
@ 2023-06-14 19:16 Masatake YAMATO
  2023-06-14 19:16 ` [PATCH v2 2/2] dismod, dispol: reduce the messages in batch mode Masatake YAMATO
  2023-06-14 19:54 ` [PATCH v2 1/2] dismod: print the policy version only in interactive mode James Carter
  0 siblings, 2 replies; 4+ messages in thread
From: Masatake YAMATO @ 2023-06-14 19:16 UTC (permalink / raw)
  To: selinux; +Cc: yamato

Instead, a new action, 'v' for printing the policy (and/or
module) version in batch mode is added.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
 checkpolicy/test/dismod.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/checkpolicy/test/dismod.c b/checkpolicy/test/dismod.c
index 515fc9a5..fa729ef2 100644
--- a/checkpolicy/test/dismod.c
+++ b/checkpolicy/test/dismod.c
@@ -91,6 +91,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"},
@@ -899,6 +900,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;
@@ -952,17 +966,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("");
@@ -1069,6 +1076,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);
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] dismod, dispol: reduce the messages in batch mode
  2023-06-14 19:16 [PATCH v2 1/2] dismod: print the policy version only in interactive mode Masatake YAMATO
@ 2023-06-14 19:16 ` Masatake YAMATO
  2023-06-14 19:54 ` [PATCH v2 1/2] dismod: print the policy version only in interactive mode James Carter
  1 sibling, 0 replies; 4+ messages in thread
From: Masatake YAMATO @ 2023-06-14 19:16 UTC (permalink / raw)
  To: selinux; +Cc: yamato

A change in v2:
* pass `verbose' to sepol_module_package_read().

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
 checkpolicy/test/dismod.c | 22 ++++++++++++----------
 checkpolicy/test/dispol.c |  8 +++++---
 2 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/checkpolicy/test/dismod.c b/checkpolicy/test/dismod.c
index fa729ef2..3f095da7 100644
--- a/checkpolicy/test/dismod.c
+++ b/checkpolicy/test/dismod.c
@@ -773,7 +773,7 @@ static int display_handle_unknown(policydb_t * p, FILE * out_fp)
 	return 0;
 }
 
-static int read_policy(char *filename, policydb_t * policy)
+static int read_policy(char *filename, policydb_t * policy, int verbose)
 {
 	FILE *in_fp;
 	struct policy_file f;
@@ -808,7 +808,7 @@ static int read_policy(char *filename, policydb_t * policy)
 		package->file_contexts = NULL;
 		retval =
 		    sepol_module_package_read(package,
-					      (sepol_policy_file_t *) & f, 1);
+					      (sepol_policy_file_t *) & f, verbose);
 		package->policy = NULL;
 		sepol_module_package_free(package);
 	} else {
@@ -816,13 +816,13 @@ static int read_policy(char *filename, policydb_t * policy)
 			fprintf(stderr, "%s:  Out of memory!\n", __FUNCTION__);
 			exit(1);
 		}
-		retval = policydb_read(policy, &f, 1);
+		retval = policydb_read(policy, &f, verbose);
 	}
 	fclose(in_fp);
 	return retval;
 }
 
-static void link_module(policydb_t * base, FILE * out_fp)
+static void link_module(policydb_t * base, FILE * out_fp, int verbose)
 {
 	char module_name[80] = { 0 };
 	int ret;
@@ -845,8 +845,9 @@ static void link_module(policydb_t * base, FILE * out_fp)
 	}
 
 	/* read the binary policy */
-	fprintf(out_fp, "Reading module...\n");
-	if (read_policy(module_name, mods)) {
+	if (verbose)
+		fprintf(out_fp, "Reading module...\n");
+	if (read_policy(module_name, mods, verbose)) {
 		fprintf(stderr,
 			"%s:  error(s) encountered while loading policy\n",
 			module_name);
@@ -937,12 +938,13 @@ int main(int argc, char **argv)
 	}
 
 	/* read the binary policy */
-	fprintf(out_fp, "Reading policy...\n");
+	if (!ops)
+		fprintf(out_fp, "Reading policy...\n");
 	if (policydb_init(&policydb)) {
 		fprintf(stderr, "%s:  Out of memory!\n", __FUNCTION__);
 		exit(1);
 	}
-	if (read_policy(mod, &policydb)) {
+	if (read_policy(mod, &policydb, ops? 0: 1)) {
 		fprintf(stderr,
 			"%s:  error(s) encountered while loading policy\n",
 			argv[0]);
@@ -961,7 +963,7 @@ int main(int argc, char **argv)
 		exit(1);
 	}
 
-	if (policydb_index_others(NULL, &policydb, 1)) {
+	if (policydb_index_others(NULL, &policydb, ops? 0: 1)) {
 		fprintf(stderr, "Error indexing others\n");
 		exit(1);
 	}
@@ -1074,7 +1076,7 @@ int main(int argc, char **argv)
 					&policydb, out_fp);
 			break;
 		case 'l':
-			link_module(&policydb, out_fp);
+			link_module(&policydb, out_fp, ops? 0: 1);
 			break;
 		case 'v':
 			print_version_info(&policydb, out_fp);
diff --git a/checkpolicy/test/dispol.c b/checkpolicy/test/dispol.c
index bee1a660..b567ce77 100644
--- a/checkpolicy/test/dispol.c
+++ b/checkpolicy/test/dispol.c
@@ -551,7 +551,8 @@ int main(int argc, char **argv)
 	}
 
 	/* read the binary policy */
-	fprintf(out_fp, "Reading policy...\n");
+	if (!ops)
+		fprintf(out_fp, "Reading policy...\n");
 	policy_file_init(&pf);
 	pf.type = PF_USE_MEMORY;
 	pf.data = map;
@@ -560,7 +561,7 @@ int main(int argc, char **argv)
 		fprintf(stderr, "%s:  Out of memory!\n", argv[0]);
 		exit(1);
 	}
-	ret = policydb_read(&policydb, &pf, 1);
+	ret = policydb_read(&policydb, &pf, ops? 0: 1);
 	if (ret) {
 		fprintf(stderr,
 			"%s:  error(s) encountered while parsing configuration\n",
@@ -568,7 +569,8 @@ int main(int argc, char **argv)
 		exit(1);
 	}
 
-	fprintf(stdout, "binary policy file loaded\n\n");
+	if (!ops)
+		fprintf(stdout, "binary policy file loaded\n\n");
 	close(fd);
 
 	if (!ops)
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/2] dismod: print the policy version only in interactive mode
  2023-06-14 19:16 [PATCH v2 1/2] dismod: print the policy version only in interactive mode Masatake YAMATO
  2023-06-14 19:16 ` [PATCH v2 2/2] dismod, dispol: reduce the messages in batch mode Masatake YAMATO
@ 2023-06-14 19:54 ` James Carter
  2023-06-30 12:25   ` Petr Lautrbach
  1 sibling, 1 reply; 4+ messages in thread
From: James Carter @ 2023-06-14 19:54 UTC (permalink / raw)
  To: Masatake YAMATO; +Cc: selinux

On Wed, Jun 14, 2023 at 3:23 PM Masatake YAMATO <yamato@redhat.com> wrote:
>
> Instead, a new action, 'v' for printing the policy (and/or
> module) version in batch mode is added.
>
> Signed-off-by: Masatake YAMATO <yamato@redhat.com>

For both patches:
Acked-by: James Carter <jwcart2@gmail.com>

> ---
>  checkpolicy/test/dismod.c | 30 ++++++++++++++++++++----------
>  1 file changed, 20 insertions(+), 10 deletions(-)
>
> diff --git a/checkpolicy/test/dismod.c b/checkpolicy/test/dismod.c
> index 515fc9a5..fa729ef2 100644
> --- a/checkpolicy/test/dismod.c
> +++ b/checkpolicy/test/dismod.c
> @@ -91,6 +91,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"},
> @@ -899,6 +900,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;
> @@ -952,17 +966,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("");
> @@ -1069,6 +1076,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);
> --
> 2.40.1
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/2] dismod: print the policy version only in interactive mode
  2023-06-14 19:54 ` [PATCH v2 1/2] dismod: print the policy version only in interactive mode James Carter
@ 2023-06-30 12:25   ` Petr Lautrbach
  0 siblings, 0 replies; 4+ messages in thread
From: Petr Lautrbach @ 2023-06-30 12:25 UTC (permalink / raw)
  To: James Carter, Masatake YAMATO; +Cc: selinux

James Carter <jwcart2@gmail.com> writes:

> On Wed, Jun 14, 2023 at 3:23 PM Masatake YAMATO <yamato@redhat.com> wrote:
>>
>> Instead, a new action, 'v' for printing the policy (and/or
>> module) version in batch mode is added.
>>
>> Signed-off-by: Masatake YAMATO <yamato@redhat.com>
>
> For both patches:
> Acked-by: James Carter <jwcart2@gmail.com>

both merged, thanks!


>> ---
>>  checkpolicy/test/dismod.c | 30 ++++++++++++++++++++----------
>>  1 file changed, 20 insertions(+), 10 deletions(-)
>>
>> diff --git a/checkpolicy/test/dismod.c b/checkpolicy/test/dismod.c
>> index 515fc9a5..fa729ef2 100644
>> --- a/checkpolicy/test/dismod.c
>> +++ b/checkpolicy/test/dismod.c
>> @@ -91,6 +91,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"},
>> @@ -899,6 +900,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;
>> @@ -952,17 +966,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("");
>> @@ -1069,6 +1076,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);
>> --
>> 2.40.1
>>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-06-30 12:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-14 19:16 [PATCH v2 1/2] dismod: print the policy version only in interactive mode Masatake YAMATO
2023-06-14 19:16 ` [PATCH v2 2/2] dismod, dispol: reduce the messages in batch mode Masatake YAMATO
2023-06-14 19:54 ` [PATCH v2 1/2] dismod: print the policy version only in interactive mode James Carter
2023-06-30 12:25   ` Petr Lautrbach

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).