sepolicy-analyze.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include <stddef.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include "dups.h"
  5. #include "neverallow.h"
  6. #include "perm.h"
  7. #include "typecmp.h"
  8. #include "booleans.h"
  9. #include "attribute.h"
  10. #include "utils.h"
  11. #define NUM_COMPONENTS (int) (sizeof(analyze_components)/sizeof(analyze_components[0]))
  12. #define COMP(x) { #x, sizeof(#x) - 1, x ##_usage, x ##_func }
  13. static struct {
  14. const char *key;
  15. size_t keylen;
  16. void (*usage) (void);
  17. int (*func) (int argc, char **argv, policydb_t *policydb);
  18. } analyze_components[] = {
  19. COMP(dups),
  20. COMP(neverallow),
  21. COMP(permissive),
  22. COMP(typecmp),
  23. COMP(booleans),
  24. COMP(attribute)
  25. };
  26. void usage(char *arg0)
  27. {
  28. int i;
  29. fprintf(stderr, "%s must be called on a policy file with a component and the appropriate arguments specified\n", arg0);
  30. fprintf(stderr, "%s <policy-file>:\n", arg0);
  31. for(i = 0; i < NUM_COMPONENTS; i++) {
  32. analyze_components[i].usage();
  33. }
  34. exit(1);
  35. }
  36. int main(int argc, char **argv)
  37. {
  38. char *policy;
  39. struct policy_file pf;
  40. policydb_t policydb;
  41. int rc;
  42. int i;
  43. if (argc < 3)
  44. usage(argv[0]);
  45. policy = argv[1];
  46. if(load_policy(policy, &policydb, &pf))
  47. exit(1);
  48. for(i = 0; i < NUM_COMPONENTS; i++) {
  49. if (!strcmp(analyze_components[i].key, argv[2])) {
  50. rc = analyze_components[i].func(argc - 2, argv + 2, &policydb);
  51. if (rc && USAGE_ERROR) {
  52. usage(argv[0]); }
  53. policydb_destroy(&policydb);
  54. return rc;
  55. }
  56. }
  57. usage(argv[0]);
  58. exit(0);
  59. }