
    b6                     n    d dl Z d dlmZmZmZ d dlmZ d dlmZm	Z	  G d de
          Zd Zd
dZd	 ZdS )    N)Ldbldbread_and_sub_file)system_session)SamDBdsdb_Dnc                       e Zd ZdS )	LdifErrorN)__name__
__module____qualname__     >/usr/lib/python3/dist-packages/samba/kcc/ldif_import_export.pyr
   r
      s        Dr   r
   c                     |D ]:}|                      |t          j                  }|                    d|z             ;d S )Nz%s)
write_ldifr   CHANGETYPE_NONEwrite)samdbfresmsglstrs        r   write_search_resultr   !   sL      S%899	t r   c                 X   t           j                            |           rt          d| z            t	          | t                      |dg          }|                                 	 t          |d          }|                    |d           |r|	                    d|z             |                    d           n;# t          $ r.}|                                 t          d|d|          d}~ww xY w|                                 t          | t                      |	          }|S )
a  Routine to import all objects and attributes that are relevent
    to the KCC algorithms from a previously exported LDIF file.

    The point of this function is to allow a programmer/debugger to
    import an LDIF file with non-security relevent information that
    was previously extracted from a DC database.  The LDIF file is used
    to create a temporary abbreviated database.  The KCC algorithm can
    then run against this abbreviated database for debug or test
    verification that the topology generated is computationally the
    same between different OSes and algorithms.

    :param dburl: path to the temporary abbreviated db to create
    :param ldif_file: path to the ldif file to import
    z3Specify a database (%s) that doesn't already exist.zmodules:)urlsession_infolpoptionsNzfdn: @ROOTDSE
changetype: modify
replace: dsServiceName
dsServiceName: CN=NTDS Settings,%s
            zLdn: @MODULES
@LIST: rootdse,extended_dn_in,extended_dn_out_ldb,objectguid
-
zFailed to import z: )r   r   r   )ospathexistsr
   r   r   transaction_startr   add_ldifmodify_ldif	Exceptiontransaction_canceltransaction_commitr   )dburlr   	ldif_fileforced_local_dsatmpdbdataestrr   s           r   ldif_to_samdbr/   '   ss    
w~~e M   	
 E(8(8
|- - -E 
G D11tT""" 	$  #	# $ $ $ 	  	 	 	 	
  G G G  """iYYYEFFFG 

 e.*:*:rBBBELs   'AB= =
C5)C00C5c           
      N   	 t          |t                      ||          } n6# t          j        $ r$}|j        \  }}t          d|d|          d}~ww xY wt          j                            |          rt          d|z            	 t          |d          }n4# t          $ r'}	t          d|dt          |	                    d}	~	ww xY w	 g d}
d	|                                 z  }|                     |t          j        |
d
          }t          | ||           g d}
d	|                                 z  }|                     |t          j        |
d          }t          | ||           g d}
d|                                 z  }|                     |t          j        |
d          }t          | ||           |D ]R}t          |j                  }g d}
d|z  }|                     |t          j        |
          }t          | ||           Sg }|D ]}t          |j                  }g d}g d}
|                     |t          j        |
|z   d          }|D ]x}|                                D ]a}||v r[||         D ]R}t'          | |                    d                    }t          |j                  }||vr|                    |           Sbyt          | ||           |D ]N}t          |j                  }g d}
|                     |t          j        |
d          }t          | ||           Og d}
d|                                 z  }|                     |t          j        |
d          }t          | ||           g d}
d|                                 z  }|                     |t          j        |
dd g!          }t          | ||           g d"}
d|                                 z  }|                     |t          j        |
d#          }t          | ||           g d}
d|                                 z  }|                     |t          j        |
d$          }t          | ||           g d%}
d|                                 z  }|                     |t          j        |
d&          }t          | ||           g d'}
|D ]5}|                     |t          j        |
(          }t          | ||           6g d)}
d*}|                     |t          j        |
(          }t          j        | d+          |d,         _        t          | ||           n6# t          j        $ r$}|j        \  }}t          d-|d|          d}~ww xY w|                                 dS ).a  Routine to extract all objects and attributes that are relevent
    to the KCC algorithms from a DC database.

    The point of this function is to allow a programmer/debugger to
    extract an LDIF file with non-security relevent information from
    a DC database.  The LDIF file can then be used to "import" via
    the import_ldif() function this file into a temporary abbreviated
    database.  The KCC algorithm can then run against this abbreviated
    database for debug or test verification that the topology generated
    is computationally the same between different OSes and algorithms.

    :param dburl: LDAP database URL to extract info from
    :param ldif_file: output LDIF file name to create
    )r   r   credentialsr   zUnable to open sam database (z) : Nz/Specify a file (%s) that doesn't already exist.wzUnable to open ()objectClass
