1 /* key-chain for authentication.
2 Copyright (C) 2000 Kunihiro Ishiguro
4 This file is part of GNU Zebra.
6 GNU Zebra is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 2, or (at your
9 option) any later version.
11 GNU Zebra is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Zebra; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
28 DEFINE_MTYPE_STATIC(LIB
, KEY
, "Key")
29 DEFINE_MTYPE_STATIC(LIB
, KEYCHAIN
, "Key chain")
31 DEFINE_QOBJ_TYPE(keychain
)
34 /* Master list of key chain. */
35 struct list
*keychain_list
;
37 static struct keychain
*
40 struct keychain
*keychain
;
41 keychain
= XCALLOC (MTYPE_KEYCHAIN
, sizeof (struct keychain
));
42 QOBJ_REG (keychain
, keychain
);
47 keychain_free (struct keychain
*keychain
)
49 QOBJ_UNREG (keychain
);
50 XFREE (MTYPE_KEYCHAIN
, keychain
);
56 struct key
*key
= XCALLOC (MTYPE_KEY
, sizeof (struct key
));
62 key_free (struct key
*key
)
65 XFREE (MTYPE_KEY
, key
);
69 keychain_lookup (const char *name
)
71 struct listnode
*node
;
72 struct keychain
*keychain
;
77 for (ALL_LIST_ELEMENTS_RO (keychain_list
, node
, keychain
))
79 if (strcmp (keychain
->name
, name
) == 0)
86 key_cmp_func (void *arg1
, void *arg2
)
88 const struct key
*k1
= arg1
;
89 const struct key
*k2
= arg2
;
91 if (k1
->index
> k2
->index
)
93 if (k1
->index
< k2
->index
)
99 key_delete_func (struct key
*key
)
106 static struct keychain
*
107 keychain_get (const char *name
)
109 struct keychain
*keychain
;
111 keychain
= keychain_lookup (name
);
116 keychain
= keychain_new ();
117 keychain
->name
= XSTRDUP(MTYPE_KEYCHAIN
, name
);
118 keychain
->key
= list_new ();
119 keychain
->key
->cmp
= (int (*)(void *, void *)) key_cmp_func
;
120 keychain
->key
->del
= (void (*)(void *)) key_delete_func
;
121 listnode_add (keychain_list
, keychain
);
127 keychain_delete (struct keychain
*keychain
)
130 XFREE(MTYPE_KEYCHAIN
, keychain
->name
);
132 list_delete (keychain
->key
);
133 listnode_delete (keychain_list
, keychain
);
134 keychain_free (keychain
);
138 key_lookup (const struct keychain
*keychain
, u_int32_t index
)
140 struct listnode
*node
;
143 for (ALL_LIST_ELEMENTS_RO (keychain
->key
, node
, key
))
145 if (key
->index
== index
)
152 key_lookup_for_accept (const struct keychain
*keychain
, u_int32_t index
)
154 struct listnode
*node
;
160 for (ALL_LIST_ELEMENTS_RO (keychain
->key
, node
, key
))
162 if (key
->index
>= index
)
164 if (key
->accept
.start
== 0)
167 if (key
->accept
.start
<= now
)
168 if (key
->accept
.end
>= now
|| key
->accept
.end
== -1)
176 key_match_for_accept (const struct keychain
*keychain
, const char *auth_str
)
178 struct listnode
*node
;
184 for (ALL_LIST_ELEMENTS_RO (keychain
->key
, node
, key
))
186 if (key
->accept
.start
== 0 ||
187 (key
->accept
.start
<= now
&&
188 (key
->accept
.end
>= now
|| key
->accept
.end
== -1)))
189 if (strncmp (key
->string
, auth_str
, 16) == 0)
196 key_lookup_for_send (const struct keychain
*keychain
)
198 struct listnode
*node
;
204 for (ALL_LIST_ELEMENTS_RO (keychain
->key
, node
, key
))
206 if (key
->send
.start
== 0)
209 if (key
->send
.start
<= now
)
210 if (key
->send
.end
>= now
|| key
->send
.end
== -1)
217 key_get (const struct keychain
*keychain
, u_int32_t index
)
221 key
= key_lookup (keychain
, index
);
228 listnode_add_sort (keychain
->key
, key
);
234 key_delete (struct keychain
*keychain
, struct key
*key
)
236 listnode_delete (keychain
->key
, key
);
239 XFREE(MTYPE_KEY
, key
->string
);
243 DEFUN_NOSH (key_chain
,
246 "Authentication key management\n"
247 "Key-chain management\n"
251 struct keychain
*keychain
;
253 keychain
= keychain_get (argv
[idx_word
]->arg
);
254 VTY_PUSH_CONTEXT (KEYCHAIN_NODE
, keychain
);
263 "Authentication key management\n"
264 "Key-chain management\n"
268 struct keychain
*keychain
;
270 keychain
= keychain_lookup (argv
[idx_word
]->arg
);
274 vty_out (vty
, "Can't find keychain %s%s", argv
[idx_word
]->arg
, VTY_NEWLINE
);
278 keychain_delete (keychain
);
285 "key (0-2147483647)",
287 "Key identifier number\n")
290 VTY_DECLVAR_CONTEXT (keychain
, keychain
);
294 VTY_GET_INTEGER ("key identifier", index
, argv
[idx_number
]->arg
);
295 key
= key_get (keychain
, index
);
296 VTY_PUSH_CONTEXT_SUB (KEYCHAIN_KEY_NODE
, key
);
303 "no key (0-2147483647)",
306 "Key identifier number\n")
309 VTY_DECLVAR_CONTEXT (keychain
, keychain
);
313 VTY_GET_INTEGER ("key identifier", index
, argv
[idx_number
]->arg
);
314 key
= key_lookup (keychain
, index
);
317 vty_out (vty
, "Can't find key %d%s", index
, VTY_NEWLINE
);
321 key_delete (keychain
, key
);
323 vty
->node
= KEYCHAIN_NODE
;
335 VTY_DECLVAR_CONTEXT_SUB (key
, key
);
338 XFREE(MTYPE_KEY
, key
->string
);
339 key
->string
= XSTRDUP(MTYPE_KEY
, argv
[idx_line
]->arg
);
344 DEFUN (no_key_string
,
346 "no key-string [LINE]",
351 VTY_DECLVAR_CONTEXT_SUB (key
, key
);
355 XFREE(MTYPE_KEY
, key
->string
);
362 /* Convert HH:MM:SS MON DAY YEAR to time_t value. -1 is returned when
363 given string is malformed. */
365 key_str2time (const char *time_str
, const char *day_str
, const char *month_str
,
366 const char *year_str
)
372 unsigned int sec
, min
, hour
;
373 unsigned int day
, month
, year
;
375 const char *month_name
[] =
392 #define _GET_LONG_RANGE(V,STR,MMCOND) \
394 unsigned long tmpl; \
395 char *endptr = NULL; \
396 tmpl = strtoul ((STR), &endptr, 10); \
397 if (*endptr != '\0' || tmpl == ULONG_MAX) \
403 #define GET_LONG_RANGE(V,STR,MIN,MAX) \
404 _GET_LONG_RANGE(V,STR,tmpl < (MIN) || tmpl > (MAX))
405 #define GET_LONG_RANGE0(V,STR,MAX) \
406 _GET_LONG_RANGE(V,STR,tmpl > (MAX))
408 /* Check hour field of time_str. */
409 colon
= strchr (time_str
, ':');
414 /* Hour must be between 0 and 23. */
415 GET_LONG_RANGE0 (hour
, time_str
, 23);
417 /* Check min field of time_str. */
418 time_str
= colon
+ 1;
419 colon
= strchr (time_str
, ':');
420 if (*time_str
== '\0' || colon
== NULL
)
424 /* Min must be between 0 and 59. */
425 GET_LONG_RANGE0 (min
, time_str
, 59);
427 /* Check sec field of time_str. */
428 time_str
= colon
+ 1;
429 if (*time_str
== '\0')
432 /* Sec must be between 0 and 59. */
433 GET_LONG_RANGE0 (sec
, time_str
, 59);
435 /* Check day_str. Day must be <1-31>. */
436 GET_LONG_RANGE (day
, day_str
, 1, 31);
438 /* Check month_str. Month must match month_name. */
440 if (strlen (month_str
) >= 3)
441 for (i
= 0; month_name
[i
]; i
++)
442 if (strncmp (month_str
, month_name
[i
], strlen (month_str
)) == 0)
450 /* Check year_str. Year must be <1993-2035>. */
451 GET_LONG_RANGE (year
, year_str
, 1993, 2035);
453 memset (&tm
, 0, sizeof (struct tm
));
459 tm
.tm_year
= year
- 1900;
464 #undef GET_LONG_RANGE
468 key_lifetime_set (struct vty
*vty
, struct key_range
*krange
,
469 const char *stime_str
, const char *sday_str
,
470 const char *smonth_str
, const char *syear_str
,
471 const char *etime_str
, const char *eday_str
,
472 const char *emonth_str
, const char *eyear_str
)
477 time_start
= key_str2time (stime_str
, sday_str
, smonth_str
, syear_str
);
480 vty_out (vty
, "Malformed time value%s", VTY_NEWLINE
);
483 time_end
= key_str2time (etime_str
, eday_str
, emonth_str
, eyear_str
);
487 vty_out (vty
, "Malformed time value%s", VTY_NEWLINE
);
491 if (time_end
<= time_start
)
493 vty_out (vty
, "Expire time is not later than start time%s", VTY_NEWLINE
);
497 krange
->start
= time_start
;
498 krange
->end
= time_end
;
504 key_lifetime_duration_set (struct vty
*vty
, struct key_range
*krange
,
505 const char *stime_str
, const char *sday_str
,
506 const char *smonth_str
, const char *syear_str
,
507 const char *duration_str
)
512 time_start
= key_str2time (stime_str
, sday_str
, smonth_str
, syear_str
);
515 vty_out (vty
, "Malformed time value%s", VTY_NEWLINE
);
518 krange
->start
= time_start
;
520 VTY_GET_INTEGER ("duration", duration
, duration_str
);
521 krange
->duration
= 1;
522 krange
->end
= time_start
+ duration
;
528 key_lifetime_infinite_set (struct vty
*vty
, struct key_range
*krange
,
529 const char *stime_str
, const char *sday_str
,
530 const char *smonth_str
, const char *syear_str
)
534 time_start
= key_str2time (stime_str
, sday_str
, smonth_str
, syear_str
);
537 vty_out (vty
, "Malformed time value%s", VTY_NEWLINE
);
540 krange
->start
= time_start
;
547 DEFUN (accept_lifetime_day_month_day_month
,
548 accept_lifetime_day_month_day_month_cmd
,
549 "accept-lifetime HH:MM:SS (1-31) MONTH (1993-2035) HH:MM:SS (1-31) MONTH (1993-2035)",
550 "Set accept lifetime of the key\n"
552 "Day of th month to start\n"
553 "Month of the year to start\n"
556 "Day of th month to expire\n"
557 "Month of the year to expire\n"
563 int idx_number_2
= 4;
564 int idx_hhmmss_2
= 5;
565 int idx_number_3
= 6;
567 int idx_number_4
= 8;
568 VTY_DECLVAR_CONTEXT_SUB (key
, key
);
570 return key_lifetime_set (vty
, &key
->accept
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
, argv
[idx_month
]->arg
,
571 argv
[idx_number_2
]->arg
, argv
[idx_hhmmss_2
]->arg
, argv
[idx_number_3
]->arg
, argv
[idx_month_2
]->arg
, argv
[idx_number_4
]->arg
);
574 DEFUN (accept_lifetime_day_month_month_day
,
575 accept_lifetime_day_month_month_day_cmd
,
576 "accept-lifetime HH:MM:SS (1-31) MONTH (1993-2035) HH:MM:SS MONTH (1-31) (1993-2035)",
577 "Set accept lifetime of the key\n"
579 "Day of th month to start\n"
580 "Month of the year to start\n"
583 "Month of the year to expire\n"
584 "Day of th month to expire\n"
590 int idx_number_2
= 4;
591 int idx_hhmmss_2
= 5;
593 int idx_number_3
= 7;
594 int idx_number_4
= 8;
595 VTY_DECLVAR_CONTEXT_SUB (key
, key
);
597 return key_lifetime_set (vty
, &key
->accept
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
, argv
[idx_month
]->arg
,
598 argv
[idx_number_2
]->arg
, argv
[idx_hhmmss_2
]->arg
, argv
[idx_number_3
]->arg
, argv
[idx_month_2
]->arg
, argv
[idx_number_4
]->arg
);
601 DEFUN (accept_lifetime_month_day_day_month
,
602 accept_lifetime_month_day_day_month_cmd
,
603 "accept-lifetime HH:MM:SS MONTH (1-31) (1993-2035) HH:MM:SS (1-31) MONTH (1993-2035)",
604 "Set accept lifetime of the key\n"
606 "Month of the year to start\n"
607 "Day of th month to start\n"
610 "Day of th month to expire\n"
611 "Month of the year to expire\n"
617 int idx_number_2
= 4;
618 int idx_hhmmss_2
= 5;
619 int idx_number_3
= 6;
621 int idx_number_4
= 8;
622 VTY_DECLVAR_CONTEXT_SUB (key
, key
);
624 return key_lifetime_set (vty
, &key
->accept
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
, argv
[idx_month
]->arg
,
625 argv
[idx_number_2
]->arg
, argv
[idx_hhmmss_2
]->arg
, argv
[idx_number_3
]->arg
, argv
[idx_month_2
]->arg
, argv
[idx_number_4
]->arg
);
628 DEFUN (accept_lifetime_month_day_month_day
,
629 accept_lifetime_month_day_month_day_cmd
,
630 "accept-lifetime HH:MM:SS MONTH (1-31) (1993-2035) HH:MM:SS MONTH (1-31) (1993-2035)",
631 "Set accept lifetime of the key\n"
633 "Month of the year to start\n"
634 "Day of th month to start\n"
637 "Month of the year to expire\n"
638 "Day of th month to expire\n"
644 int idx_number_2
= 4;
645 int idx_hhmmss_2
= 5;
647 int idx_number_3
= 7;
648 int idx_number_4
= 8;
649 VTY_DECLVAR_CONTEXT_SUB (key
, key
);
651 return key_lifetime_set (vty
, &key
->accept
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
, argv
[idx_month
]->arg
,
652 argv
[idx_number_2
]->arg
, argv
[idx_hhmmss_2
]->arg
, argv
[idx_number_3
]->arg
, argv
[idx_month_2
]->arg
, argv
[idx_number_4
]->arg
);
655 DEFUN (accept_lifetime_infinite_day_month
,
656 accept_lifetime_infinite_day_month_cmd
,
657 "accept-lifetime HH:MM:SS (1-31) MONTH (1993-2035) infinite",
658 "Set accept lifetime of the key\n"
660 "Day of th month to start\n"
661 "Month of the year to start\n"
668 int idx_number_2
= 4;
669 VTY_DECLVAR_CONTEXT_SUB (key
, key
);
671 return key_lifetime_infinite_set (vty
, &key
->accept
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
,
672 argv
[idx_month
]->arg
, argv
[idx_number_2
]->arg
);
675 DEFUN (accept_lifetime_infinite_month_day
,
676 accept_lifetime_infinite_month_day_cmd
,
677 "accept-lifetime HH:MM:SS MONTH (1-31) (1993-2035) infinite",
678 "Set accept lifetime of the key\n"
680 "Month of the year to start\n"
681 "Day of th month to start\n"
688 int idx_number_2
= 4;
689 VTY_DECLVAR_CONTEXT_SUB (key
, key
);
691 return key_lifetime_infinite_set (vty
, &key
->accept
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
,
692 argv
[idx_month
]->arg
, argv
[idx_number_2
]->arg
);
695 DEFUN (accept_lifetime_duration_day_month
,
696 accept_lifetime_duration_day_month_cmd
,
697 "accept-lifetime HH:MM:SS (1-31) MONTH (1993-2035) duration (1-2147483646)",
698 "Set accept lifetime of the key\n"
700 "Day of th month to start\n"
701 "Month of the year to start\n"
703 "Duration of the key\n"
704 "Duration seconds\n")
709 int idx_number_2
= 4;
710 int idx_number_3
= 6;
711 VTY_DECLVAR_CONTEXT_SUB (key
, key
);
713 return key_lifetime_duration_set (vty
, &key
->accept
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
,
714 argv
[idx_month
]->arg
, argv
[idx_number_2
]->arg
, argv
[idx_number_3
]->arg
);
717 DEFUN (accept_lifetime_duration_month_day
,
718 accept_lifetime_duration_month_day_cmd
,
719 "accept-lifetime HH:MM:SS MONTH (1-31) (1993-2035) duration (1-2147483646)",
720 "Set accept lifetime of the key\n"
722 "Month of the year to start\n"
723 "Day of th month to start\n"
725 "Duration of the key\n"
726 "Duration seconds\n")
731 int idx_number_2
= 4;
732 int idx_number_3
= 6;
733 VTY_DECLVAR_CONTEXT_SUB (key
, key
);
735 return key_lifetime_duration_set (vty
, &key
->accept
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
,
736 argv
[idx_month
]->arg
, argv
[idx_number_2
]->arg
, argv
[idx_number_3
]->arg
);
739 DEFUN (send_lifetime_day_month_day_month
,
740 send_lifetime_day_month_day_month_cmd
,
741 "send-lifetime HH:MM:SS (1-31) MONTH (1993-2035) HH:MM:SS (1-31) MONTH (1993-2035)",
742 "Set send lifetime of the key\n"
744 "Day of th month to start\n"
745 "Month of the year to start\n"
748 "Day of th month to expire\n"
749 "Month of the year to expire\n"
755 int idx_number_2
= 4;
756 int idx_hhmmss_2
= 5;
757 int idx_number_3
= 6;
759 int idx_number_4
= 8;
760 VTY_DECLVAR_CONTEXT_SUB (key
, key
);
762 return key_lifetime_set (vty
, &key
->send
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
, argv
[idx_month
]->arg
, argv
[idx_number_2
]->arg
,
763 argv
[idx_hhmmss_2
]->arg
, argv
[idx_number_3
]->arg
, argv
[idx_month_2
]->arg
, argv
[idx_number_4
]->arg
);
766 DEFUN (send_lifetime_day_month_month_day
,
767 send_lifetime_day_month_month_day_cmd
,
768 "send-lifetime HH:MM:SS (1-31) MONTH (1993-2035) HH:MM:SS MONTH (1-31) (1993-2035)",
769 "Set send lifetime of the key\n"
771 "Day of th month to start\n"
772 "Month of the year to start\n"
775 "Month of the year to expire\n"
776 "Day of th month to expire\n"
782 int idx_number_2
= 4;
783 int idx_hhmmss_2
= 5;
785 int idx_number_3
= 7;
786 int idx_number_4
= 8;
787 VTY_DECLVAR_CONTEXT_SUB (key
, key
);
789 return key_lifetime_set (vty
, &key
->send
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
, argv
[idx_month
]->arg
, argv
[idx_number_2
]->arg
,
790 argv
[idx_hhmmss_2
]->arg
, argv
[idx_number_3
]->arg
, argv
[idx_month_2
]->arg
, argv
[idx_number_4
]->arg
);
793 DEFUN (send_lifetime_month_day_day_month
,
794 send_lifetime_month_day_day_month_cmd
,
795 "send-lifetime HH:MM:SS MONTH (1-31) (1993-2035) HH:MM:SS (1-31) MONTH (1993-2035)",
796 "Set send lifetime of the key\n"
798 "Month of the year to start\n"
799 "Day of th month to start\n"
802 "Day of th month to expire\n"
803 "Month of the year to expire\n"
809 int idx_number_2
= 4;
810 int idx_hhmmss_2
= 5;
811 int idx_number_3
= 6;
813 int idx_number_4
= 8;
814 VTY_DECLVAR_CONTEXT_SUB (key
, key
);
816 return key_lifetime_set (vty
, &key
->send
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
, argv
[idx_month
]->arg
, argv
[idx_number_2
]->arg
,
817 argv
[idx_hhmmss_2
]->arg
, argv
[idx_number_3
]->arg
, argv
[idx_month_2
]->arg
, argv
[idx_number_4
]->arg
);
820 DEFUN (send_lifetime_month_day_month_day
,
821 send_lifetime_month_day_month_day_cmd
,
822 "send-lifetime HH:MM:SS MONTH (1-31) (1993-2035) HH:MM:SS MONTH (1-31) (1993-2035)",
823 "Set send lifetime of the key\n"
825 "Month of the year to start\n"
826 "Day of th month to start\n"
829 "Month of the year to expire\n"
830 "Day of th month to expire\n"
836 int idx_number_2
= 4;
837 int idx_hhmmss_2
= 5;
839 int idx_number_3
= 7;
840 int idx_number_4
= 8;
841 VTY_DECLVAR_CONTEXT_SUB (key
, key
);
843 return key_lifetime_set (vty
, &key
->send
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
, argv
[idx_month
]->arg
, argv
[idx_number_2
]->arg
,
844 argv
[idx_hhmmss_2
]->arg
, argv
[idx_number_3
]->arg
, argv
[idx_month_2
]->arg
, argv
[idx_number_4
]->arg
);
847 DEFUN (send_lifetime_infinite_day_month
,
848 send_lifetime_infinite_day_month_cmd
,
849 "send-lifetime HH:MM:SS (1-31) MONTH (1993-2035) infinite",
850 "Set send lifetime of the key\n"
852 "Day of th month to start\n"
853 "Month of the year to start\n"
860 int idx_number_2
= 4;
861 VTY_DECLVAR_CONTEXT_SUB (key
, key
);
863 return key_lifetime_infinite_set (vty
, &key
->send
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
, argv
[idx_month
]->arg
,
864 argv
[idx_number_2
]->arg
);
867 DEFUN (send_lifetime_infinite_month_day
,
868 send_lifetime_infinite_month_day_cmd
,
869 "send-lifetime HH:MM:SS MONTH (1-31) (1993-2035) infinite",
870 "Set send lifetime of the key\n"
872 "Month of the year to start\n"
873 "Day of th month to start\n"
880 int idx_number_2
= 4;
881 VTY_DECLVAR_CONTEXT_SUB (key
, key
);
883 return key_lifetime_infinite_set (vty
, &key
->send
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
, argv
[idx_month
]->arg
,
884 argv
[idx_number_2
]->arg
);
887 DEFUN (send_lifetime_duration_day_month
,
888 send_lifetime_duration_day_month_cmd
,
889 "send-lifetime HH:MM:SS (1-31) MONTH (1993-2035) duration (1-2147483646)",
890 "Set send lifetime of the key\n"
892 "Day of th month to start\n"
893 "Month of the year to start\n"
895 "Duration of the key\n"
896 "Duration seconds\n")
901 int idx_number_2
= 4;
902 int idx_number_3
= 6;
903 VTY_DECLVAR_CONTEXT_SUB (key
, key
);
905 return key_lifetime_duration_set (vty
, &key
->send
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
, argv
[idx_month
]->arg
,
906 argv
[idx_number_2
]->arg
, argv
[idx_number_3
]->arg
);
909 DEFUN (send_lifetime_duration_month_day
,
910 send_lifetime_duration_month_day_cmd
,
911 "send-lifetime HH:MM:SS MONTH (1-31) (1993-2035) duration (1-2147483646)",
912 "Set send lifetime of the key\n"
914 "Month of the year to start\n"
915 "Day of th month to start\n"
917 "Duration of the key\n"
918 "Duration seconds\n")
923 int idx_number_2
= 4;
924 int idx_number_3
= 6;
925 VTY_DECLVAR_CONTEXT_SUB (key
, key
);
927 return key_lifetime_duration_set (vty
, &key
->send
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
, argv
[idx_month
]->arg
,
928 argv
[idx_number_2
]->arg
, argv
[idx_number_3
]->arg
);
931 static struct cmd_node keychain_node
=
934 "%s(config-keychain)# ",
938 static struct cmd_node keychain_key_node
=
941 "%s(config-keychain-key)# ",
946 keychain_strftime (char *buf
, int bufsiz
, time_t *time
)
951 tm
= localtime (time
);
953 len
= strftime (buf
, bufsiz
, "%T %b %d %Y", tm
);
959 keychain_config_write (struct vty
*vty
)
961 struct keychain
*keychain
;
963 struct listnode
*node
;
964 struct listnode
*knode
;
967 for (ALL_LIST_ELEMENTS_RO (keychain_list
, node
, keychain
))
969 vty_out (vty
, "key chain %s%s", keychain
->name
, VTY_NEWLINE
);
971 for (ALL_LIST_ELEMENTS_RO (keychain
->key
, knode
, key
))
973 vty_out (vty
, " key %d%s", key
->index
, VTY_NEWLINE
);
976 vty_out (vty
, " key-string %s%s", key
->string
, VTY_NEWLINE
);
978 if (key
->accept
.start
)
980 keychain_strftime (buf
, BUFSIZ
, &key
->accept
.start
);
981 vty_out (vty
, " accept-lifetime %s", buf
);
983 if (key
->accept
.end
== -1)
984 vty_out (vty
, " infinite");
985 else if (key
->accept
.duration
)
986 vty_out (vty
, " duration %ld",
987 (long)(key
->accept
.end
- key
->accept
.start
));
990 keychain_strftime (buf
, BUFSIZ
, &key
->accept
.end
);
991 vty_out (vty
, " %s", buf
);
993 vty_out (vty
, "%s", VTY_NEWLINE
);
998 keychain_strftime (buf
, BUFSIZ
, &key
->send
.start
);
999 vty_out (vty
, " send-lifetime %s", buf
);
1001 if (key
->send
.end
== -1)
1002 vty_out (vty
, " infinite");
1003 else if (key
->send
.duration
)
1004 vty_out (vty
, " duration %ld", (long)(key
->send
.end
- key
->send
.start
));
1007 keychain_strftime (buf
, BUFSIZ
, &key
->send
.end
);
1008 vty_out (vty
, " %s", buf
);
1010 vty_out (vty
, "%s", VTY_NEWLINE
);
1013 vty_out (vty
, "!%s", VTY_NEWLINE
);
1022 keychain_list
= list_new ();
1024 install_node (&keychain_node
, keychain_config_write
);
1025 install_node (&keychain_key_node
, NULL
);
1027 install_default (KEYCHAIN_NODE
);
1028 install_default (KEYCHAIN_KEY_NODE
);
1030 install_element (CONFIG_NODE
, &key_chain_cmd
);
1031 install_element (CONFIG_NODE
, &no_key_chain_cmd
);
1032 install_element (KEYCHAIN_NODE
, &key_cmd
);
1033 install_element (KEYCHAIN_NODE
, &no_key_cmd
);
1035 install_element (KEYCHAIN_NODE
, &key_chain_cmd
);
1036 install_element (KEYCHAIN_NODE
, &no_key_chain_cmd
);
1038 install_element (KEYCHAIN_KEY_NODE
, &key_string_cmd
);
1039 install_element (KEYCHAIN_KEY_NODE
, &no_key_string_cmd
);
1041 install_element (KEYCHAIN_KEY_NODE
, &key_chain_cmd
);
1042 install_element (KEYCHAIN_KEY_NODE
, &no_key_chain_cmd
);
1044 install_element (KEYCHAIN_KEY_NODE
, &key_cmd
);
1045 install_element (KEYCHAIN_KEY_NODE
, &no_key_cmd
);
1047 install_element (KEYCHAIN_KEY_NODE
, &accept_lifetime_day_month_day_month_cmd
);
1048 install_element (KEYCHAIN_KEY_NODE
, &accept_lifetime_day_month_month_day_cmd
);
1049 install_element (KEYCHAIN_KEY_NODE
, &accept_lifetime_month_day_day_month_cmd
);
1050 install_element (KEYCHAIN_KEY_NODE
, &accept_lifetime_month_day_month_day_cmd
);
1051 install_element (KEYCHAIN_KEY_NODE
, &accept_lifetime_infinite_day_month_cmd
);
1052 install_element (KEYCHAIN_KEY_NODE
, &accept_lifetime_infinite_month_day_cmd
);
1053 install_element (KEYCHAIN_KEY_NODE
, &accept_lifetime_duration_day_month_cmd
);
1054 install_element (KEYCHAIN_KEY_NODE
, &accept_lifetime_duration_month_day_cmd
);
1056 install_element (KEYCHAIN_KEY_NODE
, &send_lifetime_day_month_day_month_cmd
);
1057 install_element (KEYCHAIN_KEY_NODE
, &send_lifetime_day_month_month_day_cmd
);
1058 install_element (KEYCHAIN_KEY_NODE
, &send_lifetime_month_day_day_month_cmd
);
1059 install_element (KEYCHAIN_KEY_NODE
, &send_lifetime_month_day_month_day_cmd
);
1060 install_element (KEYCHAIN_KEY_NODE
, &send_lifetime_infinite_day_month_cmd
);
1061 install_element (KEYCHAIN_KEY_NODE
, &send_lifetime_infinite_month_day_cmd
);
1062 install_element (KEYCHAIN_KEY_NODE
, &send_lifetime_duration_day_month_cmd
);
1063 install_element (KEYCHAIN_KEY_NODE
, &send_lifetime_duration_month_day_cmd
);