More vtysh fixes. Specifying configuration from command line works now.

This commit is contained in:
hasso 2004-08-26 22:21:31 +00:00
parent 9a0962651b
commit 67e29abc58
7 changed files with 53 additions and 38 deletions

View File

@ -1,3 +1,7 @@
2004-08-27 Hasso Tepper <hasso at quagga.net>
* Update vtysh man page to reflect changes in shell.
2004-08-10 Hasso Tepper <hasso at quagga.net> 2004-08-10 Hasso Tepper <hasso at quagga.net>
* Updated man pages. * Updated man pages.

View File

@ -1,14 +1,22 @@
.TH VTYSH 1 "10 August 2004" "Quagga VTY shell" "Version 0.96.5" .TH VTYSH 1 "27 August 2004" "Quagga VTY shell" "Version 0.96.5"
.SH NAME .SH NAME
vtysh \- a integrated shell for Quagga routing software vtysh \- a integrated shell for Quagga routing software
.SH SYNOPSIS .SH SYNOPSIS
.B vtysh .B vtysh
[ [
.B \-f
.I config-file
]
[
.B \-b .B \-b
] ]
.br .br
.B vtysh .B vtysh
[ [
.B \-f
.I config-file
]
[
.B \-c .B \-c
.I command .I command
] ]
@ -34,8 +42,11 @@ is executed and vtysh exits.
It's useful for gathering info from Quagga routing software from shell scripts It's useful for gathering info from Quagga routing software from shell scripts
etc. etc.
.IP "\fB\-e, \-\-execute \fIcommand\fP" .IP "\fB\-e, \-\-execute \fIcommand\fP"
Alias for -c. It's only for compatibility with Zebra routing software and older Alias for -c. It's here only for compatibility with Zebra routing software and
Quagga versions and this might be removed in future. older Quagga versions. This will be removed in future.
.IP "\fB\-f, \-\-config-file \fIconfig-file\fP"
Specifies the config file to use for startup. If not specified this option will
likely default to \fB\fI/usr/local/etc/vtysh.conf\fR.
.IP "\fB\-h, \-\-help\fP" .IP "\fB\-h, \-\-help\fP"
Display a usage message on standard output and exit. Display a usage message on standard output and exit.
.SH ENVIRONMENT VARIABLES .SH ENVIRONMENT VARIABLES

View File

@ -1,4 +1,13 @@
2004-08-26 Hasso Tepper <hasso@estpak.ee> 2004-08-27 Hasso Tepper <hasso at quagga.net>
* vtysh.c: Enable using ssh from ENABLE_NODE.
* vtysh_config.c: Make enable password uniq lines appear only once in
configuration.
* vtysh_main.c, vtysh_config.c, vtysh.h: Remove useless code which
searched configuration files from current directory. Add -f to
specify conf from command line.
2004-08-26 Hasso Tepper <hasso at quagga.net>
* *.c: Cosmetical changes - strip long lines, fix multiline comments * *.c: Cosmetical changes - strip long lines, fix multiline comments
style, indentation fixes, remove useless comments. style, indentation fixes, remove useless comments.

View File

@ -1999,6 +1999,7 @@ vtysh_init_vty ()
#endif #endif
install_element (ENABLE_NODE, &vtysh_telnet_cmd); install_element (ENABLE_NODE, &vtysh_telnet_cmd);
install_element (ENABLE_NODE, &vtysh_telnet_port_cmd); install_element (ENABLE_NODE, &vtysh_telnet_port_cmd);
install_element (ENABLE_NODE, &vtysh_ssh_cmd);
install_element (ENABLE_NODE, &vtysh_start_shell_cmd); install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
install_element (ENABLE_NODE, &vtysh_start_bash_cmd); install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
install_element (ENABLE_NODE, &vtysh_start_zsh_cmd); install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);

View File

@ -60,7 +60,7 @@ void vtysh_config_write ();
int vtysh_config_from_file (struct vty *, FILE *); int vtysh_config_from_file (struct vty *, FILE *);
void vtysh_read_config (char *, char *, char *); void vtysh_read_config (char *, char *);
void vtysh_config_parse (char *); void vtysh_config_parse (char *);

View File

