HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberPanel/lib64/python3.10/site-packages/paramiko/__pycache__/config.cpython-310.pyc
o

�h�j�
@s�dZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZd\Z
Zzddl
Z
WneyJZzeZWYdZ[ndZ[wwddlmZmZd	ZGd
d�d�Zdd
�ZGdd�d�ZGdd�de�ZdS)z2
Configuration file (aka ``ssh_config``) support.
�N)�sha1)�StringIO)�partial)NN�)�CouldNotCanonicalize�ConfigParseError�c@s�eZdZdZe�d�Zgd�dggd�gd�gd�gd�d	�Zd
d�Ze	dd
��Z
e	dd��Ze	dd��Zdd�Z
dd�Zd.dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�ZdS)/�	SSHConfiga�
    Representation of config information as stored in the format used by
    OpenSSH. Queries can be made via `lookup`. The format is described in
    OpenSSH's ``ssh_config`` man page. This class is provided primarily as a
    convenience to posix users (since the OpenSSH format is a de-facto
    standard on posix) but should work fine on Windows too.

    .. versionadded:: 1.6
    z(\w+)(?:\s*=\s*|\s+)(.+))�%C�%h�%l�%L�%n�%p�%r�%ur)r
�~�%drrrr)rrrr)rrr)	r
rrr
rrrrr)�controlpath�hostname�identityfile�proxycommand�	proxyjump�
match-execcCs
g|_dS)a�
        Create a new OpenSSH config object.

        Note: the newer alternate constructors `from_path`, `from_file` and
        `from_text` are simpler to use, as they parse on instantiation. For
        example, instead of::

            config = SSHConfig()
            config.parse(open("some-path.config")

        you could::

            config = SSHConfig.from_file(open("some-path.config"))
            # Or more directly:
            config = SSHConfig.from_path("some-path.config")
            # Or if you have arbitrary ssh_config text from some other source:
            config = SSHConfig.from_text("Host foo\n\tUser bar")
        N)�_config)�self�r�E/usr/local/CyberPanel/lib/python3.10/site-packages/paramiko/config.py�__init__Hs
zSSHConfig.__init__cCs|�t|��S)zg
        Create a new, parsed `SSHConfig` from ``text`` string.

        .. versionadded:: 2.7
        )�	from_filer)�cls�textrrr�	from_text]szSSHConfig.from_textcCs6t|��
}|�|�Wd�S1swYdS)zr
        Create a new, parsed `SSHConfig` from the file found at ``path``.

        .. versionadded:: 2.7
        N)�openr)r �path�florrr�	from_pathfs
$�zSSHConfig.from_pathcCs|�}|�|�|S)zp
        Create a new, parsed `SSHConfig` from file-like object ``flo``.

        .. versionadded:: 2.7
        )�parse)r r%�objrrrrps
zSSHConfig.from_filecCsLdgid�}|D]�}|��}|r|�d�rqt�|j|�}|s&td�|���|�d���}|�d�}|dvrT|j	�
|�dii}|d	krL|�|�|d	<q|�|�|d
<q|dkre|��dkred
|d|<q|�d�ru|�
d�ru|dd�}|dvr�||dvr�|d|�
|�q|g|d|<q||dvr�||d|<q|j	�
|�d
S)z�
        Read an OpenSSH config from the given file object.

        :param file_obj: a file-like object to read the config file from
        �*)�host�config�#zUnparsable line {}r�)r*�matchr+r*�matchesr�noneN�"���)r�localforward�
