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