source: libabac/options.c @ 2cdbe49

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

1) add static contraint

(limited to integer at this time)

  • Property mode set to 100644
File size: 2.2 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        name
20    );
21    exit(1);
22}
23
24void get_options(int argc, char **argv, options_t *opts) {
25#define OPT_KEYSTORE    1
26#define OPT_ROLE        2
27#define OPT_PRINCIPAL   3
28#define OPT_DUMP        4
29#define OPT_OSET        5
30#define OPT_OBJECT      6
31    struct option options[] = {
32        { "keystore",   1, 0, OPT_KEYSTORE  },
33        { "role",       1, 0, OPT_ROLE      },
34        { "principal",  1, 0, OPT_PRINCIPAL },
35        { "dump",       1, 0, OPT_DUMP },
36        { "oset",       1, 0, OPT_OSET },
37        { "object",     1, 0, OPT_OBJECT },
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;
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;
65
66            default:
67                _usage(argv[0]);
68        }
69    }
70
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))
76        _usage(argv[0]);
77}
Note: See TracBrowser for help on using the repository browser.