From owner-freebsd-bugs@FreeBSD.ORG Thu Jan 27 05:10:07 2011 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8514D1065670 for ; Thu, 27 Jan 2011 05:10:07 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 5D7D48FC12 for ; Thu, 27 Jan 2011 05:10:07 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p0R5A7RX092068 for ; Thu, 27 Jan 2011 05:10:07 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p0R5A7vx092067; Thu, 27 Jan 2011 05:10:07 GMT (envelope-from gnats) Resent-Date: Thu, 27 Jan 2011 05:10:07 GMT Resent-Message-Id: <201101270510.p0R5A7vx092067@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Callum Gibson Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8DB0B106564A for ; Thu, 27 Jan 2011 05:07:48 +0000 (UTC) (envelope-from callumgibson@optusnet.com.au) Received: from fallbackmx09.syd.optusnet.com.au (fallbackmx09.syd.optusnet.com.au [211.29.132.242]) by mx1.freebsd.org (Postfix) with ESMTP id 2AD448FC14 for ; Thu, 27 Jan 2011 05:07:47 +0000 (UTC) Received: from mail03.syd.optusnet.com.au (mail03.syd.optusnet.com.au [211.29.132.184]) by fallbackmx09.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id p0R4vXWN003985 for ; Thu, 27 Jan 2011 15:57:33 +1100 Received: from omma.gibson.athome (c122-106-15-156.rivrw1.nsw.optusnet.com.au [122.106.15.156]) by mail03.syd.optusnet.com.au (8.13.1/8.13.1) with SMTP id p0R4vTda032567 for ; Thu, 27 Jan 2011 15:57:30 +1100 Received: (qmail 76636 invoked by uid 107); 27 Jan 2011 15:57:29 +1100 Message-Id: <20110127045729.76635.qmail@omma.gibson.athome> Date: 27 Jan 2011 15:57:29 +1100 From: Callum Gibson To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: bin/154324: [patch] logger ignores tag when logging to remote host X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Callum Gibson List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Jan 2011 05:10:07 -0000 >Number: 154324 >Category: bin >Synopsis: [patch] logger ignores tag when logging to remote host >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Jan 27 05:10:06 UTC 2011 >Closed-Date: >Last-Modified: >Originator: Callum Gibson >Release: FreeBSD 8.1-STABLE i386 >Organization: >Environment: System: FreeBSD omma 8.1-STABLE FreeBSD 8.1-STABLE #13: Wed Sep 22 07:42:16 EST 2010 root@omma:/usr/local/obj/usr/src/sys/OMMA i386 >Description: If you log to a remote host with logger(1) using the -h flag, it will ignore the tag supplied with -t. The default tag prefix of login name also isn't honoured. Additionally, openlog is always called even though this is only relevant when logging to the local machine with the syslog(3) interface. The supplied patch addresses both of these issues. I've also updated the manpage to note the default tag. Patch is versus RELENG_8 but applies cleanly against HEAD as at r216370. >How-To-Repeat: Log to a remote host and note the absence of the tag supplied with -t in the resulting log entry. eg. logger -h loghost -t HELLO some message >Fix: --- usr.bin/logger/logger.c.orig 2009-08-03 18:13:06.000000000 +1000 +++ usr.bin/logger/logger.c 2011-01-27 14:55:30.000000000 +1100 @@ -63,7 +63,8 @@ int decode(char *, CODE *); int pencode(char *); -static void logmessage(int, const char *, const char *, const char *); +static void logmessage(int, const char *, const char *, const char *, + const char *); static void usage(void); struct socks { @@ -140,8 +141,11 @@ argc -= optind; argv += optind; + if (tag == NULL) + tag = getlogin(); /* setup for logging */ - openlog(tag ? tag : getlogin(), logflags, 0); + if (host == NULL) + openlog(tag, logflags, 0); (void) fclose(stdout); /* log input line if appropriate */ @@ -152,11 +156,11 @@ for (p = buf, endp = buf + sizeof(buf) - 2; *argv;) { len = strlen(*argv); if (p + len > endp && p > buf) { - logmessage(pri, host, svcname, buf); + logmessage(pri, tag, host, svcname, buf); p = buf; } if (len > sizeof(buf) - 1) - logmessage(pri, host, svcname, *argv++); + logmessage(pri, tag, host, svcname, *argv++); else { if (p != buf) *p++ = ' '; @@ -165,10 +169,10 @@ } } if (p != buf) - logmessage(pri, host, svcname, buf); + logmessage(pri, tag, host, svcname, buf); } else while (fgets(buf, sizeof(buf), stdin) != NULL) - logmessage(pri, host, svcname, buf); + logmessage(pri, tag, host, svcname, buf); exit(0); } @@ -176,7 +180,8 @@ * Send the message to syslog, either on the local host, or on a remote host */ void -logmessage(int pri, const char *host, const char *svcname, const char *buf) +logmessage(int pri, const char *tag, const char *host, const char *svcname, + const char *buf) { static struct socks *socks; static int nsock = 0; @@ -220,7 +225,7 @@ errx(1, "socket"); } - if ((len = asprintf(&line, "<%d>%s", pri, buf)) == -1) + if ((len = asprintf(&line, "<%d>%s: %s", pri, tag, buf)) == -1) errx(1, "asprintf"); lsent = -1; --- usr.bin/logger/logger.1.orig 2009-08-03 18:13:06.000000000 +1000 +++ usr.bin/logger/logger.1 2011-01-27 15:09:13.000000000 +1100 @@ -106,7 +106,8 @@ The default is ``user.notice.'' .It Fl t Ar tag Mark every line in the log with the specified -.Ar tag . +.Ar tag +rather than the default of current login name. .It Ar message Write the message to log; if not specified, and the .Fl f >Release-Note: >Audit-Trail: >Unformatted: