From owner-svn-src-all@freebsd.org Wed Nov 25 20:01:13 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6ED5FA37D84; Wed, 25 Nov 2015 20:01:13 +0000 (UTC) (envelope-from lidl@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 198C51009; Wed, 25 Nov 2015 20:01:13 +0000 (UTC) (envelope-from lidl@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tAPK1Cod007432; Wed, 25 Nov 2015 20:01:12 GMT (envelope-from lidl@FreeBSD.org) Received: (from lidl@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tAPK1CGa007431; Wed, 25 Nov 2015 20:01:12 GMT (envelope-from lidl@FreeBSD.org) Message-Id: <201511252001.tAPK1CGa007431@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: lidl set sender to lidl@FreeBSD.org using -f From: Kurt Lidl Date: Wed, 25 Nov 2015 20:01:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r291328 - head/usr.sbin/syslogd X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Nov 2015 20:01:13 -0000 Author: lidl Date: Wed Nov 25 20:01:11 2015 New Revision: 291328 URL: https://svnweb.freebsd.org/changeset/base/291328 Log: Have syslogd honor 'mesg' status when logging to users. PR: bin/196742 Submitted by: jef at mail acme com Approved by: rpaulo (mentor) Differential Revision: https://reviews.freebsd.org/D4270 Modified: head/usr.sbin/syslogd/syslogd.c Modified: head/usr.sbin/syslogd/syslogd.c ============================================================================== --- head/usr.sbin/syslogd/syslogd.c Wed Nov 25 19:49:55 2015 (r291327) +++ head/usr.sbin/syslogd/syslogd.c Wed Nov 25 20:01:11 2015 (r291328) @@ -341,6 +341,7 @@ static void printsys(char *); static int p_open(const char *, pid_t *); static void readklog(void); static void reapchild(int); +static const char *ttymsg_check(struct iovec *, int, char *, int); static void usage(void); static int validate(struct sockaddr *, const char *); static void unmapped(struct sockaddr *); @@ -1425,7 +1426,7 @@ wallmsg(struct filed *f, struct iovec *i if (!f->f_un.f_uname[i][0]) break; if (!strcmp(f->f_un.f_uname[i], ut->ut_user)) { - if ((p = ttymsg(iov, iovlen, ut->ut_line, + if ((p = ttymsg_check(iov, iovlen, ut->ut_line, TTYMSGTIME)) != NULL) { errno = 0; /* already in msg */ logerror(p); @@ -1438,6 +1439,29 @@ wallmsg(struct filed *f, struct iovec *i reenter = 0; } +/* + * Wrapper routine for ttymsg() that checks the terminal for messages enabled. + */ +static const char * +ttymsg_check(struct iovec *iov, int iovcnt, char *line, int tmout) +{ + static char device[1024]; + static char errbuf[1024]; + struct stat sb; + + (void) snprintf(device, sizeof(device), "%s%s", _PATH_DEV, line); + + if (stat(device, &sb) < 0) { + (void) snprintf(errbuf, sizeof(errbuf), + "%s: %s", device, strerror(errno)); + return (errbuf); + } + if ((sb.st_mode & S_IWGRP) == 0) + /* Messages disabled. */ + return (NULL); + return ttymsg(iov, iovcnt, line, tmout); +} + static void reapchild(int signo __unused) {