@ -228,7 +228,9 @@ vtysh_config_parse_line (char *line)
{ {
if (strncmp (line, "log", strlen ("log")) == 0 if (strncmp (line, "log", strlen ("log")) == 0
|| strncmp (line, "hostname", strlen ("hostname")) == 0 || strncmp (line, "hostname", strlen ("hostname")) == 0
|| strncmp (line, "password", strlen ("hostname")) == 0) || strncmp (line, "password", strlen ("password")) == 0
|| strncmp (line, "enable password",
strlen ("enable password")) == 0)
config_add_line_uniq (config_top, line); config_add_line_uniq (config_top, line);
else else
config_add_line (config_top, line); config_add_line (config_top, line);
@ -365,7 +367,6 @@ vtysh_read_file (FILE *confp)
/* Read up configuration file from file_name. */ /* Read up configuration file from file_name. */
void void
vtysh_read_config (char *config_file, vtysh_read_config (char *config_file,
char *config_current_dir,
char *config_default_dir) char *config_default_dir)
{ {
char *cwd; char *cwd;
@ -396,32 +397,19 @@ vtysh_read_config (char *config_file,
} }
else else
{ {
/* Relative path configuration file open. */ /* No configuration specified from command line. Open system
if (config_current_dir) * default file. */
confp = fopen (config_current_dir, "r"); confp = fopen (config_default_dir, "r");
/* If there is no relative path exists, open system default file. */
if (confp == NULL) if (confp == NULL)
{ {
confp = fopen (config_default_dir, "r"); fprintf (stderr, "can't open configuration file [%s]\n",
if (confp == NULL) config_default_dir);
{ exit (1);
fprintf (stderr, "can't open configuration file [%s]\n", }
config_default_dir);
exit (1);
}
else
fullpath = config_default_dir;
}
else else
{ fullpath = config_default_dir;
/* Rleative path configuration file. */ }
cwd = getcwd (NULL, MAXPATHLEN);
fullpath = XMALLOC (MTYPE_TMP,
strlen (cwd) + strlen (config_current_dir) + 2);
sprintf (fullpath, "%s/%s", cwd, config_current_dir);
}
}
vtysh_read_file (confp); vtysh_read_file (confp);
fclose (confp); fclose (confp);

View File

@ -39,12 +39,8 @@
/* VTY shell program name. */ /* VTY shell program name. */
char *progname; char *progname;
/* Configuration file name. Usually this is configurable, but vtysh /* Configuration file name and directory. */
* has static configuration file only. */
char *config_file = NULL; char *config_file = NULL;
/* Configuration file and directory. */
char *config_current = NULL;
char config_default[] = SYSCONFDIR VTYSH_DEFAULT_CONFIG; char config_default[] = SYSCONFDIR VTYSH_DEFAULT_CONFIG;
/* Integrated configuration file. */ /* Integrated configuration file. */
@ -146,6 +142,7 @@ usage (int status)
"Integrated shell for Quagga routing software suite. \n\n"\ "Integrated shell for Quagga routing software suite. \n\n"\
"-b, --boot Execute boot startup configuration\n" \ "-b, --boot Execute boot startup configuration\n" \
"-c, --command Execute argument as command\n "\ "-c, --command Execute argument as command\n "\
"-f, --config_file Set configuration file name\n"\
"-h, --help Display this help and exit\n\n" \ "-h, --help Display this help and exit\n\n" \
"Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS); "Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS);
@ -160,6 +157,7 @@ struct option longopts[] =
{ "eval", required_argument, NULL, 'e'}, { "eval", required_argument, NULL, 'e'},
{ "command", required_argument, NULL, 'c'}, { "command", required_argument, NULL, 'c'},
{ "help", no_argument, NULL, 'h'}, { "help", no_argument, NULL, 'h'},
{ "config_file", required_argument, NULL, 'f'},
{ 0 } { 0 }
}; };
@ -209,7 +207,7 @@ main (int argc, char **argv, char **env)
/* Option handling. */ /* Option handling. */
while (1) while (1)
{ {
opt = getopt_long (argc, argv, "be:c:h", longopts, 0); opt = getopt_long (argc, argv, "be:c:hf:", longopts, 0);
if (opt == EOF) if (opt == EOF)
break; break;
@ -229,8 +227,12 @@ main (int argc, char **argv, char **env)
case 'h': case 'h':
usage (0); usage (0);
break; break;
/* XXX It isn't used in any way. */
case 'i': case 'i':
integrated_file = strdup (optarg); integrated_file = strdup (optarg);
case 'f':
config_file = optarg;
break;
default: default:
usage (1); usage (1);
break; break;
@ -256,7 +258,7 @@ main (int argc, char **argv, char **env)
vtysh_connect_all (); vtysh_connect_all ();
/* Read vtysh configuration file. */ /* Read vtysh configuration file. */
vtysh_read_config (config_file, config_current, config_default); vtysh_read_config (config_file, config_default);
/* If eval mode. */ /* If eval mode. */
if (eval_flag) if (eval_flag)
@ -268,7 +270,7 @@ main (int argc, char **argv, char **env)
/* Boot startup configuration file. */ /* Boot startup configuration file. */
if (boot_flag) if (boot_flag)
{ {
vtysh_read_config (integrate_file, integrate_current, integrate_default); vtysh_read_config (integrate_file, integrate_default);
exit (0); exit (0);
} }