HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/sos/cleaner/mappings/__pycache__/hostname_map.cpython-310.pyc
o

([Qh(�@s(ddlZddlmZGdd�de�ZdS)�N)�SoSMapcs�eZdZdZgd�ZddgZdZdZdZdZ	dZ
iZiZdd	�Z
�fd
d�Zdd
�Zdd�Z�fdd�Zdd�Zdd�Zdd�Zdd�Z�ZS)�SoSHostnameMapaLMapping store for hostnames and domain names

    Hostnames are obfuscated using an incrementing counter based on the total
    number of hosts matched regardless of domain name.

    Domain names are obfuscated based on the host's hostname, plus any user
    defined domains passed in by the `--domains` options.

    Domains are obfuscated as whole units, meaning the domains 'example.com'
    and 'host.foo.example.com' will be separately obfuscated with no relation
    for example as 'obfuscatedomdain1.com' and 'obfuscatedomain2.com'.

    Top-level domains are left untouched.
    )�	localhostz.*localdomain.*z^com..*�www�api)
z.yamlz.ymlz.crtz.keyz.pemz.logz.repoz.rulesz.confz.cfgTrcCs�|j��D]e\}}t|�d��dkr |j||j|�d�d<q|�d�r0|�d�d|j|<qd�|�d�dd��}|s?q|j��D]%\}}d�|�d�dd��}||krid�|�d�dd��}||j|<qDq|��dS)z�Because we use 'intermediary' dicts for host names and domain names
        in this parser, we need to re-inject entries from the map_file into
        these dicts and not just the underlying 'dataset' dict
        �.�r�obfuscateddomain���N)	�dataset�items�len�split�hosts�
startswith�_domains�join�set_initial_counts)�self�domain�ob_pair�_domain_to_inject�existing_domain�value�	_existing�
_ob_domain�r�C/usr/lib/python3/dist-packages/sos/cleaner/mappings/hostname_map.py�load_domains_from_map5s"

��z$SoSHostnameMap.load_domains_from_mapcs d|vr
|�dd�}t��|�S)z�Override the base get_regex_result() to provide a regex that, if
        this is an FQDN or a straight domain, will include an underscore
        formatted regex as well.
        rz(\.|_))�replace�super�get_regex_result)r�item��	__class__rrr!SszSoSHostnameMap.get_regex_resultcCs�zt|j��dd�d�d�d}t|�d|_Wn	ty"Ynwzt|j��dd�d�d�}t|d�d�d�d|_WdStyLYdSw)	z�Set the initial counter for host and domain obfuscation numbers
        based on what is already present in the mapping.
        T)�reverser�hostrrrN)	�sortedr�valuesr�int�
host_count�
IndexErrorr�domain_count)r�h�drrrr\s �"�z!SoSHostnameMap.set_initial_countscsj||jvrdS|�d�}d�|�d�dd���t|�dkr%|d|jvSt�fdd�|jD��r3dSdS)	zkCheck if a potential domain is in one of the domains we've loaded
        and should be obfuscated
        Trrr
rc3s�|]}��|�VqdS�N)�endswith)�.0�_d��no_tldrr�	<genexpr>{s�z?SoSHostnameMap.domain_name_in_loaded_domains.<locals>.<genexpr>F)rrrr
r�any)rrr&rr3r�domain_name_in_loaded_domainsps

z,SoSHostnameMap.domain_name_in_loaded_domainsc	s�d}d}d}|�d�r||d7}|dd�}|�d�s|�d�r2||d7}|dd�}|�d�s!||jvr<|j|S|�|���sKd�|||g�S|�|j�rdd|�d�d}|�|d�}||7}||jvr�t	|j�
�dtd�D]c}d	}|�|�}|�d�}	|	dr�|	d|jvr�d}t|�dks�|ds�qs|s�|d�d�s�|�|�r�t
��|�}n(|�|d�r�z|�|d�d}
|dt
��|
�}Wn
ty�Yqswqs|s�t
��|�}|||S)
N�)r�_rrr
rT)r%�keyF)rr0rr7�lowerr�
strip_extsrrr'�keysr
rr �get�	Exception)rr"�prefix�suffix�final�extr�_host_substr�_test�_h�itmr#rrr>�s^

�

�



�

���zSoSHostnameMap.getc	Cs�|�d�}t|�dkr|�|d���St|�dkr.|�|�}tdd�|D��r,|��}|St|�dkrn|d}|dd�}t|�dkrL|�|���}nd}|�|�}||j|<d�||g�}tdd�|D��rl|��}|SdS)	Nrrr�cs��|]}|��VqdSr/��isupper�r1r-rrrr5���z/SoSHostnameMap.sanitize_item.<locals>.<genexpr>�unknowncsrIr/rJrLrrrr5�rM)	rr
�sanitize_short_namer;�sanitize_domain�all�upperrr)	rr"r&�dname�hostnamer�ob_hostname�	ob_domain�_fqdnrrr�
sanitize_item�s*



zSoSHostnameMap.sanitize_itemcCs^|r||jvr	|S||jvr*d|j��}||j|<|jd7_||j|<|�|�|j|S)z�Obfuscate the short name of the host with an incremented counter
        based on the total number of obfuscated host names
        r&r)�	skip_keysrr*r�add_regex_item)rrT�ob_hostrrrrO�s




z"SoSHostnameMap.sanitize_short_namecCsz|jD]}t�|d�|��rd�|�Sq|d��}d�|dd����}|�|�}d�||g�}||jd�|�<|S)zeObfuscate the domainname, broken out into subdomains. Top-level
        domains are ignored.
        rr
r)�ignore_matches�re�matchrr;�_new_obfuscated_domainr)rr�_skip�
top_domainrSrVrrrrP�s
�
zSoSHostnameMap.sanitize_domaincCs4||jvrd|j��|j|<|jd7_|j|S)zDGenerate an obfuscated domain for each subdomain name given
        r	r)rr,)rrSrrrr_�s

z%SoSHostnameMap._new_obfuscated_domain)�__name__�
__module__�__qualname__�__doc__r\rYr<�ignore_short_items�match_full_words_onlyr*r,rrrr!rr7r>rXrOrPr_�
__classcell__rrr#rrs,�	= r)r]�sos.cleaner.mappingsrrrrrr�<module>s