
    hu                       d dl Z d dlZd dlmZ d dlZd dlZd dlmc m	Z
 d dlZd dlZd dlmZ d dlmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZmZ d dlmZ d dlZd dlZd d	lmZm Z m!Z! d d
l"m#Z# d dlm$Z$ d dl%m&Z' d dlm(Z( d dl)Z)d dl*m+Z+ d dlm,Z, d dl-m.Z. d dl/m0Z0m1Z1m2Z2 d dl3m4Z4 d dl5m6Z6m7Z7m8Z8m9Z9 d dl:m;Z; d dl<m=Z= d dl>m?Z? d dlm@Z@ d dl"mAZA d dlBmCZCmDZD d dlEmFZF d dlGmHZHmIZI d dlJmKZKmLZL d dlMZMd dlNZNd dlOmPZP d dlQmRZRmSZSmTZTmUZUmVZV d dlWmXZXmYZYmZZZ d d l[m\Z\ d d!l]m^Z^ d d"l_m`Z`maZambZb d# Zcd$ Zdd% Zed& Zfdd'Zgdddej                  ej                  z  ej                  z  ej                  z  fd(Zld) Zmd* Znd+ Zoej                  fd,Zqd- Zre'j                  e'j                  z  e'j                  z  e'j                  z  Zwd. Zx	 	 dd/Zy G d0 d1e      Zz G d2 d3ez      Z{ G d4 d5ez      Z| G d6 d7ez      Z} G d8 d9ez      Z~ G d: d;ez      Z G d< d=ez      Z G d> d?ez      Z G d@ dAez      Z G dB dCez      Z G dD dEez      Z G dF dGez      Z G dH dIez      Z G dJ dKez      Z G dL dMez      Z G dN dOe      Z G dP dQez      Z G dR dSez      Z G dT dUe      Z G dV dWez      Z G dX dYe      Z G dZ d[ez      Z G d\ d]e      Z G d^ d_ez      Z G d` dae      Z G db dce      Z G dd dee      Z G df dgez      Z G dh die      Z G dj dke      Z G dl dmez      Z G dn doez      Z G dp dqe      Z G dr dse      Z G dt duez      Z G dv dwez      Z G dx dye      Z G dz d{e      Z G d| d}ez      Z G d~ de      Z G d de      Z G d dez      Z G d dez      Z G d de      Z G d de      Z G d de      Z G d dez      Z G d de      Z G d de      Z G d dez      Z G d de      Z G d de      Z G d dez      Z G d dez      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zy)    N)system_session)CommandCommandErrorOptionSuperCommand)SamDB)dsdb)security)
ndr_unpackndr_pack)preg) AUTH_SESSION_INFO_DEFAULT_GROUPSAUTH_SESSION_INFO_AUTHENTICATED#AUTH_SESSION_INFO_SIMPLE_PRIVILEGES)netcmd_finddc)policy)libsmb_samba_internal)NTSTATUSError)dsacl2fsacl)nbt)Net)GPParserGPNoParserExceptionGPGeneralizeException)GPPolParser)GPIniParserGPTIniParserGPFDeploy1IniParserGPScriptsIniParser)GPAuditCsvParser)GptTmplInfParser)GPAasParser)param)attr_default)	get_bytes
get_string)ConfigParser)StringIOBytesIO)	calc_modestat_from_mode)str_regtype)NT_STATUS_OBJECT_NAME_INVALIDNT_STATUS_OBJECT_NAME_NOT_FOUNDNT_STATUS_OBJECT_PATH_NOT_FOUNDNT_STATUS_OBJECT_NAME_COLLISIONNT_STATUS_ACCESS_DENIED)create_directory_hiersmb_connection
get_gpo_dn)RegistryGroupPolicies)REG_MULTI_SZ)register_gp_extensionlist_gp_extensionsunregister_gp_extensionc                 ^    t        j                  |       }|sd}|S dj                  |      }|S )zreturn gpo flags stringNONE )r   get_gpo_flagsjoin)valueflagsrets      2/usr/lib/python3/dist-packages/samba/netcmd/gpo.pygpo_flags_stringrC   [   s5      'E J hhuoJ    c                 ^    t        j                  |       }|sd}|S dj                  |      }|S )zreturn gplink options stringr;   r<   )r   get_gplink_optionsr>   )r?   optionsrA   s      rB   gplink_options_stringrH   e   s6    ''.G J hhwJrD   c                 8   g }| j                         dk(  r|S | j                  d      }|D ]l  }|s|j                  d      }t        |      dk7  s|d   j                  d      st	        d|z        |j                  |d   dd	 t        |d
         d       n |S )z.parse a gPLink into an array of dn and options ];   r   z[LDAP://zBadly formed gPLink '%s'   N   dnrG   )stripsplitlen
startswithRuntimeErrorappendint)gplinkrA   agds        rB   parse_gplinkr]   o   s    
C||~
SA ;GGCLq6Q;adooj99A=>>

!A$qr(s1Q4y9:; JrD   c                 6    dj                  d | D              }|S )z4Encode an array of dn and options into gPLink stringrJ   c              3   6   K   | ]  }d |d   |d   fz    yw)z[LDAP://%s;%d]rQ   rG   N ).0r[   s     rB   	<genexpr>z encode_gplink.<locals>.<genexpr>   s#     M"agq|%<<Ms   )r>   )gplistrA   s     rB   encode_gplinkrd      s    
''MfM
MCJrD   c                 l    ||	 t        | |      }d|z   }|S # t        $ r}t        d|      d}~ww xY w)zjIf URL is not specified, return URL for writable DC.
    If dc is provided, use that to construct ldap URLNzCould not find a DC for domainldap://)r   	ExceptionrV   )lpcredsurldces        rB   dc_urlrm      sR     {:H"2u- "nJ  H"#CQGGHs    	3.3c                    | j                         }|j                  t        j                  | d             |}d}t        j                  }|dt        j
                  |      z  }|dt        j
                  |      z  }||}t        j                  }	 | j                  |||g dd|z  g      }	|	S # t        $ r}
|d	|z  }nd
}t        ||
      d}
~
ww xY w)z0Get GPO information using gpo, displayname or dnzCN=Policies,CN=Systemz"(objectClass=groupPolicyContainer)Nz.(&(objectClass=groupPolicyContainer)(name=%s))z5(&(objectClass=groupPolicyContainer)(displayname=%s)))nTSecurityDescriptorversionNumberr@   namedisplayNamegPCFileSysPathgPCMachineExtensionNamesgPCUserExtensionNamessd_flags:1:%d)basescope
expressionattrscontrolsz!Cannot get information for GPO %szCannot get information for GPOs)
get_default_basedn	add_childldbDnSCOPE_ONELEVELbinary_encode
SCOPE_BASEsearchrg   r   )samdbgpodisplaynamerQ   sd_flagspolicies_dnbase_dnsearch_exprsearch_scopemsgrl   mesgs               rB   get_gpo_infor      s     **,K#&&(?@AG6K%%L
FIZIZ[^I__MPSPaPabmPnn	~~~$ll|&1"; &5x%?$@  
B$ J  $?6<D4D4##$s   B1 1	C:CCc                 z    d|z  }	 | j                  |dg      }|S # t        $ r}t        d|z  |      d}~ww xY w)z lists dn of containers for a GPOz(&(objectClass=*)(gPLink=*%s*))gPLink)ry   rz   z'Could not find container(s) with GPO %sN)r   rg   r   )r   r   r   r   rl   s        rB   get_gpo_containersr      sV     4c9KOllk(lD J  ODsJANNOs    	:5:c                    	 | j                  |t        j                  ddg      d   }d}t        t        | |            }d|v r[t        t        |d   d               }|D ];  }|d   j                         |j                         k(  s(|j                  |       d	} n nt	        d
      |st	        d|z        t        j                         }	||	_        |r4t        |      }
t        j                  |
t        j                  d      |	d<   n.t        j                  |d   d   t        j                  d      |	d<   	 | j!                  |	       y# t        $ r}t	        d|z  |      d}~ww xY w# t        $ r}t	        d|      d}~ww xY w)z!delete GPO link for the container(objectClass=*)r   rw   rx   ry   rz   r   Container '%s' does not existNFrQ   Tz"No GPO(s) linked to this containerz%GPO '%s' not linked to this containerr0d0z!Error removing GPO from container)r   r~   r   rg   r   strr4   r]   lowerremoveMessagerQ   rd   MessageElementFLAG_MOD_REPLACEFLAG_MOD_DELETEmodify)r   container_dnr   r   rl   foundgpo_dnrc   r[   m
gplink_strs              rB   del_gpo_linkr      s   NllCNN&7"*  --.0 EE3'(F3c#h-"234 	Aw}}&,,.0a 		 ?@@BSHIIAAD"6*
$$Z1E1ExP$$$S]1%5s7J7JHU$CQ5  N:\I1MMN6  C>BBCs/   'E :E, 	E)E$$E),	F5FFc                     g }| j                  d      r| dd j                  dd      }n&| j                  d      r| dd j                  dd      }t        |      dk7  rt        d| z        |S )	z;Parse UNC string into a hostname, a service, and a filepath\\rM   N\z///   zInvalid UNC string: %s)rU   rS   rT   
ValueError)unctmps     rB   	parse_uncr      sl    
C
~~f!"gmmD!$		!"gmmC#
3x1}1C788JrD   c                    t        j                  d| |      r
t               S t        j                  d| |      r
t               S t        j                  d| |      r
t	               S t        j                  d| |      r
t               S t        j                  d| |      r
t               S t        j                  d| |      r
t               S t        j                  d| |      r
t               S t        j                  d	| |      r
t               S t        j                  d
| |      r
t               S t        j                  d| |      r
t               S t               S )Nzfdeploy1\.ini$r@   zaudit\.csv$zGptTmpl\.inf$z	GPT\.INI$zscripts\.ini$zpsscripts\.ini$z	GPE\.INI$z.*\.ini$z.*\.pol$z.*\.aas$)rematchr   r    r!   r   r   r   r   r   r"   )rq   r@   s     rB   find_parserr     s   	xx!4u5"$$	xxE2!!	xx $e4!!	xxd%0~	xx $e4!##	xx"D6!##	xxd%0
 z	xxT/}	xxT/}	xxT/}:rD   c                    d}t         j                  j                  |      st        j                  |       |g}|g}|r?|j	                         }|j	                         }| j                  |t              }|j                  d        |D ]  }	|dz   |	d   z   }
t         j                  j                  ||	d         }|	d   t        j                  z  r8|j                  |
       |j                  |       t        j                  |       | j                  |
      }t        ||z   d      5 }|j                  |       d d d        t        |	d         }|j!                  |       |j#                  |d	z           |r>y y # 1 sw Y   DxY w)
N.SAMBABACKUPattribsc                     | d   S Nrq   r`   xs    rB   <lambda>z2backup_directory_remote_to_local.<locals>.<lambda>+  
    AfI rD   keyr   rq   attribwb.xml)ospathisdirmkdirpoplist
attr_flagssortr>   libsmbFILE_ATTRIBUTE_DIRECTORYrW   loadfileopenwriter   parse	write_xml)conn	remotedirlocaldirSUFFIXr_dirsl_dirsr_dirl_dirdirlistrl   r_namel_namedatafparsers                  rB    backup_directory_remote_to_localr      sK   F77=="
]F\F




))E:)6-. 	2AT\AfI-FWW\\%63F{V<<<f%f% }}V,&6/40 "AGGDM" %QvY/T"  &1	2  " "s   +F  F		c                 v   t         j                  j                  |      st        j                  |       |g}|g}|r|j	                         }|j	                         }| j                  |t              }|j                  d        |D ]  }|dz   |d   z   }	t         j                  j                  ||d         }
|d   t        j                  z  r8|j                  |	       |j                  |
       t        j                  |
       | j                  |	      }t        |
d      j                  |        |ry y )Nr   c                     | d   S r   r`   r   s    rB   r   z0copy_directory_remote_to_local.<locals>.<lambda>N  r   rD   r   r   rq   r   r   )r   r   r   r   r   r   r   r   r>   r   r   rW   r   r   r   )r   r   r   r   r   r   r   r   rl   r   r   r   s               rB   copy_directory_remote_to_localr   D  s    77=="
[FZF




))E:)6-. 
	/AT\AfI-FWW\\%63F{V<<<f%f% }}V,VT"((.
	/ rD   c                    | j                  |      s| j                  |       |g}|g}|r|j                         }|j                         }t        j                  |      }	|	j                          |	D ]  }
t        j                  j                  ||
      }|dz   |
z   }t        j                  j                  |      r5|j                  |       |j                  |       	 | j                  |       |r	 | j                  |       t        |d      j                         }| j                  ||        |ry y # t        $ r |s Y w xY w# t        $ r Y Qw xY w)Nr   rb)chkpathr   r   r   listdirr   r   r>   r   rW   r   r   r   readsavefile)r   r   r   ignore_existing_dirkeep_existing_filesr   r   r   r   r   rl   r   r   r   s                 rB   copy_directory_local_to_remoter   \  s6    <<	"

9ZF[F




**U# 	,AWW\\%+FT\A%Fww}}V$f%f%JJv&
 'f-  FD)..0fd++	,  % . / ) s$    D;5E;E
	E
	EEc                       e Zd Zd Zd Zy)
GPOCommandc                 x   |.t        j                         }t        d|z  | j                         t        j
                  j                  |      st        d|z        t        j
                  j                  |d      }t        j
                  j                  |      st	        j                  |       t        j
                  j                  ||      }t        j
                  j                  |      rt        d|z        	 t	        j                  |       ||fS # t        t        f$ r}t        d|      d}~ww xY w)a  Ensure that the temporary directory structure used in fetch,
        backup, create, and restore is consistent.

        If --tmpdir is used the named directory must be present, which may
        contain a 'policy' subdirectory, but 'policy' must not itself have
        a subdirectory with the gpo name. The policy and gpo directories
        will be created.

        If --tmpdir is not used, a temporary directory is securely created.
        Nz5Using temporary directory %s (use --tmpdir to change))filez'Temporary directory '%s' does not existr   z8GPO directory '%s' already exists, refusing to overwritez%Error creating teporary GPO directory)tempfilemkdtempprintoutfr   r   r   r   r>   r   IOErrorOSError)selftmpdirr   r   gpodirrl   s         rB   construct_tmpdirzGPOCommand.construct_tmpdir  s    >%%'FIFRyy" ww}}V$H6QRR77<<1ww}}X&HHXh,77== JVSU U	KHHV v~ ! 	KFJJ	Ks    D D9(D44D9c                     	 t        | j                  t               | j                  | j                        | _        y# t        $ r}t        d| j                  z  |      d}~ww xY w)z$make a ldap connection to the serverrj   session_infocredentialsrh   zLDAP connection to %s failed N)r   rj   r   ri   rh   r   rg   r   )r   rl   s     rB   samdb_connectzGPOCommand.samdb_connect  sY    	N488,:,<+/::$''CDJ  	N>I1MM	Ns   := 	A$AA$N)__name__
__module____qualname__r   r   r`   rD   rB   r   r     s    !FNrD   r   c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZddZy
)cmd_listallzList all GPOs.%prog [options]	sambaoptsversionoptscredopts-H--URL%LDB URL for database or target serverURLHhelptypemetavardestNc                 B   |j                         | _        |j                  | j                  d      | _        t	        | j                  | j                  |      | _        | j                          t        | j                  d       }|D ]  }| j                  j                  d|d   d   z         | j                  j                  d|d   d   z         | j                  j                  d|d	   d   z         | j                  j                  d
|j                  z         | j                  j                  dt        |dd      z         | j                  j                  dt        t        t        |dd                  z         | j                  j                  d        y )NTfallback_machineGPO          : %s
rq   r   display name : %s
rr   path         : %s
rs   dn           : %s
version      : %s
rp   0flags        : %s
r@   
)get_loadparmrh   get_credentialsri   rm   rj   r   r   r   r   r   rQ   r$   rC   rX   )r   r  r  r	  r  r   r   s          rB   runzcmd_listall.run  sF   ((*--dgg-M
$''4::q14::t, 	"AIIOO1AfIaL@AIIOO1Am4DQ4GGHIIOO1A6F4G4JJKIIOO1ADD89IIOO1LOUX4YYZIIOO14DSVWY`bcIdEe4ffgIIOOD!	"rD   NNNNr   r  r  __doc__synopsisrG   SambaOptionsVersionOptionsCredentialsOptionstakes_optiongroupsr   r   takes_optionsr!  r`   rD   rB   r  r    sT     H ))--.. 	tW#JQT3	(M
"rD   r  c                       e Zd ZdZdZdgZej                  ej                  ej                  dZ
 edddedd	
      gZddZy)cmd_listzList GPOs for an account.z&%prog <username|machinename> [options]accountnamer  r
  r  r  r  r  r  Nc                 	   |j                         | _        |j                  | j                  d      | _        t	        | j                  | j                  |      | _        | j                          	 | j                  j                  dt        j                  |      dt        j                  |      d      }|d   j                  }	 | j                  j                  |t        j                  d	g
      d   }d|d	   v }t        t         z  }	| j
                  $| j
                  j#                  d      r	|	t$        z  }	t&        j(                  j+                  | j                  | j                  ||	      }
