Date: Wed, 22 Aug 2001 01:38:41 -0700 From: "Crist J. Clark" <cristjc@earthlink.net> To: freebsd-audit@freebsd.org Subject: syslogd(8) Hostname Upgrade Message-ID: <20010822013841.A76483@blossom.cjclark.org>
next in thread | raw e-mail | index | archive | help
I brought this up as a PR (bin/24444) some months ago. I figured I'd finally close the PR and add this. This patch makes syslogd(8) update the hostname when the daemon is reinitialized. Before anyone points it out, this is not meant to be a security feature. It allows syslogd(8) to update the hostname without terminating and restarting the daemon and generates a message logging the change, nothing more, nothing less. I've been running with it for months on -CURRENT and -STABLE with no problems. Nit picks anyone? Index: syslogd.c =================================================================== RCS file: /export/ncvs/src/usr.sbin/syslogd/syslogd.c,v retrieving revision 1.81 diff -u -r1.81 syslogd.c --- syslogd.c 2001/08/20 13:24:39 1.81 +++ syslogd.c 2001/08/22 04:55:12 @@ -318,7 +318,7 @@ struct sockaddr_un sunx, fromunix; struct sockaddr_storage frominet; FILE *fp; - char *p, *hname, line[MAXLINE + 1]; + char *hname, line[MAXLINE + 1]; struct timeval tv, *tvp; struct sigaction sact; sigset_t mask; @@ -398,12 +398,6 @@ consfile.f_type = F_CONSOLE; (void)strcpy(consfile.f_un.f_fname, ctty + sizeof _PATH_DEV - 1); - (void)gethostname(LocalHostName, sizeof(LocalHostName)); - if ((p = strchr(LocalHostName, '.')) != NULL) { - *p++ = '\0'; - LocalDomain = p; - } else - LocalDomain = ""; (void)strcpy(bootfile, getbootfile()); (void)signal(SIGTERM, die); (void)signal(SIGINT, Debug ? die : SIG_IGN); @@ -1346,10 +1340,26 @@ char cline[LINE_MAX]; char prog[NAME_MAX+1]; char host[MAXHOSTNAMELEN]; + char oldLocalHostName[MAXHOSTNAMELEN]; + char hostMsg[2*MAXHOSTNAMELEN+40]; dprintf("init\n"); /* + * Load hostname (may have changed). + */ + if (signo) + (void)strlcpy(oldLocalHostName, LocalHostName, + sizeof(oldLocalHostName)); + if (gethostname(LocalHostName, sizeof(LocalHostName))) + err(EX_OSERR, "gethostname failed"); + if ((p = strchr(LocalHostName, '.')) != NULL) { + *p++ = '\0'; + LocalDomain = p; + } else + LocalDomain = ""; + + /* * Close all open log files. */ Initialized = 0; @@ -1498,6 +1508,16 @@ logmsg(LOG_SYSLOG|LOG_INFO, "syslogd: restart", LocalHostName, ADDDATE); dprintf("syslogd: restarted\n"); + /* + * Log a change in hostname, but only on a restart. + */ + if (signo && strcmp(oldLocalHostName, LocalHostName)) { + snprintf(hostMsg, sizeof(hostMsg), + "syslogd: hostname changed, \"%s\" to \"%s\"", + oldLocalHostName, LocalHostName); + logmsg(LOG_SYSLOG|LOG_INFO, hostMsg, LocalHostName, ADDDATE); + dprintf("%s\n", hostMsg); + } } /* -- Crist J. Clark cjclark@alum.mit.edu To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010822013841.A76483>