Blame SOURCES/rsyslog-8.24.0-rhbz1309698-imudp-case-sensitive-option.patch

ff08e8
From 9ac54f0d7d70b8a9879889b4522a1d552fca1100 Mon Sep 17 00:00:00 2001
ff08e8
From: Noriko Hosoi <nhosoi@momo7.localdomain>
ff08e8
Date: Thu, 12 Jul 2018 11:52:04 -0700
ff08e8
Subject: [PATCH] Introducing an option preservecase to imudp and imtcp module
ff08e8
 for managing the case of FROMHOST value.
ff08e8
ff08e8
Usage:
ff08e8
module(load="imudp" [preservecase="on"|"off"])
ff08e8
module(load="imtdp" [preservecase="on"|"off"])
ff08e8
ff08e8
If preservecase="on", FROMHOST value is handled in the case sensitive manner.
ff08e8
If preservecase="off", FROMHOST value is handled in the case insensitive manner.
ff08e8
ff08e8
To maintain the current behaviour, the default value of preservecase is
ff08e8
"on" for imtcp and "off" for imudp.
ff08e8
ff08e8
Incremented tcpsrvCURR_IF_VERSION by 1.
ff08e8
ff08e8
References:
ff08e8
https://github.com/rsyslog/rsyslog/pull/2774
ff08e8
https://bugzilla.redhat.com/show_bug.cgi?id=1309698
ff08e8
---
ff08e8
 plugins/imtcp/imtcp.c | 14 ++++++++++++--
ff08e8
 plugins/imudp/imudp.c | 15 ++++++++++++---
ff08e8
 runtime/msg.c         |  6 +++++-
ff08e8
 runtime/msg.h         |  2 ++
ff08e8
 runtime/net.c         |  2 +-
ff08e8
 runtime/tcpsrv.c      | 21 +++++++++++++++++++++
ff08e8
 runtime/tcpsrv.h      |  5 ++++-
ff08e8
 7 files changed, 57 insertions(+), 8 deletions(-)
ff08e8
ff08e8
diff --git a/plugins/imtcp/imtcp.c b/plugins/imtcp/imtcp.c
ff08e8
index 8e3dcc0a21..45fa240b59 100644
ff08e8
--- a/plugins/imtcp/imtcp.c
ff08e8
+++ b/plugins/imtcp/imtcp.c
ff08e8
@@ -100,6 +100,7 @@ static struct configSettings_s {
ff08e8
 	int iAddtlFrameDelim;
ff08e8
 	int bDisableLFDelim;
ff08e8
 	int bUseFlowControl;
ff08e8
+	int bPreserveCase;
ff08e8
 	uchar *pszStrmDrvrAuthMode;
ff08e8
 	uchar *pszInputName;
ff08e8
 	uchar *pszBindRuleset;
ff08e8
@@ -144,6 +145,7 @@ struct modConfData_s {
ff08e8
 	uchar *pszStrmDrvrAuthMode; /* authentication mode to use */
ff08e8
 	struct cnfarray *permittedPeers;
ff08e8
 	sbool configSetViaV2Method;
ff08e8
+	sbool bPreserveCase; /* preserve case of fromhost; true by default */
ff08e8
 };
ff08e8
 
ff08e8
 static modConfData_t *loadModConf = NULL;/* modConf ptr to use for the current load process */
ff08e8
@@ -169,7 +171,8 @@ static struct cnfparamdescr modpdescr[] = {
ff08e8
	{ "keepalive", eCmdHdlrBinary, 0 },
ff08e8
 	{ "keepalive.probes", eCmdHdlrPositiveInt, 0 },
ff08e8
 	{ "keepalive.time", eCmdHdlrPositiveInt, 0 },
ff08e8
-	{ "keepalive.interval", eCmdHdlrPositiveInt, 0 }
ff08e8
+	{ "keepalive.interval", eCmdHdlrPositiveInt, 0 },
ff08e8
+	{ "preservecase", eCmdHdlrBinary, 0 }
ff08e8
 };
ff08e8
 static struct cnfparamblk modpblk =
ff08e8
 	{ CNFPARAMBLK_VERSION,
ff08e8
@@ -375,6 +378,7 @@ addListner(modConfData_t *modConf, instanceConf_t *inst)
ff08e8
 		if(pPermPeersRoot != NULL) {
ff08e8
 			CHKiRet(tcpsrv.SetDrvrPermPeers(pOurTcpsrv, pPermPeersRoot));
ff08e8
 		}
ff08e8
+		CHKiRet(tcpsrv.SetPreserveCase(pOurTcpsrv, modConf->bPreserveCase));
ff08e8
 	}
ff08e8
 
ff08e8
 	/* initialized, now add socket and listener params */
ff08e8
@@ -473,6 +477,7 @@ CODESTARTbeginCnfLoad
ff08e8
 	loadModConf->pszStrmDrvrAuthMode = NULL;
ff08e8
 	loadModConf->permittedPeers = NULL;
ff08e8
 	loadModConf->configSetViaV2Method = 0;
ff08e8
+	loadModConf->bPreserveCase = 1; /* default to true */
ff08e8
 	bLegacyCnfModGlobalsPermitted = 1;
ff08e8
 	/* init legacy config variables */
ff08e8
 	cs.pszStrmDrvrAuthMode = NULL;
ff08e8
@@ -543,6 +548,8 @@ CODESTARTsetModCnf
ff08e8
 			loadModConf->pszStrmDrvrName = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL);
