
    gW                       S SK r S SKrS SKrS SKJr  S SKJrJrJr  S SK	J
r
  S SKJrJr  S SKJr   " S S\5      r " S	 S
\5      r\" S \R*                  R-                  5        5       5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r  " S S\5      r! " S  S!\5      r"S" r#S# r$S$ r%g)%    N)dsdb)drsblobsdrsuapimisc)dsdb_Dn)
ndr_unpackndr_pack)Counterc                       \ rS rSrSrg)KCCError%    N)__name__
__module____qualname____firstlineno____static_attributes__r       5/usr/lib/python3/dist-packages/samba/kcc/kcc_utils.pyr   r   %   s    r   r   c                   2    \ rS rSr\" SS5      u  rrrrr	Sr
g)NCType)   r      r   N)r   r   r   r   rangeunknownschemadomainconfigapplicationr   r   r   r   r   r   )   s    5:1a[2Wfffkr   r   c              #   B   #    U  H  u  pUS S S:w  d  M  X!4v   M     g 7f)N   __r   ).0kvs      r   	<genexpr>r&   .   s$     N%<TQ"1&1&%<s   
c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)NamingContext1   zBase class for a naming context.

Holds the DN, GUID, SID (if available) and type of the DN.
Subclasses may inherit from this and specialize
c                 V    Xl         SU l        SU l        [        R                  U l        g)z;Instantiate a NamingContext

:param nc_dnstr: NC dn string
N)nc_dnstrnc_guidnc_sidr   r   nc_typeselfr+   s     r   __init__NamingContext.__init__8   s"    
 !~~r   c                    U R                   R                  < S3SU R                  -  -   S[        U R                  5      -  -   nU R
                  c  US-   nOUS-   nUS[        U R                     < SU R                  < S3-   nU$ )	!Debug dump string output of class:z
	nc_dnstr=%sz
	nc_guid=%sz
	nc_sid=<absent>z
	nc_sid=<present>z

	nc_type= ())	__class__r   r+   strr,   r-   
nctype_lutr.   r0   texts     r   __str__NamingContext.__str__B   s    //1 4==01#dll"334 ;;//D00Dz$,,/G/3||= =r   c                    SS/n UR                  U R                  [        R                  US9nUS   nSU;   a1  [        R                  " UR                  SUS   S   5      5      U l
        SU;   a  US   S   U l        U R                  c   eg ! [        R                   a1  nUR
                  u  pV[        SU R                  < SU< S35      eS nAff = f)N
objectGUID	objectSidbasescopeattrszUnable to find naming context () - (r7   r   )searchr+   ldb
SCOPE_BASELdbErrorargsr   r   GUIDschema_format_valuer,   r-   )r0   samdbrE   reseenumestrmsgs           r   load_ncNamingContext.load_ncQ   s    	2,,DMM%(^^5  BC !f399U%>%>|%(%6q%9&; <DL#k*1-DK||''' || 	266LT MM41 2 2	2s   )B C",CCc                 |    U R                   [        R                  :w  d   eU R                   [        R                  :H  $ )zReturn True if NC is config)r.   r   r   r   r0   s    r   	is_configNamingContext.is_confige   s+    ||v~~---||v}},,r   c                    U R                   c  U R                  U5        U R                  [        UR	                  5       5      :X  a  [
        R                  U l        gU R                  [        UR                  5       5      :X  a  [
        R                  U l        gU R                  b  [
        R                  U l        g[
        R                  U l        g)z\Given an NC object, identify what type it is thru
the samdb basedn strings and NC sid value
N)r,   rT   r+   r9   get_schema_basednr   r   r.   get_config_basednr   r-   r   r   )r0   rN   s     r   identify_by_basedn NamingContext.identify_by_basednj   s     <<LL ==C 7 7 9::!==DL]]c%"9"9";<<!==DL[[$!==DL!--DLr   c                    US:X  a  [         R                  U l        O3US:X  a  [         R                  U l        OUS:X  a  U R                  U5        U R                  [         R                  :X  a  U R                  U5        gg)a  Given an NC which has been discovered thru the
nTDSDSA database object, determine what type of NC
it is (i.e. schema, config, domain, application) via
the use of the schema attribute under which the NC
was found.

:param attr: attr of nTDSDSA object where NC DN appears
msDS-HasDomainNCshasPartialReplicaNCshasMasterNCsN)r   r   r.   r]   r   r0   rN   attrs      r   identify_by_dsa_attr"NamingContext.identify_by_dsa_attr   sk     &&!==DL ++!==DL ^###E* <<6>>)##E* *r   )r+   r,   r-   r.   N)r   r   r   r   __doc__r1   r=   rT   rX   r]   re   r   r   r   r   r(   r(   1   s%    &((-
..+r   r(   c                       \ rS rSrSrS rS rSS jrS rS r	S r
S	 rS
 rS rSS jrS rS rS rS rS rS rSS jrSrg)	NCReplica   zNaming context replica that is relative to a specific DSA.

This is a more specific form of NamingContext class (inheriting from that
class) and it identifies unique attributes of the DSA's replica for a NC.
c                     UR                   U l        UR                  U l        SU l        SU l        SU l        SU l        SU l        / U l	        / U l
        SU l        [        R                  X5        g)zwInstantiate a Naming Context Replica

:param dsa_guid: GUID of DSA where replica appears
:param nc_dnstr: NC dn string
Fr   N)	dsa_dnstrrep_dsa_dnstrdsa_guidrep_dsa_guidrep_defaultrep_partialrep_rorep_instantiated_flagsrep_fsmo_role_ownerrep_repsFrom
rep_repsTorep_present_criteria_oner(   r1   )r0   dsar+   s      r   r1   NCReplica.__init__   sp     !]]LL  &'##'    ).% 	t.r   c                    SU R                   R                  -  SU R                  -  -   SU R                  -  -   SU R                  -  -   SU R
                  -  -   SU R                  -  -   SU R                  5       -  -   SU R                  -  -   S	R                  S
 U R                   5       5      -   S	R                  S U R                   5       5      -   n[        R                  U 5      < SU< 3$ )r4   %s:
	dsa_dnstr=%s
	dsa_guid=%sz
	default=%s
	ro=%sz
	partial=%sz
	present=%sz
	fsmo_role_owner=%s c              3   ,   #    U  H
  nS U-  v   M     g7f
%sNr   r#   reps     r   r&   $NCReplica.__str__.<locals>.<genexpr>   s     A/@v|/@   c              3   ,   #    U  H
  nS U-  v   M     g7fr   r   r   s     r   r&   r      s     ?v|r   
)r8   r   rm   ro   rp   rr   rq   
is_presentrt   joinru   rv   r(   r=   r;   s     r   r=   NCReplica.__str__   s    t~~...!D$6$667 4#4#445  $"2"223 T[[(	)
  $"2"223  $//"334 ($*B*BBC wwAt/@/@AAB ww?t??	@ )006==r   c                     Xl         g)z*Set or clear NC replica instantiated flagsN)rs   )r0   flagss     r   set_instantiated_flags NCReplica.set_instantiated_flags   s    &+#r   c                    US:X  a  SU l         SU l        OUS:X  a  SU l        OUS:X  a]  SU l        U R                  [	        UR                  5       5      :w  a.  U R                  [	        UR                  5       5      :w  a  SU l        O)US:X  a  SU l        SU l        OUS:X  a  SU l        SU l        [        R                  XU5        g)	zGiven an NC which has been discovered thru the
nTDSDSA database object, determine what type of NC
replica it is (i.e. partial, read only, default)

:param attr: attr of nTDSDSA object where NC DN appears
ra   Tr`   rb   msDS-hasFullReplicaNCsmsDS-hasMasterNCsFN)
rq   rw   rp   r+   r9   r[   r\   rr   r(   re   rc   s      r   re   NCReplica.identify_by_dsa_attr   s     ))#D,0D)
 ((#D ^#,0D)}}E$;$;$= >>}}E$;$;$= >>#'  --,0D)DK ((,0D)DK
 	**4=r   c                     U R                   $ )zMWhether this is a default domain for the dsa that this NC appears on
        )rp   rW   s    r   
is_defaultNCReplica.is_default  s     r   c                     U R                   $ )z&Return True if NC replica is read only)rr   rW   s    r   is_roNCReplica.is_ro  s    {{r   c                     U R                   $ )z$Return True if NC replica is partial)rq   rW   s    r   
is_partialNCReplica.is_partial  s    r   c                 j    U R                   (       a"  U R                  [        R                  -  S:X  a  gg)a  Given an NC replica which has been discovered thru the
nTDSDSA database object and populated with replica flags
from the msDS-HasInstantiatedNCs; return whether the NC
replica is present (true) or if the IT_NC_GOING flag is
set then the NC replica is not present (false)
r   TF)rw   rs   r   INSTANCE_TYPE_NC_GOINGrW   s    r   r   NCReplica.is_present  s,     ((&&)D)DDIr   c                     UR                  U R                  [        R                  S/S9nUS   nSU;   aY  US    HO  n [        [        R                  U5      n[        U R                  U5      n
U R                  R!                  U
5        MQ     gg! [        R                   a1  nUR
                  u  pE[        SU R                  < SU< S35      eSnAff = f! [         a&  n	[        SU-  [        R                  S	9   Sn	A	M  Sn	A	ff = f)
a
  Given an NC replica which has been discovered thru the nTDSDSA
database object, load the repsFrom attribute for the local replica.
held by my dsa.  The repsFrom attribute is not replicated so this
attribute is relative only to the local DSA that the samdb exists on
repsFromrB   Unable to find NC for (rF   r7   Nr   zbad repsFrom NDR: %rfile)rG   r+   rH   rI   rJ   rK   r   r   r   repsFromToBlobRuntimeErrorprintsysstderr
RepsFromToru   append)r0   rN   rO   e1rQ   rR   rS   valueunpackedrP   r   s              r   load_repsFromNCReplica.load_repsFrom%  s    	2,,DMM&0\  3C !f Z)(*A*A5IH
 !9!!((- )  || 	277LT MM41 2 2	2 $ 0E:"zz+/   *B  CC%,CC
D	#DD	c                    Sn/ n/ nU R                    Ht  nUR                  (       a  UR                  U5        SnM)  UR                  5       (       a  UR	                  5         SnUR                  [        UR                  5      5        Mv     U H  nU R                   R                  U5        M      / nU(       a  U(       a  g[        R                  " 5       n[        R                  " XR                  5      Ul        [        R                  " U[        R                  S5      US'    UR                  U5        g! [        R                    a#  n[#        SU R                  < SU< S35      eSnAff = f)zCommit repsFrom to the databaseFTNr   zCould not set repsFrom for (rF   r7   )ru   to_be_deletedr   is_modifiedset_unmodifiedr	   ndr_blobremoverH   MessageDnr+   dnMessageElementFLAG_MOD_REPLACEmodifyrJ   r   )	r0   rN   ror   newrepsdelrepsr   mrR   s	            r   commit_repsFromNCReplica.commit_repsFromB  s+    ))H %%x(##%%'') NN8H$5$567' *,  H$$X.   KKMvve]]+ w(<(<jI 	
*	2LLO|| 	2 MM41 2 2	2   $D6 6E-
E((E-c                     UR                  U R                  [        R                  S/S9nUS   nSU;   af  US   S   n[        [        R                  U5      nUR                  S:w  a  [        S	UR                  -  5      eUR                  R                  U l        g/ U l        g! [        R                   a1  nUR
                  u  pE[        SU R                  < SU< S35      eSnAff = f)
a  Given an NC replica which has been discovered thru the nTDSDSA
database object, load the replUpToDateVector attribute for the
local replica. held by my dsa. The replUpToDateVector
attribute is not replicated so this attribute is relative only
to the local DSA that the samdb exists on

replUpToDateVectorrB   r   rF   r7   Nr   r!   z(Unexpected replUpToDateVector version %d)rG   r+   rH   rI   rJ   rK   r   r   r   replUpToDateVectorBlobversionAttributeErrorctrcursorsrep_replUpToDateVector_cursors)	r0   rN   rO   e2rQ   rR   rS   r   blobs	            r   load_replUpToDateVector!NCReplica.load_replUpToDateVector  s    	2,,DMM&:%;  =C !f  3&,-a0Eh==#%D||q $%O'+||&4 5 5 37((2B2BD/24D/' || 	277LT MM41 2 2	2s   *B% %C*9,C%%C*c                 F    SR                  S U R                   5       5      $ )Nr   c              3   \   #    U  H"  oR                   (       d  M  [        U5      v   M$     g 7fN)r   r9   r#   xs     r   r&   2NCReplica.dumpstr_to_be_deleted.<locals>.<genexpr>  s     N):AooQ):s   ,,r   ru   rW   s    r   dumpstr_to_be_deletedNCReplica.dumpstr_to_be_deleted      yyN):):NNNr   c                 F    SR                  S U R                   5       5      $ )Nr   c              3   d   #    U  H&  oR                  5       (       d  M  [        U5      v   M(     g 7fr   )r   r9   r   s     r   r&   3NCReplica.dumpstr_to_be_modified.<locals>.<genexpr>  s      N):AmmoQ):s   00r   rW   s    r   dumpstr_to_be_modified NCReplica.dumpstr_to_be_modified  r   r   c                     UR                  U R                  [        R                  S/S9nUS   nSU;   a  US   U l        gg! [        R                   a1  nUR
                  u  pE[        SU R                  < SU< S35      eSnAff = f)zrGiven an NC replica which has been discovered thru the nTDSDSA
database object, load the fSMORoleOwner attribute.
fSMORoleOwnerrB   r   rF   r7   Nr   )rG   r+   rH   rI   rJ   rK   r   rt   )r0   rN   rO   e3rQ   rR   rS   s          r   load_fsmo_rolesNCReplica.load_fsmo_roles  s    	2,,DMM&5%6  8C !f c!'*?';D$ " || 	277LT MM41 2 2	2s   *A B,BBc                 @    U R                   b  U R                   U:X  a  gg)NTF)rt   r0   rl   s     r   is_fsmo_role_ownerNCReplica.is_fsmo_role_owner  s"    ##/##y0r   c                     UR                  U R                  [        R                  S/S9nUS   nSU;   aY  US    HO  n [        [        R                  U5      n[        U R                  U5      n
U R                  R!                  U
5        MQ     gg! [        R                   a1  nUR
                  u  pE[        SU R                  < SU< S35      eSnAff = f! [         a&  n	[        SU-  [        R                  S	9   Sn	A	M  Sn	A	ff = f)
ar  Given an NC replica which has been discovered thru the nTDSDSA
database object, load the repsTo attribute for the local replica.
held by my dsa.  The repsTo attribute is not replicated so this
attribute is relative only to the local DSA that the samdb exists on

This is responsible for push replication, not scheduled pull
replication. Not to be confused for repsFrom.
repsTorB   r   rF   r7   Nr   zbad repsTo NDR: %rr   )rG   r+   rH   rI   rJ   rK   r   r   r   r   r   r   r   r   r   rv   r   )r0   rN   rO   e4rQ   rR   rS   r   r   rP   r   s              r   load_repsToNCReplica.load_repsTo  s    	2,,DMM&.Z  1C !f s?X)(*A*A5IH
 !9&&s+ '  || 	277LT MM41 2 2	2 $ .%8"zz+r   c                    Sn/ n/ nU R                    Ht  nUR                  (       a  UR                  U5        SnM)  UR                  5       (       a  UR	                  5         SnUR                  [        UR                  5      5        Mv     U H  nU R                   R                  U5        M      / nU(       a  U(       a  g[        R                  " 5       n[        R                  " XR                  5      Ul        [        R                  " U[        R                  S5      US'    UR                  U5        g! [        R                    a#  n[#        SU R                  < SU< S35      eSnAff = f)zCommit repsTo to the databaseFTNr   zCould not set repsTo for (rF   r7   )rv   r   r   r   r   r	   r   r   rH   r   r   r+   r   r   r   r   rJ   r   )	r0   rN   r   r   r   r   r   r   rR   s	            r   commit_repsToNCReplica.commit_repsTo  s%    ooF ##v&!!##%%' NN8FOO45' &, FOO""6*  KKMvve]]+ w(<(<hG 	
(	2LLO|| 	2 MM41 2 2	2r   )rp   rm   ro   rt   rs   rq   rw   r   ru   rv   rr   N)r   F)r   r   r   r   rg   r1   r=   r   re   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ri   ri      sb    />>,/>b 
 
.:=2~5BOO<&,@=2r   ri   c                       \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rSS jrS rS rS rS rS rS rSrg)DirectoryServiceAgenti!  c                     Xl         SU l        SU l        SU l        SU l        SU l        SU l        SU l        0 U l        0 U l	        0 U l
        g)zInitialize DSA class.

Class is subsequently fully populated by calling the load_dsa() method

:param dsa_dnstr:  DN of the nTDSDSA
NFr   )rl   rn   dsa_ivid	dsa_is_rodsa_is_istgoptionsdsa_behaviordefault_dnstrcurrent_rep_tableneeded_rep_tableconnect_tabler   s     r   r1   DirectoryServiceAgent.__init__#  s[     # ! "$ !#
  r   c                    SU R                   R                  -  nU R                  b  USU R                  -  -   nU R                  b  US[	        U R                  5      -  -   nU R
                  b  US[	        U R
                  5      -  -   nUSU R                  5       -  SU R                  5       -  -   SU R                  5       -  -   S-   S	U R                  5       -  -   S
-   S	U R                  5       -  -   S-   S	U R                  5       -  -   -  nU$ )r4   r{   r|   r}   z
	dsa_ivid=%sr~   z
	gc=%sz	
	istg=%sz
current_replica_table:r   z
needed_replica_table:z
connect_table:)r8   r   rl   rn   r9   r   r   is_gcis_istgdumpstr_current_replica_tabledumpstr_needed_replica_tabledumpstr_connect_tabler;   s     r   r=   DirectoryServiceAgent.__str__@  s&    t~~...>>%,t~~==D==$+c$--.@@@D==$+c$--.@@@Ddjjl*djjl*+./ ++ ;;==	>
 ** ::<<= ## 33556 	6 r   c                 8    U R                   R                  U5      $ r   )r   getr/   s     r   get_current_replica)DirectoryServiceAgent.get_current_replicaW  s    %%))(33r   c                 @    U R                   =(       d    U R                  $ )zAReturns True if dsa is intersite topology generator for it's site)r   r   rW   s    r   r  DirectoryServiceAgent.is_istgZ  s     14>>1r   c                     U R                   $ )z1Returns True if dsa a read only domain controller)r   rW   s    r   r   DirectoryServiceAgent.is_ro_  s    ~~r   c                 H    U R                   [        R                  -  S:w  a  gg)z*Returns True if dsa hosts a global catalogr   TF)r   r   DS_NTDSDSA_OPT_IS_GCrW   s    r   r   DirectoryServiceAgent.is_gcc  s    LL4444:r   c                 &    U R                   U:  a  gg)zIs dsa at minimum windows level greater than or equal to (version)

:param version: Windows version to test against
    (e.g. DS_DOMAIN_FUNCTION_2008)
TF)r   )r0   r   s     r   is_minimum_behavior)DirectoryServiceAgent.is_minimum_behaviori  s     'r   c                 H    U R                   [        R                  -  S:w  a  gg)z>Whether this allows NTDSConnection translation in its options.r   TF)r   r   %DS_NTDSDSA_OPT_DISABLE_NTDSCONN_XLATErW   s    r   is_translate_ntdsconn_disabled4DirectoryServiceAgent.is_translate_ntdsconn_disableds  s    LL4EEE!Kr   c                 2    U R                   U R                  4$ )z5Return DSA current and needed replica tables
        )r   r   rW   s    r   get_rep_tables$DirectoryServiceAgent.get_rep_tablesy  s     %%t'<'<<<r   c                 B    U R                   R                  S5      u  pnU$ )z(Get the parent DN string of this object.,)rl   	partition)r0   headseptails       r   get_parent_dnstr&DirectoryServiceAgent.get_parent_dnstr~  s    ..22374r   c                    / SQn UR                  U R                  [        R                  US9nUS   n[        R                  " UR                  SUS   S   5      5      U l
        S	U;   a1  [        R                  " UR                  SUS	   S   5      5      U l        S
U;   a  [        US
   S   5      U l        SU;   a  [        US   S   5      S:X  a  SU l        OSU l        SU;   a  [        US   S   5      U l        U R#                  U5        U R%                  U5        g! [        R                   a1  nUR
                  u  pV[        SU R                  < SU< S35      eSnAff = f)zLoad a DSA from the samdb.

Prior initialization has given us the DN of the DSA that we are to
load.  This method initializes all other attributes, including loading
the NC replica table for this DSA.
)r@   invocationIDr   msDS-isRODCmsDS-Behavior-VersionrB   zUnable to find nTDSDSA for (rF   r7   Nr   r@   invocationIdr   r%  TRUETFr&  )rG   rl   rH   rI   rJ   rK   r   r   rL   rM   rn   r   intr   r9   r   r   load_current_replica_tableload_connection_table)r0   rN   rE   rO   e5rQ   rR   rS   s           r   load_dsaDirectoryServiceAgent.load_dsa  sd   *
	3,,DNN#..%*  ,C !f		%";";L"%l"3A"6#8 9
 S  IIe&?&?&).&9!&<'> ?DM s9~a01DLCCM(:1(=$>&$H!DN"DN"c) #C(?$@$C DD 	''. 	""5)= || 	377LT NND2 3 3	3s   )D! !E&5,E!!E&c                    / SQn UR                  U R                  [        R                  US9n0 n[        US   5      S:  a  US   R                  5        H  nUS:X  a  M  US   U    H  n	[        XR                  S	5      5      n
U
R                  5       n[        U
R                  5      nX;  a  [        X5      nXU'   OX|   nUS
:X  a  UR                  U5        Mt  UR!                  X5        UR#                  5       (       d  M  Xl        M     M     O[        SU R                  -  5      eXpl        g! [        R                   a1  nUR
                  u  pV[        SU R                  < SU< S35      eSnAff = f)a  Method to load the NC replica's listed for DSA object.

This method queries the samdb for (hasMasterNCs, msDS-hasMasterNCs,
hasPartialReplicaNCs, msDS-HasDomainNCs, msDS-hasFullReplicaNCs, and
msDS-HasInstantiatedNCs) to determine complete list of NC replicas that
are enumerated for the DSA.  Once a NC replica is loaded it is
identified (schema, config, etc) and the other replica attributes
(partial, ro, etc) are determined.

:param samdb: database to query for DSA replica list
)rb   r   ra   r`   r   msDS-HasInstantiatedNCsrB   z Unable to find nTDSDSA NCs for (rF   r7   Nr   r   utf8r0  zNo nTDSDSA NCs for (%s))rG   rl   rH   rI   rJ   rK   r   lenkeysr   decodeget_binary_integerr9   r   ri   r   re   r   r   r   )r0   rN   ncattrsrO   e6rQ   rR   	tmp_tabler$   r   dsdnr   dnstrr   s                 r   r*  0DirectoryServiceAgent.load_current_replica_table  se   
	3,,DNN#..%,  .C 	 s1v;? V[[]9
 !VAYE #5,,v*>?D 335ELE-'4+.%('.552259 ,,U6 ~~''-2*- ' #> 4t~~EFF "+g || 	377LT NND2 3 3	3s   )D3 3E8,E33E8c                 4    XR                   UR                  '   g)zMMethod to add a NC replica that "should be present" to the
