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