Module Name:    src
Committed By:   gutteridge
Date:           Wed Aug 21 17:13:24 UTC 2024

Modified Files:
        src/usr.sbin/syslogd: syslogd.8 syslogd.c

Log Message:
syslogd.8 & syslogd.c: add -k option

Provide a means of disabling the translation of (remote) messages
received with facility kern to facility user. Feature equivalent to
what FreeBSD added years ago, though the code is slightly different
(a bit easier to follow expressively). Patches from RVP, provided in
PR lib/57172 (with very minor tweaks by me).


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/usr.sbin/syslogd/syslogd.8
cvs rdiff -u -r1.143 -r1.144 src/usr.sbin/syslogd/syslogd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/syslogd/syslogd.8
diff -u src/usr.sbin/syslogd/syslogd.8:1.59 src/usr.sbin/syslogd/syslogd.8:1.60
--- src/usr.sbin/syslogd/syslogd.8:1.59	Tue Nov  8 01:43:09 2022
+++ src/usr.sbin/syslogd/syslogd.8	Wed Aug 21 17:13:24 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: syslogd.8,v 1.59 2022/11/08 01:43:09 uwe Exp $
+.\"	$NetBSD: syslogd.8,v 1.60 2024/08/21 17:13:24 gutteridge Exp $
 .\"
 .\" Copyright (c) 1983, 1986, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"     from: @(#)syslogd.8	8.1 (Berkeley) 6/6/93
 .\"
-.Dd November 8, 2022
+.Dd August 21, 2024
 .Dt SYSLOGD 8
 .Os
 .Sh NAME
@@ -37,7 +37,7 @@
 .Nd log systems messages
 .Sh SYNOPSIS
 .Nm
-.Op Fl nrSsTUvX
+.Op Fl knrSsTUvX
 .Op Fl B Ar buffer_length
 .Op Fl b Ar bind_address
 .Op Fl d Op Oo Cm \&~ Oc Ns Ar what
@@ -91,6 +91,15 @@ the default is
 Set GID to
 .Ar group
 after the sockets and log files have been opened.
+.It Fl k
+Disable the translation of (remote) messages received with facility
+.Dq kern
+to facility
+.Dq user .
+Usually the
+.Dq kern
+facility is reserved for messages read directly from
+.Pa /dev/klog .
 .It Fl m Ar mark_interval
 Select the number of minutes between ``mark'' messages;
 the default is 20 minutes.

Index: src/usr.sbin/syslogd/syslogd.c
diff -u src/usr.sbin/syslogd/syslogd.c:1.143 src/usr.sbin/syslogd/syslogd.c:1.144
--- src/usr.sbin/syslogd/syslogd.c:1.143	Wed Aug 21 16:30:27 2024
+++ src/usr.sbin/syslogd/syslogd.c	Wed Aug 21 17:13:24 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: syslogd.c,v 1.143 2024/08/21 16:30:27 gutteridge Exp $	*/
+/*	$NetBSD: syslogd.c,v 1.144 2024/08/21 17:13:24 gutteridge Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993, 1994
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = "@(#)syslogd.c	8.3 (Berkeley) 4/4/94";
 #else
-__RCSID("$NetBSD: syslogd.c,v 1.143 2024/08/21 16:30:27 gutteridge Exp $");
+__RCSID("$NetBSD: syslogd.c,v 1.144 2024/08/21 17:13:24 gutteridge Exp $");
 #endif
 #endif /* not lint */
 
@@ -205,6 +205,7 @@ bool	BSDOutputFormat = true;	/* if true 
 				 * this, it will only break some syslog-sign
 				 * configurations (e.g. with SG="0").
 				 */
+bool	KernXlat = true;	/* translate kern.* -> user.* */
 char	appname[]   = "syslogd";/* the APPNAME for own messages */
 char   *include_pid;		/* include PID in own messages */
 char	include_pid_buf[11];
@@ -319,7 +320,7 @@ main(int argc, char *argv[])
 	/* should we set LC_TIME="C" to ensure correct timestamps&parsing? */
 	(void)setlocale(LC_ALL, "");
 
-	while ((ch = getopt(argc, argv, "b:B:d::nsSf:m:o:p:P:ru:g:t:TUvX")) != -1)
+	while ((ch = getopt(argc, argv, "b:B:d::knsSf:m:o:p:P:ru:g:t:TUvX")) != -1)
 		switch(ch) {
 		case 'b':
 			bindhostname = optarg;
@@ -360,6 +361,9 @@ main(int argc, char *argv[])
 			if (*group == '\0')
 				usage();
 			break;
+		case 'k':		/* pass-through (remote) kern.* */
+			KernXlat = false;
+			break;
 		case 'm':		/* mark interval */
 			MarkInterval = atoi(optarg) * 60;
 			break;
@@ -686,7 +690,7 @@ usage(void)
 {
 
 	(void)fprintf(stderr,
-	    "usage: %s [-dnrSsTUvX] [-B buffer_length] [-b bind_address]\n"
+	    "usage: %s [-dknrSsTUvX] [-B buffer_length] [-b bind_address]\n"
 	    "\t[-f config_file] [-g group]\n"
 	    "\t[-m mark_interval] [-P file_list] [-p log_socket\n"
 	    "\t[-p log_socket2 ...]] [-t chroot_dir] [-u user]\n",
@@ -1549,11 +1553,11 @@ printline(const char *hname, char *msg, 
 		pri = DEFUPRI;
 
 	/*
-	 * Don't allow users to log kernel messages.
+	 * Don't (usually) allow users to log kernel messages.
 	 * NOTE: Since LOG_KERN == 0, this will also match
 	 *	 messages with no facility specified.
 	 */
-	if ((pri & LOG_FACMASK) == LOG_KERN)
+	if ((pri & LOG_FACMASK) == LOG_KERN && KernXlat)
 		pri = LOG_USER | LOG_PRI(pri);
 
 	if (bsdsyslog) {

Reply via email to