Skip to content

Commit

Permalink
[WIP] checkpolicy: validate generated policies
Browse files Browse the repository at this point in the history
After generating policies validate them.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
  • Loading branch information
cgzones committed Jul 1, 2023
1 parent d68d2e4 commit 648acf9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions checkpolicy/checkmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <sepol/policydb/expand.h>
#include <sepol/policydb/link.h>
#include <sepol/policydb/sidtab.h>
#include <sepol/policydb/validate.h>

#include "queue.h"
#include "checkpolicy.h"
Expand Down Expand Up @@ -334,6 +335,14 @@ int main(int argc, char **argv)

sepol_sidtab_destroy(&sidtab);

modpolicydb.policyvers = policyvers;

if (policydb_validate(NULL, &modpolicydb)) {
fprintf(stderr, "%s: validation of generated policy failed\n", argv[0]);
exit(1);
}
printf("%s: validation of generated policy succeeded\n", argv[0]);

if (outfile) {
FILE *outfp = fopen(outfile, "w");

Expand Down
7 changes: 7 additions & 0 deletions checkpolicy/checkpolicy.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
#include <sepol/policydb/hierarchy.h>
#include <sepol/policydb/expand.h>
#include <sepol/policydb/link.h>
#include <sepol/policydb/validate.h>

#include "queue.h"
#include "checkpolicy.h"
Expand Down Expand Up @@ -656,6 +657,12 @@ int main(int argc, char **argv)
}
}

if (policydb_validate(NULL, policydbp)) {
fprintf(stderr, "%s: validation of generated policy failed\n", argv[0]);
exit(1);
}
printf("%s: validation of generated policy succeeded\n", argv[0]);

if (outfile) {
if (!strcmp(outfile, "-")) {
outfp = stdout;
Expand Down

0 comments on commit 648acf9

Please sign in to comment.