33#include "cmdhandler.h"
40#include "clientpipe.h"
41#include "longgetopt.h"
49static const char *module_str =
"keystate_list_task";
52#define HID KEY_STATE_STATE_HIDDEN
53#define RUM KEY_STATE_STATE_RUMOURED
54#define OMN KEY_STATE_STATE_OMNIPRESENT
55#define UNR KEY_STATE_STATE_UNRETENTIVE
56#define NAV KEY_STATE_STATE_NA
59const char*
statenames[] = {
"generate",
"publish",
"ready",
60 "active",
"retire",
"unknown",
"mixed",
"dead"};
145 return strdup(
"waiting for ds-submit");
147 return strdup(
"waiting for ds-seen");
149 return strdup(
"waiting for ds-retract");
151 return strdup(
"waiting for ds-gone");
158 return strdup(
"now");
161 localtime_r(&t, &srtm);
162 strftime(ct, 26,
"%Y-%m-%d %H:%M:%S", &srtm);
168 const char* zonename,
const char* keytype,
const char* keystate,
169 void (printheader)(
int sockfd),
179 client_printf_err(sockfd,
"Unable to get list of keys, memory "
180 "allocation or database error!\n");
185 (*printheader)(sockfd);
201 tchange = map_keytime(zone, key);
203 (*printkey)(sockfd, zone, key, tchange, hsmkey);
216 client_printf(sockfd,
218 " [--verbose] aka -v\n"
219 " [--debug] aka -d\n"
221 " [--parsable] aka -p\n"
222 " [--zone] aka -z \n"
223 " [--keystate | --all] aka -k | -a \n"
230 client_printf(sockfd,
231 "List the keys in the enforcer database.\n"
233 "verbose also show additional key parameters\n"
234 "debug print information about the keystate\n"
235 "full print information about the keystate and keytags\n"
236 "parsable output machine parsable list\n"
237 "zone limit the output to the specific zone\n"
238 "keytype limit the output to the given type, can be ZSK, KSK, or CSK\n"
239 "keystate limit the output to the given state\n"
240 "all print keys in all states (including generate) \n\n");
244printcompatheader(
int sockfd) {
245 client_printf(sockfd,
"Keys:\n");
246 client_printf(sockfd,
"%-31s %-8s %-9s %s\n",
"Zone:",
"Keytype:",
"State:",
247 "Date of next transition:");
253 client_printf(sockfd,
254 "%-31s %-8s %-9s %s\n",
262printverboseheader(
int sockfd) {
263 client_printf(sockfd,
"Keys:\n");
264 client_printf(sockfd,
"%-31s %-8s %-9s %-24s %-5s %-10s %-32s %-11s %s\n",
"Zone:",
"Keytype:",
"State:",
265 "Date of next transition:",
"Size:",
"Algorithm:",
"CKA_ID:",
266 "Repository:",
"KeyTag:");
272 client_printf(sockfd,
273 "%-31s %-8s %-9s %-24s %-5d %-10d %-32s %-11s %d\n",
288 client_printf(sockfd,
289 "%-31s %-8s %-9s %d %s %-12s %-12s %-12s %-12s %d %4d %s\n",
306 client_printf(sockfd,
307 "%s;%s;%s;%s;%d;%d;%s;%s;%d\n",
320printdebugheader(
int sockfd) {
321 client_printf(sockfd,
322 "Keys:\nZone: Key role: "
323 "DS: DNSKEY: RRSIGDNSKEY: RRSIG: "
330 client_printf(sockfd,
331 "%-31s %-13s %-12s %-12s %-12s %-12s %d %4d %s\n",
346 client_printf(sockfd,
347 "%s;%s;%s;%s;%s;%s;%d;%d;%s\n",
360run(cmdhandler_ctx_type* context,
int argc,
char* argv[])
362 int sockfd = context->sockfd;
363 struct longgetopt optctx;
365 int bVerbose = 0, bDebug = 0, bFull = 0, bParsable = 0, bAll = 0;
366 int long_index = 0, opt = 0;
367 const char* keytype = NULL;
368 const char* keystate = NULL;
369 const char* zonename = NULL;
372 static struct option long_options[] = {
373 {
"verbose", no_argument, 0,
'v'},
374 {
"debug", no_argument, 0,
'd'},
375 {
"full", no_argument, 0,
'f'},
376 {
"parsable", no_argument, 0,
'p'},
377 {
"zone", required_argument, 0,
'z'},
378 {
"keytype", required_argument, 0,
't'},
379 {
"keystate", required_argument, 0,
'e'},
380 {
"all", no_argument, 0,
'a'},
384 for(opt = longgetopt(argc, argv,
"vdfpz:t:e:a", long_options, &long_index, &optctx); opt != -1;
385 opt = longgetopt(argc, argv, NULL, long_options, &long_index, &optctx)) {
400 zonename = optctx.optarg;
403 keytype = optctx.optarg;
406 keystate = optctx.optarg;
412 client_printf_err(sockfd,
"unknown arguments\n");
413 ods_log_error(
"[%s] unknown arguments for key list command", module_str);
418 if (keystate != NULL && bAll) {
419 client_printf(sockfd,
"Error: --keystate and --all option cannot be given together\n");
424 success = perform_keystate_list(sockfd, dbconn, zonename, keytype, keystate, NULL, &printFullkey);
427 success = perform_keystate_list(sockfd, dbconn, zonename, keytype, keystate, NULL, &printdebugparsablekey);
429 success = perform_keystate_list(sockfd, dbconn, zonename, keytype, keystate, &printdebugheader, &printdebugkey);
431 }
else if (bVerbose) {
433 success = perform_keystate_list(sockfd, dbconn, zonename, keytype, keystate, NULL, &printverboseparsablekey);
435 success = perform_keystate_list(sockfd, dbconn, zonename, keytype, keystate, &printverboseheader, &printverbosekey);
439 client_printf_err(sockfd,
"-p option only available in combination with -v and -d.\n");
440 success = perform_keystate_list(sockfd, dbconn, zonename, keytype, keystate, &printcompatheader, &printcompatkey);
446 "key list", &usage, &help, NULL, NULL, &run, NULL
int db_value_cmp(const db_value_t *value_a, const db_value_t *value_b, int *result)
db_connection_t * getconnectioncontext(cmdhandler_ctx_type *context)
void hsm_key_free(hsm_key_t *hsm_key)
const char * hsm_key_repository(const hsm_key_t *hsm_key)
const char * hsm_key_locator(const hsm_key_t *hsm_key)
unsigned int hsm_key_algorithm(const hsm_key_t *hsm_key)
unsigned int hsm_key_bits(const hsm_key_t *hsm_key)
zone_db_t * key_data_get_zone(const key_data_t *key_data)
unsigned int key_data_active_ksk(const key_data_t *key_data)
void key_data_free(key_data_t *key_data)
key_data_list_t * key_data_list_new_get(const db_connection_t *connection)
hsm_key_t * key_data_get_hsm_key(const key_data_t *key_data)
unsigned int key_data_keytag(const key_data_t *key_data)
const char * key_data_role_text(const key_data_t *key_data)
unsigned int key_data_publish(const key_data_t *key_data)
void key_data_list_free(key_data_list_t *key_data_list)
unsigned int key_data_introducing(const key_data_t *key_data)
unsigned int key_data_active_zsk(const key_data_t *key_data)
key_data_t * key_data_list_get_next(key_data_list_t *key_data_list)
const db_value_t * key_data_zone_id(const key_data_t *key_data)
enum key_data_ds_at_parent key_data_ds_at_parent_t
@ KEY_DATA_DS_AT_PARENT_SUBMITTED
@ KEY_DATA_DS_AT_PARENT_RETRACT
@ KEY_DATA_DS_AT_PARENT_SEEN
@ KEY_DATA_DS_AT_PARENT_INVALID
@ KEY_DATA_DS_AT_PARENT_SUBMIT
@ KEY_DATA_DS_AT_PARENT_RETRACTED
const key_state_t * key_data_cached_rrsig(key_data_t *key_data)
int key_data_cache_key_states(key_data_t *key_data)
const key_state_t * key_data_cached_dnskey(key_data_t *key_data)
const key_state_t * key_data_cached_ds(key_data_t *key_data)
const key_state_t * key_data_cached_rrsigdnskey(key_data_t *key_data)
const char * key_state_state_text(const key_state_t *key_state)
struct cmd_func_block key_list_funcblock
const char * statenames[]
const char * map_keystate(key_data_t *key)
void zone_db_free(zone_db_t *zone)
const char * zone_db_name(const zone_db_t *zone)
const db_value_t * zone_db_id(const zone_db_t *zone)
int zone_db_next_change(const zone_db_t *zone)