📄 keychain.c
字号:
intkey_lifetime_duration_set (struct vty *vty, struct key_range *krange, char *stime_str, char *sday_str, char *smonth_str, char *syear_str, char *duration_str){ time_t time_start; u_int32_t duration; char *endptr = NULL; time_start = key_str2time (stime_str, sday_str, smonth_str, syear_str); if (time_start < 0) { vty_out (vty, "Malformed time value%s", VTY_NEWLINE); return CMD_WARNING; } krange->start = time_start; duration = strtoul (duration_str, &endptr, 10); if (duration == ULONG_MAX || *endptr != '\0') { vty_out (vty, "Malformed duration%s", VTY_NEWLINE); return CMD_WARNING; } krange->duration = 1; krange->end = time_start + duration; return CMD_SUCCESS;}intkey_lifetime_infinite_set (struct vty *vty, struct key_range *krange, char *stime_str, char *sday_str, char *smonth_str, char *syear_str){ time_t time_start; time_start = key_str2time (stime_str, sday_str, smonth_str, syear_str); if (time_start < 0) { vty_out (vty, "Malformed time value%s", VTY_NEWLINE); return CMD_WARNING; } krange->start = time_start; krange->end = -1; return CMD_SUCCESS;}DEFUN (accept_lifetime_day_month_day_month, accept_lifetime_day_month_day_month_cmd, "accept-lifetime HH:MM:SS <1-31> MONTH <1993-2035> HH:MM:SS <1-31> MONTH <1993-2035>", "Set accept lifetime of the key\n" "Time to start\n" "Day of th month to start\n" "Month of the year to start\n" "Year to start\n" "Time to expire\n" "Day of th month to expire\n" "Month of the year to expire\n" "Year to expire\n"){ struct key *key; key = vty->index_sub; return key_lifetime_set (vty, &key->accept, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7]);}DEFUN (accept_lifetime_day_month_month_day, accept_lifetime_day_month_month_day_cmd, "accept-lifetime HH:MM:SS <1-31> MONTH <1993-2035> HH:MM:SS MONTH <1-31> <1993-2035>", "Set accept lifetime of the key\n" "Time to start\n" "Day of th month to start\n" "Month of the year to start\n" "Year to start\n" "Time to expire\n" "Month of the year to expire\n" "Day of th month to expire\n" "Year to expire\n"){ struct key *key; key = vty->index_sub; return key_lifetime_set (vty, &key->accept, argv[0], argv[1], argv[2], argv[3], argv[4], argv[6], argv[5], argv[7]);}DEFUN (accept_lifetime_month_day_day_month, accept_lifetime_month_day_day_month_cmd, "accept-lifetime HH:MM:SS MONTH <1-31> <1993-2035> HH:MM:SS <1-31> MONTH <1993-2035>", "Set accept lifetime of the key\n" "Time to start\n" "Month of the year to start\n" "Day of th month to start\n" "Year to start\n" "Time to expire\n" "Day of th month to expire\n" "Month of the year to expire\n" "Year to expire\n"){ struct key *key; key = vty->index_sub; return key_lifetime_set (vty, &key->accept, argv[0], argv[2], argv[1], argv[3], argv[4], argv[5], argv[6], argv[7]);}DEFUN (accept_lifetime_month_day_month_day, accept_lifetime_month_day_month_day_cmd, "accept-lifetime HH:MM:SS MONTH <1-31> <1993-2035> HH:MM:SS MONTH <1-31> <1993-2035>", "Set accept lifetime of the key\n" "Time to start\n" "Month of the year to start\n" "Day of th month to start\n" "Year to start\n" "Time to expire\n" "Month of the year to expire\n" "Day of th month to expire\n" "Year to expire\n"){ struct key *key; key = vty->index_sub; return key_lifetime_set (vty, &key->accept, argv[0], argv[2], argv[1], argv[3], argv[4], argv[6], argv[5], argv[7]);}DEFUN (accept_lifetime_infinite_day_month, accept_lifetime_infinite_day_month_cmd, "accept-lifetime HH:MM:SS <1-31> MONTH <1993-2035> infinite", "Set accept lifetime of the key\n" "Time to start\n" "Day of th month to start\n" "Month of the year to start\n" "Year to start\n" "Never expires"){ struct key *key; key = vty->index_sub; return key_lifetime_infinite_set (vty, &key->accept, argv[0], argv[1], argv[2], argv[3]);}DEFUN (accept_lifetime_infinite_month_day, accept_lifetime_infinite_month_day_cmd, "accept-lifetime HH:MM:SS MONTH <1-31> <1993-2035> infinite", "Set accept lifetime of the key\n" "Time to start\n" "Month of the year to start\n" "Day of th month to start\n" "Year to start\n" "Never expires"){ struct key *key; key = vty->index_sub; return key_lifetime_infinite_set (vty, &key->accept, argv[0], argv[2], argv[1], argv[3]);}DEFUN (accept_lifetime_duration_day_month, accept_lifetime_duration_day_month_cmd, "accept-lifetime HH:MM:SS <1-31> MONTH <1993-2035> duration <1-2147483646>", "Set accept lifetime of the key\n" "Time to start\n" "Day of th month to start\n" "Month of the year to start\n" "Year to start\n" "Duration of the key\n" "Duration seconds\n"){ struct key *key; key = vty->index_sub; return key_lifetime_duration_set (vty, &key->accept, argv[0], argv[1], argv[2], argv[3], argv[4]);}DEFUN (accept_lifetime_duration_month_day, accept_lifetime_duration_month_day_cmd, "accept-lifetime HH:MM:SS MONTH <1-31> <1993-2035> duration <1-2147483646>", "Set accept lifetime of the key\n" "Time to start\n" "Month of the year to start\n" "Day of th month to start\n" "Year to start\n" "Duration of the key\n" "Duration seconds\n"){ struct key *key; key = vty->index_sub; return key_lifetime_duration_set (vty, &key->accept, argv[0], argv[2], argv[1], argv[3], argv[4]);}DEFUN (send_lifetime_day_month_day_month, send_lifetime_day_month_day_month_cmd, "send-lifetime HH:MM:SS <1-31> MONTH <1993-2035> HH:MM:SS <1-31> MONTH <1993-2035>", "Set send lifetime of the key\n" "Time to start\n" "Day of th month to start\n" "Month of the year to start\n" "Year to start\n" "Time to expire\n" "Day of th month to expire\n" "Month of the year to expire\n" "Year to expire\n"){ struct key *key; key = vty->index_sub; return key_lifetime_set (vty, &key->send, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7]);}DEFUN (send_lifetime_day_month_month_day, send_lifetime_day_month_month_day_cmd, "send-lifetime HH:MM:SS <1-31> MONTH <1993-2035> HH:MM:SS MONTH <1-31> <1993-2035>", "Set send lifetime of the key\n" "Time to start\n" "Day of th month to start\n" "Month of the year to start\n" "Year to start\n" "Time to expire\n" "Month of the year to expire\n" "Day of th month to expire\n" "Year to expire\n"){ struct key *key; key = vty->index_sub; return key_lifetime_set (vty, &key->send, argv[0], argv[1], argv[2], argv[3], argv[4], argv[6], argv[5], argv[7]);}DEFUN (send_lifetime_month_day_day_month, send_lifetime_month_day_day_month_cmd, "send-lifetime HH:MM:SS MONTH <1-31> <1993-2035> HH:MM:SS <1-31> MONTH <1993-2035>", "Set send lifetime of the key\n" "Time to start\n" "Month of the year to start\n" "Day of th month to start\n" "Year to start\n" "Time to expire\n" "Day of th month to expire\n" "Month of the year to expire\n" "Year to expire\n"){ struct key *key; key = vty->index_sub; return key_lifetime_set (vty, &key->send, argv[0], argv[2], argv[1], argv[3], argv[4], argv[5], argv[6], argv[7]);}DEFUN (send_lifetime_month_day_month_day, send_lifetime_month_day_month_day_cmd, "send-lifetime HH:MM:SS MONTH <1-31> <1993-2035> HH:MM:SS MONTH <1-31> <1993-2035>", "Set send lifetime of the key\n" "Time to start\n" "Month of the year to start\n" "Day of th month to start\n" "Year to start\n" "Time to expire\n" "Month of the year to expire\n" "Day of th month to expire\n" "Year to expire\n"){ struct key *key; key = vty->index_sub; return key_lifetime_set (vty, &key->send, argv[0], argv[2], argv[1], argv[3], argv[4], argv[6], argv[5], argv[7]);}DEFUN (send_lifetime_infinite_day_month, send_lifetime_infinite_day_month_cmd, "send-lifetime HH:MM:SS <1-31> MONTH <1993-2035> infinite", "Set send lifetime of the key\n" "Time to start\n" "Day of th month to start\n" "Month of the year to start\n" "Year to start\n" "Never expires"){ struct key *key; key = vty->index_sub; return key_lifetime_infinite_set (vty, &key->send, argv[0], argv[1], argv[2], argv[3]);}DEFUN (send_lifetime_infinite_month_day, send_lifetime_infinite_month_day_cmd, "send-lifetime HH:MM:SS MONTH <1-31> <1993-2035> infinite", "Set send lifetime of the key\n" "Time to start\n" "Month of the year to start\n" "Day of th month to start\n" "Year to start\n" "Never expires"){ struct key *key; key = vty->index_sub; return key_lifetime_infinite_set (vty, &key->send, argv[0], argv[2], argv[1], argv[3]);}DEFUN (send_lifetime_duration_day_month, send_lifetime_duration_day_month_cmd, "send-lifetime HH:MM:SS <1-31> MONTH <1993-2035> duration <1-2147483646>", "Set send lifetime of the key\n" "Time to start\n" "Day of th month to start\n" "Month of the year to start\n" "Year to start\n" "Duration of the key\n" "Duration seconds\n"){ struct key *key; key = vty->index_sub; return key_lifetime_duration_set (vty, &key->send, argv[0], argv[1], argv[2], argv[3], argv[4]);}DEFUN (send_lifetime_duration_month_day, send_lifetime_duration_month_day_cmd, "send-lifetime HH:MM:SS MONTH <1-31> <1993-2035> duration <1-2147483646>", "Set send lifetime of the key\n" "Time to start\n" "Month of the year to start\n" "Day of th month to start\n" "Year to start\n" "Duration of the key\n" "Duration seconds\n"){ struct key *key; key = vty->index_sub; return key_lifetime_duration_set (vty, &key->send, argv[0], argv[2], argv[1], argv[3], argv[4]);}struct cmd_node keychain_node ={ KEYCHAIN_NODE, "%s(config-keychain)# ", 1};struct cmd_node keychain_key_node ={ KEYCHAIN_KEY_NODE, "%s(config-keychain-key)# ", 1};intkeychain_strftime (char *buf, int bufsiz, time_t *time){ struct tm *tm; size_t len; tm = localtime (time); len = strftime (buf, bufsiz, "%T %b %d %Y", tm); return len;}intkeychain_config_write (struct vty *vty){ struct keychain *keychain; struct key *key; struct listnode *nn; struct listnode *nm; char buf[BUFSIZ]; LIST_LOOP (keychain_list, keychain, nn) { vty_out (vty, "key chain %s%s", keychain->name, VTY_NEWLINE); LIST_LOOP (keychain->key, key, nm) { vty_out (vty, " key %d%s", key->index, VTY_NEWLINE); if (key->string) vty_out (vty, " key-string %s%s", key->string, VTY_NEWLINE); if (key->accept.start) { keychain_strftime (buf, BUFSIZ, &key->accept.start); vty_out (vty, " accept-lifetime %s", buf); if (key->accept.end == -1) vty_out (vty, " infinite"); else if (key->accept.duration) vty_out (vty, " duration %ld", key->accept.end - key->accept.start); else { keychain_strftime (buf, BUFSIZ, &key->accept.end); vty_out (vty, " %s", buf); } vty_out (vty, "%s", VTY_NEWLINE); } if (key->send.start) { keychain_strftime (buf, BUFSIZ, &key->send.start); vty_out (vty, " send-lifetime %s", buf); if (key->send.end == -1) vty_out (vty, " infinite"); else if (key->send.duration) vty_out (vty, " duration %ld", key->send.end - key->send.start); else { keychain_strftime (buf, BUFSIZ, &key->send.end); vty_out (vty, " %s", buf); } vty_out (vty, "%s", VTY_NEWLINE); } } vty_out (vty, "!%s", VTY_NEWLINE); } return 0;}voidkeychain_init (){ keychain_list = list_new (); install_node (&keychain_node, keychain_config_write); install_node (&keychain_key_node, NULL); install_default (KEYCHAIN_NODE); install_default (KEYCHAIN_KEY_NODE); install_element (CONFIG_NODE, &key_chain_cmd); install_element (CONFIG_NODE, &no_key_chain_cmd); install_element (KEYCHAIN_NODE, &key_cmd); install_element (KEYCHAIN_NODE, &no_key_cmd); install_element (KEYCHAIN_NODE, &key_chain_cmd); install_element (KEYCHAIN_NODE, &no_key_chain_cmd); install_element (KEYCHAIN_KEY_NODE, &key_string_cmd); install_element (KEYCHAIN_KEY_NODE, &no_key_string_cmd); install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd); install_element (KEYCHAIN_KEY_NODE, &no_key_chain_cmd); install_element (KEYCHAIN_KEY_NODE, &key_cmd); install_element (KEYCHAIN_KEY_NODE, &no_key_cmd); install_element (KEYCHAIN_KEY_NODE, &accept_lifetime_day_month_day_month_cmd); install_element (KEYCHAIN_KEY_NODE, &accept_lifetime_day_month_month_day_cmd); install_element (KEYCHAIN_KEY_NODE, &accept_lifetime_month_day_day_month_cmd); install_element (KEYCHAIN_KEY_NODE, &accept_lifetime_month_day_month_day_cmd); install_element (KEYCHAIN_KEY_NODE, &accept_lifetime_infinite_day_month_cmd); install_element (KEYCHAIN_KEY_NODE, &accept_lifetime_infinite_month_day_cmd); install_element (KEYCHAIN_KEY_NODE, &accept_lifetime_duration_day_month_cmd); install_element (KEYCHAIN_KEY_NODE, &accept_lifetime_duration_month_day_cmd); install_element (KEYCHAIN_KEY_NODE, &send_lifetime_day_month_day_month_cmd); install_element (KEYCHAIN_KEY_NODE, &send_lifetime_day_month_month_day_cmd); install_element (KEYCHAIN_KEY_NODE, &send_lifetime_month_day_day_month_cmd); install_element (KEYCHAIN_KEY_NODE, &send_lifetime_month_day_month_day_cmd); install_element (KEYCHAIN_KEY_NODE, &send_lifetime_infinite_day_month_cmd); install_element (KEYCHAIN_KEY_NODE, &send_lifetime_infinite_month_day_cmd); install_element (KEYCHAIN_KEY_NODE, &send_lifetime_duration_day_month_cmd); install_element (KEYCHAIN_KEY_NODE, &send_lifetime_duration_month_day_cmd);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -