2 * Copyright (C) 2015 Andreas Steffen
4 * Copyright (C) secunet Security Networks AG
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 #define LABELED_CRL_URI (1 << 0)
24 #define LABELED_OCSP_URI (1 << 1)
26 CALLBACK(authority_kv
, int,
27 void *null
, vici_res_t
*res
, char *name
, void *value
, int len
)
31 chunk
= chunk_create(value
, len
);
32 if (chunk_printable(chunk
, NULL
, ' '))
34 printf(" %s: %.*s\n", name
, len
, value
);
41 CALLBACK(authority_list
, int,
42 int *labeled
, vici_res_t
*res
, char *name
, void *value
, int len
)
46 chunk
= chunk_create(value
, len
);
47 if (chunk_printable(chunk
, NULL
, ' '))
49 if (streq(name
, "crl_uris"))
52 (*labeled
& LABELED_CRL_URI
) ? " " : "crl_uris: ",
54 *labeled
|= LABELED_CRL_URI
;
56 if (streq(name
, "ocsp_uris"))
59 (*labeled
& LABELED_OCSP_URI
) ? " " : "ocsp_uris:",
61 *labeled
%= LABELED_OCSP_URI
;
67 CALLBACK(authorities
, int,
68 void *null
, vici_res_t
*res
, char *name
)
72 printf("%s:\n", name
);
74 return vici_parse_cb(res
, NULL
, authority_kv
, authority_list
, &labeled
);
77 CALLBACK(list_cb
, void,
78 command_format_options_t
*format
, char *name
, vici_res_t
*res
)
80 if (*format
& COMMAND_FORMAT_RAW
)
82 vici_dump(res
, "list-authorities event", *format
& COMMAND_FORMAT_PRETTY
,
87 if (vici_parse_cb(res
, authorities
, NULL
, NULL
, NULL
) != 0)
89 fprintf(stderr
, "parsing authority event failed: %s\n",
95 static int list_authorities(vici_conn_t
*conn
)
99 command_format_options_t format
= COMMAND_FORMAT_NONE
;
100 char *arg
, *ca_name
= NULL
;;
105 switch (command_getopt(&arg
))
108 return command_usage(NULL
);
113 format
|= COMMAND_FORMAT_PRETTY
;
114 /* fall through to raw */
116 format
|= COMMAND_FORMAT_RAW
;
121 return command_usage("invalid --list-authorities option");
125 if (vici_register(conn
, "list-authority", list_cb
, &format
) != 0)
128 fprintf(stderr
, "registering for authorities failed: %s\n",
133 req
= vici_begin("list-authorities");
136 vici_add_key_valuef(req
, "name", "%s", ca_name
);
138 res
= vici_submit(req
, conn
);
142 fprintf(stderr
, "list-authorities request failed: %s\n", strerror(errno
));
145 if (format
& COMMAND_FORMAT_RAW
)
147 vici_dump(res
, "list-authorities reply", format
& COMMAND_FORMAT_PRETTY
,
155 * Register the command.
157 static void __attribute__ ((constructor
))reg()
159 command_register((command_t
) {
160 list_authorities
, 'B', "list-authorities",
161 "list loaded authority configurations",
162 {"[--raw|--pretty]"},
164 {"help", 'h', 0, "show usage information"},
165 {"name", 'n', 1, "filter by authority name"},
166 {"raw", 'r', 0, "dump raw response message"},
167 {"pretty", 'P', 0, "dump raw response message in pretty print"},