ó
    cÛ–iÆ€  ã                   óœ  • S r SSKrSSKrSSKrSSKrSSKJr  SSKJrJr  SSK	J
r
JrJr  SSK	r	SSKJrJrJrJrJrJr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKrSr Sr!Sr"Sr#Sr$Sr%Sr&\'" / SQ5      r( " S S\)5      r*S r+S r,S+S jr-S r.S+S jr/S r0S r1S r2S r3S r4S  r5S! r6S" r7S# r8S$ r9S% r:S& r;S' r<S( r=S) r>S* r?g),z>Helpers used for upgrading between different database formats.é    N)Úcmp)ÚLdbÚversion)ÚSCOPE_SUBTREEÚSCOPE_ONELEVELÚ
SCOPE_BASE)Úprovision_paths_from_lpÚgetpolicypathÚcreate_gpo_structÚ	provisionÚProvisioningErrorÚsecretsdb_self_join)Ú	FILL_FULL)Údrsblobs)ÚSEC_CHAN_BDC)Ú
ndr_unpack)ÚSamDB)Ú_glueéÿÿÿÿé   é   é   é   éÿ   )ÚdnÚwhenCreatedÚwhenChangedÚ
objectGUIDÚ
uSNCreatedÚreplPropertyMetaDataÚ
uSNChangedÚ
parentGUIDÚobjectCategoryÚdistinguishedNameÚnTMixedDomainÚshowInAdvancedViewOnlyÚinstanceTypezmsDS-Behavior-VersionÚnextRidÚcnÚversionNumberÚlmPwdHistoryÚ
pwdLastSetÚntPwdHistoryÚ
unicodePwdÚdBCSPwdÚsupplementalCredentialsÚgPCUserExtensionNamesÚgPCMachineExtensionNamesÚ	maxPwdAgeÚsecretÚpossibleInferiorsÚ	privilegeÚsAMAccountTypec                   ó2   • \ rS rSrS rS rS rS rS rSr	g)	ÚProvisionLDBéD   c                 ót   • S U l         S U l        S U l        S U l        S U l        S U l        S U l        S U l        g ©N)ÚsamÚsecretsÚidmapr6   ÚhkcrÚhkcuÚhkuÚhklm©Úselfs    Ú6/usr/lib/python3/dist-packages/samba/upgradehelpers.pyÚ__init__ÚProvisionLDB.__init__F   s:   € ØˆŒØˆŒØˆŒ
ØˆŒØˆŒ	ØˆŒ	ØˆŒØˆ�	ó    c                 ó^   • U R                   U R                  U R                  U R                  4$ r<   )r=   r>   r?   r6   rD   s    rF   ÚdbsÚProvisionLDB.dbsP   s!   € Ø—‘˜$Ÿ,™,¨¯
©
°D·N±NÐCÐCrI   c                 óR   • U R                  5        H  nUR                  5         M     g r<   )rK   Útransaction_start©rE   Údbs     rF   ÚstartTransactionsÚProvisionLDB.startTransactionsS   s   € Ø—(‘(–*ˆBØ× Ñ Ö"ò rI   c                 ó€   • SnU R                  5        H  n UR                  5         M     U$ ! [         a    Sn M)  f = f)NTF)rK   Útransaction_cancelÚ	Exception)rE   ÚokrP   s      rF   ÚgroupedRollbackÚProvisionLDB.groupedRollback\   sE   € ØˆØ—(‘(–*ˆBðØ×%Ñ%Ö'ñ ð
 ˆ	øô ó Ø“ðús   —-­=¼=c                 ó$  •  U R                  5        H  nUR                  5         M      U R                  5        H  nUR	                  5         M     g! [         a    U R                  5       s $ f = f! [         a    U R                  5       s $ f = f)NT)rK   Útransaction_prepare_commitrU   rW   Útransaction_commitrO   s     rF   ÚgroupedCommitÚProvisionLDB.groupedCommitj   sˆ   € ð	*Ø—h‘h–j�Ø×-Ñ-Ö/ñ !ð	*Ø—h‘h–j�Ø×%Ñ%Ö'ñ !ð øô% ó 	*Ø×'Ñ'Ó)Ò)ð	*ûô ó 	*Ø×'Ñ'Ó)Ò)ð	*ús"   ‚'A ª'A2 ÁA/Á.A/Á2BÂB)r@   rA   rC   rB   r?   r6   r=   r>   N)
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__rG   rK   rQ   rW   r\   Ú__static_attributes__© rI   rF   r9   r9   D   s   † òòDò#òõrI   r9   c           	      óò   • [        5       n[        U R                  UUUS/SS9Ul        [	        U R
                  X!US9Ul        [	        U R                  X!US9Ul        [	        U R                  X!US9Ul        U$ )au  Return LDB object mapped on most important databases

:param paths: An object holding the different importants paths for provision object
:param creds: Credential used for opening LDB files
:param session: Session to use for opening LDB files
:param lp: A loadparam object
:return: A ProvisionLDB object that contains LDB object for the different LDB files of the provisionzmodules:samba_dsdbr   )Úsession_infoÚcredentialsÚlpÚoptionsÚflags)re   rf   rg   )	r9   r   Úsamdbr=   r   r>   Úidmapdbr?   r6   )ÚpathsÚcredsÚsessionrg   Úldbss        rF   Úget_ldbsrp   ƒ   sw   € ô ‹>€Dä�U—[‘[Ø")Ø!&ØØ2Ð3Øñ€D„Hô �u—}‘}°7ÐRTÑU€D„LÜ�U—]‘]°ÐPRÑS€D„JÜ˜Ÿ™°wÐVXÑY€D„Nð €KrI   c                 óÈ   • SnSnSnU(       aT  U[        U5      :X  a  SnM  U [        X   5      :  a  US-  S:X  a  SnSnU [        X   5      :X  a  SnSnUS-   nU(       a  MT  U$ )a˜  Check if the usn is in one of the range provided.
To do so, the value is checked to be between the lower bound and
higher bound of a range

:param usn: A integer value corresponding to the usn that we want to update
:param range: A list of integer representing ranges, lower bounds are in
              the even indices, higher in odd indices
:return: True if the usn is in one of the range, False otherwise
r   TFr   r   )ÚlenÚint)ÚusnÚrangeÚidxÚcontrV   s        rF   Úusn_in_rangerx   Ÿ   s|   € ð €CØ€DØ	€BÞ
Ø”#�e“*ÓØˆDÙØ”�U‘Z“Ó Ø�Q‰w˜!‹|Ø�ØˆDØ”#�e‘j“/Ó!ØˆDØˆBØ�A‰gˆ÷ ˆ$ð €IrI   c                 ót  • Ub´  [         R                  R                  U5      (       d  [         R                  " U5        [         R                  R	                  US5      n[         R                  R                  U5      (       d  [         R
                  " U5        [         R                  R	                  US5      nUc  U R                  5       n[         R                  R                  U5      (       d  [        SU-  5      eU R                  5       nUR                  U5        [        XDR                  S5      5      nU$ )a  Get paths to important provision objects (smb.conf, ldb files, ...)

