Blame SOURCES/rsyslog-8.37.0-rhbz1614181-imtcp-imudp-preservecase-option.patch

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