|
j,                  }g }d}t        j.                  | j                  t1        |            j3                         }	 | j                  j                  |t        j                  ddg
      d   }d|v rt5        t1        |d   d               }|D ]  }|s|d   t6        j8                  z  s|d   t6        j:                  z  r4	 t<        j>                  t<        j@                  z  t<        jB                  z  }| j                  j                  |d   t        j                  g dd|z  g      }|d   d   d   }tE        t<        jF                  |      }	 t&        j<                  jM                  ||t<        jN                  t<        jP                  z  t<        jR                  z         tW        tY        |d   dd            }|r|t6        jZ                  z  rD|s|t6        j\                  z  r[|j_                  |d   d   d   |d   d   d   f        tW        tY        |dd            }|t6        j`                  z  rd}|| j                  jc                         k(  rn|j3                         }0|rd}nd}| jH                  jK                  d|d|d        |D ]*  }| jH                  jK                  d!|d   d|d"   d        , y # t        $ r t        d|z        w xY w# t        $ r t        d|z        w xY w# t        $ r% | jH                  jK                  d|d   z         Y w xY w# tT        $ r, | jH                  jK                  d|j                  z         Y w xY w)#NTr  z(&(|(samAccountName=z)(samAccountName=z$))(objectClass=User)))ry   r   zFailed to find account %sobjectClass)rw   rx   rz   computerz!Failed to find objectClass for %sldap)lp_ctxrQ   session_info_flagsr   	gPOptionsrG   rQ   )rq   rr   r@   ro   rv   )rw   rx   rz   r{   ro   z8Failed to fetch gpo object with nTSecurityDescriptor %s
zFailed access check on %s
r@   rr   rq   Fuserz	GPOs for r<   r  z    rO   )2r  rh   r   ri   rm   rj   r   r   r   r~   r   rQ   rg   r   r   r   r   rU   r   sambaauthuser_sessionsecurity_tokenr   r   parentr]   r	   GPLINK_OPT_ENFORCEGPLINK_OPT_DISABLEr
   SECINFO_OWNERSECINFO_GROUPSECINFO_DACLr   
descriptorr   r   access_checkSEC_STD_READ_CONTROLSEC_ADS_LISTSEC_ADS_READ_PROPrV   rX   r$   GPO_FLAG_MACHINE_DISABLEGPO_FLAG_USER_DISABLErW   GPO_BLOCK_INHERITANCEr|   )r   r-  r  r  r	  r  r   user_dnis_computerr3  sessiontokengposinheritrQ   glistr[   r   gmsgsecdesc_ndrsecdescr@   	gpoptionsmsg_strs                           rB   r!  zcmd_list.run  s   ((*--dgg-M
$''4::q1	J**##%(%6%6{%CSEVEVWbEc0e# fC!fiiG
	R**##}o#^_`aC$M(::K ?=> 88DHH$7$7$?"EE**))$**TWW=O * Q &&VVDJJG-446**##3>>(T_I`#abcdC3$SXq)9%:; $QA"AiL4;R;R,R |d&=&== !$,$:$:$,$:$:%;$,$9$9%:  $zz00agS^^8P;JX;U:V  1  X '+1g.D&Ea&H",X-@-@+"N!33GU4<4Q4Q4<4I4I5J4<4N4N5OP  T!Wgq ABE"0M0M(M &ED4N4N,N KKa!7!:DGFOA<N OPI$QN Lk1=>I4555TZZ2244Bc f  GG		g{CD 	:AIIOOQqT1Q489	:g  	J:[HII	J  	RB[PQQ	RN % !		(c()$)0 1 ! ( !		(E(NO !s?   /AQ 7Q BQ:AR+QQ7:*R('R(+1S S r"  )r   r  r  r$  r%  
takes_argsrG   r&  r'  r(  r)  r   r   r*  r!  r`   rD   rB   r,  r,    sY    #7HJ))--.. 	tW#JS	2M
a:rD   r,  c                       e Zd ZdZdZej                  ej                  ej                  dZ	dgZ
 edde      gZd
d	Zy)cmd_showzShow information for a GPO.%prog <gpo> [options]r  r   r
  r  r  r  Nc                 	   |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }|| _        nGt        | j                  | j                        }t        | j                  | j                  |      | _        | j                          	 t        | j                  |      d   }	 |d   d   }t        t        j                  |      }	|	j!                         }
| j"                  j%                  d
|d   d   z         | j"                  j%                  d|d   d   z         | j"                  j%                  d|d   d   z         d|v r$| j"                  j%                  d|d   d   z         d|v r$| j"                  j%                  d|d   d   z         | j"                  j%                  d|j&                  z         | j"                  j%                  dt)        |dd      z         | j"                  j%                  dt+        t-        t)        |dd                  z         | j"                  j%                  d|
z         t/        |d| j                  | j                        }| j                  j1                  d      }dj3                  |j5                         d|d g      }g }d!D ]  }	 t        t6        j8                  |j;                  ||z              }|jH                  D ]  }|jJ                  d#k(  ri }|jL                  |d$<   |jJ                  |d%<   ||d&<   tO        |jP                        |d'<   |jR                  |d(<   tQ        |d(         tT        k(  r\|jP                  tV        k(  r8|d(   jY                  d)      }|j[                  d*      j]                  d*      |d(<   nt_        |d(         |d(<   |ja                  |        " | j"                  j%                  d+       tc        jd                  || j"                  d,-       | j"                  j%                  d.       y # t        $ r t        d|z        w xY w# t        $ r d	}
Y pw xY w# t<        $ rM}|j>                  d   t@        tB        tD        fv rY d }~|j>                  d   tF        k(  rt        d"       d }~ww xY w)/NTr  rf      rk   r   GPO '%s' does not existro   z<hidden>r  rq   r  rr   r  rs   rt   zMachine Exts : %s
ru   zUser Exts    : %s
r  r  rp   r  r  r@   zACL          : %s
sysvolrh   ri   realmr   Policiesz%s\Registry.pol)MACHINEUSER:The authenticated user does not have sufficient privilegesz
**delvals.keyname	valuenameclassr  r   z	utf-16-le zPolicies     :
   )indentr  )3r  rh   r   ri   rU   rj   r   rm   r   r   r   rg   r   r   r
   r@  as_sddlr   r   rQ   r$   rC   rX   r3   getr>   r   r   r   r   r   argsr-   r.   r/   r1   entriesre  rd  r,   r  r   bytesr6   decoderstriprS   r   rW   jsondump)r   r   r  r  r	  r  dc_hostnamer   rP  rQ  secdesc_sddlr   r_  pol_filepolicy_defspolicy_classpol_datarl   entrydefsr   s                        rB   r!  zcmd_show.runZ  sC   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH	@tzz3/2C	&45a8K !4!4kBG"??,L 			-FA>?		-M0B10EEF		-4D0Ea0HHI%,IIOO1C8R4STU4VVW"c)IIOO1C8O4PQR4SST		-67		-S/SV0WWX		-0@\RUW^`aEbAc0dde		-<= k&!%$(JJ0
 G$99ekkmZ 24 5/ 	)L%dii&*mmH|4K&LN ")) )??l2"'--Y$)OO[! ,W*5::6V$zzVV%.zz\1#F|22;?'+{{6':'@'@'HV'+DL'9V""4(!)	)> 			*+		+tyy3		C  	@83>??	@  	&%L	&: ! 66!9!>!@!@!B B 66!9 77& (H I Is<   0Q 
2Q ,Q0QQ-,Q-0	S9 S"SSr"  r   r  r  r$  r%  rG   r&  r'  r(  r)  rT  r   r   r*  r!  r`   rD   rB   rV  rV  I  sT    %&H ))--.. J 	tALMRrD   rV  c            
           e Zd ZdZdZej                  ej                  ej                  dZ	dgZ
 edde       edd	e       ed
dddgd       eddddgd       edddd      gZ	 	 	 	 ddZy)cmd_loada  Load policies onto a GPO.

    Reads json from standard input until EOF, unless a json formatted
    file is provided via --content.

    Example json_input:
    [
        {
            "keyname": "Software\Policies\Mozilla\Firefox\Homepage",
            "valuename": "StartPage",
            "class": "USER",
            "type": "REG_SZ",
            "data": "homepage"
        },
        {
            "keyname": "Software\Policies\Mozilla\Firefox\Homepage",
            "valuename": "URL",
            "class": "USER",
            "type": "REG_SZ",
            "data": "google.com"
        },
        {
            "keyname": "Software\Microsoft\Internet Explorer\Toolbar",
            "valuename": "IEToolbar",
            "class": "USER",
            "type": "REG_BINARY",
            "data": [0]
        },
        {
            "keyname": "Software\Policies\Microsoft\InputPersonalization",
            "valuename": "RestrictImplicitTextCollection",
            "class": "USER",
            "type": "REG_DWORD",
            "data": 1
        }
    ]

    Valid class attributes: MACHINE|USER|BOTH
    Data arrays are interpreted as bytes.

    The --machine-ext-name and --user-ext-name options are multi-value inputs
    which respectively set the gPCMachineExtensionNames and gPCUserExtensionNames
    ldap attributes on the GPO. These attributes must be set to the correct GUID
    names for Windows Group Policy to work correctly. These GUIDs represent
    the client side extensions to apply on the machine. Linux Group Policy does
    not enforce this constraint.
    {35378EAC-683F-11D2-A89A-00C04FBBCFA2} is provided by default, which
    enables most Registry policies.
    rW  r  r   r
  r  rX  	--contentJSON file of policy inputs--machine-ext-namerW   machine_exts&{35378EAC-683F-11D2-A89A-00C04FBBCFA2}z;A machine extension name to add to gPCMachineExtensionNames)actionr  defaultr  --user-ext-name	user_extsz5A user extension name to add to gPCUserExtensionNamesz	--replace
store_trueFz8Replace the existing Group Policies, rather than mergingr  r  r  Nc
                    |dg}|dg}|2t        j                  t        j                  j	                               }
nUt
        j                  j                  |      r+t        |d      5 }t        j                  |      }
d d d        nt        d      |j                         | _        |j                  | j                  d      | _        t        | j                  | j                  |      | _        | j#                          t%        || j                  | j                  | j&                  |      }|D ]  }|j)                  |d        |D ]  }|j)                  |d        	 |r|j+                  
       y |j-                  
       y # 1 sw Y   xY w# t.        $ r'}|j0                  d   t2        k(  rt        d	       d }~ww xY w)
Nr  r   $The JSON content file does not existTr  rt   ru   r   rc  )rq  loadssysstdinr   r   r   existsr   loadr   r  rh   r   ri   rm   rj   r   r5   r   register_extension_name	replace_smerge_sr   rl  r1   )r   r   r  contentr  r  replacer  r	  r  rv  rregext_namerl   s                  rB   r!  zcmd_load.run  s    DELABI?**SYY^^%56KWW^^G$gt$ +"iil+ + EFF((*--dgg-M
$''4::q1#C$**djj!L$ 	NH''2LM	N! 	KH''2IJ	K
	k*K(%+ +&  	vvay33" $D E E 	s*   *F!F 5F F	G"F>>G)NNNNFNNNr{  r`   rD   rB   r}  r}    s    0d 'H ))--.. J 	tAL{!=CH#.=>N	P 	 +=>H	J 	{<N	PM (,FJ#rD   r}  c            
           e Zd ZdZdZej                  ej                  ej                  dZ	dgZ
 edde       edd	e       ed
dg dd       eddg dd      gZ	 	 ddZy)
cmd_removeag  Remove policies from a GPO.

    Reads json from standard input until EOF, unless a json formatted
    file is provided via --content.

    Example json_input:
    [
        {
            "keyname": "Software\Policies\Mozilla\Firefox\Homepage",
            "valuename": "StartPage",
            "class": "USER",
        },
        {
            "keyname": "Software\Policies\Mozilla\Firefox\Homepage",
            "valuename": "URL",
            "class": "USER",
        },
        {
            "keyname": "Software\Microsoft\Internet Explorer\Toolbar",
            "valuename": "IEToolbar",
            "class": "USER"
        },
        {
            "keyname": "Software\Policies\Microsoft\InputPersonalization",
            "valuename": "RestrictImplicitTextCollection",
            "class": "USER"
        }
    ]

    Valid class attributes: MACHINE|USER|BOTH
    rW  r  r   r
  r  rX  r~  r  r  rW   r  z@A machine extension name to remove from gPCMachineExtensionNames)r  r  r  r  r  r  z:A user extension name to remove from gPCUserExtensionNamesNc	                 `   |g }|g }|2t        j                  t        j                  j	                               }	nUt
        j                  j                  |      r+t        |d      5 }
t        j                  |
      }	d d d        nt        d      |j                         | _        |j                  | j                  d      | _        t        | j                  | j                  |      | _        | j#                          t%        || j                  | j                  | j&                  |      }|D ]  }|j)                  |d        |D ]  }|j)                  |d        	 |j+                  	       y # 1 sw Y   xY w# t,        $ r'}|j.                  d   t0        k(  rt        d       d }~ww xY w)	Nr   r  Tr  rt   ru   r   rc  )rq  r  r  r  r   r   r   r  r   r  r   r  rh   r   ri   rm   rj   r   r5   r   unregister_extension_nameremove_sr   rl  r1   )r   r   r  r  r  r  r  r	  r  rv  r  r  r  rl   s                 rB   r!  zcmd_remove.runW  s   LI?**SYY^^%56KWW^^G$gt$ +"iil+ + EFF((*--dgg-M
$''4::q1#C$**djj!L$ 	PH))(4NO	P! 	MH))(4KL	M	LL%+ +   	vvay33" $D E E 	s$   (E1E= 1E:=	F-"F((F-NNNNNNNr{  r`   rD   rB   r  r  !  s    @ 'H ))--.. J 	tAL{!=CH#RnS	U 	 RkM	O	M KO7;rD   r  c                       e Zd ZdZdZej                  ej                  ej                  dZ	dgZ
 edde      gZ	 	 d
d	Zy)cmd_getlinkzList GPO Links for a container.%prog <container_dn> [options]r  r   r
  r  rX  Nc                    |j                         | _        |j                  | j                  d      | _        t	        | j                  | j                  |      | _        | j                          	 | j                  j                  |t        j                  ddg      d   }d|v r|d   r| j                  j                  d|z         t        t!        |d   d               }|D ]  }t#        | j                  |d	   
      }| j                  j                  d|d   d   d   z         | j                  j                  d|d   d   d   z         | j                  j                  dt%        |d         z         | j                  j                  d        y | j                  j                  d|z         y # t        $ r t        d|z        w xY w)NTr  r   r   r   r   r   zGPO(s) linked to DN %s
rQ   )rQ   z    GPO     : %s
rq   z    Name    : %s
rr   z    Options : %s
rG   r  zNo GPO(s) linked to DN=%s
)r  rh   r   ri   rm   rj   r   r   r   r~   r   rg   r   r   r   r]   r   r   rH   )	r   r   r  r  r	  r  r   rc   r[   s	            rB   r!  zcmd_getlink.run  s    ((*--dgg-M
$''4::q1	O**##S^^/@+3* $ 6679C s?s8}IIOO6EF!#c(mA&6"78F &"4::!D':		 4s1vf~a7H HI		 4s1vm7LQ7O OP		 47LQy\7Z Z[		%& IIOO9LHI  	O>MNN	Os   /1F5 5Gr"  r{  r`   rD   rB   r  r  x  s_    )/H ))--.. !!J 	tALM BFJrD   r  c            	           e Zd ZdZdZej                  ej                  ej                  dZ	ddgZ
 edde       ed	d
ddd       eddddd      gZ	 	 ddZy)cmd_setlinkz(Add or update a GPO link to a container.$%prog <container_dn> <gpo> [options]r  r   r   r
  r  rX  z	--disabledisabledFr  zDisable policyr  r  r  r  z	--enforceenforcedzEnforce policyNc	                    |j                         | _        |j                  | j                  d      | _        t	        | j                  | j                  |      | _        | j                          d}	|r|	t        j                  z  }	|r|	t        j                  z  }		 t        | j                  |      d    t        t        | j                  |            }
	 | j                  j!                  |t"        j$                  ddg      d   }d
}d|v rxt'        t        |d   d               }d}d
}|D ]/  }|d   j)                         |
j)                         k(  s(|	|d<   d} n |rt        d|z        |j+                  d|
|	d       ng }|j-                  |
|	d       t/        |      }t#        j0                         }t#        j2                  | j                  |      |_        |r)t#        j6                  |t"        j8                  d      |d<   n(t#        j6                  |t"        j:                  d      |d<   	 | j                  j=                  |       | j>                  jA                  d       tC               jE                  |||||       y # t        $ r t        d|z        w xY w# t        $ r t        d	|z        w xY w# t        $ r}t        d|      d }~ww xY w)NTr  r   r   r\  r   r   r   r   FrQ   rG   z)GPO '%s' already linked to this containerrP   	new_valuezError adding GPO LinkzAdded/Updated GPO link
)#r  rh   r   ri   rm   rj   r   r	   r<  r;  r   r   rg   r   r   r4   r   r~   r   r]   r   insertrW   rd   r   r   rQ   r   r   FLAG_MOD_ADDr   r   r   r  r!  )r   r   r   r  r  r  r  r	  r  gplink_optionsr   r   existing_gplinkrc   r   r[   r   r   rl   s                      rB   r!  zcmd_setlink.run  s    ((*--dgg-M
$''4::q1d555Nd555N	@-a0 Z

C01	O**##S^^/@+3* $ 6679C  s?!#c(mA&6"78F"OE T7==?flln4#1AiL E	
 "#NQT#TUUa>!JKFMMNCD"6*
KKMvvdjj,/ //
C<P<PRZ[AkN //
C<L<LhWAkN	;JJa  			23,9hL_  	@83>??	@  	O>MNN	OD  	;6::	;s0   J 1J! 2J< J!J9<	KKK)NFFNNNr{  r`   rD   rB   r  r    s    25H ))--.. !%(J 	tAL{U<$	&{U<$	&	M GL7;BMrD   r  c                       e Zd ZdZdZej                  ej                  ej                  dZ	ddgZ
 edde      gZ	 	 dd
Zy	)cmd_dellinkz!Delete GPO link from a container.r  r  	containerr   r
  r  rX  Nc                 (   |j                         | _        |j                  | j                  d      | _        t	        | j                  | j                  |      | _        | j                          	 t        | j                  |      d    t        j                  | j                  |      }t        | j                  ||       | j                  j                  d       t!               j#                  |||||       y # t        $ r t        d|z        w xY w)NTr  r  r   r\  zDeleted GPO link.
)r  rh   r   ri   rm   rj   r   r   r   rg   r   r~   r   r   r   r   r  r!  )r   r  r   r  r  r	  r  r   s           rB   r!  zcmd_dellink.run  s     ((*--dgg-M
$''4::q1	@-a0 vvdjj)4TZZs3		-.,9hL  	@83>??	@s   /C9 9Dr"  r{  r`   rD   rB   r  r    sa    +5H ))--.. u%J 	tALM DHMrD   r  c                       e Zd ZdZdZej                  ej                  ej                  dZ	dgZ
 edde      gZ	 	 d
