
    ~ g(                     .    S SK r S SKJr   " S S\5      rg)    N)SoSMapc                      ^  \ rS rSrSr/ SQrSS/rSrSrSr	Sr
Sr0 r0 rS	 rU 4S
 jrS rS rU 4S jrS rS rS rS rSrU =r$ )SoSHostnameMap   a(  Mapping 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.cfgTr   c                    U R                   R                  5        GH7  u  p[        UR                  S5      5      S:X  a0  U R                   U   U R                  UR                  S5      S   '   MT  UR                  S5      (       a#  UR                  S5      S   U R                  U'   M  SR                  UR                  S5      SS 5      nU(       d  M  U R                   R                  5        H`  u  pESR                  UR                  S5      SS 5      nXc:X  d  M/  SR                  UR                  S5      SS 5      nXpR                  U'   Mb     GM:     U R                  5         g)zBecause 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   obfuscateddomainN)	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_map$SoSHostnameMap.load_domains_from_map5   s*   
  $||113OF6<<$%*37<<3G

6<<,Q/0%%&899,3MM#,>q,ADMM&) %(HHV\\#->q-D$E!(.2ll.@.@.B*O #)>)>s)CCR)H II 5%(XXekk#.>s.C%D
;E&78	 /C%  4. 	!    c                 R   > SU;   a  UR                  SS5      n[        TU ]	  U5      $ )zOverride 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     r    r'   SoSHostnameMap.get_regex_resultS   s,    
 $;<<Y/Dw'--r#   c                     [        U R                  R                  5       SS9S   R                  S5      S   n[	        U5      S-   U l         [        U R                  R                  5       SS9S   R                  S5      n[	        US   R                  S5      S   5      S-   U l        g! [         a     Njf = f! [         a     gf = f)	zqSet the initial counter for host and domain obfuscation numbers
based on what is already present in the mapping.
T)reverser   hostr   r   r   N)	sortedr   valuesr   int
host_count
IndexErrorr   domain_count)r   hds      r    r   !SoSHostnameMap.set_initial_counts\   s    
	tzz((*D9!<BB6J1MA!!fqjDO	t}}++-t<Q?EEhOA #AaDJJsOA$6 7! ;D  		  		s%   A
B* AB: *
B76B7:
CCc                   ^ XR                   ;   a  gUR                  S5      nSR                  UR                  S5      SS 5      m[        U5      S:X  a  US   U R                  ;   $ [        U4S jU R                    5       5      (       a  gg)z[Check if a potential domain is in one of the domains we've loaded
and should be obfuscated
Tr   r   r   r   c              3   F   >#    U  H  nTR                  U5      v   M     g 7fN)endswith).0_dno_tlds     r    	<genexpr>?SoSHostnameMap.domain_name_in_loaded_domains.<locals>.<genexpr>{   s     ;]rvr""]s   !F)r   r   r   r   r   any)r   r   r-   r=   s      @r    domain_name_in_loaded_domains,SoSHostnameMap.domain_name_in_loaded_domainsp   sw     ]]"||C &,,s+Ab12t9>7djj((;T]];;;r#   c                   > SnSnS nUR                  S5      (       a$  X!S   -  nUSS  nUR                  S5      (       a  M$  UR                  S5      (       a$  X1S   -  nUSS nUR                  S5      (       a  M$  XR                  ;   a  U R                  U   $ U R                  UR	                  5       5      (       d  SR                  X!U/5      $ UR                  U R                  5      (       a-  SUR                  S5      S   -   nUR                  US5      nX5-  nXR                  ;  Ga  [        U R                  R                  5       S[        S9 H  nS	nUR                  U5      nUR                  S5      n	U	S   (       a  U	S   U R                  ;   a  Sn[        U5      S:X  d
  US   (       d  Ma  U(       d@  US   R                  S5      (       d  UR                  U5      (       a  [        TU ]9  U5      n  OLUR                  US   5      (       d  M   UR                  US   5      S   n
US   [        TU ]9  U
5      -   n  O   U(       d  [        TU ]9  U5      nX$-   U-   $ ! [         a     GM  f = f)
N )r   _r   r   r   r   T)r,   keyF)r   r:   r   rA   lowerr   
strip_extsr   r%   r.   keysr   r   r&   get	Exception)r   r(   prefixsuffixfinalextr   _host_substr_test_hitmr)   s              r    rJ   SoSHostnameMap.get   sB    ooj))1gF8D ooj)) mmJ''2hF":D mmJ'' <<<<%%11$**,?? 77F&122==))

3++C<<R(DMF||# $DLL$5$5$7(+-	$

9-__S) a5RUdjj0#'Lu:?%(#q):):3)?)?)-y)A)A!GK-E::eAh''"jjq215 %a57;s+; ;/-8 GK%E~&& % s   ,I&&
I54I5c                 b   UR                  S5      n[        U5      S:X  a"  U R                  US   R                  5       5      $ [        U5      S:X  a:  U R	                  U5      n[        S U 5       5      (       a  UR                  5       nU$ [        U5      S:  a  US   nUSS  n[        U5      S:  a   U R                  UR                  5       5      nOSnU R	                  U5      nXpR                  U'   SR                  Xg/5      n[        S U 5       5      (       a  UR                  5       nU$ g )Nr   r   r      c              3   @   #    U  H  oR                  5       v   M     g 7fr9   isupperr;   r4   s     r    r>   /SoSHostnameMap.sanitize_item.<locals>.<genexpr>        -199;;   unknownc              3   @   #    U  H  oR                  5       v   M     g 7fr9   rX   rZ   s     r    r>   r[      r\   r]   )	r   r   sanitize_short_namerG   sanitize_domainallupperr   r   )	r   r(   r-   dnamehostnamer   ob_hostname	ob_domain_fqdns	            r    sanitize_itemSoSHostnameMap.sanitize_item   s   zz#t9>++DGMMO<<t9>((.E----Lt9q=AwH!"XF8}q "66x~~7GH (,,V4I!*LLHHk56E----Lr#   c                    U(       a  XR                   ;   a  U$ XR                  ;  aQ  SU R                   3nX R                  U'   U =R                  S-  sl        X R                  U'   U R	                  U5        U R                  U   $ )ztObfuscate the short name of the host with an incremented counter
based on the total number of obfuscated host names
r-   r   )	skip_keysr   r1   r   add_regex_item)r   re   ob_hosts      r    r`   "SoSHostnameMap.sanitize_short_name   ss     8~~5O<<'T__-.G#*JJx OOq O%,LL")||H%%r#   c                    U R                    HA  n[        R                  " USR                  U5      5      (       d  M0  SR                  U5      s  $    US   R	                  5       nSR                  USS 5      R	                  5       nU R                  U5      nSR                  XS/5      nXPR                  SR                  U5      '   U$ )zUObfuscate the domainname, broken out into subdomains. Top-level
domains are ignored.
r   r   r   )ignore_matchesrematchr   rG   _new_obfuscated_domainr   )r   r   _skip
top_domainrd   rg   s         r    ra   SoSHostnameMap.sanitize_domain   s     ((Exxsxx/00xx'' ) BZ%%'
"&,,.//6	HHi45	)2SXXf%&r#   c                     XR                   ;  a1  SU R                   3U R                   U'   U =R                  S-  sl        U R                   U   $ )zDGenerate an obfuscated domain for each subdomain name given
        r   r   )r   r3   )r   rd   s     r    rt   %SoSHostnameMap._new_obfuscated_domain   sJ     %%5d6G6G5H#IDMM% "}}U##r#   )r3   r1   )__name__
__module____qualname____firstlineno____doc__rq   rl   rH   ignore_short_itemsmatch_full_words_onlyr1   r3   r   r   r!   r'   r   rA   rJ   ri   r`   ra   rt   __static_attributes____classcell__)r)   s   @r    r   r      s{    N 	I
-J  JLHE"<.( ;'z@&$ $r#   r   )rr   sos.cleaner.mappingsr   r    r#   r    <module>r      s    
 'p$V p$r#   