
    bW                    <   d dl Z d dlZd dlZd dlmZ d dlmZmZmZ d dl	m
Z
 d dlmZmZ d dlmZ  G d de          Z G d	 d
e          Z ed ej                                        D                       Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z  G d de          Z! G d  d!e          Z"d" Z#d# Z$d$ Z%dS )%    N)dsdb)drsblobsdrsuapimisc)dsdb_Dn)
ndr_unpackndr_pack)Counterc                       e Zd ZdS )KCCErrorN)__name__
__module____qualname__     5/usr/lib/python3/dist-packages/samba/kcc/kcc_utils.pyr   r   %   s        Dr   r   c                   2    e Zd Z edd          \  ZZZZZdS )NCTyper      N)	r   r   r   rangeunknownschemadomainconfigapplicationr   r   r   r   r   )   s(        5:U1a[[2Wfffkkkr   r   c              #   @   K   | ]\  }}|d d         dk    ||fV  d S )N   __r   ).0kvs      r   	<genexpr>r"   .   s6      NNTQ"1"1a&NNr   c                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	NamingContextzBase 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                 R    || _         d| _        d| _        t          j        | _        dS )zKInstantiate a NamingContext

        :param nc_dnstr: NC dn string
        N)nc_dnstrnc_guidnc_sidr   r   nc_typeselfr&   s     r   __init__zNamingContext.__init__8   s&    
 !~r   c                     | j         j        dd| j        z  z   dt          | j                  z  z   }| j        |dz   }n|dz   }|dt          | j                 d| j        d	z   }|S )
!Debug dump string output of class:z
	nc_dnstr=%sz
	nc_guid=%sNz
	nc_sid=<absent>z
	nc_sid=<present>z

	nc_type= ())	__class__r   r&   strr'   r(   
nctype_lutr)   r+   texts     r   __str__zNamingContext.__str__B   s    ///1 4=01#dl"3"334 ;//DD00Dtz$,/G/G/G/3|||= =r   c                    ddg}	 |                     | j        t          j        |          }n<# t          j        $ r*}|j        \  }}t          d| j        d|d          d }~ww xY w|d         }d|v r9t          j        |	                    d|d         d                             | _
        d|v r|d         d         | _        | j
        J d S )N