needed_rep_table.
N)r   r+   )r0   r   s     r   add_needed_replica(DirectoryServiceAgent.add_needed_replica  s     /2cll+r   c                     UR                  U R                  [        R                  SS9nU HS  n[        UR                  5      nXpR                  ;   a  M)  [        U5      nUR                  U5        XR                  U'   MU     g! [        R                   a1  nUR
                  u  pE[        SU R                  < SU< S35      eSnAff = f)zsMethod to load the nTDSConnections listed for DSA object.

:param samdb: database to query for DSA connection list
z(objectClass=nTDSConnection)rC   rD   
expression#Unable to find nTDSConnection for (rF   r7   N)rG   rl   rH   SCOPE_SUBTREErJ   rK   r   r9   r   r   NTDSConnectionload_connection)	r0   rN   rO   e7rQ   rR   rS   r:  connects	            r   r+  +DirectoryServiceAgent.load_connection_table  s    
	3,,DNN%(%6%6*H  JC CKE ***$U+G##E*(/u%  || 	377LT NND2 3 3	3s   )B C
,CC
c                 l   / nU R                   R                  5        H~  u  pEUR                  (       a  UR                  X5        UR                  (       a  UR                  X5        UR                  (       d  M\  UR                  X5        UR                  U5        M     U H  nU R                   U	 M     g)aC  Method to commit any uncommitted nTDSConnections
modifications that are in our table.  These would be
identified connections that are marked to be added or
deleted

:param samdb: database to commit DSA connection list to
:param ro: if (true) then perform internal operations but
    do not write to the database (readonly)
N)	r   itemsto_be_addedcommit_addedto_be_modifiedcommit_modifiedr   commit_deletedr   )r0   rN   r   delconnr:  rG  s         r   commit_connections(DirectoryServiceAgent.commit_connections'  s     "00668NE""$$U/%%''2$$$&&u1u% 9 E""5) r   c                 B    XR                   ;  d   eX R                   U'   g r   )r   )r0   r:  rG  s      r   add_connection$DirectoryServiceAgent.add_connectionB  s"    .....$+5!r   c                     / nU R                   R                  5        H*  nUR                  5       U:X  d  M  UR                  U5        M,     U$ )zScan DSA nTDSConnection table and return connection
with a "fromServer" dn string equivalent to method
input parameter.

:param from_dnstr: search for this from server entry
)r   valuesget_from_dnstrr   )r0   
from_dnstranswerrG  s       r   get_connection_by_from_dnstr2DirectoryServiceAgent.get_connection_by_from_dnstrF  sF     ))002G%%':5g& 3 r   c                 F    SR                  S U R                   5       5      $ )z1Debug dump string output of current replica tabler   c              3   8   #    U  H  n[        U5      v   M     g 7fr   r9   r   s     r   r&   FDirectoryServiceAgent.dumpstr_current_replica_table.<locals>.<genexpr>V  s     @)?AQ)?   )r   r   rW   s    r   r  3DirectoryServiceAgent.dumpstr_current_replica_tableT  s    yy@)?)?@@@r   c                 F    SR                  S U R                   5       5      $ )z0Debug dump string output of needed replica tabler   c              3   8   #    U  H  n[        U5      v   M     g 7fr   r_  r   s     r   r&   EDirectoryServiceAgent.dumpstr_needed_replica_table.<locals>.<genexpr>Z  s     ?)>AQ)>ra  )r   r   rW   s    r   r  2DirectoryServiceAgent.dumpstr_needed_replica_tableX  s    yy?)>)>???r   c                 F    SR                  S U R                   5       5      $ )z)Debug dump string output of connect tabler   c              3   8   #    U  H  n[        U5      v   M     g 7fr   r_  r   s     r   r&   >DirectoryServiceAgent.dumpstr_connect_table.<locals>.<genexpr>^  s     <);AQ);ra  )r   r   rW   s    r   r  +DirectoryServiceAgent.dumpstr_connect_table\  s    yy<););<<<r   c                 V   S[        [        R                  " 5       5      -  U R                  -   n[	        U5      nSUl        SUl        XGl        Xl        X'l	        Ub"  UR                  Ul        UR                  Ul        Ub  XWl        O[        5       Ul        U R!                  Xg5        U$ )zSet up a new connection for the DSA based on input
parameters.  Connection will be added to the DSA
connect_table and will be marked as "to be added" pending
a call to commit_connections()
zCN=%s,T)r9   uuiduuid4rl   rD  rK  enabledrY  r   system_flagsr:  transport_dnstrguidtransport_guidschedulenew_connection_schedulerT  )r0   r   ro  	transportrY  schedr:  rG  s           r   new_connection$DirectoryServiceAgent.new_connection`  s     3tzz|,,t~~= '"'!+ &/ooG#%.^^G"$  78GE+r   )r   r   r   r   rl   rn   r   r   r   r   r   Nr   )r   r   r   r   r1   r=   r  r  r   r   r  r  r  r!  r-  r*  r=  r+  rQ  rT  r[  r  r  r  rw  r   r   r   r   r   r   !  sp     :.42
=

.*`Q+f206*6,A@=r   r   c                       \ rS rSrSrS rS rS rS rSS jr	SS jr
SS	 jrS
 rS rS rS rS rS rS rS rS rS rS rS rSrg)rD  i  z5Class defines a nTDSConnection found under a DSA
    c                     Xl         S U l        SU l        SU l        SU l        SU l        SU l        SU l        SU l        S U l	        S U l
        S U l        S U l        g )NFr   )r:  rq  rn  whenCreatedrK  r   rM  r   ro  rp  rr  rY  rs  r0   r:  s     r   r1   NTDSConnection.__init__  sb    
	 "##"r   c                    U R                   R                  < SU R                  < 3SU R                  -  -   SU R                  -  -   SU R
                  -  -   SU R                  -  -   SU R                  -  -   SU R                  -  -   SU R                  -  -   S	U R                  -  -   nU R                  b  US
