a Ö>ïh(ã@s(ddlZddlmZGdd„deƒZdS)éN)ÚSoSMapcseZdZdZgd¢ZddgZdZdZdZdZ dZ iZ iZ 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. )Z localhostz.*localdomain.*z^com..*ZwwwZapi) z.yamlz.ymlz.crtz.keyz.pemz.logz.repoz.rulesz.confz.cfgTrcCsâ|j ¡D]Ê\}}t| d¡ƒdkr@|j||j| d¡d<q | d¡r`| d¡d|j|<q d | d¡dd…¡}|s~q |j ¡D]J\}}d | d¡dd…¡}||krˆd | d¡dd…¡}||j|<qˆq | ¡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ÚdomainZob_pairZ_domain_to_injectZexisting_domainÚvalueÚ _existingZ _ob_domain©rúE/usr/lib/python3.9/site-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__rrrSs zSoSHostnameMap.get_regex_resultcCsšz2t|j ¡ddd d¡d}t|ƒd|_WntyDYn0z{óz?SoSHostnameMap.domain_name_in_loaded_domains..F)rr rr r Úany)rrrrr+rÚdomain_name_in_loaded_domainsps   z,SoSHostnameMap.domain_name_in_loaded_domainsc sÔd}d}d}| d¡r0||d7}|dd…}q | d¡rT||d7}|dd…}q0||jvrh|j|S| | ¡¡s†d |||g¡S| |j¡r¸d| d¡d}| |d¡}||7}||jvr¶t |j  ¡dt dD]Ü}d }| |¡}| d¡} | dr| d|j vrd}t |ƒdksØ|ds*qØ|s^|d d¡sL| |¡r^t ƒ |¡}q¶| |d¡rØz2| |d¡d} |dt ƒ | ¡}Wq¶WqØty²YqØ0qØ|sÈt ƒ |¡}|||S) NÚ)rÚ_rrrrT)rÚkeyF)r r)rr/ÚlowerrÚ strip_extsr rr Úkeysr r rÚgetÚ Exception) rrÚprefixÚsuffixÚfinalÚextrZ _host_substrÚ_testZ_hZitmrrrr6€sV          ÿ   ÿ   zSoSHostnameMap.getc Csà| d¡}t|ƒdkr(| |d ¡¡St|ƒdkr\| |¡}tdd„|DƒƒrX| ¡}|St|ƒdkrÜ|d}|dd…}t|ƒdkr˜| | ¡¡}nd}| |¡}||j|<d ||g¡}tdd„|DƒƒrØ| ¡}|SdS) Nrrrécss|]}| ¡VqdSr(©Úisupper©r*r&rrrr,År-z/SoSHostnameMap.sanitize_item..Úunknowncss|]}| ¡VqdSr(r>r@rrrr,Ør-) r r Úsanitize_short_namer3Úsanitize_domainÚallÚupperrr) rrrÚdnameÚhostnamerZ ob_hostnameÚ ob_domainZ_fqdnrrrÚ sanitize_item½s*         zSoSHostnameMap.sanitize_itemcCs^|r||jvr|S||jvrTd|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 rr)Ú skip_keysrr#r Zadd_regex_item)rrGZob_hostrrrrBÝ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. rrr)Úignore_matchesÚreÚmatchrr3Ú_new_obfuscated_domainr)rrZ_skipZ top_domainrFrHrrrrCës   zSoSHostnameMap.sanitize_domaincCs4||jvr*d|j›|j|<|jd7_|j|S)zDGenerate an obfuscated domain for each subdomain name given rr)rr%)rrFrrrrNús z%SoSHostnameMap._new_obfuscated_domain)Ú__name__Ú __module__Ú __qualname__Ú__doc__rKrJr4Zignore_short_itemsZmatch_full_words_onlyr#r%rr rrrr/r6rIrBrCrNÚ __classcell__rrrrrs*þ  = r)rLZsos.cleaner.mappingsrrrrrrÚ s