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");
157 return strdup(
"now");
160 localtime_r(&t, &srtm);
161 strftime(ct, 26,
"%Y-%m-%d %H:%M:%S", &srtm);
167 const char* zonename,
const char* keytype,
const char* keystate,
168 void (printheader)(
int sockfd),
178 client_printf_err(sockfd,
"Unable to get list of keys, memory "
179 "allocation or database error!\n");
184 (*printheader)(sockfd);
200 tchange = map_keytime(zone, key);
202 (*printkey)(sockfd, zone, key, tchange, hsmkey);
215 client_printf(sockfd,
217 " [--verbose] aka -v\n"
218 " [--debug] aka -d\n"
220 " [--parsable] aka -p\n"
221 " [--zone] aka -z \n"
222 " [--keystate | --all] aka -k | -a \n"
229 client_printf(sockfd,
230 "List the keys in the enforcer database.\n"
232 "verbose also show additional key parameters\n"
233 "debug print information about the keystate\n"
234 "full print information about the keystate and keytags\n"
235 "parsable output machine parsable list\n"
236 "zone limit the output to the specific zone\n"
237 "keytype limit the output to the given type, can be ZSK, KSK, or CSK\n"
238 "keystate limit the output to the given state\n"
239 "all print keys in all states (including generate) \n\n");
243 printcompatheader(
int sockfd) {
244 client_printf(sockfd,
"Keys:\n");
245 client_printf(sockfd,
"%-31s %-8s %-9s %s\n",
"Zone:",
"Keytype:",
"State:",
246 "Date of next transition:");
252 client_printf(sockfd,
253 "%-31s %-8s %-9s %s\n",
261 printverboseheader(
int sockfd) {
262 client_printf(sockfd,
"Keys:\n");
263 client_printf(sockfd,
"%-31s %-8s %-9s %-24s %-5s %-10s %-32s %-11s %s\n",
"Zone:",
"Keytype:",
"State:",
264 "Date of next transition:",
"Size:",
"Algorithm:",
"CKA_ID:",
265 "Repository:",
"KeyTag:");
271 client_printf(sockfd,
272 "%-31s %-8s %-9s %-24s %-5d %-10d %-32s %-11s %d\n",
287 client_printf(sockfd,
288 "%-31s %-8s %-9s %d %s %-12s %-12s %-12s %-12s %d %4d %s\n",
305 client_printf(sockfd,
306 "%s;%s;%s;%s;%d;%d;%s;%s;%d\n",
319 printdebugheader(
int sockfd) {
320 client_printf(sockfd,
321 "Keys:\nZone: Key role: "
322 "DS: DNSKEY: RRSIGDNSKEY: RRSIG: "
329 client_printf(sockfd,
330 "%-31s %-13s %-12s %-12s %-12s %-12s %d %4d %s\n",
345 client_printf(sockfd,
346 "%s;%s;%s;%s;%s;%s;%d;%d;%s\n",
359 run(
int sockfd, cmdhandler_ctx_type* context,
const char *cmd)
361 char buf[ODS_SE_MAXLINE];
363 const char *argv[
NARGV];
364 int success, argIndex;
365 int argc = 0, 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'},
387 strncpy(buf, cmd,
sizeof (buf));
388 buf[
sizeof (buf) - 1] =
'\0';
391 argc = ods_str_explode(buf,
NARGV, argv);
393 ods_log_error(
"[%s] too many arguments for %s command",
395 client_printf_err(sockfd,
"too many arguments\n");
399 while ((opt = getopt_long(argc, (
char*
const*)argv,
"vdfpz:t:e:a", long_options, &long_index) ) != -1) {
426 client_printf_err(sockfd,
"unknown arguments\n");
427 ods_log_error(
"[%s] unknown arguments for %s command",
433 if (keystate != NULL && bAll) {
434 client_printf(sockfd,
"Error: --keystate and --all option cannot be given together\n");
439 success = perform_keystate_list(sockfd, dbconn, zonename, keytype, keystate, NULL, &printFullkey);
442 success = perform_keystate_list(sockfd, dbconn, zonename, keytype, keystate, NULL, &printdebugparsablekey);
444 success = perform_keystate_list(sockfd, dbconn, zonename, keytype, keystate, &printdebugheader, &printdebugkey);
446 }
else if (bVerbose) {
448 success = perform_keystate_list(sockfd, dbconn, zonename, keytype, keystate, NULL, &printverboseparsablekey);
450 success = perform_keystate_list(sockfd, dbconn, zonename, keytype, keystate, &printverboseheader, &printverbosekey);
454 client_printf_err(sockfd,
"-p option only available in combination with -v and -d.\n");
455 success = perform_keystate_list(sockfd, dbconn, zonename, keytype, keystate, &printcompatheader, &printcompatkey);
462 "key list", &usage, &help, NULL, &run
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)
unsigned int hsm_key_algorithm(const hsm_key_t *hsm_key)
unsigned int hsm_key_bits(const hsm_key_t *hsm_key)
const char * hsm_key_locator(const hsm_key_t *hsm_key)
unsigned int key_data_active_ksk(const key_data_t *key_data)
void key_data_free(key_data_t *key_data)
key_data_t * key_data_list_get_next(key_data_list_t *key_data_list)
const char * key_data_role_text(const key_data_t *key_data)
zone_db_t * key_data_get_zone(const key_data_t *key_data)
unsigned int key_data_keytag(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)
const db_value_t * key_data_zone_id(const key_data_t *key_data)
unsigned int key_data_active_zsk(const key_data_t *key_data)
hsm_key_t * key_data_get_hsm_key(const key_data_t *key_data)
key_data_list_t * key_data_list_new_get(const db_connection_t *connection)
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
int key_data_cache_key_states(key_data_t *key_data)
const key_state_t * key_data_cached_rrsigdnskey(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_rrsig(key_data_t *key_data)
const key_state_t * key_data_cached_ds(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 * map_keystate(key_data_t *key)
const char * statenames[]
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)