ff08e8
 		} else if(!strcmp(modpblk.descr[i].name, "permittedpeer")) {
ff08e8
 			loadModConf->permittedPeers = cnfarrayDup(pvals[i].val.d.ar);
ff08e8
+		} else if(!strcmp(modpblk.descr[i].name, "preservecase")) {
ff08e8
+			loadModConf->bPreserveCase = (int) pvals[i].val.d.n;
ff08e8
 		} else {
ff08e8
 			dbgprintf("imtcp: program error, non-handled "
ff08e8
 			  "param '%s' in beginCnfLoad\n", modpblk.descr[i].name);
ff08e8
@@ -584,6 +591,7 @@ CODESTARTendCnfLoad
ff08e8
 			loadModConf->pszStrmDrvrAuthMode = cs.pszStrmDrvrAuthMode;
ff08e8
 			cs.pszStrmDrvrAuthMode = NULL;
ff08e8
 		}
ff08e8
+		pModConf->bPreserveCase = cs.bPreserveCase;
ff08e8
 	}
ff08e8
 	free(cs.pszStrmDrvrAuthMode);
ff08e8
 	cs.pszStrmDrvrAuthMode = NULL;
ff08e8
@@ -731,6 +739,7 @@ resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unus
ff08e8
 	cs.pszInputName = NULL;
ff08e8
 	free(cs.pszStrmDrvrAuthMode);
ff08e8
 	cs.pszStrmDrvrAuthMode = NULL;
ff08e8
+	cs.bPreserveCase = 1;
ff08e8
 	return RS_RET_OK;
ff08e8
 }
ff08e8
 
ff08e8
@@ -797,7 +806,8 @@ CODEmodInit_QueryRegCFSLineHdlr
ff08e8
 			   NULL, &cs.bEmitMsgOnClose, STD_LOADABLE_MODULE_ID, &bLegacyCnfModGlobalsPermitted));
ff08e8
 	CHKiRet(regCfSysLineHdlr2(UCHAR_CONSTANT("inputtcpserverstreamdrivermode"), 0, eCmdHdlrInt,
ff08e8
 			   NULL, &cs.iStrmDrvrMode, STD_LOADABLE_MODULE_ID, &bLegacyCnfModGlobalsPermitted));
ff08e8
-
ff08e8
+	CHKiRet(regCfSysLineHdlr2(UCHAR_CONSTANT("inputtcpserverpreservecase"), 1, eCmdHdlrBinary,
ff08e8
+			   NULL, &cs.bPreserveCase, STD_LOADABLE_MODULE_ID, &bLegacyCnfModGlobalsPermitted));
ff08e8
 	CHKiRet(omsdRegCFSLineHdlr(UCHAR_CONSTANT("resetconfigvariables"), 1, eCmdHdlrCustomHandler,
ff08e8
 				   resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID));
ff08e8
 ENDmodInit