[        U R                  5      -  -  nU R                  b  US[        U R                  5      -  -  nUSU R                  -  -   nU R                  b  USU R                  R                   -  SU R                  R"                  -  -   SU R                  R$                  -  -   -  n['        U R                  R(                  5       Hl  u  p#USX#R*                  4-  SX#R,                  4-  -   SU-  -   SR/                  S U R                  R0                  U   R2                   5       5      -   S-   -  nMn     U$ )z1Debug dump string output of NTDSConnection object:
	dn=z
	enabled=%sz
	to_be_added=%sz
	to_be_deleted=%sz
	to_be_modified=%sz
	options=0x%08Xz
	system_flags=0x%08Xz
	whenCreated=%dz
	transport_dn=%s	
	guid=%s
	transport_guid=%sz
	from_dn=%s
	schedule.size=%s
	schedule.bandwidth=%s
	schedule.numberOfSchedules=%s"
	schedule.headerArray[%d].type=%d$
	schedule.headerArray[%d].offset=%d 
	schedule.dataArray[%d].slots[ r   c              3   ,   #    U  H
  nS U-  v   M     g7fz0x%X Nr   r#   slots     r   r&   )NTDSConnection.__str__.<locals>.<genexpr>       \;[4$;[r   ])r8   r   r:  rn  rK  r   rM  r   ro  r{  rp  rq  r9   rr  rY  rs  size	bandwidthnumberOfSchedules	enumerateheaderArraytypeoffsetr   	dataArrayslots)r0   r<   iheaders       r   r=   NTDSConnection.__str__  s    "&!8!8$**E$,,./#d&6&667 &(:(::; ')<)<<	=
 $dll23 )4+<+<<= $d&6&667 %t';';;< 99 MC		N22D*+c$2E2E.FFFD&88==$*T]]-?-??/$--2I2IIJ8]]4456 6D
 't}}'@'@A	?KK()A]]+,- =q@	A
 \4==;R;RST;U;[;[\\]   B r   c                    / SQn UR                  U R                  [        R                  US9nUS   nSU;   a  [        US   S   5      U l        S	U;   aF  [        US	   S   5      R                  5       R                  5       R                  5       S
:X  a  SU l        SU;   a  [        US   S   5      U l         [        R                   " UR#                  SUS   S   5      5      U l        SU;   aE  [)        XS   S   R+                  S5      5      nU R-                  U[        UR.                  5      5        SU;   a%  [1        [2        R4                  US   S   5      U l        SU;   a*  [        R6                  " [        US   S   5      5      U l        SU;   aJ  [)        XS   S   R+                  S5      5      n[        UR.                  5      U l        U R:                  c   egg! [        R                   a1  nUR
                  u  pV[        SU R                  < SU< S35      eSnAff = f! [&         a    [        SU R                  -  5      ef = f)zGiven a NTDSConnection object with an prior initialization
for the object's DN, search for the DN and load attributes
from the samdb.
)r   enabledConnectionrs  r{  r@   transportType
fromServersystemFlagsrB   rB  rF   r7   Nr   r   r  r(  Tr  r@   z4Unable to find objectGUID in nTDSConnection for (%s)r  r1  rs  r{  r  )rG   r:  rH   rI   rJ   rK   r   r)  r   r9   upperlstriprstriprn  ro  r   rL   rM   rq  KeyErrorr   r4  load_connection_transportr   r   r   rs  string_to_timer{  rY  )	r0   rN   rE   rO   e8rQ   rR   rS   r9  s	            r   rE  NTDSConnection.load_connection  s5   
 	/,,DJJcnn%*  ,C !fs9~a01DL#%3*+A./557>>@GGIVS#C #C$6q$9 :D	6		%33L474Ea4HJ K I c!5o"6q"9"@"@"HID**5#dgg,?&x'8'8#j/!:LMDMC"11#c-6H6K2LMD35l"3A"6"="=f"EFD!$''lDO??... G || 	/77LT JJ. / /	/*  	6 &)-5 6 6	6s#   )G! 91H) !H&5,H!!H&)#Ic                    S/n UR                  U[        R                  US9nSUS   ;   a<  US   nX l        [        R                  " UR                  SUS   S   5      5      U l
        U R                  c   eU R                  c   eg! [        R                   a'  nUR                  u  pg[        SU< SU< S35      eSnAff = f)zGiven a NTDSConnection object which enumerates a transport
DN, load the transport information for the connection object

:param tdnstr: transport DN to load
r@   rB   zUnable to find transport (rF   r7   Nr   )rG   rH   rI   rJ   rK   r   rp  r   rL   rM   rr  )	r0   rN   tdnstrrE   rO   e9rQ   rR   rS   s	            r   r  (NTDSConnection.load_connection_transport  s     	+,,F%(^^5  BC 3q6!a&C#) 		%33L474Ea4HJ K  ##///""... || 	+77LT"D* + +	+s   B C"B>>Cc                    U R                   (       d   eSU l         U(       a  g UR                  U R                  5        g! [        R                   a1  nUR
                  u  pE[        SU R                  < SU< S35      eSnAff = f)zLocal helper routine for commit_connections() which
handles committed connections that are to be deleted from
the database database
FNz%Could not delete nTDSConnection for (rF   r7   )r   deleter:  rH   rJ   rK   r   )r0   rN   r   e10rQ   rR   s         r   rO  NTDSConnection.commit_deleted	  sr    
 !!!!" 	/LL$|| 	/88LT JJ. / /	/s   A   B,B  Bc                    U R                   (       d   eSU l         U(       a  gSn UR                  U R                  [        R                  S9n[        U5      S:w  a  SnU(       a  [        S	U R                  -  5      eU R                  (       a  S
nOSn[        R                  " 5       n	[        R                  " XR                  5      U	l        [        R                  " S[        R                  S5      U	S'   [        R                  " S
[        R                  S5      U	S'   [        R                  " U[        R                  S5      U	S'   [        R                  " U R                   [        R                  S5      U	S'   [        R                  " [#        U R$                  5      [        R                  S5      U	S'   [        R                  " [#        U R&                  5      [        R                  S5      U	S'   U R(                  b<  [        R                  " [#        U R(                  5      [        R                  S5      U	S'   U R*                  b<  [        R                  " [-        U R*                  5      [        R                  S5      U	S'    UR/                  U	5        g! [        R                   aK  nUR                  u  pgU[        R                  :w  a  [        SU R                  < SU< S35      e SnAGNSnAff = f! [        R                   a1  n
U
R                  u  pg[        SU R                  < SU< S35      eSn
A
ff = f)zwLocal helper routine for commit_connections() which
handles committed connections that are to be added to the
database
FNrC   rD   r   TUnable to search for (rF   r7   z'nTDSConnection for (%s) already exists!r(  FALSEnTDSConnectionobjectClassshowInAdvancedViewOnlyr  r  r   r  r  rs  z"Could not add nTDSConnection for ()rK  rG   r:  rH   rI   r2  rJ   rK   ERR_NO_SUCH_OBJECTr   rn  r   r   r   r   FLAG_MOD_ADDrY  r9   r   ro  rp  rs  r	   add)r0   rN   r   foundrS   e11rQ   rR   	enablestrr   e12s              r   rL  NTDSConnection.commit_added  s   
    		3,,DJJcnn,EC3x1} D::& ' ' <<II KKMvveZZ( /1A1A,. 	
- vs'7'779 	

"# y#*:*:24 	

 t0@0@,O 	
, s4<<0#2B2BIN 	
) s4#4#45s7G7G,. 	
- +""3t';';#<c>N>N#24 o ==$""8DMM#:#&#3#3ZA jM	/IIaL[ || 	388LTs--- $

D 2 3 3 .	3\ || 	/88LT JJ. / /	/s0   9J K; K8-A K33K8;M ,L;;M c                 J   U R                   (       d   eSU l         U(       a  g UR                  U R                  [        R                  S9  U R                  (       a  SnOS	n[        R                  " 5       n[        R                  " XR                  5      Ul        [        R                  " U[        R                  S
5      US
'   [        R                  " U R                  [        R                  S5      US'   [        R                  " [!        U R"                  5      [        R                  S5      US'   [        R                  " [!        U R$                  5      [        R                  S5      US'   U R&                  b=  [        R                  " [!        U R&                  5      [        R                  S5      US'   O)[        R                  " / [        R(                  S5      US'   U R*                  b=  [        R                  " [-        U R*                  5      [        R                  S5      US'   O)[        R                  " / [        R(                  S5      US'    UR/                  U5        g! [        R
                   a]  nUR                  u  pEU[        R                  :X  a  [        SU R                  -  5      e[        SU R                  < SU< S35      eSnAff = f! [        R
                   a1  nUR                  u  pE[        SU R                  < SU< S35      eSnAff = f)zzLocal helper routine for commit_connections() which
handles committed connections that are to be modified to the
database
FNr  z&nTDSConnection for (%s) doesn't exist!r  rF   r7   r(  r  r  r  r   r  r  rs  z%Could not modify nTDSConnection for ()rM  rG   r:  rH   rI   rJ   rK   r  r   rn  r   r   r   r   r   rY  r9   r   ro  rp  FLAG_MOD_DELETErs  r	   r   )	r0   rN   r   e13rQ   rR   r  r   e14s	            r   rN  NTDSConnection.commit_modifiedc  s   
 """"# 	/ LLdjjL? <<II KKMvveZZ( y#*>*>24 	

 t0D0D+- 	
, s4<<0#2F2F(* 	
) s4#4#45s7K7K,. 	
- +""3t';';#<#&#7#7J o
 ""2s':':OL o ==$""8DMM#:#&#7#7E jM
 ""2s':':JG jM	/LLO] || 	/88LTs---G#zz * + + JJ. / /	/^ || 	/88LT JJ. / /	/s0   (I) K )K=AKKL"1,LL"c                     Xl         g r   )rM  )r0   	truefalses     r   set_modifiedNTDSConnection.set_modified  s    'r   c                     U R                   b  U R                   R                  S   c  gU R                   R                  S   R                   H  nUS-  S:w  d  M    g   g)zjReturns True if our schedule includes at least one
replication interval within the week.  False otherwise
r   F   T)rs  r  r  )r0   r  s     r   !is_schedule_minimum_once_per_week0NTDSConnection.is_schedule_minimum_once_per_week  sX     == DMM$;$;A$>$FMM++A.44Dt# 5 r   c                    U R                   c  USL $ Uc  gU R                   R                  UR                  :w  dH  U R                   R                  UR                  :w  d$  U R                   R                  UR                  :w  a  g[	        U R                   R
                  5       H  u  p#U R                   R
                  U   R                  UR
                  U   R                  :w  a    gU R                   R
                  U   R                  UR
                  U   R                  :w  a    g[        U R                   R                  U   R                  UR                  U   R                  5       H  u  pEXE:w  d  M      g   M     g)zrReturns True if our schedule is equivalent to the input
comparison schedule.

:param shed: schedule to compare to
NFT)rs  r  r  r  r  r  r  r  zipr  r  )r0   rv  r  r  abs         r   is_equivalent_schedule%NTDSConnection.is_equivalent_schedule  s.    == D= =]]5::-]]$$7]],,0G0GG"4==#<#<=IA}}((+00E4E4Ea4H4M4MM}}((+22  #**+DMM33A6<<!OOA.4466 6 > r   c                 H    U R                   [        R                  -  S:X  a  gg)z=Returns True if NTDS Connection specifies RODC
topology only
r   FT)r   r   NTDSCONN_OPT_RODC_TOPOLOGYrW   s    r   is_rodc_topologyNTDSConnection.is_rodc_topology  s!     <<$999Q>r   c                 H    U R                   [        R                  -  S:X  a  gg)zsReturns True if NTDS Connection was generated by the
KCC topology algorithm as opposed to set by the administrator
r   FT)r   r   NTDSCONN_OPT_IS_GENERATEDrW   s    r   is_generatedNTDSConnection.is_generated  s!     <<$888A=r   c                 H    U R                   [        R                  -  S:X  a  gg)zGReturns True if NTDS Connection should override notify default
        r   FT)r   r   $NTDSCONN_OPT_OVERRIDE_NOTIFY_DEFAULTrW   s    r   is_override_notify_default)NTDSConnection.is_override_notify_default  s!     <<$CCCqHr   c                 H    U R                   [        R                  -  S:X  a  gg)z:Returns True if NTDS Connection should use notify
        r   FT)r   r   NTDSCONN_OPT_USE_NOTIFYrW   s    r   is_use_notifyNTDSConnection.is_use_notify  s!     <<$666!;r   c                 H    U R                   [        R                  -  S:X  a  gg)z?Returns True if NTDS Connection should use twoway sync
        r   FT)r   r   NTDSCONN_OPT_TWOWAY_SYNCrW   s    r   is_twoway_syncNTDSConnection.is_twoway_sync  s!     <<$7771<r   c                 H    U R                   [        R                  -  S:X  a  gg)zBReturns True if NTDS Connection intersite compression
is disabled
r   FT)r   r   *NTDSCONN_OPT_DISABLE_INTERSITE_COMPRESSIONrW   s    r   !is_intersite_compression_disabled0NTDSConnection.is_intersite_compression_disabled  s!     <<$IIIQNr   c                 H    U R                   [        R                  -  S:X  a  gg)zBReturns True if NTDS Connection has a user owned schedule
        r   FT)r   r    NTDSCONN_OPT_USER_OWNED_SCHEDULErW   s    r   is_user_owned_schedule%NTDSConnection.is_user_owned_schedule  s!     <<$???1Dr   c                     U R                   $ )z3Returns True if NTDS Connection is enabled
        )rn  rW   s    r   
is_enabledNTDSConnection.is_enabled  s     ||r   c                     U R                   $ )z%Return fromServer dn string attribute)rY  rW   s    r   rX  NTDSConnection.get_from_dnstr  s    r   )r:  rn  rY  rq  r   rs  ro  rK  r   rM  rp  rr  r{  Nr   )r   r   r   r   rg   r1   r=   rE  r  rO  rL  rN  r  r  r  r  r  r  r  r  r  r  r  rX  r   r   r   r   rD  rD    sm    $L7/r/2/&E/NE/N(&P
r   rD  c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)	Partitioni!  a  A naming context discovered thru Partitions DN of the config schema.

This is a more specific form of NamingContext class (inheriting from that
class) and it identifies unique attributes enumerated in the Partitions
such as which nTDSDSAs are cross referenced for replicas
c                 t    Xl         SU l        SU l        / U l        / U l        [
        R                  U S 5        g )NTr   )partstrrn  ro  rw_location_listro_location_listr(   r1   )r0   r  s     r   r1   Partition.__init__(  s8     " "
 	tT*r   c                 ^   / SQn UR                  U R                  [        R                  US9nUS   nUR                  5        GH  nUS:X  a  M  US	:X  aO  [        Xx   S   5      R                  5       R                  5       R                  5       S
:X  a  SU l        OSU l        Ma  US:X  a  [        Xx   S   5      U l        M~  Xx    H  n	[        XR!                  S5      5      n
[        U
R"                  5      nUS:X  a  Xl        M@  US:X  a  U R&                  R)                  U5        Mc  US:X  d  Mk  U R*                  R)                  U5        M     GM     U R-                  U5        g! [        R                   a1  nUR
                  u  pV[        SU R                  < SU< S35      eSnAff = f)aw  Given a Partition class object that has been initialized with its
partition dn string, load the partition from the sam database, identify
the type of the partition (schema, domain, etc) and record the list of
nTDSDSAs that appear in the cross reference attributes
msDS-NC-Replica-Locations and msDS-NC-RO-Replica-Locations.

:param samdb: sam database to load partition from
)nCNameEnabledr  msDS-NC-Replica-LocationsmsDS-NC-RO-Replica-LocationsrB   zUnable to find partition for (rF   r7   Nr   r   r  r(  TFr  r1  r  r  r  )rG   r  rH   rI   rJ   rK   r   r3  r9   r  r  r  rn  r)  ro  r   r4  r   r+   r  r   r  r]   )r0   rN   rE   rO   e15rQ   rR   rS   r$   r   r9  r:  s               r   load_partitionPartition.load_partition4  s   1
	1,,DLL%*  ,C !fADyI~svay>'')00299;vE#'DL#(DLM!$'q	N!ull6&:;DGG=$)M33))00766))007   B 	&M || 	188LT LL$0 1 1	1s   )E' 'F,;,F''F,c                     U R                   $ )z-Returns True if partition is enabled
        )r  rW   s    r   r  Partition.is_enabledn  s     r   c                 H    U R                   [        R                  -  S:X  a  gg)zsReturns True if this is not an Active Directory NC in our
forest but is instead something else (e.g. a foreign NC)
r   TF)ro  r   SYSTEM_FLAG_CR_NTDS_NCrW   s    r   
is_foreignPartition.is_foreigns  s#      ; ;;Ar   c                 H   SnSnU R                   [        R                  :H  =(       da    U R                   [        R                  :H  =(       d=    U R                   [        R                  :H  =(       a    U R
                  UR                  :H  nU R                   [        R                  :X  aN  UR                  5       (       a  UR                  U R                  ;   a  SnOUR                  U R                  ;   a  SnUR                  5       (       ap  U R                   [        R                  :X  aR  U R
                  UR                  :w  a8  UR                  U R                  ;   d  UR                  U R                  ;   a  SnSnU(       a  UR                  5       (       d  U(       a  SnXBU4$ )zTests whether this partition should have an NC replica
on the target dsa.  This method returns a tuple of
needed=True/False, ro=True/False, partial=True/False

:param target_dsa: should NC be present on target dsa
FT)r.   r   r   r   r   r+   r   r   r   rl   r  r  r   )r0   
target_dsar   partialneededs        r   should_be_presentPartition.should_be_present|  sF    
 ,,&--/ >,,&--/><<6==0 ===J$<$<< 	 <<6---!!''4+@+@@!F''4+@+@@!F
 LLFMM)MMZ555!!T%:%::!!T%:%::FG z''))WB7""r   c                     S[         R                  U 5      -  SU R                  -  -   SR                  S U R                   5       5      -   SR                  S U R
                   5       5      -   nU$ )r4   z%sz
	partdn=%sr   c              3   ,   #    U  H
  nS U-  v   M     g7f)z
	msDS-NC-Replica-Locations=%sNr   r#   r$   s     r   r&   $Partition.__str__.<locals>.<genexpr>  s     ]G\!9A=G\r   c              3   ,   #    U  H
  nS U-  v   M     g7f)z!
	msDS-NC-RO-Replica-Locations=%sNr   r  s     r   r&   r    s     `J_Q<q@J_r   )r(   r=   r  r   r  r  r;   s     r   r=   Partition.__str__  sm    m++D11-.ww]tG\G\]]^ ww`$J_J_``a r   )rn  r+   r  r  r  ro  N)r   r   r   r   rg   r1   r   r  r  r  r=   r   r   r   r   r  r  !  s'    
+8't
.#`r   r  c                   f    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rSrg)Sitei  zzAn individual site object discovered thru the configuration
naming context.  Contains all DSAs that exist within the site
c                 p    Xl         S U l        SU l        S U l        SU l        0 U l        0 U l        X l        g Nr   )
site_dnstr	site_guidsite_optionssite_topo_generatorsite_topo_failover	dsa_tablerw_dsa_tablent_now)r0   r  r  s      r   r1   Site.__init__  s:    $#' "#r   c                    SU R                   -  n/ SQn UR                  U[        R                  US9nUR                  U R                   [        R                  S/S9nUS	   n	S
U	;   a  [        U	S
   S	   5      U l        SU	;   a  [        U	S   S	   5      U l
        SU	;   a  [        U	S   S	   5      U l        US	   n	SU	;   a1  [        R                  " UR                  SU	S   S	   5      5      U l        U R!                  U5        g! [        R                   a'  nUR
                  u  px[        SU< SU< S35      eSnAff = f)zLoads the NTDS Site Settings options attribute for the site
as well as querying and loading all DSAs that appear within
the site.
CN=NTDS Site Settings,%s)r   interSiteTopologyFailoverinterSiteTopologyGeneratorrB   r@   z"Unable to find site settings for (rF   r7   Nr   r   r$  r#  )r  rG   rH   rI   rJ   rK   r   r)  r  r9   r  r  r   rL   rM   r  load_all_dsa)
r0   rN   ssdnrE   rO   self_rese16rQ   rR   rS   s
             r   	load_siteSite.load_site  sS   
 *DOO;/	),,D%*  ,C||+7. $ :H !f #C	N1$5 6D'3.C45a89 $ '#-&)#.I*J1*M&ND#qk3!YYu'@'@'*<'8';(= >DN 	% + || 	)88LT $( ) )	)s   A	D E "D;;E c                     UR                  U R                  [        R                  SS9nU Hx  n[        UR                  5      nXpR                  ;   a  M)  [        U5      nUR                  U5        XR                  U'   UR                  5       (       a  Mj  XR                  U'   Mz     g! [        R                   a!  nUR
                  u  pE[        SU-  5      eSnAff = f)zDiscover all nTDSDSA thru the sites entry and
instantiate and load the DSAs.  Each dsa is inserted
into the dsa_table by dn string.
z(objectClass=nTDSDSA))rD   rA  zUnable to find nTDSDSAs - (%s)N)rG   r  rH   rC  rJ   rK   r   r9   r   r  r   r-  r   r  )	r0   rN   rO   e17rQ   rR   rS   r:  rx   s	            r   r%  Site.load_all_dsa  s    
	D,,t%(%6%6*A  CC CKE &'.CLL %(NN5!99;;+.!!%( 	 || 	D88LT;dBCC	Ds   )B* *C>CCc                 8    U R                   R                  U5      $ )zReturn a previously loaded DSA object by consulting
the sites dsa_table for the provided DSA dn string

:return: None if DSA doesn't exist
)r  r  r|  s     r   get_dsaSite.get_dsa  s     ~~!!%((r   c                    UR                   (       a  SUl        UR                  U l        g[	        U5      nUR                  U5        UR                  U5        [        U R                  R                  5       S S9nU R                  S:X  a  SnOU R                  S-  S-  nU R                  R                  U R                  5      nUb  XrLa  UR                  U5      nS	n	UR                   H!  n
UR                  U
R                   :X  d  M  Sn	  O   U	(       d  UnSnONU R"                  W
R$                  -
  U:  a  SnSnO,UnU
R$                  nOUR                  U5      nU R"                  nXR"                  U-
  U-  -   ['        U5      -  nX]   nSUl        XrLa  g	U R                  UR                  :X  a  gUR                  U l        U(       a  gS
U R(                  -  n[*        R,                  " 5       n[*        R.                  " X5      Ul        [*        R2                  " UR                  [*        R4                  S5      US'    UR7                  U5        g! [*        R8                   a  n[;        SU< SU< S35      eSnAff = f)a<  Determine if my DC should be an intersite topology
generator.  If my DC is the istg and is both a writeable
DC and the database is opened in write mode then we perform
an originating update to set the interSiteTopologyGenerator
attribute in the NTDS Site Settings object.  An RODC always
acts as an ISTG for itself.
Tc                 ,    [        U R                  5      $ r   )r	   rn   )rx   s    r   <lambda>"Site.select_istg.<locals>.<lambda>5  s    HS\\2r   )keyr   l    PC <   i NFr"  r$  z.Could not set interSiteTopologyGenerator for (rF   r7   )r   r   rl   r  get_dsa_config_repr   r   sortedr  rW  r  r  r  indexr   r   source_dsa_invocation_idr  last_sync_successr2  r  rH   r   r   r   r   r   r   rJ   r   )r0   rN   mydsar   c_repD_sortfd_dsaj_idxr  cursori_idxt_timek_idxr&  r   rR   s                    r   select_istgSite.select_istg  sY    ?? $E',D$"5)
 	E"%%e,  $$&24$ ""a'&A''",x7A ""4#;#;< !3( LL'EE>>>>V%D%DD E ?
 
 v777!;11 LL'E[[F ;;/A56#f+E    ##u6#(??   *DOO;KKMvve" u0D0D;= 	

&'	LLO 	 || 	t 	s   I J 'I;;J c                 B    U R                   [        R                  -  S:g  $ )z8Returns True if intra-site topology is disabled for siter   )r  r   -DS_NTDSSETTINGS_OPT_IS_AUTO_TOPOLOGY_DISABLEDrW   s    r   is_intrasite_topology_disabled#Site.is_intrasite_topology_disabled  s)    !!BBCGHI 	Ir   c                 B    U R                   [        R                  -  S:g  $ )z8Returns True if inter-site topology is disabled for siter   )r  r   8DS_NTDSSETTINGS_OPT_IS_INTER_SITE_AUTO_TOPOLOGY_DISABLEDrW   s    r   is_intersite_topology_disabled#Site.is_intersite_topology_disabled  s'    ""NNO 	r   c                 B    U R                   [        R                  -  S:g  $ )z:Returns True if selection of random bridgehead is disabledr   )r  r   1DS_NTDSSETTINGS_OPT_IS_RAND_BH_SELECTION_DISABLEDrW   s    r   is_random_bridgehead_disabled"Site.is_random_bridgehead_disabled  )    !!FFGKLM 	Mr   c                 B    U R                   [        R                  -  S:g  $ )z1Returns True if detect stale is disabled for siter   )r  r   1DS_NTDSSETTINGS_OPT_IS_TOPL_DETECT_STALE_DISABLEDrW   s    r   is_detect_stale_disabledSite.is_detect_stale_disabled  rT  r   c                 B    U R                   [        R                  -  S:g  $ )z<Returns True if NTDS Connection cleanup is disabled for siter   )r  r   ,DS_NTDSSETTINGS_OPT_IS_TOPL_CLEANUP_DISABLEDrW   s    r   is_cleanup_ntdsconn_disabled!Site.is_cleanup_ntdsconn_disabled  s)    !!AABFGH 	Hr   c                 F    U R                  UR                  5      (       a  gg)z"Return True if dsa is in this siteTF)r/  rl   )r0   rx   s     r   	same_siteSite.same_site  s    <<&&r   c                 j    [        U R                  5      S:  a  [        U R                  5      S:X  a  gg)Nr   TF)r2  r  r  rW   s    r   is_rodc_siteSite.is_rodc_site  s+    t~~"s4+<+<'='Br   c                    SU R                   R                  -  SU R                  -  -   SU R                  -  -   SU R                  -  -   SU R
                  -  -   nU R                  R                  5        H  u  p#USU-  -   nM     U$ )r4   r{   z
	dn=%sz
	options=0x%Xz
	topo_generator=%sz
	topo_failover=%dr   )r8   r   r  r  r  r  r  rJ  )r0   r<   r5  rx   s       r   r=   Site.__str__  s    t~~...T__,-!D$5$556 ')A)AAB &(?(??	@
 ,,.HC&3,&D /r   )r  r  r  r  r  r  r  r  N)r   r   r   r   rg   r1   r)  r%  r/  rF  rJ  rN  rR  rW  r[  r^  ra  r=   r   r   r   r   r  r    sO    #!J/<)gRI
M
M
H

	r   r  c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)	GraphNodei  zA graph node describing a set of edges that should be directed to it.

Each edge is a connection for a particular naming context replica directed
from another node in the forest to this node.
c                 *    X l         Xl        / U l        g)zInstantiate the graph node according to a DSA dn string

:param max_node_edges: maximum number of edges that should ever
    be directed to the node
N)	max_edgesrl   	edge_from)r0   rl   max_node_edgess      r   r1   GraphNode.__init__  s     ("r   c                     SU R                   R                  -  SU R                  -  -   SU R                  -  -   n[	        U R
                  5       H%  u  p#[        U[        5      (       d  M  USX#4-  -  nM'     U$ )Nr{   r|   z
	max_edges=%dz
	edge_from[%d]=%s)r8   r   rl   rh  r  ri  
isinstancer9   )r0   r<   r  edges       r   r=   GraphNode.__str__  su    t~~...!DNN23!DNN23 !0GA$$$.!:: 1 r   c                     [        U[        5      (       d   eXR                  :X  a  gXR                  ;   a  g[	        U R                  5      U R
                  :  a  gU R                  R                  U5        g)zwAdd an edge from the dsa to our graph nodes edge from list

:param from_dsa_dnstr: the dsa that the edge emanates from
FT)rm  r9   rl   ri  r2  rh  r   )r0   from_dsa_dnstrs     r   add_edge_fromGraphNode.add_edge_from  s`    
 .#.... ^^+^^+t~~$..0n-r   c                 |    UR                   R                  5        H  nU R                  UR                  5        M      g)a5  For each nTDSConnection object associated with a particular
DSA, we test if it implies an edge to this graph node (i.e.
the "fromServer" attribute).  If it does then we add an
edge from the server unless we are over the max edges for this
graph node

:param dsa: dsa with a dnstr equivalent to his graph node
N)r   rW  rr  rY  )r0   rx   rG  s      r   add_edges_from_connections$GraphNode.add_edges_from_connections  s1     ((//1Gw112 2r   c                 .   U R                    H  nUR                  U5      nSnU H  nUR                  5       (       a  M  SnM     U(       a  MA  [        R                  n[        R
                  [        R                  -  nUR                  XxX#S5        M     g)zmFor each edge directed to this graph node, ensure there
is a corresponding nTDSConnection object in the dsa.
FTN)ri  r[  r  r   r  SYSTEM_FLAG_CONFIG_ALLOW_RENAMESYSTEM_FLAG_CONFIG_ALLOW_MOVErw  )	r0   rx   ru  
edge_dnstrconnectionsfound_validrG  optr   s	            r   add_connections_from_edges$GraphNode.add_connections_from_edges#  s     ..J:::FK  K&++--" '
  00C99778E s9$GC )r   c                 L    [        U R                  5      U R                  :  a  gg)z<Return True if we have met the maximum "from edges" criteriaTF)r2  ri  rh  rW   s    r   has_sufficient_edgesGraphNode.has_sufficient_edgesJ  s    t~~$..0r   )rl   ri  rh  N)r   r   r   r   rg   r1   r=   rr  ru  r~  r  r   r   r   r   rf  rf    s'    	&
3%HNr   rf  c                   *    \ rS rSrSrS rS rS rSrg)	TransportiQ  z;Class defines a Inter-site transport found under Sites
    c                 V    Xl         SU l        S U l        S U l        S U l        / U l        g r  )r:  r   rq  nameaddress_attrbridgehead_listr|  s     r   r1   Transport.__init__U  s,    
		 !r   c                 ,   U R                   R                  < SU R                  < 3S[        U R                  5      -  -   SU R
                  -  -   SU R                  -  -   SU R                  -  -   SR                  S U R                   5       5      -   nU$ ),Debug dump string output of Transport objectr  r  
	options=%dz
	address_attr=%sz	
	name=%sr   c              3   ,   #    U  H
  nS U-  v   M     g7f)z
	bridgehead_list=%sNr   )r#   r:  s     r   r&   $Transport.__str__.<locals>.<genexpr>e  s     ZEYE/%7EYr   )
r8   r   r:  r9   rq  r   r  r  r   r  r;   s     r   r=   Transport.__str__]  s     "&!8!8$**Es499~-.$,,./ %t'8'889 tyy(	)
 wwZTEYEYZZ[ r   c                    / SQn UR                  U R                  [        R                  US9nUS   n[        R                  " UR                  SUS   S   5      5      U l
        S	U;   a  [        US	   S   5      U l        S
U;   a  [        US
   S   5      U l        SU;   a  [        US   S   5      U l        SU;   ah  US    H^  n[!        XR#                  S5      5      n	[        U	R$                  5      n
XR&                  ;  d  MC  U R&                  R)                  U
5        M`     gg! [        R                   a1  nUR
                  u  pV[        SU R                  < SU< S35      eSnAff = f)zGiven a Transport object with an prior initialization
for the object's DN, search for the DN and load attributes
from the samdb.
)r@   r   r  bridgeheadServerListBLtransportAddressAttributerB   zUnable to find Transport for (rF   r7   Nr   r@   r   r  r  r  r1  )rG   r:  rH   rI   rJ   rK   r   r   rL   rM   rq  r)  r   r9   r  r  r   r4  r   r  r   )r0   rN   rE   rO   e18rQ   rR   rS   r   r9  r:  s              r   load_transportTransport.load_transporti  sZ   
.
	/,,DJJcnn%*  ,C !fIIe77!,/24 5	 s9~a01DL&#- #C(C$DQ$G HDS=CKN+DI#s*56ull6&:;DGG 4 44((//6	 7 +% || 	/88LT JJ. / /	/s   )D( (E-<,E((E-)r  r  r:  rq  r  r   N)	r   r   r   r   rg   r1   r=   r  r   r   r   r   r  r  Q  s    "
%7r   r  c                   @    \ rS rSrSrSS jrS rS rS rS r	S	 r
S
rg)r   i  zClass encapsulation of the NDR repsFromToBlob.

Removes the necessity of external code having to
understand about other_info or manipulation of
update flags.
Nc                 <   SU R                   S'   XR                   S'   SU R                   S'   Uc  [        R                  " 5       U R                   S'   SU R                   S   l        S U R                   S'   S U R                   S	'   [        R                  " 5       =U R                   S   R
                  l        U R                   S
'   g X R                   S'   UR
                  R                  U R                   S
'   UR                  S:X  a=  UR
                  R                  R                  U R                   S'   S U R                   S	'   g UR
                  R                  R                  U R                   S'   UR
                  R                  R                  U R                   S	'   g )NFr   r+   r   update_flagsr      	dns_name1	dns_name2
other_info)
__dict__r   r   r   repsFromTo1OtherInfor   r  dns_namer  r  )r0   r+   r   s      r   r1   RepsFromTo.__init__  sF   ).o&$,j!(+n%8 (0(?(?(ADMM*%03DMM*%-)-DMM+&)-DMM+& /7.K.K.MNDMM*%))4l+ )1MM*%*2,,*A*ADMM,'3&-5\\-D-D-M-Mk*-1k*-5\\-D-D-N-Nk*-5\\-D-D-N-Nk*r   c                 
   SU R                   R                  -  SU R                  -  -   SU R                  -  -   SU R                  -  -   SU R
                  -  -   SU R                  -  -   SU R                  -  -   SU R                  -  -   S	U R                  -  -   S
U R                  -  -   SU R                  -  -   SU R                  -  -   SU R                  -  -   S-   SR                  S U R                   5       5      -   S-   nU$ )r4   r{   z

	dnstr=%sz
	update_flags=0x%Xz
	version=%dz
	source_dsa_obj_guid=%sz
	source_dsa_invocation_id=%sr  z
	replica_flags=0x%Xz
	consecutive_sync_failures=%dz
	last_success=%sz
	last_attempt=%sz
	dns_name1=%sz
	dns_name2=%sz
	schedule[ r   c              3   ,   #    U  H
  nS U-  v   M     g7fr  r   r  s     r   r&   %RepsFromTo.__str__.<locals>.<genexpr>  s     @-$w~-r   r  )r8   r   r+   r  r   source_dsa_obj_guidr:  rr  replica_flagsconsecutive_sync_failureslast_successlast_attemptr  r  r   rs  r;   s     r   r=   RepsFromTo.__str__  sH    t~~...-.&):)::;  $,,./ ,d.F.FF	G
 2../0 ')<)<<= ($*<*<<= 3//0
1 %t'8'889 %t'8'889 "DNN23 "DNN23     ww@$--@@!A" #& r   c                    US;   a|  US;   a&  U R                   S==   [        R                  -  ss'   O+US;   a%  U R                   S==   [        R                  -  ss'   [	        U R                   S   R
                  X5        GO[US;   a  X R                   S'   U R                   S   R                  S:X  a6  U R                   S   U R                   S   R
                  R                  l        OU R                   S   U R                   S   R
                  R                  l	        OUS	;   al  X R                   S
'   U R                   S   R                  S:X  a  [        U5      eU R                   S
   U R                   S   R
                  R                  l        OLUS;   a  X R                   S'   O7US;   a  X R                   S'   O"US;   a  [        SU-  5      e[        SU-  5      eU R                   S==   [        R                  -  ss'   g)zSet an attribute and change update flag.

Be aware that setting any RepsFromTo attribute will set the
drsuapi.DRSUAPI_DRS_UPDATE_ADDRESS update flag.
rs  r  rr  r  r:  r  r  r  )r  r  )rs  r   r  r  r  r  r  r+   r+   r   r   r   z$Attempt to set readonly attribute %sUnknown attribute %sN)r  r   DRSUAPI_DRS_UPDATE_FLAGSDRSUAPI_DRS_UPDATE_SCHEDULEsetattrr   r   r  r  r  r   r  DRSUAPI_DRS_UPDATE_ADDRESS)r0   itemr   s      r   __setattr__RepsFromTo.__setattr__  s     $ $
 ((n-1Q1QQ-%n-1T1TT-DMM*-114?]").MM+&}}Z(00C7MM+. j)--88A MM+. j)--88B ]").MM+&}}Z(00C7$T** MM+. j)--88B \!(-MM*%&&-2MM/*[  !G$!NOO !7$!>??n%)K)KK%r   c                    US;   a#  [        U R                  S   R                  U5      $ US;   a  U R                  S   R                  $ US;   aw  U R                  S   R                  S:X  a-  U R                  S   R                  R                  R
                  $ U R                  S   R                  R                  R                  $ US;   aU  U R                  S   R                  S:X  a  [        U5      eU R                  S   R                  R                  R                  $ US;   a  U R                  S   $ US	;   a  U R                  S
   $ US;   a  U R                  S   $ [        SU-  5      e)zjOverload of RepsFromTo attribute retrieval.

Allows external code to ignore substructures within the blob
r  r   r  r  r  r  r  r   r  r+   r  r  r  )	getattrr  r   r   r  r  r  r   r  )r0   r  s     r   __getattr__RepsFromTo.__getattr__  sP   
  $ $ 4==488$??[ ==,444]"}}Z(00C7}}Z044??HHH}}Z044??III]"}}Z(00C7$T**}}Z044??III&&==11\!==,,%%==003d:;;r   c                      U R                   S:g  $ r  r  rW   s    r   r   RepsFromTo.is_modified;  s    !!S()r   c                 "    SU R                   S'   g )Nr   r  )r  rW   s    r   r   RepsFromTo.set_unmodified>  s    (+n%r   r   )NN)r   r   r   r   rg   r1   r=   r  r  r   r   r   r   r   r   r   r     s*    2Oh00Ld#<J*,r   r   c                   *    \ rS rSrSrS rS rS rSrg)SiteLinkiB  z0Class defines a site link found under sites
    c                 d    Xl         SU l        SU l        SU l        S U l        S U l        / U l        g r  )r:  r   ro  costrs  interval	site_listr|  s     r   r1   SiteLink.__init__F  s2    
	r   c                    U R                   R                  < SU R                  < 3SU R                  -  -   SU R                  -  -   SU R
                  -  -   SU R                  -  -   nU R                  b  USU R                  R                  -  SU R                  R                  -  -   SU R                  R                  -  -   -  n[        U R                  R                  5       Hl  u  p#US	X#R                  4-  S
X#R                  4-  -   SU-  -   SR                  S U R                  R                   U   R"                   5       5      -   S-   -  nMn     U R$                   H  u  pEUSU< SU< S3-   nM     U$ )r  r  r  z
	system_flags=%dz	
	cost=%dz
	interval=%sr  r  r  r  r  r  r   c              3   ,   #    U  H
  nS U-  v   M     g7fr  r   r  s     r   r&   #SiteLink.__str__.<locals>.<genexpr>d  r  r   r  z
	site_list=r6   r7   )r8   r   r:  r   ro  r  r  rs  r  r  r  r  r  r  r  r   r  r  r  )r0   r<   r  r  rq  r   s         r   r=   SiteLink.__str__O  s    "&!8!8$**E$,,./$t'8'889 tyy() !4==0	1 ==$*T]]-?-??/$--2I2IIJ8]]4456 6D
 't}}'@'@A	?[[)*A]]+,- =q@	A
 \4==;R;RST;U;[;[\\]   B HDT2>>D 'r   c                    / SQn UR                  U R                  [        R                  US/S9nUS   nS	U;   a  [        US	   S   5      U l        S
U;   a  [        US
   S   5      U l	        SU;   a  [        US   S   5      U l
        SU;   a  [        US   S   5      U l        SU;   a  US    H  n[        XR                  S5      5      n	[        R                  " U	R                   R#                  S5      5      n
[%        U	R                   5      nX4U R&                  ;  d  Mt  U R&                  R)                  X45        M     SU;   a   [+        [,        R.                  W5      U l        g[1        5       U l        g! [        R                   a1  nUR
                  u  pV[        SU R                  < SU< S35      eSnAff = f)zGiven a siteLink object with an prior initialization
for the object's DN, search for the DN and load attributes
from the samdb.
)r   r  r  rs  replIntervalsiteListzextended_dn:0)rC   rD   rE   controlszUnable to find SiteLink for (rF   r7   Nr   r   r  r  r  r  r1  rL   rs  )rG   r:  rH   rI   rJ   rK   r   r)  r   ro  r  r  r   r4  r   rL   r   get_extended_componentr9   r  r   r   r   rs  rt  )r0   rN   rE   rO   e19rQ   rR   rS   r   r9  rq  r:  s               r   load_sitelinkSiteLink.load_sitelinkk  s   
	/,,DJJcnn%*o5F  HC !fs9~a01DLC #C$6q$9 :DS=CKN+DIS N 3A 67DMZull6&:;yy!?!?!GHDGG=6NN))4-8 ) &x'8'8%@DM35DM= || 	/88LT JJ. / /	/s   +E; ;G ,F;;G )r  r:  r  r   rs  r  ro  N)	r   r   r   r   rg   r1   r=   r  r   r   r   r   r  r  B  s    8-6r   r  c                       \ rS rSrS rSrg)KCCFailedObjecti  c                 @    Xl         X l        X0l        X@l        XPl        g r   )rl  failure_counttime_first_failurelast_resultr  )r0   rl  r  r  r  r  s         r   r1   KCCFailedObject.__init__  s    	*"4& r   )r  r  r  r  rl  N)r   r   r   r   r1   r   r   r   r   r  r    s    !r   r  c                     U R                   R                  5        H  nUR                  5       (       d  M  Us  $    [        SU R                  -  5      e)Nz)Unable to find config NC replica for (%s))r   rW  rX   r   rl   )rx   r=  s     r   r7  r7    sK    &&--/??L 0 >==! " "r   c                      [         R                  " 5       n SU l        SU l        SU l        [         R
                  " 5       nSUl        SUl        U/U l        [         R                  " 5       nS/S-  Ul
        U/U l        U $ )zCreate a default schedule for an NTDSConnection or Sitelink. This
is packed differently from the repltimes schedule used elsewhere
in KCC (where the 168 nibbles are packed into 84 bytes).
   r   r        )r   rs  r  r  r  scheduleHeaderr  r  r  scheduleSlotsr  r  )rs  r  datas      r   rt  rt    sy       "HHMH!"H$$&FFKFM"8H!!#D#DJHOr   c           
         / nU R                  U R                  5       [        R                  SS9nU R                  U R                  5       [        R                  SS9n[	        5       nSnU H|  nUR
                  R                  5       R                  5       nXXR                  5       ==   S-  ss'   UR                  5       R                  5       UR                  5       :X  d  Mw  US-  nM~     [        U5      [        U5      :w  Gah  / n	U H4  nUR
                  R                  5       U;  d  M#  U	R                  U5        M6     SR                  [        R                  " U5      [        R                  " [        U R                  5       5      5      5      n
U	 GH  n[        R                  " [        UR
                  5      5      nU R                  U R                  5       [        R                  S/SR                  U5      S	/S
9nU R                  U R                  5       [        R                  SS/SR                  U
U5      S	/S
9n[        U5      S:  d  M  [        U5      S:  d  M  [        US   S   S   5      n[        US   S   S   5      nUU:w  a  GM  SnUS   S    H  n[        R                   " U [        U5      5      nUR                  5       nUR                  5       R                  5       nUU   U:  a  Sn  O'UU   U:X  d  Mi  UUR                  5       :  d  M  Sn  O   U(       d  GM  UR
                  R                  5       nUR                  UR                  5       5        GM     U$ )a  
Discover which sites have no DCs and whose lowest single-hop cost
distance for any link attached to that site is linked to the site supplied.

We compare the lowest cost of your single-hop link to this site to all of
those available (if it exists). This means that a lower ranked siteLink
with only the uncovered site can trump any available links (but this can
only be done with specific, poorly enacted user configuration).

If the site is connected to more than one other site with the same
siteLink, only the largest site (failing that sorted alphabetically)
creates the DNS records.

:param samdb database
:param site_name origin site (with a DC)

:return a list of sites this site should be covering (for DNS)
z*(&(objectClass=server)(serverReference=*))r@  z(objectClass=site)r   r  zCN={},CN=Sites,{}r  z&(&(objectClass=siteLink)(siteList={}))zserver_sort:1:0:cost)rC   rD   rE   rA  r  r  z3(&(objectClass=siteLink)(siteList={})(siteList={}))TF)rG   r\   rH   rC  r
   r   parentcanonical_strget_rdn_valuelowerr2  r   formatbinary_encoder9   r)  r   )rN   	site_namesites_to_cover
server_ressite_ressites_in_usedc_countrS   site_dnsites_uncoveredown_site_dnsite
encoded_dn	link_res1	link_res2cost1cost2to_coversite_valsite_dn_strsite_rdnsite_cover_rdns                         r   uncovered_sites_to_coverr    s)   & N5#:#:#<$'$5$5*5  6J
 ||!8!8!:"%"3"3';  =H 9LH &&--/((***,-2-  "((*ioo.??MH  <CM)Cvv##%\9&&s+  *00i(c%"9"9";<=

 $D**3tww<8J %*A*A*C+.+<+<VH166<fZ6H/E.F	 % HI %*A*A*C+.+<+<,2J+?1CCI6)4)3D5 0F.F % HI 9~!c)nq&8IaL034IaL034 E>
   )!Z 8H!ffUCM:G")"7"7"9K&446<<>H#K08;#(&{3x?"Y__%66#( !9 8%)WW%:%:%<N")).*>*>*@Aa $d r   )&r   rH   rl  sambar   samba.dcerpcr   r   r   samba.samdbr   	samba.ndrr   r	   collectionsr
   	Exceptionr   objectr   dictr  rJ  r:   r(   ri   r   rD  r  r  rf  r  r   r  r  r7  rt  r  r   r   r   <module>r     s  ,  
   
   * 	y 	AV A
 NV__%:%:%<NN
n+F n+b|2 |2~[F [|
_V _DQ Qhp6 pf	f fR=7 =7@n, n,bV6v V6r!f !"Bhr   