objectGUID	objectSidbasescopeattrszUnable to find naming context () - (r1   r   )searchr&   ldb
SCOPE_BASELdbErrorargsr   r   GUIDschema_format_valuer'   r(   )r+   samdbr>   reseenumestrmsgs           r   load_nczNamingContext.load_ncQ   s   	2,,DM%(^5  B BCC | 	2 	2 	26LT4( MMM4441 2 2 2	2 !f39U%>%>|%(%6q%9&; &; < <DL#k*1-DK|'''''   '. A'%A""A'c                 Z    | j         t          j        k    sJ | j         t          j        k    S )zReturn True if NC is config)r)   r   r   r   r+   s    r   	is_configzNamingContext.is_confige   s&    |v~----|v},,r   c                    | j         |                     |           | j        t          |                                          k    rt
          j        | _        dS | j        t          |                                          k    rt
          j	        | _        dS | j
        t
          j        | _        dS t
          j        | _        dS )zoGiven an NC object, identify what type is is thru
           the samdb basedn strings and NC sid value
        N)r'   rM   r&   r3   get_schema_basednr   r   r)   get_config_basednr   r(   r   r   )r+   rG   s     r   identify_by_basednz NamingContext.identify_by_basednj   s     <LL =C 7 7 9 9::::!=DLLL]c%"9"9";";<<<<!=DLLL[$!=DLLL!-DLLLr   c                     |dk    rt           j        | _        n3|dk    rt           j        | _        n|dk    r|                     |           | j        t           j        k    r|                     |           dS dS )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)   rU   r   r+   rG   attrs      r   identify_by_dsa_attrz"NamingContext.identify_by_dsa_attr   s     &&&!=DLL +++!=DLL ^####E*** <6>))##E***** *)r   N)
r   r   r   __doc__r,   r7   rM   rQ   rU   r\   r   r   r   r$   r$   1   sx         & & &  ( ( ((- - -
. . ..+ + + + +r   r$   c                   ~    e Zd ZdZd Zd ZddZd Zd Zd Z	d	 Z
d
 Zd ZddZd Zd Zd Zd Zd Zd ZddZdS )	NCReplicazNaming 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                     |j         | _        |j        | _        d| _        d| _        d| _        d| _        d| _        g | _	        g | _
        d| _        t                              | |           dS )zInstantiate 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$   r,   )r+   dsar&   s      r   r,   zNCReplica.__init__   sz     !]L  &'##'    ).% 	tX.....r   c                    d| j         j        z  d| j        z  z   d| j        z  z   d| j        z  z   d| j        z  z   d| j        z  z   d|                                 z  z   d| j        z  z   d		                    d
 | j
        D                       z   d		                    d | j        D                       z   }t                              |           d|S )r.   %s:
	dsa_dnstr=%s
	dsa_guid=%sz
	default=%s
	ro=%sz
	partial=%sz
	present=%sz
	fsmo_role_owner=%s c              3       K   | ]	}d |z  V  
dS 
%sNr   r   reps     r   r"   z$NCReplica.__str__.<locals>.<genexpr>   s&      AAv|AAAAAAr   c              3       K   | ]	}d |z  V  
dS ru   r   rw   s     r   r"   z$NCReplica.__str__.<locals>.<genexpr>   s&      ??v|??????r   
)r2   r   rb   rd   re   rg   rf   
is_presentri   joinrj   rk   r$   r7   r5   s     r   r7   zNCReplica.__str__   s   t~..!D$667 4#445  $"223 T[(	)
  $"223  $//"3"334 ($*BBC wwAAt/@AAAAAB ww??t?????	@ )006666==r   r   c                     || _         dS )z*Set or clear NC replica instantiated flagsN)rh   )r+   flagss     r   set_instantiated_flagsz NCReplica.set_instantiated_flags   s    &+###r   c                    |dk    rd| _         d| _        n|dk    rd| _        n|dk    rcd| _        | j        t	          |                                          k    r1| j        t	          |                                          k    rd| _        n)|dk    rd| _        d| _        n|dk    rd| _        d| _        t          	                    | ||           dS )	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
        rX   TrW   rY   msDS-hasFullReplicaNCsmsDS-hasMasterNCsFN)
rf   rl   re   r&   r3   rS   rT   rg   r$   r\   rZ   s      r   r\   zNCReplica.identify_by_dsa_attr   s     )))#D,0D))
 (((#D ^##,0D)}E$;$;$=$= > >>>}E$;$;$=$= > >>>#'  ---,0D)DKK (((,0D)DK
 	**4=====r   c                     | j         S )zMWhether this is a default domain for the dsa that this NC appears on
        )re   rP   s    r   
is_defaultzNCReplica.is_default  s     r   c                     | j         S )z&Return True if NC replica is read only)rg   rP   s    r   is_rozNCReplica.is_ro  s
    {r   c                     | j         S )z$Return True if NC replica is partial)rf   rP   s    r   
is_partialzNCReplica.is_partial  s    r   c                 H    | j         r| j        t          j        z  dk    rdS dS )a7  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)rl   rh   r   INSTANCE_TYPE_NC_GOINGrP   s    r   r{   zNCReplica.is_present  s/     ( 	&)DDII4ur   c                    	 |                     | j        t          j        dg          }n<# t          j        $ r*}|j        \  }}t          d| j        d|d          d}~ww xY w|d         }d|v r|d         D ]}	 t          t          j	        |          }n5# t          $ r(}	t          d|z  t          j        	           Y d}	~	Kd}	~	ww xY wt          | j        |          }
| j                            |
           dS dS )
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
        repsFromr;   Unable to find NC for (r?   r1   Nr   zbad repsFrom NDR: %rfile)r@   r&   rA   rB   rC   rD   r   r   r   repsFromToBlobRuntimeErrorprintsysstderr
RepsFromTorj   append)r+   rG   rH   e1rJ   rK   rL   valueunpackedrI   rx   s              r   load_repsFromzNCReplica.load_repsFrom%  sU   	2,,DM&0\  3 3CC | 	2 	2 	27LT4( MMM4441 2 2 2	2
 !f Z . .)(*A5IIHH#   0E:"z+ + + +HHHH !99!((---- . .,   (+ A$%AA$>B
C#CCFc                    d}g }g }| j         D ]r}|j        r|                    |           d}!|                                r|                                 d}|                    t          |j                             s|D ]}| j                             |           g }|r|rdS t          j	                    }t          j
        || j                  |_        t          j        |t          j        d          |d<   	 |                    |           dS # t          j        $ r }t#          d| j        d|d          d}~ww xY w)zCommit repsFrom to the databaseFTNr   zCould not set repsFrom for (r?   r1   )rj   to_be_deletedr   is_modifiedset_unmodifiedr	   ndr_blobremoverA   MessageDnr&   dnMessageElementFLAG_MOD_REPLACEmodifyrC   r   )	r+   rG   ror   newrepsdelrepsr   mrK   s	            r   commit_repsFromzNCReplica.commit_repsFromB  s    ) 	8 	8H % x(((##%% ''))) NN8H$5667777   	/ 	/H$$X....  	 	FKMMveT]++ w(<jII 	
*	2LLOOOOO| 	2 	2 	2( MMM4441 2 2 2	2   >D E$D??Ec                    	 |                     | j        t          j        dg          }n<# t          j        $ r*}|j        \  }}t          d| j        d|d          d}~ww xY w|d         }d|v r]|d         d         }t          t          j	        |          }|j
        dk    rt          d	|j
        z            |j        j        | _        dS g | _        dS )
aF  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

        replUpToDateVectorr;   r   r?   r1   Nr   r   z(Unexpected replUpToDateVector version %d)r@   r&   rA   rB   rC   rD   r   r   r   replUpToDateVectorBlobversionAttributeErrorctrcursorsrep_replUpToDateVector_cursors)	r+   rG   rH   e2rJ   rK   rL   r   blobs	            r   load_replUpToDateVectorz!NCReplica.load_replUpToDateVector  s   	2,,DM&:%;  = =CC | 	2 	2 	27LT4( MMM4441 2 2 2	2
 !f  3&&,-a0Eh=#% %D|q  $%O'+|&4 5 5 5 37(2BD///24D///   (+ A$%AA$c                 J    d                     d | j        D                       S )Nrz   c              3   B   K   | ]}|j         	t          |          V  d S N)r   r3   r   xs     r   r"   z2NCReplica.dumpstr_to_be_deleted.<locals>.<genexpr>  s/      NNAaoNQNNNNNNr   r|   rj   rP   s    r   dumpstr_to_be_deletedzNCReplica.dumpstr_to_be_deleted  &    yyNN):NNNNNNr   c                 J    d                     d | j        D                       S )Nrz   c              3   \   K   | ]'}|                                 t          |          V  (d S r   )r   r3   r   s     r   r"   z3NCReplica.dumpstr_to_be_modified.<locals>.<genexpr>  s5      NNAammooNQNNNNNNr   r   rP   s    r   dumpstr_to_be_modifiedz NCReplica.dumpstr_to_be_modified  r   r   c                    	 |                     | j        t          j        dg          }n<# t          j        $ r*}|j        \  }}t          d| j        d|d          d}~ww xY w|d         }d|v r|d         | _        dS dS )zGiven an NC replica which has been discovered thru the nTDSDSA
        database object, load the fSMORoleOwner attribute.
        fSMORoleOwnerr;   r   r?   r1   Nr   )r@   r&   rA   rB   rC   rD   r   ri   )r+   rG   rH   e3rJ   rK   rL   s          r   load_fsmo_roleszNCReplica.load_fsmo_roles  s    	2,,DM&5%6  8 8CC | 	2 	2 	27LT4( MMM4441 2 2 2	2
 !f c!!'*?';D$$$ "!r   c                 .    | j         | j         |k    rdS dS )NTF)ri   r+   ra   s     r   is_fsmo_role_ownerzNCReplica.is_fsmo_role_owner  s#    #/#y004ur   c                    	 |                     | j        t          j        dg          }n<# t          j        $ r*}|j        \  }}t          d| j        d|d          d}~ww xY w|d         }d|v r|d         D ]}	 t          t          j	        |          }n5# t          $ r(}	t          d|z  t          j        	           Y d}	~	Kd}	~	ww xY wt          | j        |          }
| j                            |
           dS dS )
a  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.
        repsTor;   r   r?   r1   Nr   zbad repsTo NDR: %rr   )r@   r&   rA   rB   rC   rD   r   r   r   r   r   r   r   r   r   rk   r   )r+   rG   rH   e4rJ   rK   rL   r   r   rI   rx   s              r   load_repsTozNCReplica.load_repsTo  sQ   	2,,DM&.Z  1 1CC | 	2 	2 	27LT4( MMM4441 2 2 2	2
 !f s??X , ,)(*A5IIHH#   .%8"z+ + + +HHHH !99&&s++++ ?, ,r   c                    d}g }g }| j         D ]r}|j        r|                    |           d}!|                                r|                                 d}|                    t          |j                             s|D ]}| j                             |           g }|r|rdS t          j	                    }t          j
        || j                  |_        t          j        |t          j        d          |d<   	 |                    |           dS # t          j        $ r }t#          d| j        d|d          d}~ww xY w)zCommit repsTo to the databaseFTNr   zCould not set repsTo for (r?   r1   )rk   r   r   r   r   r	   r   r   rA   r   r   r&   r   r   r   r   rC   r   )	r+   rG   r   r   r   r   r   r   rK   s	            r   commit_repsTozNCReplica.commit_repsTo  s}    o 	6 	6F # v&&&!!## %%''' NN8FO445555  	+ 	+FO""6****  	 	FKMMveT]++ w(<hGG 	
(	2LLOOOOO| 	2 	2 	2( MMM4441 2 2 2	2r   N)r   F)r   r   r   r]   r,   r7   r   r\   r   r   r   r{   r   r   r   r   r   r   r   r   r   r   r   r   r_   r_      s6        / / />> > >, , , ,/> /> />b     
       
 
 
. . .:=2 =2 =2 =2~5 5 5BO O OO O O< < <&  , , ,@=2 =2 =2 =2 =2 =2r   r_   c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd ZddZd Zd Zd Zd Zd Zd ZdS )DirectoryServiceAgentc                     || _         d| _        d| _        d| _        d| _        d| _        d| _        d| _        i | _        i | _	        i | _
        dS )zInitialize DSA class.

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

        :param dsa_dnstr:  DN of the nTDSDSA
        NFr   )ra   rc   dsa_ivid	dsa_is_rodsa_is_istgoptionsdsa_behaviordefault_dnstrcurrent_rep_tableneeded_rep_tableconnect_tabler   s     r   r,   zDirectoryServiceAgent.__init__#  sc     # ! "$ !#
  r   c                    d| j         j        z  }| j        |d| j        z  z   }| j        |dt	          | j                  z  z   }| j        |dt	          | j                  z  z   }|d|                                 z  d|                                 z  z   d|                                 z  z   d	z   d
| 	                                z  z   dz   d
| 
                                z  z   dz   d
|                                 z  z   z  }|S )r.   ro   Nrp   rq   z
	dsa_ivid=%srr   z
	gc=%sz	
	istg=%sz
current_replica_table:rv   z
needed_replica_table:z
connect_table:)r2   r   ra   rc   r3   r   r   is_gcis_istgdumpstr_current_replica_tabledumpstr_needed_replica_tabledumpstr_connect_tabler5   s     r   r7   zDirectoryServiceAgent.__str__@  s*    t~..>%,t~==D=$+c$-.@.@@@D=$+c$-.@.@@@Ddjjll*djjll*+./ ++ ;;===	>
 ** ::<<<= ## 335556 	6 r   c                 6    | j                             |          S r   )r   getr*   s     r   get_current_replicaz)DirectoryServiceAgent.get_current_replicaW  s    %))(333r   c                     | j         p| j        S )zAReturns True if dsa is intersite topology generator for it's site)r   r   rP   s    r   r   zDirectoryServiceAgent.is_istgZ  s     14>1r   c                     | j         S )z1Returns True if dsa a read only domain controller)r   rP   s    r   r   zDirectoryServiceAgent.is_ro_  s
    ~r   c                 :    | j         t          j        z  dk    rdS dS )z*Returns True if dsa hosts a global catalogr   TF)r   r   DS_NTDSDSA_OPT_IS_GCrP   s    r   r   zDirectoryServiceAgent.is_gcc  s!    L444::4ur   c                      | j         |k    rdS dS )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   )r+   r   s     r   is_minimum_behaviorz)DirectoryServiceAgent.is_minimum_behaviori  s     ''4ur   c                 :    | j         t          j        z  dk    rdS dS )z>Whether this allows NTDSConnection translation in its options.r   TF)r   r   %DS_NTDSDSA_OPT_DISABLE_NTDSCONN_XLATErP   s    r   is_translate_ntdsconn_disabledz4DirectoryServiceAgent.is_translate_ntdsconn_disableds  s!    L4EE!KK4ur   c                     | j         | j        fS )z5Return DSA current and needed replica tables
        )r   r   rP   s    r   get_rep_tablesz$DirectoryServiceAgent.get_rep_tablesy  s     %t'<<<r   c                 B    | j                             d          \  }}}|S )z(Get the parent DN string of this object.,)ra   	partition)r+   headseptails       r   get_parent_dnstrz&DirectoryServiceAgent.get_parent_dnstr~  s"    .22377c4r   c                    g d}	 |                     | j        t          j        |          }n<# t          j        $ r*}|j        \  }}t          d| j        d|d          d}~ww xY w|d         }t          j        |	                    d|d         d                             | _
        d	|v r9t          j        |	                    d|d	         d                             | _        d
