Skip to content

Commit

Permalink
core bugfix: rsyslog messages may not always have FQDN
Browse files Browse the repository at this point in the history
Even if hostname FQDN is configured, rsyslog internal messages generated
after rsyslog startup and before the first HUP will not necessarily have
FQDN but instead only the shortname of the local host. This commit
fixes the situation.

Special thanks to github user eciii for doing a great bug analysis
and helping us considerably to fix the issue.

closes #5218
  • Loading branch information
rgerhards committed Dec 6, 2023
1 parent 0d1e6af commit f886d1f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions runtime/glbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* Module begun 2008-04-16 by Rainer Gerhards
*
* Copyright 2008-2022 Rainer Gerhards and Adiscon GmbH.
* Copyright 2008-2023 Rainer Gerhards and Adiscon GmbH.
*
* This file is part of the rsyslog runtime library.
*
Expand Down Expand Up @@ -1447,7 +1447,7 @@ glblDoneLoadCnf(void)
* hostname. These messages are currently in iminternal queue. Once they
* are taken from that queue, the hostname will be adapted.
*/
queryLocalHostname();
queryLocalHostname(loadConf);
RETiRet;
}

Expand Down
4 changes: 2 additions & 2 deletions runtime/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ cvthname(struct sockaddr_storage *f, prop_t **localName, prop_t **fqdn, prop_t *
*/
#define EMPTY_HOSTNAME_REPLACEMENT "localhost-empty-hostname"
static rsRetVal
getLocalHostname(uchar **ppName)
getLocalHostname(rsconf_t *const pConf, uchar **ppName)
{
DEFiRet;
char hnbuf[8192];
Expand All @@ -1183,7 +1183,7 @@ getLocalHostname(uchar **ppName)

char *dot = strstr(hnbuf, ".");
struct addrinfo *res = NULL;
if(!empty_hostname && dot == NULL && runConf != NULL && !glbl.GetDisableDNS(runConf)) {
if(!empty_hostname && dot == NULL && pConf != NULL && !glbl.GetDisableDNS(pConf)) {
/* we need to (try) to find the real name via resolver */
struct addrinfo flags;
memset(&flags, 0, sizeof(flags));
Expand Down
2 changes: 1 addition & 1 deletion runtime/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ BEGINinterface(net) /* name must also be changed in ENDinterface macro! */
int ipfreebind, char *device);
void (*closeUDPListenSockets)(int *finet);
int (*isAllowedSender)(uchar *pszType, struct sockaddr *pFrom, const char *pszFromHost); /* deprecated! */
rsRetVal (*getLocalHostname)(uchar**);
rsRetVal (*getLocalHostname)(rsconf_t *const, uchar**);
int (*should_use_so_bsdcompat)(void);
/* permitted peer handling should be replaced by something better (see comments above) */
rsRetVal (*AddPermittedPeer)(permittedPeers_t **ppRootPeer, uchar *pszID);
Expand Down
2 changes: 1 addition & 1 deletion runtime/rsconf.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* The rsconf object. It models a complete rsyslog configuration.
*
* Copyright 2011-2022 Rainer Gerhards and Adiscon GmbH.
* Copyright 2011-2023 Rainer Gerhards and Adiscon GmbH.
*
* This file is part of the rsyslog runtime library.
*
Expand Down
4 changes: 2 additions & 2 deletions runtime/rsyslog.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Begun 2005-09-15 RGerhards
*
* Copyright (C) 2005-2019 by Rainer Gerhards and Adiscon GmbH
* Copyright (C) 2005-2023 by Rainer Gerhards and Adiscon GmbH
*
* This file is part of the rsyslog runtime library.
*
Expand Down Expand Up @@ -782,7 +782,7 @@ rsRetVal rsrtExit(void);
int rsrtIsInit(void);
void rsrtSetErrLogger(void (*errLogger)(const int, const int, const uchar*));
void dfltErrLogger(const int, const int, const uchar *errMsg);
rsRetVal queryLocalHostname(void);
rsRetVal queryLocalHostname(rsconf_t *const);


/* this define below is (later) intended to be used to implement empty
Expand Down
9 changes: 6 additions & 3 deletions tools/rsyslogd.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,18 @@ get_bHadHUP(void)
return ret;
}

/* we need a pointer to the conf, because in early startup stage we
* need to use loadConf, later on runConf.
*/
rsRetVal
queryLocalHostname(void)
queryLocalHostname(rsconf_t *const pConf)
{
uchar *LocalHostName = NULL;
uchar *LocalDomain = NULL;
uchar *LocalFQDNName;
DEFiRet;

CHKiRet(net.getLocalHostname(&LocalFQDNName));
CHKiRet(net.getLocalHostname(pConf, &LocalFQDNName));
uchar *dot = (uchar*) strstr((char*)LocalFQDNName, ".");
if(dot == NULL) {
CHKmalloc(LocalHostName = (uchar*) strdup((char*)LocalFQDNName));
Expand Down Expand Up @@ -1956,7 +1959,7 @@ doHUP(void)
logmsgInternal(NO_ERRCODE, LOG_SYSLOG|LOG_INFO, (uchar*)buf, 0);
}

queryLocalHostname(); /* re-read our name */
queryLocalHostname(runConf); /* re-read our name */
ruleset.IterateAllActions(ourConf, doHUPActions, NULL);
DBGPRINTF("doHUP: doing modules\n");
modDoHUP();
Expand Down

0 comments on commit f886d1f

Please sign in to comment.