33 #include "cmdhandler.h"
40 #include "clientpipe.h"
48 static const char *module_str =
"keystate_list_task";
51 #define HID KEY_STATE_STATE_HIDDEN
52 #define RUM KEY_STATE_STATE_RUMOURED
53 #define OMN KEY_STATE_STATE_OMNIPRESENT
54 #define UNR KEY_STATE_STATE_UNRETENTIVE
55 #define NAV KEY_STATE_STATE_NA
58 const char*
statenames[] = {
"generate",
"publish",
"ready",
59 "active",
"retire",
"unknown",
"mixed",
"dead"};
144 return strdup(
"waiting for ds-submit");
146 return strdup(
"waiting for ds-seen");
148 return strdup(
"waiting for ds-retract");
150 return strdup(
"waiting for ds-gone");
160 return strdup(
"now");
163 localtime_r(&t, &srtm);
164 strftime(ct, 26,
"%Y-%m-%d %H:%M:%S", &srtm);
170 const char* zonename,
const char* keytype,
const char* keystate,
171 void (printheader)(
int sockfd),
181 client_printf_err(sockfd,
"Unable to get list of keys, memory "
182 "allocation or database error!\n");
187 (*printheader)(sockfd);
203 tchange = map_keytime(zone, key);
205 (*printkey)(sockfd, zone, key, tchange, hsmkey);
218 client_printf(sockfd,
220 " [--verbose] aka -v\n"
221 " [--debug] aka -d\n"
223 " [--parsable] aka -p\n"
224 " [--zone] aka -z \n"
225 " [--keystate | --all] aka -k | -a \n"
232 client_printf(sockfd,
233 "List the keys in the enforcer database.\n"
235 "verbose also show additional key parameters\n"
236 "debug print information about the keystate\n"
237 "full print information about the keystate and keytags\n"
238 "parsable output machine parsable list\n"
239 "zone limit the output to the specific zone\n"
240 "keytype limit the output to the given type, can be ZSK, KSK, or CSK\n"
241 "keystate limit the output to the given state\n"
242 "all print keys in all states (including generate) \n\n");
246 printcompatheader(
int sockfd) {
247 client_printf(sockfd,
"Keys:\n");
248 client_printf(sockfd,
"%-31s %-8s %-9s %s\n",
"Zone:",
"Keytype:",
"State:",
249 "Date of next transition:");
255 client_printf(sockfd,
256 "%-31s %-8s %-9s %s\n",
264 printverboseheader(
int sockfd) {
265 client_printf(sockfd,
"Keys:\n");
266 client_printf(sockfd,
"%-31s %-8s %-9s %-24s %-5s %-10s %-32s %-11s %s\n",
"Zone:",
"Keytype:",
"State:",
267 "Date of next transition:",
"Size:",
"Algorithm:",
"CKA_ID:",
268 "Repository:",
"KeyTag:");
274 client_printf(sockfd,
275 "%-31s %-8s %-9s %-24s %-5d %-10d %-32s %-11s %d\n",
290 client_printf(sockfd,
291 "%-31s %-8s %-9s %d %s %-12s %-12s %-12s %-12s %d %4d %s\n",
308 client_printf(sockfd,
309 "%s;%s;%s;%s;%d;%d;%s;%s;%d\n",
322 printdebugheader(
int sockfd) {
323 client_printf(sockfd,
324 "Keys:\nZone: Key role: "
325 "DS: DNSKEY: RRSIGDNSKEY: RRSIG: "
332 client_printf(sockfd,
333 "%-31s %-13s %-12s %-12s %-12s %-12s %d %4d %s\n",
348 client_printf(sockfd,
349 "%s;%s;%s;%s;%s;%s;%d;%d;%s\n",
362 run(
int sockfd, cmdhandler_ctx_type* context,
const char *cmd)
364 char buf[ODS_SE_MAXLINE];
366 const char *argv[
NARGV];
367 int success, argIndex;
368 int argc = 0, bVerbose = 0, bDebug = 0, bFull = 0, bParsable = 0, bAll = 0;
369 int long_index = 0, opt = 0;
370 const char* keytype = NULL;
371 const char* keystate = NULL;
372 const char* zonename = NULL;
375 static struct option long_options[] = {
376 {
"verbose", no_argument, 0,
'v'},
377 {
"debug", no_argument, 0,
'd'},
378 {
"full", no_argument, 0,
'f'},
379 {
"parsable", no_argument, 0,
'p'},
380 {
"zone", required_argument, 0,
'z'},
381 {
"keytype", required_argument, 0,
't'},
382 {
"keystate", required_argument, 0,
'e'},
383 {
"all", no_argument, 0,
'a'},
390 strncpy(buf, cmd,
sizeof (buf));
391 buf[
sizeof (buf) - 1] =
'\0';
394 argc = ods_str_explode(buf,
NARGV, argv);
396 ods_log_error(
"[%s] too many arguments for %s command",
398 client_printf_err(sockfd,
"too many arguments\n");
402 while ((opt = getopt_long(argc, (
char*
const*)argv,
"vdfpz:t:e:a", long_options, &long_index) ) != -1) {
429 client_printf_err(sockfd,
"unknown arguments\n");
430 ods_log_error(
"[%s] unknown arguments for %s command",
436 if (keystate != NULL && bAll) {
437 client_printf(sockfd,
"Error: --keystate and --all option cannot be given together\n");
442 success = perform_keystate_list(sockfd, dbconn, zonename, keytype, keystate, NULL, &printFullkey);
445 success = perform_keystate_list(sockfd, dbconn, zonename, keytype, keystate, NULL, &printdebugparsablekey);
447 success = perform_keystate_list(sockfd, dbconn, zonename, keytype, keystate, &printdebugheader, &printdebugkey);
449 }
else if (bVerbose) {
451 success = perform_keystate_list(sockfd, dbconn, zonename, keytype, keystate, NULL, &printverboseparsablekey);
453 success = perform_keystate_list(sockfd, dbconn, zonename, keytype, keystate, &printverboseheader, &printverbosekey);
457 client_printf_err(sockfd,
"-p option only available in combination with -v and -d.\n");
458 success = perform_keystate_list(sockfd, dbconn, zonename, keytype, keystate, &printcompatheader, &printcompatkey);
465 "key list", &usage, &help, NULL, &run