socklog-conf patch for Linux 2.6
Florian Westphal <[email protected]>
| Newsgroups | gmane.comp.misc.pape.general |
|---|---|
| Message-ID | <[email protected]> |
Hello, attached is a patch that makes socklog-conf check for Linux Kernel 2.6. If a 2.6 kernel is found, socklog-conf will set up the klog service to run as root (the acct parameter is ignored. It will also print a warning message about this). The patch also adds a small 2.6 notice to socklog-conf.8 and the html documentation. Thanks, Florian.
socklog-linux26.diff
(text/plain, 3.1 KB)
diff -Naur socklog-1.4.2/doc/socklog-conf.8.html socklog-1.4.2-fw/doc/socklog-conf.8.html
--- socklog-1.4.2/doc/socklog-conf.8.html 2004-03-23 19:33:40.000000000 +0100
+++ socklog-1.4.2-fw/doc/socklog-conf.8.html 2004-04-04 18:04:41.407653120 +0200
@@ -63,6 +63,10 @@
<b>socklog-conf</b> arranges for <i><b>socklog</b>(8)</i> to run under the uid and gid of <i>acct</i>
and to read kernel messages from <i>/proc/kmsg</i> on Linux, or <i>/dev/klog</i> on BSD.
<p>
+Note: Unfortunately the implementation of the proc filesystem in the 2.6.x
+Linux kernels force the application reading from <i>/proc/kmsg</i> to
+run under root privileges, thus the <i>acct</i> parameter is ignored on Linux 2.6 systems.
+<p>
It also creates automatically rotated log directories in <i>/var/log/socklog-klog</i>.
The logs are owned by <i>logacct</i>. The corresponding <i><b>svlogd</b>(8)</i> process runs
under the uid and gid of <i>logacct</i>. <p>
diff -Naur socklog-1.4.2/man/socklog-conf.8 socklog-1.4.2-fw/man/socklog-conf.8
--- socklog-1.4.2/man/socklog-conf.8 2004-03-23 19:33:40.000000000 +0100
+++ socklog-1.4.2-fw/man/socklog-conf.8 2004-04-04 18:03:57.340352368 +0200
@@ -136,6 +136,13 @@
.I /dev/klog
on BSD.
.LP
+Note: Unfortunately the implementation of the proc filesystem in the 2.6.x
+Linux kernels force the application reading from
+.I /proc/kmsg
+to run under root privileges, thus the
+.I acct
+parameter is ignored on Linux 2.6 systems.
+.LP
It also creates automatically rotated log directories in
.IR /var/log/socklog-klog .
The logs are owned by
diff -Naur socklog-1.4.2/src/socklog-conf.c socklog-1.4.2-fw/src/socklog-conf.c
--- socklog-1.4.2/src/socklog-conf.c 2004-03-23 19:33:40.000000000 +0100
+++ socklog-1.4.2-fw/src/socklog-conf.c 2004-04-04 17:55:33.104007944 +0200
@@ -15,6 +15,13 @@
#include "scan.h"
#endif
+#if defined (__linux__)
+#define WANT_LINUX_26_CHECK
+#include <sys/utsname.h>
+#include "scan.h"
+#include "str.h"
+#endif
+
#ifndef SOLARIS
#include <paths.h>
#endif
@@ -110,7 +117,7 @@
struct utsname u;
unsigned long sunos_version;
uname(&u);
- scan_ulong(u.release+strlen(u.release)-1, &sunos_version);
+ scan_ulong(u.release+str_len(u.release)-1, &sunos_version);
#endif
#endif
makedir("unix");
@@ -232,6 +239,24 @@
perm(0750);
}
+#ifdef WANT_LINUX_26_CHECK
+static int is_linux_26() {
+ struct utsname u;
+ unsigned long ver;
+
+ uname(&u);
+
+ if (str_equal("Linux", u.sysname) &&
+ str_len(u.release) >= 5 )
+ {
+ if ( scan_ulong(u.release, &ver) && (2 == ver) &&
+ scan_ulong(u.release+2, &ver) && (6 == ver) )
+ return 1;
+ }
+return 0;
+}
+#endif
+
void conf_klog() {
makedir("klog");
perm(0750);
@@ -248,9 +273,21 @@
outs("#!/bin/sh\n");
outs("exec <"); outs(_PATH_KLOG); outs("\n");
outs("exec 2>&1\n");
+
+#ifdef WANT_LINUX_26_CHECK
+ if ( is_linux_26() ) {
+ strerr_warn2(WARNING, "found Linux 2.6, configuring socklog klog to run as root", 0);
+ outs("exec socklog ucspi\n");
+ } else {
+ outs("exec chpst -u");
+ outs(user);
+ outs(" socklog ucspi\n");
+ }
+#else
outs("exec chpst -u");
outs(user);
outs(" socklog ucspi\n");
+#endif
finish();
perm(0750);