|v r t          |d
         d                   | _        d|v r't          |d         d                   dk    rd| _        nd| _        d|v r t          |d         d                   | _        |                     |           |                     |           dS )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.
        )r9   invocationIDr   msDS-isRODCmsDS-Behavior-Versionr;   zUnable to find nTDSDSA for (r?   r1   Nr   r9   invocationIdr   r   TRUETFr   )r@   ra   rA   rB   rC   rD   r   r   rE   rF   rc   r   intr   r3   r   r   load_current_replica_tableload_connection_table)r+   rG   r>   rH   e5rJ   rK   rL   s           r   load_dsazDirectoryServiceAgent.load_dsa  s   * * *
	3,,DN#.%*  , ,CC | 	3 	3 	37LT4( NNNDDD2 3 3 3	3
 !f	%";";L"%l"3A"6#8 #8 9 9
 S   Ie&?&?&).&9!&<'> '> ? ?DM s9~a011DLCCM(:1(=$>$>&$H$H!DNN"DN"c)) #C(?$@$C D DD 	''... 	""5)))))rN   c                 *   g d}	 |                     | j        t          j        |          }n<# t          j        $ r*}|j        \  }}t          d| j        d|d          d}~ww xY wi }t          |d                   dk    r|d                                         D ]}|dk    r	|d         |         D ]}	t          ||	
                    d	                    }
|
                                }t          |
j                  }||vrt          | |          }|||<   n||         }|d
k    r|                    |           |                    ||           |                                r|| _        nt          d| j        z            || _        dS )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
        )rY   r   rX   rW   r   msDS-HasInstantiatedNCsr;   z Unable to find nTDSDSA NCs for (r?   r1   Nr   r   utf8r  zNo nTDSDSA NCs for (%s))r@   ra   rA   rB   rC   rD   r   lenkeysr   decodeget_binary_integerr3   r   r_   r   r\   r   r   r   )r+   rG   ncattrsrH   e6rJ   rK   	tmp_tabler    r   dsdnr~   dnstrrx   s                 r   r  z0DirectoryServiceAgent.load_current_replica_table  s   
 
 
	3,,DN#.%,  . .CC | 	3 	3 	37LT4( NNNDDD2 3 3 3	3 	 s1v;;?? V[[]] 3 399
 !VAY 3 3E #5%,,v*>*>??D 3355ELLEI--'e44+.	%(('.555225999 ,,UA666 ~~'' 3-2*-33> 4t~EFFF "+rN   c                 $    || j         |j        <   dS )z]Method to add a NC replica that "should be present" to the
        needed_rep_table.
        N)r   r&   )r+   rx   s     r   add_needed_replicaz(DirectoryServiceAgent.add_needed_replica  s     /2cl+++r   c                 r   	 |                     | j        t          j        d          }n<# t          j        $ r*}|j        \  }}t          d| j        d|d          d}~ww xY w|D ]N}t          |j                  }|| j	        v r t          |          }|                    |           || j	        |<   OdS )zMethod to load the nTDSConnections listed for DSA object.

        :param samdb: database to query for DSA connection list
        z(objectClass=nTDSConnection)r<   r=   
expression#Unable to find nTDSConnection for (r?   r1   N)r@   ra   rA   SCOPE_SUBTREErC   rD   r   r3   r   r   NTDSConnectionload_connection)	r+   rG   rH   e7rJ   rK   rL   r  connects	            r   r  z+DirectoryServiceAgent.load_connection_table  s    
	3,,DN%(%6*H  J JCC | 	3 	3 	37LT4( NNNDDD2 3 3 3	3
  
	0 
	0CKKE ***$U++G##E***(/Du%%
	0 
	0s   '* A#%AA#Fc                 :   g }| j                                         D ]q\  }}|j        r|                    ||           |j        r|                    ||           |j        r+|                    ||           |                    |           r|D ]
}| j         |= dS )az  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 peform 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   )r+   rG   r   delconnr  r  s         r   commit_connectionsz(DirectoryServiceAgent.commit_connections'  s     "06688 		& 		&NE7" 0$$UB///% 3''r222$ &&&ub111u%%%  	* 	*E"5))	* 	*r   c                 0    || j         vsJ || j         |<   d S r   )r   )r+   r  r  s      r   add_connectionz$DirectoryServiceAgent.add_connectionB  s)    D.....$+5!!!r   c                     g }| j                                         D ]/}|                                |k    r|                    |           0|S )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   )r+   
from_dnstranswerr  s       r   get_connection_by_from_dnstrz2DirectoryServiceAgent.get_connection_by_from_dnstrF  sV     )0022 	' 	'G%%'':55g&&&r   c                 J    d                     d | j        D                       S )z1Debug dump string output of current replica tablerz   c              3   4   K   | ]}t          |          V  d S r   r3   r   s     r   r"   zFDirectoryServiceAgent.dumpstr_current_replica_table.<locals>.<genexpr>V  s(      @@AQ@@@@@@r   )r|   r   rP   s    r   r   z3DirectoryServiceAgent.dumpstr_current_replica_tableT  s&    yy@@)?@@@@@@r   c                 J    d                     d | j        D                       S )z0Debug dump string output of needed replica tablerz   c              3   4   K   | ]}t          |          V  d S r   r/  r   s     r   r"   zEDirectoryServiceAgent.dumpstr_needed_replica_table.<locals>.<genexpr>Z  s(      ??AQ??????r   )r|   r   rP   s    r   r   z2DirectoryServiceAgent.dumpstr_needed_replica_tableX  s&    yy??)>??????r   c                 J    d                     d | j        D                       S )z)Debug dump string output of connect tablerz   c              3   4   K   | ]}t          |          V  d S r   r/  r   s     r   r"   z>DirectoryServiceAgent.dumpstr_connect_table.<locals>.<genexpr>^  s(      <<AQ<<<<<<r   )r|   r   rP   s    r   r   z+DirectoryServiceAgent.dumpstr_connect_table\  s&    yy<<);<<<<<<r   c                 Z   dt          t          j                              z  | j        z   }t	          |          }d|_        d|_        ||_        ||_        ||_	        ||j
        |_        |j        |_        |||_        nt                      |_        |                     ||           |S )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)r3   uuiduuid4ra   r  r  enabledr*  r   system_flagsr  transport_dnstrguidtransport_guidschedulenew_connection_scheduler&  )r+   r   r8  	transportr*  schedr  r  s           r   new_connectionz$DirectoryServiceAgent.new_connection`  s     3tz||,,,t~= ''"'!+ &/oG#%.^G"$G  788GE7+++r   Nr   )r   r   r   r,   r7   r   r   r   r   r   r   r   r   r  r  r  r  r$  r&  r,  r   r   r   r@  r   r   r   r   r   !  s_            :  .4 4 42 2 2
        = = =
  
.* .* .*`Q+ Q+ Q+f2 2 20 0 06* * * *6, , ,  A A A@ @ @= = =    r   r   c                       e Zd ZdZd Zd Zd Zd ZddZddZ	dd	Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )r  z5Class defines a nTDSConnection found under a DSA
    c                     || _         d | _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d | _	        d | _
        d | _        d | _        d S )NFr   )r  r:  r7  whenCreatedr  r   r   r   r8  r9  r;  r*  r<  r+   r  s     r   r,   zNTDSConnection.__init__  sh    
	 "##"r   c                    | j         j        d| j        d| j        z  z   d| j        z  z   d| j        z  z   d| j        z  z   d| j        z  z   d| j        z  z   d| j	        z  z   d	| j
        z  z   }| j        |dt          | j                  z  z  }| j        |dt          | j                  z  z  }|d| j        z  z   }| j        |d| j        j        z  d| j        j        z  z   d| j        j        z  z   z  }t'          | j        j                  D ]_\  }}|d||j        fz  d||j        fz  z   d|z  z   d                    d | j        j        |         j        D                       z   dz   z  }`|S )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=%sN	
	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[ rs   c              3       K   | ]	}d |z  V  
