Repository: cobbler/cobbler

Issue:
Wrong bind config for Debian
### Describe the bug

We use the wrong bind path in our settings.py:

```python
def autodetect_bind_chroot():
    """
    Autodetect bind chroot configuration
    """
    bind_config_filename = None
    if os.path.exists("/etc/sysconfig/named"):
        # RHEL/Fedora
        bind_config_filename = "/etc/sysconfig/named"
    else:
        # Debian
        bind_config_files = glob.glob("/etc/default/bind*")
        for filename in bind_config_files:
            if os.path.exists(filename):
                bind_config_filename = filename
    # Parse the config file if available
    if bind_config_filename:
        parse_bind_config(bind_config_filename)

```
The correct path according to the Debian wiki is `/etc/bind/`. Thanks @agraul!
Furthermore we should us the OS detection instead of checking if certain files exist.

### Expected behavior

The correct path should be used.

### Cobbler version

<!--- Paste output from `cobbler version` -->
Git master.


### Additional information

https://wiki.debian.org/Bind9#Configuration
<!--- Add any other context about the problem here. -->



Discussion:
This is a candidate for our pre-build shellscript because we can once at buildtime define the location and don't execute the check on every restart of Cobbler. After all the code currently in place is just thought for a reasonable default.

Resolving patch:
diff --git a/cobbler/settings/__init__.py b/cobbler/settings/__init__.py
--- a/cobbler/settings/__init__.py
+++ b/cobbler/settings/__init__.py
@@ -24,8 +24,6 @@
 from cobbler import utils
 from cobbler.settings import migrations
 
-BIND_CHROOT_PATH = ""
-
 
 class Settings:
     """
@@ -62,7 +60,7 @@ def __init__(self):
         self.authn_pam_service = "login"
         self.autoinstall_snippets_dir = "/var/lib/cobbler/snippets"
         self.autoinstall_templates_dir = "/var/lib/cobbler/templates"
-        self.bind_chroot_path = BIND_CHROOT_PATH
+        self.bind_chroot_path = ""
         self.bind_zonefile_path = "/var/lib/named"
         self.bind_master = "127.0.0.1"
         self.boot_loader_conf_template_dir = "/etc/cobbler/boot_loader_conf"
@@ -282,53 +280,6 @@ def validate_settings(settings_content: dict) -> dict:
     return migrations.normalize(settings_content)
 
 
-def parse_bind_config(configpath: str):
-    """
-    Parse the Bind9 configuration file and adjust the Cobbler default settings according to the readings.
-
-    :param configpath: The path in the filesystem where the file can be read.
-    """
-    global BIND_CHROOT_PATH
-    bind_config = {}
-    # When running as a webapp we can't access this, but don't need it
-    try:
-        bind_config_file = open(configpath, "r")
-    except (IOError, OSError):
-        pass
-    else:
-        for line in bind_config_file:
-            if re.match(r"[a-zA-Z]+=", line):
-                (name, value) = line.rstrip().split("=")
-                bind_config[name] = value.strip('"')
-        # RHEL, SysV Fedora
-        if "ROOTDIR" in bind_config:
-            BIND_CHROOT_PATH = bind_config["ROOTDIR"]
-        # Debian, Systemd Fedora
-        if "OPTIONS" in bind_config:
-            rootdirmatch = re.search(r"-t ([/\w]+)", bind_config["OPTIONS"])
-            if rootdirmatch is not None:
-                BIND_CHROOT_PATH = rootdirmatch.group(1)
-
-
-def autodetect_bind_chroot():
-    """
-    Autodetect bind chroot configuration
-    """
-    bind_config_filename = None
-    if os.path.exists("/etc/sysconfig/named"):
-        # RHEL/Fedora
-        bind_config_filename = "/etc/sysconfig/named"
-    else:
-        # Debian
-        bind_config_files = glob.glob("/etc/default/bind*")
-        for filename in bind_config_files:
-            if os.path.exists(filename):
-                bind_config_filename = filename
-    # Parse the config file if available
-    if bind_config_filename:
-        parse_bind_config(bind_config_filename)
-
-
 def read_yaml_file(filepath="/ect/cobbler/settings.yaml") -> Dict[Hashable, Any]:
     """
     Reads settings files from ``filepath`` and all paths in `include` (which is read from the settings file) and saves
@@ -433,7 +384,3 @@ def migrate(yaml_dict: dict, settings_path: Path) -> dict:
     :return: The migrated settings
     """
     return migrations.migrate(yaml_dict, settings_path)
-
-
-# Initialize Settings module for manipulating the global DEFAULTS variable
-autodetect_bind_chroot()


Test patch:
diff --git a/tests/settings/settings_test.py b/tests/settings/settings_test.py
--- a/tests/settings/settings_test.py
+++ b/tests/settings/settings_test.py
@@ -65,26 +65,6 @@ def test_validate_settings(parameter, expected_exception, expected_result):
         assert result == expected_result
 
 
-def test_parse_bind_config():
-    # Arrange
-
-    # Act
-    settings.parse_bind_config("/test_dir/tests/test_data/named.conf")
-
-    # Assert
-    assert True
-
-
-def test_autodect_bind_chroot():
-    # Arrange
-
-    # Act
-    settings.autodetect_bind_chroot()
-
-    # Assert
-    assert True
-
-
 def test_read_settings_file():
     # Arrange
     # Default path should be fine for the tests.
diff --git a/tests/test_data/V3_3_1/settings.yaml b/tests/test_data/V3_3_1/settings.yaml
--- a/tests/test_data/V3_3_1/settings.yaml
+++ b/tests/test_data/V3_3_1/settings.yaml
@@ -336,7 +336,7 @@ next_server_v6: "::1"
 manage_dns: false
 
 # set to path of bind chroot to create bind-chroot compatible bind
-# configuration files.  This should be automatically detected.
+# configuration files.
 bind_chroot_path: ""
 
 # set to path where zonefiles of bind/named server are located.