Gives syslogd(8) the ability to refresh its idea of the hostname of
the system on which it is running. The hostname is reloaded when 'HUPped' and a log message generated to note a change (before anyone points it out, this is not an added security feature). PR: bin/24444 Reviewed by: freebsd-audit Approved by: ru MFC after: 2 weeks
This commit is contained in:
parent
d626906b0c
commit
ba1cc9067d
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=82442
@ -318,7 +318,7 @@ main(argc, argv)
|
||||
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 @@ main(argc, argv)
|
||||
|
||||
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,9 +1340,25 @@ init(signo)
|
||||
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 != 0)
|
||||
(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.
|
||||
*/
|
||||
@ -1498,6 +1508,16 @@ init(signo)
|
||||
|
||||
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 != 0 && strcmp(oldLocalHostName, LocalHostName) != 0) {
|
||||
(void)snprintf(hostMsg, sizeof(hostMsg),
|
||||
"syslogd: hostname changed, \"%s\" to \"%s\"",
|
||||
oldLocalHostName, LocalHostName);
|
||||
logmsg(LOG_SYSLOG|LOG_INFO, hostMsg, LocalHostName, ADDDATE);
|
||||
dprintf("%s\n", hostMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user