dS z0x%X Nr   r   slots     r   r"   z)NTDSConnection.__str__.<locals>.<genexpr>  &      \\4$\\\\\\r   ])r2   r   r  r7  r  r   r   r   r8  rC  r9  r:  r3   r;  r*  r<  size	bandwidthnumberOfSchedules	enumerateheaderArraytypeoffsetr|   	dataArrayslots)r+   r6   iheaders       r   r7   zNTDSConnection.__str__  s    "&!8!8!8$**E$,./#d&667 &(::; ')<<	=
 $dl23 )4+<<= $d&667 %t';;< 9 MC	NN22D*+c$2E.F.FFFD&88=$*T]-??/$-2IIJ8]456 6D
 't}'@AA  	6?FK()AV]+,- =q@	A
 \\4=;RST;U;[\\\\\]   r   c                 &   g d}	 |                     | j        t          j        |          }n<# t          j        $ r*}|j        \  }}t          d| j        d|d          d}~ww xY w|d         }d|v r t          |d         d                   | _        d	|v r\t          |d	         d                   
                                                                                                d
k    rd| _        d|v r t          |d         d                   | _        	 t          j        |                    d|d         d                             | _        n%# t&          $ r t          d| j        z            w xY wd|v rWt)          ||d         d                             d                    }|                     |t          |j                             d|v r+t1          t2          j        |d         d                   | _        d|v r2t          j        t          |d         d                             | _        d|v rQt)          ||d         d                             d                    }t          |j                  | _        | j        J dS dS )zGiven a NTDSConnection object with an prior initialization
        for the object's DN, search for the DN and load attributes
        from the samdb.
        )r   enabledConnectionr<  rC  r9   transportType
fromServersystemFlagsr;   r  r?   r1   Nr   r   ra  r   Trd  r9   z4Unable to find objectGUID in nTDSConnection for (%s)rb  r  r<  rC  rc  )r@   r  rA   rB   rC   rD   r   r   r   r3   upperlstriprstripr7  r8  r   rE   rF   r:  KeyErrorr   r
  load_connection_transportr   r   r   r<  string_to_timerC  r*  )	r+   rG   r>   rH   e8rJ   rK   rL   r  s	            r   r  zNTDSConnection.load_connection  s   
     	/,,DJcn%*  , ,CC | 	/ 	/ 	/7LT4( JJJ. / / /	/
 !fs9~a011DL#%%3*+A.//5577>>@@GGIIVSS#C #C$6q$9 : :D	6	%33L474Ea4HJ J K K II  	6 	6 	6 &)-5 6 6 6	6 c!!5#o"6q"9"@"@"H"HIID**5#dg,,???&x'8#j/!:LMMDMC"1#c-6H6K2L2LMMD35#l"3A"6"="=f"E"EFFD!$'llDO?...  /.s    '. A'%A""A'9E "E7c                    dg}	 |                     |t          j        |          }n7# t          j        $ r%}|j        \  }}t          d|d|d          d}~ww xY wd|d         v rH|d         }|| _        t          j        |	                    d|d         d                             | _
        | j        J | j
        J dS )zGiven a NTDSConnection object which enumerates a transport
        DN, load the transport information for the connection object

        :param tdnstr: transport DN to load
        r9   r;   zUnable to find transport (r?   r1   Nr   )r@   rA   rB   rC   rD   r   r9  r   rE   rF   r;  )	r+   rG   tdnstrr>   rH   e9rJ   rK   rL   s	            r   ri  z(NTDSConnection.load_connection_transport  s    	+,,F%(^5  B BCC | 	+ 	+ 	+7LT4("FFDDD* + + +	+
 3q6!!a&C#)D 	%33L474Ea4HJ J K K  #///".....s   "( A AAFc                     | j         sJ d| _         |rdS 	 |                    | j                   dS # t          j        $ r*}|j        \  }}t          d| j        d|d          d}~ww xY w)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 (r?   r1   )r   deleter  rA   rC   rD   r   )r+   rG   r   e10rJ   rK   s         r   r"  zNTDSConnection.commit_deleted	  s    
 !!!!"  	F	/LL$$$$$| 	/ 	/ 	/8LT4( JJJ. / / /	/s   2 A+%A&&A+c                    | j         sJ d| _         |rdS d}	 |                    | j        t          j                  }t          |          dk    rd}nQ# t          j        $ r?}|j        \  }}|t          j        k    rt          d| j        d|d          Y d}~nd}~ww xY w|rt          d	| j        z            | j
        rd
}nd}t          j                    }	t          j        || j                  |	_        t          j        dt          j        d          |	d<   t          j        d
t          j        d          |	d<   t          j        |t          j        d          |	d<   t          j        | j        t          j        d          |	d<   t          j        t#          | j                  t          j        d          |	d<   t          j        t#          | j                  t          j        d          |	d<   | j        5t          j        t#          | j                  t          j        d          |	d<   | j        5t          j        t-          | j                  t          j        d          |	d<   	 |                    |	           dS # t          j        $ r*}
|
j        \  }}t          d| j        d|d          d}
~
ww xY w)zLocal helper routine for commit_connections() which
        handles committed connections that are to be added to the
        database
        FNr<   r=   r   TUnable to search for (r?   r1   z'nTDSConnection for (%s) already exists!r   FALSEnTDSConnectionobjectClassshowInAdvancedViewOnlyra  rc  r   rd  rb  r<  z"Could not add nTDSConnection for ()r  r@   r  rA   rB   r  rC   rD   ERR_NO_SUCH_OBJECTr   r7  r   r   r   r   FLAG_MOD_ADDr*  r3   r   r8  r9  r<  r	   add)r+   rG   r   foundrL   e11rJ   rK   	enablestrr   e12s              r   r  zNTDSConnection.commit_added  s   
    	F 		3,,DJcn,EEC3xx1}}| 	3 	3 	38LT4s---h $


DDD 2 3 3 3 .----	3
  	'D:& ' ' ' < 	 III KMMveTZ(( /1A,. . 	
- vs'779 9 	

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

 t0@,OO 	
, s4<00#2BINN 	
) s4#455s7G,. . 	
- +"3t';#<#<c>N#24 4 o =$"8DM#:#:#&#3ZA A jM	/IIaLLLLL| 	/ 	/ 	/8LT4( JJJ. / / /	/s/   ;A B"#5BB"0J K %J;;K c                 N   | j         sJ d| _         |rdS 	 |                    | j        t          j                   nc# t          j        $ rQ}|j        \  }}|t          j        k    rt          d| j        z            t          d| j        d|d          d}~ww xY w| j	        rd}nd	}t          j
                    }t          j        || j                  |_        t          j        |t          j        d
          |d
