Blame SOURCES/0044-fix-io-functions-check_config-against-on-disk-conf.patch

343241
From 0e28840f5c3362d032f2f805cbbe6fbbaa217437 Mon Sep 17 00:00:00 2001
343241
From: Eric Garver <eric@garver.life>
343241
Date: Wed, 27 Oct 2021 13:58:27 -0400
343241
Subject: [PATCH 44/50] fix(io/functions): check_config against on disk conf
343241
343241
Before this change the runtime FirewallConfig() instance was used. This
343241
caused some permanent configuration issues to not be caught due to
343241
comparing against the runtime instances of all objects.
343241
343241
For example, two zones in permanent configuration may use the same
343241
interface (which is not valid), but if the runtime configuration does
343241
not have have these interface assignments then check_config() won't
343241
catch the issue since it compares against the runtime configuration.
343241
343241
Fix is to build a temporary FirewallConfig() instance for all the
343241
on-disk/permanent configuration.
343241
343241
(cherry picked from commit 35d4facc8962cd1b66bc245fe03f658d491e1061)
343241
(cherry picked from commit 55a799e872dc88b1341a6bc38af33e77dfedb72f)
343241
---
343241
 src/firewall/core/io/functions.py | 47 ++++++++++++++++++++++---------
343241
 1 file changed, 34 insertions(+), 13 deletions(-)
343241
343241
diff --git a/src/firewall/core/io/functions.py b/src/firewall/core/io/functions.py
343241
index 0c7b1886426c..35a7eaf8dec8 100644
343241
--- a/src/firewall/core/io/functions.py
343241
+++ b/src/firewall/core/io/functions.py
343241
@@ -24,6 +24,7 @@ import os
343241
 from firewall import config
343241
 from firewall.errors import FirewallError
343241
 
343241
+from firewall.core.fw_config import FirewallConfig
343241
 from firewall.core.io.zone import zone_reader
343241
 from firewall.core.io.service import service_reader
343241
 from firewall.core.io.ipset import ipset_reader
343241
@@ -34,26 +35,46 @@ from firewall.core.io.direct import Direct
343241
 from firewall.core.io.lockdown_whitelist import LockdownWhitelist
343241
 from firewall.core.io.firewalld_conf import firewalld_conf
343241
 
343241
-def check_config(fw=None):
343241
+def check_config(fw):
343241
+    fw_config = FirewallConfig(fw)
343241
     readers = {
343241
-        "ipset" : (ipset_reader, [config.FIREWALLD_IPSETS, config.ETC_FIREWALLD_IPSETS]),
343241
-        "helper" : (helper_reader, [config.FIREWALLD_HELPERS, config.ETC_FIREWALLD_HELPERS]),
343241
-        "icmptype" : (icmptype_reader, [config.FIREWALLD_ICMPTYPES, config.ETC_FIREWALLD_ICMPTYPES]),
343241
-        "service" : (service_reader, [config.FIREWALLD_SERVICES, config.ETC_FIREWALLD_SERVICES]),
343241
-        "zone" : (zone_reader, [config.FIREWALLD_ZONES, config.ETC_FIREWALLD_ZONES]),
343241
-        "policy" : (policy_reader, [config.FIREWALLD_POLICIES, config.ETC_FIREWALLD_POLICIES]),
343241
+        "ipset":    {"reader": ipset_reader,
343241
+                     "add": fw_config.add_ipset,
343241
+                     "dirs": [config.FIREWALLD_IPSETS, config.ETC_FIREWALLD_IPSETS],
343241
+                    },
343241
+        "helper":   {"reader": helper_reader,
343241
+                     "add": fw_config.add_helper,
343241
+                     "dirs": [config.FIREWALLD_HELPERS, config.ETC_FIREWALLD_HELPERS],
343241
+                    },
343241
+        "icmptype": {"reader": icmptype_reader,
343241
+                     "add": fw_config.add_icmptype,
343241
+                     "dirs": [config.FIREWALLD_ICMPTYPES, config.ETC_FIREWALLD_ICMPTYPES],
343241
+                    },
343241
+        "service":  {"reader": service_reader,
343241
+                     "add": fw_config.add_service,
343241
+                     "dirs": [config.FIREWALLD_SERVICES, config.ETC_FIREWALLD_SERVICES],
343241
+                    },
343241
+        "zone":     {"reader": zone_reader,
343241
+                     "add": fw_config.add_zone,
343241
+                     "dirs": [config.FIREWALLD_ZONES, config.ETC_FIREWALLD_ZONES],
343241
+                    },
343241
+        "policy":   {"reader": policy_reader,
343241
+                     "add": fw_config.add_policy_object,
343241
+                     "dirs": [config.FIREWALLD_POLICIES, config.ETC_FIREWALLD_POLICIES],
343241
+                    },
343241
     }
343241
     for reader in readers.keys():
343241
-        for dir in readers[reader][1]:
343241
-            if not os.path.isdir(dir):
343241
+        for _dir in readers[reader]["dirs"]:
343241
+            if not os.path.isdir(_dir):
343241
                 continue
343241
-            for file in sorted(os.listdir(dir)):
343241
+            for file in sorted(os.listdir(_dir)):
343241
                 if file.endswith(".xml"):
343241
                     try:
343241
-                        obj = readers[reader][0](file, dir)
343241
-                        if fw and reader in ["zone", "policy"]:
343241
-                            obj.fw_config = fw.config
343241
+                        obj = readers[reader]["reader"](file, _dir)
343241
+                        if reader in ["zone", "policy"]:
343241
+                            obj.fw_config = fw_config
343241
                         obj.check_config(obj.export_config())
343241
+                        readers[reader]["add"](obj)
343241
                     except FirewallError as error:
343241
                         raise FirewallError(error.code, "'%s': %s" % (file, error.msg))
343241
                     except Exception as msg:
343241
-- 
343241
2.27.0
343241