HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //lib/python3.6/site-packages/sos/cleaner/mappings/__pycache__/__init__.cpython-36.pyc
3

\��h��@s6ddlZddlZddlZddlmZGdd�d�ZdS)�N)�Pathc@s|eZdZdZgZgZdZdZdZdd�Z	dd�Z
dd	�Zd
d�Zdd
�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)�SoSMapz�Standardized way to store items with their obfuscated counterparts.

    Each type of sanitization that SoSCleaner supports should have a
    corresponding SoSMap() object, to allow for easy retrieval of obfuscated
    items.
    TFcCsJi|_t�|_g|_|jjj�|_||_t	j
j|jd|j�|_|j
�dS)NZ
cleaner_cache)�dataset�set�
_regexes_made�compiled_regexes�	__class__�__name__�lowerZcname�workdir�os�path�join�	cache_dir�load_entries)�selfr�r�/usr/lib/python3.6/__init__.py�__init__ s
zSoSMap.__init__cCs"t|j�jddd�|jd�dS)ai Load cached entries from the disk. This method must be called when
        we initialize a Map instance and whenever we want to retrieve
        self.dataset (e.g. to store default_mapping file). The later is
        essential since a concurrent Map can add more objects to the cache,
        so we need to update self.dataset up to date.

        Keep in mind that size of self.dataset is usually bigger than number
        of files in the corresponding cleaner's directory: directory contains
        just whole items (e.g. IP addresses) while dataset contains more
        derived objects (e.g. subnets).
        T)�parents�exist_ok�N)rr�mkdir�load_new_entries_from_dir)rrrrr,s
zSoSMap.load_entriescCs\|s0||jks0||jj�ks0|jr4t|�dkr4dSx"|jD]}tj||tj�r<dSq<WdS)z�Some items need to be completely ignored, for example link-local or
        loopback addresses should not be obfuscated
        �TF)	�	skip_keysr�values�ignore_short_items�len�ignore_matches�re�match�I)r�item�skiprrr�ignore_item<szSoSMap.ignore_itemcCsHy|j|�|j|<Wntk
r2||j|<YnX|jrD|j|�dS)N)�
sanitize_itemr�	Exception�compile_regexes�add_regex_item)rr#rrr�add_sanitised_item_to_datasetHsz$SoSMap.add_sanitised_item_to_datasetc
Cs�d}x�|dkr�tjj|j|��}xhtjj|�r�d}t|ddd��}|j�}WdQRX|jj|d�sl|j	|�|d7}tjj|j|��}q"W|d8}|d7}qWdS)N�r�rzutf-8)�encodingFr)
rr
rr�isfile�open�readr�getr*)r�counterZno_files_cntZfname�fr#rrrrPs

z SoSMap.load_new_entries_from_dircCs�|j|�r|Sd}x�|jj|d�s�|sZtj|jd�}t|jddd��}|j|�WdQRXy8t	|j�d}t
j|jt
jj
|j|���|j|�Wqtk
r�|j|�YqXqW|j|S)z�Add a particular item to the map, generating an obfuscated pair
        for it.

        Positional arguments:

            :param item:        The plaintext object to obfuscate
        NF)�dir�wzutf-8)r-r)r%rr1�tempfileZNamedTemporaryFilerr/�name�writerr�linkr
rr*�FileExistsErrorr)rr#Ztmpfiler3r2rrr�addfs 

z
SoSMap.addcCsR|j|�rdS||jkrN|jj|�|jj||j|�f�|jjdd�dd�dS)z�Add an item to the regexes dict and then re-sort the list that the
        parsers will use during parse_line()

        :param item:    The unobfuscated item to generate a regex for
        :type item:     ``str``
        NcSst|d�S)Nr)r)�xrrr�<lambda>�sz'SoSMap.add_regex_item.<locals>.<lambda>T)�key�reverse)r%rr;r�append�get_regex_result�sort)rr#rrrr)�s

zSoSMap.add_regex_itemcCs2|jrdtj|��d�}n
tj|�}tj|tj�S)a9Generate the object/value that is used by the parser when iterating
        over pre-generated regexes during parse_line(). For most parsers this
        will simply be a ``re.Pattern()`` object, but for more complex parsers
        this can be overridden to provide a different object, e.g. a tuple,
        for that parer's specific iteration needs.

        :param item:    The unobfuscated string to generate the regex for
        :type item:     ``str``

        :returns:       A compiled regex pattern for the item
        :rtype:         ``re.Pattern``
        z
(?<![a-z0-9])z
(?=\b|_|-))�match_full_words_onlyr �escape�compiler")rr#rrrrA�s

zSoSMap.get_regex_resultcCs|S)z�Perform the obfuscation relevant to the item being added to the map.

        This should be overridden by each type of map that subclasses SoSMap

        Positional arguments:

            :param item:        The plaintext object to obfuscate
        r)rr#rrrr&�s	zSoSMap.sanitize_itemcCs,|j|�r|S||jkr"|j|�S|j|S)z�Retrieve an item's obfuscated counterpart from the map. If the item
        does not yet exist in the map, add it by generating one on the fly
        )r%rr;)rr#rrrr1�s



z
SoSMap.getcCs|jj|�dS)a%Update the map using information from a previous run to ensure that
        we have consistent obfuscation between reports

        Positional arguments:

            :param config:    A dict of mappings with the form of
                              {clean_entry: 'obfuscated_entry'}
        N)r�update)r�configrrr�conf_update�s	zSoSMap.conf_updateN)r	�
__module__�__qualname__�__doc__rrr(rrCrrr%r*rr;r)rAr&r1rHrrrrrs"
r)r rr6Zpathlibrrrrrr�<module>s