2005-03-08 Paul Jakma <paul.jakma@sun.com>

* command.c: (banner_motd_file_cmd) use XSTRDUP/XFREE
	* vty.c: (vty_hello) suggestions from Andrew, read by line and
	  stub out trailling non-printable characters on each line thus
	  allowing us to specify VTY_NEWLINE to vty_out.
This commit is contained in:
paul 2005-03-08 15:16:57 +00:00
parent 3b0c5d9a56
commit b45da6f016
3 changed files with 22 additions and 12 deletions

View File

@ -1,3 +1,10 @@
2005-03-08 Paul Jakma <paul.jakma@sun.com>
* command.c: (banner_motd_file_cmd) use XSTRDUP/XFREE
* vty.c: (vty_hello) suggestions from Andrew, read by line and
stub out trailling non-printable characters on each line thus
allowing us to specify VTY_NEWLINE to vty_out.
2005-03-08 Jeroen Massar <jeroen@unfix.org> 2005-03-08 Jeroen Massar <jeroen@unfix.org>
* vty.c: (vty_hello) display motd file, if set * vty.c: (vty_hello) display motd file, if set

View File

@ -1,5 +1,5 @@
/* /*
$Id: command.c,v 1.38 2005/03/08 10:43:43 paul Exp $ $Id: command.c,v 1.39 2005/03/08 15:16:57 paul Exp $
Command interpreter routine for virtual terminal [aka TeletYpe] Command interpreter routine for virtual terminal [aka TeletYpe]
Copyright (C) 1997, 98, 99 Kunihiro Ishiguro Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
@ -3409,8 +3409,10 @@ DEFUN (banner_motd_file,
"Banner from a file\n" "Banner from a file\n"
"Filename\n") "Filename\n")
{ {
if (host.motdfile) free(host.motdfile); if (host.motdfile)
host.motdfile = strdup(argv[0]); XFREE (MTYPE_TMP, host.motdfile);
host.motdfile = XSTRDUP (MTYPE_TMP, argv[0]);
return CMD_SUCCESS; return CMD_SUCCESS;
} }

View File

@ -220,22 +220,23 @@ vty_hello (struct vty *vty)
{ {
FILE *f; FILE *f;
char buf[4096]; char buf[4096];
int r;
f = fopen (host.motdfile, "r"); f = fopen (host.motdfile, "r");
if (f) if (f)
{ {
while (!feof (f)) while (fgets (buf, sizeof (buf), f))
{ {
memset (buf, '\0', sizeof (buf)); char *s;
r = fread (&buf, sizeof (buf) - 1, 1, f); /* work backwards and squash all isspace() chars
if (r < 0) * we want nul terminated for vty_out */
break; for (s = buf+strlen(buf); (s > buf) && isspace(*(s-1)); s--);
vty_out (vty, buf); *s = '\0';
vty_out (vty, "%s%s", buf, VTY_NEWLINE);
} }
fclose (f); fclose (f);
} }
else else
vty_out (vty, "MOTD file not found\n"); vty_out (vty, "MOTD file not found%s", VTY_NEWLINE);
} }
else if (host.motd) else if (host.motd)
vty_out (vty, host.motd); vty_out (vty, host.motd);