Subject: bin/8656: syslog forwarding entries could use ability to rewrite facility
To: None <gnats-bugs@gnats.netbsd.org>
From: None <paul@whooppee.com>
List: netbsd-bugs
Date: 10/20/1999 11:22:04
>Number:         8656
>Category:       bin
>Synopsis:       syslog forwarding entries could use ability to rewrite facility
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Wed Oct 20 11:20:59 1999
>Last-Modified:
>Originator:     Paul Goyette
>Organization:
-----------------------------------------------------------------------
|   Paul Goyette  | PGP DSS Key fingerprint:  | E-mail addresses:     |
| Network Engineer|  BCD7 5301 9513 58A6 0DBC |  paul@whooppee.com    |
| & kernel hacker |  91EB ADB1 A280 3B79 9221 |  pgoyette@juniper.net |
-----------------------------------------------------------------------
>Release:        Oct 15 1999
>Environment:
	
System: NetBSD pc1.whooppee.com 1.4L NetBSD 1.4L (PC1) #0: Tue Oct 12 18:01:13 PDT 1999 paul@pc2.whooppee.com:/usr/src/sys/arch/i386/compile/PC1 i386


>Description:
	It might be useful for syslog's forwarding capability to be
	extended to be able to "rewrite" the facility value when sending
	to the remote syslogd.  Consider a widely distributed group of
	systems, where you want to send all messages to a single syslog
	host, but want to keep the East cost machines' stuff separated
	from the West coast machines.
>How-To-Repeat:
	see above
>Fix:
	Applying the following patches implements an optional :<facility>
	specification on /etc/syslog.conf forwarding entries.  This has
	been tested on NetBSD-current and works just fine.


Index: syslog.conf.5
===================================================================
RCS file: /cvsroot/basesrc/usr.sbin/syslogd/syslog.conf.5,v
retrieving revision 1.5
diff -c -r1.5 syslog.conf.5
*** syslog.conf.5	1997/10/17 13:46:09	1.5
--- syslog.conf.5	1999/10/20 18:10:37
***************
*** 162,171 ****
  A pathname (beginning with a leading slash).
  Selected messages are appended to the file.
  .It
! A hostname (preceded by an at (``@'') sign).
  Selected messages are forwarded to the
  .Xr syslogd
! program on the named host.
  .It
  A comma separated list of users.
  Selected messages are written to those users
--- 162,177 ----
  A pathname (beginning with a leading slash).
  Selected messages are appended to the file.
  .It
! A hostname (preceded by an at (``@'') sign
! and optionally followed by a colon (``:'') 
! and a facility name).
  Selected messages are forwarded to the
  .Xr syslogd
! program on the named host.  If the hostname is
! followed by a colon and a facility name, the
! forwarded messages are sent to the named host
! with the specified facility; the level is
! unchanged.
  .It
  A comma separated list of users.
  Selected messages are written to those users


Index: syslogd.c
===================================================================
RCS file: /cvsroot/basesrc/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.28
diff -c -r1.28 syslogd.c
*** syslogd.c	1999/06/07 15:34:07	1.28
--- syslogd.c	1999/10/20 18:13:09
***************
*** 141,146 ****
--- 141,147 ----
  		struct {
  			char	f_hname[MAXHOSTNAMELEN+1];
  			struct sockaddr_in	f_addr;
+ 			int	f_forward_facility;
  		} f_forw;		/* forwarding address */
  		char	f_fname[MAXPATHLEN];
  	} f_un;
***************
*** 719,725 ****
  {
  	struct iovec iov[6];
  	struct iovec *v;
! 	int l;
  	char line[MAXLINE + 1], repbuf[80], greetings[200];
  
  	v = iov;
--- 720,726 ----
  {
  	struct iovec iov[6];
  	struct iovec *v;
! 	int l, forw_pri;
  	char line[MAXLINE + 1], repbuf[80], greetings[200];
  
  	v = iov;
***************
*** 771,784 ****
  	case F_FORW:
  		dprintf(" %s\n", f->f_un.f_forw.f_hname);
  		/* check for local vs remote messages (from FreeBSD PR#bin/7055) */
  		if (strcmp(f->f_prevhost, LocalHostName)) {
  			l = snprintf(line, sizeof(line) - 1,
  				     "<%d>%.15s [%s]: %s",
! 				     f->f_prevpri, (char *) iov[0].iov_base,
  				     f->f_prevhost, (char *) iov[4].iov_base);
  		} else {
  			l = snprintf(line, sizeof(line) - 1, "<%d>%.15s %s",
! 				     f->f_prevpri, (char *) iov[0].iov_base,
  				     (char *) iov[4].iov_base);
  		}
  		if (l > MAXLINE)
--- 772,790 ----
  	case F_FORW:
  		dprintf(" %s\n", f->f_un.f_forw.f_hname);
  		/* check for local vs remote messages (from FreeBSD PR#bin/7055) */
+ 		if (f->f_un.f_forw.f_forward_facility != -1)
+ 			forw_pri = LOG_MAKEPRI ( f->f_un.f_forw.f_forward_facility, LOG_PRI(f->f_prevpri));
+ 		else
+ 			forw_pri = f->f_prevpri;
+ 		dprintf("forwarding priority 0%o, prevpri 0%o\n", forw_pri, f->f_prevpri);
  		if (strcmp(f->f_prevhost, LocalHostName)) {
  			l = snprintf(line, sizeof(line) - 1,
  				     "<%d>%.15s [%s]: %s",
! 				     forw_pri, (char *) iov[0].iov_base,
  				     f->f_prevhost, (char *) iov[4].iov_base);
  		} else {
  			l = snprintf(line, sizeof(line) - 1, "<%d>%.15s %s",
! 				     forw_pri, (char *) iov[0].iov_base,
  				     (char *) iov[4].iov_base);
  		}
  		if (l > MAXLINE)
***************
*** 1125,1131 ****
  {
  	struct hostent *hp;
  	int i, pri;
! 	char *bp, *p, *q;
  	char buf[MAXLINE], ebuf[100];
  
  	dprintf("cfline(%s)\n", line);
--- 1131,1137 ----
  {
  	struct hostent *hp;
  	int i, pri;
! 	char *bp, *p, *q, *r;
  	char buf[MAXLINE], ebuf[100];
  
  	dprintf("cfline(%s)\n", line);
***************
*** 1199,1206 ****
  	switch (*p)
  	{
  	case '@':
  		if (!InetInuse)
! 			break;
  		(void)strcpy(f->f_un.f_forw.f_hname, ++p);
  		hp = gethostbyname(p);
  		if (hp == NULL) {
--- 1205,1221 ----
  	switch (*p)
  	{
  	case '@':
+ 		f->f_un.f_forw.f_forward_facility = -1;
  		if (!InetInuse)
! 		/*	break*/;
! 		r = p;
! 		while (*++r ) {
! 			if (*r == ':') {
! 				*r++ = '\0';
! 				f->f_un.f_forw.f_forward_facility = decode(r, facilitynames)>>3;
! 				break;
! 			}
! 		}
  		(void)strcpy(f->f_un.f_forw.f_hname, ++p);
  		hp = gethostbyname(p);
  		if (hp == NULL) {
>Audit-Trail:
>Unformatted: