[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" |
---|
| 18 | " extracts all credentials from the prolog db\n", |
---|
[06d7b3a] | 19 | name |
---|
| 20 | ); |
---|
| 21 | exit(1); |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | void get_options(int argc, char **argv, options_t *opts) { |
---|
| 25 | #define OPT_KEYSTORE 1 |
---|
| 26 | #define OPT_ROLE 2 |
---|
| 27 | #define OPT_PRINCIPAL 3 |
---|
[da5afdf] | 28 | #define OPT_DUMP 4 |
---|
| 29 | #define OPT_OSET 5 |
---|
| 30 | #define OPT_OBJECT 6 |
---|
[06d7b3a] | 31 | struct option options[] = { |
---|
| 32 | { "keystore", 1, 0, OPT_KEYSTORE }, |
---|
| 33 | { "role", 1, 0, OPT_ROLE }, |
---|
| 34 | { "principal", 1, 0, OPT_PRINCIPAL }, |
---|
[da5afdf] | 35 | { "dump", 1, 0, OPT_DUMP }, |
---|
| 36 | { "oset", 1, 0, OPT_OSET }, |
---|
| 37 | { "object", 1, 0, OPT_OBJECT }, |
---|
[06d7b3a] | 38 | { 0 }, |
---|
| 39 | }; |
---|
| 40 | |
---|
| 41 | for ( ; ; ) { |
---|
| 42 | int c = getopt_long(argc, argv, "", options, NULL); |
---|
| 43 | if (c < 0) |
---|
| 44 | break; |
---|
| 45 | |
---|
| 46 | switch (c) { |
---|
| 47 | case OPT_KEYSTORE: |
---|
| 48 | opts->keystore = strdup(optarg); |
---|
| 49 | break; |
---|
| 50 | case OPT_ROLE: |
---|
| 51 | opts->role = strdup(optarg); |
---|
| 52 | break; |
---|
| 53 | case OPT_PRINCIPAL: |
---|
| 54 | opts->principal = strdup(optarg); |
---|
| 55 | break; |
---|
[da5afdf] | 56 | case OPT_DUMP: |
---|
| 57 | opts->filename = strdup(optarg); |
---|
| 58 | break; |
---|
| 59 | case OPT_OSET: |
---|
| 60 | opts->oset = strdup(optarg); |
---|
| 61 | break; |
---|
| 62 | case OPT_OBJECT: |
---|
| 63 | opts->object = strdup(optarg); |
---|
| 64 | break; |
---|
[06d7b3a] | 65 | |
---|
| 66 | default: |
---|
| 67 | _usage(argv[0]); |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | |
---|
[da5afdf] | 71 | if (!(opts->keystore && |
---|
| 72 | ((opts->role && opts->principal && !opts->oset) || |
---|
| 73 | (opts->oset && opts->principal && !opts->role) || |
---|
| 74 | (opts->oset && opts->object && !opts->role) )) && |
---|
| 75 | !(opts->filename)) |
---|
[06d7b3a] | 76 | _usage(argv[0]); |
---|
| 77 | } |
---|