Current File : //lib/python3/dist-packages/sos/cleaner/mappings/__pycache__/hostname_map.cpython-312.pyc
�

-�_g(��.�ddlZddlmZGd�de�Zy)�N)�SoSMapc���eZdZdZgd�ZddgZdZdZdZdZ	dZ
iZiZd�Z
�fd	�Zd
�Zd�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.cfgTrc��|jj�D�](\}}t|jd��dk(r/|j||j|jd�d<�S|jd�r"|jd�d|j|<��dj|jd�dd�}|s��|jj�D]`\}}dj|jd�dd�}||k(s�/dj|jd�dd�}||j|<�b��+|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�set_initial_counts)�self�domain�ob_pair�_domain_to_inject�existing_domain�value�	_existing�
_ob_domains        �C/usr/lib/python3/dist-packages/sos/cleaner/mappings/hostname_map.py�load_domains_from_mapz$SoSHostnameMap.load_domains_from_map5s=��
 $�|�|�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�!�(��.2�l�l�.@�.@�.B�F�*�O�U� #����)>�)>�s�)C�C�R�)H� I�I� �$5�5�%(�X�X�e�k�k�#�.>�s��.C�%D�
�;E��
�
�&7�8�	F�%	F�.	
���!�c�N��d|vr|jdd�}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.
        r
z(\.|_))�replace�super�get_regex_result)r�item�	__class__s  �rr%zSoSHostnameMap.get_regex_resultSs,���
�$�;��<�<��Y�/�D��w�'��-�-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���||jvry|jd�}dj|jd�dd��t|�dk(r|d|jvSt�fd�|jD��ryy)zkCheck if a potential domain is in one of the domains we've loaded
        and should be obfuscated
        Tr
rr
rc3�@�K�|]}�j|����y�w�N)�endswith)�.0�_d�no_tlds  �r�	<genexpr>z?SoSHostnameMap.domain_name_in_loaded_domains.<locals>.<genexpr>{s�����;�r�v���r�"�;�s�F)rrrrr�any)rrr*r9s   @r�domain_name_in_loaded_domainsz,SoSHostnameMap.domain_name_in_loaded_domainspsv����T�]�]�"���|�|�C� �����&�,�,�s�+�A�b�1�2���t�9��>���7�d�j�j�(�(��;�T�]�]�;�;��r!c�b��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
}||jvr�t|jj�dt��D]�}d	}|j|�}|jd�}	|	dr|	d|jvrd}t|�dk(s|ds�S|s6|djd�s|j|�rt�|�9|�}nE|j|d�s��	|j|d�d}
|dt�|�9|
�z}n|st�|�9|�}||z|zS#t$rY��wxYw)
N�)r
�_rrr
r
T)r)�keyF)rr6rr<�lowerr�
strip_extsrr#r+�keysrrr$�get�	Exception)rr&�prefix�suffix�final�extr�_host_substr�_test�_h�itmr's           �rrDzSoSHostnameMap.get�s:����������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��(+�-�
�	�$���
�
�9�-���_�_�S�)���a�5�R��U�d�j�j�0�#'�L��u�:��?�%��(��#��q��):�):�3�)?�)-���y�)A�!�G�K��-�E���:�:�e�A�h�'��"�j�j��q��2�1�5�� %�a��5�7�;�s�+;� ;���/
�8��G�K��%�E���~��&�&��
%����s�,H"�"	H.�-H.c�J�|jd�}t|�dk(r"|j|dj��St|�dk(r5|j	|�}td�|D��r|j
�}|St|�dkDr�|d}|dd}t|�dkDr |j|j��}nd}|j	|�}||j|<dj||g�}td�|D��r|j
�}|Sy)Nr
rr�c3�<K�|]}|j����y�wr5��isupper�r7r1s  rr:z/SoSHostnameMap.sanitize_item.<locals>.<genexpr>������-�1�1�9�9�;�-����unknownc3�<K�|]}|j����y�wr5rQrSs  rr:z/SoSHostnameMap.sanitize_item.<locals>.<genexpr>�rTrU)	rr�sanitize_short_namerA�sanitize_domain�all�upperrr)	rr&r*�dname�hostnamer�ob_hostname�	ob_domain�_fqdns	         r�
sanitize_itemzSoSHostnameMap.sanitize_item�s	���z�z�#����t�9��>��+�+�D��G�M�M�O�<�<��t�9��>��(�(��.�E��-��-�-����
���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��-��-�-����
���L�r!c��|r||jvr|S||jvrSd|j��}||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
        r*r)�	skip_keysrr.r�add_regex_item)rr]�ob_hosts   rrXz"SoSHostnameMap.sanitize_short_name�s{���8�t�~�~�5��O��4�<�<�'��T�_�_�-�.�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_matches�re�matchrrA�_new_obfuscated_domainr)rr�_skip�
top_domainr\r_s      rrYzSoSHostnameMap.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|j��|j|<|xjdz
c_|j|S)zDGenerate an obfuscated domain for each subdomain name given
        rr)rr0)rr\s  rrjz%SoSHostnameMap._new_obfuscated_domain�sL����
�
�%�%5�d�6G�6G�5H�#I�D�M�M�%� �����"���}�}�U�#�#r!)�__name__�
__module__�__qualname__�__doc__rgrcrB�ignore_short_items�match_full_words_onlyr.r0rrr r%rr<rDrarXrYrj�
__classcell__)r's@rrrsv���
��N�	�
��I�
-�J��� ���J��L��H��E�"�<.��(� ;'�z�@&�
�$r!r)rh�sos.cleaner.mappingsrr�r!r�<module>rws��
�'�p$�V�p$r!