]> git.puffer.fish Git - matthieu/frr.git/commitdiff
2005-03-08 Jeroen Massar <jeroen@unfix.org>
authorpaul <paul>
Tue, 8 Mar 2005 10:43:43 +0000 (10:43 +0000)
committerpaul <paul>
Tue, 8 Mar 2005 10:43:43 +0000 (10:43 +0000)
* vty.c: (vty_hello) display motd file, if set
* command.h: add char *motdfile to struct host
* command.c: (config_write_host) write out motdfile config
  (banner_motd_file_cmd) new command, allow motd to be read from
  file.
  (no_banner_motd_cmd) free motdfile string, if needs be.
  (cmd_init) init (struct host).motdfile. Add new motd file
  commands.

lib/ChangeLog
lib/command.c
lib/command.h
lib/vty.c

index d57aa3028c248f1ddf1f583150b92c9932f72d97..3b60e294a2bd98780ca9c235bdd6893aa5814c7f 100644 (file)
@@ -1,3 +1,14 @@
+2005-03-08 Jeroen Massar <jeroen@unfix.org>
+
+       * vty.c: (vty_hello) display motd file, if set
+       * command.h: add char *motdfile to struct host
+       * command.c: (config_write_host) write out motdfile config
+         (banner_motd_file_cmd) new command, allow motd to be read from
+         file.
+         (no_banner_motd_cmd) free motdfile string, if needs be.
+         (cmd_init) init (struct host).motdfile. Add new motd file
+         commands.
+
 2005-03-07 Michael Sandee <voidptr@voidptr.sboost.org>
 
        * command.c: host.name might be NULL.
index 1e1f3cf55cbdc15be7eff740309952ea38a885a2..ca1100da78888aecb56967268e0ed258ea8a44ae 100644 (file)
@@ -1,5 +1,5 @@
 /*
-   $Id: command.c,v 1.37 2005/03/07 08:35:39 hasso Exp $
+   $Id: command.c,v 1.38 2005/03/08 10:43:43 paul Exp $
 
    Command interpreter routine for virtual terminal [aka TeletYpe]
    Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
@@ -597,7 +597,9 @@ config_write_host (struct vty *vty)
     vty_out (vty, "service terminal-length %d%s", host.lines,
             VTY_NEWLINE);
 
-  if (! host.motd)
+  if (host.motdfile)
+    vty_out (vty, "banner motd file %s%s", host.motdfile, VTY_NEWLINE);
+  else if (! host.motd)
     vty_out (vty, "no banner motd%s", VTY_NEWLINE);
 
   return 1;
@@ -3399,6 +3401,18 @@ DEFUN (no_config_log_record_priority,
   return CMD_SUCCESS;
 }
 
+DEFUN (banner_motd_file,
+       banner_motd_file_cmd,
+       "banner motd file [FILE]",
+       "Set banner\n"
+       "Banner for motd\n"
+       "Banner from a file\n"
+       "Filename\n")
+{
+  if (host.motdfile) free(host.motdfile);
+  host.motdfile = strdup(argv[0]);
+  return CMD_SUCCESS;
+}
 
 DEFUN (banner_motd_default,
        banner_motd_default_cmd,
@@ -3419,6 +3433,8 @@ DEFUN (no_banner_motd,
        "Strings for motd\n")
 {
   host.motd = NULL;
+  if (host.motdfile) free(host.motdfile);
+  host.motdfile = NULL;
   return CMD_SUCCESS;
 }
 
@@ -3460,6 +3476,7 @@ cmd_init (int terminal)
   host.config = NULL;
   host.lines = -1;
   host.motd = default_motd;
+  host.motdfile = NULL;
 
   /* Install top nodes. */
   install_node (&view_node, NULL);
@@ -3539,6 +3556,7 @@ cmd_init (int terminal)
       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);
+      install_element (CONFIG_NODE, &banner_motd_file_cmd);
       install_element (CONFIG_NODE, &no_banner_motd_cmd);
       install_element (CONFIG_NODE, &service_terminal_length_cmd);
       install_element (CONFIG_NODE, &no_service_terminal_length_cmd);
index eba919cbdf62991bdd805f988ee1cb86bd1f78e7..14808330233cafb4d073251b493502005e8e9395 100644 (file)
@@ -55,6 +55,7 @@ struct host
 
   /* Banner configuration. */
   const char *motd;
+  char *motdfile;
 };
 
 /* There are some command levels which called from command node. */
index f8e483f6a920e3dc644786d6dec15eb876cdc4f4..bb3f14a50c7cabbffe776f8082b5cb2ae052c1e6 100644 (file)
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -216,7 +216,28 @@ vty_time_print (struct vty *vty, int cr)
 void
 vty_hello (struct vty *vty)
 {
-  if (host.motd)
+  if (host.motdfile)
+    {
+      FILE *f;
+      char buf[4096];
+      int r;
+      f = fopen (host.motdfile, "r");
+      if (f)
+       {
+         while (!feof (f))
+           {
+             memset (buf, '\0', sizeof (buf));
+             r = fread (&buf, sizeof (buf) - 1, 1, f);
+             if (r < 0)
+               break;
+             vty_out (vty, buf);
+           }
+         fclose (f);
+       }
+      else
+       vty_out (vty, "MOTD file not found\n");
+    }
+  else if (host.motd)
     vty_out (vty, host.motd);
 }