<   t          j        | j        t          j        d          |d<   t          j        t!          | j                  t          j        d          |d<   t          j        t!          | j                  t          j        d          |d<   | j        6t          j        t!          | j                  t          j        d          |d<   n#t          j        g t          j        d          |d<   | j        6t          j        t-          | j                  t          j        d          |d<   n#t          j        g t          j        d          |d<   	 |                    |           dS # t          j        $ r*}|j        \  }}t          d| j        d|d          d}~ww xY w)zLocal helper routine for commit_connections() which
        handles committed connections that are to be modified to the
        database
        FNrs  z&nTDSConnection for (%s) doesn't exist!rt  r?   r1   r   ru  ra  rc  r   rd  rb  r<  z%Could not modify nTDSConnection for ()r   r@   r  rA   rB   rC   rD   ry  r   r7  r   r   r   r   r   r*  r3   r   r8  r9  FLAG_MOD_DELETEr<  r	   r   )	r+   rG   r   e13rJ   rK   r~  r   e14s	            r   r!  zNTDSConnection.commit_modifiedc  s   
 """"#  	F	/ LLdjL????| 	/ 	/ 	/8LT4s---G#z * + + +( JJJ. / / /	/ < 	 III KMMveTZ(( y#*>24 4 	

 t0D+- - 	
, s4<00#2F(* * 	
) s4#455s7K,. . 	
- +"3t';#<#<#&#7J J o
 "2s':OLL o =$"8DM#:#:#&#7E E jMM
 "2s':JGG jM	/LLOOOOO| 	/ 	/ 	/8LT4( JJJ. / / /	/s.   &= BABBI+ +J$:%JJ$c                     || _         d S r   )r   )r+   	truefalses     r   set_modifiedzNTDSConnection.set_modified  s    'r   c                     | j         | j         j        d         dS | j         j        d         j        D ]}|dz  dk    r dS dS )zzReturns True if our schedule includes at least one
        replication interval within the week.  False otherwise
        Nr   F   T)r<  r\  r]  )r+   rR  s     r   !is_schedule_minimum_once_per_weekz0NTDSConnection.is_schedule_minimum_once_per_week  s\     = DM$;A$>$F5M+A.4 	 	Dt##tt $ur   c                 &   | j         |du S |dS | j         j        |j        k    s*| j         j        |j        k    s| j         j        |j        k    rdS t	          | j         j                  D ]\  }}| j         j        |         j        |j        |         j        k    r dS | j         j        |         j        |j        |         j        k    r dS t          | j         j	        |         j
        |j	        |         j
                  D ]\  }}||k    r  dS dS )zReturns True if our schedule is equivalent to the input
        comparison schedule.

        :param shed: schedule to compare to
        NFT)r<  rU  rV  rW  rX  rY  rZ  r[  zipr\  r]  )r+   r?  r^  r_  abs         r   is_equivalent_schedulez%NTDSConnection.is_equivalent_schedule  s1    = D= =5]5:--]$77],0GGG5"4=#<== 	! 	!IAv}(+0E4Ea4H4MMMuu}(+2 #*+ +uuDM3A6<!OA.46 6 ! !166 555 ! tr   c                 :    | j         t          j        z  dk    rdS dS )zMReturns True if NTDS Connection specifies RODC
        topology only
        r   FT)r   r   NTDSCONN_OPT_RODC_TOPOLOGYrP   s    r   is_rodc_topologyzNTDSConnection.is_rodc_topology  s#     <$99Q>>5tr   c                 :    | j         t          j        z  dk    rdS dS )zReturns 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_GENERATEDrP   s    r   is_generatedzNTDSConnection.is_generated  s#     <$88A==5tr   c                 :    | j         t          j        z  dk    rdS dS )zGReturns True if NTDS Connection should override notify default
        r   FT)r   r   $NTDSCONN_OPT_OVERRIDE_NOTIFY_DEFAULTrP   s    r   is_override_notify_defaultz)NTDSConnection.is_override_notify_default  s#     <$CCqHH5tr   c                 :    | j         t          j        z  dk    rdS dS )z:Returns True if NTDS Connection should use notify
        r   FT)r   r   NTDSCONN_OPT_USE_NOTIFYrP   s    r   is_use_notifyzNTDSConnection.is_use_notify  s#     <$66!;;5tr   c                 :    | j         t          j        z  dk    rdS dS )z?Returns True if NTDS Connection should use twoway sync
        r   FT)r   r   NTDSCONN_OPT_TWOWAY_SYNCrP   s    r   is_twoway_synczNTDSConnection.is_twoway_sync  s#     <$771<<5tr   c                 :    | j         t          j        z  dk    rdS dS )zRReturns True if NTDS Connection intersite compression
        is disabled
        r   FT)r   r   *NTDSCONN_OPT_DISABLE_INTERSITE_COMPRESSIONrP   s    r   !is_intersite_compression_disabledz0NTDSConnection.is_intersite_compression_disabled  s#     <$IIQNN5tr   c                 :    | j         t          j        z  dk    rdS dS )zBReturns True if NTDS Connection has a user owned schedule
        r   FT)r   r    NTDSCONN_OPT_USER_OWNED_SCHEDULErP   s    r   is_user_owned_schedulez%NTDSConnection.is_user_owned_schedule  s#     <$??1DD5tr   c                     | j         S )z3Returns True if NTDS Connection is enabled
        )r7  rP   s    r   
is_enabledzNTDSConnection.is_enabled  s     |r   c                     | j         S )z%Return fromServer dn string attribute)r*  rP   s    r   r)  zNTDSConnection.get_from_dnstr  s
    r   Nr   )r   r   r   r]   r,   r7   r  ri  r"  r  r!  r  r  r  r  r  r  r  r  r  r  r  r)  r   r   r   r  r    sW          $ $ $L7/ 7/ 7/r/ / /2/ / / /&E/ E/ E/ E/NE/ E/ E/ E/N( ( (  & & &P                
    r   r  c                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )		Partitiona!  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                     || _         d| _        d| _        g | _        g | _        t
                              | d            d S )NTr   )partstrr7  r8  rw_location_listro_location_listr$   r,   )r+   r  s     r   r,   zPartition.__init__(  sF     " "
 	tT*****r   c                    g d}	 |                     | j        t          j        |          }n<# t          j        $ r*}|j        \  }}t          d| j        d|d          d}~ww xY w|d         }|                                D ].}|dk    r
|d	k    ret          ||         d                   	                                
                                                                d
k    rd| _        nd| _        u|dk    r!t          ||         d                   | _        ||         D ]}	t          ||	                    d                    }
t          |
j                  }|dk    r|| _        G|dk    r| j                            |           h|dk    r| j                            |           0|                     |           dS )a  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Enabledrd  msDS-NC-Replica-LocationsmsDS-NC-RO-Replica-Locationsr;   zUnable to find partition for (r?   r1   Nr   r   r  r   TFrd  r  r  r  r  )r@   r  rA   rB   rC   rD   r   r	  r3   re  rf  rg  r7  r   r8  r   r
  r   r&   r  r   r  rU   )r+   rG   r>   rH   e15rJ   rK   rL   r    r   r  r  s               r   load_partitionzPartition.load_partition4  s   1 1 1
	1,,DL%*  , ,CC | 	1 	1 	18LT4( LLL$$$0 1 1 1	1 !f 	 	ADyyI~~s1vay>>''))002299;;vEE#'DLL#(DLM!!$'Aq	NN!Q  uell6&:&:;;DG==$)DM333)00777666)00777 7$ 	&&&&&rN   c                     | j         S )z-Returns True if partition is enabled
        )r  rP   s    r   r  zPartition.is_enabledn  s     r   c                 :    | j         t          j        z  dk    rdS dS )zReturns True if this is not an Active Directory NC in our
        forest but is instead something else (e.g. a foreign NC)
        r   TF)r8  r   SYSTEM_FLAG_CR_NTDS_NCrP   s    r   
is_foreignzPartition.is_foreigns  s$      ;;AA45r   c                 ,   d}d}| j         t          j        k    p9| j         t          j        k    p$| j         t          j        k    o| j        |j        k    }| j         t          j        k    r5|                                r|j	        | j
        v rd}n|j	        | j        v rd}|                                rE| j         t          j        k    r0| j        |j        k    r |j	        | j
        v s|j	        | j        v rd}d}|r|                                s|rd}|||fS )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   ra   r  r  r   )r+   
target_dsar   partialneededs        r   should_be_presentzPartition.should_be_present|  s?    
 ,&-/ >,&-/><6=0 ==J$<< 	 <6---!! "'4+@@@!F'4+@@@!F
  	LFM))MZ555!T%:::!T%:::FG  	z'')) 	W 	Br7""r   c                     dt                               |           z  d| j        z  z   d                    d | j        D                       z   d                    d | j        D                       z   }|S )r.   z%sz
	partdn=%srs   c              3       K   | ]	}d |z  V  
dS )z
	msDS-NC-Replica-Locations=%sNr   r   r    s     r   r"   z$Partition.__str__.<locals>.<genexpr>  s(      ]]!9A=]]]]]]r   c              3       K   | ]	}d |z  V  
dS )z!
	msDS-NC-RO-Replica-Locations=%sNr   r  s     r   r"   z$Partition.__str__.<locals>.<genexpr>  s(      ``Q<q@``````r   )r$   r7   r  r|   r  r  r5   s     r   r7   zPartition.__str__  s    m++D111-.ww]]tG\]]]]]^ ww``$J_`````a r   N)
r   r   r   r]   r,   r  r  r  r  r7   r   r   r   r  r  !  sz         
+ 
+ 
+8' 8' 8't  
  .# .# .#`    r   r  c                   `    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd ZdS )SitezAn individual site object discovered thru the configuration
    naming context.  Contains all DSAs that exist within the site
    c                 v    || _         d | _        d| _        d | _        d| _        i | _        i | _        || _        d S Nr   )
site_dnstr	site_guidsite_optionssite_topo_generatorsite_topo_failover	dsa_tablerw_dsa_tablent_now)r+   r  r  s      r   r,   zSite.__init__  sB    $#' "#r   c                    d| j         z  }g d}	 |                    |t          j        |          }|                    | j         t          j        dg          }n7# t          j        $ r%}|j        \  }}t          d|d|d          d}~ww xY w|d	         }	d
|	v r t          |	d
         d	                   | _        d|	v r t          |	d         d	                   | _
        d|	v r t          |	d         d	                   | _        |d	         }	d|	v r9t          j        |                    d|	d         d	                             | _        |                     |           dS )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interSiteTopologyGeneratorr;   r9   z"Unable to find site settings for (r?   r1   Nr   r   r  r  )r  r@   rA   rB   rC   rD   r   r   r  r3   r  r  r   rE   rF   r  load_all_dsa)
r+   rG   ssdnr>   rH   self_rese16rJ   rK   rL   s
             r   	load_sitezSite.load_site  s   
 *DO;/ / /	),,D%*  , ,C||+7. $ : :HH| 	) 	) 	)8LT4( DD$$$( ) ) )	)
 !f #C	N1$5 6 6D'3..C45a899 $ '#--&)#.I*J1*M&N&ND#qk3!Yu'@'@'*<'8';(= (= > >DN 	%     s   A
A B* B

Bc                    	 |                     | j        t          j        d          }n3# t          j        $ r!}|j        \  }}t          d|z            d}~ww xY w|D ]l}t          |j                  }|| j	        v r t          |          }|                    |           || j	        |<   |                                s
|| j        |<   mdS )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))r=   r  zUnable to find nTDSDSAs - (%s)N)r@   r  rA   r  rC   rD   r   r3   r   r  r   r  r   r  )	r+   rG   rH   e17rJ   rK   rL   r  rm   s	            r   r  zSite.load_all_dsa  s    
	D,,t%(%6*A  C CCC | 	D 	D 	D8LT4;dBCCC	D  	/ 	/CKKE &&'..CLL %(DN5!99;; /+.!%(	/ 	/s   '* AAAc                 6    | j                             |          S )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   rD  s     r   get_dsazSite.get_dsa  s     ~!!%(((r   c                 j   |j         rd|_        |j        | _        dS t	          |          }|                    |           |                    |           t          | j        	                                d           }| j
        dk    rd}n| j
        dz  dz  }| j                            | j                  }|b||ur^|                    |          }d	}	|j        D ]}
|j        |
j        k    rd}	 n|	s|}d}n>| j        |
j        z
  |k    rd}d}n&|}|
j        }n|                    |          }| j        }|| j        |z
  |z  z   t'          |          z  }||         }d|_        ||urd	S | j        |j        k    rdS |j        | _        |rdS d
| j        z  }t+          j                    }t+          j        ||          |_        t+          j        |j        t*          j        d          |d<   	 |                    |           n-# t*          j        $ r}t;          d|d|d          d}~ww xY wdS )al  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                 *    t          | j                  S r   )r	   rc   )rm   s    r   <lambda>z"Site.select_istg.<locals>.<lambda>5  s    HS\22 r   )keyr   l    PC <   i NFr  r  z.Could not set interSiteTopologyGenerator for (r?   r1   )r   r   ra   r  get_dsa_config_repr   r   sortedr  r(  r  r  r   indexr   r   source_dsa_invocation_idr  last_sync_successr  r  rA   r   r   r   r   r   r   rC   r   )r+   rG   mydsar   c_repD_sortfd_dsaj_idxr|  cursori_idxt_timek_idxr  r   rK   s                    r   select_istgzSite.select_istg  s    ? 	 $E',D$4"5))
 	E"""%%e,,,  $$&&224 4 4$ "a''&AA'",x7A ""4#;<< e!3!3( LL''EE>  >V%DDD EE E  2
 v77!;;1 LL''E[F 4;/A56#f++E u  5 #u664#(?   	4 *DO;KMMveT"" u0D;= = 	

&'	LLOOOO| 	 	 	(ttt  	 ts   0H H0H++H0c                 2    | j         t          j        z  dk    S )z8Returns True if intra-site topology is disabled for siter   )r  r   -DS_NTDSSETTINGS_OPT_IS_AUTO_TOPOLOGY_DISABLEDrP   s    r   is_intrasite_topology_disabledz#Site.is_intrasite_topology_disabled  s#    !BCGHI 	Ir   c                 2    | j         t          j        z  dk    S )z8Returns True if inter-site topology is disabled for siter   )r  r   8DS_NTDSSETTINGS_OPT_IS_INTER_SITE_AUTO_TOPOLOGY_DISABLEDrP   s    r   is_intersite_topology_disabledz#Site.is_intersite_topology_disabled  s!    "NO 	r   c                 2    | j         t          j        z  dk    S )z:Returns True if selection of random bridgehead is disabledr   )r  r   1DS_NTDSSETTINGS_OPT_IS_RAND_BH_SELECTION_DISABLEDrP   s    r   is_random_bridgehead_disabledz"Site.is_random_bridgehead_disabled  #    !FGKLM 	Mr   c                 2    | j         t          j        z  dk    S )z1Returns True if detect stale is disabled for siter   )r  r   1DS_NTDSSETTINGS_OPT_IS_TOPL_DETECT_STALE_DISABLEDrP   s    r   is_detect_stale_disabledzSite.is_detect_stale_disabled  r  r   c                 2    | j         t          j        z  dk    S )z<Returns True if NTDS Connection cleanup is disabled for siter   )r  r   ,DS_NTDSSETTINGS_OPT_IS_TOPL_CLEANUP_DISABLEDrP   s    r   is_cleanup_ntdsconn_disabledz!Site.is_cleanup_ntdsconn_disabled  s#    !ABFGH 	Hr   c                 >    |                      |j                  rdS dS )z"Return True if dsa is in this siteTF)r  ra   )r+   rm   s     r   	same_sitezSite.same_site  s"    <<&& 	4ur   c                 j    t          | j                  dk    rt          | j                  dk    rdS dS )Nr   TF)r  r  r  rP   s    r   is_rodc_sitezSite.is_rodc_site  s6    t~""s4+<'='='B'B4ur   c                     d| j         j        z  d| j        z  z   d| j        z  z   d| j        z  z   d| j        z  z   }| j                                        D ]\  }}|d|z  z   }|S )r.   ro   z
	dn=%sz
	options=0x%Xz
	topo_generator=%sz
	topo_failover=%drv   )r2   r   r  r  r  r  r  r  )r+   r6   r  rm   s       r   r7   zSite.__str__  s    t~..T_,-!D$556 ')AAB &(??	@
 ,,.. 	' 	'HC&3,&DDr   N)r   r   r   r]   r,   r  r  r  r  r  r  r  r  r  r   r  r7   r   r   r   r  r    s           #! #! #!J/ / /<) ) )g g gRI I I
  M M M