remoteforward)�strip�
startswith�rer.�SETTINGS_REGEXr�format�group�lowerr�append�
_get_hosts�_get_matches�endswith)r�file_obj�context�liner.�key�valuerrrr'{s8
�zSSHConfig.parsecCs�|j|d�}d|vr||d<|�dd�dv}t|�dd��}|rC|�d�|krC|d	��}|�|||�}||d<|j||d
d
d�}|S|j||dd
d�}|S)
a

        Return a dict (`SSHConfigDict`) of config options for a given hostname.

        The host-matching rules of OpenSSH's ``ssh_config`` man page are used:
        For each parameter, the first obtained value will be used.  The
        configuration files contain sections separated by ``Host`` and/or
        ``Match`` specifications, and that section is only applied for hosts
        which match the given patterns or keywords

        Since the first obtained value for each parameter is used, more host-
        specific declarations should be given near the beginning of the file,
        and general defaults at the end.

        The keys in the returned dict are all normalized to lowercase (look for
        ``"port"``, not ``"Port"``. The values are processed according to the
        rules for substitution variable expansion in ``ssh_config``.

        Finally, please see the docs for `SSHConfigDict` for deeper info on
        features such as optional type conversion methods, e.g.::

            conf = my_config.lookup('myhost')
            assert conf['passwordauthentication'] == 'yes'
            assert conf.as_bool('passwordauthentication') is True

        .. note::
            If there is no explicitly configured ``HostName`` value, it will be
            set to the being-looked-up hostname, which is as close as we can
            get to OpenSSH's behavior around that particular option.

        :param str hostname: the hostname to lookup

        .. versionchanged:: 2.5
            Returns `SSHConfigDict` objects instead of dict literals.
        .. versionchanged:: 2.7
            Added canonicalization support.
        .. versionchanged:: 2.7
            Added ``Match`` support.
        .. versionchanged:: 3.3
            Added ``Match final`` support.
        )rr�canonicalizehostnameN)�yes�always�canonicalizemaxdotsr�.�canonicaldomainsT)�	canonical�finalF)�_lookup�get�int�count�split�canonicalize)rr�options�canon�maxdots�domainsrrr�lookup�s"*���zSSHConfig.lookupNFcs��durt��|jD]K}|�|�dg�|�s$|�|�dg�|||��s$q
|d��D]*\�}��vrA|dur<|dd�n|��<q*�dkrT�����fdd�|D��q*q
|r^|��|���S)Nr*r/r+rc3s �|]}|��vr|VqdS�Nr��.0�x�rCrSrr�	<genexpr>s��z$SSHConfig._lookup.<locals>.<genexpr>)�
SSHConfigDictr�_pattern_matchesrN�_does_match�items�extend�_expand_variables)rrrSrKrLrArDrr\rrM�s4
�
��
���zSSHConfig._lookupc	Cs�d}|D].}d�||�}t||�}|dur|d}nzt�|�}Wn
tjy+Ynw|r2|Sq|�dd�dkr=|St|��)ag
        Return canonicalized version of ``hostname``.

        :param str hostname: Target hostname.
        :param options: An `SSHConfigDict` from a previous lookup pass.
        :param domains: List of domains (e.g. ``["paramiko.org"]``).

        :returns: A canonicalized hostname if one was found, else ``None``.

        .. versionadded:: 2.7
        Fz{}.{}Nr�canonicalizefallbacklocalrF)r9�_addressfamily_host_lookup�socket�
gethostbyname�gaierrorrNr)rrrSrV�found�domain�	candidate�family_specificrrrrRs"

��zSSHConfig.canonicalizecCs$t�}|jD]	}|�|d�q|S)z�
        Return the set of literal hostnames defined in the SSH config (both
        explicit hostnames and wildcard entries).
        r*)�setr�update)r�hosts�entryrrr�
get_hostnamesEs
zSSHConfig.get_hostnamescCsZt|d�r
|�d�}d}|D]}|�d�r"t�||dd��r"dSt�||�r*d}q|S)NrQ�,F�!rT)�hasattrrQr6�fnmatch)r�patterns�targetr.�patternrrrr_Os

