%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/sos/cleaner/mappings/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/sos/cleaner/mappings/__pycache__/hostname_map.cpython-312.pyc

�

i��d/(��.�ddlZddlmZGd�de�Zy)�N)�SoSMapc�v��eZdZdZgd�ZddgZdZdZdZiZ	iZ
d�Zd�Zd	�Z
d
�Z�fd�Zd�Zd
�Zd�Zd�Z�xZS)�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.cfgrc���|jj�D�]2\}}t|jd��dk(r/|j||j|jd�d<�S|jd�r"|jd�d|j|<��dj|jd�dd�}|s��|jj�D]j}dj|jd�dd�}||k(s�,dj|j|jd�dd�}||j|<�l��5|j�y)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�keys�set_initial_counts)�self�domain�ob_pair�_domain_to_inject�existing_domain�	_existing�
_ob_domains       �C/usr/lib/python3/dist-packages/sos/cleaner/mappings/hostname_map.py�load_domains_from_mapz$SoSHostnameMap.load_domains_from_map3sI��
 $�|�|�1�1�3�	F�O�F�G��6�<�<��$�%��*�37�<�<��3G��
�
�6�<�<��,�Q�/�0��%�%�&8�9�,3�M�M�#�,>�q�,A�D�M�M�&�)��%(�H�H�V�\�\�#�->�q��-D�$E�!�(��'+�|�|�'8�'8�':�F�O� #����)>�)>�s�)C�C�R�)H� I�I� �$5�5�%(�X�X� �L�L��9�?�?��D�S�b�I�&�
�<F��
�
�&7�8�
F�%	F�2	
���!�c�v�d|vr|jdd�}tj|tj�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.
        r
z(\.|_))�replace�re�compile�I)r�items  r�get_regex_resultzSoSHostnameMap.get_regex_resultSs0��
�$�;��<�<��Y�/�D��z�z�$����%�%r!c��	t|jj�d��djd�d}t	|�dz|_	t|jj�d��djd�}t	|djd�d�dz|_y#t$rY�lwxYw#t$rYywxYw)	z�Set the initial counter for host and domain obfuscation numbers
        based on what is already present in the mapping.
        T)�reverser�hostrrr
N)	�sortedr�valuesr�int�
host_count�
IndexErrorr�domain_count)r�h�ds   rrz!SoSHostnameMap.set_initial_counts\s���
	��t�z�z�(�(�*�D�9�!�<�B�B�6�J�1�M�A�!�!�f�q�j�D�O�	��t�}�}�+�+�-�t�<�Q�?�E�E�h�O�A� #�A�a�D�J�J�s�O�A�$6� 7�!� ;�D����	��	���	��	�s%�A
B0�AB?�0	B<�;B<�?	C�
Cc�8�||jvry|jd�}dj|jd�dd�}t|�dk(r|d|jvSt|jD�cgc]}|j
|���c}�ryycc}w)zkCheck if a potential domain is in one of the domains we've loaded
        and should be obfuscated
        Tr
