abac0-leakabac0-meicompt_changesgec13mei-idmei-rt0-nmei_rt0mei_rt2mei_rt2_fix_1meiyap-rt1meiyap1rt2tvf-new-xml
Last change
on this file since 0aaa651 was
0aaa651,
checked in by Mike Ryan <mikeryan@…>, 13 years ago
|
change show_issuer into a generic option for displaying metadata
see #17
|
-
Property mode set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 | #include <creddy.h> |
---|
2 | |
---|
3 | #include "creddy_common.h" |
---|
4 | |
---|
5 | void display_main(options_t *opts) { |
---|
6 | if (opts->cert == NULL) |
---|
7 | usage(opts); |
---|
8 | |
---|
9 | char *show = opts->show; |
---|
10 | if (show == NULL) |
---|
11 | usage(opts); |
---|
12 | |
---|
13 | int show_issuer = 0; |
---|
14 | char *opt; |
---|
15 | |
---|
16 | while ((opt = strsep(&show, ",")) != NULL) { |
---|
17 | if (strcmp(opt, "issuer") == 0) |
---|
18 | show_issuer = 1; |
---|
19 | else if (strcmp(opt, "all") == 0) { |
---|
20 | show_issuer = 1; |
---|
21 | } |
---|
22 | else { |
---|
23 | printf("Error: Unknown option to --show: %s\n", opt); |
---|
24 | usage(opts); |
---|
25 | } |
---|
26 | } |
---|
27 | |
---|
28 | // first try ID cert |
---|
29 | creddy_id_t *id = creddy_id_from_file(opts->cert); |
---|
30 | if (id != NULL) { |
---|
31 | if (show_issuer) { |
---|
32 | char *issuer = creddy_id_issuer(id); |
---|
33 | puts(creddy_id_issuer(id)); |
---|
34 | } |
---|
35 | |
---|
36 | creddy_id_free(id); |
---|
37 | return; |
---|
38 | } |
---|
39 | |
---|
40 | // then try attribute cert |
---|
41 | certificate_t *ac = lib->creds->create(lib->creds, |
---|
42 | CRED_CERTIFICATE, CERT_X509_AC, |
---|
43 | BUILD_FROM_FILE, opts->cert, |
---|
44 | BUILD_END |
---|
45 | ); |
---|
46 | if (ac != NULL) { |
---|
47 | if (show_issuer) |
---|
48 | printf("%Y\n", ac->get_issuer(ac)); |
---|
49 | |
---|
50 | DESTROY_IF(ac); |
---|
51 | return; |
---|
52 | } |
---|
53 | |
---|
54 | // give up if neither works |
---|
55 | errx(1, "Couldn't load %s as an ID or attribute cert", opts->cert); |
---|
56 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.