d	Zy)cmd_listcontainersz%List all linked containers for a GPO.rW  r  r   r
  r  rX  Nc                    |j                         | _        |j                  | j                  d      | _        t	        | j                  | j                  |      | _        | j                          t        | j                  |      }t        |      rG| j                  j                  d|z         |D ]#  }| j                  j                  d|d   z         % y | j                  j                  d|z         y )NTr  zContainer(s) using GPO %s
z    DN: %s
rQ   zNo Containers using GPO %s
)r  rh   r   ri   rm   rj   r   r   r   rT   r   r   )r   r   r  r  r	  r  r   r   s           rB   r!  zcmd_listcontainers.run9  s     ((*--dgg-M
$''4::q1 S1s8IIOO9C?@ :		4 89: IIOO:S@ArD   r"  r{  r`   rD   rB   r  r  (  s\    /&H ))--.. J 	tALM 9=BrD   r  c                       e Zd ZdZdZej                  ej                  ej                  dZ	dgZ
 edde      gZ	 	 d
d	Zy)cmd_getinheritancez%Get inheritance flag for a container.r  r  r   r
  r  rX  Nc                 :   |j                         | _        |j                  | j                  d      | _        t	        | j                  | j                  |      | _        | j                          	 | j                  j                  |t        j                  ddg      d   }d}d|v rt        |d   d         }|t        j                  k(  r| j                   j#                  d       y | j                   j#                  d	       y # t        $ r t        d|z        w xY w)
NTr  r   r4  r   r   r   z$Container has GPO_BLOCK_INHERITANCE
zContainer has GPO_INHERIT
)r  rh   r   ri   rm   rj   r   r   r   r~   r   rg   r   rX   r	   rG  r   r   )r   r   r  r  r	  r  r   inheritances           rB   r!  zcmd_getinheritance.run]  s    ((*--dgg-M
$''4::q1	O**##S^^/@+6- $ 99:<C #c+.q12K$444IIOOCDIIOO9:  	O>MNN	Os   /1D Dr"  r{  r`   rD   rB   r  r  L  s^    //H ))--.. !!J 	tALM BF;rD   r  c                       e Zd ZdZdZej                  ej                  ej                  dZ	ddgZ
 edde      gZ	 	 dd
Zy	)cmd_setinheritancez$Set inheritance flag on a container.z.%prog <container_dn> <block|inherit> [options]r  r   inherit_stater
  r  rX  Nc                    |j                         dk(  rt        j                  }n2|j                         dk(  rt        j                  }nt	        d|z        |j                         | _        |j                  | j                  d      | _        t        | j                  | j                  |      | _
        | j                          	 | j                  j                  |t        j                  ddg      d	   }t        j"                         }	t        j$                  | j                  |      |	_        d|v r2t        j(                  t+        |      t        j,                  d      |	d<   n1t        j(                  t+        |      t        j.                  d      |	d<   	 | j                  j1                  |	       y # t         $ r t	        d
|z        w xY w# t         $ r}
t	        d|z  |
      d }