:param param: Param object
:param targetdir: Directory where the provision is (or will be) stored
:param smbconf: Path to the smb.conf file
:return: A list with the path of important provision objectsÚetczsmb.confzUnable to find smb.conf at %sÚrealm)ÚosÚpathÚexistsÚmkdirÚjoinÚmakedirsÚdefault_pathr   ÚLoadParmÚloadr	   Úget)ÚparamÚ	targetdirÚsmbconfÚetcdirrg   rl   s         rF   Ú	get_pathsrŠ   ¼   sÖ   € ð ÑÜ�w‰w�~‰~˜i×(Ñ(Ü�HŠH�YÔÜ—‘—‘˜i¨Ó/ˆÜ�w‰w�~‰~˜f×%Ñ%Ü�KŠK˜ÔÜ—'‘'—,‘,˜v zÓ2ˆØ�Ø×$Ñ$Ó&ˆä�7‰7�>‰>˜'×"Ñ"ÜÐ ?À'Ñ IÓJÐJà	�‰Ó	€BØ‡G�GˆGÔÜ# B¯©¨w«Ó8€EØ€LrI   c                 óÂ  • UR                  SS[        U R                  5      -   [        SS/S9n[        US   S   5      R	                  SS5      R	                  S	S5      U l        UR                  S
S[        U R                  5      -   [        SS/S9n[        U5      S:X  a7  [        US   S   5      R	                  SS5      R	                  S	S5      U l        gSU l        g)z¢Update policy ids that could have changed after sam update

:param names: List of key provision parameters
:param samdb: An Ldb object conntected with the sam DB
z#(displayName=Default Domain Policy)zCN=Policies,CN=System,r)   ÚdisplayName©Ú
expressionÚbaseÚscopeÚattrsr   Ú{Ú Ú}z/(displayName=Default Domain Controllers Policy)r   N)ÚsearchÚstrÚrootdnr   ÚreplaceÚpolicyidrr   Úpolicyid_dc)Únamesrj   ÚresÚres2s       rF   Úupdate_policyidsrž   Ö   sÞ   € ð �,‰,Ð"GØ4´s¸5¿<¹<Ó7HÑHÜ+°D¸-Ð3Hð ð J€Cô ˜˜Q™ ™Ó&×.Ñ.¨s°BÓ7×?Ñ?ÀÀRÓH€E„Nà�<‰<ð $.à5¼¸E¿L¹LÓ8IÑIÜ,°T¸=Ð4Ið ð K€Dô ˆ4ƒy�Aƒ~Ü  Q¡¨¡Ó.×6Ñ6°s¸BÓ?×GÑGÈÈRÓPˆÕà ˆÕrI   c                 ó–  • [         R                  R                  U5      (       a  [        R                  " U5        [         R
                  " U5        UR                  SU5        [        XA40 SU_SU_S[        _SU R                  _SU R                  _SU R                  _SU R                  _S	U R                  _S
U R                  _SU R                  _SU R                   R#                  5       _SS_SS_SU R$                  _SU R&                  _SS_SS_SS_SS_SS_SS_SS_SU R(                  _SU R*                  _SS_SS_SU_S U_6$ )!a�  Create a new provision.

This provision will be the reference for knowing what has changed in the
since the latest upgrade in the current provision

:param names: List of provision parameters
:param creds: Credentials for the authentication
:param session: Session object
:param smbconf: Path to the smb.conf file
:param provdir: Directory where the provision will be stored
:param logger: A Logger
zProvision stored in %srˆ   r‡   Ú
samdb_fillr{   ÚdomainÚ
domainguidÚ	domainsidÚntdsguidÚ
policyguidÚpolicyguid_dcÚhostnameÚhostipNÚhostip6ÚinvocationidÚ	adminpassÚ
krbtgtpassÚmachinepassÚdnspassÚrootÚnobodyÚusersÚ
serverrolezdomain controllerÚdom_for_fun_levelÚdns_backendÚuseeadbTÚ	use_ntvfsÚbase_schemaÚadprep_level)r|   r}   ÚisdirÚshutilÚrmtreer   Úinfor   r   r{   r¡   r¢   r£   r¤   r™   rš   ÚnetbiosnameÚlowerÚ
invocationr«   Údomainlevelr´   )r›   rn   rˆ   ÚprovdirÚloggerr·   r¸   s          rF   ÚnewprovisionrÃ   ì   s«  € ô 
‡w�w‡}�}�W×ÑÜ�Š�gÔÜ‡H‚HˆWÔØ
‡K�KÐ(¨'Ô2Ü�Vò 0©gð 0Ù&ð0Ý3<ð0ØDIÇKÂKð0à!ŸLšLð0à5:×5EÒ5Eð0ð  %Ÿšð0ð :?¿ºð0ð !&§¢ð	0ð ?D×>OÒ>Oð	0ð
 $×/Ñ/×5Ñ5Ô7ð0ñ
 AEð0ñ
 OSð0ð #(×"2Ò"2ð0ð ?D¿oºoð0ñ !%ð0ñ 37ð0ñ AEð0ñ LPð0ñ !ð0ñ )-ð0ñ !4ð0ð (-×'8Ò'8ð0ð GL×FWÒFWð0ñ "ð0ñ .2ð0ñ @Kð0ñ #/ð0ð 0rI   c                 óü  • [         R                  " S5      nUR                  [        U 5      5      nUR                  [        U5      5      n[	        [        U5      [        U5      5      n[        U5      S-
  n[        U5      S-
  n[        SU5       Hg  n[        X6U-
     XGU-
     5      n	U	S:w  a  U	s  $ X…S-
  :X  d  M-  Xg:w  d.   SSR                  U5      -   S-   SR                  U5      -   5       eXg:”  a    g  g   W	$ )zãSorts two DNs in the lexicographical order it and put higher level DN
before.

So given the dns cn=bar,cn=foo and cn=foo the later will be return as
smaller

:param x: First object to compare
:param y: Second object to compare
z
(?<!\\), ?r   r   zPB PB PBÚ z / r   )	ÚreÚcompileÚsplitr–   Úminrr   ru   r   r€   )
ÚxÚyÚpÚtab1Útab2ÚminimumÚlen1Úlen2ÚiÚrets
             rF   Údn_sortrÔ     sâ   € ô 	�
Š
�=Ó!€AØ�7‰7”3�q“6‹?€DØ�7‰7”3�q“6‹?€DÜ”#�d“)œS ›YÓ'€GÜˆt‹9�q‰=€DÜˆt‹9�q‰=€Dä�1�gÖˆÜ�$˜a‘x‘. $¨a¡x¡.Ó1ˆØ�!‹8ØŠJà˜a‘KÕØ“|ÐY Z°#·(±(¸4³.Ñ%@À5Ñ%HÈ3Ï8É8ÐTXË>Ñ%YÓY�|Ø“;Ùáñ ð €JrI   c           	      óú   • [        U5      R                  SS5      u  p#U R                  U[        R                  " X< SU< 35      S/5        U R                  [        R                  " X< SU< 35      US/5        g)zªPerform a back and forth rename to trigger renaming on attribute that
can't be directly modified.

:param lbdobj: An Ldb Object
:param dn: DN of the object to manipulate
Ú=r   z=foozrelax:0N)r–   rÈ   ÚrenameÚldbÚDn)Úldbobjr   ÚbeforeÚafters       rF   Úidentic_renamerÝ   +  s^   € ô ˜"“g—m‘m C¨Ó+�O€Và
‡M�M�"”c—f’f˜V²6º5Ð%AÓBÀYÀKÔPØ
‡M�M”#—&’&˜ªv²uÐ!=Ó>ÀÀYÀKÕPrI   c           
      ó†	  • U" [         S5        U R                  S[        S9nUR                  S[        S9nU(       d   S5       e[        U5      S:X  aj  UR	                  [
        R                  " 5       US   5      nUS   R                  R                  UR
                  5      Ul        UR                  US   5        O=UR	                  US   US   5      nUS   R                  Ul        UR                  U5        U R                  SS[        S/S	9nUR                  SS[        S/S	9n0 n0 n/ n/ n	[
        R                  " 5       n
[        S[        U5      5       H)  nX;   S   U[        X;   S   5      R                  5       '   M+     [        S[        U5      5       H)  nXK   S   U[        XK   S   5      R                  5       '   M+     UR                  5        H0  nXÇ;  a  UR!                  Xl   5        M  U	R!                  Xl   5        M2     U HÁ  nU R                  S
U-  S[        S9nUR	                  X£S   5      n["         H  nUR%                  U5        M     U" [&        SUS   R                  -  5        U H  nU" [&        SU-  5        M     US   R                  R                  UR
                  5      Ul        UR                  U5        MÃ     U	 HÀ  nU R                  S
U-  S[        S9nUR                  S
U-  S[        S9nUR	                  US   US   5      n["         H  nUR%                  U5        M     U HQ  nUS:X  a7  U" [&        SUS   R                  -  5        [)        XS   R                  5        M@  UR%                  U5        MS     MÂ     U	 HØ  nU R                  S
U-  S[        S9nUR                  S
U-  S[        S9nUR	                  US   US   5      n["         H  nUR%                  U5        M     U HD  nUS:X  a  UR%                  U5        US:w  d  M"  U" [&        SU< SUS   R                  < 35        MF     US   R                  Ul        UR                  U5        MÚ     UR                  S[        S/S9n[        U5      S:X  a%  U" [         S5        UR+                  US   S   5        gg)záUpdate secrets.ldb

:param newsecrets_ldb: An LDB object that is connected to the secrets.ldb
    of the reference provision
:param secrets_ldb: An LDB object that is connected to the secrets.ldb
    of the updated provision
zUpdate of secrets.ldbz@MODULES)r�   r�   z'Reference modules list can not be emptyr   zobjectClass=topr“   r   r�   údistinguishedName=%s)rŽ   r�   r�   z$Entry %s is missing from secrets.ldbz Adding attribute %sÚnamez/Found attribute name on  %s, must rename the DNúmsDS-KeyVersionNumberzAdding/Changing attribute z to z(samaccountname=dns))rŽ   r�   r‘   r   zRemove old dns accountN)ÚSIMPLEr•   r   rr   Úmsg_diffrØ   ÚMessager   ÚcopyÚaddÚmodifyr   ru   r–   r¾   ÚkeysÚappendÚhashAttrNotCopiedÚremoveÚCHANGErÝ   Údelete)Únewsecrets_ldbÚsecrets_ldbÚmessagefuncÚ	referenceÚcurrentÚdeltaÚhash_newÚhashÚlistMissingÚlistPresentÚemptyrÒ   ÚkÚentryÚattr�   s                   rF   Úupdate_secretsrü   8  s¨  € ñ ”Ð/Ô0Ø×%Ñ%¨:¼ZÐ%ÐH€IØ× Ñ  j¼
Ð ÐC€GÞÐ?Ð?Ó?ˆ9Ü
ˆ7ƒ|�qÓà×$Ñ$¤S§[¢[£]°I¸a±LÓAˆØ˜Q‘<—?‘?×'Ñ'¨¯	©	Ó2ˆŒØ�‰˜	 !™Õ%à×$Ñ$ W¨Q¡Z°¸1±Ó>ˆØ˜1‘:—=‘=ˆŒØ×Ñ˜5Ô!à×%Ñ%Ð1BÈÜ,9À$Àð &ð I€Ià× Ñ Ð,=ÀBÜ'4¸T¸Fð !ð D€Gà€HØ€DØ€KØ€Kä�KŠK‹M€EÜ�1”c˜)“nÖ%ˆØ4=±LÀÑ4Fˆ”�Y‘\ $Ñ'Ó(×.Ñ.Ó0Ó1ñ &ô
 �1”c˜'“lÖ#ˆØ.5©j¸Ñ.>ˆŒS�‘˜DÑ!Ó"×(Ñ(Ó*Ó+ñ $ð �]‰]Ž_ˆØ‹=Ø×Ñ˜x™{Ö+à×Ñ˜x™{Ö+ñ	 ó ˆØ"×)Ñ)Ð5KÈeÑ5SØ/1¼ð *ð Hˆ	à×$Ñ$ U°a©LÓ9ˆß$ˆCØ�L‰L˜Öñ %á”FÐBØ˜a‘L—O‘Oñ$ô 	%ãˆCÙœÐ 6¸Ñ <Ö=ñ à˜Q‘<—?‘?×'Ñ'¨¯	©	Ó2ˆŒØ�‰˜Öñ ó ˆØ"×)Ñ)Ð5KÈeÑ5SØ/1¼ð *ð Hˆ	à×$Ñ$Ð0FÈÑ0NÐUWÜ+8ð %ð :ˆà×$Ñ$ W¨Q¡Z°¸1±Ó>ˆß$ˆCØ�L‰L˜Öñ %ãˆCØ�f‹}ÙœFð %:Ø=DÀQ¹Z¿]¹]ñ%Lô Mä˜{°a©L¯O©OÖ<à—‘˜SÖ!ó ñ ó  ˆØ"×)Ñ)Ð5KÈeÑ5SÐZ\Ü0=ð *ð ?ˆ	à×$Ñ$Ð0FÈÑ0NÐUWÜ+8ð %ð :ˆà×$Ñ$ W¨Q¡Z°¸1±Ó>ˆß$ˆCØ�L‰L˜Öñ %ãˆCØÐ-Ó-Ø—‘˜SÔ!Ø�d�{Ù�Fã  '¨!¡*§-£-ð1ö2ñ	 ð ˜1‘:—=‘=ˆŒØ×Ñ˜5Ö!ñ# ð& ×ÑÐ)?Ü$1¸$¸ð ð A€Dô ˆ4ƒy�Aƒ~ÙœÐ 8Ô9Ø×Ñ˜t A™w t™}Õ-ð rI   c                 óª   • U R                  S[        U5      [        SS/S9n[        U5      S:”  a#  US   R	                  S5      (       a
  US   S   nU$ g)zæReturn OEM Information on the top level Samba4 use to store version
info in this field

:param samdb: An LDB object connect to sam.ldb
:param rootdn: Root DN of the domain
:return: The content of the field oEMInformation (if any)
ú(objectClass=*)r   ÚoEMInformationr�   r   r“   )r•   r–   r   rr   r…   )rj   r—   rœ   r¼   s       rF   Ú
getOEMInfor   Ÿ  sa   € ð �,‰,Ð"3¼#¸f»+Ü'°Ð6FÐ/Gð ð I€Cä
ˆ3ƒx�!ƒ|˜˜A™Ÿ
™
Ð#3×4Ñ4Ø�1‰vÐ&Ñ'ˆØˆàrI   c                 ó¼  • U R                  SU[        SS/S9n[        U5      S:”  aµ  US   R                  S5      (       a  [	        US   S   5      nOSnU< S[
        < 3n[        R                  " 5       n[        R                  " U [	        US   S   5      5      Ul	        [        R                  " U[        R                  S5      US'   U R                  U5        gg)	zÐUpdate the OEMinfo field to add information about upgrade

:param samdb: an LDB object connected to the sam DB
:param rootdn: The string representation of the root DN of
    the provision (ie. DC=...,DC=...)
rþ   r   rÿ   r�   r   r“   z, upgrade to N)r•   r   rr   r…   r–   r   rØ   rä   rÙ   r   ÚMessageElementÚFLAG_MOD_REPLACErç   )rj   r—   rœ   r¼   ró   s        rF   ÚupdateOEMInfor  °  sÉ   € ð �,‰,Ð"3¸&Ü'°Ð6FÐ/Gð ð I€Cä
ˆ3ƒx�!ƒ|Øˆq‰6�:‰:Ð&×'Ñ'Ü�s˜1‘vÐ.Ñ/Ó0‰DàˆDÛ&*®GÐ4ˆÜ—’“ˆÜ—6’6˜%¤ S¨¡V¨D¡\Ó!2Ó3ˆŒÜ"%×"4Ò"4°T¼3×;OÑ;OØ5Eó#GˆÐÑà�‰�UÕð rI   c                 óž  • [        U R                  UR                  UR                  5      n[        R
                  R                  U5      (       d  [        U5        UR                  c  [        S5      e[        U R                  UR                  UR                  5      n[        R
                  R                  U5      (       d  [        U5        gg)z-Create missing GPO file object if needed
    Nz*Policy ID for Domain controller is missing)
r
   ÚsysvolÚ	dnsdomainr™   r|   r}   r¹   r   rš   r   )rl   r›   Údirs      rF   Ú
update_gpor	  Æ  s�   € ô ˜Ÿ™ e§o¡o°u·~±~Ó
F€CÜ�7‰7�=‰=˜×ÑÜ˜#Ôà×ÑÑ ÜÐ LÓMÐMÜ
˜Ÿ™ e§o¡o°u×7HÑ7HÓ
I€CÜ�7‰7�=‰=˜×ÑÜ˜#Õð rI   c           	      ó>  • U R                  S[        R                  " U [        U5      5      [        S/S/S9nSn[        U5      S:X  a  [        S5      eU HÄ  n[        UR                  5      R                  5       U;   d  M,  UR                  S5      nU(       d  Sn[        [        U[        UR                  5      R                  5          5      5      n[        [        U5      5      U:  d  M˜  US-   nU R                  [        UR                  5      S	US
5        MÆ     g)aì  For a given hash associating dn and a number, this function will
update the replPropertyMetaData of each dn in the hash, so that the
calculated value of the msDs-KeyVersionNumber is equal or superior to the
one associated to the given dn.

:param samdb: An SamDB object pointing to the sam
:param rootdn: The base DN where we want to start
:param hashDns: A hash with dn as key and number representing the
             minimum value of msDs-KeyVersionNumber that we want to
             have
z(objectClass=user)zmsDs-KeyVersionNumberúsearch_options:1:2©rŽ   r�   r�   r‘   Úcontrolsr   z$Unable to find msDs-KeyVersionNumberÚ0r   r.   TN)r•   rØ   rÙ   r–   r   rr   r   r   r¾   r…   rs   Ú"set_attribute_replmetadata_version)rj   r—   ÚhashDnsrú   ÚdoneÚeÚvalr   s           rF   Ú&increment_calculated_keyversion_numberr  Ô  sî   € ð �L‰LÐ$8Ü!Ÿfšf U¬C°«KÓ8Ü,Ð5LÐ4MØ#7Ð"8ð ð :€Eð €DÜ
ˆ5ƒz�QƒÜÐ FÓGÐGãˆAÜ�1—4‘4‹y�‰Ó  GÕ+Ø—e‘eÐ3Ó4�ÞØ�CÜœc '¬#¨a¯d©d«)¯/©/Ó*;Ñ"<Ó=Ó>�Ü”s˜3“x“= 7Õ*Ø !™8�DØ×<Ñ<¼SÀÇÁ»YØ=IØ=DÀdöLò rI   c                 óæ  • U" [         S5        [        XUUS/S9n[        XX$S/S9n[        R                  " 5       nSn	UR	                  SS9n
U
 GH  nUR	                  SUS   -  [
        S	9n[        U5      (       dâ  UR                  X‹5      nU" [        S
[        UR                  5      -  5        [        UR                  5      S:X  aW  UR                  [        R                  R                  5      (       a)  UR                  [        R                  R                  5        UR                  R!                  UR                  5      Ul
        UR#                  U5        GM  UR                  US   U5      n[        UR                  5      S:X  a  UR                  X¼S   5      n	[        UR                  5      S:X  aW  UR                  [        R                  R                  5      (       a)  UR                  [        R                  R                  5        [        UR%                  5       5      S:”  d  GMâ  UR                  R!                  UR                  5      Ul
        UR'                  U5        GM      U	$ )aá  Update the provision container db: sam.ldb
This function is aimed for alpha9 and newer;

:param refsampath: Path to the samdb in the reference provision
:param sampath: Path to the samdb in the upgraded provision
:param creds: Credential used for opening LDB files
:param session: Session to use for opening LDB files
:param lp: A loadparam object
:return: A msg_diff object with the difference between the @ATTRIBUTES
         of the current provision and the reference provision
z<Update base samdb by searching difference with reference onezmodules:)re   rf   rg   rh   Nr“   ©rŽ   rß   r   )rŽ   r�   zAdding %s to sam dbz
@PROVISIONr   z@ATTRIBUTESr   )râ   r   rØ   rä   r•   r   rr   rã   rì   r–   r   r…   Úsambar   ÚLAST_PROVISION_USN_ATTRIBUTErë   rå   ræ   Úitemsrç   )Ú
refsampathÚsampathrm   rn   rg   ÚmessageÚrefsamr=   rø   Ú	deltaattrrñ   Úrefentryrú   ró   s                 rF   Údelta_update_basesamdbr   õ  sÕ  € ñ ŒFØJôLä�¸uØ  ñ.€Fä
ˆg¸Ø!�lñ$€Cô �KŠK‹M€EØ€IØ—‘¨�Ð,€IäˆØ—
‘
Ð&<¸xÈ¹~Ñ&MÜ!.ð ð 0ˆä�5�z‰zØ—L‘L Ó1ˆEÙ”FÐ1´C¸¿¹Ó4DÑDÔEÜ�8—;‘;Ó <Ó/Ø—I‘IœeŸo™o×JÑJ×KÑKØ—‘œUŸ_™_×IÑIÔJØ—{‘{×'Ñ'¨¯	©	Ó2ˆEŒHØ�G‰G�E�Nà—L‘L  q¡¨8Ó4ˆEÜ�8—;‘;Ó =Ó0ØŸL™L¨¸±8Ó<�	Ü�8—;‘;Ó <Ó/Ø—I‘IœeŸo™o×JÑJ×KÑKØ—‘œUŸ_™_×IÑIÔJÜ�5—;‘;“=Ó! AÖ%Ø#Ÿ;™;×+Ñ+¨E¯I©IÓ6�”Ø—
‘
˜5×!ñ) ð, ÐrI   c                 ó\   • Sn[        U 5      S:”  a  SnU  H  nU< SU< S3nM     SU-  nU$ )zæConstruct a exists or LDAP search expression.

:param attrs: List of attribute on which we want to create the search
    expression.
:return: A string representing the expression, if attrs is empty an
    empty string is returned
r“   r   z(|Ú(z=*)z%s))rr   )r‘   Úexprrû   s      rF   Úconstruct_existor_exprr$  &  s;   € ð €DÜ
ˆ5ƒz�Aƒ~ØˆÛˆCÛ $£cÐ*ŠDñ à�d‰{ˆØ€KrI   c                 ó  • SUR                   -  nUR                  US/S9n[        US   S   S   5      [        :X  GaF  U R                  U/ S9n[	        U5      S:X  d   e[
        R                  " US   R                  5      n[        R                  " SS5      nUR                  S5      n[
        R                  " U[
        R                  S5      US'   U R                  U5        U R                  SUR                   -  S	/S9n[	        U5      S:X  d   e[        [        US   S	   5      5      n	[        US   S   S   5      n
[        XR                   UR"                  UR$                  UR&                  UR                   UU	U
S
9	  g[)        S5      e)a>  Update (change) the password of the current DC both in the SAM db and in
   secret one

:param samdb: An LDB object related to the sam.ldb file of a given provision
:param secrets_ldb: An LDB object related to the secrets.ldb file of a given
                    provision
:param names: List of key provision parameterszsamAccountName=%s$ÚsecureChannelType©rŽ   r‘   r   r   éx   ú	utf-16-leÚclearTextPasswordúmsDs-keyVersionNumber)r¡   r{   r£   r  r½   r­   Úkey_version_numberÚsecure_channel_typez3Unable to find a Secure Channelof type SEC_CHAN_BDCN)r½   r•   rs   r   rr   rØ   rä   r   r  Ú generate_random_machine_passwordÚencoder  r  rç   r–   r   r¡   r{   r£   r  r   )rj   rï   r›   rŽ   Úsecrets_msgrœ   Úmsgr­   Úmputf16ÚkvnoÚsecChanTypes              rF   Úupdate_machine_account_passwordr5  7  s�  € ð &¨×(9Ñ(9Ñ9€JØ×$Ñ$°
Ø,?Ð+@ð %ð B€Kä
ˆ;�q‰>Ð-Ñ.¨qÑ1Ó2´lÔBØ�l‰l j¸ˆlÐ;ˆÜ�3‹x˜1‹}Ðˆ}ä�kŠk˜#˜a™&Ÿ)™)Ó$ˆÜ×<Ò<¸SÀ#ÓFˆØ×$Ñ$ [Ó1ˆÜ#&×#5Ò#5°gÜ69×6JÑ6JØ6Ió$KˆÐÑ ð 	�‰�SÔà�l‰lÐ';¸e×>OÑ>OÑ'OØ"9Ð!:ð ð <ˆä�3‹x˜1‹}Ðˆ}Ü”3�s˜1‘vÐ5Ñ6Ó7Ó8ˆÜ˜+ a™.Ð)<Ñ=¸aÑ@ÓAˆä˜K·±Ø"'§+¡+Ø&+§o¡oØ&+§o¡oØ(-×(9Ñ(9Ø(3Ø/3Ø0;ó	=ô  ð !7ó 8ð 	8rI   c                 ó   • SUR                   -  nUR                  US9n[        U5      S:X  Ga`  U R                  U/ S9n[        U5      S:X  d   e[        R                  " US   R
                  5      n[        R                  " SS5      nUR                  S5      n[        R                  " U[        R                  S	5      US	'   U R                  U5        U R                  US
/S9n[        U5      S:X  d   e[        US   S
   5      n	[        R                  " US   R
                  5      n[        R                  " U[        R                  S5      US'   [        R                  " U	[        R                  S5      US'   UR                  U5        gg)a7  Update (change) the password of the dns both in the SAM db and in
   secret one

:param samdb: An LDB object related to the sam.ldb file of a given provision
:param secrets_ldb: An LDB object related to the secrets.ldb file of a given
                    provision
:param names: List of key provision parameterszsamAccountName=dns-%sr  r   r'  r   é€   r   r)  r*  r+  r4   rá   N)r½   r•   rr   rØ   rä   r   r  Úgenerate_random_passwordr/  r  r  rç   r–   )
rj   rï   r›   rŽ   r0  rœ   r1  r­   r2  r3  s
             rF   Úupdate_dns_account_passwordr9  b  sv  € ð )¨5×+<Ñ+<Ñ<€JØ×$Ñ$°
Ð$Ð;€KÜ
ˆ;Ó˜1ÔØ�l‰l j¸ˆlÐ;ˆÜ�3‹x˜1‹}Ðˆ}ä�kŠk˜#˜a™&Ÿ)™)Ó$ˆÜ×4Ò4°S¸#Ó>ˆØ×$Ñ$ [Ó1ˆÜ#&×#5Ò#5°gÜ69×6JÑ6JØ6Ió$KˆÐÑ ð 	�‰�SÔà�l‰l jØ"9Ð!:ð ð <ˆä�3‹x˜1‹}Ðˆ}Ü�3�q‘6Ð1Ñ2Ó3ˆä�kŠk˜+ a™.×+Ñ+Ó,ˆÜ×*Ò*¨;Ü+.×+?Ñ+?Ø+3ó5ˆˆH‰ô (+×'9Ò'9¸$Ü:=×:NÑ:NØ:Qó(SˆÐ#Ñ$ð 	×Ñ˜3Õð5 rI   c                 óT  • SnU R                  U/ S9n[        U5      S:X  d   e[        R                  " US   R                  5      n[
        R                  " SS5      nUR                  S5      n[        R                  " U[        R                  S5      US'   U R                  U5        g	)
z€Update (change) the password of the krbtgt account

:param samdb: An LDB object related to the sam.ldb file of a given provisionzsamAccountName=krbtgtr'  r   r   r7  r   r)  r*  N)r•   rr   rØ   rä   r   r  r.  r/  r  r  rç   )rj   rŽ   rœ   r1  r¬   Úkputf16s         rF   Úupdate_krbtgt_account_passwordr<  Š  s˜   € ð
 )€JØ
�,‰, *°Bˆ,Ð
7€CÜˆs‹8�q‹=Ðˆ=ä
�+Š+�c˜!‘f—i‘iÓ
 €Cô ×7Ò7¸¸SÓA€JØ×Ñ Ó,€GÜ"×1Ò1°'Ü25×2FÑ2FØ2Eó G€CÐÑð 
‡L�L�ÕrI   c           	      óö  • 0 n[        U5      nUS:X  a  U$ U R                  U[        R                  " U [	        U5      5      [
        USS/S9n[        U5      S:X  a  U$ U H•  nU HŒ  nUR                  U5      (       d  M  Xs;   a5  [	        Xg   5      X7   [	        UR                  5      R                  5       '   MU  0 X7'   [	        Xg   5      X7   [	        UR                  5      R                  5       '   MŽ     M—     U$ )a¬  Search a given sam DB for calculated attributes that are
still stored in the db.

:param samdb: An LDB object pointing to the sam
:param rootdn: The base DN where the search should start
:param attrs: A list of attributes to be searched
:return: A hash with attributes as key and an array of
         array. Each array contains the dn and the associated
         values for this attribute as they are stored in the
         sam.r“   r  zbypassoperational:0r  r   )
r$  r•   rØ   rÙ   r–   r   rr   r…   r   r¾   )rj   r—   r‘   ÚhashAttr#  rú   Úentrû   s           rF   Úsearch_constructed_attrs_storedr@     sà   € ð €GÜ! %Ó(€DØˆrƒzØˆØ�L‰L D¬s¯vªv°e¼SÀ»[Ó/IÜ,°EØ#7Ð9NÐ"Oð ð Q€Eô ˆ5ƒz�QƒàˆãˆÛˆCØ�w‰w�s�|‹|Ø“>Ü8;¸C¹H»�G‘L¤ S§V¡V£×!2Ñ!2Ó!4Ó5à#%�G‘LÜ8;¸C¹H»�G‘L¤ S§V¡V£×!2Ñ!2Ó!4Ó5ó ñ ð €NrI   c                 ó  • Sn0 nU R                  US[        R                  S/S/S9nU GHÙ  nUS-   n[        [        R
                  [        US   5      5      R                  nUR                   GH�  n[        R                  " UR                  5      S-  nUR                  [        UR                  5      5      n	U	cA  0 n
UR                  U
S'   UR                  U
S	'   SU
S
'   [        UR                  5      /U
S'   0 n	OåU	R                  U5      n
U
c?  0 n
UR                  U
S'   UR                  U
S	'   SU
S
'   [        UR                  5      /U
S'   O’U
S   UR                  :”  a  UR                  U
S'   U
S	   UR                  :  a  UR                  U
S	'   [        UR                  5      U
S   ;  a2  U
S
   S-   U
S
'   U
S   R!                  [        UR                  5      5        X©U'   X“[        UR                  5      '   GM’     GMÜ     X24$ )aÕ  Find ranges of usn grouped by invocation id and then by timestamp
rouned at 1 minute

:param samdb: An LDB object pointing to the samdb
:param basedn: The DN of the forest

:return: A two level dictionary with invoication id as the
        first level, timestamp as the second one and then
        max, min, and number as subkeys, representing respectivily
        the maximum usn for the range, the minimum usn and the number
        of object with usn in this range.
r   zobjectClass=*r    r  )r�   rŽ   r�   r‘   r  r   é<   rÉ   ÚmaxÚnumÚlist)r•   rØ   r   r   r   ÚreplPropertyMetaDataBlobr–   ÚctrÚarrayr   Únttime2unixÚoriginating_change_timer…   Úoriginating_invocation_idÚoriginating_usnr   ré   )rj   ÚbasednÚnb_objÚhash_idrœ   r  ÚobjÚoÚminutestampÚhash_tsÚobs              rF   ÚfindprovisionrangerU  Ã  sþ  € ð €FØ€Gà
�,‰,˜F¨Ü ×.Ñ.Ø4Ð5Ø!5Ð 6ð ð 8€Cô
 ˆØ˜!‘ˆÜœ×:Ñ:Ü˜QÐ5Ñ6Ó7ó9ß9<¹ð 	ð —•ˆAä×+Ò+¨A×,EÑ,EÓFÈ"ÑLˆKØ—k‘k¤# a×&AÑ&AÓ"BÓCˆGà‰Ø�Ø×-Ñ-��5‘	Ø×-Ñ-��5‘	Ø��5‘	Ü! !§$¡$›i˜[��6‘
Ø‘à—[‘[ Ó-�Ø‘:Ø�BØ !× 1Ñ 1�B�u‘IØ !× 1Ñ 1�B�u‘IØ !�B�u‘IÜ"% a§d¡d£) �B�v’Jà˜%‘y 1×#4Ñ#4Ó4Ø$%×$5Ñ$5˜˜5™	Ø˜%‘y 1×#4Ñ#4Ó4Ø$%×$5Ñ$5˜˜5™	Ü §¡›I¨¨F©Ó3Ø$& u¡I°¡M˜˜5™	Ø˜6™
×)Ñ)¬#¨a¯d©d«)Ô4Ø#%�KÑ Ø8?”C˜×3Ñ3Ó4Ô5ô; ñ ðH ÐÐrI   c           
      ó  • SnU  GHX  nX   n/ nUR                  UR                  5       5        UR                  5         / n	U Hu  n
Xz   nUS   U:”  aG  [        R                  " [        R
                  " U
S-  5      5      n[        SXËS   US   US   4-  5        Xz   S   S:”  d  Md  U	R                  U
5        Mw     [        S[        U	5      5       HZ  nUS:w  d  M  X�   nX�S	-
     nXï-
  S	:X  d  M   [        X~   S   5      [        X   S   5      S	-   :X  d  MG  X~   S   X   S'   S
X~   S'   M\     U	 H)  n
Xz   nUR                  S5      b  M  SX[S   US   U4-  nM+     GM[     US:w  aŸ  [        R                  " USSS9u  nn[        5         [        S5        [        SU-  5        [        SU-  5        [        S[        U5      < SU< S35        SU< SU< 3n[        R                   " UU5        [        R"                  " U5        gg)aE  print the different ranges passed as parameter

:param dic: A dictionary as returned by findprovisionrange
:param limit_print: minimum number of object in a range in order to print it
:param dest: Destination directory
:param samdb_path: Path to the sam.ldb file
:param invoicationid: Invocation ID for the current provision
r“   rD  rB  z*%s # of modification: %d  	min: %d max: %drÉ   rC  iX  r   r   TÚskippedNz%slastProvisionUSN: %d-%d;%s
Úusnprovz.ldif)r  ÚprefixÚsuffixzFTo track the USNs modified/created by provision and upgrade proivsion,zM the following ranges are proposed to be added to your provision sam.ldb: 
%szdWe recommend to review them, and if it's correct to integrate the following ldif: %s in your sam.ldbz,You can load this file like this: ldbadd -H rÅ   Ú
zdn: @PROVISION
provisionnerID: )Úextendrè   Úsortr   Únttime2stringÚunix2nttimeÚprintré   ru   rr   rs   r…   ÚtempfileÚmkstempr–   r|   ÚwriteÚclose)ÚdicÚlimit_printÚdestÚ
samdb_pathrª   ÚldifÚidrS  Úsorted_keysÚkept_recordrù   rP  ÚdtrÒ   Úkey1Úkey2ÚfdÚfiles                     rF   Úprint_provision_rangesrr  ÿ  s  € ð €DäˆØ‘'ˆØˆØ×Ñ˜7Ÿ<™<›>Ô*Ø×ÑÔàˆÛˆAØ‘*ˆCØ�5‰z˜KÓ'Ü×(Ò(¬×):Ò):¸1¸r¹6Ó)BÓC�ÜÐCÀrÈuÉ:ØGJÈ5ÁzØGJÈ5ÁzðGSñ Sô Tð ‰z˜%Ñ  3Õ&Ø×"Ñ" 1Ö%ñ ô �qœ#˜kÓ*Ö+ˆAØ�A�vØ"‘~�Ø" q¡5Ñ)�Ø‘; !Õ#ä˜7™=¨Ñ/Ó0´C¸¹ÀeÑ8LÓ4MÐPQÑ4QÕQð 07©}¸UÑ/C˜™ eÑ,Ø37˜™ iÓ0ñ ,ó ˆAØ‘j�Ø—7‘7˜9Ó%Ó-Ø;¸tÈÁZØ?BÀ5¹zÈ2ð?Oñ O’Dô ñ= ðH ˆrƒzÜ×#Ò#¨°YÀwÑO‰ˆˆDÜŒÜÐVÔWÜÐ^ÐaeÑeÔfÜÐtÐw{Ñ{Ô|ÝÄcÈ*ÆoÓW[Ð\Õ]Û;GÊÐNˆÜ
�Š��TÔÜ
�Š��ð rI   c                 ó6   • [        U 5      nSUS-  US-	  4-  nU$ )z‡Display the int64 range stored in value as xxx-yyy

:param value: The int64 range
:return: A string of the representation of the range
z%d-%dl   ÿÿ é    )rs   )ÚvalueÚlvaluer–   s      rF   Úint64range2strrw  :  s*   € ô �‹Z€FØ
�V˜ZÑ'¨°"©Ð5Ñ
5€CØ€JrI   )NN)@Ú__doc__r|   rÆ   rº   r  Úsamba.commonr   r   r   rØ   r   r   r   Úsamba.provisionr	   r
   r   r   r   r   Úsamba.provision.commonr   Úsamba.dcerpcr   Úsamba.dcerpc.miscr   Ú	samba.ndrr   Úsamba.samdbr   r   ra  ÚERRORrâ   rì   ÚCHANGESDÚGUESSÚ	PROVISIONÚ	CHANGEALLÚsetrê   Úobjectr9   rp   rx   rŠ   rž   rÃ   rÔ   rÝ   rü   r   r  r	  r  r   r$  r5  r9  r<  r@  rU  rr  rw  rc   rI   rF   Ú<module>r‡     s   ðñ, Eã 	Û 	Û Û å ß ß 9Ñ 9Û 
÷2÷ 2õ -Ý !Ý *Ý  Ý Ý Û ð 	€Ø	€Ø	€Ø€Ø€Ø€	Ø€	áò Mó NÐ ô<�6ô <ò~ò8ô:ò4!ô,0ò@ò>
Qòd.òNò"ò,òLòB.òbò"(8òV% òPò, òF9òx8óvrI   