M M M
H H H
    
	 	 	 	 	r   r  c                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )		GraphNodezA 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                 0    || _         || _        g | _        dS )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_edgesra   	edge_from)r+   ra   max_node_edgess      r   r,   zGraphNode.__init__  s     ("r   c                     d| j         j        z  d| j        z  z   d| j        z  z   }t	          | j                  D ]$\  }}t          |t                    r
|d||fz  z  }%|S )Nro   rp   z
	max_edges=%dz
	edge_from[%d]=%s)r2   r   ra   r  rX  r  
isinstancer3   )r+   r6   r^  edges       r   r7   zGraphNode.__str__  sz    t~..!DN23!DN23 !00 	; 	;GAt$$$ ;.!T::r   c                     t          |t                    sJ || j        k    rdS || j        v rdS t	          | j                  | j        k    rdS | j                            |           dS )zAdd an edge from the dsa to our graph nodes edge from list

        :param from_dsa_dnstr: the dsa that the edge emanates from
        FT)r  r3   ra   r  r  r  r   )r+   from_dsa_dnstrs     r   add_edge_fromzGraphNode.add_edge_from  sw    
 .#..... T^++5T^++5t~$.005n---tr   c                 r    |j                                         D ]}|                     |j                   dS )ae  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   r(  r  r*  )r+   rm   r  s      r   add_edges_from_connectionsz$GraphNode.add_edges_from_connections  sF     (//11 	3 	3Gw12222	3 	3r   c                    | j         D ]v}|                    |          }d}|D ]}|                                rd}|r8t          j        }t          j        t          j        z  }|                    ||||d           wdS )zFor each edge directed to this graph node, ensure there
           is a corresponding nTDSConnection object in the dsa.
        FTN)r  r,  r  r   r  SYSTEM_FLAG_CONFIG_ALLOW_RENAMESYSTEM_FLAG_CONFIG_ALLOW_MOVEr@  )	r+   rm   r>  
