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

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