source: libabac/options.c @ 7764378

abac0-leak
Last change on this file since 7764378 was 7764378, checked in by Mei <mei@…>, 11 years ago

1) tweak according valgrind's leak report

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[461541a]1
2/* options.c */
3
4#include <stdio.h>
[06d7b3a]5#include <getopt.h>
6#include <stdlib.h>
7#include <string.h>
8
9#include "options.h"
10
11static void _usage(char *name) {
12    printf(
13        "Usage: %s \\\n"
14        "        --keystore <keystore> \\\n"
15        "        --role <keyid.role> --principal <keyid>\n"
[461541a]16        "        --dump <file>\n"
[06d7b3a]17        "    loads the keystore and runs the query role <-?- principal\n",
18        name
19    );
20    exit(1);
21}
22
[7764378]23void free_options(options_t *opts)
24{           
25    if(opts->keystore) free(opts->keystore); 
26    if(opts->role) free(opts->role);
27    if(opts->principal) free(opts->principal);
28    if(opts->rulefile) free(opts->rulefile);
29}
30
[06d7b3a]31void get_options(int argc, char **argv, options_t *opts) {
32#define OPT_KEYSTORE    1
33#define OPT_ROLE        2
34#define OPT_PRINCIPAL   3
[461541a]35#define OPT_DUMP        4
[06d7b3a]36    struct option options[] = {
37        { "keystore",   1, 0, OPT_KEYSTORE  },
38        { "role",       1, 0, OPT_ROLE      },
39        { "principal",  1, 0, OPT_PRINCIPAL },
[461541a]40        { "dump",       1, 0, OPT_DUMP },
[06d7b3a]41        { 0 },
42    };
43
44    for ( ; ; ) {
45        int c = getopt_long(argc, argv, "", options, NULL);
46        if (c < 0)
47            break;
48
49        switch (c) {
50            case OPT_KEYSTORE:
51                opts->keystore = strdup(optarg);
52                break;
53            case OPT_ROLE:
54                opts->role = strdup(optarg);
55                break;
56            case OPT_PRINCIPAL:
57                opts->principal = strdup(optarg);
58                break;
[461541a]59            case OPT_DUMP:
60                opts->rulefile = strdup(optarg);
61                break;
62
[06d7b3a]63
64            default:
65                _usage(argv[0]);
66        }
67    }
68
[461541a]69    if (!(opts->keystore && opts->role && opts->principal) && !(opts->rulefile) )
[06d7b3a]70        _usage(argv[0]);
71}
Note: See TracBrowser for help on using the repository browser.