1 | /** |
---|
2 | ** options.h |
---|
3 | **/ |
---|
4 | |
---|
5 | #include <stdio.h> |
---|
6 | #include <getopt.h> |
---|
7 | #include <stdlib.h> |
---|
8 | #include <string.h> |
---|
9 | |
---|
10 | #include "options.h" |
---|
11 | |
---|
12 | /****************************************************************/ |
---|
13 | |
---|
14 | static void _usage(char *name) { |
---|
15 | printf( |
---|
16 | "Usage: %s \\\n" |
---|
17 | " --keystore <keystore> \\\n" |
---|
18 | " --role <keyid.role> --principal <keyid>\n" |
---|
19 | " --oset <keyid.oset> --object <otype>\n" |
---|
20 | " loads the keystore and runs the query role <-?- principal\\\n" |
---|
21 | " the query oset <-?- object\\\n" |
---|
22 | " --dump <file> \n" |
---|
23 | " extracts all credentials from the prolog db\n" |
---|
24 | " --dbdump \n" |
---|
25 | " extracts all prolog rules directly from the prolog db\n", |
---|
26 | " --all \n" |
---|
27 | " extracts multiple solution proofs (stops at 3rd one)\n", |
---|
28 | name |
---|
29 | ); |
---|
30 | exit(1); |
---|
31 | } |
---|
32 | |
---|
33 | void get_options(int argc, char **argv, options_t *opts) { |
---|
34 | |
---|
35 | #define OPT_KEYSTORE 1 |
---|
36 | #define OPT_ROLE 2 |
---|
37 | #define OPT_PRINCIPAL 3 |
---|
38 | #define OPT_DUMP 4 |
---|
39 | #define OPT_OSET 5 |
---|
40 | #define OPT_OBJECT 6 |
---|
41 | #define OPT_DBDUMP 7 |
---|
42 | #define OPT_ALL 8 |
---|
43 | |
---|
44 | struct option options[] = { |
---|
45 | { "keystore", 1, 0, OPT_KEYSTORE }, |
---|
46 | { "role", 1, 0, OPT_ROLE }, |
---|
47 | { "principal", 1, 0, OPT_PRINCIPAL }, |
---|
48 | { "dump", 1, 0, OPT_DUMP }, |
---|
49 | { "dbdump", 0, 0, OPT_DBDUMP }, |
---|
50 | { "all", 0, 0, OPT_ALL }, |
---|
51 | { "oset", 1, 0, OPT_OSET }, |
---|
52 | { "object", 1, 0, OPT_OBJECT }, |
---|
53 | { 0 }, |
---|
54 | }; |
---|
55 | |
---|
56 | opts->dbdump=0; |
---|
57 | opts->all=0; |
---|
58 | for ( ; ; ) { |
---|
59 | int c = getopt_long(argc, argv, "", options, NULL); |
---|
60 | if (c < 0) |
---|
61 | break; |
---|
62 | |
---|
63 | switch (c) { |
---|
64 | case OPT_KEYSTORE: |
---|
65 | opts->keystore = strdup(optarg); |
---|
66 | break; |
---|
67 | case OPT_ROLE: |
---|
68 | opts->role = strdup(optarg); |
---|
69 | break; |
---|
70 | case OPT_PRINCIPAL: |
---|
71 | opts->principal = strdup(optarg); |
---|
72 | break; |
---|
73 | case OPT_DUMP: |
---|
74 | opts->filename = strdup(optarg); |
---|
75 | break; |
---|
76 | case OPT_DBDUMP: |
---|
77 | opts->dbdump=1; |
---|
78 | break; |
---|
79 | case OPT_ALL: |
---|
80 | opts->all=1; |
---|
81 | break; |
---|
82 | case OPT_OSET: |
---|
83 | opts->oset = strdup(optarg); |
---|
84 | break; |
---|
85 | case OPT_OBJECT: |
---|
86 | opts->object = strdup(optarg); |
---|
87 | break; |
---|
88 | |
---|
89 | default: |
---|
90 | _usage(argv[0]); |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | if (!(opts->keystore && |
---|
95 | ((opts->role && opts->principal && !opts->oset) || |
---|
96 | (opts->oset && opts->principal && !opts->role) || |
---|
97 | (opts->oset && opts->object && !opts->role) )) && |
---|
98 | !(opts->filename) && !(opts->dbdump) && !(opts->all)) |
---|
99 | _usage(argv[0]); |
---|
100 | } |
---|