��zSSHConfig._pattern_matchescCsNg}|dd�}t��}|r�|�d�}	d}
|�dd�}|�dd�}|	d|	d}
}|
dkr6|�||	�r6dS|
dkr=|}
nU|
d	krCd
S|
dkrR|pJ|}|�||�}
n@|
dkr]|�||�}
n5|
dkrl|pd|}|�||�}
n&|
d
krw|�||�}
n|
dkr�|�||d|�}tdur�t�tj	|dd
d�j
}
|
dur�|�|
|	�r�dS|�|	�|s|S)Nrr�user�type�paramrKFrL�allTr*�originalhost�	localuser�execr�stdout)�hide�warn)�getpass�getuser�poprN�_should_failr_�	_tokenize�invoke�invoke_import_error�run�okr<)r�
match_list�target_hostnamerKrLrS�matched�
candidates�local_usernamerk�passed�configured_host�configured_user�type_r{�hostvalry�exec_cmdrrrr``sL
�
�0zSSHConfig._does_matchcCs|dr|S|S)N�negater)r�
would_passrkrrrr��szSSHConfig._should_failcCs�|�|�}|s	|S|}|dkr|�d|�}d|vr|d}nt}t��}d|vr-|d}	n|}	t���d�d}
t||
�}t	j
�d�}|
|t|�|	}
t
|
�����|||
||||	||d�
}|}|��D]\}}||vroqf|�|t|��}qf|S)a�
        Tokenize a string based on current config/hostname data.

        :param config: Current config data.
        :param target_hostname: Original target connection hostname.
        :param key: Config key being tokenized (used to filter token list).
        :param value: Config value being tokenized.

        :returns: The tokenized version of the input ``value`` string.
        r�portryrIrr)
r
rrr
rrrrrr)�_allowed_tokensrN�SSH_PORTr�r�rf�gethostnamerQ�LazyFqdn�osr$�
expanduser�reprr�encode�	hexdigestra�replace�str)rr+r�rCrD�allowed_tokens�configured_hostnamer�ry�
remoteuser�local_hostname�
local_fqdn�homedir�tohash�replacements�	tokenized�findr�rrrr��sD



�zSSHConfig._tokenizecCs|j�|g�S)aJ
        Given config ``key``, return list of token strings to tokenize.

        .. note::
            This feels like it wants to eventually go away, but is used to
            preserve as-strict-as-possible compatibility with OpenSSH, which
            for whatever reason only applies some tokens to some config keys.
        )�TOKENS_BY_CONFIG_KEYrN�rrCrrrr��s	zSSHConfig._allowed_tokenscCsr|D]4}||durqt|j|||�}t||t�r.t||�D]\}}||�|||<q q|||�||<q|S)aA
        Return a dict of config options with expanded substitutions
        for a given original & current target hostname.

        Please refer to :doc:`/api/config` for details.

        :param dict config: the currently parsed config
        :param str hostname: the hostname whose config is being looked up
        N)rr��
isinstance�list�	enumerate)rr+r��k�	tokenizer�irDrrrrc�s
�zSSHConfig._expand_variablescCs*zt�|�WStytd�|���w)z>
        Return a list of host_names from host value.
        zUnparsable host {})�shlexrQ�
ValueErrorrr9)rr*rrrr=�s
�zSSHConfig._get_hostsc	sg}t�|�}|rHdddd�}|�d�}|�d�r#d|d<|dd�}||d	<|d
vr1|�|�q|s:td�|���|�d�|d<|�|�|s	d
d�|D�}d|vr�d�tt�fdd�|��tt�fdd�|��}}d}t	|�rud}nd|vr�|�
d�|�
d�kr�d}|dur�t|��|S)z�
        Parse a specific Match config line into a list-of-dicts for its values.

        Performs some parse-time validation as well.
        NF)rzr{r�rrsTr�rrz)r|rKrLz'Missing parameter to Match '{}' keywordr{cSsg|]}|d�qS)rzrrYrrr�
<listcomp>sz*SSHConfig._get_matches.<locals>.<listcomp>r|)r|rKcs|�vSrXr�r[��	allowablerr�<lambda>"�z(SSHConfig._get_matches.<locals>.<lambda>cs|�vSrXrr�r�rrr�#r�z>Match does not allow 'all' mixed with anything but 'canonical'rKz-Match does not allow 'all' before 'canonical')r�rQr�r6r<rr9r��filter�any�index)	rr.r/�tokensr��keywordsr��bad�errrr�rr>sB



�
��zSSHConfig._get_matches)NFF)�__name__�
__module__�__qualname__�__doc__r7�compiler8r�r�classmethodr"r&rr'rWrMrRrqr_r`r�r�r�rcr=r>rrrrr	.s<

