Esempio n. 1
0
 def test_generate_rndc_returns_configurations(self):
     rndc_content, named_content = generate_rndc()
     # rndc_content and named_content look right.
     self.assertIn('# Start of rndc.conf', rndc_content)
     self.assertIn('controls {', named_content)
     # named_content does not include any comment.
     self.assertNotIn('\n#', named_content)
Esempio n. 2
0
 def test_generate_rndc_returns_configurations(self):
     rndc_content, named_content = generate_rndc(
         include_default_controls=False)
     # rndc_content and named_content look right.
     self.assertIn("# Start of rndc.conf", rndc_content)
     self.assertIn("controls {", named_content)
     # named_content does not include any comment.
     self.assertNotIn("\n#", named_content)
Esempio n. 3
0
    def set_up_named(self, overwrite_config=True):
        """Setup an environment to run 'named'.

        - Creates the default configuration for 'named' and sets up rndc.
        - Copies the 'named' executable inside homedir.  AppArmor won't
          let us run the installed version the way we want.
        """
        # Generate rndc configuration (rndc config and named snippet).
        # Disable remote administration for init scripts by suppressing the
        # "controls" statement.
        rndcconf, namedrndcconf = generate_rndc(
            port=self.rndc_port,
            key_name="dnsfixture-rndc-key",
            include_default_controls=False,
        )
        # Write main BIND config file.
        if should_write(self.conf_file, overwrite_config):
            named_conf = self.NAMED_CONF_TEMPLATE.substitute(
                homedir=self.homedir,
                port=self.port,
                log_file=self.log_file,
                include_in_options=self.include_in_options,
                extra=namedrndcconf,
            )
            atomic_write(
                (GENERATED_HEADER + named_conf).encode("ascii"), self.conf_file
            )
        # Write rndc config file.
        if should_write(self.rndcconf_file, overwrite_config):
            atomic_write(
                (GENERATED_HEADER + rndcconf).encode("ascii"),
                self.rndcconf_file,
            )

        # Copy named executable to home dir.  This is done to avoid
        # the limitations imposed by apparmor if the executable
        # is in /usr/sbin/named.
        # named's apparmor profile prevents loading of zone and
        # configuration files from outside of a restricted set,
        # none of which an ordinary user has write access to.
        if should_write(self.named_file, overwrite_config):
            named_path = self.NAMED_PATH
            assert os.path.exists(named_path), (
                "'%s' executable not found.  Install the package "
                "'bind9' or define an environment variable named "
                "NAMED_PATH with the path where the 'named' "
                "executable can be found." % named_path
            )
            copy(named_path, self.named_file)
Esempio n. 4
0
    def set_up_named(self, overwrite_config=True):
        """Setup an environment to run 'named'.

        - Creates the default configuration for 'named' and sets up rndc.
        - Copies the 'named' executable inside homedir.  AppArmor won't
          let us run the installed version the way we want.
        """
        # Generate rndc configuration (rndc config and named snippet).
        # Disable remote administration for init scripts by suppressing the
        # "controls" statement.
        rndcconf, namedrndcconf = generate_rndc(
            port=self.rndc_port, key_name='dnsfixture-rndc-key',
            include_default_controls=False)
        # Write main BIND config file.
        if should_write(self.conf_file, overwrite_config):
            named_conf = (
                self.NAMED_CONF_TEMPLATE.substitute(
                    homedir=self.homedir, port=self.port,
                    log_file=self.log_file,
                    include_in_options=self.include_in_options,
                    extra=namedrndcconf))
            atomic_write(
                GENERATED_HEADER + named_conf, self.conf_file)
        # Write rndc config file.
        if should_write(self.rndcconf_file, overwrite_config):
            atomic_write(
                GENERATED_HEADER + rndcconf, self.rndcconf_file)

        # Copy named executable to home dir.  This is done to avoid
        # the limitations imposed by apparmor if the executable
        # is in /usr/sbin/named.
        # named's apparmor profile prevents loading of zone and
        # configuration files from outside of a restricted set,
        # none of which an ordinary user has write access to.
        if should_write(self.named_file, overwrite_config):
            named_path = self.NAMED_PATH
            assert os.path.exists(named_path), (
                "'%s' executable not found.  Install the package "
                "'bind9' or define an environment variable named "
                "NAMED_PATH with the path where the 'named' "
                "executable can be found." % named_path)
            copy(named_path, self.named_file)