~
ww xY w)NblockrM  zUnknown inheritance state (%s)Tr  r   r4  r   r   r   r  z"Error setting inheritance state %s)r   r	   rG  GPO_INHERITr   r  rh   r   ri   rm   rj   r   r   r   r~   r   rg   r   r   rQ   r   r   r   r  r   )r   r   r  r  r  r	  r  r  r   r   rl   s              rB   r!  zcmd_setinheritance.run  s     G+44K  "i/**K?-OPP((*--dgg-M
$''4::q1	O**##S^^/@+6- $ 99:<C KKMvvdjj,/# //K0@#BVBVXcdAkN //K0@#BRBRT_`AkN	XJJa   	O>MNN	O  	XCmSUVWW	Xs$   1F3 G 3G	G+G&&G+r"  r{  r`   rD   rB   r  r  x  sa    .?H ))--.. !/2J 	tALM QU"XrD   r  c                       e Zd ZdZdZej                  ej                  ej                  dZ	dgZ
 edde       edd	e      gZddZy
)	cmd_fetchzDownload a GPO.rW  r  r   r
  r  rX  --tmpdir,Temporary directory for copying policy filesNc                 D   |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }|| _        nGt        | j                  | j                        }t        | j                  | j                  |      | _        | j                          	 t        | j                  |      d   }t        |d   d         }		 t        |	      \  }
}}t!        ||| j                  | j                  
      }| j#                  ||      \  }}	 t%        |||       | j&                  j)                  d|z         y # t        $ r t        d|z        w xY w# t        $ r t        d	|	z        w xY w# t        $ r}t        d|      d }~ww xY w)NTr  rf   rZ  r[  r   r\  rs   Invalid GPO path (%s)r^  Error copying GPO from DCGPO copied to %s
)r  rh   r   ri   rU   rj   r   rm   r   r   r   rg   r   r   r   r   r3   r   r   r   r   )r   r   r  r   r  r	  r  rs  r   r   dom_nameservice	sharepathr   r   rl   s                   rB   r!  zcmd_fetch.run  s   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH	@tzz3/2C
 #&'*+	>-6s^*Xw	
 k7tww$(JJ0 ..vs;	?*4FC 			,v56-  	@83>??	@  	>6<==	>  	?:A>>	?s0   0E E* #F E'*F	FFFNNNNNr{  r`   rD   rB   r  r    sa    &H ))--.. J 	tALz NUXYM
&7rD   r  c            	           e Zd ZdZdZej                  ej                  ej                  dZ	dgZ
 edde       edd	e       ed
ddd       eddde      gZ	 	 ddZed        Zy)
cmd_backupzBackup a GPO.rW  r  r   r
  r  rX  r  r  z--generalizez"Generalize XML entities to restoreFr  r  r  r  
--entitiesz4File to export defining XML entities for the restoreent_file)r  r  r  Nc	           	      &   |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }	|| _        nGt        | j                  | j                        }	t        | j                  | j                  |	      | _        | j                          	 t        | j                  |      d   }
t        |
d   d         }	 t        |      \  }}}t!        |	|| j                  | j                  
      }| j#                  ||      \  }}	 t%        |||       | j&                  j)                  d|z         |r| j&                  j)                  d       t*        j-                  | j&                  ||      }dd l}dj1                  d t3        |j5                         |j7                  d            D              }|rEt9        |d      5 }|j)                  |       d d d        | j&                  j)                  d|z         n6| j&                  j)                  d       | j&                  j)                  |       dD ]T  }||
v st9        t:        j<                  j1                  ||dz         d      5 }|j)                  |
|   d          d d d        V y # t        $ r t        d|z        w xY w# t        $ r t        d	|z        w xY w# t        $ r}t        d|      d }~ww xY w# 1 sw Y   xY w# 1 sw Y   xY w)NTr  rf   rZ  r[  r   r\  rs   r  r^  r  r  z(
Attempting to generalize XML entities:
rJ   c              3   j   K   | ]+  }d j                  |d   j                  d      |d          - yw)z<!ENTITY {} "{}
">rO   z&;r   N)formatrR   )ra   ents     rB   rb   z!cmd_backup.run.<locals>.<genexpr>.  s9      ^!$ 177AT8JCPQFS ^s   13rO   r   wz$Entities successfully written to %s
z
Entities:
rt   ru   	.SAMBAEXTr   )r  rh   r   ri   rU   rj   r   rm   r   r   r   rg   r   r   r   r   r3   r   r   r   r   r  generalize_xml_entitiesoperatorr>   sorteditems
itemgetterr   r   r   )r   r   r  r   
generalizer  r	  r  r  rs  r   r   r  r  r  r   r   rl   entitiesr  entsr   exts                          rB   r!  zcmd_backup.run  s    ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH	@tzz3/2C
 #&'*+	>-6s^*Xw	
 k7tww$(JJ0 ..vs;	?,T9fE
 			,v56IIOOHI!99$))V:@BH77 ^(.x~~/?XEXEXYZE[(\^ ^D (C( "AGGDM"		 G (!) * 		0		% I 	)Ccz"'',,vs[/@A4H )AGGCHQK() )	)W  	@83>??	@  	>6<==	>  	?:A>>	?" ") )sH   0J' K #K K:L'J?K	K7&K22K7:LL	c                    i }t         j                  j                  |      st        j                  |       |g}|g}|r|j	                         }|j	                         }t        j
                  |      }|j                          |D ]  }	t         j                  j                  ||	      }
t         j                  j                  ||	      }t         j                  j                  |
      rX|j                  |
       |j                  |       t         j                  j                  |      rt        j                  |       |
j                  d      r}t         j                  j                  |
      d d }t        |      }	 t        |
d      5 }|j                         }d d d        t        j                         }|j#                  |||      }It         j                  j)                  |
|      rkt+        j,                  |
|        |r|S # 1 sw Y   txY w# t$        $ r | j'                  d|z         Y w xY w)Nr   r  z%SKIPPING: Generalizing failed for %s
)r   r   r  r   r   r   r   r>   r   rW   endswithbasenamer   r   r   ET
fromstringgeneralize_xmlr   r   samefileshutilcopy2)r   	sourcedir	targetdirr  r   r   r   r   r   rl   r   r   to_parser   ltempr   concrete_xmlfound_entitiess                     rB   r  z"cmd_backup.generalize_xml_entities@  s   ww~~i(HHYJJLEJJLEjj'GLLN !9eQ/eQ/77==(MM&)MM&)77>>&1(v. $&77#3#3F#;CR#@!,X!6\!%fc!2 4e',zz|4 ,.==+>L-3-B-B<QWYa-bN  "ww//?"LL8C!9 R #4 4
  5 \ JJ'ORZ'Z[\s*   HH0HH	HH>=H>)NNFNNNN)r   r  r  r$  r%  rG   r&  r'  r(  r)  rT  r   r   r*  r!  staticmethodr  r`   rD   rB   r  r    s    &H ))--.. J 	tALz NUXY~$H\	3|"XS	*M IM6:?)B 1 1rD   r  c                       e Zd ZdZdZej                  ej                  ej                  dZ	dgZ
 edde       edd	e      gZ	 	 ddZy
)
cmd_createzCreate an empty GPO.z%prog <displayname> [options]r  r   r
  r  rX  r  r  Nc                    |j                         | _        |j                  | j                  d      | _        t	        | j                  | j                        }|rc|j                  d      rR|dd  }|| _        t        j                  t        j                  z  t        j                  z  }	|j                  ||	      }
nt        j                  t        j                  z  t        j                  z  }	|j                  | j                  j                  d      |	      }
|
j                  }t        | j                  | j                  |	      | _        | j                          t!        | j"                  |
      }|j$                  dkD  rt'        d|z        t)        t+        j,                               }d|j/                         z  }|| _        |
j2                  }d|d|d|}| j5                  ||      \  | _        }|| _        	 t;        j<                  t:        j>                  jA                  |d             t;        j<                  t:        j>                  jA                  |d             d}tC        t:        j>                  jA                  |d      d      jE                  |       tI        |      \  }}}|| _%        tM        ||| j                  | j                        }|| _'        | j"                  jQ                          	 tS        | j"                  |      }tU        jV                         }||_,        tU        jZ                  dtT        j\                  d      |d<   | j"                  j_                  |       tU        jV                         }tU        j`                  | j"                  dt)        |      z        |_,        tU        jZ                  dtT        j\                  d      |d<   | j"                  j_                  |       tU        jV                         }tU        j`                  | j"                  dt)        |      z        |_,        tU        jZ                  dtT        j\                  d      |d<   | j"                  j_                  |       tb        jd                  tb        jf                  z  tb        jh                  z  }t!        | j"                  ||      d   }|d   d   }tk        tb        jl                  |      jo                         }tc        jp                  | j"                  js                               }tu        ||      }tb        jl                  jw                  ||      }ty        ||       tb        jd                  tb        jf                  z  tb        jh                  z  tb        jz                  z  }|j}                  |||       t        |||       tU        jV                         }||_,        tU        jZ                  |tT        j                  d       |d!<   tU        jZ                  |tT        j                  d"      |d#<   tU        jZ                  d$tT        j                  d%      |d&<   tU        jZ                  d'tT        j                  d(      |d)<   tU        jZ                  d$tT        j                  d*      |d+<   d,g} | j"                  j                  || -       | j"                  j                          |t        j                  | j6                         | j                  jE                  d.|d/|d0       y # tF        $ r}t'        d|      d }~ww xY w# tF        $ r | j"                  j                           w xY w)1NTr  )ri   rh   rf   rZ  )addressr@   r_  )domainr@   r[  )r   r   z%A GPO already existing with name '%s'{%s}r   z\sysvol\z
\Policies\MachineUserz[General]
Version=0
zGPT.INIr  zError Creating GPO filesr^  groupPolicyContainerr/  a01
CN=User,%sr  CN=Machine,%s)r   r   ro   rr   a02rs   a03r  rp   a052gpcFunctionalityVersiona07r@   a04zpermissive_modify:0)r{   zGPO 'z' created as r  )Gr  rh   r   ri   r   rU   rj   r   NBT_SERVER_LDAPNBT_SERVER_DSNBT_SERVER_WRITABLEfinddcrk  pdc_dns_namerm   r   r   r   countr   r   uuiduuid4uppergpo_name
dns_domainr   r   r   r   r   r   r>   r   r   rg   r   r  r3   r   transaction_startr4   r~   r   rQ   r   r  addr   r
   r=  r>  r?  r   r@  rj  dom_sidget_domain_sidr   	from_sddlr2   SECINFO_PROTECTED_DACLset_aclr   r   r   transaction_committransaction_cancelr  rmtreer   )!r   r   r  r   r  r	  r  netrs  r@   	cldap_retr   guidr   r_  unc_pathr   gpt_contentsrl   r  r  r  r   r   r   ds_sd_flags	ds_sd_ndrds_sd
domain_sidsddlfs_sdsior{   s!                                    rB   r!  zcmd_create.run  s    ((*--dgg-M


tww/ i(AB%KDH((&&',,-E 

;e
DI((&&',,-E 

$''++g*>e
LI#00KdggtzzkBDH4::;?99q=FTUU DJJL!tzz|#$$9>sK #33FC@V	>HHRWW\\&)45HHRWW\\&&127Lfi0#6<<\J
 *38)<&7I"k7tww$(JJ0 	

$$&<	,

C0FAAD))*@#BRBRTabAeHJJNN1 A66$**lS[&@AAD))+s7G7GWAeHJJNN1 A66$**oF&CDAD))+s7G7GWAeHJJNN1 $11#112#001K tzzs[I!LC23A6Ix22I>FFHE "))$***C*C*EFJuj1D''11$
CE "$	2 ))))*(() 223C LLE3/ +4CAAD))+s7K7K][AeH))(C4H4HJZ[AeH))#s/C/C_UAeH))#s/C/CE^_AeH))#s/C/CWMAeH-.HJJa(3
 JJ))+>MM$++&		k3GH]  	>91==	>H  	JJ))+	s&   B!\) ?O] )	]2\>>]%]+r  r{  r`   rD   rB   r  r  u  sm    .H ))--..  J 	tALz NUXYM
 NR~IrD   r  c            	            e Zd ZdZdZej                  ej                  ej                  dZ	ddgZ
 edde       ed	d
e       edde       edddd      gZddZ	 	 d fd	Z xZS )cmd_restorez!Restore a GPO to a new container.z/%prog <displayname> <backup location> [options]r  r   backupr
  r  rX  r  r  r  z8File defining XML entities to insert into DOCTYPE headerz--restore-metadataz7Keep the old GPT.INI file and associated version numberFr  r  c                 <   d}t         j                  j                  |      st        j                  |       |g}|g}|r|j	                         }|j	                         }t        j
                  |      }	|	j                          |	D ]  }
t         j                  j                  ||
      }t         j                  j                  ||
      }t         j                  j                  |      rX|j                  |       |j                  |       t         j                  j                  |      rt        j                  |       |j                  d      st         j                  j                  |      d d }t        |      }	 t        |d      5 }|j                         }d}|j                  |      r9|t!        |      d  }|j#                  t%        j&                  ||z   |z                n'|j#                  t%        j&                  ||z                |j)                  |d d        d d d         |ry y # 1 sw Y   xY w# t*        $ r^ |d d |z   }t-        j.                  ||d d        | j0                  j3                  d|z         | j0                  j3                  d       Y " dd l}|j7                          |d d |z   }t-        j.                  ||d d        | j0                  j3                  d	|z         | j0                  j3                  d       Y xY w)
Nr   r   r  r  z&<?xml version="1.0" encoding="utf-8"?>zWARNING: No such parser for %s
z.WARNING: Falling back to simple copy-restore.
r   z%WARNING: Error during parsing for %s
)r   r   r  r   r   r   r   r>   r   rW   r  r  r   r   r   rU   rT   load_xmlr  r  write_binaryr   r  r  r   r   	traceback	print_exc)r   r  r  
dtd_headerr   r   r   r   r   r   rl   r   r   r  r   r  r   xml_headoriginal_filer,  s                       rB    restore_from_backup_to_local_dirz,cmd_restore.restore_from_backup_to_local_dir  s}   ww~~i(HHYJJLEJJLEjj'GLLN 4_eQ/eQ/77==(MM&)MM&)77>>&1(v. $&77#3#3F#;CR#@!,X!6#_!%fc!2 Ae',zz|+S#'??8#< ,0H+?D %+OOBMM(ZBWZ^B^4_$`$*OOBMM*tBS4T$U !' 3 3F3BK @!A%4_ 0A A$  3 _,23BK&,@M"LLsD IIOO,NQY,YZ IIOO,]^	_,%//1 -33BK&,@M"LLsD IIOO,TW],]^ IIOO,]^s-   IBH7&I7I 	<IA#L)A/Lc
                    d}
t         j                  j                  |      st        d|z        |d}
t         j                  j                  |      st        d|z        t	        |d      5 }|j                         }t        j                  d|t        j                        	 t        d      |
|j                         z  }
d d d        |
d	z  }
t        t        | 3  ||||||       	 | j                  || j                  |
       |	 }t        | j                   | j                  | j"                  d
|       t%        | j&                  | j(                        }dD ]  }t         j                  j+                  ||dz         }t         j                  j                  |      sFt	        |d      5 }|j                         }d d d        t-        j.                         }||_        t-        j2                  t,        j4                  |      ||<   | j&                  j7                  |        y # 1 sw Y   dxY w# 1 sw Y   wxY w# t8        $ r}dd l}|j=                          | j>                  jA                  tC        |      dz          | j>                  jA                  d       tE               }|j                  | j(                  ||||       t        d|z        d }~ww xY w)NrJ   z"Backup directory does not exist %sz<!DOCTYPE foobar [
zEntities file does not exist %sr  z*(\s*<!ENTITY\s*[a-zA-Z0-9_]+\s*.*?>)+\s*\Zr   zPEntities file does not appear to conform to format
e.g. <!ENTITY entity "value">z
]>
T)r   r   r  r  r   r   r  z%Failed to restore GPO -- deleting...
zFailed to restore: %s)#r   r   r  r   r   r   r   r   	MULTILINErR   superr'  r!  r1  r   r   r   r  r4   r   r  r>   r~   r   rQ   r   r   r   rg   r,  r-  r   r   r   cmd_del)r   r   r(  r  r   r  r  r	  r  restore_metadatar.  entities_fileentities_contentkeep_new_filesr   r  ext_filer   r   r   rl   r,  cmd	__class__s                          rB   r!  zcmd_restore.runa  s    
ww~~f%CfLMM 0J77>>(+"#D#+$, - -h$ 	7#0#5#5#7  88I,BLLBEIJ& (G H H .4466
	7 ("Jk4$[!VY%-{	<&	<11&$++2<> "21N +499dkk+/>>?C?MO
  

DMM:F M )77<<k0AB77>>(+h- ( vvx( A!AD //c6J6J035AcF JJ%%a()A	7 	7F( (  		<!IIOOCFTM*IIOODE)CGGDMM1i;G6:;;		<sF   .AH&*B5H?  H? ,H3=A(H? &H03H<	8H? ?	KBKK)rJ   r  )r   r  r  r$  r%  rG   r&  r'  r(  r)  rT  r   r   r*  r1  r!  __classcell__)r<  s   @rB   r'  r'    s    +@H ))--..  *J 	tALz NUXY|"\cfg#*c\	3	MB_H ei/3G< G<rD   r'  c                       e Zd ZdZdZej                  ej                  ej                  dZ	dgZ
 edde      gZ	 	 d
d	Zy)r5  zDelete a GPO.rW  r  r   r
  r  rX  Nc           	         |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }|| _        nGt        | j                  | j                        }t        | j                  | j                  |      | _        | j                          	 t        | j                  |      d   }t        |d   d         }t        |      \  }	}
}t        ||
| j                  | j                  
      }| j                  j!                          	 t#        | j                  |      }t%        |      r`| j&                  j)                  d|z         |D ]=  }t+        | j                  |d   |       | j&                  j)                  d|d   z         ? t-        | j                  |      }| j                  j/                  t1        j2                  | j                  dt        |      z               | j                  j/                  t1        j2                  | j                  dt        |      z               | j                  j/                  |       |j5                  |       | j                  j7                          | j&                  j)                  d|z         y # t        $ r t        d	|z        w xY w# t        $ r | j                  j9                           w xY w)NTr  rf   rZ  r[  r  r   rs   r\  r^  zGPO %s is linked to containers
rQ   z    Removed link from %s.
r  r  zGPO %s deleted.
)r  rh   r   ri   rU   rj   r   rm   r   r   r   r   rg   r   r   r3   r  r   rT   r   r   r   r4   deleter~   r   deltreer  r  )r   r   r  r  r	  r  rs  r   r  r  r  r  r   r   r   s                  rB   r!  zcmd_del.run  s`    ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH	@tzzs3A6C3/034H
 *38)<&7Ik7tww$(JJ0 	

$$&	,$TZZ5C3x		 BS HI MA QtWc:IIOO$AAdG$KLM
  

C0FJJcffTZZF1KLMJJcffTZZ3v;1NOPJJf% LL# JJ))+		+c12E  	@83>??	@8  	JJ))+	s   0+J. (EK	 .K	%K.r"  r{  r`   rD   rB   r5  r5    s[    &H ))--.. J 	tALM 9=63rD   r5  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZddZy
)cmd_aclcheckz.Check all GPOs have matching LDAP and DS ACLs.r  r  r
  r  r  r  r  r  Nc           	         |j                         | _        |j                  | j                  d      | _        t	        | j                  | j                  |      | _        |r|j                  d      r|dd  }|| _        nGt        | j                  | j                        }t	        | j                  | j                  |      | _        | j                          t        | j                  d       }|D ]G  }t        |d   d         }	 t        |      \  }	}
}t        ||
| j                  | j                  	      }|j!                  |t"        j$                  t"        j&                  z  t"        j(                  z  t"        j*                        }d
|vrt        d      |d
   d   }t-        t"        j.                  |      j1                         }t#        j2                  | j                  j5                               }t7        ||      }|j1                  |      |k7  s't        d|j1                  |      d|d|       y # t        $ r t        d|z        w xY w)NTr  rf   rZ  r[  rs   r   r  r^  ro   zKCould not read nTSecurityDescriptor. This requires an Administrator accountzInvalid GPO ACL z
 on path (z), should be )r  rh   r   ri   rm   rj   rU   r   r   r   r   r   r   r   r   r3   get_aclr
   r=  r>  r?  SEC_FLAG_MAXIMUM_ALLOWEDr   r@  rj  r  r  r   )r   r  r  r	  r  rs  r   r   r   r  r  r  r   r$  r   r!  r"  expected_fs_sddls                     rB   r!  zcmd_aclcheck.run  s%   ((*--dgg-M
$''4::q1 i(AB%KDH'<KdggtzzkBDH4::t, 	OAa()!,-CB1:3.7I
 "+w477(,

4D LLH,B,BXE[E[,[^f^s^s,su}  vW  vW  XE%Q." $L M M 01!4Ix22I>FFHE "))$***C*C*EFJ*5*=j)-=="V[VcVcdnVoqz  }M  $N  O  O5	O
  B"#:S#@AABs   H99Ir"  r#  r`   rD   rB   rC  rC    sU    8 H ))--.. 	tW#JQT3	(M
-OrD   rC  c            
           e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	       e
d
deej                  j                   ej                          d            gZ	 	 ddZy)cmd_admxloadz Loads samba admx files to sysvolr  r  r
  r  r  r  r  r  z
--admx-dirz)Directory where admx templates are storedz
samba/admx)r  r  r  Nc                    |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }|| _        nGt        | j                  | j                        }t        | j                  | j                  |      | _        t        |d| j                  | j                        }dj                  | j                  j                  d	      j                         d
dg      }	 |j                  |       t%        j&                  |      D ]  \  }
}}|D ]  }|
j)                  |d      }t$        j*                  j                  |
|      }dj                  ||g      j)                  dd      }dj                  ||g      }	 t-        ||       t/        |d      5 }	 |j1                  ||j3                                d d d          | j4                  j7                  d       y # t        $ rC}	|	j                  d   t        k(  rt!        d      |	j                  d   t"        k7  r Y d }	~	3d }	~	ww xY w# t        $ rB}	|	j                  d   t        k(  rt!        d      |	j                  d   t"        k7  r Y d }	~	d }	~	ww xY w# t        $ r+}	|	j                  d   t        k(  rt!        d      Y d }	~	d }	~	ww xY w# 1 sw Y   xY w)NTr  rf   rZ  r[  r]  r^  r   r_  r`  PolicyDefinitionsr   rc  rJ   r   r   a  Installing ADMX templates to the Central Store prevents Windows from displaying its own templates in the Group Policy Management Console. You will need to install these templates from https://www.microsoft.com/en-us/download/102157 to continue using Windows Administrative Templates.
)r  rh   r   ri   rU   rj   r   rm   r3   r>   rk  r   r   r   rl  r1   r   r0   r   walkr  r   r2   r   r   r   r   r   )r   r  r  r	  r  admx_dirrs  r   smb_dirrl   dirnamedirsfilesfnamepath_in_admx	full_pathsub_dirsmb_pathr   s                      rB   r!  zcmd_admxload.runF  s   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 ))TWW[[1779')<> ?	JJw %'GGH$5 	Q GT5 Q&x<GGLL%8	))Wl$;<DDS$O99gu%56)$8 )T* QaQh9Q QQ	Q* 			 P 	Q9  	vvay33" $D E E== >		 % vvay$;;* ,L M M&EE F	 ) Q66!9(??". 0P #Q Q @QQ Qs`   >G; I
1K3 J;	I8II
	J8JJ	K	!!K	KK	KKr  )r   r  r  r$  r%  rG   r&  r'  r(  r)  r   r   r   r   r>   r#   data_dirr*  r!  r`   rD   rB   rI  rI  4  s    * H ))--.. 	tW#JQTC	)|"M"'',,~u~~/?"N	PM FJ8QrD   rI  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	       e
d
ddd      gZg dZ	 	 ddZy)cmd_add_sudoersa  Adds a Samba Sudoers Group Policy to the sysvol

This command adds a sudo rule to the sysvol for applying to winbind clients.

The command argument indicates the final field in the sudo rule.
The user argument indicates the user specified in the parentheses.
The users and groups arguments are comma separated lists, which are combined to
form the first field in the sudo rule.
The --passwd argument specifies whether the sudo entry will require a password
be specified. The default is False, meaning the NOPASSWD field will be
specified in the sudo entry.

Example:
samba-tool gpo manage sudoers add {31B2F340-016D-11D2-945F-00C04FB984F9} ALL ALL fakeu fakeg

The example command will generate the following sudoers entry:
fakeu,fakeg% ALL=(ALL) NOPASSWD: ALL
    z7%prog <gpo> <command> <user> <users> [groups] [options]r  r
  r  r  r  r  r  z--passwdr  Fz;Specify to indicate that sudo entry must provide a passwordr  )r   commandr5  userszgroups?Nc                 X	   |j                         | _        |	j                  | j                  d      | _        |r|j	                  d      r|dd  }|| _        nGt        | j                  | j                        }t        | j                  | j                  |      | _        t        |d| j                  | j                        }| j                          t        || j                  | j                  | j                  |      }| j                  j                  d      }d	j                  |j                         d
|ddg      }d	j                  |dg      }	 t        j                   t        j"                  |j%                  |                  }|j'                         j)                  d      }|j)                  d      }t        j6                  |d      }|rt        j6                  |d       t        j6                  |d      }||_        t        j6                  |d       }||_        t        j6                  |d!      }|j?                  d"      D ].  }t        j6                  |d#      }||_        d |j@                  d$<   0 |A|j?                         D ].  } t        j6                  |d#      }| |_        d%|j@                  d$<   0 tC               }!|jE                  |!d&d'       |!jG                  d       	 tI        ||       |jK                  ||!jM                                |jO                  d(       y # t*        $ rA}|j,                  d   t.        t0        t2        fv rt        j                   t        j4                  d            }t        j6                  |j'                         d      }t        j6                  |d      }d|_        t        j6                  |d      }d|_        t        j6                  |d      }d|_        t        j6                  |d      }d|_        t        j6                  |d      }t        j6                  |d      }d|_        n"|j,                  d   t:        k(  rt=        d       Y d }~d }~ww xY w# t*        $ r'}|j,                  d   t:        k(  rt=        d       d }~ww xY w))NTr  rf   rZ  r[  r]  r^  r_  r   r`  MACHINE\VGP\VTLA\SudoSudoersConfigurationmanifest.xmlpolicysettingr   r   	vgppolicyversion1rq   zSudo Policydescriptionz!Sudoers File Configuration Policy
apply_modemergeload_plugintruerc  sudoers_entrypasswordrZ  r5  listelement,	principalr  groupUTF-8encodingxml_declarationmachine_changed)(r  rh   r   ri   rU   rj   r   rm   r3   r   r5   r   rk  r>   r   r  ElementTreer  r   getrootfindr   rl  r-   r.   r/   Element
SubElementtextr1   r   rS   r   r)   r   seekr2   r   r   increment_gpt_ini)"r   r   rZ  r5  r[  groupspasswdr  r  r	  r  rs  r   r  r_  vgp_dirvgp_xmlxml_datar`  r   rl   pvrq   rd  re  rg  ri  command_elmuser_elmrk  urm  r[   outs"                                     rB   r!  zcmd_add_sudoers.run  s   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 	#C$**djj!LG$))U[[]J735 6 ))Wn56	~~bmmDMM'4J&KLH$,,.33ODM %%f-D4 dO<MM-4mmM9="==7mmM=AS! 	.Ak;?IIN'-IV$	. \\^ 3MM+{C	!"	+2	  (3
 isWdC	!$0MM'388:.!!$!7c  	vvay:<<> > >>"**[*AB "h.>.>.@.=!?]]=)<}}]F;)	 mmM=I#F ]]=,G
")
}}]F; mmD-@#) 55" $D E E  !%	d  	vvay33" $D E E		s2   A'L+ ,>Q9 +
Q65D6Q11Q69	R)"R$$R))NNNNNNr   r  r  r$  r%  rG   r&  r'  r(  r)  r   r   r*  rT  r!  r`   rD   rB   rY  rY    sz    & IH ))--.. 	tW#JQTC	)z,Q	SM @JAE?CUrD   rY  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZd
gZddZy)cmd_list_sudoerszList Samba Sudoers Group Policy from the sysvol

This command lists sudo rules from the sysvol that will be applied to winbind clients.

Example:
samba-tool gpo manage sudoers list {31B2F340-016D-11D2-945F-00C04FB984F9}
    rW  r  r
  r  r  r  r  r  r   Nc                    |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }|| _        nGt        | j                  | j                        }t        | j                  | j                  |      | _        t        |d| j                  | j                        }| j                  j                  d      }d	j                  |j                         d
|ddg      }		 t        j                  |j                  |	            }
|
J|
j-                  d      } |j,                  d      }|j/                  d      D ]  }|j-                  d      j0                  }|j-                  d      j0                  }|j/                  d      }g }|D ]"  }|j3                  |j/                  d             $ t5        |      dkD  rKdj                  |D cg c]/  }|j6                  d   dk(  r|j0                  nd|j0                  z  1 c}      }nd}|j-                  d      d u }|rdnd}|d|d|d|}| j8                  j;                  d |z          d	j                  |j                         d
|d!g      }	 t=        t>        j@                  |j                  |            }d"}|jB                  D ]g  }tE        |jF                        |k(  stI        |jJ                        jM                         s@| j8                  j;                  d |jJ                  z         i y # t        $ rP}|j                   d   t"        t$        t&        fv rd }
n"|j                   d   t(        k(  rt+        d       Y d }~gd }~ww xY wc c}w # t        $ rL}|j                   d   t"        t$        t&        fv rY d }~y |j                   d   t(        k(  rt+        d       d }~ww xY w)#NTr  rf   rZ  r[  r]  r^  r_  r   r`  r]  z!SudoersConfiguration\manifest.xmlr   rc  r`  r   ri  rZ  r5  rk  rm  rl  r  %s%%ALLrj  
 NOPASSWD:rJ    ALL=()r<   %s
MACHINE\Registry.pols1   Software\Policies\Samba\Unix Settings\Sudo Rights)'r  rh   r   ri   rU   rj   r   rm   r3   rk  r>   r   r  r  r   r   rl  r-   r.   r/   r1   r   rw  findallrz  extendrT   r   r   r   r   r   r   rm  r%   rd  r&   r   rR   )r   r   r  r  r	  r  rs  r   r_  r  r  rl   r   r   ry  rZ  r5  listelements
principalsrk  r  uname
nopasswordnp_entrypru  rx  rd  s                               rB   r!  zcmd_list_sudoers.run  s   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 G$))U[[]J : DF G	}}T]]7%;<H ]]?3F6;;v&Do6 ,**Y/44zz&)..$}}];
#/ HK%%k&9&9+&FGHz?Q&HH6@&B12 120@F0Jaff#aff_'- &B CE "E"ZZ
3t;
+5<2*/xI		
+," 99ekkmZ57 8
	!$))T]]8-DEH K%% 	5E'72uzz*002		 34	5a  
	vvay:<<> >  55" $D E E  
	.&B  	vvay:<<> > vvay33" $D E E	s=   $L9 .4N
)N 9	NANN	O/# O*"O**O/r"  r  r`   rD   rB   r  r    sb     'H ))--.. 	tW#JQTC	)M
 JK5rD   r  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZd
dgZddZy)cmd_remove_sudoersa  Removes a Samba Sudoers Group Policy from the sysvol

This command removes a sudo rule from the sysvol from applying to winbind clients.

Example:
samba-tool gpo manage sudoers remove {31B2F340-016D-11D2-945F-00C04FB984F9} 'fakeu ALL=(ALL) NOPASSWD: ALL'
    %prog <gpo> <entry> [options]r  r
  r  r  r  r  r  r   ry  Nc                    |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }|| _        nGt        | j                  | j                        }t        | j                  | j                  |      | _        t        |d| j                  | j                        }| j                          t        || j                  | j                  | j                  |      }	| j                  j                  d      }
