source: libabac/options.c @ f89b991

mei_rt2
Last change on this file since f89b991 was 2e9455f, checked in by Mei <mei@…>, 11 years ago

1) added namespace
2) tweak ?This,
3) allowing linking role/oset as constraining conditions
4) adding access_tests regression testing that uses GENI's access policy
5) added couple multi contexts regression tests
6) add compression/uncompression calls to abac_encode_string/abac_decode_string
(libstrongwan only allows 512 char for attribute rule storage)
7) add attribute_now option to creddy that takes a whole char string for attribute
rule

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