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"};
139 return strdup(
"waiting for ds-submit");
141 return strdup(
"waiting for ds-seen");
143 return strdup(
"waiting for ds-retract");
145 return strdup(
"waiting for ds-gone");
153 localtime_r(&t, &srtm);
154 strftime(ct, 26,
"%Y-%m-%d %H:%M:%S", &srtm);
160 const char* filterZone,
char** filterKeytype,
char** filterKeystate,
161 void (printheader)(
int sockfd),
172 client_printf_err(sockfd,
"Unable to get list of keys, memory " 173 "allocation or database error!\n");
178 (*printheader)(sockfd);
194 tchange = map_keytime(zone, key);
198 if(filterZone != NULL && strcmp(
zone_name(zone), filterZone))
200 for(i=0; filterKeytype && filterKeytype[i]; i++)
203 if(filterKeytype && filterKeytype[i] == NULL)
205 for(i=0; filterKeystate && filterKeystate[i]; i++)
208 if(filterKeystate && filterKeystate[i] == NULL)
211 (*printkey)(sockfd, zone, key, tchange, hsmkey);
225 client_printf(sockfd,
227 " [--verbose] aka -v\n" 228 " [--debug] aka -d\n" 229 " [--parsable] aka -p\n" 230 " [--zone] aka -z \n" 231 " [--keystate | --all] aka -k | -a \n" 238 client_printf(sockfd,
239 "List the keys in the enforcer database.\n" 241 "verbose also show additional key parameters\n" 242 "debug print information about the keystate\n" 243 "parsable output machine parsable list\n" 244 "zone limit the output to the specific zone\n" 245 "keytype limit the output to the given type, can be ZSK, KSK, or CSK\n" 246 "keystate limit the output to the given state\n" 247 "all print keys in all states (including generate) \n\n");
251 handles(
const char *cmd, ssize_t n)
257 printcompatheader(
int sockfd) {
258 client_printf(sockfd,
"Keys:\n");
259 client_printf(sockfd,
"%-31s %-8s %-9s %s\n",
"Zone:",
"Keytype:",
"State:",
260 "Date of next transition:");
266 client_printf(sockfd,
267 "%-31s %-8s %-9s %s\n",
275 printverboseheader(
int sockfd) {
276 client_printf(sockfd,
"Keys:\n");
277 client_printf(sockfd,
"%-31s %-8s %-9s %-24s %-5s %-10s %-32s %-11s %s\n",
"Zone:",
"Keytype:",
"State:",
278 "Date of next transition:",
"Size:",
"Algorithm:",
"CKA_ID:",
279 "Repository:",
"KeyTag:");
285 client_printf(sockfd,
286 "%-31s %-8s %-9s %-24s %-5d %-10d %-32s %-11s %d\n",
300 client_printf(sockfd,
301 "%s;%s;%s;%s;%d;%d;%s;%s;%d\n",
314 printdebugheader(
int sockfd) {
315 client_printf(sockfd,
316 "Keys:\nZone: Key role: " 317 "DS: DNSKEY: RRSIGDNSKEY: RRSIG: " 324 client_printf(sockfd,
325 "%-31s %-13s %-12s %-12s %-12s %-12s %d %4d %s\n",
340 client_printf(sockfd,
341 "%s;%s;%s;%s;%s;%s;%d;%d;%s\n",
354 tokenizeparam(
char *argument)
360 char* argSavePtr = NULL;
363 if ((argString = strtok_r(argument,
",", &argSavePtr)) != NULL) {
364 if ((tokenized = malloc(
sizeof (
char*)*argSize)) == NULL) {
369 if (strcmp(argString,
"")) {
370 tokenized[argCount] = argString;
372 if (argCount == argSize) {
374 if ((newtokenized = realloc(tokenized,
sizeof (
char*)*argSize)) == NULL) {
378 tokenized = newtokenized;
381 }
while (strtok_r(NULL,
",", &argSavePtr) != NULL);
382 tokenized[argCount] = NULL;
384 if ((tokenized = malloc(
sizeof (
char*)*2)) == NULL) {
387 tokenized[0] = argument;
394 run(
int sockfd,
engine_type* engine,
const char *cmd, ssize_t n,
396 char buf[ODS_SE_MAXLINE];
398 const char *argv[
NARGV];
399 int success, argIndex;
400 int argc, bVerbose, bDebug, bParsable, bAll;
403 const char* filterZone;
404 char** filterKeytype;
405 char** filterKeystate;
412 strncpy(buf, cmd,
sizeof (buf));
413 buf[
sizeof (buf) - 1] =
'\0';
416 argc = ods_str_explode(buf,
NARGV, argv);
420 client_printf(sockfd,
"too many arguments\n");
424 bVerbose = ods_find_arg(&argc, argv,
"verbose",
"v") != -1;
425 bDebug = ods_find_arg(&argc, argv,
"debug",
"d") != -1;
426 bParsable = ods_find_arg(&argc, argv,
"parsable",
"p") != -1;
427 if ((argIndex = ods_find_arg_and_param(&argc, argv,
"zone",
"z", &filterZone)) == -1) {
430 if (ods_find_arg_and_param(&argc, argv,
"keytype",
"k", (
const char **)&keytypeParam) == -1) {
433 if (ods_find_arg_and_param(&argc, argv,
"keystate",
"e", (
const char **)&keystateParam) == -1) {
434 keystateParam = NULL;
437 bAll = (ods_find_arg(&argc, argv,
"all",
"a") != -1);
439 if (keystateParam != NULL && bAll) {
440 client_printf(sockfd,
"Error: --keystate and --all option cannot be given together\n");
446 client_printf(sockfd,
"unknown arguments\n");
451 filterKeytype = tokenizeparam(keytypeParam);
453 filterKeytype = NULL;
455 filterKeystate = tokenizeparam(keystateParam);
457 filterKeystate = NULL;
459 if (filterKeystate != NULL) {
460 free(filterKeystate);
462 filterKeystate = NULL;
463 }
else if(filterKeystate == NULL) {
464 if ((filterKeystate = malloc(
sizeof (
char*) * 6))) {
465 filterKeystate[0] = (
char *)
"publish";
466 filterKeystate[1] = (
char *)
"ready";
467 filterKeystate[2] = (
char *)
"active";
468 filterKeystate[3] = (
char *)
"retire";
469 filterKeystate[4] = (
char *)
"mixed";
470 filterKeystate[5] = NULL;
476 success = perform_keystate_list(sockfd, dbconn, filterZone, filterKeytype, filterKeystate, NULL, &printdebugparsablekey);
478 success = perform_keystate_list(sockfd, dbconn, filterZone, filterKeytype, filterKeystate, &printdebugheader, &printdebugkey);
480 }
else if (bVerbose) {
482 success = perform_keystate_list(sockfd, dbconn, filterZone, filterKeytype, filterKeystate, NULL, &printverboseparsablekey);
484 success = perform_keystate_list(sockfd, dbconn, filterZone, filterKeytype, filterKeystate, &printverboseheader, &printverbosekey);
487 success = perform_keystate_list(sockfd, dbconn, filterZone, filterKeytype, filterKeystate, &printcompatheader, &printcompatkey);
493 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,...)