From f886d1f1b2fcda9d9b72efdc15b387d3fc9b1f55 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 6 Dec 2023 17:11:20 +0100 Subject: [PATCH] core bugfix: rsyslog messages may not always have FQDN 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 https://github.com/rsyslog/rsyslog/issues/5218 Reference:https://github.com/rsyslog/rsyslog/commit/f886d1f1b2fcda9d9b72efdc15b387d3fc9b1f55 Conflict:NA --- runtime/glbl.c | 4 ++-- runtime/net.c | 4 ++-- runtime/net.h | 2 +- runtime/rsconf.h | 2 +- runtime/rsyslog.h | 4 ++-- tools/rsyslogd.c | 10 ++++++---- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/runtime/glbl.c b/runtime/glbl.c index a2e2545..3fdaeea 100644 --- a/runtime/glbl.c +++ b/runtime/glbl.c @@ -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. * @@ -1431,7 +1431,7 @@ finalize_it: * hostname. These messages are currently in iminternal queue. Once they * are taken from that queue, the hostname will be adapted. */ - queryLocalHostname(); + queryLocalHostname(loadConf); RETiRet; } diff --git a/runtime/net.c b/runtime/net.c index 8611125..ff46cbc 100644 --- a/runtime/net.c +++ b/runtime/net.c @@ -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]; @@ -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)); diff --git a/runtime/net.h b/runtime/net.h index c2847f6..88d2df5 100644 --- a/runtime/net.h +++ b/runtime/net.h @@ -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); diff --git a/runtime/rsconf.h b/runtime/rsconf.h index dd89b81..58f4212 100644 --- a/runtime/rsconf.h +++ b/runtime/rsconf.h @@ -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. * diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h index 2607506..b28d628 100644 --- a/runtime/rsyslog.h +++ b/runtime/rsyslog.h @@ -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. * @@ -781,7 +781,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 diff --git a/tools/rsyslogd.c b/tools/rsyslogd.c index cc3486e..a5548a3 100644 --- a/tools/rsyslogd.c +++ b/tools/rsyslogd.c @@ -237,16 +237,18 @@ setsid(void) } #endif - +/* 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)); @@ -1859,7 +1861,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(); -- 2.19.1