ff08e8
diff --git a/plugins/imudp/imudp.c b/plugins/imudp/imudp.c
ff08e8
index 51a9d712a0..74437781ca 100644
ff08e8
--- a/plugins/imudp/imudp.c
ff08e8
+++ b/plugins/imudp/imudp.c
ff08e8
@@ -152,6 +152,7 @@ struct modConfData_s {
ff08e8
 	int batchSize;			/* max nbr of input batch --> also recvmmsg() max count */
ff08e8
 	int8_t wrkrMax;			/* max nbr of worker threads */
ff08e8
 	sbool configSetViaV2Method;
ff08e8
+	sbool bPreserveCase;	/* preserves the case of fromhost; "off" by default */
ff08e8
 };
ff08e8
 static modConfData_t *loadModConf = NULL;/* modConf ptr to use for the current load process */
ff08e8
 static modConfData_t *runModConf = NULL;/* modConf ptr to use for the current load process */
ff08e8
@@ -162,7 +163,8 @@ static struct cnfparamdescr modpdescr[] = {
ff08e8
 	{ "schedulingpriority", eCmdHdlrInt, 0 },
ff08e8
 	{ "batchsize", eCmdHdlrInt, 0 },
ff08e8
 	{ "threads", eCmdHdlrPositiveInt, 0 },
ff08e8
-	{ "timerequery", eCmdHdlrInt, 0 }
ff08e8
+	{ "timerequery", eCmdHdlrInt, 0 },
ff08e8
+	{ "preservecase", eCmdHdlrBinary, 0 }
ff08e8
 };
ff08e8
 static struct cnfparamblk modpblk =
