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