ó
    cÛ–iò ã                   ó6  • S r SSKrSSKrSSKrSSKrSSKrSSKrSSKJrJr  SSK	J
r
Jr  SSKJrJr  SSKJr  SSKJrJr  SSKJr  SS	KJr  SS
KJr  SSKJrJr  SSKrSrS r " S S\5      r " S S\5      r " S S\R<                  5      r " S S\ 5      r!g)z(Convenience functions for using the SAM.é    N)ÚdsdbÚdsdb_dns)Ú
ndr_unpackÚndr_pack)ÚdrsblobsÚmisc)Únormalise_int32)Ú	get_bytesÚcmp)Úsecurity)Úis_ad_dc_built)Ústring_is_guid)ÚNTSTATUSErrorÚntstatusÚrestructuredTextc                  ó   • g)NÚtdb© r   ó    Ú-/usr/lib/python3/dist-packages/samba/samdb.pyÚget_default_backend_storer   -   s   € Ør   c                   ó   • \ rS rSrSrg)Ú
SamDBErroré0   r   N©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__static_attributes__r   r   r   r   r   0   ó   † Úr   r   c                   ó   • \ rS rSrSrg)ÚSamDBNotFoundErroré3   r   Nr   r   r   r   r#   r#   3   r!   r   r#   c            
       óB  ^ • \ rS rSrSr0 r " S S5      rSSSSS\R                  SSSS4
U 4S jjr	SbU 4S jjr
S	 r\rS
 rS rS rS rS rS r  ScS jrS rS r   SdS jrS rS r   SeS jrS r  SfS jr         SgS jr               ShS jr   SiS jrS r SjS jr SkS jr!S r"S  r#\$" \#\"S!S"9r%S# r&\$" \&S$S"9r'S% r(S& r)\$" \)\(S'S"9r*S( r+ SkS) jr,S* r-S+ r.S, r/S- r0S. r1S/ r2S0 r3S1 r4S2 r5S3 r6S4 r7S5 r8S6 r9S7 r:S8 r;S9 r<SlS: jr=SlS; jr>S< r?S= r@S> rAS? rBS@ rCSA rD SkSB jrESC rFSD rGSE rHSF rISG rJSH rKSI rLSJ rMSK rNSL rOSM rPSN rQSO rRSP rSSmSQ jrTU 4SR jrUSS rVST rWSnSU jrXSV rYSW rZSX r[ SnSY jr\SZ r]S[ r^S\ r_S] r`S^ raS_ rbS` rcSardU =re$ )oÚSamDBé6   zThe SAM database.c                   ó&   • \ rS rSrS rS rS rSrg)ÚSamDB._CleanUpOnErroré;   c                 ó   • Xl         X l        g ©N)ÚsamdbÚdn)Úselfr-   r.   s      r   Ú__init__ÚSamDB._CleanUpOnError.__init__<   s   € ØŒJØ�Gr   c                 ó   • g r,   r   ©r/   s    r   Ú	__enter__ÚSamDB._CleanUpOnError.__enter__@   s   € Ør   c                 óT   • Ub%  U R                   R                  U R                  5        g)NF)r-   Údeleter.   )r/   Úexc_typeÚexc_valÚexc_tbs       r   Ú__exit__ÚSamDB._CleanUpOnError.__exit__C   s%   € ØÑ#ð —
‘
×!Ñ! $§'¡'Ô*ð r   )r.   r-   N)r   r   r   r   r0   r4   r;   r    r   r   r   Ú_CleanUpOnErrorr)   ;   s   † ò	ò	õ
	r   r=   NTc           
      óî   >• X l         U	(       d  S nOUc  Ub  UR                  5       nXl        [        TU ]  XUXEUUS9  U(       a  [
        R                  " U 5        U
b  [
        R                  " X
5        g g )N)ÚurlÚlpÚmodules_dirÚsession_infoÚcredentialsÚflagsÚoptions)r@   Ú	samdb_urlr?   Úsuperr0   r   Ú_dsdb_set_global_schemaÚ_dsdb_set_am_rodc)r/   r?   r@   rA   rB   rC   rD   rE   Úglobal_schemaÚauto_connectÚam_rodcÚ	__class__s              €r   r0   ÚSamDB.__init__O   sv   ø€ ð ŒÞØ‰CØ‰[˜R™^Ø—,‘,“.ˆCàŒä‰Ñ˜S°[Ø&2ÐSXØ!(ð 	ñ 	*ö Ü×(Ò(¨Ô.àÑÜ×"Ò" 4Õ1ð r   c                 óÆ   >• U R                   b?  [        R                  R                  U5      (       d  U R                   R	                  U5      nXl        [        TU ]  XUS9  g)zconnect to the databaseN)r?   rD   rE   )r@   ÚosÚpathÚexistsÚprivate_pathr?   rG   Úconnect)r/   r?   rD   rE   rM   s       €r   rT   ÚSamDB.connecte   sH   ø€ à�7‰7Ñ¤r§w¡w§~¡~°c×':Ñ':Ø—'‘'×&Ñ& sÓ+ˆCØŒä‰‰˜C°gˆÒ>r   c                 ó~   • U R                   (       a  S[        U 5      S SU R                    S3$ S[        U 5      S S3$ )Nz<SamDB Úxz (z)>z (no connection)>)r?   Úidr3   s    r   Ú__repr__ÚSamDB.__repr__m   s>   € Ø�8�8ØœR ›X a˜L¨¨4¯8©8¨*°BÐ7Ð7àœ˜D› !˜Ð$5Ð6Ð6r   c                 ó.   • [         R                  " U 5      $ )zreturn True if we are an RODC)r   Ú_am_rodcr3   s    r   rL   ÚSamDB.am_rodcu   s   € ä�}Š}˜TÓ"Ð"r   c                 ó.   • [         R                  " U 5      $ )z%return True if we are an PDC emulator)r   Ú_am_pdcr3   s    r   Úam_pdcÚSamDB.am_pdcy   s   € ä�|Š|˜DÓ!Ð!r   c                 ó4   • [        U R                  5       5      $ )zreturn the domain DN)ÚstrÚget_default_basednr3   s    r   Ú	domain_dnÚSamDB.domain_dn}   s   € ä�4×*Ñ*Ó,Ó-Ð-r   c                 ó4   • [        U R                  5       5      $ )zreturn the schema partition dn)rc   Úget_schema_basednr3   s    r   Ú	schema_dnÚSamDB.schema_dn�   s   € ä�4×)Ñ)Ó+Ó,Ð,r   c                 óX   • [         R                  R                  nU R                  XSS9  g)zeDisables an account

:param search_filter: LDAP filter to find the user (eg
    sAMAccountName=name)
