Пример #1
0
 def test_get_prefix(self):
     from certbot.plugins.util import get_prefixes
     self.assertEqual(
         get_prefixes('/a/b/c'),
         [os.path.normpath(path) for path in ['/a/b/c', '/a/b', '/a', '/']])
     self.assertEqual(get_prefixes('/'), [os.path.normpath('/')])
     self.assertEqual(get_prefixes('a'), ['a'])
Пример #2
0
 def test_get_prefix(self):
     from certbot.plugins.util import get_prefixes
     self.assertEqual(
         get_prefixes('/a/b/c'),
         [os.path.normpath(path) for path in ['/a/b/c', '/a/b', '/a', '/']])
     self.assertEqual(get_prefixes('/'), [os.path.normpath('/')])
     self.assertEqual(get_prefixes('a'), ['a'])
Пример #3
0
    def _create_challenge_dirs(self):
        path_map = self.conf("map")
        if not path_map:
            raise errors.PluginError(
                "Missing parts of webroot configuration; please set either "
                "--webroot-path and --domains, or --webroot-map. Run with "
                " --help webroot for examples.")
        for name, path in path_map.items():
            self.full_roots[name] = os.path.join(path, os.path.normcase(
                challenges.HTTP01.URI_ROOT_PATH))
            logger.debug("Creating root challenges validation dir at %s",
                         self.full_roots[name])

            # Change the permissions to be writable (GH #1389)
            # Umask is used instead of chmod to ensure the client can also
            # run as non-root (GH #1795)
            old_umask = filesystem.umask(0o022)
            try:
                # We ignore the last prefix in the next iteration,
                # as it does not correspond to a folder path ('/' or 'C:')
                for prefix in sorted(util.get_prefixes(self.full_roots[name])[:-1], key=len):
                    if os.path.isdir(prefix):
                        # Don't try to create directory if it already exists, as some filesystems
                        # won't reliably raise EEXIST or EISDIR if directory exists.
                        continue
                    try:
                        # Set owner as parent directory if possible, apply mode for Linux/Windows.
                        # For Linux, this is coupled with the "umask" call above because
                        # os.mkdir's "mode" parameter may not always work:
                        # https://docs.python.org/3/library/os.html#os.mkdir
                        filesystem.mkdir(prefix, 0o755)
                        self._created_dirs.append(prefix)
                        try:
                            filesystem.copy_ownership_and_apply_mode(
                                path, prefix, 0o755, copy_user=True, copy_group=True)
                        except (OSError, AttributeError) as exception:
                            logger.warning("Unable to change owner and uid of webroot directory")
                            logger.debug("Error was: %s", exception)
                    except OSError as exception:
                        raise errors.PluginError(
                            "Couldn't create root for {0} http-01 "
                            "challenge responses: {1}".format(name, exception))
            finally:
                filesystem.umask(old_umask)

            # On Windows, generate a local web.config file that allows IIS to serve expose
            # challenge files despite the fact they do not have a file extension.
            if not filesystem.POSIX_MODE:
                web_config_path = os.path.join(self.full_roots[name], "web.config")
                if os.path.exists(web_config_path):
                    logger.info("A web.config file has not been created in "
                                "%s because another one already exists.", self.full_roots[name])
                    continue
                logger.info("Creating a web.config file in %s to allow IIS "
                            "to serve challenge files.", self.full_roots[name])
                with safe_open(web_config_path, mode="w", chmod=0o644) as web_config:
                    web_config.write(_WEB_CONFIG_CONTENT)
Пример #4
0
    def _create_challenge_dirs(self):
        path_map = self.conf("map")
        if not path_map:
            raise errors.PluginError(
                "Missing parts of webroot configuration; please set either "
                "--webroot-path and --domains, or --webroot-map. Run with "
                " --help webroot for examples.")
        for name, path in path_map.items():
            self.full_roots[name] = os.path.join(
                path, challenges.HTTP01.URI_ROOT_PATH)
            logger.debug("Creating root challenges validation dir at %s",
                         self.full_roots[name])

            # Change the permissions to be writable (GH #1389)
            # Umask is used instead of chmod to ensure the client can also
            # run as non-root (GH #1795)
            old_umask = os.umask(0o022)
            try:
                # We ignore the last prefix in the next iteration,
                # as it does not correspond to a folder path ('/' or 'C:')
                for prefix in sorted(util.get_prefixes(
                        self.full_roots[name])[:-1],
                                     key=len):
                    try:
                        # Set owner as parent directory if possible, apply mode for Linux/Windows.
                        # For Linux, this is coupled with the "umask" call above because
                        # os.mkdir's "mode" parameter may not always work:
                        # https://docs.python.org/3/library/os.html#os.mkdir
                        filesystem.mkdir(prefix, 0o755)
                        self._created_dirs.append(prefix)
                        try:
                            filesystem.copy_ownership_and_apply_mode(
                                path,
                                prefix,
                                0o755,
                                copy_user=True,
                                copy_group=True)
                        except (OSError, AttributeError) as exception:
                            logger.info(
                                "Unable to change owner and uid of webroot directory"
                            )
                            logger.debug("Error was: %s", exception)
                    except OSError as exception:
                        if exception.errno not in (errno.EEXIST, errno.EISDIR):
                            raise errors.PluginError(
                                "Couldn't create root for {0} http-01 "
                                "challenge responses: {1}".format(
                                    name, exception))
            finally:
                os.umask(old_umask)