d	j                  |
j                         d
|ddg      }d	j                  |dg      }	 t        j                   t        j"                  |j%                  |                  }|j'                         j)                  d      }|j)                  d      }d	j                  |
j                         d
|dg      }	 t9        t:        j<                  |j%                  |            }i }|r|j?                  d      ng D ]  }|j)                  d      j@                  }|j)                  d      j@                  }|j?                  d      }g }|D ]"  }|jC                  |j?                  d             $ tE        |      dkD  rKdj                  |D cg c]/  }|jF                  d   dk(  r|j@                  nd|j@                  z  1 c}      }nd}|j)                  d      d u }|rdnd}|d|d |d!|}|||<    ||jI                         v r|jK                  ||          tM               }jO                  |d"d#       |jQ                  d       	 tS        ||       |jU                  ||jW                                |	jY                  d$       y ||r$|jZ                  D cg c]  }|j\                   c}ng v ro|jZ                  D cg c]  }|j\                  |k7  s| }}tE        |      |_/        ||_-        	 |jU                  |ta        |             |	jY                  d$       y t7        d%|z        # t*        $ rP}|j,                  d   t.        t0        t2        fv rd }n"|j,                  d   t4        k(  rt7        d       Y d }~d }~ww xY w# t*        $ rP}|j,                  d   t.        t0        t2        fv rd }n"|j,                  d   t4        k(  rt7        d       Y d }~d }~ww xY wc c}w # t*        $ r'}|j,                  d   t4        k(  rt7        d       d }~ww xY wc c}w c c}w # t*        $ r'}|j,                  d   t4        k(  rt7        d       d }~ww xY w)&NTr  rf   rZ  r[  r]  r^  r_  r   r`  r]  r^  r_  r`  r   r   rc  r  ri  rZ  r5  rk  rm  rl  r  r  r  rj  r  rJ   r  r  r<   ro  rp  rs  ,Cannot remove '%s' because it does not exist)1r  rh   r   ri   rU   rj   r   rm   r3   r   r5   r   rk  r>   r   r  ru  r  r   rv  rw  r   rl  r-   r.   r/   r1   r   r   r   r   r  rz  r  rT   r   keysr   r)   r   r{  r2   r   r   r|  rm  r   num_entriesr   )r   r   ry  r  r  r	  r  rs  r   r  r_  r  r  r  r`  r   rl   ru  rx  rm  rZ  r5  r  r  rk  r  r  r  r  r  r  s                                  rB   r!  zcmd_remove_sudoers.runy  s   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 	#C$**djj!LG$))U[[]J735 6 ))Wn56	~~bmmDMM'4J&KLH$,,.33ODM %%f-D 99ekkmZ57 8	!$))T]]8-DEH 26o.B 	AffY',,G66&>&&D99]3LJ+ D!!+"5"5k"BCD:"2<">-. -.HHV,<,F!&&!&&#) "> ? 
+t3J'1|rH&+T8WEAGAJ	" GLLN"KK')CNN3$NGHHQK%dG4gsxxz2%%d%; X(8(89192N"*"2"2FQaffoqFGF#&w<H &Hh(:;%%d%; M$ % & &S  		vvay:<<> > 55" $D E E  			  		vvay:<<> >  55" $D E E  			(">& ! 66!9 77& (H I I	
 :F ! 66!9 77& (H I I	s{   A'Q )R0 -4T
.>T >U%U	:U	-U 	R-AR((R-0	T	9ATT		U"T<<U	U>"U99U>r"  r  r`   rD   rB   r  r  a  se     /H ))--.. 	tW#JQTC	)M
 !Jh&rD   r  c                   P    e Zd ZdZi Z e       ed<    e       ed<    e       ed<   y)cmd_sudoersz#Manage Sudoers Group Policy Objectsr  r   r   N)r   r  r  r$  subcommandsrY  r  r  r`   rD   rB   r  r    s1    -K(*K*,K.0KrD   r  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZg d
Z	 	 ddZy)cmd_set_securitya  Set Samba Security Group Policy to the sysvol

This command sets a security setting to the sysvol for applying to winbind
clients. Not providing a value will unset the policy.
These settings only apply to the ADDC.

Example:
samba-tool gpo manage security set {31B2F340-016D-11D2-945F-00C04FB984F9} MaxTicketAge 10

Possible policies:
MaxTicketAge            Maximum lifetime for user ticket
                        Defined in hours

MaxServiceAge           Maximum lifetime for service ticket
                        Defined in minutes

MaxRenewAge             Maximum lifetime for user ticket renewal
                        Defined in minutes

MinimumPasswordAge      Minimum password age
                        Defined in days

MaximumPasswordAge      Maximum password age
                        Defined in days

MinimumPasswordLength   Minimum password length
                        Defined in characters

PasswordComplexity      Password must meet complexity requirements
                        1 is Enabled, 0 is Disabled
    rW  r  r
  r  r  r  r  r  )r   r   value?Nc                    |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }|| _        nGt        | j                  | j                        }t        | j                  | j                  |      | _        t        |d| j                  | j                        }	| j                          t        || j                  | j                  | j                  |      }
| j                  j                  d      }d	j                  |j                         d
|dg      }d	j                  |dg      }	 t        d       }t         |_        |	j%                  |      }	 |j'                  t)        |j+                                      dddddddd}||   }j=                  |      s|j?                  |       ||jA                  |||       n@|jC                  ||       tE        |jG                  |            dk(  r|jI                  |       t)               }|jK                  |       	 tM        |	|       |	jO                  |tQ        |jS                                      |
jU                  d       y # t,        $ r- |j'                  t)        |j+                  d                   Y  w xY w# t.        $ rM}|j0                  d   t2        k(  rt5        d      |j0                  d   t6        t8        t:        fvr Y d }~ud }~ww xY w# t.        $ r'}|j0                  d   t2        k(  rt5        d       d }~ww xY w)NTr  rf   rZ  r[  r]  r^  r_  r   r`  z$MACHINE\Microsoft\Windows NT\SecEditzGptTmpl.infinterpolationutf-16r   rc  Kerberos PolicySystem Access)MaxTicketAgeMaxServiceAgeMaxRenewAgeMinimumPasswordAgeMaximumPasswordAgeMinimumPasswordLengthPasswordComplexityrs  )+r  rh   r   ri   rU   rj   r   rm   r3   r   r5   r   rk  r>   r   r'   r   optionxformr   	read_filer(   ro  UnicodeDecodeErrorr   rl  r1   r   r-   r.   r/   has_sectionadd_sectionsetremove_optionrT   rG   remove_sectionr   r2   r   r%   getvaluer|  )r   r   r   r?   r  r  r	  r  rs  r   r  r_  inf_dirinf_fileinf_datarawrl   section_mapsectionr  s                       rB   r!  zcmd_set_security.run	  s   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 	#C$**djj!LG$))U[[]J57 899g}56	#$7H!$H --)CC""8CJJL#9: *;*;(9/>/>2A/> f%##G,  )LL&%0""7F38##G,-2''0js		!$0MM(Iclln$=>!!$!7G & C""8CJJx,@#ABC 	vvay33" $D E Evvay!>!@!@!B B B		D  	vvay33" $D E E 	sP   (K :(J AL 2K?K KK 	LALL	M("M

Mr  r  r`   rD   rB   r  r    sg    @ 'H ))--.. 	tW#JQTC	)M
 -J=A'+IrD   r  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZd
gZddZy)cmd_list_securitya  List Samba Security Group Policy from the sysvol

This command lists security settings from the sysvol that will be applied to winbind clients.
These settings only apply to the ADDC.

Example:
samba-tool gpo manage security list {31B2F340-016D-11D2-945F-00C04FB984F9}
    rW  r  r
  r  r  r  r  r  r   Nc                 n   |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }|| _        nGt        | j                  | j                        }t        | j                  | j                  |      | _        t        |d| j                  | j                        }| j                  j                  d      }d	j                  |j                         d
|dg      }		 t        d       }
t        |
_        |j                  |	      }	 |
j!                  t#        |j%                                      |
j7                         D ]A  }|dvr|
j9                  |      D ]&  \  }}| j:                  j=                  |d|d       ( C y # t&        $ r, |
j!                  t#        |j%                  d                   Y w xY w# t(        $ rL}|j*                  d   t,        t.        t0        fv rY d }~y |j*                  d   t2        k(  rt5        d       d }~ww xY w)NTr  rf   rZ  r[  r]  r^  r_  r   r`  z0MACHINE\Microsoft\Windows NT\SecEdit\GptTmpl.infr  r  r   rc  )r  r   = r  )r  rh   r   ri   rU   rj   r   rm   r3   rk  r>   r   r'   r   r  r   r  r(   ro  r  r   rl  r-   r.   r/   r1   r   sectionsr  r   r   )r   r   r  r  r	  r  rs  r   r_  r  r  r  rl   r  r   r?   s                   rB   r!  zcmd_list_security.run~	  s   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 G$99ekkmZBD E	#$7H!$H --)CC""8CJJL#9:  ((* 	<GBB&nnW5 <
U		sE :;<	< & C""8CJJx,@#ABC 	vvay:<<> > vvay33" $D E E	s<   (G *(F' '2GG GG 	H4( H/"H//H4r"  r  r`   rD   rB   r  r  e	  sa     'H ))--.. 	tW#JQTC	)M
 J+<rD   r  c                   <    e Zd ZdZi Z e       ed<    e       ed<   y)cmd_securityz$Manage Security Group Policy Objectsr  r   N)r   r  r  r$  r  r  r  r`   rD   rB   r  r  	  s$    .K)+K+-KrD   r  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZd
gZddZy)cmd_list_smb_confzList Samba smb.conf Group Policy from the sysvol

This command lists smb.conf settings from the sysvol that will be applied to winbind clients.

Example:
samba-tool gpo manage smb_conf list {31B2F340-016D-11D2-945F-00C04FB984F9}
    rW  r  r
  r  r  r  r  r  r   Nc                 p   |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }|| _        nGt        | j                  | j                        }t        | j                  | j                  |      | _        t        |d| j                  | j                        }| j                  j                  d      }d	j                  |j                         d
|dg      }		 t        t        j                  |j                  |	            }
d}t/        j0                         }|
j2                  D ]  }t5        |j6                        |k(  s|j9                  |j:                  t=        |j>                               |j                  |j:                        }| j@                  jC                  |j:                  d|d        y # t         $ rL}|j"                  d   t$        t&        t(        fv rY d }~y |j"                  d   t*        k(  rt-        d       d }~ww xY w)NTr  rf   rZ  r[  r]  r^  r_  r   r`  r  r   rc      Software\Policies\Samba\smb_confr  r  )"r  rh   r   ri   rU   rj   r   rm   r3   rk  r>   r   r   r   r   r   r   rl  r-   r.   r/   r1   r   r#   LoadParmrm  r%   rd  r  re  r   r   r   r   )r   r   r  r  r	  r  rs  r   r_  ru  rx  rl   rd  rh   ry  vals                   rB   r!  zcmd_list_smb_conf.run	  s   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 G$99ekkmZ 79 :
	!$))T]]8-DEH 9^^%% 	FE'72uEJJ8ffU__-		u DE		F  	vvay:<<> > vvay33" $D E E	s   )G   	H5) H0"H00H5r"  r  r`   rD   rB   r  r  	  sb     'H ))--.. 	tW#JQTC	)M
 J'FrD   r  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZg d
Z	 	 ddZy)cmd_set_smb_confa%  Sets a Samba smb.conf Group Policy to the sysvol

This command sets an smb.conf setting to the sysvol for applying to winbind
clients. Not providing a value will unset the policy.

Example:
samba-tool gpo manage smb_conf set {31B2F340-016D-11D2-945F-00C04FB984F9} 'apply gpo policies' yes
    r  r  r
  r  r  r  r  r  r   settingr  Nc                    |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }|| _        nGt        | j                  | j                        }t        | j                  | j                  |      | _        t        |d| j                  | j                        }	| j                          t        || j                  | j                  | j                  |      }
| j                  j                  d      }d	j                  |j                         d
|dg      }d	j                  |dg      }	 t        t         j"                  |	j%                  |            }|t||j4                  D cg c]  }|j6                   c}vrt3        d|z        |j4                  D cg c]  }|j6                  |k7  r| }}||_        t9        |      |_        nt=        |      j                         dv rd}d}n]t=        |      j                         dv rd}d}n=t=        |      j?                         rd}tA        t=        |            }nd}tC        |      }t!        jD                         }d|_#        tC        |      |_        ||_$        ||_%        tM        |j4                        }|jO                  |       ||_        t9        |      |_        	 tQ        |	|       |	jS                  |tU        |             |
jW                  d       y # t&        $ rb}|j(                  d   t*        t,        t.        fv rt!        j"                         }n"|j(                  d   t0        k(  rt3        d       Y d }~
d }~ww xY wc c}w c c}w # t&        $ r'}|j(                  d   t0        k(  rt3        d       d }~ww xY w)NTr  rf   rZ  r[  r]  r^  r_  r   r`  ra  zRegistry.polr   rc  r  )yesrh  rc  rh  rO   )nofalser  r  rs  ),r  rh   r   ri   rU   rj   r   rm   r3   r   r5   r   rk  r>   r   r   r   r   r   r   rl  r-   r.   r/   r1   r   rm  re  rT   r  r&   	isnumericrX   r%   ry  rd  r  r   r   rW   r2   r   r   r|  )r   r   r  r?   r  r  r	  r  rs  r   r  r_  pol_dirru  rx  rl   rm  etyper  s                      rB   r!  zcmd_set_smb_conf.run
  s^   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 	#C$**djj!LG$))U[[]JYGH99g~67	!$))T]]8-DEH =H4D4DEqq{{EE" $029$: ; ;"*"2"2 +Q;;')  +G +&H#&w<H % &&(,@@E"((*.BBE",,.*U+,&

A>AI#G,AKAFAF8++,GNN1&H#&w<H 	!$0MM(HX$67!!$!7[  		vvay:<<> >  99;55" $D E E  			 F+>  	vvay33" $D E E		s=   )L N>N$9N 	N	'ANN		O"OOr  r  r`   rD   rB   r  r  	  sf     /H ))--.. 	tW#JQTC	)M
 .JMQMrD   r  c                   <    e Zd ZdZi Z e       ed<    e       ed<   y)cmd_smb_confz$Manage smb.conf Group Policy Objectsr   r  N)r   r  r  r$  r  r  r  r`   rD   rB   r  r  Z
  s$    .K+-K)+KrD   r  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZd
gZddZy)cmd_list_symlinkzList VGP Symbolic Link Group Policy from the sysvol

This command lists symlink settings from the sysvol that will be applied to winbind clients.

Example:
samba-tool gpo manage symlink list {31B2F340-016D-11D2-945F-00C04FB984F9}
    rW  r  r
  r  r  r  r  r  r   Nc                     |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }|| _        nGt        | j                  | j                        }t        | j                  | j                  |      | _        t        |d| j                  | j                        }| j                  j                  d      }d	j                  |j                         d
|ddg      }		 t        j                  |j                  |	            }
|
j-                  d      } |j,                  d      }|j/                  d      D ]Z  }|j-                  d      }|j-                  d      }| j0                  j3                  d|j4                  d|j4                  d       \ y # t        $ rL}|j                   d   t"        t$        t&        fv rY d }~y |j                   d   t(        k(  rt+        d       d }~ww xY w)NTr  rf   rZ  r[  r]  r^  r_  r   r`  MACHINE\VGP\VTLA\UnixzSymlink\manifest.xmlr   rc  r`  r   file_propertiessourcetargetzln -s r<   r  r  rh   r   ri   rU   rj   r   rm   r3   rk  r>   r   r  r  r   r   rl  r-   r.   r/   r1   r   rw  r  r   r   rz  )r   r   r  r  r	  r  rs  r   r_  r  r  rl   r   r   r  r  r  s                    rB   r!  zcmd_list_symlink.runx
  s   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 G$))U[[]J : 79 :
	}}T]]7%;<H /v{{6"#||,=> 	JO$))(3F$))(3FIIOOv{{FKKHI	J  	vvay:<<> > vvay33" $D E E	s   $F8 8	H H&"HHr"  r  r`   rD   rB   r  r  `
  sb     'H ))--.. 	tW#JQTC	)M
 J'JrD   r  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZg d
Z	 	 ddZy)cmd_add_symlinkzAdds a VGP Symbolic Link Group Policy to the sysvol

This command adds a symlink setting to the sysvol that will be applied to winbind clients.

Example:
samba-tool gpo manage symlink add {31B2F340-016D-11D2-945F-00C04FB984F9} /tmp/source /tmp/target
    '%prog <gpo> <source> <target> [options]r  r
  r  r  r  r  r  r   r  r  Nc                 ~   |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }|| _        nGt        | j                  | j                        }t        | j                  | j                  |      | _        t        |d| j                  | j                        }	| j                          t        || j                  | j                  | j                  |      }
| j                  j                  d      }d	j                  |j                         d
|dg      }d	j                  |dg      }	 t        j                   t        j"                  |	j%                  |                  }|j'                         j)                  d      } |j(                  d      }t        j6                  |d      }t        j6                  |d      }||_        t        j6                  |d      }||_        t?               }|jA                  |dd       |jC                  d       	 tE        |	|       |	jG                  ||jI                                |
jK                  d       y # t*        $ r}|j,                  d   t.        t0        t2        fv rt        j                   t        j4                  d            }t        j6                  |j'                         d      }t        j6                  |d      }d|_        t        j6                  |d      }d|_        t        j6                  |d      }d|_        t        j6                  |d      }n"|j,                  d   t:        k(  rt=        d       Y d }~d }~ww xY w# t*        $ r'}|j,                  d   t:        k(  rt=        d       d }~ww xY w)NTr  rf   rZ  r[  r]  r^  r_  r   r`  MACHINE\VGP\VTLA\Unix\Symlinkr_  r`  r   r   ra  rb  rc  rq   zSymlink Policyrd  zSpecifies symbolic link datarc  r  r  r  ro  rp  rs  )&r  rh   r   ri   rU   rj   r   rm   r3   r   r5   r   rk  r>   r   r  ru  r  r   rv  rw  r   rl  r-   r.   r/   rx  ry  rz  r1   r   r)   r   r{  r2   r   r   r|  )r   r   r  r  r  r  r	  r  rs  r   r  r_  r  r  r  r   r   rl   r`  r  rq   rd  r  
source_elm
target_elmr  s                             rB   r!  zcmd_add_symlink.run
  s   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 	#C$**djj!LG$))U[[]J@B C))Wn56	~~bmmDMM'4J&KLH%%',,_=F6;;v&D, --.?@]]?H=
 
]]?H=
 