edge_dnstrconnectionsfound_validr  optr~   s	            r   add_connections_from_edgesz$GraphNode.add_connections_from_edges#  s     . !	H !	HJ:::FFK  K& # #++-- "  0C978E sE9j$GGGGC!	H !	Hr   c                 D    t          | j                  | j        k    rdS dS )z<Return True if we have met the maximum "from edges" criteriaTF)r  r  r  rP   s    r   has_sufficient_edgeszGraphNode.has_sufficient_edgesJ  s#    t~$.004ur   N)
r   r   r   r]   r,   r7   r  r  r  r  r   r   r   r  r    s|           	 	 	  &
3 
3 
3%H %H %HN    r   r  c                   $    e Zd ZdZd Zd Zd ZdS )	Transportz;Class defines a Inter-site transport found under Sites
    c                 Z    || _         d| _        d | _        d | _        d | _        g | _        d S r  )r  r   r:  nameaddress_attrbridgehead_listrD  s     r   r,   zTransport.__init__U  s4    
		 !r   c                     | j         j        d| j        dt          | j                  z  z   d| j        z  z   d| j        z  z   d| j        z  z   d                    d | j	        D                       z   }|S ),Debug dump string output of Transport objectrF  rG  
	options=%dz
	address_attr=%sz	
	name=%srs   c              3       K   | ]	}d |z  V  
dS )z
	bridgehead_list=%sNr   )r   r  s     r   r"   z$Transport.__str__.<locals>.<genexpr>e  s(      ZZE/%7ZZZZZZr   )
r2   r   r  r3   r:  r   r   r  r|   r!  r5   s     r   r7   zTransport.__str__]  s     "&!8!8!8$**Es49~~-.$,./ %t'889 ty(	)
 wwZZTEYZZZZZ[ r   c                    g d}	 |                     | j        t          j        |          }n<# t          j        $ r*}|j        \  }}t          d| j        d|d          d}~ww xY w|d         }t          j        |	                    d|d         d                             | _
        d	|v r t          |d	         d                   | _        d
|v r t          |d
         d                   | _        d|v r t          |d         d                   | _        d|v re|d         D ]^}t!          ||                    d                    }	t          |	j                  }
|
| j        vr| j                            |
           ]dS dS )zGiven a Transport object with an prior initialization
        for the object's DN, search for the DN and load attributes
        from the samdb.
        )r9   r   r  bridgeheadServerListBLtransportAddressAttributer;   zUnable to find Transport for (r?   r1   Nr   r9   r   r(  r  r'  r  )r@   r  rA   rB   rC   rD   r   r   rE   rF   r:  r   r   r3   r   r  r   r
  r   r!  r   )r+   rG   r>   rH   e18rJ   rK   rL   r   r  r  s              r   load_transportzTransport.load_transporti  s   
. . .
	/,,DJcn%*  , ,CC | 	/ 	/ 	/8LT4( JJJ. / / /	/
 !fIe77!,/24 4 5 5	 s9~a011DL&#-- #C(C$DQ$G H HDS==CKN++DI#s**56 7 7uell6&:&:;;DG 444(//666 +*7 7rN   N)r   r   r   r]   r,   r7   r*  r   r   r   r  r  Q  sK         " " "
 
 
%7 %7 %7 %7 %7r   r  c                   8    e Zd ZdZd	dZd Zd Zd Zd Zd Z	dS )
r   zClass encapsulation of the NDR repsFromToBlob.

    Removes the necessity of external code having to
    understand about other_info or manipulation of
    update flags.
    Nc                 0   d| j         d<   || j         d<   d| j         d<   |ut          j                    | j         d<   d| j         d         _        d | j         d<   d | j         d	<   t          j                    x| j         d         j        _        | j         d
<   d S || j         d<   |j        j        | j         d
<   |j        dk    r%|j        j        j        | j         d<   d | j         d	<   d S |j        j        j        | j         d<   |j        j        j	        | j         d	<   d S )NFr   r&   r   update_flagsr      	dns_name1	dns_name2
other_info)
__dict__r   r   r   repsFromTo1OtherInfor   r1  dns_namer/  r0  )r+   r&   r   s      r   r,   zRepsFromTo.__init__  s   ).o&$,j!(+n%8 (0(?(A(ADM*%03DM*%-)-DM+&)-DM+& /7.K.M.MNDM*%)4l+++ )1DM*%*2,*ADM,'3&&-5\-D-Mk*-1k***-5\-D-Nk*-5\-D-Nk***r   c                    d| j         j        z  d| j        z  z   d| j        z  z   d| j        z  z   d| j        z  z   d| j        z  z   d| j        z  z   d| j        z  z   d	| j	        z  z   d
| j
        z  z   d| j        z  z   d| j        z  z   d| j        z  z   dz   d                    d | j        D                       z   dz   }|S )r.   ro   z

	dnstr=%sz
	update_flags=0x%Xz
	version=%dz
	source_dsa_obj_guid=%sz
	source_dsa_invocation_id=%srH  z
	replica_flags=0x%Xz
	consecutive_sync_failures=%dz
	last_success=%sz
	last_attempt=%sz
	dns_name1=%sz
	dns_name2=%sz
	schedule[ rs   c              3       K   | ]	}d |z  V  
dS rP  r   rQ  s     r   r"   z%RepsFromTo.__str__.<locals>.<genexpr>  s&      @@$w~@@@@@@r   rT  )r2   r   r&   r-  r   source_dsa_obj_guidr  r;  replica_flagsconsecutive_sync_failureslast_successlast_attemptr/  r0  r|   r<  r5   s     r   r7   zRepsFromTo.__str__  s-    t~..-.&)::;  $,./ ,d.FF	G
 2./0 ')<<= ($*<<= 3/0