rr
rF)rrrrr�any�endswith)rrr+�no_tld�_ds     r�domain_name_in_loaded_domainsz,SoSHostnameMap.domain_name_in_loaded_domainsps����T�]�]�"���|�|�C� �����&�,�,�s�+�A�b�1�2���t�9��>���7�d�j�j�(�(�
��
�
�>�"�&�/�/�"�%�>�
?����?s�6Bc���d}d}d}|jd�r||dz
}|dd}|jd�r�|jd�r||dz
}|dd}|jd�r�||jvr|j|S|j|j	��sdj|||g�S|j|j�r.d|jd�dz}|j|d�}||z
}||jj�v�r
t|jj�dd��	�D]�}d
}|j|�}|jd�}	|	dr!|	d|jj�vrd}t|�dk(s|ds�a|s:|djd�s|j|�rtt|�?|�}nI|j|d�s��	|j|d�d}
|dtt|�?|
�z}n|stt|�?|�}||z|zS#t $rY��wxYw)N�)r
�_rrr
r
Tc��t|�S)N)r)�xs r�<lambda>z$SoSHostnameMap.get.<locals>.<lambda>�s
��#�a�&�r!)r*�keyF)rr6rr9�lowerr�
strip_extsrr#rr,rr�superr�get�	Exception)rr'�prefix�suffix�final�extr�_host_substr�_test�_h�itm�	__class__s           �rrDzSoSHostnameMap.get�sS����������o�o�j�)��d�1�g��F����8�D��o�o�j�)��m�m�J�'��d�2�h��F���"�:�D��m�m�J�'��4�<�<���<�<��%�%��1�1�$�*�*�,�?��7�7�F�D�&�1�2�2��=�=����)���
�
�3���+�+�C��<�<��R�(�D��c�M�F��t�|�|�(�(�*�*�$�D�L�L�$5�$5�$7��(8�:�
�	�$���
�
�9�-���_�_�S�)���a�5�R��U�d�j�j�o�o�&7�7�#'�L��u�:��?�%��(��%�5��8�+<�+<�S�+A�+/�=�=��+C�!�.�$�;�D�A�E���Z�Z��a��)��"�j�j��q��2�1�5�� %�a��5���+J�3�+O� O���/
�8��.�$�3�D�9�E���~��&�&��
%����s�80I�	I�Ic��|jd�}t|�dk(r"|j|dj��St|�dk(rJ|j	|�}t|D�cgc]}|j
���c}�r|j�}|St|�dkDr�|d}|dd}t|�dkDr |j|j��}nd}|j	|�}||j|<dj||g�}	t|D�cgc]}|j
���c}�r|	j�}	|	Sycc}wcc}w)Nr
rr��unknown)
rr�sanitize_short_namerA�sanitize_domain�all�isupper�upperrr)
rr'r+�dnamer2�hostnamer�ob_hostname�	ob_domain�_fqdns
          r�
sanitize_itemzSoSHostnameMap.sanitize_item�s+���z�z�#����t�9��>��+�+�D��G�M�M�O�<�<��t�9��>��(�(��.�E���.�A�A�I�I�K�.�/����
���L��t�9�q�=��A�w�H��!�"�X�F��8�}�q� �"�6�6�x�~�~�7G�H��(���,�,�V�4�I�!*�D�L�L����H�H�k�9�5�6�E���.�A�A�I�I�K�.�/����
���L�%��/��&/s�*E�Ec��|r||jvr|S||jvrSd|jz}||j|<|xjdz
c_||j|<|j	|�|j|S)z�Obfuscate the short name of the host with an incremented counter
        based on the total number of obfuscated host names
        zhost%sr)�	skip_keysrr/r�add_regex_item)rrX�ob_hosts   rrRz"SoSHostnameMap.sanitize_short_name�sx���8�t�~�~�5��O��4�<�<�'�����0�G�#*�D�J�J�x� ��O�O�q� �O�%,�D�L�L��"�����)��|�|�H�%�%r!c��|jD]:}tj|dj|��s�)dj|�cS|dj	�}dj|dd�j	�}|j|�}dj||g�}||jdj|�<|S)zeObfuscate the domainname, broken out into subdomains. Top-level
        domains are ignored.
        r
r
r)�ignore_matchesr$�matchrrA�_new_obfuscated_domainr)rr�_skip�
top_domainrWrZs      rrSzSoSHostnameMap.sanitize_domain�s����(�(�	(�E��x�x��s�x�x��/�0��x�x��'�'�	(��B�Z�%�%�'�
������"��&�,�,�.���/�/��6�	��H�H�i��4�5�	�)2����S�X�X�f�%�&��r!c��||jvr1d|jz|j|<|xjdz
c_|j|S)zDGenerate an obfuscated domain for each subdomain name given
        zobfuscateddomain%sr)rr1)rrWs  rrdz%SoSHostnameMap._new_obfuscated_domain�sI����
�
�%�#7�$�:K�:K�#K�D�M�M�%� �����"���}�}�U�#�#r!)�__name__�
__module__�__qualname__�__doc__rbr^rBr/r1rrr r(rr9rDr\rRrSrd�
__classcell__)rNs@rrrsj���
��N�	�
��I�
-�J��J��L��H��E�"�@&��(� :'�x�>&�
�$r!r)r$�sos.cleaner.mappingsrr�r!r�<module>ros��
�'�n$�V�n$r!

Zerion Mini Shell 1.0