Пример #5
0
    def _create_challenge_dirs(self):
        path_map = self.conf("map")
        if not path_map:
            raise errors.PluginError(
                "Missing parts of webroot configuration; please set either "
                "--webroot-path and --domains, or --webroot-map. Run with "
                " --help webroot for examples.")
        for name, path in path_map.items():
            self.full_roots[name] = os.path.join(
                path, challenges.HTTP01.URI_ROOT_PATH)

            logger.debug("Creating root challenges validation dir at %s",
                         self.full_roots[name])

            # Change the permissions to be writable (GH #1389)
            # Umask is used instead of chmod to ensure the client can also
            # run as non-root (GH #1795)
            old_umask = os.umask(0o022)
            try:
                stat_path = os.stat(path)
                for prefix in sorted(util.get_prefixes(self.full_roots[name]),
                                     key=len):
                    try:
                        # This is coupled with the "umask" call above because
                        # os.mkdir's "mode" parameter may not always work:
                        # https://docs.python.org/3/library/os.html#os.mkdir
                        os.mkdir(prefix, 0o0755)
                        self._created_dirs.append(prefix)
                        # Set owner as parent directory if possible
                        try:
                            os.chown(prefix, stat_path.st_uid,
                                     stat_path.st_gid)
                        except OSError as exception:
                            logger.info(
                                "Unable to change owner and uid of webroot directory"
                            )
                            logger.debug("Error was: %s", exception)
                    except OSError as exception:
                        if exception.errno not in (errno.EEXIST, errno.EISDIR):
                            raise errors.PluginError(
                                "Couldn't create root for {0} http-01 "
                                "challenge responses: {1}".format(
                                    name, exception))
            finally:
                os.umask(old_umask)
Пример #6
0
    def _create_challenge_dirs(self):
        path_map = self.conf("map")
        if not path_map:
            raise errors.PluginError(
                "Missing parts of webroot configuration; please set either "
                "--webroot-path and --domains, or --webroot-map. Run with "
                " --help webroot for examples.")
        for name, path in path_map.items():
            self.full_roots[name] = os.path.join(path, challenges.HTTP01.URI_ROOT_PATH)
            logger.debug("Creating root challenges validation dir at %s",
                         self.full_roots[name])

            # Change the permissions to be writable (GH #1389)
            # Umask is used instead of chmod to ensure the client can also
            # run as non-root (GH #1795)
            old_umask = os.umask(0o022)
            try:
                stat_path = os.stat(path)
                # We ignore the last prefix in the next iteration,
                # as it does not correspond to a folder path ('/' or 'C:')
                for prefix in sorted(util.get_prefixes(self.full_roots[name])[:-1], key=len):
                    try:
                        # This is coupled with the "umask" call above because
                        # os.mkdir's "mode" parameter may not always work:
                        # https://docs.python.org/3/library/os.html#os.mkdir
                        os.mkdir(prefix, 0o0755)
                        self._created_dirs.append(prefix)
                        # Set owner as parent directory if possible
                        try:
                            os.chown(prefix, stat_path.st_uid, stat_path.st_gid)
                        except (OSError, AttributeError) as exception:
                            logger.info("Unable to change owner and uid of webroot directory")
                            logger.debug("Error was: %s", exception)
                    except OSError as exception:
                        if exception.errno not in (errno.EEXIST, errno.EISDIR):
                            raise errors.PluginError(
                                "Couldn't create root for {0} http-01 "
                                "challenge responses: {1}".format(name, exception))
            finally:
                os.umask(old_umask)
Пример #7
0
 def test_get_prefix(self):
     from certbot.plugins.util import get_prefixes
     self.assertEqual(get_prefixes('/a/b/c'), ['/a/b/c', '/a/b', '/a', '/'])
     self.assertEqual(get_prefixes('/'), ['/'])
     self.assertEqual(get_prefixes('a'), ['a'])
Пример #8
0
 def test_get_prefix(self):
     from certbot.plugins.util import get_prefixes
     self.assertEqual(get_prefixes('/a/b/c'), ['/a/b/c', '/a/b', '/a', '/'])
     self.assertEqual(get_prefixes('/'), ['/'])
     self.assertEqual(get_prefixes('a'), ['a'])
Пример #9
0
 def test_get_prefix(self):
     from certbot.plugins.util import get_prefixes
     self.assertEqual(get_prefixes("/a/b/c/"), ['/a/b/c/', '/a/b/c', '/a/b', '/a', '/'])
     self.assertEqual(get_prefixes("/"), ["/"])
     self.assertEqual(get_prefixes("a"), ["a"])