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.
diff --git a/lib/vty.c b/lib/vty.c
index f8e483f..bb3f14a 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -216,7 +216,28 @@
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);
}