objectGUIDcnwhenChanged	objectSidEnabledsystemFlagsdnsRootnCNamezmsDS-NC-Replica-LocationszmsDS-NC-RO-Replica-LocationszCN=Partitions,%sz(objectClass=crossRef))basescopeattrs
expression)r3   r4   r5   r6   fSMORoleOwnerr9   msDS-Behavior-VersionzmsDS-EnabledFeaturez(objectClass=crossRefContainer))r3   r4   r5   r6   r9   zCN=Sites,%sz(objectClass=site))r3   r4   r5   r6   interSiteTopologyGeneratorinterSiteTopologyFailoverscheduler   zCN=NTDS Site Settings,%s)r<   r=   r>   )hasMasterNCszmsDS-hasMasterNCshasPartialReplicaNCszmsDS-HasDomainNCszmsDS-hasFullReplicaNCszmsDS-HasInstantiatedNCs)r3   r4   r5   r6   invocationIDr   zmsDS-isRODCrA   z(objectClass=nTDSDSA)utf8)r3   r4   r5   r6   r   whenCreatedenabledConnectionrD   transportType
fromServerr9   z(objectClass=nTDSConnection))r3   r4   r5   r6   r   namebridgeheadServerListBLtransportAddressAttributez$CN=Inter-Site Transports,CN=Sites,%sz (objectClass=interSiteTransport))r=   r>   r?   )
r3   r4   r5   r6   r9   r   rD   replIntervalsiteListcostz(objectClass=siteLink)zextended_dn:0)r=   r>   r?   controls)r3   r4   r5   r6   siteLinkListz(objectClass=siteLinkBridge)z(objectClass=serversContainer))r3   r4   r5   r6   r9   dNSHostNamemailAddressz(objectClass=server))	r3   r4   r5   r6   r7   r@   rA   repsFromrepsTo)r=   r>   )	r3   r4   r5   r6   rootDomainNamingContextconfigurationNamingContextschemaNamingContextdefaultNamingContextdsServiceName z@ROOTDSEr   zError processing ()r   r   r   LdbErrorargsr
   r    r!   r"   openIOErrorstrget_config_basednsearchSCOPE_SUBTREEr   dn
SCOPE_BASEkeysr   decodeappendDnclose)r   r)   r   credsr*   eenumr.   r   ioerrr>   sstrr   sitesr   sitestrnclistncattrsres_msgkvaluedsdndnstre1s                           r   samdb_to_ldif_filer}   \   s\   '%#1#3#3"'B0 0 0 < ' ' 'vti& ' ' 	''
 
w~~i   #I!" # # 	#NC   N N NiiiiULMMMNTE
1 
1 
1 "E$;$;$=$==llC,=!&&>  @ @
 	E1c***( ( ( "E$;$;$=$==llC,=!&&G  I I
 	E1c***      u66888$c.?#((<  > >
 	E1e,,,  	/ 	/C#&kkG     E .7D,,D%*  , ,C  q#....   %	/ %	/Csv;;D2 2 2G. . .E ,,D0A%*W_*A  C CC  	5 	5  5 5AG||%,QZ 5 5E $+5%,,v2F2F#G#GD$'LLE$F22 &e 4 4 45  q#....  	/ 	/Csv;;D
$ 
$ 
$E ,,D0A%**H  J JC  q#..... . . 6&&(()ll4s'8!&&H  J J
 	E1c***	 	 	 &&(()ll4s'8!&&>%4$5  7 7 	E1c***! ! ! u66888ll4s'8!&&D  F F
 	E1c***      u66888ll4s'8!&&F  H H
 	E1c***      u66888ll4s'8!&&<  > >
 	E1c***    	/ 	/D,,t3>%*  , ,C  q#...." " " ll4s~!&  ( ( F5*--A	 	E1c****< E E EwtiddCDDDE GGIIIIIsE   " AAA
B 
C%"CCR
U V*V		V)N)r    sambar   r   r   
samba.authr   samba.samdbr   r   r&   r
   r   r/   r}   r   r   r   <module>r      s   , 
			 - - - - - - - - - - % % % % % % & & & & & & & &	 	 	 	 		 	 	 	  2 2 2 2jw w w w wr   