From f366ad31ae6bf7e2fb7271cf8eab6dee4af3baf9 Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Thu, 27 Jul 2006 18:01:41 +0000 Subject: [vtysh] Never skip authentication, and add support for multiple -c commands 2006-07-27 Andrew J. Schorr * vtysh.1: Document new options -d and -E, and note that now multiple -c options may be supplied, with embedded linefeed now supported. In BUGS section, remove warning about vtysh causing a daemon to freeze, since this has been fixed. * vtysh_main.c: (usage) Add new -d and -E options. And note that -c can be used multiple times, possibly with embedded linefeeds. (longopts) Add new -d and -E options. (main) Add new -d and -E options, and create a linked list to support multiple -c options. Do not call vtysh_connect_all until after vtysh_read_config(config_default) and vtysh_auth have succeeded. This prevents the vtysh.conf file from configuring any daemons, and it ensures that authentication has been passed before we send any commands to any daemons. Call vtysh_connect_all with any daemon name supplied with -d. If it is unable to connect to any daemons, issue an error message and exit immediately. When used in -c mode, call vtysh_execute("enable") before executing the commands in order to match interactive behavior. And detect embedded linefeed chars in -c commands and break them up appropriately. * vtysh.h: (vtysh_connect_all) Fix proto to reflect new daemon_name argument, and that it now returns an integer -- the number of daemons to which we were able to connect. * vtysh.c: (vtysh_connect_all) Add a new daemon_name argument. If supplied, connect only to that daemon. And return the number of daemons to which we were able to connect. (vtysh_prompt): Performance enhancement -- make struct utsname static so we call uname to get the hostname only once. --- vtysh/vtysh.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'vtysh/vtysh.c') diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 110c361a..9b7d300f 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -2119,18 +2119,28 @@ vtysh_connect (struct vtysh_client *vclient) return 0; } -void -vtysh_connect_all(void) +int +vtysh_connect_all(const char *daemon_name) { u_int i; + int rc = 0; + int matches = 0; for (i = 0; i < VTYSH_INDEX_MAX; i++) { - vtysh_connect(&vtysh_client[i]); - /* We need direct access to ripd in vtysh_exit_ripd_only. */ - if (vtysh_client[i].flag == VTYSH_RIPD) - ripd_client = &vtysh_client[i]; + if (!daemon_name || !strcmp(daemon_name, vtysh_client[i].name)) + { + matches++; + if (vtysh_connect(&vtysh_client[i]) == 0) + rc++; + /* We need direct access to ripd in vtysh_exit_ripd_only. */ + if (vtysh_client[i].flag == VTYSH_RIPD) + ripd_client = &vtysh_client[i]; + } } + if (!matches) + fprintf(stderr, "Error: no daemons match name %s!\n", daemon_name); + return rc; } /* To disable readline's filename completion. */ @@ -2155,7 +2165,7 @@ vtysh_readline_init (void) char * vtysh_prompt (void) { - struct utsname names; + static struct utsname names; static char buf[100]; const char*hostname; extern struct host host; @@ -2164,7 +2174,8 @@ vtysh_prompt (void) if (!hostname) { - uname (&names); + if (!names.nodename[0]) + uname (&names); hostname = names.nodename; } -- cgit v1.2.1