ff08e8
 	{ CNFPARAMBLK_VERSION,
ff08e8
@@ -447,8 +449,12 @@ processPacket(struct lstn_s *lstn, struct sockaddr_storage *frominetPrev, int *p
ff08e8
 		if(lstn->dfltTZ != NULL)
ff08e8
 			MsgSetDfltTZ(pMsg, (char*) lstn->dfltTZ);
ff08e8
 		pMsg->msgFlags  = NEEDS_PARSING | PARSE_HOSTNAME | NEEDS_DNSRESOL;
ff08e8
-		if(*pbIsPermitted == 2)
ff08e8
-			pMsg->msgFlags  |= NEEDS_ACLCHK_U; /* request ACL check after resolution */
ff08e8
+		if(*pbIsPermitted == 2) {
ff08e8
+			pMsg->msgFlags |= NEEDS_ACLCHK_U; /* request ACL check after resolution */
ff08e8
+		}
ff08e8
+		if(runModConf->bPreserveCase) {
ff08e8
+			pMsg->msgFlags |= PRESERVE_CASE; /* preserve case of fromhost */
ff08e8
+		}
ff08e8
 		CHKiRet(msgSetFromSockinfo(pMsg, frominet));
ff08e8
 		CHKiRet(ratelimitAddMsg(lstn->ratelimiter, multiSub, pMsg));
ff08e8
 		STATSCOUNTER_INC(lstn->ctrSubmit, lstn->mutCtrSubmit);
ff08e8
@@ -1030,6 +1036,7 @@ CODESTARTbeginCnfLoad
ff08e8
 	loadModConf->iTimeRequery = TIME_REQUERY_DFLT;
ff08e8
 	loadModConf->iSchedPrio = SCHED_PRIO_UNSET;
ff08e8
 	loadModConf->pszSchedPolicy = NULL;
ff08e8
+	loadModConf->bPreserveCase = 0; /* off */
ff08e8
 	bLegacyCnfModGlobalsPermitted = 1;
ff08e8
 	/* init legacy config vars */
ff08e8
 	cs.pszBindRuleset = NULL;
ff08e8
@@ -1079,6 +1086,8 @@ CODESTARTsetModCnf
ff08e8
 			} else {
ff08e8
 				loadModConf->wrkrMax = wrkrMax;
ff08e8
 			}
ff08e8
+		} else if(!strcmp(modpblk.descr[i].name, "preservecase")) {
ff08e8
+			loadModConf->bPreserveCase = (int) pvals[i].val.d.n;
ff08e8
 		} else {
ff08e8
 			dbgprintf("imudp: program error, non-handled "
ff08e8
 			  "param '%s' in beginCnfLoad\n", modpblk.descr[i].name);
ff08e8
diff --git a/runtime/msg.c b/runtime/msg.c
ff08e8
index c43f813142..9ed4eaf84d 100644
ff08e8
--- a/runtime/msg.c
ff08e8
+++ b/runtime/msg.c
ff08e8
@@ -506,7 +506,11 @@ resolveDNS(smsg_t * const pMsg) {
ff08e8
 	MsgLock(pMsg);
ff08e8
 	CHKiRet(objUse(net, CORE_COMPONENT));
ff08e8
 	if(pMsg->msgFlags & NEEDS_DNSRESOL) {
ff08e8
-		localRet = net.cvthname(pMsg->rcvFrom.pfrominet, &localName, NULL, &ip);
ff08e8
+		if (pMsg->msgFlags & PRESERVE_CASE) {
ff08e8
+			localRet = net.cvthname(pMsg->rcvFrom.pfrominet, NULL, &localName, &ip);
ff08e8
+		} else {
ff08e8
+			localRet = net.cvthname(pMsg->rcvFrom.pfrominet, &localName, NULL, &ip);
ff08e8
+		}
ff08e8
 		if(localRet == RS_RET_OK) {
ff08e8
 			/* we pass down the props, so no need for AddRef */
ff08e8
 			MsgSetRcvFromWithoutAddRef(pMsg, localName);
ff08e8
diff --git a/runtime/msg.h b/runtime/msg.h
ff08e8
index cd530aca38..1287cb7a4b 100644
ff08e8
--- a/runtime/msg.h
ff08e8
+++ b/runtime/msg.h
ff08e8
@@ -144,6 +144,7 @@  struct msg {
ff08e8
 #define NEEDS_DNSRESOL	0x040	/* fromhost address is unresolved and must be locked up via DNS reverse lookup first */
ff08e8
 #define NEEDS_ACLCHK_U	0x080	/* check UDP ACLs after DNS resolution has been done in main queue consumer */
ff08e8
 #define NO_PRI_IN_RAW	0x100	/* rawmsg does not include a PRI (Solaris!), but PRI is already set correctly in the msg object */
ff08e8
+#define PRESERVE_CASE	0x200	/* preserve case in fromhost */
ff08e8
 
ff08e8
 /* (syslog) protocol types */
ff08e8
 #define MSG_LEGACY_PROTOCOL 0
ff08e8
diff --git a/runtime/net.c b/runtime/net.c
ff08e8
index d6ff8a3d4d..aef906601c 100644
ff08e8
--- a/runtime/net.c
ff08e8
+++ b/runtime/net.c
ff08e8
@@ -1152,7 +1152,7 @@ cvthname(struct sockaddr_storage *f, prop_t **localName, prop_t **fqdn, prop_t *
ff08e8
 {
ff08e8
 	DEFiRet;
ff08e8
 	assert(f != NULL);
ff08e8
-	iRet = dnscacheLookup(f, NULL, fqdn, localName, ip);
ff08e8
+	iRet = dnscacheLookup(f, fqdn, NULL, localName, ip);
ff08e8
 	RETiRet;
ff08e8
 }
ff08e8
 
ff08e8
diff --git a/runtime/tcpsrv.c b/runtime/tcpsrv.c
ff08e8
index 61e9ff4d22..d5993b4f00 100644
ff08e8
--- a/runtime/tcpsrv.c
ff08e8
+++ b/runtime/tcpsrv.c
ff08e8
@@ -495,6 +495,15 @@ SessAccept(tcpsrv_t *pThis, tcpLstnPortList_t *pLstnInfo, tcps_sess_t **ppSess,
ff08e8
 
ff08e8
 	/* get the host name */
ff08e8
 	CHKiRet(netstrm.GetRemoteHName(pNewStrm, &fromHostFQDN));
ff08e8
+	if (!pThis->bPreserveCase) {
ff08e8
+		/* preserve_case = off */
ff08e8
+		uchar *p;
ff08e8
+		for(p = fromHostFQDN; *p; p++) {
ff08e8
+			if (isupper((int) *p)) {
ff08e8
+				*p = tolower((int) *p);
ff08e8
+			}
ff08e8
+		}
ff08e8
+	}
ff08e8
 	CHKiRet(netstrm.GetRemoteIP(pNewStrm, &fromHostIP));
ff08e8
 	CHKiRet(netstrm.GetRemAddr(pNewStrm, &addr));
ff08e8
 	/* TODO: check if we need to strip the domain name here -- rgerhards, 2008-04-24 */
ff08e8
@@ -1001,6 +1010,7 @@ BEGINobjConstruct(tcpsrv) /* be sure to specify the object type also in END macr
ff08e8
 	pThis->ratelimitBurst = 10000;
ff08e8
 	pThis->bUseFlowControl = 1;
ff08e8
 	pThis->pszDrvrName = NULL;
ff08e8
+	pThis->bPreserveCase = 1; /* preserve case in fromhost; default to true. */
ff08e8
 ENDobjConstruct(tcpsrv)
ff08e8
 
ff08e8
 
ff08e8
@@ -1433,6 +1443,16 @@ SetSessMax(tcpsrv_t *pThis, int iMax)
ff08e8
 }
ff08e8
 
ff08e8
 
ff08e8
+static rsRetVal
ff08e8
+SetPreserveCase(tcpsrv_t *pThis, int bPreserveCase)
ff08e8
+{
ff08e8
+	DEFiRet;
ff08e8
+	ISOBJ_TYPE_assert(pThis, tcpsrv);
ff08e8
+	pThis-> bPreserveCase = bPreserveCase;
ff08e8
+	RETiRet;
ff08e8
+}
ff08e8
+
ff08e8
+
ff08e8
 /* queryInterface function
ff08e8
  * rgerhards, 2008-02-29
ff08e8
  */
ff08e8
@@ -1491,6 +1511,7 @@ CODESTARTobjQueryInterface(tcpsrv)
ff08e8
 	pIf->SetRuleset = SetRuleset;
ff08e8
 	pIf->SetLinuxLikeRatelimiters = SetLinuxLikeRatelimiters;
ff08e8
 	pIf->SetNotificationOnRemoteClose = SetNotificationOnRemoteClose;
ff08e8
+	pIf->SetPreserveCase = SetPreserveCase;
ff08e8
 
ff08e8
 finalize_it:
ff08e8
 ENDobjQueryInterface(tcpsrv)
ff08e8
diff --git a/runtime/tcpsrv.h b/runtime/tcpsrv.h
ff08e8
index 22a65c20a0..f17b1b4384 100644
ff08e8
--- a/runtime/tcpsrv.h
ff08e8
+++ b/runtime/tcpsrv.h
ff08e8
@@ -81,6 +81,7 @@  struct tcpsrv_s {
ff08e8
 
ff08e8
 	int addtlFrameDelim;	/**< additional frame delimiter for plain TCP syslog framing (e.g. to handle NetScreen) */
ff08e8
 	int bDisableLFDelim;	/**< if 1, standard LF frame delimiter is disabled (*very dangerous*) */
ff08e8
+	sbool bPreserveCase;	/**< preserve case in fromhost */
ff08e8
 	int ratelimitInterval;
ff08e8
 	int ratelimitBurst;
ff08e8
 	tcps_sess_t **pSessions;/**< array of all of our sessions */
ff08e8
@@ -168,8 +169,10 @@  BEGINinterface(tcpsrv) /* name must also be changed in ENDinterface macro! */
ff08e8
 	rsRetVal (*SetKeepAliveTime)(tcpsrv_t*, int);
ff08e8
 	/* added v18 */
ff08e8
 	rsRetVal (*SetbSPFramingFix)(tcpsrv_t*, sbool);
ff08e8
+	/* added v21 -- Preserve case in fromhost, 2018-08-16 */
ff08e8
+	rsRetVal (*SetPreserveCase)(tcpsrv_t *pThis, int bPreserveCase);
ff08e8
 ENDinterface(tcpsrv)
ff08e8
-#define tcpsrvCURR_IF_VERSION 18 /* increment whenever you change the interface structure! */
ff08e8
+#define tcpsrvCURR_IF_VERSION 21 /* increment whenever you change the interface structure! */
ff08e8
 /* change for v4:
ff08e8
  * - SetAddtlFrameDelim() added -- rgerhards, 2008-12-10
ff08e8
  * - SetInputName() added -- rgerhards, 2008-12-10