37 #include "clientpipe.h" 45 static const char *module_str =
"keystate_list_task";
48 #define HID KEY_STATE_STATE_HIDDEN 49 #define RUM KEY_STATE_STATE_RUMOURED 50 #define OMN KEY_STATE_STATE_OMNIPRESENT 51 #define UNR KEY_STATE_STATE_UNRETENTIVE 52 #define NAV KEY_STATE_STATE_NA 55 const char*
statenames[] = {
"generate",
"publish",
"ready",
56 "active",
"retire",
"dead",
"unknown",
"mixed"};
140 return strdup(
"waiting for ds-submit");
142 return strdup(
"waiting for ds-seen");
144 return strdup(
"waiting for ds-retract");
146 return strdup(
"waiting for ds-gone");
154 localtime_r(&t, &srtm);
155 strftime(ct, 26,
"%Y-%m-%d %H:%M:%S", &srtm);
161 const char* filterZone,
char** filterKeytype,
char** filterKeystate,
162 void (printheader)(
int sockfd),
173 client_printf_err(sockfd,
"Unable to get list of keys, memory " 174 "allocation or database error!\n");
179 (*printheader)(sockfd);
195 tchange = map_keytime(zone, key);
199 if(filterZone != NULL && strcmp(
zone_name(zone), filterZone))
201 for(i=0; filterKeytype && filterKeytype[i]; i++)
204 if(filterKeytype && filterKeytype[i] == NULL)
206 for(i=0; filterKeystate && filterKeystate[i]; i++)
209 if(filterKeystate && filterKeystate[i] == NULL)
212 (*printkey)(sockfd, zone, key, tchange, hsmkey);
226 client_printf(sockfd,
228 " [--verbose] aka -v\n" 229 " [--debug] aka -d\n" 230 " [--parsable] aka -p\n" 231 " [--zone] aka -z \n" 232 " [--keystate | --all] aka -k | -a \n" 239 client_printf(sockfd,
240 "List the keys in the enforcer database.\n" 242 "verbose also show additional key parameters\n" 243 "debug print information about the keystate\n" 244 "parsable output machine parsable list\n" 245 "zone limit the output to the specific zone\n" 246 "keytype limit the output to the given type, can be ZSK, KSK, or CSK\n" 247 "keystate limit the output to the given state\n" 248 "all print keys in all states (including generate) \n\n");
252 handles(
const char *cmd, ssize_t n)
258 printcompatheader(
int sockfd) {
259 client_printf(sockfd,
"Keys:\n");
260 client_printf(sockfd,
"%-31s %-8s %-9s %s\n",
"Zone:",
"Keytype:",
"State:",
261 "Date of next transition:");
267 client_printf(sockfd,
268 "%-31s %-8s %-9s %s\n",
276 printverboseheader(
int sockfd) {
277 client_printf(sockfd,
"Keys:\n");
278 client_printf(sockfd,
"%-31s %-8s %-9s %-24s %-5s %-10s %-32s %-11s %s\n",
"Zone:",
"Keytype:",
"State:",
279 "Date of next transition:",
"Size:",
"Algorithm:",
"CKA_ID:",
280 "Repository:",
"KeyTag:");
286 client_printf(sockfd,
287 "%-31s %-8s %-9s %-24s %-5d %-10d %-32s %-11s %d\n",
301 client_printf(sockfd,
302 "%s;%s;%s;%s;%d;%d;%s;%s;%d\n",
315 printdebugheader(
int sockfd) {
316 client_printf(sockfd,
317 "Keys:\nZone: Key role: " 318 "DS: DNSKEY: RRSIGDNSKEY: RRSIG: " 325 client_printf(sockfd,
326 "%-31s %-13s %-12s %-12s %-12s %-12s %d %4d %s\n",
341 client_printf(sockfd,
342 "%s;%s;%s;%s;%s;%s;%d;%d;%s\n",
355 tokenizeparam(
char *argument)
361 char* argSavePtr = NULL;
364 if ((argString = strtok_r(argument,
",", &argSavePtr)) != NULL) {
365 if ((tokenized = malloc(
sizeof (
char*)*argSize)) == NULL) {
370 if (strcmp(argString,
"")) {
371 tokenized[argCount] = argString;
373 if (argCount == argSize) {
375 if ((newtokenized = realloc(tokenized,
sizeof (
char*)*argSize)) == NULL) {
379 tokenized = newtokenized;
382 }
while (strtok_r(NULL,
",", &argSavePtr) != NULL);
383 tokenized[argCount] = NULL;
385 if ((tokenized = malloc(
sizeof (
char*)*2)) == NULL) {
388 tokenized[0] = argument;
395 run(
int sockfd,
engine_type* engine,
const char *cmd, ssize_t n,
397 char buf[ODS_SE_MAXLINE];
399 const char *argv[
NARGV];
400 int success, argIndex;
401 int argc, bVerbose, bDebug, bParsable, bAll;
404 const char* filterZone;
405 char** filterKeytype;
406 char** filterKeystate;
413 strncpy(buf, cmd,
sizeof (buf));
414 buf[
sizeof (buf) - 1] =
'\0';
417 argc = ods_str_explode(buf,
NARGV, argv);
421 client_printf(sockfd,
"too many arguments\n");
425 bVerbose = ods_find_arg(&argc, argv,
"verbose",
"v") != -1;
426 bDebug = ods_find_arg(&argc, argv,
"debug",
"d") != -1;
427 bParsable = ods_find_arg(&argc, argv,
"parsable",
"p") != -1;
428 if ((argIndex = ods_find_arg_and_param(&argc, argv,
"zone",
"z", &filterZone)) == -1) {
431 if (ods_find_arg_and_param(&argc, argv,
"keytype",
"k", (
const char **)&keytypeParam) == -1) {
434 if (ods_find_arg_and_param(&argc, argv,
"keystate",
"e", (
const char **)&keystateParam) == -1) {
435 keystateParam = NULL;
438 bAll = (ods_find_arg(&argc, argv,
"all",
"a") != -1);
440 if (keystateParam != NULL && bAll) {
441 client_printf(sockfd,
"Error: --keystate and --all option cannot be given together\n");
447 client_printf(sockfd,
"unknown arguments\n");
452 filterKeytype = tokenizeparam(keytypeParam);
454 filterKeytype = NULL;
456 filterKeystate = tokenizeparam(keystateParam);
458 filterKeystate = NULL;
460 if (filterKeystate != NULL) {
461 free(filterKeystate);
463 filterKeystate = NULL;
464 }
else if(filterKeystate == NULL) {
465 if ((filterKeystate = malloc(
sizeof (
char*) * 6))) {
466 filterKeystate[0] = (
char *)
"publish";
467 filterKeystate[1] = (
char *)
"ready";
468 filterKeystate[2] = (
char *)
"active";
469 filterKeystate[3] = (
char *)
"retire";
470 filterKeystate[4] = (
char *)
"mixed";
471 filterKeystate[5] = NULL;
477 success = perform_keystate_list(sockfd, dbconn, filterZone, filterKeytype, filterKeystate, NULL, &printdebugparsablekey);
479 success = perform_keystate_list(sockfd, dbconn, filterZone, filterKeytype, filterKeystate, &printdebugheader, &printdebugkey);
481 }
else if (bVerbose) {
483 success = perform_keystate_list(sockfd, dbconn, filterZone, filterKeytype, filterKeystate, NULL, &printverboseparsablekey);
485 success = perform_keystate_list(sockfd, dbconn, filterZone, filterKeytype, filterKeystate, &printverboseheader, &printverbosekey);
488 success = perform_keystate_list(sockfd, dbconn, filterZone, filterKeytype, filterKeystate, &printcompatheader, &printcompatkey);
494 free(filterKeystate);
const char * key_data_role_text(const key_data_t *key_data)
const char * key_state_state_text(const key_state_t *key_state)
hsm_key_t * key_data_get_hsm_key(const key_data_t *key_data)
void ods_log_debug(const char *format,...)
unsigned int key_data_publish(const key_data_t *key_data)
unsigned int key_data_active_zsk(const key_data_t *key_data)
key_data_list_t * key_data_list_new_get(const db_connection_t *connection)
const db_value_t * key_data_zone_id(const key_data_t *key_data)
int(* run)(int sockfd, struct engine_struct *engine, const char *cmd, ssize_t n, db_connection_t *dbconn)
int zone_next_change(const zone_t *zone)
struct cmd_func_block * key_list_funcblock(void)
enum key_data_ds_at_parent key_data_ds_at_parent_t
unsigned int key_data_keytag(const key_data_t *key_data)
key_data_t * key_data_list_get_next(key_data_list_t *key_data_list)
const char * hsm_key_repository(const hsm_key_t *hsm_key)
void zone_free(zone_t *zone)
unsigned int key_data_introducing(const key_data_t *key_data)
void(* usage)(int sockfd)
const key_state_t * key_data_cached_rrsigdnskey(key_data_t *key_data)
int db_value_cmp(const db_value_t *value_a, const db_value_t *value_b, int *result)
const char * statenames[]
int key_data_cache_key_states(key_data_t *key_data)
const char * hsm_key_locator(const hsm_key_t *hsm_key)
zone_t * key_data_get_zone(const key_data_t *key_data)
const char * zone_name(const zone_t *zone)
const char * map_keystate(key_data_t *key)
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)
void key_data_list_free(key_data_list_t *key_data_list)
const key_state_t * key_data_cached_dnskey(key_data_t *key_data)
void key_data_free(key_data_t *key_data)
const db_value_t * zone_id(const zone_t *zone)
unsigned int hsm_key_algorithm(const hsm_key_t *hsm_key)
void hsm_key_free(hsm_key_t *hsm_key)
unsigned int key_data_active_ksk(const key_data_t *key_data)
int(* handles)(const char *cmd, ssize_t n)
unsigned int hsm_key_bits(const hsm_key_t *hsm_key)
void ods_log_warning(const char *format,...)