MMCT TEAM
Server IP : 128.199.20.84  /  Your IP : 172.70.100.104
Web Server : Apache/2.4.41 (Ubuntu)
System : Linux competent-maruti 5.4.0-128-generic #144-Ubuntu SMP Tue Sep 20 11:00:04 UTC 2022 x86_64
User : www-data ( 33)
PHP Version : 8.0.20
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF
Directory (0755) :  /lib/python3/dist-packages/certbot/plugins/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //lib/python3/dist-packages/certbot/plugins/util.py
"""Plugin utilities."""
import logging

from certbot import util
from certbot.compat import os
from certbot.compat.misc import STANDARD_BINARY_DIRS

logger = logging.getLogger(__name__)


def get_prefixes(path):
    """Retrieves all possible path prefixes of a path, in descending order
    of length. For instance,
        (linux) /a/b/c returns ['/a/b/c', '/a/b', '/a', '/']
        (windows) C:\\a\\b\\c returns ['C:\\a\\b\\c', 'C:\\a\\b', 'C:\\a', 'C:']
    :param str path: the path to break into prefixes

    :returns: all possible path prefixes of given path in descending order
    :rtype: `list` of `str`
    """
    prefix = os.path.normpath(path)
    prefixes = []
    while prefix:
        prefixes.append(prefix)
        prefix, _ = os.path.split(prefix)
        # break once we hit the root path
        if prefix == prefixes[-1]:
            break
    return prefixes


def path_surgery(cmd):
    """Attempt to perform PATH surgery to find cmd

    Mitigates https://github.com/certbot/certbot/issues/1833

    :param str cmd: the command that is being searched for in the PATH

    :returns: True if the operation succeeded, False otherwise
    """
    path = os.environ["PATH"]
    added = []
    for d in STANDARD_BINARY_DIRS:
        if d not in path:
            path += os.pathsep + d
            added.append(d)

    if any(added):
        logger.debug("Can't find %s, attempting PATH mitigation by adding %s",
                     cmd, os.pathsep.join(added))
        os.environ["PATH"] = path

    if util.exe_exists(cmd):
        return True
    expanded = " expanded" if any(added) else ""
    logger.debug("Failed to find executable %s in%s PATH: %s", cmd,
                 expanded, path)
    return False

MMCT - 2023