Blame SOURCES/rsyslog-8.1911.0-rhbz1659383-config-enabled-error.patch

9e14e3
From ba5b68be84888b24918dd019b87ed9f62d7fa988 Mon Sep 17 00:00:00 2001
9e14e3
From: Jiri Vymazal <jvymazal@redhat.com>
9e14e3
Date: Tue, 11 Feb 2020 13:46:23 +0100
9e14e3
Subject: [PATCH] Fixed processing of 'cofig.enabled' directive
937096
9e14e3
Previously the directive was processed way too late which caused
9e14e3
false errors whenever it was set to 'off' and possibly other
9e14e3
problems.
937096
---
9e14e3
 grammar/rainerscript.c | 43+++++++++++++++++++++++----------------
9e14e3
 grammar/rainerscript.h |  1 +
9e14e3
 runtime/rsconf.c       | 10 +++++++++
9e14e3
 3 files changed, 38 insertions(+), 18 deletions(-)
937096
937096
diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c
9e14e3
index 8f14bbe319..4398e6011a 100644
937096
--- a/grammar/rainerscript.c
937096
+++ b/grammar/rainerscript.c
9e14e3
@@ -699,6 +699,22 @@ nvlstFindNameCStr(struct nvlst *lst, const char *const __restrict__ name)
9e14e3
 	return lst;
9e14e3
 }
9e14e3
 
9e14e3
+/* check if the nvlst is disabled, and mark config.enabled directive
9e14e3
+ * as used if it is not. Returns 1 if block is disabled, 0 otherwise.
9e14e3
+ */
9e14e3
+int nvlstChkDisabled(struct nvlst *lst)
9e14e3
+{
9e14e3
+	struct nvlst *valnode;
9e14e3
+
9e14e3
+	if((valnode = nvlstFindNameCStr(lst, "config.enabled")) != NULL) {
9e14e3
+		lst->bUsed = 1;
9e14e3
+		if(es_strbufcmp(valnode->val.d.estr, (unsigned char*) "on", 2)) {
9e14e3
+			return 1;
9e14e3
+		}
9e14e3
+	}
9e14e3
+	return 0;
9e14e3
+}
9e14e3
+
9e14e3
 
9e14e3
 /* check if there are duplicate names inside a nvlst and emit
9e14e3
  * an error message, if so.
9e14e3
@@ -1207,21 +1224,6 @@ nvlstGetParams(struct nvlst *lst, struct cnfparamblk *params,
937096
 		}
937096
 	}
937096
 
9e14e3
-	/* now config-system parameters (currently a bit hackish, as we
9e14e3
-	 * only have one...). -- rgerhards, 2018-01-24
9e14e3
-	 */
9e14e3
-	if((valnode = nvlstFindNameCStr(lst, "config.enabled")) != NULL) {
9e14e3
-		if(es_strbufcmp(valnode->val.d.estr, (unsigned char*) "on", 2)) {
9e14e3
-			dbgprintf("config object disabled by configuration\n");
9e14e3
-			/* flag all params as used to not emit error mssages */
9e14e3
-			bInError = 1;
9e14e3
-			struct nvlst *val;
9e14e3
-			for(val = lst; val != NULL ; val = val->next) {
9e14e3
-				val->bUsed = 1;
9e14e3
-			}
9e14e3
-		}
9e14e3
-	}
9e14e3
-
9e14e3
 	/* done parameter processing */
9e14e3
 	if(bInError) {
9e14e3
 		if(bValsWasNULL)
9e14e3
@@ -4418,8 +4418,13 @@ cnfstmtNewAct(struct nvlst *lst)
9e14e3
 	struct cnfstmt* cnfstmt;
9e14e3
 	char namebuf[256];
9e14e3
 	rsRetVal localRet;
9e14e3
-	if((cnfstmt = cnfstmtNew(S_ACT)) == NULL)
9e14e3
+	if((cnfstmt = cnfstmtNew(S_ACT)) == NULL) {
9e14e3
 		goto done;
9e14e3
+	}
9e14e3
+	if (nvlstChkDisabled(lst)) {
9e14e3
+		dbgprintf("action disabled by configuration\n");
9e14e3
+		cnfstmt->nodetype = S_NOP;
9e14e3
+	}
9e14e3
 	localRet = actionNewInst(lst, &cnfstmt->d.act);
9e14e3
 	if(localRet == RS_RET_OK_WARN) {
9e14e3
 		parser_errmsg("warnings occured in file '%s' around line %d",
9e14e3
@@ -5284,6 +5289,11 @@ includeProcessCnf(struct nvlst *const lst)
9e14e3
 		goto done;
9e14e3
 	}
9e14e3
 
9e14e3
+	if (nvlstChkDisabled(lst)) {
9e14e3
+		DBGPRINTF("include statement disabled\n");
9e14e3
+		goto done;
9e14e3
+	}
9e14e3
+
9e14e3
 	pvals = nvlstGetParams(lst, &incpblk, NULL);
9e14e3
 	if(pvals == NULL) {
9e14e3
 		goto done;
9e14e3
diff --git a/grammar/rainerscript.h b/grammar/rainerscript.h
9e14e3
index bfa8ee6cb9..0f8128861b 100644
9e14e3
--- a/grammar/rainerscript.h
9e14e3
+++ b/grammar/rainerscript.h
9e14e3
@@ -340,6 +340,7 @@ void nvlstDestruct(struct nvlst *lst);
9e14e3
 void nvlstPrint(struct nvlst *lst);
9e14e3
 void nvlstChkUnused(struct nvlst *lst);
9e14e3
 struct nvlst* nvlstFindName(struct nvlst *lst, es_str_t *name);
9e14e3
+int nvlstChkDisabled(struct nvlst *lst);
9e14e3
 struct cnfobj* cnfobjNew(enum cnfobjType objType, struct nvlst *lst);
9e14e3
 void cnfobjDestruct(struct cnfobj *o);
9e14e3
 void cnfobjPrint(struct cnfobj *o);
9e14e3
diff --git a/runtime/rsconf.c b/runtime/rsconf.c
9e14e3
index fc0863a738..303e06365b 100644
9e14e3
--- a/runtime/rsconf.c
9e14e3
+++ b/runtime/rsconf.c
9e14e3
@@ -438,6 +438,16 @@ cnfDoObj(struct cnfobj *const o)
9e14e3
 
9e14e3
 	dbgprintf("cnf:global:obj: ");
9e14e3
 	cnfobjPrint(o);
9e14e3
+
9e14e3
+	/* We need to check for object disabling as early as here to cover most
9e14e3
+	 * of them at once and avoid needless initializations
9e14e3
+	 * - jvymazal 2020-02-12
9e14e3
+	 */
9e14e3
+	if (nvlstChkDisabled(o->nvlst)) {
9e14e3
+		dbgprintf("object disabled by configuration\n");
9e14e3
+		return;
9e14e3
+	}
9e14e3
+
9e14e3
 	switch(o->objType) {
9e14e3
 	case CNFOBJ_GLOBAL:
9e14e3
 		glblProcessCnf(o);