T©ÚonN)Úsambar   ÚUF_ACCOUNTDISABLEÚtoggle_userAccountFlags©r/   Úsearch_filterrD   s      r   Údisable_accountÚSamDB.disable_account…   s&   € ô —
‘
×,Ñ,ˆØ×$Ñ$ ]¸dÐ$ÒCr   c                 óŽ   • [         R                  R                  [         R                  R                  -  nU R	                  XSS9  g)zdEnables an account

:param search_filter: LDAP filter to find the user (eg
    sAMAccountName=name)
Frl   N)rn   r   ro   ÚUF_PASSWD_NOTREQDrp   rq   s      r   Úenable_accountÚSamDB.enable_account�   s5   € ô —
‘
×,Ñ,¬u¯z©z×/KÑ/KÑKˆØ×$Ñ$ ]¸eÐ$ÒDr   c                 óâ  • U R                  U R                  5       [        R                  US/S9n[	        U5      S:X  a  [        SU-  5      e[	        U5      S:X  d   eUS   R                  n[        US   S   S   5      nU(       a%  U(       a  X‚-  (       a  SU-  n	[        U	5      eX‚-  n
O%U(       a  X‚-  (       d  SU-  n	[        U	5      eX‚) -  n
XŠ:X  a  gS	XxU
4-  nU R                  U5        g)
a7  Toggle_userAccountFlags

:param search_filter: LDAP filter to find the user (eg
    sAMAccountName=name)
:param flags: samba.dsdb.UF_* flags
:param on: on=True (default) => set, on=False => unset
:param strict: strict=False (default) ignore if no action is needed
         strict=True raises an Exception if...
ÚuserAccountControl©ÚbaseÚscopeÚ
expressionÚattrsr   z!Unable to find account where '%s'é   z Account flag(s) '%s' already setz"Account flag(s) '%s' already unsetNz|
dn: %s
changetype: modify
delete: userAccountControl
userAccountControl: %u
add: userAccountControl
userAccountControl: %u
)	Úsearchre   ÚldbÚSCOPE_SUBTREEÚlenÚ	Exceptionr.   ÚintÚmodify_ldif)r/   rr   rD   Ú	flags_strrm   ÚstrictÚresÚ
account_dnÚold_uacÚerrorÚnew_uacÚmods               r   rp   ÚSamDB.toggle_userAccountFlags™   sÿ   € ð �k‰k˜tŸ~™~Ó/´s×7HÑ7HØ%2Ð;OÐ:Pð ð Rˆäˆs‹8�q‹=ÜÐ CÀmÑ SÓTÐTÜ�3‹x˜1‹}Ðˆ}Ø˜‘V—Y‘Yˆ
ä�c˜!‘fÐ1Ñ2°1Ñ5Ó6ˆÞÞ˜7Ÿ?Ø:¸YÑF�Ü Ó&Ð&à‘o‰Gæ˜wŸØ<¸yÑH�Ü Ó&Ð&à Ñ&ˆGàÓØðð ˜GÐ$ñ%ˆð 	×Ñ˜Õr   c                 ó  • U R                  U R                  5       [        R                  U/ S9n[	        U5      S:X  a  [        SU-  5      e[	        U5      S:X  d   eUS   R                  nSU-  nU R                  U5        g)zxForces a password change at next login

:param search_filter: LDAP filter to find the user (eg
    sAMAccountName=name)
r{   r   úUnable to find user "%s"r€   z=
dn: %s
changetype: modify
replace: pwdLastSet
pwdLastSet: 0
N)r�   re   r‚   rƒ   r„   r…   r.   r‡   ©r/   rr   rŠ   Úuser_dnr�   s        r   Ú#force_password_change_at_next_loginÚ)SamDB.force_password_change_at_next_loginÆ   s‡   € ð �k‰k˜tŸ~™~Ó/´s×7HÑ7HØ%2¸"ð ð >ˆäˆs‹8�q‹=ÜÐ :¸]Ñ JÓKÐKÜ�3‹x˜1‹}Ðˆ}Ø�a‘&—)‘)ˆðð
 ñˆð 	×Ñ˜Õr   c                 ó  • U R                  U R                  5       [        R                  U/ S9n[	        U5      S:X  a  [        SU-  5      e[	        U5      S:w  a  [        SU-  5      eUS   R                  nSU-  nU R                  U5        g)z·Unlock a user account by resetting lockoutTime to 0.
This does also reset the badPwdCount to 0.

:param search_filter: LDAP filter to find the user (e.g.
    sAMAccountName=username)
r{   r   r’   r€   zUser "%s" is not uniquez?
dn: %s
changetype: modify
replace: lockoutTime
lockoutTime: 0
N)	r�   re   r‚   rƒ   r„   r#   r   r.   r‡   r“   s        r   Úunlock_accountÚSamDB.unlock_accountÛ   s—   € ð �k‰k˜tŸ~™~Ó/Ü #× 1Ñ 1Ø%2Ø "ð ð $ˆô ˆs‹8�q‹=Ü$Ð%?À-Ñ%OÓPÐPÜˆs‹8�q‹=ÜÐ6¸ÑFÓGÐGØ�a‘&—)‘)ˆðð
 ñˆð 	×Ñ˜Õr   c
                 óŒ  • U(       a  SU< SU< SU R                  5       < 3n
O6SU< SU R                  U R                  5       [        R                  5      < 3n
U
USS.nUb  [        U5      US'   Ub  XKS'   Ub  X[S'   Ub  XkS	'   Ub  [        U5      US
'   U	b  XS'   X›S'   Ub  [        U5      US'   U R                  U5        g)a”  Adds a new group with additional parameters

:param groupname: Name of the new group
:param grouptype: Type of the new group
:param description: Description of the new group
:param mailaddress: Email address of the new group
:param notes: Notes of the new group
:param gidnumber: GID Number of the new group
:param nisdomain: NIS Domain Name of the new group
:param sd: security descriptor of the object
úCN=Ú,Úgroup©r.   ÚsAMAccountNameÚobjectClassNÚ	groupTypeÚdescriptionÚmailÚinfoÚ	gidNumberÚmsSFU30NameÚmsSFU30NisDomainÚnTSecurityDescriptor)re   Úget_wellknown_dnrd   r   ÚDS_GUID_USERS_CONTAINERr	   r   Úadd)r/   Ú	groupnameÚgroupouÚ	grouptyper¢   ÚmailaddressÚnotesÚsdÚ	gidnumberÚ	nisdomainÚgroup_dnÚ
ldbmessages               r   ÚnewgroupÚSamDB.newgroupô   sî   € ÷ Û(1³7¸D¿N¹NÕ<LÐM‰Hð ó &/°×0EÑ0EØ(,×(?Ñ(?Ó(AÜ(,×(DÑ(Dõ1Fð GˆHð %Ø(1Ø%,ñ.ˆ
ð Ñ Ü&5°iÓ&@ˆJ�{Ñ#àÑ"Ø(3�}Ñ%àÑ"Ø!,�vÑàÑØ!&�vÑàÑ Ü&5°iÓ&@ˆJ�{Ñ#àÑ Ø(1�}Ñ%Ø-6Ð)Ñ*à‰>Ü19¸"³ˆJÐ-Ñ.à�‰�Õr   c                 óÈ  • S[         R                  " U5      < SS< SU R                  5       < S3nU R                  5          U R	                  U R                  5       [         R
                  U/ S9n[        U5      S:X  a  [        SU-  5      e[        U5      S	:X  d   eU R                  US   R                  5        U R                  5         g
!   U R                  5         e = f)z<Deletes a group

:param groupname: Name of the target group
ú(&(sAMAccountName=ú)(objectCategory=ú#CN=Group,CN=Schema,CN=Configurationrœ   ú))r{   r   úUnable to find group "%s"r€   N©r‚   Úbinary_encodere   Útransaction_startr�   rƒ   r„   r…   r7   r.   Útransaction_commitÚtransaction_cancel)r/   r¬   ÚgroupfilterÚtargetgroups       r   ÚdeletegroupÚSamDB.deletegroup(  sæ   � ô IL×HYÒHYÐZcÖHdó  gLð  NR÷  N\ñ  N\ö  N^ð  _ˆØ×ÑÔ ð	&ØŸ+™+¨4¯>©>Ó+;Ä3×CTÑCTØ1<ÀBð &ð HˆKä�;Ó 1Ó$ÜÐ ;¸iÑ GÓHÐHÜ�{Ó# qÓ(Ð)Ð(Ø�K‰K˜ A™×)Ñ)Ô*ð
 ×#Ñ#Õ%øð		Ø×#Ñ#Ô%Øúó   ÁA:C ÃC!c           	      ó‚  • Sn/ SQnSU;   a  UnU H+  nXT;  d  M
  [        SU< SSR                  U5      < S35      e   SU;   a,  US	[        R                  " U5      [        R
                  4-  -  nS
U;   a  US[        R                  " U5      -  -  nSU;   a<  UnUS   S:w  a  SU-  nUS[        R                  [        R                  " U5      4-  -  nSU;   a<  UnUS   S:w  a  SU-  nUS[        R                  [        R                  " U5      4-  -  nSU;   a  US[        R                  " U5      -  -  nSU-  nU$ )NÚ )Úuserr�   ÚcomputerÚserviceaccountÚcontactÚallzInvalid group member type "z". Valid types are z, z	 and all.rÊ   z)(&(sAMAccountName=%s)(samAccountType=%d))r�   zQ(&(sAMAccountName=%s)(objectClass=group)(!(groupType:1.2.840.113556.1.4.803:=1)))rË   éÿÿÿÿÚ$ú%s$zW(&(samAccountType=%d)(!(objectCategory=msDS-ManagedServiceAccount))(sAMAccountName=%s))rÌ   zT(&(samAccountType=%d)(objectCategory=msDS-ManagedServiceAccount)(sAMAccountName=%s))rÍ   z3(&(objectCategory=Person)(!(objectSid=*))(name=%s))z(|%s))r…   Újoinr‚   r¿   r   ÚATYPE_NORMAL_ACCOUNTÚATYPE_WORKSTATION_TRUST)r/   ÚmemberÚmember_typesÚfilterÚall_member_typesÚmember_typeÚsamaccountnames          r   Úgroup_member_filterÚSamDB.group_member_filter=  s�  € ØˆòÐð �LÓ Ø+ˆLã'ˆKØÕ2Ýã!,¨d¯i©iÐ8HÖ.Ið!Kó Lð Lñ (ð �\Ó!ØÐBÜ×)Ò)¨&Ó1´4×3LÑ3LÐMñNñ OˆFà�lÓ"Øð Cô ×(Ò(¨Ó0ñ1ñ 2ˆFð ˜Ó%Ø#ˆNØ�b‰z˜SÓ Ø!&¨¡�Øð .ô ×4Ñ4Ü×)Ò)¨.Ó9ð;ñ;ñ <ˆFð
 ˜|Ó+Ø#ˆNØ�b‰z˜SÓ Ø!&¨¡�Øð .ô ×4Ñ4Ü×)Ò)¨.Ó9ð;ñ;ñ <ˆFð
 ˜Ó$ØÐLÜ×(Ò(¨Ó0ñ1ñ 2ˆFð ˜6Ñ!ˆàˆr   c                 óš	  • Uc  / SQnUc  U R                  5       nSnSn [        R                  " U5      nUb  SnSnUc,  [	        U5      (       a   [
        R                  " U5      nUb  SnUcé  Sn [        U[        R                  5      (       a&  [        R                  " XR                  S5      5      nO![        R                  " U [        U5      5      n Ub}  UR!                  S5      nUR!                  S5      nUb  [#        [        R                  U5      nSnO;Ub  [#        [
        R                  U5      nSnO[        U5      n[        R$                  nUb  SU-  n[        R$                  nUb  SU-  n[        R$                  nUc9  U R                  5       n[        R&                  nS	[        R(                  " U5      -  nS
U< SS< SU R                  5       < S3nU R+                  5          U R-                  WWUS/S/S9n[/        U5      S:X  a  [1        SU-  5      e[/        U5      S:X  d   eSnUb  SU-  nO!Ub  SU-  nO[        US   R2                  5      nSU-  nU GHœ  nSnSn [        R                  " U5      nS[        U5      -  nUc`   [        R                  " U U5      nUR5                  5       UR                  S5      :X  a  U R7                  U5      nOUnUR                  S5      nUc±  U R9                  UU5      nU R-                  U[        R&                  U/ S9n[/        U5      S:”  a5  SnU H  nUSUR;                  S5      -  -  nM     [1        SU< SU< 35      e[/        U5      S:w  a  [1        SU-  5      eUS   R2                  R                  S5      nS nU" U US   UU5      n USL a  U (       d  SnUS[        U5      -  -  nGMw  USL d  GM  U (       d  GM‰  SnUS [        U5      -  -  nGMŸ     USL a  U R=                  U5        U R?                  5         g! [         a     GNf = f! [         a/  n	U	R                  u  p«U
[        R                  :w  a  U	e Sn	A	GNSn	A	ff = f! [         a     GN²f = f! [         a     GNf = f! [         a  n	 Sn	A	GN·Sn	A	ff = f!   U RA                  5         e = f)!ag  Adds or removes group members

:param group: sAMAccountName, DN, SID or GUID of the target group
:param members: list of group members
:param add_members_operation: Defines if its an add or remove
    operation
:param member_types: List of object types, used to filter the search
    for the specified members
:param member_base_dn: Base dn for member search
N)rÊ   r�   rË   z(objectClass=*)r€   ÚSIDÚGUIDz<SID=%s>z	<GUID=%s>z(sAMAccountName=%s)z(&z(objectCategory=r»   rœ   r¼   zextended_dn:1:1rÕ   )r|   r}   r~   Úcontrolsr   r   r½   Fz
dn: %s
changetype: modify
r{   rÉ   z%s
r.   zFound multiple results for "z":
z)Unable to find "%s". Operation cancelled.c                 ó.  • UR                  S5      c  gUR                  S5       Hm  n[        R                  " U [        U5      5      nUR	                  S5      nU(       a!  [        [        R                  U5      nX7:X  a    gU[        U5      :X  d  Mm    g   g)NrÕ   FrÞ   T)Úgetr‚   ÚDnrc   Úget_extended_componentr   r   Údom_sid)r-   r�   Ú	member_dnÚ
member_sidÚmÚm_ext_dnÚm_binary_sidÚm_sids           r   Ú
_is_memberÚ2SamDB.add_remove_group_members.<locals>._is_member	  s}   € Ø—y‘y Ó*Ñ2Ø$à"ŸY™Y xÖ0˜Ü#&§6¢6¨%´°Q³Ó#8˜Ø'/×'FÑ'FÀuÓ'M˜Þ'Ü$.¬x×/?Ñ/?ÀÓ$N˜EØ)Ó2Ù'+Ø$¬¨H«Õ5Ù#'ñ 1ð !r   Tzadd: member
member: %s
zdelete: member
member: %s
)!re   r   rå   Ú
ValueErrorr   r   rß   r   Úargsr   ÚNT_STATUS_INVALID_PARAMETERÚ
isinstancer‚   rã   Úextended_strrc   rä   r   Ú
SCOPE_BASErƒ   r¿   rÀ   r�   r„   r…   r.   Úget_linearizedÚnormalize_dn_in_domainrÛ   râ   r‡   rÁ   rÂ   )!r/   r�   ÚmembersÚadd_members_operationrÖ   Úmember_base_dnÚpartial_groupfilterÚ	group_sidÚ
group_guidÚeÚstatusÚ_r´   Úgroup_b_sidÚgroup_b_guidÚsearch_baseÚsearch_scoperÃ   rÄ   ÚmodifiedÚtargetgroup_dnÚaddtargettogrouprÕ   Útargetmember_dnÚ	membersidræ   Úfull_member_dnrr   ÚtargetmemberÚtargetmemberlist_strÚmsgrì   Ú	is_members!                                    r   Úadd_remove_group_membersÚSamDB.add_remove_group_membersr  s&  € ð ÑÚ8ˆLàÑ!Ø!Ÿ^™^Ó-ˆNà"Ðð ˆ	ð	Ü ×(Ò(¨Ó/ˆIð Ñ Ø"3Ðàˆ
ØÑ&¬>¸%×+@Ñ+@ðÜ!ŸYšY uÓ-�
ð
 Ñ%Ø&7Ð#àÑ&ØˆHðÜ˜e¤S§V¡V×,Ñ,Ü"Ÿvšv d×,>Ñ,>¸qÓ,AÓB‘Hä"Ÿvšv d¬C°«JÓ7‘Hð Ñ#Ø&×=Ñ=¸eÓD�Ø'×>Ñ>¸vÓF�ØÑ*Ü *¬8×+;Ñ+;¸[Ó I�IØ*;Ñ'Ø!Ñ-Ü!+¬D¯I©I°|Ó!D�JØ*;Ñ'ä"% h£-�KÜ#&§>¡>�LàÑ Ø$ yÑ0ˆKÜŸ>™>ˆLàÑ!Ø%¨
Ñ2ˆKÜŸ>™>ˆLàÑ&ØŸ.™.Ó*ˆKÜ×,Ñ,ˆLØ"7Ü×!Ò! %Ó(ñ#*Ðøó  Û1Ø�N‰NÖðˆð
 	×ÑÔ ðd	&ØŸ+™+¨;Ø,8Ø1<Ø0AÐ/BØ-5¨Jð	 &ð 8ˆKô
 �;Ó 1Ó$ÜÐ ;¸eÑ CÓDÐDÜ�{Ó# qÓ(Ð)Ð(àˆHàÑ$Ø!+¨iÑ!7‘ØÑ'Ø!,¨zÑ!9‘ä!$ [°¡^×%6Ñ%6Ó!7�ð ð ñ Ðô
 "�Ø"&�Ø �	ðÜ (× 0Ò 0°Ó 8�IØ&0´3°y³>Ñ&A�Oð #Ñ*ðÜ$'§F¢F¨4°Ó$8˜	Ø$×3Ñ3Ó5¸×9OÑ9OÐPQÓ9RÓRØ-1×-HÑ-HÈÓ-S™Nà-6˜NØ*8×*EÑ*EÀaÓ*H˜ð #Ñ*Ø$(×$<Ñ$<¸VÀ\Ó$R�MØ#'§;¡;°NÜ58×5FÑ5FØ:GØ57ð $/ð $9�Lô
 ˜<Ó(¨1Ó,Ø/1Ð,Û#/˜CØ0°F¸S¿W¹WÀT»]Ñ4JÑJÒ0ñ $0å'Û)/Ò1Eð)Gó Hð Hä˜<Ó(¨AÓ-Ü'Ð(SÐV\Ñ(\Ó]Ð]Ø&2°1¡o×&8Ñ&8×&EÑ&EÀaÓ&H�Oò!ñ  ' tØ'2°1¡~Ø'6Ø'0ó2�	ð )¨DÒ0¾Ø#�HØ$ð )ä
ˆ?Óñ)ñ Ó$ð +¨eÕ3¿	¹	Ø#�HØ$ð )ä
ˆ?Óñ)ñ Ó$ñC "ðJ ˜4ÒØ× Ñ Ð!1Ô2ð ×#Ñ#Õ%øô} ó 	Úð	ûô !ó ØŸf™f‘�ØœX×AÑAÓAØ�Gõ Bûðûô ó ÚðûôB "ó Úðûô &ó Ýûðûðn	Ø×#Ñ#Ô%Øús¥    P0 ÁQ Á2AQ= Â7 Q= Ç2A>R7 É1$RÊR7 ÊARË8C*R7 Ï'R7 Ï1.R7 Ð0
P>Ð=P>Ñ
Q:Ñ$Q5Ñ5Q:Ñ=
RÒ
RÒ
RÒR7 ÒRÒR7 Ò
R4Ò)R7 Ò/R4Ò4R7 Ò7S
c                 óR  • Uc  gX2;   a  [        U5      [        X#   5      :X  a  g[        U5      S:X  a=  X2;   a7  [        R                  " / [        R                  U5      nUR                  U5        g[        R                  " U[        R                  U5      nUR                  U5        g)a!  Changes the MessageElement with the given attr_name of the
given Message. If the value is "" set an empty value and the flag
FLAG_MOD_DELETE, otherwise set the new value and FLAG_MOD_REPLACE.
If the value is None or the Message contains the attr_name with this
value, nothing will changed.Nr   )rc   r„   r‚   ÚMessageElementÚFLAG_MOD_DELETEr«   ÚFLAG_MOD_REPLACE)r/   r  ÚoldÚ	attr_nameÚvalueÚels         r   Úprepare_attr_replaceÚSamDB.prepare_attr_replace2  s‰   € ð ‰=ØØÓ¤ E£
¬c°#±.Ó.AÓ AØô ˆu‹:˜‹?ØÓÜ×'Ò'¨¬C×,?Ñ,?ÀÓK�Ø—‘˜”Øô ×Ò ¤s×';Ñ';¸YÓGˆØ�‰��r   c                 ó\  • Uc  0 nUUUS.nUR                  5        H   u  pxUb  M
  Xt;   d  M  [        XG   5      Xg'   M"     US   (       a&  US   R                  S5      (       d  US==   S-  ss'   [        [	        SUR                  5       5      5      n	SR                  U	5      n
U
S:X  a  U$ U
$ )z—Prepares new combined fullname, using the name parts.
Used for things like displayName or cn.
Use the original name values, if no new one is specified.N)Ú	givenNameÚinitialsÚsnr  Ú.Ú rÉ   )Úitemsrc   ÚendswithÚlistr×   ÚvaluesrÒ   )r/   Ú
given_namer  ÚsurnameÚ	old_attrsÚfallback_defaultr   r  Ú
attr_valueÚattrs_valuesÚfullnames              r   Úfullname_from_namesÚSamDB.fullname_from_namesI  s¹   € ð
 ÑØˆIà(Ø%Øñ ˆð
 &+§[¡[¦]Ñ!ˆIØÓ! iÕ&<Ü#& yÑ';Ó#<�Ó ñ &3ð �× U¨:Ñ%6×%?Ñ%?À×%DÑ%DØ�*Ó Ñ$Óô œF 4¨¯©«Ó8Ó9ˆð —8‘8˜LÓ)ˆà�r‹>Ø#Ð#àˆr   c                 óþ  • U R                  UUUS9nUn Uc  US:w  a  Un U(       a  SU < SU< SU R                  5       < 3n!O6SU < SU R                  U R                  5       [        R
                  5      < 3n![        R                  " X R                  5       5      R                  5       R                  SS5      n"U< SU"< 3n#U!UU#SS	.n$U(       a/  [        [        R                  [        R                  -  5      U$S
'   SnUb  UU$S'   Ub  UU$S'   US:w  a
  UU$S'   UU$S'   Ub  SU-  U$S'   U	b  U	U$S'   U
b  U
U$S'   Ub  UU$S'   Ub  UU$S'   Ub  UU$S'   Ub  UU$S'   Ub  UU$S'   Ub  UU$S'   Ub  UU$S'   Ub  UU$S'   Ub  UU$S'   Ub  UU$S'   Ub  [        U5      U$S'   Sn%[        [        S UUUUUUU45      5      (       Gaÿ  [        R                   " 5       n%[        R                  " U U!5      U%l        Ub2  [        R$                  " [        U5      [        R&                  S 5      U%S '   Ub2  [        R$                  " [        U5      [        R&                  S!5      U%S!'   Ub2  [        R$                  " [        U5      [        R&                  S"5      U%S"'   Ub2  [        R$                  " [        U5      [        R&                  S#5      U%S#'   Ub2  [        R$                  " [        U5      [        R&                  S$5      U%S$'   Ub2  [        R$                  " [        U5      [        R&                  S%5      U%S%'   Ub�  [        R$                  " [        U5      [        R&                  S&5      U%S&'   [        R$                  " [        U5      [        R&                  S'5      U%S''   [        R$                  " S([        R&                  S)5      U%S)'   U R)                  5          U R+                  U$5        U R-                  U U!5         U%(       a  U R/                  U%5        U(       a*  U R1                  S*[        R2                  " U!5      -  UU5        SSS5        U R5                  5         g! , (       d  f       N= f!   U R7                  5         e = f)+al  Adds a new user with additional parameters

:param username: Name of the new user
:param password: Password for the new user
:param force_password_change_at_next_login_req: Force password change
:param useusernameascn: Use username as cn rather that firstname +
    initials + lastname
:param userou: Object container (without domainDN postfix) for new user
:param surname: Surname of the new user
:param givenname: First name of the new user
:param initials: Initials of the new user
:param profilepath: Profile path of the new user
:param scriptpath: Logon script path of the new user
:param homedrive: Home drive of the new user
:param homedirectory: Home directory of the new user
:param jobtitle: Job title of the new user
:param department: Department of the new user
:param company: Company of the new user
:param description: of the new user
:param mailaddress: Email address of the new user
:param internetaddress: Home page of the new user
:param telephonenumber: Phone number of the new user
:param physicaldeliveryoffice: Office location of the new user
:param sd: security descriptor of the object
:param setpassword: optionally disable password reset
:param uidnumber: RFC2307 Unix numeric UID of the new user
:param gidnumber: RFC2307 Unix primary GID of the new user
:param gecos: RFC2307 Unix GECOS field of the new user
:param loginshell: RFC2307 Unix login shell of the new user
:param uid: RFC2307 Unix username of the new user
:param nisdomain: RFC2307 Unix NIS domain of the new user
:param unixhome: RFC2307 Unix home directory of the new user
:param smartcard_required: set the UF_SMARTCARD_REQUIRED bit of the new user
©r#  r  r$  NrÉ   r›   rœ   Ú/Ú@rÊ   )r.   rŸ   ÚuserPrincipalNamer    rz   Fr  r  ÚdisplayNameÚnameú%s.r  ÚprofilePathÚ
scriptPathÚ	homeDriveÚhomeDirectoryÚtitleÚ
departmentÚcompanyr¢   r£   ÚwWWHomePageÚtelephoneNumberÚphysicalDeliveryOfficeNamer¨   c                 ó
   • U S L$ r,   r   )Úbs    r   Ú<lambda>ÚSamDB.newuser.<locals>.<lambda>è  s   € ˜Q d™]r   ÚuidÚ	uidNumberr¥   ÚgecosÚ
loginShellÚunixHomeDirectoryr§   r¦   zABCD!efgh12345$67890ÚunixUserPasswordú(distinguishedName=%s))r*  re   r©   rd   r   rª   r‚   rã   Úcanonical_strÚreplacerc   ÚUF_NORMAL_ACCOUNTÚUF_SMARTCARD_REQUIREDr   ÚanyÚmapÚMessager.   r  r  rÀ   r«   r=   ÚmodifyÚsetpasswordr¿   rÁ   rÂ   )&r/   ÚusernameÚpasswordÚ'force_password_change_at_next_login_reqÚuseusernameascnÚuserour$  Ú	givennamer  ÚprofilepathÚ
scriptpathÚ	homedriveÚhomedirectoryÚjobtitler9  r:  r¢   r¯   ÚinternetaddressÚtelephonenumberÚphysicaldeliveryofficer±   rQ  Ú	uidnumberr²   rD  Ú
loginshellrB  r³   ÚunixhomeÚsmartcard_requiredÚdisplaynameÚcnr”   Ú	dnsdomainÚuser_principal_namerµ   Úldbmessage2s&                                         r   ÚnewuserÚSamDB.newuserj  sš  € ðZ ×.Ñ.¸)Ø8@Ø7>ð /ð @ˆð ˆØÑ" {°bÓ'8ØˆBçÛ')«6°4·>±>Õ3CÐD‰Gð ó %'¨×(=Ñ(=Ø(,×(?Ñ(?Ó(AÜ(,×(DÑ(Dõ)Fð GˆGô —F’F˜4§¡Ó!1Ó2×@Ñ@ÓB×JÑJÈ3ÐPRÓSˆ	Û)1²9Ð=Ðð $Ø(0Ø+>Ø%+ñ-ˆ
ö
 Ü/2´4×3IÑ3IÜ37×3MÑ3Mñ4Nó 0OˆJÐ+Ñ,àˆKàÑØ&ˆJ�tÑàÑ Ø&/ˆJ�{Ñ#à˜"ÓØ(3ˆJ�}Ñ%Ø!,ˆJ�vÑàÑØ%*¨XÑ%5ˆJ�zÑ"àÑ"Ø(3ˆJ�}Ñ%àÑ!Ø'1ˆJ�|Ñ$àÑ Ø&/ˆJ�{Ñ#àÑ$Ø*7ˆJ�Ñ'àÑØ"*ˆJ�wÑàÑ!Ø'1ˆJ�|Ñ$àÑØ$+ˆJ�yÑ!àÑ"Ø(3ˆJ�}Ñ%àÑ"Ø!,ˆJ�vÑàÑ&Ø(7ˆJ�}Ñ%àÑ&Ø,;ˆJÐ(Ñ)à!Ñ-Ø7MˆJÐ3Ñ4à‰>Ü19¸"³ˆJÐ-Ñ.àˆÜŒsÑ*¨S°)¸YÈØ-7¸ÀHð-Nó O÷ Pò PäŸ+š+›-ˆKÜ ŸVšV D¨'Ó2ˆKŒNØ‰Ü%(×%7Ò%7¼¸C»Ä#×BVÑBVÐX]Ó%^�˜EÑ"ØÑ$Ü+.×+=Ò+=¼cÀ)»nÌc×NbÑNbÐdoÓ+p�˜KÑ(ØÑ$Ü+.×+=Ò+=¼cÀ)»nÌc×NbÑNbÐdoÓ+p�˜KÑ(ØÑ Ü'*×'9Ò'9¼#¸e»*Äc×FZÑFZÐ\cÓ'd�˜GÑ$ØÑ%Ü,/×,>Ò,>¼sÀ:»ÔPS×PdÑPdÐfrÓ,s�˜LÑ)ØÑ#Ü36×3EÒ3EÜ˜“M¤3×#7Ñ#7Ð9Ló4N�Ð/Ñ0àÑ$Ü25×2DÒ2DÜ˜	“N¤C×$8Ñ$8Ð:Ló3N�Ð.Ñ/ä-0×-?Ò-?Ü˜“M¤3×#7Ñ#7¸ó.H�˜MÑ*ä25×2DÒ2DØ*¬C×,@Ñ,@Ø&ó3(�Ð.Ñ/ð 	×ÑÔ ð	&Ø�H‰H�ZÔ à×%Ñ% d¨GÕ4ÞØ—K‘K Ô,ö Ø×$Ñ$Ð&>Ü&)×&7Ò&7¸Ó&@ñ'Aà%-Ø%LôN÷ 5ð ×#Ñ#Õ%÷ 5Õ4ûð	Ø×#Ñ#Ô%Øús%   Ï#Q) Ï5A
QÐ?Q) Ñ
Q&Ñ"Q) Ñ)Q<c                 óÀ  • U R                  UUUS9nUb  UnUc  US:X  a  [        S5      eU R                  5       nU(       a  U R                  U5      nSU< SU< 3nUSS.nUb  UUS'   Ub  UUS	'   Ub  UUS
'   Ub  SU-  US'   Ub  UUS'   Ub  UUS'   U	b  U	US'   U
b  U
US'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   U R	                  U5        U$ )a3  Adds a new contact with additional parameters

:param fullcontactname: Optional full name of the new contact
:param ou: Object container for new contact
:param surname: Surname of the new contact
:param givenname: First name of the new contact
:param initials: Initials of the new contact
:param displayname: displayName of the new contact
:param jobtitle: Job title of the new contact
:param department: Department of the new contact
:param company: Company of the new contact
:param description: Description of the new contact
:param mailaddress: Email address of the new contact
:param internetaddress: Home page of the new contact
:param telephonenumber: Phone number of the new contact
:param mobilenumber: Primary mobile number of the new contact
:param physicaldeliveryoffice: Office location of the new contact
r-  rÉ   zNo name for contact specifiedr›   rœ   rÍ   ©r.   r    r  r  r1  r3  r  r8  r9  r:  r¢   r£   r;  r<  Úmobiler=  )r*  r…   re   rõ   r«   )r/   ÚfullcontactnameÚour$  rW  r  rd  r\  r9  r:  r¢   r¯   r]  r^  Úmobilenumberr_  re  Úcontactcontainer_dnÚ
contact_dnrµ   s                       r   Ú
newcontactÚSamDB.newcontact  sk  € ðH ×%Ñ%°Ø/7Ø.5ð &ð 7ˆð Ñ&Ø ˆBàÑ" r¨R£xÜÐ;Ó<Ð<à"Ÿn™nÓ.ÐÞØ"&×"=Ñ"=¸bÓ"AÐøã#%Ò':Ð;ˆ
à&Ø%.ñˆ
ð ÑØ&ˆJ�tÑàÑ Ø&/ˆJ�{Ñ#àÑ"Ø(3ˆJ�}Ñ%àÑØ%*¨XÑ%5ˆJ�zÑ"àÑØ"*ˆJ�wÑàÑ!Ø'1ˆJ�|Ñ$àÑØ$+ˆJ�yÑ!àÑ"Ø(3ˆJ�}Ñ%àÑ"Ø!,ˆJ�vÑàÑ&Ø(7ˆJ�}Ñ%àÑ&Ø,;ˆJÐ(Ñ)àÑ#Ø#/ˆJ�xÑ à!Ñ-Ø7MˆJÐ3Ñ4à�‰�Ôàˆ	r   c                 ó¬  • [         R                  " SSU5      nUR                  S5      (       a  [        SU-  5      eSU-  nU R	                  U R                  5       [        R                  5      n	U(       a  U R                  U5      n	SU< SU	< 3n
U
USS	.nUb  X;S'   U(       a  XkS'   [        [        R                  [        R                  -  5      nU(       a  [        [        R                  5      nXËS'   U(       a"  SR                  XpR                  5       5      US'   U R                  5          U R                  U5        U(       aT  UR!                  5       nU R#                  X
5         U R%                  S[&        R(                  " U
5      -  US5        S
S
S
5        U R+                  5         g
! , (       d  f       N= f!   U R-                  5         e = f)a’  Adds a new user with additional parameters

:param computername: Name of the new computer
:param computerou: Object container for new computer
:param description: Description of the new computer
:param prepare_oldjoin: Preset computer password for oldjoin mechanism
:param ip_address_list: ip address list for DNS A or AAAA record
:param service_principal_name_list: string list of servicePincipalName
z\$$rÉ   rÐ   zIllegal computername "%s"rÑ   r›   rœ   rË   rž   Nr¢   ÚservicePrincipalNamerz   z{}.{}ÚdNSHostNamerH  F)ÚreÚsubÚcountr…   r©   rd   r   ÚDS_GUID_COMPUTERS_CONTAINERrõ   rc   ÚUF_WORKSTATION_TRUST_ACCOUNTro   ÚformatÚdomain_dns_namerÀ   r«   Úlowerr=   rQ  r‚   r¿   rÁ   rÂ   )r/   ÚcomputernameÚ
computerour¢   Úprepare_oldjoinÚip_address_listÚservice_principal_name_listre  rÚ   Úcomputercontainer_dnÚcomputer_dnrµ   ÚaccountcontrolrS  s                 r   ÚnewcomputerÚSamDB.newcomputer|  s£  € ô �VŠV�F˜B Ó-ˆØ�8‰8�C�=‰=ÜÐ7¸,ÑFÓGÐGØ ™ˆà#×4Ñ4°T×5LÑ5LÓ5NÜ.2×.NÑ.Nó PÐæØ#'×#>Ñ#>¸zÓ#JÐ øã$&Ò(<Ð=ˆà'Ø(6Ø%/ñˆ
ð
 Ñ"Ø(3�}Ñ%æ&Ø1LÐ-Ñ.äœT×>Ñ>Ü!×3Ñ3ñ4ó 5ˆæÜ ¤×!BÑ!BÓCˆNØ+9Ð'Ñ(æØ(/¯©Ø×(Ñ(Ó*ó),ˆJ�}Ñ%ð 	×ÑÔ ð	&Ø�H‰H�ZÔ æØŸ8™8›:�Ø×)Ñ)¨$Õ<Ø×$Ñ$Ð&>Ü&)×&7Ò&7¸Ó&Dñ'Eà%-¨uô6÷ =ð ×#Ñ#Õ%÷ =Õ<ûð	Ø×#Ñ#Ô%Øús$   Ä29G  Å++F/ÆG  Æ/
F=Æ9G  Ç Gc                 óÈ  • S[         R                  " U5      < SS< SU R                  5       < S3nU R                  5          U R	                  U R                  5       [         R
                  U/ S9n[        U5      S:X  a  [        SU-  5      e[        U5      S	:X  d   eU R                  US   R                  5        U R                  5         g
!   U R                  5         e = f)z9Deletes a user

:param username: Name of the target user
r¹   rº   z$CN=Person,CN=Schema,CN=Configurationrœ   r¼   r{   r   r’   r€   Nr¾   )r/   rR  r×   Útargets       r   Ú
deleteuserÚSamDB.deleteuserº  sá   � ô DG×CTÒCTÐU]ÖC^ó  aGð  IM÷  IWñ  IWö  IYð  ZˆØ×ÑÔ ð	&Ø—[‘[ d§n¡nÓ&6¼c×>OÑ>OØ,2¸"ð !ð >ˆFä�6‹{˜aÓÜÐ :¸XÑ EÓFÐFÜ�v“; !Ó#Ð$Ð#Ø�K‰K˜˜q™	Ÿ™Ô%ð
 ×#Ñ#Õ%øð		Ø×#Ñ#Ô%ØúrÇ   c                 óö  • U R                  5          U R                  U R                  5       [        R                  U/ S9n[        U5      S:X  a  [        SU=(       d    U-  5      e[        U5      S:”  a  [        S[        U5      U4-  5      eUS   R                  n[        U[        5      (       d  UR                  S5      nOUnSU-   S-   R                  S5      nS	U< S
[        R                  " U5      R                  S5      < S3nU R                  U5        U(       a   U R                  S[        U5      -   S-   5        U R!                  U5        U R#                  5         g!   U R%                  5         e = f)zÎSets the password for a user

:param search_filter: LDAP filter to find the user (eg
    sAMAccountName=name)
:param password: Password for the user
:param force_change_at_next_login: Force password change
r{   r   r’   r€   z*Matched %u multiple users with filter "%s"úutf-8Ú"z	utf-16-lez
dn: z5
changetype: modify
replace: unicodePwd
unicodePwd:: Ú
z(distinguishedName=Ú)N)rÀ   r�   re   r‚   rƒ   r„   r…   r.   rñ   rc   ÚdecodeÚencodeÚbase64Ú	b64encoder‡   r•   rw   rÁ   rÂ   )	r/   rr   rS  Úforce_change_at_next_loginrR  rŠ   r”   ÚpwÚsetpws	            r   rQ  ÚSamDB.setpasswordÏ  sY  € ð 	×ÑÔ ð 	&Ø—+‘+ 4§>¡>Ó#3¼3×;LÑ;LØ)6¸bð ð BˆCä�3‹x˜1‹}ÜÐ :¸h×>WÈ-Ñ XÓYÐYÜ�3‹x˜!‹|ÜÐ LÔPSÐTWÓPXÐZgÐOhÑ hÓiÐiØ˜!‘f—i‘iˆGÜ˜h¬×,Ñ,Ø—_‘_ WÓ-‘à�Ø˜‘(˜S‘.×(Ñ(¨Ó5‰Bó ”× Ò  Ó$×+Ñ+¨GÖ4ð6ˆEð ×Ñ˜UÔ#æ)Ø×8Ñ8Ø)¬C°«LÑ8¸3Ñ>ô@ð ×Ñ Ô.ð
 ×#Ñ#Õ%øð		Ø×#Ñ#Ô%Øús   ’EE% Å%E8c                 ó6  • U R                  5          U R                  U R                  5       [        R                  USS/S9n[        U5      S:X  a  [        SU-  5      e[        U5      S:X  d   eUS   R                  n[        US   S   S   5      nU(       a  US-  nSnO:US-  n[        R                  " U[        [        R                  " 5       5      -   5      nS	XVU4-  nU R                  U5        U R                  5         g
!   U R                  5         e = f)zäSets the account expiry for a user

:param search_filter: LDAP filter to find the user (eg
    sAMAccountName=name)
:param expiry_seconds: expiry time from now in seconds
:param no_expiry_req: if set, then don't expire password
rz   ÚaccountExpiresr{   r   r’   r€   i   iÿÿþÿzy
dn: %s
changetype: modify
replace: userAccountControl
userAccountControl: %u
replace: accountExpires
accountExpires: %u
N)rÀ   r�   re   r‚   rƒ   r„   r…   r.   r†   rn   Úunix2nttimeÚtimer‡   rÁ   rÂ   )	r/   rr   Úexpiry_secondsÚno_expiry_reqrŠ   r”   rz   rœ  Úsetexps	            r   Ú	setexpiryÚSamDB.setexpiryû  s#  € ð 	×ÑÔ ð	&Ø—+‘+ 4§>¡>Ó#3¼3×;LÑ;LØ)6Ø%9Ð;KÐ$Lð ð NˆCô �3‹x˜1‹}ÜÐ :¸]Ñ JÓKÐKÜ�s“8˜q“=Ð!�=Ø˜!‘f—i‘iˆGä!$ S¨¡VÐ,@Ñ%AÀ!Ñ%DÓ!EÐÞØ%7¸'Ñ%AÐ"Ø!"‘à%7¸(Ñ%BÐ"Ü!&×!2Ò!2°>ÄCÌÏ	Ê	ËÓDTÑ3TÓ!U�ðð  NÐ3ñ4ˆFð ×Ñ˜VÔ$ð
 ×#Ñ#Õ%øð		Ø×#Ñ#Ô%Øús   ’C"D ÄDc                 ó0   • [         R                  " X5        g)zPChange the domain SID used by this LDB.

:param sid: The new domain sid to use.
N)r   Ú_samdb_set_domain_sid)r/   Úsids     r   Úset_domain_sidÚSamDB.set_domain_sid%  s   € ô
 	×"Ò" 4Õ-r   c                 ó.   • [         R                  " U 5      $ )z&Read the domain SID used by this LDB. )r   Ú_samdb_get_domain_sidr3   s    r   Úget_domain_sidÚSamDB.get_domain_sid,  s   € ä×)Ò)¨$Ó/Ð/r   zSID for the domain)Údocc                 óš   • U R                  S[        R                  S/S9S   n[        [	        [
        R                  US   S   5      5      $ )z&Returns the SID of the connected user.rÉ   ÚtokenGroups©r|   r}   r   r   )r�   r‚   ró   rc   r   r   rå   )r/   r  s     r   Úget_connecting_user_sidÚSamDB.get_connecting_user_sid3  sD   € à�k‰k˜r¬¯©À¸ˆkÐOÐPQÑRˆÜ”:œh×.Ñ.°°MÑ0BÀ1Ñ0EÓFÓGÐGr   zSID of the connecting userc                 ó0   • [         R                  " X5        g)z_Set the invocation id for this SamDB handle.

:param invocation_id: GUID of the invocation id.
N)r   Ú_dsdb_set_ntds_invocation_id)r/   Úinvocation_ids     r   Úset_invocation_idÚSamDB.set_invocation_id;  s   € ô
 	×)Ò)¨$Õ>r   c                 ó.   • [         R                  " U 5      $ )zGet the invocation_id id)r   Ú_samdb_ntds_invocation_idr3   s    r   Úget_invocation_idÚSamDB.get_invocation_idB  s   € ä×-Ò-¨dÓ3Ð3r   zInvocation ID GUIDc                 ó.   • [         R                  " X5      $ r,   )r   Ú_dsdb_get_oid_from_attid©r/   Úattids     r   Úget_oid_from_attidÚSamDB.get_oid_from_attidI  s   € Ü×,Ò,¨TÓ9Ð9r   c                 ó0   • [         R                  " U X5      $ )zNreturn the attribute ID for a LDAP attribute as an integer as found in DRSUAPI)r   Ú$_dsdb_get_attid_from_lDAPDisplayName)r/   Úldap_display_nameÚis_schema_ncs      r   Úget_attid_from_lDAPDisplayNameÚ$SamDB.get_attid_from_lDAPDisplayNameL  s   € ô ×8Ò8¸Ø9JóZð 	Zr   c                 ó.   • [         R                  " X5      $ )z6return the syntax OID for a LDAP attribute as a string)r   Ú)_dsdb_get_syntax_oid_from_lDAPDisplayName©r/   rÄ  s     r   Ú#get_syntax_oid_from_lDAPDisplayNameÚ)SamDB.get_syntax_oid_from_lDAPDisplayNameR  s   € ä×=Ò=¸dÓVÐVr   c                 ó.   • [         R                  " X5      $ )z8return the systemFlags for a LDAP attribute as a integer)r   Ú*_dsdb_get_systemFlags_from_lDAPDisplayNamerÊ  s     r   Ú$get_systemFlags_from_lDAPDisplayNameÚ*SamDB.get_systemFlags_from_lDAPDisplayNameV  s   € ä×>Ò>¸tÓWÐWr   c                 ó.   • [         R                  " X5      $ )z3return the linkID for a LDAP attribute as a integer)r   Ú%_dsdb_get_linkId_from_lDAPDisplayNamerÊ  s     r   Úget_linkId_from_lDAPDisplayNameÚ%SamDB.get_linkId_from_lDAPDisplayNameZ  s   € ä×9Ò9¸$ÓRÐRr   c                 ó.   • [         R                  " X5      $ )z;return the lDAPDisplayName from an integer DRS attribute ID)r   Ú"_dsdb_get_lDAPDisplayName_by_attidr¾  s     r   Úget_lDAPDisplayName_by_attidÚ"SamDB.get_lDAPDisplayName_by_attid^  s   € ä×6Ò6°tÓCÐCr   c                 ó.   • [         R                  " X5      $ )z†return the attribute name of the corresponding backlink from the name
of a forward link attribute. If there is no backlink return None)r   Ú'_dsdb_get_backlink_from_lDAPDisplayNamerÊ  s     r   Ú!get_backlink_from_lDAPDisplayNameÚ'SamDB.get_backlink_from_lDAPDisplayNameb  s   € ô ×;Ò;¸DÓTÐTr   c                 ó0   • [         R                  " X5        g)zÂSet the NTDS Settings DN, as would be returned on the dsServiceName
rootDSE attribute.

This allows the DN to be set before the database fully exists

:param ntds_settings_dn: The new DN to use
N)r   Ú_samdb_set_ntds_settings_dn)r/   Úntds_settings_dns     r   Úset_ntds_settings_dnÚSamDB.set_ntds_settings_dng  s   € ô 	×(Ò(¨Õ@r   c                 ó.   • [         R                  " U 5      $ )zGet the NTDS objectGUID)r   Ú_samdb_ntds_objectGUIDr3   s    r   Úget_ntds_GUIDÚSamDB.get_ntds_GUIDq  s   € ä×*Ò*¨4Ó0Ð0r   c                 ój   • U R                  S[        R                  S/S9n[        US   S   S   5      $ )z/Get the current time as generalized time stringrÉ   ÚcurrentTimer°  r   ©r�   r‚   ró   rc   ©r/   rŠ   s     r   Úget_timestrÚSamDB.get_timestru  s>   € à�k‰k˜rÜ #§¡Ø!. ð ð 1ˆô �3�q‘6˜-Ñ(¨Ñ+Ó,Ð,r   c                 óJ   • [         R                  " U R                  5       5      $ )z!Get the current time as UNIX time)r‚   Ústring_to_timerê  r3   s    r   Úget_timeÚSamDB.get_time|  s   € ä×!Ò! $×"2Ñ"2Ó"4Ó5Ð5r   c                 óJ   • [         R                  " U R                  5       5      $ )zGet the current time as NT time)rn   r�  rî  r3   s    r   Ú
get_nttimeÚSamDB.get_nttime€  s   € ä× Ò  §¡£Ó1Ð1r   c                 ó.   • [         R                  " U 5      $ )zGet the server site name)r   Ú_samdb_server_site_namer3   s    r   Úserver_site_nameÚSamDB.server_site_name„  s   € ä×+Ò+¨DÓ1Ð1r   c                 ój   • U R                  S[        R                  S/S9n[        US   S   S   5      $ )z return the DNS name of this hostrÉ   rw  r°  r   rè  ré  s     r   Úhost_dns_nameÚSamDB.host_dns_nameˆ  s5   € à�k‰k˜r¬¯©À¸ˆkÐOˆÜ�3�q‘6˜-Ñ(¨Ñ+Ó,Ð,r   c                 óf   • U R                  5       nUR                  5       R                  S5      S   $ )z&return the DNS name of the domain rootr.  r   )rd   rI  Úsplit)r/   re   s     r   r~  ÚSamDB.domain_dns_name�  s/   € à×+Ñ+Ó-ˆ	Ø×&Ñ&Ó(×.Ñ.¨sÓ3°AÑ6Ð6r   c                 ó  • U R                  5       nU R                  5       nSU< SU< S3nU R                  5       nU R                  U[        R
                  US9n US   S   S   R                  5       nU$ ! [         a     gf = f)z*return the NetBIOS name of the domain rootz/(&(objectClass=crossRef)(nETBIOSName=*)(ncName=z
)(dnsroot=r¼   )r}   r~   r   ÚnETBIOSNameN)rd   r~  Úget_partitions_dnr�   r‚   ÚSCOPE_ONELEVELr“  Ú
IndexError)r/   re   Údns_namer×   Úpartitions_dnrŠ   Únetbios_domains          r   Údomain_netbios_nameÚSamDB.domain_netbios_name’  s•   € à×+Ñ+Ó-ˆ	Ø×'Ñ'Ó)‰ÛV_ÓaiÐjˆØ×.Ñ.Ó0ˆØ�k‰k˜-Ü #× 2Ñ 2Ø%+ð ð -ˆð	Ø  ™V MÑ2°1Ñ5×<Ñ<Ó>ˆNð Ðøô ó 	Ùð	ús   ÁA7 Á7
BÂBc                 óf   • U R                  5       nUR                  5       R                  S5      S   $ )z&return the DNS name of the forest rootr.  r   )Úget_root_basednrI  rû  )r/   Ú	forest_dns     r   Úforest_dns_nameÚSamDB.forest_dns_name¡  s/   € à×(Ñ(Ó*ˆ	Ø×&Ñ&Ó(×.Ñ.¨sÓ3°AÑ6Ð6r   c                 ó.   • [         R                  " X5      $ r,   )r   Ú_dsdb_load_partition_usn)r/   Úbase_dns     r   Úload_partition_usnÚSamDB.load_partition_usn¦  s   € Ü×,Ò,¨TÓ;Ð;r   c                 ó8   • U R                  UR                  US9  g )N)Úwrite_indices_and_attributes)Úset_schema_from_ldbr‚   )r/   Úschemar  s      r   Ú
set_schemaÚSamDB.set_schema©  s   € Ø× Ñ  §¡ÐJfÐ Ògr   c                 ó2   • [         R                  " XU5        g r,   )r   Ú_dsdb_set_schema_from_ldb)r/   Úldb_connr  s      r   r  ÚSamDB.set_schema_from_ldb¬  s   € Ü×&Ò& tÐ7SÕTr   c                 ó*   • SnU R                  U5        g )Nz@
dn:
changetype: modify
add: schemaUpdateNow
schemaUpdateNow: 1
)r‡   )r/   Úldifs     r   Úset_schema_update_nowÚSamDB.set_schema_update_now¯  s   € ðˆð 	×Ñ˜Õr   c                 ó0   • [         R                  " XU5      $ )zBconvert a list of attribute values to a DRSUAPI DsReplicaAttribute)r   Ú_dsdb_DsReplicaAttribute©r/   r‚   rÄ  Úldif_elementss       r   Údsdb_DsReplicaAttributeÚSamDB.dsdb_DsReplicaAttribute¸  s   € ä×,Ò,¨SÀ]ÓSÐSr   c                 ó0   • [         R                  " XU5      $ )z$normalise a list of attribute values)r   Ú_dsdb_normalise_attributesr!  s       r   Údsdb_normalise_attributesÚSamDB.dsdb_normalise_attributes¼  s   € ä×.Ò.¨sÀ}ÓUÐUr   c                 óì   • [        U R                  R                  5       5      S:X  a  U R                  5         U R	                  U5      U R                  ;   a  U R                  U R	                  U5         $ g)z�Get from an attid the associated attribute

:param attid: The attribute id for searched attribute
:return: The name of the attribute associated with this id
r   N)r„   Úhash_oid_nameÚkeysÚ_populate_oid_attidrÀ  r¾  s     r   Úget_attribute_from_attidÚSamDB.get_attribute_from_attidÀ  sd   € ô ˆt×!Ñ!×&Ñ&Ó(Ó)¨QÓ.Ø×$Ñ$Ô&Ø×"Ñ" 5Ó)¨T×-?Ñ-?Ó?Ø×%Ñ% d×&=Ñ&=¸eÓ&DÑEÐEàr   c                 óì   • 0 U l         U R                  SS/SS/S9n[        U5      S:”  aJ  U HC  n[        UR	                  S5      5      nX0R                   [        UR	                  S5      5      '   ME     gg)zwPopulate the hash hash_oid_name.

This hash contains the oid of the attribute as a key and
its display name as a value
zobjectClass=attributeSchemaúsearch_options:1:2ÚattributeIDÚlDAPDisplayName)r~   rà   r   r   N)r*  r�   r„   rc   râ   )r/   rŠ   rü   Ú
strDisplays       r   r,  ÚSamDB._populate_oid_attidÍ  s   € ð  ˆÔØ�k‰kÐ%BØ$8Ð#9Ø!.Ø!2ð!4ð ð 5ˆô ˆs‹8�a‹<Û�Ü  §¡Ð'8Ó!9Ó:�
Ø@J×"Ñ"¤3 q§u¡u¨]Ó';Ó#<Ó=ò ð r   c                 ó2  • U R                  SU-  [        R                  S/S/S9n[        U5      S:X  a  g[	        [
        R                  US   S   S   5      nUR                  n[        U R                  R                  5       5      S:X  a  U R                  5         UR                   Hl  nU R                  UR                  5      nXpR                  ;   d  M/  UR                  5       U R                  U   R                  5       :X  d  M`  UR                  s  $    g)a+  Get the version field trom the replPropertyMetaData for
the given field

:param dn: The on which we want to get the version
:param att: The name of the attribute
:return: The value of the version field in the replPropertyMetaData
    for the given attribute. None if the attribute is not replicated
údistinguishedName=%sr0  ÚreplPropertyMetaData©r~   r}   rà   r   r   N)r�   r‚   rƒ   r„   r   r   ÚreplPropertyMetaDataBlobÚctrr*  r+  r,  ÚarrayrÀ  r¿  r  Úversion)r/   r.   ÚattrŠ   Úreplr:  ÚoÚatt_oids           r   Ú"get_attribute_replmetadata_versionÚ(SamDB.get_attribute_replmetadata_versionÝ  sø   € ð �k‰kÐ%;¸bÑ%@Ü #× 1Ñ 1Ø$8Ð#9Ø!7Ð 8ð ð :ˆô ˆs‹8�q‹=Øäœ(×;Ñ;Ø˜a™&Ð!7Ñ8¸Ñ;ó=ˆà�h‰hˆÜˆt×!Ñ!×&Ñ&Ó(Ó)¨QÓ.Ø×$Ñ$Ô&Ø—”ˆAà×-Ñ-¨a¯g©gÓ6ˆGØ×,Ñ,Õ,Ø�y‰y‹{˜d×0Ñ0°Ñ9×?Ñ?ÓAÕAØ—y‘yÒ ñ ð r   c                 ó$  • U R                  SU-  [        R                  S/S/S9n[        U5      S:X  a  g [	        [
        R                  US   S   S   5      nUR                  n[        R                  " [        [        R                  " 5       5      5      nSn	[        U R                  R                  5       5      S:X  a  U R                  5         UR                   HÂ  n
U R!                  U
R"                  5      nX°R                  ;   d  M/  UR%                  5       U R                  U   R%                  5       :X  d  M`  Sn	U R'                  [        R(                  5      nX:l        XŠl        [.        R0                  " U R3                  5       5      U
l        XÊl        XÊl        MÄ     U	(       dð  U(       aé  [        UR                  5      S:”  aÐ  [
        R:                  " 5       nSUl        U R!                  UR"                  5      nU R'                  [        R(                  5      nX=l        X�l        [.        R0                  " U R3                  5       5      Ul        XÍl        XÍl        Sn	UR                  nUR=                  U5        UR>                  S	-   Ul        Xçl        U	(       aq  [A        U5      n[        RB                  " 5       nUS   RD                  Ul"        [        RF                  " U[        RH                  S5      US'   U RK                  US
/5        g g )Nr6  r0  r7  r8  r   FTiZ 	 r€   z#local_oid:1.3.6.1.4.1.7165.4.3.14:0)&r�   r‚   rƒ   r„   r   r   r9  r:  rn   r�  r†   rž  r*  r+  r,  r;  rÀ  r¿  r  Úsequence_numberÚSEQ_NEXTr<  Úoriginating_change_timer   rß   rº  Úoriginating_invocation_idÚoriginating_usnÚ	local_usnÚreplPropertyMetaData1Úappendrz  r   rO  r.   r  r  rP  )r/   r.   r=  r  ÚaddifnotexistrŠ   r>  r:  ÚnowÚfoundr?  r@  ÚseqÚo2ÚtabÚreplBlobr  s                    r   Ú"set_attribute_replmetadata_versionÚ(SamDB.set_attribute_replmetadata_versionû  sf  € à�k‰kÐ%;¸bÑ%@Ü #× 1Ñ 1Ø$8Ð#9Ø!7Ð 8ð ð :ˆô ˆs‹8�q‹=Øäœ(×;Ñ;Ø˜a™&Ð!7Ñ8¸Ñ;ó=ˆà�h‰hˆÜ×Ò¤¤D§I¢I£KÓ 0Ó1ˆØˆÜˆt×!Ñ!×&Ñ&Ó(Ó)¨QÓ.Ø×$Ñ$Ô&Ø—”ˆAà×-Ñ-¨a¯g©gÓ6ˆGØ×,Ñ,Õ,Ø�y‰y‹{˜d×0Ñ0°Ñ9×?Ñ?ÓAÕAØ�Ø×*Ñ*¬3¯<©<Ó8�Ø!”	Ø,/Ô)Ü.2¯iªi¸×8NÑ8NÓ8PÓ.Q�Ô+Ø$'Ô!Ø!–ñ ö ž¬3¨s¯y©y«>¸AÓ+=Ü×/Ò/Ó1ˆBØˆBŒHØ×-Ñ-¨b¯h©hÓ7ˆGØ×&Ñ&¤s§|¡|Ó4ˆCØŒJØ),Ô&Ü+/¯9ª9°T×5KÑ5KÓ5MÓ+NˆBÔ(Ø!$ÔØŒLØˆEØ—)‘)ˆCØ�J‰J�rŒNØŸ	™	 A™ˆCŒIØŒIæÜ “~ˆHÜ—+’+“-ˆCØ˜‘V—Y‘YˆCŒFä×"Ò" 8Ü#&×#7Ñ#7Ø#9ó;ð Ð&Ñ'ð �K‰K˜ÐCÐDÕEð r   c                 ó0   • [         R                  " U 5        g r,   )r   Ú'_dsdb_write_prefixes_from_schema_to_ldbr3   s    r   Úwrite_prefixes_from_schemaÚ SamDB.write_prefixes_from_schema2  s   € Ü×4Ò4°TÕ:r   c                 ó.   • [         R                  " U 5      $ r,   )r   Ú_dsdb_get_partitions_dnr3   s    r   rÿ  ÚSamDB.get_partitions_dn5  s   € Ü×+Ò+¨DÓ1Ð1r   c                 ó.   • [         R                  " X5      $ r,   )r   Ú_dsdb_get_nc_root)r/   r.   s     r   Úget_nc_rootÚSamDB.get_nc_root8  s   € Ü×%Ò% dÓ/Ð/r   c                 ó0   • [         R                  " XU5      $ r,   )r   Ú_dsdb_get_wellknown_dn)r/   Únc_rootÚwkguids      r   r©   ÚSamDB.get_wellknown_dn;  s   € Ü×*Ò*¨4¸&ÓAÐAr   c                 óR  • [        U[        5      (       d  [        U5      R                  S5      n[        R
                  " 5       n[        R                  " X R                  5       5      Ul        [        R                  " U[        R                  S5      US'   U R                  U5        g )NÚutf8Ú	minPwdAge©rñ   Úbytesrc   r”  r‚   rO  rã   re   r.   r  r  rP  ©r/   r  rè   s      r   Úset_minPwdAgeÚSamDB.set_minPwdAge>  ón   € Ü˜%¤×'Ñ'Ü˜“J×%Ñ% fÓ-ˆEÜ�KŠK‹MˆÜ�vŠv�dŸN™NÓ,Ó-ˆŒÜ×+Ò+¨E´3×3GÑ3GÈÓUˆˆ+‰Ø�‰�A�r   c                 óº   • U R                  U R                  5       [        R                  S/S9n[	        U5      S:X  a  g SUS   ;  a  g [        US   S   S   5      $ )Nrg  ©r}   r   r   ©r�   re   r‚   ró   r„   r†   ré  s     r   Úget_minPwdAgeÚSamDB.get_minPwdAgeF  óY   € Ø�k‰k˜$Ÿ.™.Ó*´#·.±.ÈÈˆkÐVˆÜˆs‹8�q‹=ØØ  A¡Ó&Øä�s˜1‘v˜kÑ*¨1Ñ-Ó.Ð.r   c                 óR  • [        U[        5      (       d  [        U5      R                  S5      n[        R
                  " 5       n[        R                  " X R                  5       5      Ul        [        R                  " U[        R                  S5      US'   U R                  U5        g )Nrf  Ú	maxPwdAgerh  rj  s      r   Úset_maxPwdAgeÚSamDB.set_maxPwdAgeO  rm  r   c                 óº   • U R                  U R                  5       [        R                  S/S9n[	        U5      S:X  a  g SUS   ;  a  g [        US   S   S   5      $ )Nru  ro  r   rp  ré  s     r   Úget_maxPwdAgeÚSamDB.get_maxPwdAgeW  rs  r   c                 óR  • [        U[        5      (       d  [        U5      R                  S5      n[        R
                  " 5       n[        R                  " X R                  5       5      Ul        [        R                  " U[        R                  S5      US'   U R                  U5        g )Nrf  ÚminPwdLengthrh  rj  s      r   Úset_minPwdLengthÚSamDB.set_minPwdLength`  so   € Ü˜%¤×'Ñ'Ü˜“J×%Ñ% fÓ-ˆEÜ�KŠK‹MˆÜ�vŠv�dŸN™NÓ,Ó-ˆŒÜ×.Ò.¨u´c×6JÑ6JÈNÓ[ˆˆ.ÑØ�‰�A�r   c                 óº   • U R                  U R                  5       [        R                  S/S9n[	        U5      S:X  a  g SUS   ;  a  g [        US   S   S   5      $ )Nr|  ro  r   rp  ré  s     r   Úget_minPwdLengthÚSamDB.get_minPwdLengthh  sZ   € Ø�k‰k˜$Ÿ.™.Ó*´#·.±.ÈÐHXˆkÐYˆÜˆs‹8�q‹=ØØ 3 q¡6Ó)Øä�s˜1‘v˜nÑ-¨aÑ0Ó1Ð1r   c                 óR  • [        U[        5      (       d  [        U5      R                  S5      n[        R
                  " 5       n[        R                  " X R                  5       5      Ul        [        R                  " U[        R                  S5      US'   U R                  U5        g )Nrf  ÚpwdPropertiesrh  rj  s      r   Úset_pwdPropertiesÚSamDB.set_pwdPropertiesq  so   € Ü˜%¤×'Ñ'Ü˜“J×%Ñ% fÓ-ˆEÜ�KŠK‹MˆÜ�vŠv�dŸN™NÓ,Ó-ˆŒÜ ×/Ò/°´s×7KÑ7KÈ_Ó]ˆˆ/ÑØ�‰�A�r   c                 óº   • U R                  U R                  5       [        R                  S/S9n[	        U5      S:X  a  g SUS   ;  a  g [        US   S   S   5      $ )Nrƒ  ro  r   rp  ré  s     r   Úget_pwdPropertiesÚSamDB.get_pwdPropertiesy  sZ   € Ø�k‰k˜$Ÿ.™.Ó*´#·.±.ÈÐHYˆkÐZˆÜˆs‹8�q‹=ØØ C¨¡FÓ*Øä�s˜1‘v˜oÑ.¨qÑ1Ó2Ð2r   c                 ór  • [         R                  " 5       n[         R                  " U SU R                  5       R	                  5       -  5      Ul        Ub*  [         R                  " U[         R                  S5      US'   O)[         R                  " / [         R                  S5      US'   U R                  U5        g )Nú1CN=Directory Service,CN=Windows NT,CN=Services,%sÚdSHeuristics)
r‚   rO  rã   Úget_config_basednrô   r.   r  r  r  rP  )r/   Údsheuristicsrè   s      r   Úset_dsheuristicsÚSamDB.set_dsheuristics‚  sž   € Ü�KŠK‹MˆÜ�vŠv�dÐOØ×.Ñ.Ó0×?Ñ?ÓAñBó CˆŒàÑ#ä×"Ò" <Ü#&×#7Ñ#7Ø#1ó3ð ˆnÒô ×"Ò" 2¤s×':Ñ':Ø#1ó3ð ˆnÑð 	�‰�A�r   c                 óÚ   • U R                  SU R                  5       R                  5       -  [        R                  S/S9n[        U5      S:X  a  S nU$ SUS   ;   a  US   S   S   nU$ S nU$ )NrŠ  r‹  ro  r   )r�   rŒ  rô   r‚   ró   r„   )r/   rŠ   r�  s      r   Úget_dsheuristicsÚSamDB.get_dsheuristics‘  s�   € Ø�k‰kÐMØ ×2Ñ2Ó4×CÑCÓEñFä #§¡°~Ð6Fð ð Hˆô ˆs‹8�q‹=ØˆLð Ðð ˜s 1™vÓ%Ø˜q™6 .Ñ1°!Ñ4ˆLð Ðð  ˆLàÐr   c                 ó†   • USS.nU(       a  X%S'   U(       a  X5S'   U(       a  [        U5      US'   U R                  U5        g)zîCreates an organizationalUnit object
:param ou_dn: dn of the new object
:param description: description attribute
:param name: name attribute
:param sd: security descriptor of the object, can be
an SDDL string or security.descriptor type
ÚorganizationalUnitrl  r¢   r2  r¨   N)r   r«   )r/   Úou_dnr¢   r2  r±   rè   s         r   Ú	create_ouÚSamDB.create_ouž  sE   € ð Ø0ñ2ˆö Ø*ˆmÑÞØˆf‰IæÜ(0°«ˆAÐ$Ñ%Ø�‰��r   c                 ó”   >• U R                  5          [        TU ]	  U5      nU R                  5         U$ !   U R	                  5         e = f)zsReturns the value of the sequence number according to the requested type
:param seq_type: type of sequence number
 )rÀ   rG   rD  rÁ   rÂ   )r/   Úseq_typerO  rM   s      €r   rD  ÚSamDB.sequence_number²  sN   ø€ ð 	×ÑÔ ð	&Ü‘'Ñ)¨(Ó3ˆCð
 ×#Ñ#Ô%Øˆ
øð	Ø×#Ñ#Ô%Øús	   “4 ´Ac                 ój   • U R                  S[        R                  S/S9n[        US   S   S   5      $ )z get the NTDS DN from the rootDSErÉ   ÚdsServiceNamer°  r   rè  ré  s     r   Úget_dsServiceNameÚSamDB.get_dsServiceNameÀ  s6   € à�k‰k˜r¬¯©ÀÐ?PˆkÐQˆÜ�3�q‘6˜/Ñ*¨1Ñ-Ó.Ð.r   c                 ój   • U R                  S[        R                  S/S9n[        US   S   S   5      $ )z"get the server DN from the rootDSErÉ   Ú
serverNamer°  r   rè  ré  s     r   Úget_serverNameÚSamDB.get_serverNameÅ  s5   € à�k‰k˜r¬¯©À¸~ˆkÐNˆÜ�3�q‘6˜,Ñ'¨Ñ*Ó+Ð+r   c                 ó^   • Uc  [         R                  " X5      $ [         R                  " XUS9$ )zDDo a DNS lookup in the database, returns the NDR database structures)Údns_partition)r   Úlookup)r/   r  r¤  s      r   Ú
dns_lookupÚSamDB.dns_lookupÊ  s/   € àÑ Ü—?’? 4Ó2Ð2ä—?’? 4Ø1>ñ@ð @r   c                 ó.   • [         R                  " X5      $ )z;Return the NDR database structures from a dnsRecord element)r   Úextract)r/   r  s     r   Údns_extractÚSamDB.dns_extractÒ  s   € ä×Ò Ó)Ð)r   c                 ó0   • [         R                  " XU5      $ )zVDo a DNS modification on the database, sets the NDR database
structures on a DNS name
)r   rJ  )r/   r  Únew_recordss      r   Údns_replaceÚSamDB.dns_replaceÖ  s   € ô ×Ò °Ó<Ð<r   c                 ó0   • [         R                  " XU5      $ )zÑDo a DNS modification on the database, sets the NDR database
structures on a LDB DN

This routine is important because if the last record on the DN
is removed, this routine will put a tombstone in the record.
)r   Úreplace_by_dn)r/   r.   r­  s      r   Údns_replace_by_dnÚSamDB.dns_replace_by_dnÜ  s   € ô ×%Ò% d°Ó<Ð<r   c                 óš   • [        5       (       d  [        S5      eUc  [        R                  " XU5      $ [        R                  " XUU5      $ )z{garbage_collect_tombstones(lp, samdb, [dn], current_time, tombstone_lifetime)
-> (num_objects_expunged, num_links_expunged)z6Cannot garbage collect tombstones: AD DC was not built)r   r   r   Ú _dsdb_garbage_collect_tombstones)r/   r.   Úcurrent_timeÚtombstone_lifetimes       r   Úgarbage_collect_tombstonesÚ SamDB.garbage_collect_tombstoneså  s`   € ô
 ×ÑÜð &ó 'ð 'ð Ñ%Ü×8Ò8¸Ø9EóGð Gô ×8Ò8¸Ø9EØ9KóMð Mr   c                 ó.   • [         R                  " U 5      $ )zcreate a RID set for this DSA)r   Ú_dsdb_create_own_rid_setr3   s    r   Úcreate_own_rid_setÚSamDB.create_own_rid_setö  s   € ä×,Ò,¨TÓ2Ð2r   c                 ó.   • [         R                  " U 5      $ )z.return a new RID from the RID Pool on this DSA)r   Ú_dsdb_allocate_ridr3   s    r   Úallocate_ridÚSamDB.allocate_ridú  s   € ä×&Ò& tÓ,Ð,r   c                 ó*   • U R                  5       u  pU$ )a  return the next free RID from the RID Pool on this DSA.

:note: This function is not intended for general use, and care must be
    taken if it is used to generate objectSIDs. The returned RID is not
    formally reserved for use, creating the possibility of duplicate
    objectSIDs.
)Úfree_rid_bounds)r/   Úridrþ   s      r   Únext_free_ridÚSamDB.next_free_ridþ  s   € ð ×%Ñ%Ó'‰ˆØˆ
r   c                 ó"  • [         R                  " X R                  5       5      nU R                  U[         R                  S/S9n US   S   n[         R                  " XS   R                  S5      5      nU R                  U[         R                  S/S9n US   S   n[         R                  " XS   R                  S5      5      nU R                  U[         R                  / S	QS9nS
nSn [        US   S   S   5      n	X˜:X  a(  [         R                  " [         R                  SU-  5      e [        US   S   S   5      n
 [        US   S   S   5      nX¨:X  d  X·:X  a  U	n
X§-  nOUS-  nX§-  nU
S-	  nX½:”  a7  Xš:X  a%  [         R                  " [         R                  S5      eU	n
X§-  nU
S-	  nUnX¼:  d  X½:”  a*  [         R                  " [         R                  SX¼U4-  5      eX½4$ ! [
         a*    [         R                  " [         R                  SU-  5      Sef = f! [
         a*    [         R                  " [         R                  SU-  5      Sef = f! [
         a    Un	 GNff = f! [
         a    Un
 GN7f = f! [
         a    Un GN5f = f)aa  return the low and high bounds (inclusive) of RIDs that are
    available for use in this DSA's current RID pool.

:note: This function is not intended for general use, and care must be
    taken if it is used to generate objectSIDs. The returned range of
    RIDs is not formally reserved for use, creating the possibility of
    duplicate objectSIDs.
ÚserverReferencer°  r   zUNo RID Set DN - Cannot find attribute serverReference of %s to calculate reference dnNr�  ÚrIDSetReferenceszVNo RID Set DN - Cannot find attribute rIDSetReferences of %s to calculate reference dn)ÚrIDAllocationPoolÚrIDPreviousAllocationPoolÚ
rIDNextRIDl   ÿÿ l   ÿÿÿÿ rÊ  zBad RID Set %srË  rÌ  r€   é    zRID pools out of RIDsz"Bad RID chosen %d from range %d-%d)r‚   rã   r¡  r�   ró   ÚKeyErrorÚLdbErrorÚERR_NO_SUCH_ATTRIBUTEr“  r†   ÚERR_OPERATIONS_ERROR)r/   Úserver_name_dnrŠ   Ú
server_refÚserver_ref_dnÚrid_set_refsÚ
rid_set_dnÚ
uint32_maxÚ
uint64_maxÚ
alloc_poolÚ	prev_poolÚnext_ridÚprev_pool_loÚprev_pool_his                 r   rÃ  ÚSamDB.free_rid_bounds	  sú  € ô Ÿš ×&9Ñ&9Ó&;Ó<ˆØ�k‰k˜~Ü #§¡Ø!2Ð 3ð ð 5ˆð	HØ˜Q™Ð 1Ñ2ˆJô Ÿš˜t°¡]×%9Ñ%9¸'Ó%BÓCˆà�k‰k˜}Ü #§¡Ø!3Ð 4ð ð 6ˆð	GØ˜q™6Ð"4Ñ5ˆLô —V’V˜D¨q¡/×"8Ñ"8¸Ó"AÓBˆ
ð �k‰k˜zÜ #§¡ò!/ð ð 0ˆð ˆ
Øˆ
ð	$Ü˜S ™VÐ$7Ñ8¸Ñ;Ó<ˆJð Ó#Ü—,’,œs×7Ñ7Ø/°*Ñ<ó>ð >ð	#Ü˜C ™FÐ#>Ñ?ÀÑBÓCˆIð	"Ü˜3˜q™6 ,Ñ/°Ñ2Ó3ˆHð
 Ó" hÓ&<Ø"ˆIØ Ñ-‰Hà˜‰MˆHð !Ñ-ˆØ  B‘ˆØÓ"ð Ó&Ü—l’l¤3×#;Ñ#;Ø#:ó<ð <ð #ˆIØ$Ñ1ˆLØ$¨™?ˆLØ#ˆHàÓ" hÓ&=Ü—,’,œs×7Ñ7ØCØ (¸ÐEñ FóGð Gð Ð%Ð%øôY ó 	HÜ—,’,Ü×)Ñ)ð,à.<ñ=ó>ð DHð	Hð	Hûô ó 	GÜ—,’,Ü×)Ñ)ð,à.;ñ<ó=ð CGð	Gð	Gûô( ó 	$Ø#‹Jð	$ûô ó 	#Ø"‹Ið	#ûô ó 	"Ø!‹Hð	"úsN   ÁG* ÂH! Ã-I Ä/I+ ÅI> Ç*4HÈ!4IÉI(É'I(É+I;É:I;É>JÊJc                 ó  • [         R                  " X R                  5       5      n[        U[         R                  5      (       a  [	        U5      n[         R                  " X5      nUR                  U5      (       d  UR                  U5        U$ )z�return a new DN expanded by adding the domain DN

If the dn is already a child of the domain DN, just
return it as-is.

:param dn: relative dn
)r‚   rã   re   rñ   rc   Úis_child_ofÚadd_base)r/   r.   re   Úfull_dns       r   rõ   ÚSamDB.normalize_dn_in_domaing  se   € ô —F’F˜4§¡Ó!1Ó2ˆ	ä�bœ#Ÿ&™&×!Ñ!Ü�R“ˆBä—&’&˜Ó"ˆØ×"Ñ" 9×-Ñ-Ø×Ñ˜YÔ'Øˆr   c                 ó:   • [         R                  " U /UQ70 UD6nU$ )rÉ   )r   Ú_dsdb_create_gkdi_root_key)r/   rï   Úkwargsr.   s       r   Únew_gkdi_root_keyÚSamDB.new_gkdi_root_keyy  s!   € ä×,Ò,¨TÐC°DÒC¸FÑCˆØˆ	r   c                 ó˜   • U R                  SS[        R                  S/S9nU R                  SUS   S   S   5      R	                  S5      $ )NrÉ   r¯  )r|   r~   r}   r   r   rf  )r�   r‚   ró   Úschema_format_valuer“  ré  s     r   Úget_admin_sidÚSamDB.get_admin_sid~  sW   € Ø�k‰kØ ¬#¯.©.ÀÀð ð Qˆð ×'Ñ'Ø˜3˜q™6 -Ñ0°Ñ3ó5ß5;±V¸F³^ð	Dr   )r*  r@   r?   )Nr   N)NTF)NNNNNNNN)TNN)NNNNrÉ   )FFNNNNNNNNNNNNNNNNNTNNNNNNNF)NNNNNNNNNNNNNNN)NNFNN)FN)F)T)NNNr,   )fr   r   r   r   Ú__doc__r*  r=   r‚   ÚFLG_DONT_CREATE_DBr0   rT   rY   Ú__str__rL   r`   re   ri   rs   rw   rp   r•   r˜   r¶   rÅ   rÛ   r  r  r*  ri  rs  rˆ  rŒ  rQ  r¢  r§  r«  ÚpropertyÚ
domain_sidr±  Úconnecting_user_sidr¶  rº  rµ  rÀ  rÆ  rË  rÏ  rÓ  r×  rÛ  rà  rä  rê  rî  rñ  rõ  rø  r~  r  r
  r  r  r  r  r#  r'  r-  r,  rA  rS  rW  rÿ  r^  r©   rk  rq  rv  ry  r}  r€  r„  r‡  rŽ  r‘  r–  rD  r�  r¡  r¦  rª  r®  r²  r¸  r¼  rÀ  rÅ  rÃ  rõ   rç  rë  r    Ú__classcell__)rM   s   @r   r&   r&   6   sé  ø† Ùà€M÷ñ ð(   D°dÈØ!¨×)?Ñ)?Ø¨TØ"¨D÷2÷,?ò7ð €Gò#ò"ò.ò-òDòEð GKØ05ô+òZò*ð2 ;?ØDHØ+/ô2òh&ò*3ðl 8<Ø.2Ø04ô~&ò@ð. KOØ=?ôðD 9>ØLPØLPØLPØDHØFJØHLØDHØ#(ôj&ðZ $(ØØØ!Ø Ø#Ø Ø"ØØ#Ø#Ø#'Ø#'Ø $Ø*.ôdðL FJØ;?Ø04ô<&ò|&ð, @Dô*&ôX(&òT.ò0ñ ˜.¨.Ø2ñ4€JòHñ
 #Ð#:Ø'CñEÐò?ò4ñ Ð.Ð0AØ!5ñ7€Mò:ð 5:ôZòWòXòSòDòUò
Aò1ò-ò6ò2ò2ò-ò
7ò
ò7ò
<ôhôUòòTòVòòKò ð> :?ô5Fòn;ò2ò0òBòò/òò/òò2òò3òòôõ(ò/ò
,ô
@ò*ò=ò=ð 7;ôMò"3ò-ò	ò\&ò|ò$÷
Dð Dr   r&   c                   ó^   • \ rS rSrSrSS jrS rS rS rS r	S	 r
S
 rS rS rS rS rSrg)Údsdb_Dni†  za class for binary DNNc                 óŠ  • Uc^  UR                  S5      (       a  [        R                  nO7UR                  S5      (       a  [        R                  nO[        R                  nU[        R                  [        R                  4;   a…  UR                  S5      n[        U5      S:  a  [        SU-  5      eS[        US   5      -   [        US   5      -   nUSU U l	        U R                  S	[        US   5      -   S
 U l
        X%S U l        OX l        SU l	        SU l
        [        R                  " XR                  5      U l        g)zcreate a dsdb_DnNzB:zS:Ú:é   zInvalid DN %sr€   r   é   rÏ   rÉ   )Ú
startswithr   ÚDSDB_SYNTAX_BINARY_DNÚDSDB_SYNTAX_STRING_DNÚDSDB_SYNTAX_OR_NAMErû  r„   ÚRuntimeErrorr†   ÚprefixÚbinaryÚdnstringr‚   rã   r.   )r/   r-   r  Ú
syntax_oidÚcolonsÚ
prefix_lens         r   r0   Údsdb_Dn.__init__‰  s  € àÑà×"Ñ" 4×(Ñ(Ü!×7Ñ7‘
Ø×$Ñ$ T×*Ñ*Ü!×7Ñ7‘
ä!×5Ñ5�
Øœ$×4Ñ4´d×6PÑ6PÐQÓQà—^‘^ CÓ(ˆFÜ�6‹{˜Q‹Ü" ?°XÑ#=Ó>Ð>ØœS ¨¡›^Ñ+¬c°&¸±)«nÑ<ˆJØ" 1 ZÐ0ˆDŒKØŸ+™+ a¬#¨f°Q©i«.Ñ&8¸Ð<ˆDŒKØ$ [Ð1ˆD�Mà$ŒMØˆDŒKØˆDŒKÜ—&’&˜§¡Ó.ˆ�r   c                 ó`   • U R                   [        U R                  R                  SS95      -   $ )Nr€   )Úmode)rÿ  rc   r.   rò   r3   s    r   rï  Údsdb_Dn.__str__¢  s(   € Ø�{‰{œS §¡×!5Ñ!5¸1Ð!5Ð!=Ó>Ñ>Ð>r   c                 óà   • U nUnUR                   R                  S5      nUR                   R                  S5      n[        XE5      nUS:w  a  U$ [        UR                  UR                  5      nU$ )z5compare dsdb_Dn values similar to parsed_dn_compare()rß   r   )r.   rä   r   r   )r/   ÚotherÚdn1Údn2Úguid1Úguid2Úvs          r   Ú__cmp__Údsdb_Dn.__cmp__¥  sc   € àˆØˆØ—‘×-Ñ-¨fÓ5ˆØ—‘×-Ñ-¨fÓ5ˆä�ÓˆØ�‹6ØˆHÜ�—
‘
˜CŸJ™JÓ'ˆØˆr   c                 ó*   • U R                  U5      S:H  $ ©Nr   ©r  ©r/   r
  s     r   Ú__eq__Údsdb_Dn.__eq__³  ó   € Ø�|‰|˜EÓ" aÑ'Ð'r   c                 ó*   • U R                  U5      S:g  $ r  r  r  s     r   Ú__ne__Údsdb_Dn.__ne__¶  r  r   c                 ó*   • U R                  U5      S:  $ r  r  r  s     r   Ú__lt__Údsdb_Dn.__lt__¹  ó   € Ø�|‰|˜EÓ" QÑ&Ð&r   c                 ó*   • U R                  U5      S:*  $ r  r  r  s     r   Ú__le__Údsdb_Dn.__le__¼  r  r   c                 ó*   • U R                  U5      S:„  $ r  r  r  s     r   Ú__gt__Údsdb_Dn.__gt__¿  r  r   c                 ó*   • U R                  U5      S:¬  $ r  r  r  s     r   Ú__ge__Údsdb_Dn.__ge__Â  r  r   c                 óP   • U R                   S:X  a  g[        U R                  S5      $ )z6return binary part of a dsdb_Dn as an integer, or NonerÉ   Né   )rÿ  r†   r   r3   s    r   Úget_binary_integerÚdsdb_Dn.get_binary_integerÅ  s"   € à�;‰;˜"ÓØÜ�4—;‘; Ó#Ð#r   c                 óB   • [         R                  " U R                  5      $ )zreturn binary as a byte string)ÚbinasciiÚ	unhexlifyr   r3   s    r   r
   Údsdb_Dn.get_bytesË  s   € ä×!Ò! $§+¡+Ó.Ð.r   )r   r.   r  rÿ  r,   )r   r   r   r   rí  r0   rï  r  r  r  r  r!  r$  r'  r+  r
   r    r   r   r   rõ  rõ  †  s<   † Ùô/ò2?òò(ò(ò'ò(ò'ò(ò$õ/r   rõ  )"rí  rn   r‚   rž  r•  rP   rx  r   r   Ú	samba.ndrr   r   Úsamba.dcerpcr   r   Úsamba.commonr	   r
   r   r   r   r   r   r   r.  Ú__docformat__r   r…   r   r#   ÚLdbr&   Úobjectrõ  r   r   r   Ú<module>r7     s   ðñ. /ã Û 
Û Û Û 	Û 	ß  ß *ß 'Ý (ß 'Ý !Ý  Ý  ß )Û à"€òô	�ô 	ô	˜ô 	ôMDˆE�I‰Iô MDô`2G/ˆfõ G/r   