isWdC	!$0MM'388:.!!$!7C  	vvay:<<> > >>"**[*AB "h.>.>.@.=!?]]=)<}}]F;,	 mmM=I#A }}]F;55" $D E E  	D  	vvay33" $D E E		s2   A(I8 9>N 8
N	C<NN		N<"N77N<r"  r  r`   rD   rB   r  r  
  sf     9H ))--.. 	tW#JQTC	)M
 -JHLDrD   r  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZg d
Z	 	 ddZy)cmd_remove_symlinka  Removes a VGP Symbolic Link Group Policy from the sysvol

This command removes a symlink setting from the sysvol from applying to winbind
clients.

Example:
samba-tool gpo manage symlink remove {31B2F340-016D-11D2-945F-00C04FB984F9} /tmp/source /tmp/target
    r  r  r
  r  r  r  r  r  r  Nc                 l   |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }|| _        nGt        | j                  | j                        }t        | j                  | j                  |      | _        t        |d| j                  | j                        }	| j                          t        || j                  | j                  | j                  |      }
| j                  j                  d      }d	j                  |j                         d
|dg      }d	j                  |dg      }	 t        j                   t        j"                  |	j%                  |                  }|j'                         j)                  d      } |j(                  d      }|j9                  d      D ]V  }|j)                  d      }|j)                  d      }|j:                  |k(  s5|j:                  |k(  sE|j=                  |        n t5        d|z  |      t?               }|jA                  |dd       |jC                  d       	 tE        |	|       |	jG                  ||jI                                |
jK                  d       y # t*        $ rV}|j,                  d   t.        t0        t2        fv rt5        d|z  |      |j,                  d   t6        k(  rt5        d       d }~ww xY w# t*        $ r'}|j,                  d   t6        k(  rt5        d       d }~ww xY w)NTr  rf   rZ  r[  r]  r^  r_  r   r`  r  r_  r`  r   r   z>Cannot remove link from '%s' to '%s' because it does not existrc  r  r  r  ro  rp  rs  )&r  rh   r   ri   rU   rj   r   rm   r3   r   r5   r   rk  r>   r   r  ru  r  r   rv  rw  r   rl  r-   r.   r/   r   r1   r  rz  r   r)   r   r{  r2   r   r   r|  )r   r   r  r  r  r  r	  r  rs  r   r  r_  r  r  r  r   r   rl   r  r  r  r  s                         rB   r!  zcmd_remove_symlink.run  s   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 	#C$**djj!LG$))U[[]J@B C))Wn56	~~bmmDMM'4J&KLH%%',,_=F6;;v&D  $||,=> 	MO(--h7J(--h7J&(Z__-FO,	M   ;=C DEKM M isWdC	!$0MM'388:.!!$!7;  
	vvay:<<> > # $028$9:@B B55" $D E E 
	<  	vvay33" $D E E		s2   A(J! ">L !	L *AK;;L 	L3"L..L3r"  r  r`   rD   rB   r  r  
  sf     9H ))--.. 	tW#JQTC	)M
 -JHL@rD   r  c                   P    e Zd ZdZi Z e       ed<    e       ed<    e       ed<   y)cmd_symlinkz#Manage symlink Group Policy Objectsr   r  r   N)r   r  r  r$  r  r  r  r  r`   rD   rB   r  r  Z  s1    -K*,K(*K.0KrD   r  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZd
gZddZy)cmd_list_fileszList VGP Files Group Policy from the sysvol

This command lists files which will be copied from the sysvol and applied to winbind clients.

Example:
samba-tool gpo manage files list {31B2F340-016D-11D2-945F-00C04FB984F9}
    rW  r  r
  r  r  r  r  r  r   Nc           
         |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }|| _        nGt        | j                  | j                        }t        | j                  | j                  |      | _        t        |d| j                  | j                        }| j                  j                  d      }d	j                  |j                         d
|ddg      }		 t        j                  |j                  |	            }
|
j-                  d      } |j,                  d      }|j/                  d      D ]  }|j-                  d      j0                  }|j-                  d      j0                  }|j-                  d      j0                  }|j-                  d      j0                  }t3        |      }t5        |      d|d|d|d|	}| j6                  j9                  d|z          y # t        $ rL}|j                   d   t"        t$        t&        fv rY d }~y |j                   d   t(        k(  rt+        d       d }~ww xY w)NTr  rf   rZ  r[  r]  r^  r_  r   r`  r  zFiles\manifest.xmlr   rc  r`  r   r  r  r  r5  rn  	z -> r  )r  rh   r   ri   rU   rj   r   rm   r3   rk  r>   r   r  r  r   r   rl  r-   r.   r/   r1   r   rw  r  rz  r*   r+   r   r   )r   r   r  r  r	  r  rs  r   r_  r  r  rl   r   r   ry  r  r  r5  rn  moder  s                        rB   r!  zcmd_list_files.runy  s   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 G$))U[[]J : 57 8
	}}T]]7%;<H /v{{6"\\"34 	(EZZ)..FZZ)..F::f%**DJJw',,EU#D#D)4HAIIOOFQJ'	(  	vvay:<<> > vvay33" $D E E	s   $H 	I# I<"II#r"  r  r`   rD   rB   r  r  a  sa     'H ))--.. 	tW#JQTC	)M
 J,(rD   r  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZg d
Z	 	 ddZy)cmd_add_filesa  Add VGP Files Group Policy to the sysvol

This command adds files which will be copied from the sysvol and applied to winbind clients.

Example:
samba-tool gpo manage files add {31B2F340-016D-11D2-945F-00C04FB984F9} ./source.txt /usr/share/doc/target.txt root root 600
    z=%prog <gpo> <source> <target> <user> <group> <mode> [options]r  r
  r  r  r  r  r  )r   r  r  r5  rn  r  Nc                 
   |j                         | _        |	j                  | j                  d      | _        t        j
                  j                  |      st        d|z        |r|j                  d      r|dd  }|| _	        nGt        | j                  | j                        }t        | j                  | j                  |      | _	        t        |d| j                  | j                        }| j                          t        || j                  | j                  | j                  |      }| j                  j!                  d	      }d
j#                  |j%                         d|dg      }d
j#                  |dg      }	 t'        j(                  t'        j*                  |j-                  |                  }|j/                         j1                  d      } |j0                  d      }t'        j>                  |d      }t'        j>                  |d      }t        j
                  jE                  |      |_         t'        j>                  |d      }||_         t'        j>                  |d      }||_         t'        j>                  |d      }||_         dD ]  \  }}t'        j>                  |d      } | jG                  d |       tI        |d!      d"|z  z  rt'        j>                  | d#       tI        |d!      d$|z  z  rt'        j>                  | d%       tI        |d!      d&|z  z  st'        j>                  | d'        tK               }!|jM                  |!d(d)       |!jO                  d       tQ        |d*      jS                         }"d
j#                  |t        j
                  jE                  |      g      }#	 tU        ||       |jW                  ||!jS                                |jW                  |#|"       |jY                  d+       y # t2        $ r}|j4                  d   t6        t8        t:        fv rt'        j(                  t'        j<                  d            }t'        j>                  |j/                         d      }t'        j>                  |d      }d|_         t'        j>                  |d      }d|_         t'        j>                  |d      }d|_         t'        j>                  |d      }n"|j4                  d   tB        k(  rt        d       Y d }~)d }~ww xY w# t2        $ r'}|j4                  d   tB        k(  rt        d       d }~ww xY w),NTr  zSource '%s' does not existrf   rZ  r[  r]  r^  r_  r   r`  MACHINE\VGP\VTLA\Unix\Filesr_  r`  r   r   ra  rb  rc  rq   Filesrd  z+Represents file data to set/copy on clientsrc  r  r  r  r5  rn  ))r5     )rn  r   )otherr   permissionsr  rN   rh  r   rM   r   rO   executero  rp  r   rs  )-r  rh   r   ri   r   r   r  r   rU   rj   r   rm   r3   r   r5   r   rk  r>   r   r  ru  r  r   rv  rw  r   rl  r-   r.   r/   rx  ry  rz  r1   r  r  rX   r)   r   r{  r   r   r2   r   r|  )$r   r   r  r  r5  rn  r  r  r  r	  r  rs  r   r  r_  r  r  r  r   r   rl   r`  r  rq   rd  r  r  r  r  	group_elmptypeshiftr  r  source_datasysvol_sources$                                       rB   r!  zcmd_add_files.run  sS   ((*--dgg-M
ww~~f%;fDEE i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 	#C$**djj!LG$))U[[]J>@ A))Wn56	~~bmmDMM'4J&KLH%%',,_=F6;;v&D, --.?@]]?H=
''**62
]]?H=
 
==&9MM/7;		E 	6LE5--GKOOFE*4|se|,k624|se|,k734|se|,k95	6 isWdC64(--/		7BGG,<,<V,D"EF		!$0MM'388:.MM-5!!$!7c  	vvay:<<> > >>"**[*AB "h.>.>.@.=!?]]=)<}}]F;#	 mmM=I#P }}]F;55" $D E E  	d  	vvay33" $D E E		s3   >A(P 2AT 
TC<TT	U "UUr"  r  r`   rD   rB   r  r    sh     OH ))--.. 	tW#JQTC	)M
 FJ<@7;WrD   r  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZd
dgZ	 	 ddZy)cmd_remove_filesa  Remove VGP Files Group Policy from the sysvol

This command removes files which would be copied from the sysvol and applied to winbind clients.

Example:
samba-tool gpo manage files remove {31B2F340-016D-11D2-945F-00C04FB984F9} /usr/share/doc/target.txt
    z%prog <gpo> <target> [options]r  r
  r  r  r  r  r  r   r  Nc                    |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }|| _        nGt        | j                  | j                        }t        | j                  | j                  |      | _        t        |d| j                  | j                        }| j                          t        || j                  | j                  | j                  |      }	| j                  j                  d      }
d	j                  |
j                         d
|dg      }d	j                  |dg      }	 t        j                   t        j"                  |j%                  |                  }|j'                         j)                  d      } |j(                  d      }|j9                  d      D ]t  }|j)                  d      }|j)                  d      }|j:                  |k(  s5d	j                  ||j:                  g      }|j=                  |       |j?                  |        n t5        d|z        tA               }|jC                  |dd       |jE                  d       	 tG        ||       |jI                  ||jK                                |	jM                  d       y # t*        $ rU}|j,                  d   t.        t0        t2        fv rt5        d|z        |j,                  d   t6        k(  rt5        d       d }~ww xY w# t*        $ r'}|j,                  d   t6        k(  rt5        d       d }~ww xY w)NTr  rf   rZ  r[  r]  r^  r_  r   r`  r  r_  r`  r   r   z1Cannot remove file '%s' because it does not existrc  r  r  r  ro  rp  rs  )'r  rh   r   ri   rU   rj   r   rm   r3   r   r5   r   rk  r>   r   r  ru  r  r   rv  rw  r   rl  r-   r.   r/   r   r1   r  rz  unlinkr   r)   r   r{  r2   r   r   r|  )r   r   r  r  r  r	  r  rs  r   r  r_  r  r  r  r   r   rl   r  r  r  r  r  s                         rB   r!  zcmd_remove_files.run0  s   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 	#C$**djj!LG$))U[[]J>@ A))Wn56	~~bmmDMM'4J&KLH%%',,_=F6;;v&D  $||,=> 
	EO(--h7J(--h7J&(GZ__#=>F#O,
	E   ;=C D E E isWdC	!$0MM'388:.!!$!7?  
	vvay:<<> > # $028$9 : :55" $D E E 
	@  	vvay33" $D E E		s2   A(J> ?>L >	LALL	M("M

Mr"  r  r`   rD   rB   r  r    sk     0H ))--.. 	tW#JQTC	)M
 "J@DBrD   r  c                   P    e Zd ZdZi Z e       ed<    e       ed<    e       ed<   y)	cmd_filesz!Manage Files Group Policy Objectsr   r  r   N)r   r  r  r$  r  r  r  r  r`   rD   rB   r
  r
  t  s0    +K(*K&K,.KrD   r
  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZd
gZddZy)cmd_list_opensshzList VGP OpenSSH Group Policy from the sysvol

This command lists openssh options from the sysvol that will be applied to winbind clients.

Example:
samba-tool gpo manage openssh list {31B2F340-016D-11D2-945F-00C04FB984F9}
    rW  r  r
  r  r  r  r  r  r   Nc           	         |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }|| _        nGt        | j                  | j                        }t        | j                  | j                  |      | _        t        |d| j                  | j                        }| j                  j                  d      }d	j                  |j                         d
|ddg      }		 t        j                  |j                  |	            }
|
j-                  d      } |j,                  d      }|j-                  d      }|j/                  d      D ]  }|j-                  d      j0                  r|j/                  d      D ]U  }| j2                  j5                  |j-                  d      j0                  d|j-                  d      j0                  d       W  y # t        $ rL}|j                   d   t"        t$        t&        fv rY d }~y |j                   d   t(        k(  rt+        d       d }~ww xY w)NTr  rf   rZ  r[  r]  r^  r_  r   r`  zMACHINE\VGP\VTLA\SshCfgzSshD\manifest.xmlr   rc  r`  r   
configfileconfigsectionsectionnamekeyvaluepairr   r<   r?   r  r  rh   r   ri   rU   rj   r   rm   r3   rk  r>   r   r  r  r   r   rl  r-   r.   r/   r1   r   rw  r  rz  r   r   )r   r   r  r  r	  r  rs  r   r_  r  r  rl   r   r   r  r  kvs                    rB   r!  zcmd_list_openssh.run  s   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 G$))U[[]J < 46 7
	}}T]]7%;<H /v{{6"YY|,
'//@ 	EM!!-055#++N; E		RWWU^-@-@-/WWW-=-B-B!D EE	E  	vvay:<<> > vvay33" $D E E	s   $G6 6	I? I$"IIr"  r  r`   rD   rB   r  r  {  sb     'H ))--.. 	tW#JQTC	)M
 J*ErD   r  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZg d
Z	 	 ddZy)cmd_set_openssha"  Sets a VGP OpenSSH Group Policy to the sysvol

This command sets an openssh setting to the sysvol for applying to winbind
clients. Not providing a value will unset the policy.

Example:
samba-tool gpo manage openssh set {31B2F340-016D-11D2-945F-00C04FB984F9} KerberosAuthentication Yes
    z'%prog <gpo> <setting> [value] [options]r  r
  r  r  r  r  r  r  Nc                 
   |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }|| _        nGt        | j                  | j                        }t        | j                  | j                  |      | _        t        |d| j                  | j                        }	| j                          t        || j                  | j                  | j                  |      }
| j                  j                  d      }d	j                  |j                         d
|dg      }d	j                  |dg      }	 t        j                   t        j"                  |	j%                  |                  }|j'                         j)                  d      } |j(                  d      }|j)                  d      }||j?                  d      D ]  }|j)                  d      j8                  ri }|j?                  d      D ]  }|||j)                  d      <    ||jA                         v r|||   _        ht        j6                  |d      }t        j6                  |d      }||_        t        j6                  |d      }||_         n|j?                  d      D ]  }|j)                  d      j8                  ri }|j?                  d      D ]   }|||j)                  d      j8                  <   " ||jA                         v r|jC                  ||          |t=        d |z         tE               }|jG                  |d!d"       |jI                  d       	 tK        |	|       |	jM                  ||jO                                |
jQ                  d#       y # t*        $ rg}|j,                  d   t.        t0        t2        fv rt        j                   t        j4                  d            }t        j6                  |j'                         d      }t        j6                  |d      }d|_        t        j6                  |d      }d|_        t        j6                  |d      }d|_        t        j6                  |d      }d|_        t        j6                  |d      }t        j6                  |d      }t        j6                  |d      }t        j6                  |d       n"|j,                  d   t:        k(  rt=        d       Y d }~Ed }~ww xY w# t*        $ r'}|j,                  d   t:        k(  rt=        d       d }~ww xY w)$NTr  rf   rZ  r[  r]  r^  r_  r   r`  zMACHINE\VGP\VTLA\SshCfg\SshDr_  r`  r   r  r   ra  rb  rc  rq   zConfiguration Filerd  z+Represents Unix configuration file settingsre  rf  r  r  rc  r  r   r?   r  ro  rp  rs  ))r  rh   r   ri   rU   rj   r   rm   r3   r   r5   r   rk  r>   r   r  ru  r  r   rv  rw  r   rl  r-   r.   r/   rx  ry  rz  r1   r   r  r  r   r)   r   r{  r2   r   r   r|  )r   r   r  r?   r  r  r	  r  rs  r   r  r_  r  r  r  r   r   r  rl   r`  r  rq   rd  re  r  settingsr  r  r   dvaluer  s                                  rB   r!  zcmd_set_openssh.run  s   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 	#C$**djj!LG$))U[[]J?A B))Wn56	~~bmmDMM'4J&KLH%%',,_=F6;;v&D<0J6 !+!3!3O!D ( %%m499'//? 2B/1HRWWU^,2hmmo--2HW%*#%==#OL--e<C&CH]]<AF"'FK( ",!3!3O!D 
> %%m499'//? 7B46HRWWU^0017hmmo-!(('):;& (35<(= > >
> isWdC	!$0MM'388:.!!$!7y  	vvay:<<> > >>"**[*AB "h.>.>.@.=!?]]=)<}}]F;0	 mmM=I#P ]]=,G
")
}}]F;]]4>
 "j/ Jm];55" $D E E  <'	z  	vvay33" $D E E		s2   A9N# $>T #
T-ETT	U "UUr  r  r`   rD   rB   r  r    sf     9H ))--.. 	tW#JQTC	)M
 .J>B'+`rD   r  c                   <    e Zd ZdZi Z e       ed<    e       ed<   y)cmd_opensshz#Manage OpenSSH Group Policy Objectsr   r  N)r   r  r  r$  r  r  r  r`   rD   rB   r  r  :  s$    -K*,K(*KrD   r  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZd
gZddZy)cmd_list_startupzList VGP Startup Script Group Policy from the sysvol

This command lists the startup script policies currently set on the sysvol.

Example:
samba-tool gpo manage scripts startup list {31B2F340-016D-11D2-945F-00C04FB984F9}
    rW  r  r
  r  r  r  r  r  r   Nc           
         |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }|| _        nGt        | j                  | j                        }t        | j                  | j                  |      | _        t        |d| j                  | j                        }| j                  j                  d      }d	j                  |j                         d