1 %t'889 %t'889 "DN23 "DN23     ww@@$-@@@@@!A" #& r   c                 J   |dv rj|dv r | j         dxx         t          j        z  cc<   n#|dv r| j         dxx         t          j        z  cc<   t	          | j         d         j        ||           n|dv rp|| j         d<   | j         d         j        dk    r(| j         d         | j         d         j        j        _        n| j         d         | j         d         j        j        _	        n|d	v rW|| j         d
<   | j         d         j        dk    rt          |          | j         d
         | j         d         j        j        _        nF|dv r|| j         d<   n7|dv r|| j         d<   n(|dv rt          d|z            t          d|z            | j         dxx         t          j        z  cc<   dS )zSet an attribute and chyange update flag.

        Be aware that setting any RepsFromTo attribute will set the
        drsuapi.DRSUAPI_DRS_UPDATE_ADDRESS update flag.
        r<  r8  r;  r7  r  r9  r:  r;  )r8  r-  )r<  r   r/  r/  r.  r0  r0  r&   r&   r   r   r   z$Attempt to set readonly attribute %sUnknown attribute %sN)r2  r   DRSUAPI_DRS_UPDATE_FLAGSDRSUAPI_DRS_UPDATE_SCHEDULEsetattrr   r   r1  r4  r/  r   r0  DRSUAPI_DRS_UPDATE_ADDRESS)r+   itemr   s      r   __setattr__zRepsFromTo.__setattr__  s     $ $ $
 (((n---1QQ----%%n---1TT---DM*-14????]"").DM+&}Z(0C77M+. j)-8AA M+. j)-8BB ]"").DM+&}Z(0C77$T*** M+. j)-8BB \!!(-DM*%%&&&-2DM/**[   !G$!NOOO !7$!>???n%%%)KK%%%%%r   c                 .   |dv r t          | j        d         j        |          S |dv r| j        d         j        S |dv rN| j        d         j        dk    r| j        d         j        j        j        S | j        d         j        j        j        S |dv rA| j        d         j        dk    rt          |          | j        d         j        j        j        S |dv r| j        d         S |d	v r| j        d
         S |dv r| j        d         S t          d|z            )zzOverload of RepsFromTo attribute retrieval.

        Allows external code to ignore substructures within the blob
        r=  r   rB  r>  r.  r?  rA  r   r@  r&   r-  r-  rC  )	getattrr2  r   r   r1  r4  r/  r   r0  )r+   rH  s     r   __getattr__zRepsFromTo.__getattr__  s;   
  $ $ $ 4=48$???[  =,44]""}Z(0C77}Z04?HH}Z04?II]""}Z(0C77$T***}Z04?II&&&=11\!!=,,%%%=003d:;;;r   c                     | j         dk    S r  rK  rP   s    r   r   zRepsFromTo.is_modified;  s    !S()r   c                     d| j         d<   d S )Nr   r-  )r2  rP   s    r   r   zRepsFromTo.set_unmodified>  s    (+n%%%r   )NN)
r   r   r   r]   r,   r7   rI  rM  r   r   r   r   r   r   r     s         2O 2O 2O 2Oh  00L 0L 0Ld#< #< #<J* * *, , , , ,r   r   c                   $    e Zd ZdZd Zd Zd ZdS )SiteLinkz0Class defines a site link found under sites
    c                 h    || _         d| _        d| _        d| _        d | _        d | _        g | _        d S r  )r  r   r8  costr<  interval	site_listrD  s     r   r,   zSiteLink.__init__F  s8    
	r   c                     | j         j        d| j        d| j        z  z   d| j        z  z   d| j        z  z   d| j        z  z   }| j        |d| j        j        z  d| j        j	        z  z   d	| j        j
        z  z   z  }t          | j        j                  D ]_\  }}|d
||j        fz  d||j        fz  z   d|z  z   d                    d | j        j        |         j        D                       z   dz   z  }`| j        D ]\  }}|d|d|dz   }|S )r#  rF  r$  z
	system_flags=%dz	
	cost=%dz
	interval=%sNrI  rJ  rK  rL  rM  rN  rs   c              3       K   | ]	}d |z  V  
dS rP  r   rQ  s     r   r"   z#SiteLink.__str__.<locals>.<genexpr>d  rS  r   rT  z
	site_list=r0   r1   )r2   r   r  r   r8  rS  rT  r<  rU  rV  rW  rX  rY  rZ  r[  r|   r\  r]  rU  )r+   r6   r^  r_  r:  r   s         r   r7   zSiteLink.__str__O  s    "&!8!8!8$**E$,./$t'889 ty() !4=0	1 =$*T]-??/$-2IIJ8]456 6D
 't}'@AA  	6?V[)*AV]+,- =q@	A
 \\4=;RST;U;[\\\\\]    	? 	?HD"4TTT222>>DDr   c                    g d}	 |                     | j        t          j        |dg          }n<# t          j        $ r*}|j        \  }}t          d| j        d|d          d}~ww xY w|d         }d	|v r t          |d	         d                   | _        d
|v r t          |d
         d                   | _	        d|v r t          |d         d                   | _
        d|v r t          |d         d                   | _        d|v r|d         D ]}t          ||                    d                    }	t          j        |	j                            d                    }
t%          |	j                  }|
|f| j        vr| j                            |
|f           d|v r!t+          t,          j        |          | _        dS t1                      | _        dS )zGiven a siteLink object with an prior initialization
        for the object's DN, search for the DN and load attributes
        from the samdb.
        )r   rd  rS  r<  replIntervalsiteListzextended_dn:0)r<   r=   r>   controlszUnable to find SiteLink for (r?   r1   Nr   r   rd  rS  rY  rZ  r  rE   r<  )r@   r  rA   rB   rC   rD   r   r   r   r8  rS  rT  r   r
  r   rE   r   get_extended_componentr3   rU  r   r   r   r<  r=  )r+   rG   r>   rH   e19rJ   rK   rL   r   r  r:  r  s               r   load_sitelinkzSiteLink.load_sitelinkk  s   
  	/,,DJcn%*o5F  H HCC | 	/ 	/ 	/8LT4( JJJ. / / /	/
 !fs9~a011DLC #C$6q$9 : :DS==CKN++DIS  N 3A 677DMZ 9 9uell6&:&:;;y!?!?!G!GHHDG%=66N))4-888&x'8%@@DMMM355DMMMs   )0 A)%A$$A)N)r   r   r   r]   r,   r7   r^  r   r   r   rQ  rQ  B  sK             8-6 -6 -6 -6 -6r   rQ  c                       e Zd Zd ZdS )KCCFailedObjectc                 L    || _         || _        || _        || _        || _        d S r   )r5  failure_counttime_first_failurelast_resultr4  )r+   r5  rb  rc  rd  r4  s         r   r,   zKCCFailedObject.__init__  s,    	*"4& r   N)r   r   r   r,   r   r   r   r`  r`    s#        ! ! ! ! !r   r`  c                     | j                                         D ]}|                                r|c S t          d| j        z            )Nz)Unable to find config NC replica for (%s))r   r(  rQ   r   ra   )rm   r  s     r   r  r    sa    &--//  ?? 	LLL	 >=! " " "r   c                      t          j                    } d| _        d| _        d| _        t          j                    }d|_        d|_        |g| _        t          j	                    }dgdz  |_
        |g| _        | S )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   r<  rU  rV  rW  scheduleHeaderrZ  r[  rY  scheduleSlotsr]  r\  )r<  r_  datas      r   r=  r=    sy      ""HHMH!"H$&&FFKFM"8H!##D#DJHOr   c           
         g }|                      |                                 t          j        d          }|                      |                                 t          j        d          }t	                      }d}|D ]}|j                                                                        }||                                xx         dz  cc<   |                                	                                |	                                k    r|dz  }t          |          t          |          k    rg }	|D ]2}|j                                        |vr|	                    |           3d                    t          j        |          t          j        t          |                                                               }
|	D ]}t          j        t          |j                            }|                      |                                 t          j        dgd                    |          d	g
          }|                      |                                 t          j        ddgd                    |
|          d	g
          }t          |          dk    rGt          |          dk    r3t          |d         d         d                   }t          |d         d         d                   }||k    r3d}|d         d         D ]}t          j        | t          |                    }|                                }|                                	                                }||         |k    rd} n)||         |k    r||	                                k     rd} n|r@|j                                        }|                    |	                                           |S )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,{}rS  z&(&(objectClass=siteLink)(siteList={}))zserver_sort:1:0:cost)r<   r=   r>   r  r[  rZ  z3(&(objectClass=siteLink)(siteList={})(siteList={}))TF)r@   rT   rA   r  r
   r   parentcanonical_strget_rdn_valuelowerr  r   formatbinary_encoder3   r   r   )rG   	site_namesites_to_cover
server_ressite_ressites_in_usedc_countrL   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  6 6J
 ||!8!8!:!:"%"3';  = =H 99LH   &--//((**W**,,---2---  ""((**ioo.?.???MH
<CMM)) 	, 	,Cv##%%\99&&s+++)00i((c%"9"9";";<<==
 

 $ 0	B 0	BD*3tw<<88J %*A*A*C*C+.+<VH166<fZ6H6H/E.F	 % H HI %*A*A*C*C+.+<,2J+?1CCI6)4)3D5 D5 0F.F % H HI 9~~!!c)nnq&8&8IaL0344IaL0344 E>>
   )!Z 8 
 
H!fUCMM::G")"7"7"9"9K&4466<<>>H#K08;;#(&{3x??"Y__%6%666#( B%)W%:%:%<%<N")).*>*>*@*@AAAr   )&r   rA   r5  sambar   samba.dcerpcr   r   r   samba.samdbr   	samba.ndrr   r	   collectionsr
   	Exceptionr   objectr   dictr2  r  r4   r$   r_   r   r  r  r  r  r  r   rQ  r`  r  r=  r  r   r   r   <module>r     s  , 


 



                
        * * * * * * * *      	 	 	 	 	y 	 	 	A A A A AV A A A
 TNNV_%:%:%<%<NNNNN
n+ n+ n+ n+ n+F n+ n+ n+b|2 |2 |2 |2 |2 |2 |2 |2~[ [ [ [ [F [ [ [|
_ _ _ _ _V _ _ _DQ Q Q Q Q Q Q Qhp p p p p6 p p pf	f f f f f f f fR=7 =7 =7 =7 =7 =7 =7 =7@n, n, n, n, n, n, n, n,bV6 V6 V6 V6 V6v V6 V6 V6r! ! ! ! !f ! ! !" " "  Bh h h h hr   