From d2519962b71b512eb5fd55a378f8ef748d17c30f Mon Sep 17 00:00:00 2001 From: Paul Jakma Date: Fri, 12 May 2006 23:19:37 +0000 Subject: [lib] CID #37, fix error case leak, cmd_complete_command_real 2006-05-12 Paul Jakma * command.c: (cmd_complete_command_real) Fix leak of cmd_vector in error case, Coverity CID #37. --- lib/command.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/command.c') diff --git a/lib/command.c b/lib/command.c index ac3516c3..1c277b38 100644 --- a/lib/command.c +++ b/lib/command.c @@ -1,5 +1,5 @@ /* - $Id: command.c,v 1.51 2005/10/26 05:49:54 paul Exp $ + $Id: command.c,v 1.52 2006/05/12 23:19:37 paul Exp $ Command interpreter routine for virtual terminal [aka TeletYpe] Copyright (C) 1997, 98, 99 Kunihiro Ishiguro @@ -1785,6 +1785,7 @@ cmd_complete_command_real (vector vline, struct vty *vty, int *status) if (vector_active (vline) == 0) { + vector_free (cmd_vector); *status = CMD_ERR_NO_MATCH; return NULL; } -- cgit v1.2.3 From 5fc60519ede0d34688832e353c35bf1832a4330d Mon Sep 17 00:00:00 2001 From: Paul Jakma Date: Fri, 12 May 2006 23:24:09 +0000 Subject: [lib] CID #55, fix return of freed pointer, cmd_describe_command_real 2006-05-12 Paul Jakma * command.c: (cmd_describe_command_real) Fix return of freed pointer when no-match, CID #55. --- lib/command.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/command.c') diff --git a/lib/command.c b/lib/command.c index 1c277b38..07297eff 100644 --- a/lib/command.c +++ b/lib/command.c @@ -1,5 +1,5 @@ /* - $Id: command.c,v 1.52 2006/05/12 23:19:37 paul Exp $ + $Id: command.c,v 1.53 2006/05/12 23:24:09 paul Exp $ Command interpreter routine for virtual terminal [aka TeletYpe] Copyright (C) 1997, 98, 99 Kunihiro Ishiguro @@ -1693,10 +1693,10 @@ cmd_describe_command_real (vector vline, struct vty *vty, int *status) { vector_free (matchvec); *status = CMD_ERR_NO_MATCH; + return NULL; } - else - *status = CMD_SUCCESS; + *status = CMD_SUCCESS; return matchvec; } -- cgit v1.2.3 From e5cd706c1a4b8138e9b78933e03460f0b032c77e Mon Sep 17 00:00:00 2001 From: Paul Jakma Date: Thu, 15 Jun 2006 12:25:55 +0000 Subject: [lib] Fix vector leak in error path in command.c, CID #38 2006-06-15 Paul Jakma * command.c: (cmd_describe_command_real) Fix leak, CID #38. --- lib/command.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/command.c') diff --git a/lib/command.c b/lib/command.c index 07297eff..316971e4 100644 --- a/lib/command.c +++ b/lib/command.c @@ -1,5 +1,5 @@ /* - $Id: command.c,v 1.53 2006/05/12 23:24:09 paul Exp $ + $Id$ Command interpreter routine for virtual terminal [aka TeletYpe] Copyright (C) 1997, 98, 99 Kunihiro Ishiguro @@ -1629,12 +1629,14 @@ cmd_describe_command_real (vector vline, struct vty *vty, int *status) if ((ret = is_cmd_ambiguous (command, cmd_vector, i, match)) == 1) { vector_free (cmd_vector); + vector_free (matchvec); *status = CMD_ERR_AMBIGUOUS; return NULL; } else if (ret == 2) { vector_free (cmd_vector); + vector_free (matchvec); *status = CMD_ERR_NO_MATCH; return NULL; } -- cgit v1.2.3 From 1ed72e0b3a643fa1be6f1efa904965798a575cd1 Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Sat, 28 Apr 2007 22:14:10 +0000 Subject: [logging] Add new "log timestamp precision" command for subsecond timestamps 2007-04-28 Andrew J. Schorr * command.c: (config_write_host) Save "log timestamp precision" if not default value. (show_logging) Show configured timestamp precision. (config_log_timestamp_precision) Enable configuration of timestamp precision. (no_config_log_timestamp_precision) Restore default timestamp precision. (cmd_init) Install new timestamp precision commands. * log.h: (struct zlog) New timestamp_precision field. (quagga_timestamp) New function to generate a timestamp with the desired precision. (struct timestamp_control) Declare a structure for use in avoiding repeated duplicate calls to quagga_timestamp. * log.c: (quagga_timestamp) New function to generate a timestamp of the desired precision. (time_print) Call quagga_timestamp if the time hasn't already been calculated. (vzlog) Initialize a timestamp_control structure and pass it to time_print and vty_log. (zlog_backtrace) Fix 64-bit problem: cannot print size_t with %u. * vty.h: Must now include "log.h". (vty_log) Takes an additional struct timestamp_control argument. * vty.c: (vty_log_out) Use new struct timestamp_control and new quagga_timestamp function to print timestamps of the desired precision. (vty_time_print) Use new quagga_timestamp function. (vty_log) Accept new struct timestamp_control argument and pass it down to vty_log_out. --- lib/command.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'lib/command.c') diff --git a/lib/command.c b/lib/command.c index 316971e4..f3d96ede 100644 --- a/lib/command.c +++ b/lib/command.c @@ -594,6 +594,10 @@ config_write_host (struct vty *vty) if (zlog_default->record_priority == 1) vty_out (vty, "log record-priority%s", VTY_NEWLINE); + if (zlog_default->timestamp_precision > 0) + vty_out (vty, "log timestamp precision %d%s", + zlog_default->timestamp_precision, VTY_NEWLINE); + if (host.advanced) vty_out (vty, "service advanced-vty%s", VTY_NEWLINE); @@ -3092,6 +3096,8 @@ DEFUN (show_logging, zlog_proto_names[zl->protocol], VTY_NEWLINE); vty_out (vty, "Record priority: %s%s", (zl->record_priority ? "enabled" : "disabled"), VTY_NEWLINE); + vty_out (vty, "Timestamp precision: %d%s", + zl->timestamp_precision, VTY_NEWLINE); return CMD_SUCCESS; } @@ -3416,6 +3422,37 @@ DEFUN (no_config_log_record_priority, return CMD_SUCCESS; } +DEFUN (config_log_timestamp_precision, + config_log_timestamp_precision_cmd, + "log timestamp precision <0-6>", + "Logging control\n" + "Timestamp configuration\n" + "Set the timestamp precision\n" + "Number of subsecond digits\n") +{ + if (argc != 1) + { + vty_out (vty, "Insufficient arguments%s", VTY_NEWLINE); + return CMD_WARNING; + } + + VTY_GET_INTEGER_RANGE("Timestamp Precision", + zlog_default->timestamp_precision, argv[0], 0, 6); + return CMD_SUCCESS; +} + +DEFUN (no_config_log_timestamp_precision, + no_config_log_timestamp_precision_cmd, + "no log timestamp precision", + NO_STR + "Logging control\n" + "Timestamp configuration\n" + "Reset the timestamp precision to the default value of 0\n") +{ + zlog_default->timestamp_precision = 0 ; + return CMD_SUCCESS; +} + DEFUN (banner_motd_file, banner_motd_file_cmd, "banner motd file [FILE]", @@ -3571,6 +3608,8 @@ cmd_init (int terminal) install_element (CONFIG_NODE, &no_config_log_trap_cmd); install_element (CONFIG_NODE, &config_log_record_priority_cmd); install_element (CONFIG_NODE, &no_config_log_record_priority_cmd); + install_element (CONFIG_NODE, &config_log_timestamp_precision_cmd); + install_element (CONFIG_NODE, &no_config_log_timestamp_precision_cmd); install_element (CONFIG_NODE, &service_password_encrypt_cmd); install_element (CONFIG_NODE, &no_service_password_encrypt_cmd); install_element (CONFIG_NODE, &banner_motd_default_cmd); -- cgit v1.2.3 From 62687ff1cd3d4460cdbd4b0fbf1e3298fe277ad2 Mon Sep 17 00:00:00 2001 From: Paul Jakma Date: Sat, 23 Aug 2008 14:27:06 +0100 Subject: [vty] Add support for a 'restricted mode' with anonymous vty connections * lib/command.h: Add a RESTRICTED_NODE, intended for use with anonymous, 'no login' vtys, to provide a subset of 'view' mode commands. * lib/command.c: Add RESTRICTED_NODE bits, nothing special, just following VIEW_NODE. * lib/vty.c: (vty_auth) enable authentication should fall back to restricted/view node as appropriate. (vty_create) init vty's to restricted/view node as appropriate, for the 'no login' case. (vty_{no_,}restricted_mode_cmd) config commands to enable 'anonymous restricted' in vty configuration. (vty_config_write) 'anonymous restricted' config. (vty_init) Install some commands to restricted mode, and the 'anonymous restricted' config commands into VTY_NODE. * bgpd/*.c: Install some of the safe(r) BGP commands into 'restricted mode', i.e. lookup commands of non-sensitive data. Useful with looking-glass route-servers. --- lib/command.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'lib/command.c') diff --git a/lib/command.c b/lib/command.c index f3d96ede..4887f94f 100644 --- a/lib/command.c +++ b/lib/command.c @@ -53,6 +53,12 @@ struct cmd_node view_node = "%s> ", }; +struct cmd_node restricted_node = +{ + RESTRICTED_NODE, + "%s$ ", +}; + struct cmd_node auth_enable_node = { AUTH_ENABLE_NODE, @@ -1563,6 +1569,7 @@ cmd_try_do_shortcut (enum node_type node, char* first_word) { node != VIEW_NODE && node != AUTH_ENABLE_NODE && node != ENABLE_NODE && + node != RESTRICTED_NODE && 0 == strcmp( "do", first_word ) ) return 1; return 0; @@ -2376,6 +2383,7 @@ DEFUN (config_exit, { case VIEW_NODE: case ENABLE_NODE: + case RESTRICTED_NODE: if (vty_shell (vty)) exit (0); else @@ -2431,6 +2439,7 @@ DEFUN (config_end, { case VIEW_NODE: case ENABLE_NODE: + case RESTRICTED_NODE: /* Nothing to do. */ break; case CONFIG_NODE: @@ -3538,6 +3547,7 @@ cmd_init (int terminal) install_node (&enable_node, NULL); install_node (&auth_node, NULL); install_node (&auth_enable_node, NULL); + install_node (&restricted_node, NULL); install_node (&config_node, config_write_host); /* Each node's basic commands. */ @@ -3553,6 +3563,15 @@ cmd_init (int terminal) install_element (VIEW_NODE, &config_terminal_no_length_cmd); install_element (VIEW_NODE, &show_logging_cmd); install_element (VIEW_NODE, &echo_cmd); + + install_element (RESTRICTED_NODE, &config_list_cmd); + install_element (RESTRICTED_NODE, &config_exit_cmd); + install_element (RESTRICTED_NODE, &config_quit_cmd); + install_element (RESTRICTED_NODE, &config_help_cmd); + install_element (RESTRICTED_NODE, &config_enable_cmd); + install_element (RESTRICTED_NODE, &config_terminal_length_cmd); + install_element (RESTRICTED_NODE, &config_terminal_no_length_cmd); + install_element (RESTRICTED_NODE, &echo_cmd); } if (terminal) @@ -3620,6 +3639,7 @@ cmd_init (int terminal) install_element (VIEW_NODE, &show_thread_cpu_cmd); install_element (ENABLE_NODE, &show_thread_cpu_cmd); + install_element (RESTRICTED_NODE, &show_thread_cpu_cmd); install_element (VIEW_NODE, &show_work_queues_cmd); install_element (ENABLE_NODE, &show_work_queues_cmd); } -- cgit v1.2.3