|ddg      }		 t        j                  |j                  |	            }
|
j-                  d      } |j,                  d      }|j/                  d      D ]  }|j-                  d      }d	j                  d	|j                         d
|dd|j0                  g      }|j-                  d      }|j-                  d      }||j0                  }nd}||j0                  }nd}| j2                  j5                  d|d|d|d        y # t        $ rL}|j                   d   t"        t$        t&        fv rY d }~y |j                   d   t(        k(  rt+        d       d }~ww xY w)NTr  rf   rZ  r[  r]  r^  r_  r   r`  r  zScripts\Startup\manifest.xmlr   rc  r`  r   rk  scriptzMACHINE\VGP\VTLA\Unix\ScriptsStartup
parametersrun_asrootrJ   z@reboot r<   r  r  )r   r   r  r  r	  r  rs  r   r_  r  r  rl   r   r   rk  r  script_pathr   r!  s                      rB   r!  zcmd_list_startup.runX  s*   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 G$))U[[]J : @B C
	}}T]]7%;<H /v{{6"<<6 	?K %%h/F))T5;;=*c%H%.%= >K %)),7J %%h/F!%'__

IIOOFK2<> ?	?  	vvay:<<> > vvay33" $D E E	s   $H
 
	I I8"IIr"  r  r`   rD   rB   r  r  @  sa     'H ))--.. 	tW#JQTC	)M
 J4?rD   r  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	       e
d
dddd      gZg dZ	 	 ddZy)cmd_add_startupzAdds VGP Startup Script Group Policy to the sysvol

This command adds a startup script policy to the sysvol.

Example:
samba-tool gpo manage scripts startup add {31B2F340-016D-11D2-945F-00C04FB984F9} test_script.sh '\-n \-p all'
    z.%prog <gpo> <script> [args] [run_as] [options]r  r
  r  r  r  r  r  z
--run-oncerun_onceFr  z#Whether to run the script only oncer  )r   r  zargs?zrun_as?Nc
                 0
   |j                         | _        |j                  | j                  d      | _        t        j
                  j                  |      st        d|z        |r|j                  d      r|dd  }
|| _	        nGt        | j                  | j                        }
t        | j                  | j                  |
      | _	        t        |
d| j                  | j                        }| j                          t        || j                  | j                  | j                  |      }| j                  j!                  d	      }d
j#                  |j%                         d|dg      }d
j#                  |dg      }	 t'        j(                  t'        j*                  |j-                  |                  }|j/                         j1                  d      } |j0                  d      }tE        |d      jG                         }t'        j>                  |d      }t'        j>                  |d      }t        j
                  jI                  |      |_         t'        j>                  |d      }tK        jL                  |      jO                         jQ                         |_         |Kt'        j>                  |d      }|jS                  d      jS                  d      jU                  d d!      |_         |t'        j>                  |d"      }||_         |rt'        j>                  |d#       tW               }|jY                  |d$d%       |j[                  d       d
j#                  |t        j
                  jI                  |      g      }	 t]        ||       |j_                  ||jG                                |j_                  ||       |ja                  d&       y # t2        $ r}|j4                  d   t6        t8        t:        fv rt'        j(                  t'        j<                  d            }t'        j>                  |j/                         d      }t'        j>                  |d      }d|_         t'        j>                  |d      }d|_         t'        j>                  |d      }d|_         t'        j>                  |d      }n"|j4                  d   tB        k(  rt        d       Y d }~d }~ww xY w# t2        $ r'}|j4                  d   tB        k(  rt        d       d }~ww xY w)'NTr  zScript '%s' does not existrf   rZ  r[  r]  r^  r_  r   r`  %MACHINE\VGP\VTLA\Unix\Scripts\Startupr_  r`  r   r   ra  rb  rc  rq   zUnix Scriptsrd  z6Represents Unix scripts to run on Group Policy clientsrc  r   rk  r  hashr   "'z\--r!  r&  ro  rp  rs  )1r  rh   r   ri   r   r   r  r   rU   rj   r   rm   r3   r   r5   r   rk  r>   r   r  ru  r  r   rv  rw  r   rl  r-   r.   r/   rx  ry  rz  r1   r   r   r  hashlibmd5	hexdigestr  rR   r  r)   r   r{  r2   r   r|  ) r   r   r  rl  r!  r&  r  r  r	  r  rs  r   r  r_  r  r  r  r   r   rl   r`  r  rq   rd  script_datark  
script_elmr)  r   
run_as_elmr  sysvol_scripts                                    rB   r!  zcmd_add_startup.run  s   ((*--dgg-M
ww~~f%;fDEE i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 	#C$**djj!LG$))U[[]JIK L))Wn56	~~bmmDMM'4J&KLH%%',,_=F6;;v&D. 64(--/mmD-8]];9
''**62
}}[&1KK,668>>@	{LAJ"jjo33C8@@LJO{H=J$JOMM+z2isWdC		7BGG,<,<V,D"EF		!$0MM'388:.MM-5!!$!7[  	vvay:<<> > >>"**[*AB "h.>.>.@.=!?]]=)<}}]F;*	 mmM=IL  }}]F;55" $D E E  	\  	vvay33" $D E E		s3   >A(O  AS% 
S"C<SS"%	T."TTr  r  r`   rD   rB   r%  r%    sz     @H ))--.. 	tW#JQTC	)|*eL9	;M 7J@D?CSrD   r%  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZd
dgZ	 	 ddZy)cmd_remove_startupzRemoves VGP Startup Script Group Policy from the sysvol

This command removes a startup script policy from the sysvol.

Example:
samba-tool gpo manage scripts startup remove {31B2F340-016D-11D2-945F-00C04FB984F9} test_script.sh
    z%prog <gpo> <script> [options]r  r
  r  r  r  r  r  r   r  Nc                    |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }|| _        nGt        | j                  | j                        }t        | j                  | j                  |      | _        t        |d| j                  | j                        }| j                          t        || j                  | j                  | j                  |      }	| j                  j                  d      }
d	j                  |
j                         d
|dg      }d	j                  |dg      }	 t        j                   t        j"                  |j%                  |                  }|j'                         j)                  d      } |j(                  d      }|j9                  d      D ]b  }|j)                  d      }|j:                  t<        j>                  jA                  |jC                  d	d            k(  sQ|jE                  |        n t5        d|z        tG               }|jI                  |dd       |jK                  d       	 tM        ||       |jO                  ||jQ                                |	jS                  d       y # t*        $ rU}|j,                  d   t.        t0        t2        fv rt5        d|z        |j,                  d   t6        k(  rt5        d       d }~ww xY w# t*        $ r'}|j,                  d   t6        k(  rt5        d       d }~ww xY w)NTr  rf   rZ  r[  r]  r^  r_  r   r`  r(  r_  r`  r   r   z3Cannot remove script '%s' because it does not existrc  rk  r  r   ro  rp  rs  )*r  rh   r   ri   rU   rj   r   rm   r3   r   r5   r   rk  r>   r   r  ru  r  r   rv  rw  r   rl  r-   r.   r/   r   r1   r  rz  r   r   r  r  r   r)   r   r{  r2   r   r   r|  )r   r   r  r  r  r	  r  rs  r   r  r_  r  r  r  r   r   rl   rk  r1  r  s                       rB   r!  zcmd_remove_startup.run  s   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 	#C$**djj!LG$))U[[]JIK L))Wn56	~~bmmDMM'4J&KLH%%',,_=F6;;v&D  <<6 	6K$))(3J"''"2"26>>$3L"MMK(		6   ,.4 5 6 6 isWdC	!$0MM'388:.!!$!77  
	vvay:<<> > # $028$9 : :55" $D E E 
	8  	vvay33" $D E E		s2   A(J, ->L ,	L
5ALL
	L="L88L=r"  r  r`   rD   rB   r5  r5    sj     0H ))--.. 	tW#JQTC	)M
 "J@D>rD   r5  c                   P    e Zd ZdZi Z e       ed<    e       ed<    e       ed<   y)cmd_startupz+Manage Startup Scripts Group Policy Objectsr   r  r   N)r   r  r  r$  r  r  r%  r5  r`   rD   rB   r8  r8  U  s1    5K*,K(*K.0KrD   r8  c                   (    e Zd ZdZi Z e       ed<   y)cmd_scriptsz#Manage Scripts Group Policy ObjectsstartupN)r   r  r  r$  r  r8  r`   rD   rB   r:  r:  \  s    -K(]K	rD   r:  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZd
gZddZy)cmd_list_motdzList VGP MOTD Group Policy from the sysvol

This command lists the Message of the Day from the sysvol that will be applied
to winbind clients.

Example:
samba-tool gpo manage motd list {31B2F340-016D-11D2-945F-00C04FB984F9}
    rW  r  r
  r  r  r  r  r  r   Nc                    |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }|| _        nGt        | j                  | j                        }t        | j                  | j                  |      | _        t        |d| j                  | j                        }| j                  j                  d      }d	j                  |j                         d
|ddg      }		 t        j                  |j                  |	            }
|
j-                  d      } |j,                  d      }|j-                  d      }|3|j.                  &| j0                  j3                  |j.                         y y y # t        $ rL}|j                   d   t"        t$        t&        fv rY d }~y |j                   d   t(        k(  rt+        d       d }~ww xY w)NTr  rf   rZ  r[  r]  r^  r_  r   r`  r  zMOTD\manifest.xmlr   rc  r`  r   rz  )r  rh   r   ri   rU   rj   r   rm   r3   rk  r>   r   r  r  r   r   rl  r-   r.   r/   r1   r   rw  rz  r   r   r   r   r  r  r	  r  rs  r   r_  r  r  rl   r   r   rz  s                  rB   r!  zcmd_list_motd.runz  s   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 G$))U[[]J : 46 7
	}}T]]7%;<H /v{{6"yy yy$				* %   	vvay:<<> > vvay33" $D E E	s   $F 	G% G >"G  G%r"  r  r`   rD   rB   r=  r=  a  sa     'H ))--.. 	tW#JQTC	)M
 J'+rD   r=  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZd
dgZ	 	 ddZy)cmd_set_motda  Sets a VGP MOTD Group Policy to the sysvol

This command sets the Message of the Day to the sysvol for applying to winbind
clients. Not providing a value will unset the policy.

Example:
samba-tool gpo manage motd set {31B2F340-016D-11D2-945F-00C04FB984F9} "Message for today"
    %prog <gpo> [value] [options]r  r
  r  r  r  r  r  r   r  Nc                    |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }|| _        nGt        | j                  | j                        }t        | j                  | j                  |      | _        t        |d| j                  | j                        }| j                          t        || j                  | j                  | j                  |      }	| j                  j                  d      }
d	j                  |
j                         d
|dg      }d	j                  |dg      }|$|j                  |       |	j!                  d       y 	 t#        j$                  t#        j&                  |j)                  |                  }|j+                         j-                  d      }|j-                  d      }|j-                  d      }|t#        j:                  |d      }||_        tC               }|jE                  |dd       |jG                  d       	 tI        ||       |jK                  ||jM                                |	j!                  d       y # t.        $ rA}|j0                  d   t2        t4        t6        fv rt#        j$                  t#        j8                  d            }t#        j:                  |j+                         d      }t#        j:                  |d      }d|_        t#        j:                  |d      }d|_        t#        j:                  |d      }d|_        t#        j:                  |d      }d|_        t#        j:                  |d      }t#        j:                  |d      }d|_        n"|j0                  d   t>        k(  rtA        d       Y d }~d }~ww xY w# t.        $ r'}|j0                  d   t>        k(  rtA        d       d }~ww xY w) NTr  rf   rZ  r[  r]  r^  r_  r   r`  zMACHINE\VGP\VTLA\Unix\MOTDr_  rs  r`  r   r   ra  rb  rc  rq   	Text Filerd  Represents a Generic Text Filere  r  filenamemotdrc  rz  ro  rp  )'r  rh   r   ri   rU   rj   r   rm   r3   r   r5   r   rk  r>   r   r  r|  r  ru  r  r   rv  rw  r   rl  r-   r.   r/   rx  ry  rz  r1   r   r)   r   r{  r2   r   r   )r   r   r?   r  r  r	  r  rs  r   r  r_  r  r  r  r`  r   rl   r  rq   rd  re  rF  rz  r  s                           rB   r!  zcmd_set_motd.run  sZ   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 	#C$**djj!LG$))U[[]J=? @))Wn56=KK !!$!7	~~bmmDMM'4J&KLH$,,.33ODM %%f-D4 yy <==v.D	isWdC	!$0MM'388:.!!$!7I  	vvay:<<> > >>"**[*AB "h.>.>.@.=!?]]=)<}}]F;'	 mmM=I#C ]]=,G
"+
}}]F;==z: &55" $D E E  %	J  	vvay33" $D E E		s2   7A'I= >>O =
OD6OO	O;"O66O;r  r  r`   rD   rB   rA  rA    sk     /H ))--.. 	tW#JQTC	)M
 "JDHMrD   rA  c                   <    e Zd ZdZi Z e       ed<    e       ed<   y)cmd_motdz.Manage Message of the Day Group Policy Objectsr   r  N)r   r  r  r$  r  r=  rA  r`   rD   rB   rI  rI    s"    8K'/K%KrD   rI  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZd
gZddZy)cmd_list_issuezList VGP Issue Group Policy from the sysvol

This command lists the Prelogin Message from the sysvol that will be applied
to winbind clients.

Example:
samba-tool gpo manage issue list {31B2F340-016D-11D2-945F-00C04FB984F9}
    rW  r  r
  r  r  r  r  r  r   Nc                    |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }|| _        nGt        | j                  | j                        }t        | j                  | j                  |      | _        t        |d| j                  | j                        }| j                  j                  d      }d	j                  |j                         d
|ddg      }		 t        j                  |j                  |	            }
|
j-                  d      } |j,                  d      }|j-                  d      }| j.                  j1                  |j2                         y # t        $ rL}|j                   d   t"        t$        t&        fv rY d }~y |j                   d   t(        k(  rt+        d       d }~ww xY w)NTr  rf   rZ  r[  r]  r^  r_  r   r`  r  zIssue\manifest.xmlr   rc  r`  r   rz  )r  rh   r   ri   rU   rj   r   rm   r3   rk  r>   r   r  r  r   r   rl  r-   r.   r/   r1   r   rw  r   r   rz  r?  s                  rB   r!  zcmd_list_issue.run*  s   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 G$))U[[]J : 57 8
	}}T]]7%;<H /v{{6"yy 				"  	vvay:<<> > vvay33" $D E E	s   $F   	G	 G."GGr"  r  r`   rD   rB   rK  rK    sa     'H ))--.. 	tW#JQTC	)M
 J%#rD   rK  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZd
dgZ	 	 ddZy)cmd_set_issuea  Sets a VGP Issue Group Policy to the sysvol

This command sets the Prelogin Message to the sysvol for applying to winbind
clients. Not providing a value will unset the policy.

Example:
samba-tool gpo manage issue set {31B2F340-016D-11D2-945F-00C04FB984F9} "Welcome to Samba!"
    rB  r  r
  r  r  r  r  r  r   r  Nc                 P   |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }|| _        nGt        | j                  | j                        }t        | j                  | j                  |      | _        t        |d| j                  | j                        }| j                          t        || j                  | j                  | j                  |      }	| j                  j                  d      }
d	j                  |
j                         d
|dg      }d	j                  |dg      }|$|j                  |       |	j!                  d       y 	 t#        j$                  |j'                  |            }t#        j6                  d      }||_        tA               }|jC                  |dd       |jE                  d       	 tG        ||       |jI                  ||jK                                |	j!                  d       y # t(        $ rA}|j*                  d   t,        t.        t0        fv rt#        j2                  t#        j4                  d            }t#        j6                  |j9                         d      }t#        j6                  |d      }d|_        t#        j6                  |d      }d|_        t#        j6                  |d      }d|_        t#        j6                  |d      }d|_        t#        j6                  |d      }t#        j6                  |d      }d|_        n"|j*                  d   t<        k(  rt?        d       Y d }~d }~ww xY w# t(        $ r'}|j*                  d   t<        k(  rt?        d       d }~ww xY w) NTr  rf   rZ  r[  r]  r^  r_  r   r`  zMACHINE\VGP\VTLA\Unix\Issuer_  rs  r   ra  r`  rb  rc  rq   rD  rd  rE  re  r  r   rF  issuerc  rz  ro  rp  )&r  rh   r   ri   rU   rj   r   rm   r3   r   r5   r   rk  r>   r   r  r|  r  r  r   r   rl  r-   r.   r/   ru  rx  ry  rv  rz  r1   r   r)   r   r{  r2   r   r   )r   r   r?   r  r  r	  r  rs  r   r  r_  r  r  r  rl   r`  r  rq   rd  re  r   rF  rz  r  s                           rB   r!  zcmd_set_issue.runj  s   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 	#C$**djj!LG$))U[[]J>@ A))Wn56=KK !!$!7	}}T]]7%;<H4 }}T6*	isWdC	!$0MM'388:.!!$!7E  	vvay:<<> > >>"**[*AB "h.>.>.@.=!?]]=)<}}]F;'	 mmM=I#C ]]=,G
"+
}}]F;==z: '55" $D E E  %	F  	vvay33" $D E E		s1   7$H' (>M5 '
M21D6M--M25	N%>"N  N%r  r  r`   rD   rB   rN  rN  Q  sk     /H ))--.. 	tW#JQTC	)M
 "JDHIrD   rN  c                   <    e Zd ZdZi Z e       ed<    e       ed<   y)	cmd_issuez!Manage Issue Group Policy Objectsr   r  N)r   r  r  r$  r  rK  rN  r`   rD   rB   rR  rR    s#    +K(*K&KrD   rR  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZd
gZddZy)cmd_list_accesszList VGP Host Access Group Policy from the sysvol

This command lists host access rules from the sysvol that will be applied to winbind clients.

Example:
samba-tool gpo manage access list {31B2F340-016D-11D2-945F-00C04FB984F9}
    rW  r  r
  r  r  r  r  r  r   Nc                    |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }|| _        nGt        | j                  | j                        }t        | j                  | j                  |      | _        t        |d| j                  | j                        }| j                  j                  d      }d	j                  |j                         d
