source: libabac/options.c @ c46b2fe

mei_rt2mei_rt2_fix_1
Last change on this file since c46b2fe was 2efdff5, checked in by Mei <mei@…>, 12 years ago

1) fix the missing check for 'This' rt2.y when called from creddy/prover

combo

2) patch up the stringify of abac_term that is of time type.
3) update the testing to reflect the changes to baseline output

  • Property mode set to 100644
File size: 2.5 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        name
22    );
23    exit(1);
24}
25
26void get_options(int argc, char **argv, options_t *opts) {
27#define OPT_KEYSTORE    1
28#define OPT_ROLE        2
29#define OPT_PRINCIPAL   3
30#define OPT_DUMP        4
31#define OPT_OSET        5
32#define OPT_OBJECT      6
33#define OPT_DBDUMP      7
34    struct option options[] = {
35        { "keystore",   1, 0, OPT_KEYSTORE  },
36        { "role",       1, 0, OPT_ROLE      },
37        { "principal",  1, 0, OPT_PRINCIPAL },
38        { "dump",       1, 0, OPT_DUMP },
39        { "dbdump",     0, 0, OPT_DBDUMP },
40        { "oset",       1, 0, OPT_OSET },
41        { "object",     1, 0, OPT_OBJECT },
42        { 0 },
43    };
44
45    opts->dbdump=0;
46    for ( ; ; ) {
47        int c = getopt_long(argc, argv, "", options, NULL);
48        if (c < 0)
49            break;
50
51        switch (c) {
52            case OPT_KEYSTORE:
53                opts->keystore = strdup(optarg);
54                break;
55            case OPT_ROLE:
56                opts->role = strdup(optarg);
57                break;
58            case OPT_PRINCIPAL:
59                opts->principal = strdup(optarg);
60                break;
61            case OPT_DUMP:
62                opts->filename = strdup(optarg);
63                break;
64            case OPT_DBDUMP:
65                opts->dbdump=1;
66                break;
67            case OPT_OSET:
68                opts->oset = strdup(optarg);
69                break;
70            case OPT_OBJECT:
71                opts->object = strdup(optarg);
72                break;
73
74            default:
75                _usage(argv[0]);
76        }
77    }
78
79    if (!(opts->keystore && 
80                 ((opts->role && opts->principal && !opts->oset) ||
81                 (opts->oset && opts->principal && !opts->role) ||
82                 (opts->oset && opts->object && !opts->role) )) &&
83                         !(opts->filename) && !(opts->dbdump))
84        _usage(argv[0]);
85}
Note: See TracBrowser for help on using the repository browser.