/** ** options.h **/ #include #include #include #include #include "options.h" /****************************************************************/ static void _usage(char *name) { printf( "Usage: %s \\\n" " --keystore \\\n" " --role --principal \n" " --oset --object \n" " loads the keystore and runs the query role <-?- principal\\\n" " the query oset <-?- object\\\n" " --dump \n" " extracts all credentials from the prolog db\n" " --dbdump \n" " extracts all prolog rules directly from the prolog db\n", " --all \n" " extracts multiple solution proofs (stops at 3rd one)\n", name ); exit(1); } void get_options(int argc, char **argv, options_t *opts) { #define OPT_KEYSTORE 1 #define OPT_ROLE 2 #define OPT_PRINCIPAL 3 #define OPT_DUMP 4 #define OPT_OSET 5 #define OPT_OBJECT 6 #define OPT_DBDUMP 7 #define OPT_ALL 8 struct option options[] = { { "keystore", 1, 0, OPT_KEYSTORE }, { "role", 1, 0, OPT_ROLE }, { "principal", 1, 0, OPT_PRINCIPAL }, { "dump", 1, 0, OPT_DUMP }, { "dbdump", 0, 0, OPT_DBDUMP }, { "all", 0, 0, OPT_ALL }, { "oset", 1, 0, OPT_OSET }, { "object", 1, 0, OPT_OBJECT }, { 0 }, }; opts->dbdump=0; opts->all=0; for ( ; ; ) { int c = getopt_long(argc, argv, "", options, NULL); if (c < 0) break; switch (c) { case OPT_KEYSTORE: opts->keystore = strdup(optarg); break; case OPT_ROLE: opts->role = strdup(optarg); break; case OPT_PRINCIPAL: opts->principal = strdup(optarg); break; case OPT_DUMP: opts->filename = strdup(optarg); break; case OPT_DBDUMP: opts->dbdump=1; break; case OPT_ALL: opts->all=1; break; case OPT_OSET: opts->oset = strdup(optarg); break; case OPT_OBJECT: opts->object = strdup(optarg); break; default: _usage(argv[0]); } } if (!(opts->keystore && ((opts->role && opts->principal && !opts->oset) || (opts->oset && opts->principal && !opts->role) || (opts->oset && opts->object && !opts->role) )) && !(opts->filename) && !(opts->dbdump) && !(opts->all)) _usage(argv[0]); }