|ddg      }		 t        j                  |j                  |	            }
|
|
j-                  d      } |j,                  d      }|j/                  d      D ]k  }|j-                  d      }|j-                  d      }|j-                  d      }| j0                  j3                  d|j4                  d	|j4                  d       m d	j                  |j                         d
|ddg      }		 t        j                  |j                  |	            }||j-                  d      } |j,                  d      }|j/                  d      D ]k  }|j-                  d      }|j-                  d      }|j-                  d      }| j0                  j3                  d|j4                  d	|j4                  d       m y y # t        $ rP}|j                   d   t"        t$        t&        fv rd }
n"|j                   d   t(        k(  rt+        d       Y d }~d }~ww xY w# t        $ rP}|j                   d   t"        t$        t&        fv rd }n"|j                   d   t(        k(  rt+        d       Y d }~Vd }~ww xY w)NTr  rf   rZ  r[  r]  r^  r_  r   r`  MACHINE\VGP\VTLA\VASz$HostAccessControl\Allow\manifest.xmlr   rc  r`  r   rk  adobjectrq   r  z+:z:ALL
z#HostAccessControl\Deny\manifest.xmlz-:r  )r   r   r  r  r	  r  rs  r   r_  r  allowrl   r   r   rk  rW  rq   r  denys                      rB   r!  zcmd_list_access.run  s   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 G$))U[[]J6EG H	MM$--"89E ZZ0F6;;v&D#||M: M&++J7}}V,!x0		FKK KL	M ))U[[]J6DF G	==w!78D YY/F6;;v&D#||M: M&++J7}}V,!x0		FKK KL	M I  		vvay:<<> > 55" $D E E  			2  		vvay:<<> > 55" $D E E  			s2   $J9 /$L 9	LALL	M.AM))M.r"  r  r`   rD   rB   rT  rT    sc     'H ))--.. 	tW#JQTC	)M
 JCMrD   rT  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZg d
Z	 	 ddZy)cmd_add_accessaS  Adds a VGP Host Access Group Policy to the sysvol

This command adds a host access setting to the sysvol for applying to winbind
clients. Any time an allow entry is detected by the client, an implicit deny
ALL will be assumed.

Example:
samba-tool gpo manage access add {31B2F340-016D-11D2-945F-00C04FB984F9} allow goodguy example.com
    z0%prog <gpo> <allow/deny> <cn> <domain> [options]r  r
  r  r  r  r  r  )r   r  cnr  Nc	                 h   |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }	|| _        nGt        | j                  | j                        }	t        | j                  | j                  |	      | _        t        |	d| j                  | j                        }
| j                          t        || j                  | j                  | j                  |      }| j                  j                  d      }|d	k(  r%d
j                  |j                         d|ddg      }n8|dk(  r%d
j                  |j                         d|ddg      }nt        d|z        d
j                  |dg      }	 t!        j"                  t!        j$                  |
j'                  |                  }|j)                         j+                  d      } |j*                  d      }t        | j                  | j                  |      }t?        |tA               | j                  | j                        }|jC                  |jE                         tF        jH                  d |z  g d!"      }tK        |      dk(  rt        d#|z        tM        |d   d$   d%         }|d&vrt        d'|z        t!        j8                  |d(      }t!        j8                  |d)      }|jO                         |_        t!        j8                  |d*      }|jQ                         d
tM        |d   d+   d%         |_        |d,k(  rt!        j8                  |d-      }d.|_        t!        j8                  |d/      }t!        j8                  |d      }tM        |d   d+   d%         |_        t!        j8                  |d0      } || _        t!        j8                  |d)      }||_        tS               }!|jU                  |!d1d2       |!jW                  d       	 tY        |
|       |
j[                  ||!j]                                |j_                  d3       y # t,        $ r$}|j.                  d   t0        t2        t4        fv rt!        j"                  t!        j6                  d            }t!        j8                  |j)                         d      }t!        j8                  |d      }d|_        t!        j8                  |d      }d|_        t!        j8                  |d      }d|_        t!        j8                  |d      }d|_        t!        j8                  |d      }n"|j.                  d   t<        k(  rt        d       Y d }~d }~ww xY w# t,        $ r'}|j.                  d   t<        k(  rt        d       d }~ww xY w)4NTr  rf   rZ  r[  r]  r^  r_  rX  r   r`  rV  HostAccessControl\AllowrY  HostAccessControl\DenyBThe entry type must be either 'allow' or 'deny'. Unknown type '%s'r_  r`  r   r   ra  rb  rc  rq   zHost Access Controlrd  z0Represents host access control data (pam_access)re  rf  rc  r   z(cn=%s))userPrincipalNamesamaccountnamer/  r   z!Unable to find user or group "%s"r/  )r5  rn  z%s is not a user or grouprk  r  ry  rb  rn  	groupattrsamAccountNamerW  r  ro  rp  rs  )0r  rh   r   ri   rU   rj   r   rm   r3   r   r5   r   rk  r>   r   r   r  ru  r  r   rv  rw  r   rl  r-   r.   r/   rx  ry  rz  r1   r   r   r   	domain_dnr~   SCOPE_SUBTREErT   r&   r  domain_netbios_namer)   r   r{  r2   r   r   r|  )"r   r   r  r\  r  r  r  r	  r  rs  r   r  r_  r  r  r  r   r   rl   r`  r  rq   rd  re  rj   r   resobjectclassrk  ry  rd  rW  
domain_elmr  s"                                     rB   r!  zcmd_add_access.run2  s   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 	#C$**djj!LG$Gii
C!:!;!= >G f_ii
C!:!:!< =G   ;=B C D D))Wn56	~~bmmDMM'4J&KLH%%',,_=F6;;v&D0 TWWdjjV4#N,<"&**: ll 1!$!2!2&/"n"1  2 s8q=BRGHH Q!6r!:;//:R?@@mmD-8k62 &&(
k73!&!:!:!<!+CF3C,DR,H!IK
'!dK8I-IN==j9}}Xv.s1v&67;<	]]8X6
 
h/ 
isWdC	!$0MM'388:.!!$!7  	vvay:<<> > >>"**[*AB "h.>.>.@.=!?]]=)<}}]F;1	 mmM=I#U ]]=,G
")
}}]F;55" $D E E  !	@  	vvay33" $D E E		s2   A(Q >V 
U>DU99U>	V1
"V,,V1r"  r  r`   rD   rB   r[  r[    sg     BH ))--.. 	tW#JQTC	)M
 2J<@'+krD   r[  c                       e Zd ZdZdZej                  ej                  ej                  dZ	 e
dddedd	      gZg d
Z	 	 ddZy)cmd_remove_accessa  Remove a VGP Host Access Group Policy from the sysvol

This command removes a host access setting from the sysvol for applying to
winbind clients.

Example:
samba-tool gpo manage access remove {31B2F340-016D-11D2-945F-00C04FB984F9} allow goodguy example.com
    z2%prog <gpo> <allow/deny> <name> <domain> [options]r  r
  r  r  r  r  r  )r   r  rq   r  Nc	                    |j                         | _        |j                  | j                  d      | _        |r|j	                  d      r|dd  }	|| _        nGt        | j                  | j                        }	t        | j                  | j                  |	      | _        t        |	d| j                  | j                        }
| j                          t        || j                  | j                  | j                  |      }| j                  j                  d      }|d	k(  r%d
j                  |j                         d|ddg      }n8|dk(  r%d
j                  |j                         d|ddg      }nt        d|z        d
j                  |dg      }	 t!        j"                  t!        j$                  |
j'                  |                  }|j)                         j+                  d      } |j*                  d      }|j9                  d      D ]m  }|j+                  d      }|j+                  d      }|j+                  d      }|9|j:                  |k(  sI|L|j:                  |k(  s\|j=                  |        n t        d|z        t?               }|jA                  |dd       |jC                  d       	 tE        |
|       |
jG                  ||jI                                |jK                  d       y # t,        $ rU}|j.                  d   t0        t2        t4        fv rt        d|z        |j.                  d   t6        k(  rt        d       d }~ww xY w# t,        $ r'}|j.                  d   t6        k(  rt        d       d }~ww xY w)NTr  rf   rZ  r[  r]  r^  r_  rX  r   r`  rV  r^  rY  r_  r`  r_  r`  r   r   z0Cannot remove %s entry because it does not existrc  rk  rW  rq   r  ro  rp  rs  )&r  rh   r   ri   rU   rj   r   rm   r3   r   r5   r   rk  r>   r   r   r  ru  r  r   rv  rw  r   rl  r-   r.   r/   r1   r  rz  r   r)   r   r{  r2   r   r   r|  )r   r   r  rq   r  r  r  r	  r  rs  r   r  r_  r  r  r  r   r   rl   rk  rW  name_elmrk  r  s                           rB   r!  zcmd_remove_access.run  sQ   ((*--dgg-M
 i(AB%KDH'<KdggtzzkBDH k&!%$(JJ0
 	#C$**djj!LG$Gii
C!:!;!= >G f_ii
C!:!:!< =G   ;=B C D D))Wn56	~~bmmDMM'4J&KLH%%',,_=F6;;v&D  <<6 
	8K"''
3H}}V,H!x0J#(=%*//V*CK(
	8   /16 7 8 8 isWdC	!$0MM'388:.!!$!7=  
	vvay:<<> > # $/16$7 8 855" $D E E 
	>  	vvay33" $D E E		s2   A(K6 7>M 6	M?AMM	N "NNr"  r  r`   rD   rB   rm  rm    sg     DH ))--.. 	tW#JQTC	)M
 4J>B'+JrD   rm  c                       e Zd ZdZdZej                  ej                  dZ e	dddd       e	d	ddd
      gZ
ddgZ	 	 ddZy)cmd_cse_registera  Register a Client Side Extension (CSE) on the current host

This command takes a CSE filename as an argument, and registers it for
applying policy on the current host. This is not necessary for CSEs which
are distributed with the current version of Samba, but is useful for installing
experimental CSEs or custom built CSEs.
The <cse_file> argument MUST be a permanent location for the CSE. The register
command does not copy the file to some other directory. The samba-gpupdate
command will execute the CSE from the exact location specified from this
command.

Example:
samba-tool gpo cse register ./gp_chromium_ext.py gp_chromium_ext --machine
    z%%prog <cse_file> <cse_name> [options]r  r  z	--machineFr  z-Whether to register the CSE as Machine policy)r  r  r  z--userz*Whether to register the CSE as User policycse_filecse_nameNc                 @   |j                         | _        |dk(  r|dk(  rt        d      dt        t	        j
                               z  }t        j                  j                  |      }t        |||| j                  j                  ||      }	|	st        d|z        y )NFz+Either --machine or --user must be selectedr  )smb_confmachiner5  zFailed to register CSE "%s")r  rh   r   r   r  r  r   r   realpathr7   r  )
r   rs  rt  rw  r5  r  r  ext_guidext_pathrA   s
             rB   r!  zcmd_cse_register.run$  s    ((*eLMMC

--77##H-#Hh-1WW-?-?,3$@ <xGHH rD   )FFNN)r   r  r  r$  r%  rG   r&  r'  r)  r   r*  rT  r!  r`   rD   rB   rq  rq    so     7H ))-- 	{E,C	Ex|@	BM j)J:?(,IrD   rq  c                   N    e Zd ZdZdZej                  ej                  dZddZ	y)cmd_cse_listzList the registered Client Side Extensions (CSEs) on the current host

This command lists the currently registered CSEs on the host.

Example:
samba-tool gpo cse list
    r  rr  Nc                    |j                         | _        t        | j                  j                        }|j	                         D ]  \  }}| j
                  j                  d|z         | j
                  j                  d|d   z         | j
                  j                  d|d   z         | j
                  j                  dt        |d         z         | j
                  j                  dt        |d	         z          y )
NzUniqueGUID         : %s
zFileName           : %s
DllNamezProcessGroupPolicy : %s
ProcessGroupPolicyzMachinePolicy      : %s
MachinePolicyzUserPolicy         : %s


UserPolicy)r  rh   r8   r  r  r   r   r   )r   r  r  csesr  gp_exts         rB   r!  zcmd_cse_list.runC  s    ((*!$''"4"45 JJL 	/LD&IIOO7$>?IIOO7&:KKLIIOO7/01 2IIOO7/01 2IIOO9|,-. /	/rD   NN)
r   r  r  r$  r%  rG   r&  r'  r)  r!  r`   rD   rB   r|  r|  3  s/     !H ))--
/rD   r|  c                   T    e Zd ZdZdZej                  ej                  dZdgZ	ddZ
y)cmd_cse_unregisteraq  Unregister a Client Side Extension (CSE) from the current host

This command takes a unique GUID as an argument (representing a registered
CSE), and unregisters it for applying policy on the current host. Use the
`samba-tool gpo cse list` command to determine the unique GUIDs of CSEs.

Example:
samba-tool gpo cse unregister {3F60F344-92BF-11ED-A1EB-0242AC120002}
    z%prog <guid> [options]rr  r  Nc                     |j                         | _        t        || j                  j                        }|st	        d|z        y )NzFailed to unregister CSE "%s")r  rh   r9   r  r   )r   r  r  r  rA   s        rB   r!  zcmd_cse_unregister.rune  sA    ((*%dDGG,>,>?>EFF rD   r  )r   r  r  r$  r%  rG   r&  r'  r)  rT  r!  r`   rD   rB   r  r  Q  s9     (H ))--
 JGrD   r  c                   P    e Zd ZdZi Z e       ed<    e       ed<    e       ed<   y)cmd_csezManage Client Side Extensionsregisterr   
unregisterN)r   r  r  r$  r  rq  r|  r  r`   rD   rB   r  r  l  s0    'K.0K
&.K 2 4KrD   r  c                   P    e Zd ZdZi Z e       ed<    e       ed<    e       ed<   y)
cmd_accessz'Manage Host Access Group Policy Objectsr   r  r   N)r   r  r  r$  r  rT  r[  rm  r`   rD   rB   r  r  s  s1    1K)+K')K-/KrD   r  c                       e Zd ZdZi Z e       ed<    e       ed<    e       ed<    e       ed<    e	       ed<    e
       ed<    e       ed<    e       ed	<    e       ed
<    e       ed<   y)
cmd_managezManage Group Policy Objectssudoersr
   rv  symlinkrQ  opensshscriptsrG  rP  accessN)r   r  r  r$  r  r  r  r  r  r
  r  r:  rI  rR  r  r`   rD   rB   r  r  z  s    %K(]K	*nK
*nK
(]K	$;K(]K	(]K	"*K$;K&LKrD   r  c                      e Zd ZdZi Z e       ed<    e       ed<    e       ed<    e       ed<    e	       ed<    e
       ed<    e       ed<    e       ed	<    e       ed
<    e       ed<    e       ed<    e       ed<    e       ed<    e       ed<    e       ed<    e       ed<    e       ed<    e       ed<    e       ed<    e       ed<   y)cmd_gpoz%Group Policy Object (GPO) management.listallr   showr  r   getlinksetlinkdellinklistcontainersgetinheritancesetinheritancefetchcreatedelaclcheckr(  restoreadmxloadmanagecseN)r   r  r  r$  r  r  r,  rV  r}  r  r  r  r  r  r  r  r  r  r5  rC  r  r'  rI  r  r  r`   rD   rB   r  r    s    /K(]K	"*K"*K"*K&LK(]K	(]K	(]K	$6$8K !$6$8K !$6$8K !$;K&LK K*nK
&LK(]K	*nK
&LK KrD   r  r  )FF)r   r  samba.getoptgetoptrG   r~   r   xml.etree.ElementTreeetreeru  r  r  r   
samba.authr   samba.netcmdr   r   r   r   samba.samdbr   r6  r	   samba.dcerpcr
   	samba.ndrr   r   r   samba.securityr   r   r   samba.netcmd.commonr   r   samba.samba3r   r   r   r  samba.ntaclsr   r   	samba.netr   samba.gp_parser   r   r   samba.gp_parse.gp_polr   samba.gp_parse.gp_inir   r   r   r   samba.gp_parse.gp_csvr    samba.gp_parse.gp_infr!   samba.gp_parse.gp_aasr"   r#   r$   samba.commonr%   r&   configparserr'   ior(   r)   samba.gp.vgp_files_extr*   r+   r-  rq  samba.registryr,   samba.ntstatusr-   r.   r/   r0   r1   samba.netcmd.gpcommonr2   r3   r4   samba.policiesr5   samba.dcerpc.miscr6   samba.gp.gpclassr7   r8   r9   rC   rH   r]   rd   rm   r=  r>  r?  SECINFO_SACLr   r   r   r   
IGNORECASEr   r   FILE_ATTRIBUTE_SYSTEMr   FILE_ATTRIBUTE_ARCHIVEFILE_ATTRIBUTE_HIDDENr   r   r   r   r  r,  rV  r}  r  r  r  r  r  r  r  r  r  r  r'  r5  rC  rI  rY  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r  r  r  r  r%  r5  r8  r:  r=  rA  rI  rK  rN  rR  rT  r[  rm  rq  r|  r  r  r  r  r  r`   rD   rB   <module>r     s  * 
 
  
 	 " "   %    ! *    } } -  8   $   O O -  3 2 -  , . %   <   &  
 1 * $ !dt#11#112#001 $001+\	#CL MM :2< )),,-**+ ))*
/2 8=7<",J+N +N\""* ""Jr:z r:jcz cLoz odT Tn,J* ,J^WM* WMt$M* $MN!B !BH); );X3X 3Xl87
 87vI IXPI PIf`<* `<FG3j G3T=O: =O~JQ7 JQXzj zxc5w c5J@& @&D1, 1yz yvD< D<L.< .?F ?FBfz fP,< ,?Jw ?JB\j \|Y Yv1, 1D(W D(LoJ obZz Zx/ /BEw BEHyj yv+, +L?w L?\mj m^V Vp1, 1+, +
@+G @+Df: fP(| (>#W >#@bJ bH) )[Mg [MzEZ ENc
 cJ-Iw -I^/7 /<G G65l 50 0) )#l #rD   