source: libabac/options.c @ e97d2e2

mei_rt2_fix_1
Last change on this file since e97d2e2 was abf8d5d, checked in by Mei <mei@…>, 12 years ago

1) add backtrack/multiple solutions proof code changes and new

examples.

  • Property mode set to 100644
File size: 2.8 KB
Line 
1
2#include <stdio.h>
3#include <getopt.h>
4#include <stdlib.h>
5#include <string.h>
6
7#include "options.h"
8
9static void _usage(char *name) {
10    printf(
11        "Usage: %s \\\n"
12        "        --keystore <keystore> \\\n"
13        "        --role <keyid.role> --principal <keyid>\n"
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"
19        "        --dbdump \n"
20        "    extracts all prolog rules directly from the prolog db\n",
21        "        --all \n"
22        "    extracts multiple solution proofs (stops at 3rd one)\n",
23        name
24    );
25    exit(1);
26}
27
28void get_options(int argc, char **argv, options_t *opts) {
29
30#define OPT_KEYSTORE    1
31#define OPT_ROLE        2
32#define OPT_PRINCIPAL   3
33#define OPT_DUMP        4
34#define OPT_OSET        5
35#define OPT_OBJECT      6
36#define OPT_DBDUMP      7
37#define OPT_ALL         8
38
39    struct option options[] = {
40        { "keystore",   1, 0, OPT_KEYSTORE  },
41        { "role",       1, 0, OPT_ROLE      },
42        { "principal",  1, 0, OPT_PRINCIPAL },
43        { "dump",       1, 0, OPT_DUMP },
44        { "dbdump",     0, 0, OPT_DBDUMP },
45        { "all",        0, 0, OPT_ALL },
46        { "oset",       1, 0, OPT_OSET },
47        { "object",     1, 0, OPT_OBJECT },
48        { 0 },
49    };
50
51    opts->dbdump=0;
52    opts->all=0;
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;
68            case OPT_DUMP:
69                opts->filename = strdup(optarg);
70                break;
71            case OPT_DBDUMP:
72                opts->dbdump=1;
73                break;
74            case OPT_ALL:
75                opts->all=1;
76                break;
77            case OPT_OSET:
78                opts->oset = strdup(optarg);
79                break;
80            case OPT_OBJECT:
81                opts->object = strdup(optarg);
82                break;
83
84            default:
85                _usage(argv[0]);
86        }
87    }
88
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) )) &&
93                         !(opts->filename) && !(opts->dbdump) && !(opts->all))
94        _usage(argv[0]);
95}
Note: See TracBrowser for help on using the repository browser.