diff options
author | lidl <lidl@FreeBSD.org> | 2015-11-25 20:01:11 +0000 |
---|---|---|
committer | lidl <lidl@FreeBSD.org> | 2015-11-25 20:01:11 +0000 |
commit | efa7d696b4c82583e4dd816996d2c2b39f231817 (patch) | |
tree | b0fae51d051f06b8bbcccb7020c9f036cd4ece40 | |
parent | 14c25cb332b151be17de5cbdc98045608e52a6f6 (diff) | |
download | FreeBSD-src-efa7d696b4c82583e4dd816996d2c2b39f231817.zip FreeBSD-src-efa7d696b4c82583e4dd816996d2c2b39f231817.tar.gz |
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
-rw-r--r-- | usr.sbin/syslogd/syslogd.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index b5b57b3..cd0f1b6 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -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 *iov, const int iovlen) 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 *iov, const int iovlen) 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) { |