
    Id2                     f    d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 d Z
d Z G d d	e      Zy)
    N)
gp_pol_ext)misc)
get_string)logc                 <   | j                   t        j                  k(  r:t        | j                        j                  dd      }t        j                  |      S | j                   t        j                  k(  r| j                  dv r| j                  dk(  S | j                  S )N  )r      r
   )	typer   REG_MULTI_SZr   datareplacejsonloads	REG_DWORD)er   s     9/usr/lib/python3/dist-packages/samba/gp/gp_firefox_ext.pyparse_entry_datar      sp    vv"""!&&!))&"5zz$	
4>>	!aff&6vv{66M    c                 `   | d   }i }|D ]  }|j                   j                  |      s d|j                  v r/|j                   j                  |d      j	                  d      }|r*|j                  d      }|}d}|d   j                         rdj                  |d d       }	nN|j                  j                         r|j                   }	n'dj                  |j                   |j                  g      }	t        t        |            D ]?  }
||
   dk(  rd||
<   t        }|
t        |      dz
  k(  r5|j                  j                         rt        }t        |j                        }|
t        |      dz
  k  r-||
dz      j                         rt        }t        ||
dz            }t        |      t        k(  r*||
   |vr|t        k(  r	i |||
   <   ng |||
   <   |||
      }|	|vri ||	<   |||	   j                         vr@|t        k(  r|j                  i        n|j                  g        t        |      dz
  ||	   |<   |||	   |      }B t        |      t        k(  r|j                  t!        |             mt!        |      ||j                  <   t!        |      ||j                  <    d|iS )	Npoliciesz
**delvals.r	   \PDFjsPSFjsr
   )keyname
startswith	valuenamer   stripsplit	isnumericjoinrangelendictlistintr   keysappendr   )r   sectionentriesresult	index_mapr   sub_keyscurrentindexnameictypes               r   convert_pol_to_jsonr4       s   j!FI 06yy##G,1;;&99$$Wb177=~~d+HGE|%%'yy#2/&&(yyyy!))Q[[!9:3x=) >A;')")HQKHa'AKK,A,A,C E,Es8}Q&8AaC=+B+B+D E1.E=D({'1 D=35GHQK035GHQK0%hqk2G9,*,	$IdO$8$8$:: D=#NN2.#NN2.14Wa	$.%ioe&<=G5>6 G}$/23'7':$"21"5F1;;a06b r   c                       e Zd ZdZdZej                  j                  ed      Zej                  j                  ed      Z	d Z
d Zd Z	 d
dZd	 Zy)gp_firefox_extz/usr/lib64/firefox/distributionz/etc/firefox/policiespolicies.jsonc                      y)NzMozilla/Firefox )selfs    r   __str__zgp_firefox_ext.__str__\   s     r   c                    	 t        j                  | j                  d       t        | j                  d      5 }t        j                  ||       t        j                  d| j                         d d d        	 t        j                  | j                  d       t        | j                  d      5 }t        j                  ||       t        j                  d| j                         d d d        y # 1 sw Y   xY w# t        $ r# t        j                  d| j                         Y w xY w# 1 sw Y   y xY w# t        $ r# t        j                  d| j                         Y y w xY w)NT)exist_okwzWrote Firefox preferencesz#Failed to write Firefox preferences)osmakedirs$_gp_firefox_ext__firefox_installdir1open_gp_firefox_ext__destfile1r   dumpr   debugPermissionError$_gp_firefox_ext__firefox_installdir2_gp_firefox_ext__destfile2)r:   r   fs      r   set_machine_policyz!gp_firefox_ext.set_machine_policy_   s&   	0KK22TBd&&, I		(A&		5t7G7GHI	0KK22TBd&&, I		(A&		5t7G7GHI II I  	0II;"..0	0I I  	0II;"..0	0sX   7C< 7C00C< 97D7 07D+'D7 0C95C< <)D('D(+D40D7 4D7 7)E#"E#c                 >   t         j                  j                  | j                        rVt	        | j                  d      5 }t        j                  |      }t        j                  d| j                         d d d        |S t         j                  j                  | j                        rVt	        | j                  d      5 }t        j                  |      }t        j                  d| j                         d d d        |S di i}|S # 1 sw Y   S xY w# 1 sw Y   S xY w)NrzRead Firefox preferencesr   )
r?   pathexistsrH   rB   r   loadr   rE   rC   )r:   rL   r   s      r   get_machine_policyz!gp_firefox_ext.get_machine_policyr   s    77>>$**+d&&, H99Q<		4d6F6FGH  WW^^D,,-d&&, H99Q<		4d6F6FGH
  #B'HH H
 s    6D?6DDDNc                    |,|| _         t        j                  j                  |d      | _        |D ]  \  }}| j
                  j                  |       t        |       |v rm|t        |          j                         D ]N  \  }}| j                  t        j                  |             | j
                  j                  t        |       |       P | j
                  j                           |D ]  }|j                  sd}	| j
                  j                  |j                         d}
t        j                  j                  |j                  |
      }| j!                  |      }|sx| j#                         }| j
                  j%                  t        |       dt        j&                  |             t)        ||	|j*                        }| j                  |       | j
                  j                           y )Nr7   !Software\Policies\Mozilla\FirefoxMACHINE/Registry.pol)rG   r?   rM   r"   rH   gp_dbset_guidstritemsrJ   r   r   deletecommitfile_sys_pathr1   parserP   storedumpsr4   r+   )r:   deleted_gpo_listchanged_gpo_list
policy_dirguidsettings	attributer   gpor*   pol_filerM   pol_confs                r   process_group_policyz#gp_firefox_ext.process_group_policy   s   !)3D&!ww||JHD. 	 ND(JJ%4yH$+3CI+>+D+D+F <'Ix++DJJx,@AJJ%%c$i;< JJ	  $ 	$C  @

##CHH-1ww||C$5$5x@::d+224

  TO!%H!57.x/7/?/?A''1

!!#!	$r   c                 R   i }d}d}|j                   rt        j                  j                  |j                   |      }| j	                  |      }|s|S |j
                  D ]F  }|j                  j                  |      s|j                  ||j                  d|j                  <   H |S )NrS   rR   r   )
rZ   r?   rM   r"   r[   r+   r   r   r   r   )r:   rd   outputre   r*   rM   rf   r   s           r   rsopzgp_firefox_ext.rsop   s    )877<< 1 18<Dzz$'H%% I99''0BC&&Fqyy!++>?I r   )N)__name__
__module____qualname__rA   rG   r?   rM   r"   rC   rH   r;   rJ   rP   rg   rj   r9   r   r   r6   r6   V   sV    =3'',,4oFK'',,4oFK!0& )-$>r   r6   )r?   r   samba.gp.gpclassr   samba.dcerpcr   samba.commonr   samba.gp.util.loggingr   r   r4   r6   r9   r   r   <module>rr      s2   " 
  '  # %4 lTZ Tr   