�

	

<
B#)
8>	r	cCsd|�dd���}|dkrdSztj}|dkrtj}t�|d|tjtjtj�WStj	y1YdSw)a
    Try looking up ``hostname`` in an IPv4 or IPv6 specific manner.

    This is an odd duck due to needing use in two divergent use cases. It looks
    up ``AddressFamily`` in ``options`` and if it is ``inet`` or ``inet6``,
    this function uses `socket.getaddrinfo` to perform a family-specific
    lookup, returning the result if successful.

    In any other situation -- lookup failure, or ``AddressFamily`` being
    unspecified or ``any`` -- ``None`` is returned instead and the caller is
    expected to do something situation-appropriate like calling
    `socket.gethostbyname`.

    :param str hostname: Hostname to look up.
    :param options: `SSHConfigDict` instance w/ parsed options.
    :returns: ``getaddrinfo``-style tuples, or ``None``, depending.
    �
addressfamilyr�N�inet)
rNr;rf�AF_INET6�AF_INET�getaddrinfo�
SOCK_DGRAM�
IPPROTO_IP�AI_CANONNAMErh)rrS�address_family�familyrrrre/s$��rec@s"eZdZdZddd�Zdd�ZdS)r�z7
    Returns the host's fqdn on request as string.
    NcCsd|_||_||_dSrX)�fqdnr+r*)rr+r*rrrrYs
zLazyFqdn.__init__c	Csl|jdur3d}t|j|j�}|dur(|D]}|\}}}}}|r'd|vr'|}nq|dur0t��}||_|jS)NrI)r�rer*r+rf�getfqdn)	rr��results�res�af�socktype�proto�	canonname�sarrr�__str__^s
�zLazyFqdn.__str__rX)r�r�r�r�rr�rrrrr�Ts
r�c@s eZdZdZdd�Zdd�ZdS)r^a�
    A dictionary wrapper/subclass for per-host configuration structures.

    This class introduces some usage niceties for consumers of `SSHConfig`,
    specifically around the issue of variable type conversions: normal value
    access yields strings, but there are now methods such as `as_bool` and
    `as_int` that yield casted values instead.

    For example, given the following ``ssh_config`` file snippet::

        Host foo.example.com
            PasswordAuthentication no
            Compression yes
            ServerAliveInterval 60

    the following code highlights how you can access the raw strings as well as
    usefully Python type-casted versions (recalling that keys are all
    normalized to lowercase first)::

        my_config = SSHConfig()
        my_config.parse(open('~/.ssh/config'))
        conf = my_config.lookup('foo.example.com')

        assert conf['passwordauthentication'] == 'no'
        assert conf.as_bool('passwordauthentication') is False
        assert conf['compression'] == 'yes'
        assert conf.as_bool('compression') is True
        assert conf['serveraliveinterval'] == '60'
        assert conf.as_int('serveraliveinterval') == 60

    .. versionadded:: 2.5
    cCs"||}t|t�r|S|��dkS)a�
        Express given key's value as a boolean type.

        Typically, this is used for ``ssh_config``'s pseudo-boolean values
        which are either ``"yes"`` or ``"no"``. In such cases, ``"yes"`` yields
        ``True`` and any other value becomes ``False``.

        .. note::
            If (for whatever reason) the stored value is already boolean in
            nature, it's simply returned.

        .. versionadded:: 2.5
        rF)r��boolr;)rrC�valrrr�as_bool�s
zSSHConfigDict.as_boolcCst||�S)z�
        Express given key's value as an integer, if possible.

        This method will raise ``ValueError`` or similar if the value is not
        int-appropriate, same as the builtin `int` type.

        .. versionadded:: 2.5
        )rOr�rrr�as_int�s	zSSHConfigDict.as_intN)r�r�r�r�r�r�rrrrr^zs!r^)r�rur�r�r7r�rf�hashlibr�ior�	functoolsrr�r��ImportError�e�
ssh_exceptionrrr�r	rer��dictr^rrrr�<module>s6��%&