Ë
    þI¶dXó  ã                   ó  — d Z ddlZddlZddlZddlZddlZddlZddlmZmZ ddl	m
Z
mZ ddlmZmZ ddlmZ ddlmZmZ ddlmZ dd	lmZ ddlZd
Zd„ Z G d„ de«      Z G d„ de«      Z G d„ dej6                  «      Z G d„ de«      Zy)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ÚrestructuredTextc                   ó   — y)NÚtdb© r   ó    ú-/usr/lib/python3/dist-packages/samba/samdb.pyÚget_default_backend_storer   +   s   € Ør   c                   ó   — e Zd Zy)Ú
SamDBErrorN©Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   .   ó   „ Ør   r   c                   ó   — e Zd Zy)ÚSamDBNotFoundErrorNr   r   r   r   r   r   1   r   r   r   c            
       óö  ‡ — e Zd ZdZi Zi Z G d„ d«      Zdddddej                  ddddf
ˆ fd„	Z	d[ˆ fd„	Z
d„ Zd	„ Zd
„ Zd„ Zd„ Zd„ Z	 	 d\d„Zd„ Zd„ Z	 	 	 d]d„Zd„ Zd„ Z	 	 	 d^d„Zd„ Z	 	 d_d„Z	 	 	 	 	 	 	 	 	 d`d„Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dad„Z	 	 	 dbd„Zd„ Z	 dcd„Zddd„Zd„ Z d„ Z! e"e!e d¬ «      Z#d!„ Z$d"„ Z% e"e%e$d#¬ «      Z&d$„ Z'	 ddd%„Z(d&„ Z)d'„ Z*d(„ Z+d)„ Z,d*„ Z-d+„ Z.d,„ Z/d-„ Z0d.„ Z1d/„ Z2d0„ Z3d1„ Z4d2„ Z5d3„ Z6d4„ Z7d5„ Z8ded6„Z9ded7„Z:d8„ Z;d9„ Z<d:„ Z=d;„ Z>d<„ Z?d=„ Z@	 ddd>„ZAd?„ ZBd@„ ZCdA„ ZDdB„ ZEdC„ ZFdD„ ZGdE„ ZHdF„ ZIdG„ ZJdH„ ZKdI„ ZLdJ„ ZMdK„ ZNdL„ ZOdfdM„ZPˆ fdN„ZQdO„ ZRdP„ ZSdgdQ„ZTdR„ ZUdS„ ZVdT„ ZW	 dgdU„ZXdV„ ZYdW„ ZZdX„ Z[dY„ Z\dZ„ Z]ˆ xZ^S )hÚSamDBzThe SAM database.c                   ó   — e Zd Zd„ Zd„ Zd„ Zy)úSamDB._CleanUpOnErrorc                 ó    — || _         || _        y ©N)ÚsamdbÚdn)Úselfr$   r%   s      r   Ú__init__zSamDB._CleanUpOnError.__init__;   s   € ØˆDŒJØˆD�Gr   c                  ó   — y r#   r   ©r&   s    r   Ú	__enter__zSamDB._CleanUpOnError.__enter__?   s   € Ør   c                 óR   — |�%| j                   j                  | j                  «       y)NF)r$   Údeleter%   )r&   Úexc_typeÚexc_valÚexc_tbs       r   Ú__exit__zSamDB._CleanUpOnError.__exit__B   s%   € ØÐ#ð —
‘
×!Ñ! $§'¡'Ô*ð r   N)r   r   r   r'   r*   r0   r   r   r   Ú_CleanUpOnErrorr!   :   s   „ ò	ò	ó
	r   r1   NTc           	      óè   •— || _         |	sd }n|€|�|j                  «       }|| _        t        t        | �  |||||||¬«       |rt        j                  | «       |
�t        j                  | |
«       y y )N)ÚurlÚlpÚmodules_dirÚsession_infoÚcredentialsÚflagsÚoptions)	r4   Ú	samdb_urlr3   Úsuperr   r'   r   Ú_dsdb_set_global_schemaÚ_dsdb_set_am_rodc)r&   r3   r4   r5   r6   r7   r8   r9   Úglobal_schemaÚauto_connectÚam_rodcÚ	__class__s              €r   r'   zSamDB.__init__N   s‚   ø€ ð ˆŒÙØ‰CØˆ[˜R˜^Ø—,‘,“.ˆCàˆŒäŒe�TÑ#¨°ÀØ1=È;Ð^cØ,3ð 	$ô 	5ñ Ü×(Ñ(¨Ô.àÐÜ×"Ñ" 4¨Õ1ð r   c                 óÌ   •— | j                   �:t        j                  j                  |«      s| j                   j	                  |«      }|| _        t        t        | �#  |||¬«       y)zconnect to the databaseN)r3   r8   r9   )	r4   ÚosÚpathÚexistsÚprivate_pathr3   r;   r   Úconnect)r&   r3   r8   r9   rA   s       €r   rG   zSamDB.connectd   sR   ø€ à�7‰7Ð¤r§w¡w§~¡~°cÔ':Ø—'‘'×&Ñ& sÓ+ˆCØˆŒäŒe�TÑ" s°%Ø+2ð 	#õ 	4r   c                 ó,   — t        j                  | «      S )zreturn True if we are an RODC)r   Ú_am_rodcr)   s    r   r@   zSamDB.am_rodcm   s   € ä�}‰}˜TÓ"Ð"r   c                 ó,   — t        j                  | «      S )z%return True if we are an PDC emulator)r   Ú_am_pdcr)   s    r   Úam_pdczSamDB.am_pdcq   s   € ä�|‰|˜DÓ!Ð!r   c                 ó4   — t        | j                  «       «      S )zreturn the domain DN)ÚstrÚget_default_basednr)   s    r   Ú	domain_dnzSamDB.domain_dnu   s   € ä�4×*Ñ*Ó,Ó-Ð-r   c                 ó4   — t        | j                  «       «      S )zreturn the schema partition dn)rN   Úget_schema_basednr)   s    r   Ú	schema_dnzSamDB.schema_dny   s   € ä�4×)Ñ)Ó+Ó,Ð,r   c                 ó`   — t         j                  j                  }| j                  ||d¬«       y)z|Disables an account

        :param search_filter: LDAP filter to find the user (eg
            samccountname=name)
        T©ÚonN)Úsambar   ÚUF_ACCOUNTDISABLEÚtoggle_userAccountFlags©r&   Úsearch_filterr8   s      r   Údisable_accountzSamDB.disable_account}   s(   € ô —
‘
×,Ñ,ˆØ×$Ñ$ ]°E¸dÐ$ÕCr   c                 ó–   — t         j                  j                  t         j                  j                  z  }| j	                  ||d¬«       y)z{Enables an account

        :param search_filter: LDAP filter to find the user (eg
            samccountname=name)
        FrU   N)rW   r   rX   ÚUF_PASSWD_NOTREQDrY   rZ   s      r   Úenable_accountzSamDB.enable_account‡   s7   € ô —
‘
×,Ñ,¬u¯z©z×/KÑ/KÑKˆØ×$Ñ$ ]°E¸eÐ$ÕDr   c                 ó¼  — | j                  | j                  «       t        j                  |dg¬«      }t	        |«      dk(  rt        d|z  «      ‚t	        |«      dk(  sJ ‚|d   j                  }t        |d   d   d   «      }|r|r||z  rd|z  }	t        |	«      ‚||z  }
n|r||z  sd|z  }	t        |	«      ‚|| z  }
||
k(  ryd	|||
fz  }| j                  |«       y)
an  Toggle_userAccountFlags

        :param search_filter: LDAP filter to find the user (eg
            samccountname=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
)	ÚsearchrP   ÚldbÚSCOPE_SUBTREEÚlenÚ	Exceptionr%   ÚintÚmodify_ldif)r&   r[   r8   Ú	flags_strrV   ÚstrictÚresÚ
account_dnÚold_uacÚerrorÚnew_uacÚmods               r   rY   z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 Uš?Ø:¸YÑF�Ü Ó&Ð&à ‘o‰Gá˜w¨šØ<¸yÑH�Ü Ó&Ð&à  Ñ&ˆGà�gÒØðð �7˜GÐ$ñ%ˆð 	×Ñ˜Õr   c                 ó  — | j                  | j                  «       t        j                  |g ¬«      }t	        |«      dk(  rt        d|z  «      ‚t	        |«      dk(  sJ ‚|d   j                  }d|z  }| j                  |«       y)z�Forces a password change at next login

        :param search_filter: LDAP filter to find the user (eg
            samccountname=name)
        rb   r   úUnable to find user "%s"rg   z=
dn: %s
changetype: modify
replace: pwdLastSet
pwdLastSet: 0
N)rh   rP   ri   rj   rk   rl   r%   rn   ©r&   r[   rq   Úuser_dnrv   s        r   Ú#force_password_change_at_next_loginz)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                 ó   — | j                  | j                  «       t        j                  |g ¬«      }t	        |«      dk(  rt        d|z  «      ‚t	        |«      dk7  rt        d|z  «      ‚|d   j                  }d|z  }| j                  |«       y)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)
        rb   r   rx   rg   zUser "%s" is not uniquez?
dn: %s
changetype: modify
replace: lockoutTime
lockoutTime: 0
N)	rh   rP   ri   rj   rk   r   r   r%   rn   ry   s        r   Úunlock_accountz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
                 ót  — |rd|›d|›d| j                  «       ›�}
n4d|›d| j                  | j                  «       t        j                  «      ›�}
|
|ddœ}|�t        |«      |d<   |�||d<   |�||d<   |�||d	<   |�t        |«      |d
<   |	�
||d<   |	|d<   |�t        |«      |d<   | j                  |«       y)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)rP   Úget_wellknown_dnrO   r   ÚDS_GUID_USERS_CONTAINERr	   r   Úadd)r&   Ú	groupnameÚgroupouÚ	grouptyper†   ÚmailaddressÚnotesÚsdÚ	gidnumberÚ	nisdomainÚgroup_dnÚ
ldbmessages               r   ÚnewgroupzSamDB.newgroupì   sø   € ò Ú(1²7¸D¿N¹NÔ<LÐM‰Hð ò &/°×0EÑ0EØ(,×(?Ñ(?Ó(AÜ(,×(DÑ(Dô1Fð GˆHð %Ø(1Ø%,ñ.ˆ
ð Ð Ü&5°iÓ&@ˆJ�{Ñ#àÐ"Ø(3ˆJ�}Ñ%àÐ"Ø!,ˆJ�vÑàÐØ!&ˆJ�vÑàÐ Ü&5°iÓ&@ˆJ�{Ñ#àÐ Ø(1ˆJ�}Ñ%Ø-6ˆJÐ)Ñ*àˆ>Ü19¸"³ˆJÐ-Ñ.à�‰�Õr   c                 óÂ  — dt        j                  |«      ›dd›d| j                  «       ›d�}| j                  «        	 | j	                  | j                  «       t         j
                  |g ¬«      }t        |«      dk(  rt        d|z  «      ‚t        |«      d	k(  sJ ‚| j                  |d   j                  «       | j                  «        y
#  | j                  «        ‚ xY w)zLDeletes a group

        :param groupname: Name of the target group
        ú(&(sAMAccountName=ú)(objectCategory=ú#CN=Group,CN=Schema,CN=Configurationr€   ú))rb   r   úUnable to find group "%s"rg   N©ri   Úbinary_encoderP   Útransaction_startrh   rj   rk   rl   r,   r%   Útransaction_commitÚtransaction_cancel)r&   r�   ÚgroupfilterÚtargetgroups       r   Údeletegroupz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           	      óR  — d}g d¢}d|v r|}|D ]'  }||vsŒt        d|›ddj                  |«      ›d�«      ‚ d|v r+|d	t        j                  |«      t        j
                  fz  z  }d
|v r|dt        j                  |«      z  z  }d|v r:|}|d   dk7  rd|z  }|dt        j                  t        j                  |«      fz  z  }d|v r:|}|d   dk7  rd|z  }|dt        j                  t        j                  |«      fz  z  }d|v r|dt        j                  |«      z  z  }d|z  }|S )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))rl   Újoinri   r¢   r   ÚATYPE_NORMAL_ACCOUNTÚATYPE_WORKSTATION_TRUST)r&   ÚmemberÚmember_typesÚfilterÚall_member_typesÚmember_typeÚsamaccountnames          r   Úgroup_member_filterzSamDB.group_member_filter5  s§  € ØˆòÐð �LÑ Ø+ˆLà'ò 	LˆKØÐ"2Ò2Ýâ!,¨d¯i©iÐ8HÕ.Ið!Kó Lð 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                 ó(  — |€g d¢}dt        j                  |«      ›dd›d| j                  «       ›d�}| j                  «        	 | j	                  | j                  «       t         j
                  |dg¬	«      }t        |«      d
k(  rt        d|z  «      ‚t        |«      dk(  sJ ‚d}dt        |d
   j                  «      z  }	|D �]æ  }
d}|€| j                  «       }	 t        j                  |
«      }dt        |«      z  }|€^	 t        j                  | |
«      }|j                  «       |j                  d«      k(  r| j!                  |«      }n|}|j                  d«      }|€®| j#                  |
|«      }| j	                  |t         j
                  |g ¬	«      }t        |«      dkD  r1d}|D ]  }|d|j%                  d«      z  z  }Œ t        d|
›d|›�«      ‚t        |«      dk7  rt        d|
z  «      ‚|d
   j                  j                  d«      }|du rS|d
   j%                  d«      �*t'        |«      |d
   d   D �cg c]  }t        |«      ‘Œ c}vrd}|	dt        |«      z  z  }	�Œ£|du s�Œ©|d
   j%                  d«      €�Œ¿t'        |«      |d
   d   v s�ŒÔd}|	dt        |«      z  z  }	�Œé |du r| j)                  |	«       | j+                  «        y# t        $ r Y �Œàw xY w# t        $ r}Y d}~�Œ“d}~ww xY wc c}w #  | j-                  «        ‚ xY w)zäAdds or removes group members

        :param groupname: Name of the target group
        :param members: list of group members
        :param add_members_operation: Defines if its an add or remove
            operation
        N)r¬   r�   r­   rœ   r�   rž   r€   rŸ   r·   rb   r   r    rg   Fz
dn: %s
changetype: modify
z<SID=%s>r«   z%s
r%   zFound multiple results for "z":
z)Unable to find "%s". Operation cancelled.Tzadd: member
member: %s
zdelete: member
member: %s
)ri   r¢   rP   r£   rh   rj   rk   rl   rN   r%   r   Údom_sidÚ
ValueErrorÚDnÚget_linearizedÚextended_strÚnormalize_dn_in_domainr½   Úgetr
   rn   r¤   r¥   )r&   r�   ÚmembersÚadd_members_operationr¸   Úmember_base_dnr¦   r§   ÚmodifiedÚaddtargettogroupr·   Útargetmember_dnÚ	membersidÚ	member_dnÚfull_member_dnÚer¹   ÚtargetmemberÚtargetmemberlist_strÚmsgÚxs                        r   Úadd_remove_group_memberszSamDB.add_remove_group_membersj  sÉ  € ð ÐÚ8ˆLøô ×Ñ˜iÕ(Ò*OÐQU×Q_ÑQ_ÕQaðcˆð 	×ÑÔ ðH	&ØŸ+™+¨4¯>©>Ó+;Ä3×CTÑCTØ1<ÀXÀJð &ó PˆKä�;Ó 1Ò$ÜÐ ;¸iÑ GÓHÐHÜ�{Ó# qÒ(Ð)Ð(àˆHð ô ˆ;�q‰>×ÑÓñ Ðð
 "ó 1�Ø"&�Ø!Ð)Ø%)§^¡^Ó%5�NðÜ (× 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˜ð #Ð*Ø!×5Ñ5°f¸lÓK�FØ#'§;¡;°NÜ58×5FÑ5FØ:@Ø57ð $/ó $9�Lô
 ˜<Ó(¨1Ò,Ø/1Ð,Ø#/ò K˜CØ0°F¸S¿W¹WÀT»]Ñ4JÑJÑ0ðKå'Ú)/Ñ1Eð)Gó Hð Hä˜<Ó(¨AÒ-Ü'Ð(SÐV\Ñ(\Ó]Ð]Ø&2°1¡o×&8Ñ&8×&EÑ&EÀaÓ&H�Oà(¨DÑ0°kÀ!±n×6HÑ6HÈÓ6RÐ6ZÔ^gÐhwÓ^xð  R]ð  ^_ñ  R`ð  aiñ  Rjö  Akð  MNô  BEð  FGõ  BHò  Akñ  _kØ#�HØ$ð )ä
ˆ?Óñ)ñ Ò$ð +¨eÓ3¸ÀQ¹×9KÑ9KÈHÓ9UÒ9aÔfoÐpó  gAð  EPð  QRñ  ESð  T\ñ  E]ó  g]Ø#�HØ$ð )ä
ˆ?Óñ)ñ Ò$ð_1ðf ˜4ÑØ× Ñ Ð!1Ô2ð ×#Ñ#Õ%øôe "ò Úðûô &ò Ýûðüò( Akøð	Ø×#Ñ#Ô%Øúsu   ÁBK> Ã#KÃ>K> ÄAK"ÅCK> È:K9ÉK> É+K> ÊK> Ê+K> Ë	KËK> ËKËK> Ë"	K6Ë+K> Ë1K6Ë6K> Ë>Lc                 óF  — |€y||v rt        |«      t        ||   «      k(  ryt        |«      dk(  r;||v r6t        j                  g t        j                  |«      }|j                  |«       yt        j                  |t        j                  |«      }|j                  |«       y)aA  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   )rN   rk   ri   ÚMessageElementÚFLAG_MOD_DELETEr�   ÚFLAG_MOD_REPLACE)r&   rÒ   ÚoldÚ	attr_nameÚvalueÚels         r   Úprepare_attr_replacezSamDB.prepare_attr_replaceÆ  s�   € ð ˆ=ØØ˜Ñ¤ E£
¬c°#°i±.Ó.AÒ AØô ˆu‹:˜Š?Ø˜CÑÜ×'Ñ'¨¬C×,?Ñ,?ÀÓK�Ø—‘˜”Øô ×Ñ ¤s×';Ñ';¸YÓGˆØ�‰��r   c                 ó>  — |€i }|||dœ}|j                  «       D ]  \  }}|�Œ	||v sŒt        ||   «      ||<   Œ  |d   r!|d   j                  d«      s|dxx   dz  cc<   t        t	        d|j                  «       «      «      }	dj                  |	«      }
|
dk(  r|S |
S )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«   )ÚitemsrN   ÚendswithÚlistr¹   Úvaluesr´   )r&   Ú
given_namerà   ÚsurnameÚ	old_attrsÚfallback_defaultrf   rÚ   Ú
attr_valueÚattrs_valuesÚfullnames              r   Úfullname_from_nameszSamDB.fullname_from_namesÝ  sÃ   € ð
 ÐØˆIà(Ø%Øñ ˆð
 &+§[¡[£]ò 	=Ñ!ˆI�zØÑ! i°9Ò&<Ü#& y°Ñ';Ó#<��iÒ ð	=ð �Ò U¨:Ñ%6×%?Ñ%?ÀÔ%DØ�*Ó Ñ$Óô œF 4¨¯©«Ó8Ó9ˆð —8‘8˜LÓ)ˆà�rŠ>Ø#Ð#àˆr   c                 ón  — | j                  |||¬«      }|} |€|dk7  r|} |rd| ›d|›d| j                  «       ›�}!n4d| ›d| j                  | j                  «       t        j
                  «      ›�}!t        j                  | | j                  «       «      j                  «       j                  dd«      }"|›d|"›�}#|!||#dd	œ}$|r/t        t        j                  t        j                  z  «      |$d
<   d}|�||$d<   |�||$d<   |dk7  r
||$d<   ||$d<   |�d|z  |$d<   |	�|	|$d<   |
�|
|$d<   |�||$d<   |�||$d<   |�||$d<   |�||$d<   |�||$d<   |�||$d<   |�||$d<   |�||$d<   |�||$d<   |�||$d<   |�t        |«      |$d<   d}%t        t        d„ |||||||f«      «      �rít        j                   «       }%t        j                  | |!«      |%_        |�1t        j$                  t        |«      t        j&                  d «      |%d <   |�1t        j$                  t        |«      t        j&                  d!«      |%d!<   |�1t        j$                  t        |«      t        j&                  d"«      |%d"<   |�1t        j$                  t        |«      t        j&                  d#«      |%d#<   |�1t        j$                  t        |«      t        j&                  d$«      |%d$<   |�1t        j$                  t        |«      t        j&                  d%«      |%d%<   |�Št        j$                  t        |«      t        j&                  d&«      |%d&<   t        j$                  t        |«      t        j&                  d'«      |%d'<   t        j$                  d(t        j&                  d)«      |%d)<   | j)                  «        	 | j+                  |$«       | j-                  | |!«      5  |%r| j/                  |%«       |r)| j1                  d*t        j2                  |!«      z  ||«       ddd«       | j5                  «        y# 1 sw Y   ŒxY w#  | j7                  «        ‚ xY w)+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„   ra   Frá   rß   ÚdisplayNameÚnameú%s.rà   ÚprofilePathÚ
scriptPathÚ	homeDriveÚhomeDirectoryÚtitleÚ
departmentÚcompanyr†   r‡   ÚwWWHomePageÚtelephoneNumberÚphysicalDeliveryOfficeNamerŒ   c                 ó
   — | d uS r#   r   )Úbs    r   ú<lambda>zSamDB.newuser.<locals>.<lambda>|  s
   € ˜Q d˜]€ r   ÚuidÚ	uidNumberr‰   ÚgecosÚ
loginShellÚunixHomeDirectoryr‹   rŠ   zABCD!efgh12345$67890ÚunixUserPasswordú(distinguishedName=%s))rï   rP   r�   rO   r   rŽ   ri   rÁ   Úcanonical_strÚreplacerN   ÚUF_NORMAL_ACCOUNTÚUF_SMARTCARD_REQUIREDr   ÚanyÚmapÚMessager%   rÖ   rØ   r£   r�   r1   ÚmodifyÚsetpasswordr¢   r¤   r¥   )&r&   ÚusernameÚpasswordÚ'force_password_change_at_next_login_reqÚuseusernameascnÚuserouré   Ú	givennamerà   ÚprofilepathÚ
scriptpathÚ	homedriveÚhomedirectoryÚjobtitlerý   rþ   r†   r“   ÚinternetaddressÚtelephonenumberÚphysicaldeliveryofficer•   r  Ú	uidnumberr–   r  Ú
loginshellr  r—   ÚunixhomeÚsmartcard_requiredÚdisplaynameÚcnrz   Ú	dnsdomainÚuser_principal_namer™   Úldbmessage2s&                                         r   ÚnewuserzSamDB.newuserþ  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äŸ+™+›-ˆ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ñ 	NÙØ—K‘K Ô,ñ Ø×$Ñ$Ð&>Ü&)×&7Ñ&7¸Ó&@ñ'Aà%-Ø%LôN÷	Nð ×#Ñ#Õ%÷	Nð 	Nûð	Ø×#Ñ#Ô%Øús$   Î#P! Î=?PÏ<P! ÐPÐP! Ð!P4c                 ó˜  — | j                  |||¬«      }|�|}|€|dk(  rt        d«      ‚| j                  «       }|r| j                  |«      }d|›d|›�}|ddœ}|�||d<   |�||d	<   |�||d
<   |�d|z  |d<   |�||d<   |�||d<   |	�|	|d<   |
�|
|d<   |�||d<   |�||d<   |�||d<   |�||d<   |�||d<   | j	                  |«       |S )a³  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ß   rõ   r÷   rà   rü   rý   rþ   r†   r‡   rÿ   r   Úmobiler  )rï   rl   rP   rÄ   r�   )r&   ÚfullcontactnameÚouré   r  rà   r'  r  rý   rþ   r†   r“   r   r!  Úmobilenumberr"  r(  Úcontactcontainer_dnÚ
contact_dnr™   s                       r   Ú
newcontactz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                 óf  — t        j                  dd|«      }|j                  d«      rt        d|z  «      ‚d|z  }| j	                  | j                  «       t        j                  «      }	|r| j                  |«      }	d|›d|	›�}
|
|dd	œ}|�||d<   |r||d<   t        t        j                  t        j                  z  «      }|rt        t        j                  «      }||d<   |r#dj                  || j                  «       «      |d<   | j                  «        	 | j                  |«       |rT|j!                  «       }| j#                  | |
«      5  | j%                  dt'        j(                  |
«      z  |d«       d
d
d
«       | j+                  «        y
# 1 sw Y   ŒxY w#  | j-                  «        ‚ xY w)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†   ÚservicePrincipalNamera   z{}.{}ÚdNSHostNamer  F)ÚreÚsubÚcountrl   r�   rO   r   ÚDS_GUID_COMPUTERS_CONTAINERrÄ   rN   ÚUF_WORKSTATION_TRUST_ACCOUNTrX   ÚformatÚdomain_dns_namer£   r�   Úlowerr1   r  ri   r¢   r¤   r¥   )r&   ÚcomputernameÚ
computerour†   Úprepare_oldjoinÚip_address_listÚservice_principal_name_listr(  r¼   Úcomputercontainer_dnÚcomputer_dnr™   Úaccountcontrolr  s                 r   Únewcomputerz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ˆJ�}Ñ%á&Ø1LˆJÐ-Ñ.äœT×>Ñ>Ü!×3Ñ3ñ4ó 5ˆáÜ ¤×!BÑ!BÓCˆNØ+9ˆ
Ð'Ñ(áØ(/¯©Ø�D×(Ñ(Ó*ó),ˆJ�}Ñ%ð 	×ÑÔ ð	&Ø�H‰H�ZÔ áØŸ8™8›:�Ø×)Ñ)¨$°Ó<ñ 6Ø×$Ñ$Ð&>Ü&)×&7Ñ&7¸Ó&Dñ'Eà%-¨uô6÷6ð ×#Ñ#Õ%÷6ð 6ûð	Ø×#Ñ#Ô%Øús$   Ä5F Å*FÅ8F ÆFÆF ÆF0c                 óÂ  — dt        j                  |«      ›dd›d| j                  «       ›d�}| j                  «        	 | j	                  | j                  «       t         j
                  |g ¬«      }t        |«      dk(  rt        d|z  «      ‚t        |«      d	k(  sJ ‚| j                  |d   j                  «       | j                  «        y
#  | j                  «        ‚ xY w)zIDeletes a user

        :param username: Name of the target user
        rœ   r�   z$CN=Person,CN=Schema,CN=Configurationr€   rŸ   rb   r   rx   rg   Nr¡   )r&   r  r¹   Útargets       r   Ú
deleteuserzSamDB.deleteuserN  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                 óÔ  — | j                  «        	 | j                  | j                  «       t        j                  |g ¬«      }t        |«      dk(  rt        d|xs |z  «      ‚t        |«      dkD  rt        dt        |«      |fz  «      ‚|d   j                  }t        |t        «      s|j                  d«      }n|}d|z   dz   j                  d«      }d	|›d
t        j                  |«      j                  d«      ›d�}| j                  |«       |r | j                  dt        |«      z   dz   «       | j!                  |«       | j#                  «        y#  | j%                  «        ‚ xY w)zõSets the password for a user

        :param search_filter: LDAP filter to find the user (eg
            samccountname=name)
        :param password: Password for the user
        :param force_change_at_next_login: Force password change
        rb   r   rx   rg   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£   rh   rP   ri   rj   rk   rl   r%   Ú
isinstancerN   ÚdecodeÚencodeÚbase64Ú	b64encodern   r{   r_   r¤   r¥   )	r&   r[   r  Úforce_change_at_next_loginr  rq   rz   ÚpwÚsetpws	            r   r  zSamDB.setpasswordc  sV  € ð 	×ÑÔ ð 	&Ø—+‘+ 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   ’D1E ÅE'c                 ó,  — | j                  «        	 | j                  | j                  «       t        j                  |ddg¬«      }t        |«      dk(  rt        d|z  «      ‚t        |«      dk(  sJ ‚|d   j                  }t        |d   d   d   «      }|r|dz  }d}n8|dz  }t        j                  |t        t        j                  «       «      z   «      }d	|||fz  }| j                  |«       | j                  «        y
#  | j                  «        ‚ xY w)a  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
        ra   ÚaccountExpiresrb   r   rx   rg   i   iÿÿþÿzy
dn: %s
changetype: modify
replace: userAccountControl
userAccountControl: %u
replace: accountExpires
accountExpires: %u
N)r£   rh   rP   ri   rj   rk   rl   r%   rm   rW   Úunix2nttimeÚtimern   r¤   r¥   )	r&   r[   Úexpiry_secondsÚno_expiry_reqrq   rz   ra   r[  Úsetexps	            r   Ú	setexpiryz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   — t        j                  | |«       y)z`Change 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_sidzSamDB.set_domain_sid¹  s   € ô
 	×"Ñ" 4¨Õ-r   c                 ó,   — t        j                  | «      S )z&Read the domain SID used by this LDB. )r   Ú_samdb_get_domain_sidr)   s    r   Úget_domain_sidzSamDB.get_domain_sidÀ  s   € ä×)Ñ)¨$Ó/Ð/r   zSID for the domain)Údocc                 ó0   — t        j                  | |«       y)zoSet 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_idzSamDB.set_invocation_idÇ  s   € ô
 	×)Ñ)¨$°Õ>r   c                 ó,   — t        j                  | «      S )zGet the invocation_id id)r   Ú_samdb_ntds_invocation_idr)   s    r   Úget_invocation_idzSamDB.get_invocation_idÎ  s   € ä×-Ñ-¨dÓ3Ð3r   zInvocation ID GUIDc                 ó.   — t        j                  | |«      S r#   )r   Ú_dsdb_get_oid_from_attid©r&   Úattids     r   Úget_oid_from_attidzSamDB.get_oid_from_attidÕ  s   € Ü×,Ñ,¨T°5Ó9Ð9r   c                 ó0   — t        j                  | ||«      S )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_lDAPDisplayNamez$SamDB.get_attid_from_lDAPDisplayNameØ  s    € ô ×8Ñ8¸Ø9JÈLóZð 	Zr   c                 ó.   — t        j                  | |«      S )z6return the syntax OID for a LDAP attribute as a string)r   Ú)_dsdb_get_syntax_oid_from_lDAPDisplayName©r&   rx  s     r   Ú#get_syntax_oid_from_lDAPDisplayNamez)SamDB.get_syntax_oid_from_lDAPDisplayNameÞ  s   € ä×=Ñ=¸dÐDUÓVÐVr   c                 ó.   — t        j                  | |«      S )z8return the systemFlags for a LDAP attribute as a integer)r   Ú*_dsdb_get_systemFlags_from_lDAPDisplayNamer}  s     r   Ú$get_systemFlags_from_lDAPDisplayNamez*SamDB.get_systemFlags_from_lDAPDisplayNameâ  s   € ä×>Ñ>¸tÐEVÓWÐWr   c                 ó.   — t        j                  | |«      S )z3return the linkID for a LDAP attribute as a integer)r   Ú%_dsdb_get_linkId_from_lDAPDisplayNamer}  s     r   Úget_linkId_from_lDAPDisplayNamez%SamDB.get_linkId_from_lDAPDisplayNameæ  s   € ä×9Ñ9¸$Ð@QÓRÐRr   c                 ó.   — t        j                  | |«      S )z;return the lDAPDisplayName from an integer DRS attribute ID)r   Ú"_dsdb_get_lDAPDisplayName_by_attidrs  s     r   Úget_lDAPDisplayName_by_attidz"SamDB.get_lDAPDisplayName_by_attidê  s   € ä×6Ñ6°t¸UÓCÐCr   c                 ó.   — t        j                  | |«      S )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_lDAPDisplayNamez'SamDB.get_backlink_from_lDAPDisplayNameî  s   € ô ×;Ñ;¸DÐBSÓTÐTr   c                 ó0   — t        j                  | |«       y)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_dnzSamDB.set_ntds_settings_dnó  s   € ô 	×(Ñ(¨Ð/?Õ@r   c                 ó,   — t        j                  | «      S )zGet the NTDS objectGUID)r   Ú_samdb_ntds_objectGUIDr)   s    r   Úget_ntds_GUIDzSamDB.get_ntds_GUIDý  s   € ä×*Ñ*¨4Ó0Ð0r   c                 óp   — | j                  dt        j                  dg¬«      }t        |d   d   d   «      S )z/Get the current time as generalized time stringr«   ÚcurrentTime©rc   rd   rf   r   ©rh   ri   Ú
SCOPE_BASErN   ©r&   rq   s     r   Úget_timestrzSamDB.get_timestr  s>   € à�k‰k˜rÜ #§¡Ø!. ð ó 1ˆô �3�q‘6˜-Ñ(¨Ñ+Ó,Ð,r   c                 óH   — t        j                  | j                  «       «      S )z!Get the current time as UNIX time)ri   Ústring_to_timer˜  r)   s    r   Úget_timezSamDB.get_time  s   € ä×!Ñ! $×"2Ñ"2Ó"4Ó5Ð5r   c                 óH   — t        j                  | j                  «       «      S )zGet the current time as NT time)rW   r\  r›  r)   s    r   Ú
get_nttimezSamDB.get_nttime  s   € ä× Ñ  §¡£Ó1Ð1r   c                 ó,   — t        j                  | «      S )zGet the server site name)r   Ú_samdb_server_site_namer)   s    r   Úserver_site_namezSamDB.server_site_name  s   € ä×+Ñ+¨DÓ1Ð1r   c                 óp   — | j                  dt        j                  dg¬«      }t        |d   d   d   «      S )z return the DNS name of this hostr«   r8  r”  r   r•  r—  s     r   Úhost_dns_namezSamDB.host_dns_name  s5   € à�k‰k˜r¬¯©À¸ˆkÓOˆÜ�3�q‘6˜-Ñ(¨Ñ+Ó,Ð,r   c                 óf   — | j                  «       }|j                  «       j                  d«      d   S )z&return the DNS name of the domain rootrò   r   )rO   r  Úsplit)r&   rP   s     r   r?  zSamDB.domain_dns_name  s/   € à×+Ñ+Ó-ˆ	Ø×&Ñ&Ó(×.Ñ.¨sÓ3°AÑ6Ð6r   c                 ó  — | j                  «       }| j                  «       }d|›d|›d�}| j                  «       }| j                  |t        j
                  |¬«      }	 |d   d   d   j                  «       }|S # t        $ r Y yw xY w)z*return the NetBIOS name of the domain rootz/(&(objectClass=crossRef)(nETBIOSName=*)(ncName=z
)(dnsroot=rŸ   )rd   re   r   ÚnETBIOSNameN)rO   r?  Úget_partitions_dnrh   ri   ÚSCOPE_ONELEVELrS  Ú
IndexError)r&   rP   Údns_namer¹   Úpartitions_dnrq   Únetbios_domains          r   Údomain_netbios_namezSamDB.domain_netbios_name  s•   € à×+Ñ+Ó-ˆ	Ø×'Ñ'Ó)‰ÚV_ÒaiÐjˆØ×.Ñ.Ó0ˆØ�k‰k˜-Ü #× 2Ñ 2Ø%+ð ó -ˆð	Ø  ™V MÑ2°1Ñ5×<Ñ<Ó>ˆNð Ðøô ò 	Ùð	ús   ÁA8 Á8	BÂBc                 óf   — | j                  «       }|j                  «       j                  d«      d   S )z&return the DNS name of the forest rootrò   r   )Úget_root_basednr  r¤  )r&   Ú	forest_dns     r   Úforest_dns_namezSamDB.forest_dns_name-  s/   € à×(Ñ(Ó*ˆ	Ø×&Ñ&Ó(×.Ñ.¨sÓ3°AÑ6Ð6r   c                 ó.   — t        j                  | |«      S r#   )r   Ú_dsdb_load_partition_usn)r&   Úbase_dns     r   Úload_partition_usnzSamDB.load_partition_usn2  s   € Ü×,Ñ,¨T°7Ó;Ð;r   c                 ó>   — | j                  |j                  |¬«       y )N)Úwrite_indices_and_attributes)Úset_schema_from_ldbri   )r&   Úschemar·  s      r   Ú
set_schemazSamDB.set_schema5  s   € Ø× Ñ  §¡ÐJfÐ Õgr   c                 ó2   — t        j                  | ||«       y r#   )r   Ú_dsdb_set_schema_from_ldb)r&   Úldb_connr·  s      r   r¸  zSamDB.set_schema_from_ldb8  s   € Ü×&Ñ& t¨XÐ7SÕTr   c                 ó*   — d}| j                  |«       y )Nz@
dn:
changetype: modify
add: schemaUpdateNow
schemaUpdateNow: 1
)rn   )r&   Úldifs     r   Úset_schema_update_nowzSamDB.set_schema_update_now;  s   € ðˆð 	×Ñ˜Õr   c                 ó0   — t        j                  |||«      S )zBconvert a list of attribute values to a DRSUAPI DsReplicaAttribute)r   Ú_dsdb_DsReplicaAttribute©r&   ri   rx  Úldif_elementss       r   Údsdb_DsReplicaAttributezSamDB.dsdb_DsReplicaAttributeD  s   € ä×,Ñ,¨SÐ2CÀ]ÓSÐSr   c                 ó0   — t        j                  |||«      S )z$normalise a list of attribute values)r   Ú_dsdb_normalise_attributesrÃ  s       r   Údsdb_normalise_attributeszSamDB.dsdb_normalise_attributesH  s   € ä×.Ñ.¨sÐ4EÀ}ÓUÐUr   c                 óæ   — t        | j                  j                  «       «      dk(  r| j                  «        | j	                  |«      | j                  v r| j                  | j	                  |«         S y)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)rk   Úhash_oid_nameÚkeysÚ_populate_oid_attidru  rs  s     r   Úget_attribute_from_attidzSamDB.get_attribute_from_attidL  sd   € ô ˆt×!Ñ!×&Ñ&Ó(Ó)¨QÒ.Ø×$Ñ$Ô&Ø×"Ñ" 5Ó)¨T×-?Ñ-?Ñ?Ø×%Ñ% d×&=Ñ&=¸eÓ&DÑEÐEàr   c                 óî   — i | _         | j                  ddgddg¬«      }t        |«      dkD  rI|D ]C  }t        |j	                  d«      «      }|| j                   t        |j	                  d«      «      <   ŒE yy)z�Populate 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)re   Úcontrolsrf   r   N)rÊ  rh   rk   rN   rÅ   )r&   rq   rÏ   Ú
strDisplays       r   rÌ  zSamDB._populate_oid_attidY  sˆ   € ð  ˆÔØ�k‰kÐ%BØ$8Ð#9Ø!.Ø!2ð!4ð ó 5ˆô ˆs‹8�aŠ<Øò K�Ü  §¡Ð'8Ó!9Ó:�
Ø@J�×"Ñ"¤3 q§u¡u¨]Ó';Ó#<Ò=ñKð r   c                 ó*  — | j                  d|z  t        j                  dgdg¬«      }t        |«      dk(  ryt	        t
        j                  |d   d   d   «      }|j                  }t        | j                  j                  «       «      dk(  r| j                  «        |j                  D ]h  }| j                  |j                  «      }|| j                  v sŒ-|j                  «       | j                  |   j                  «       k(  sŒ\|j                  c S  y)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=%srÏ  ÚreplPropertyMetaData©re   rd   rÒ  rf   r   N)rh   ri   rj   rk   r   r   ÚreplPropertyMetaDataBlobÚctrrÊ  rË  rÌ  Úarrayru  rt  r@  Úversion)r&   r%   Úattrq   ÚreplrÙ  ÚoÚatt_oids           r   Ú"get_attribute_replmetadata_versionz(SamDB.get_attribute_replmetadata_versioni  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                 óþ  — | j                  d|z  t        j                  dgdg¬«      }t        |«      dk(  ry t	        t
        j                  |d   d   d   «      }|j                  }t        j                  t        t        j                  «       «      «      }d}	t        | j                  j                  «       «      dk(  r| j                  «        |j                  D ]À  }
| j!                  |
j"                  «      }|| j                  v sŒ-|j%                  «       | j                  |   j%                  «       k(  sŒ\d}	| j'                  t        j(                  «      }||
_        ||
_        t/        j0                  | j3                  «       «      |
_        ||
_        ||
_        ŒÂ |	sí|rët        |j                  «      dkD  rÓt        j:                  «       }d|_        | j!                  |j"                  «      }| j'                  t        j(                  «      }||_        ||_        t/        j0                  | j3                  «       «      |_        ||_        ||_        d}	|j                  }|j=                  |«       |j>                  d	z   |_        ||_        |	rotA        |«      }t        jB                  «       }|d   jD                  |_"        t        jF                  |t        jH                  d«      |d<   | jK                  |d
g«       y y )NrÕ  rÏ  rÖ  r×  r   FTiZ 	 rg   z#local_oid:1.3.6.1.4.1.7165.4.3.14:0)&rh   ri   rj   rk   r   r   rØ  rÙ  rW   r\  rm   r]  rÊ  rË  rÌ  rÚ  ru  rt  r@  Úsequence_numberÚSEQ_NEXTrÛ  Úoriginating_change_timer   ÚGUIDrp  Úoriginating_invocation_idÚoriginating_usnÚ	local_usnÚreplPropertyMetaData1Úappendr;  r   r  r%   rÖ   rØ   r  )r&   r%   rÜ  rÛ   Úaddifnotexistrq   rÝ  rÙ  ÚnowÚfoundrÞ  rß  ÚseqÚo2ÚtabÚreplBlobrÒ   s                    r   Ú"set_attribute_replmetadata_versionz(SamDB.set_attribute_replmetadata_version‡  s  € à�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ØˆBŒJØ),ˆBÔ&Ü+/¯9©9°T×5KÑ5KÓ5MÓ+NˆBÔ(Ø!$ˆBÔØˆBŒLØˆEØ—)‘)ˆCØ�J‰J�rŒNØŸ	™	 A™ˆCŒIØˆCŒIáÜ “~ˆHÜ—+‘+“-ˆCØ˜‘V—Y‘YˆCŒFä×"Ñ" 8Ü#&×#7Ñ#7Ø#9ó;ð Ð&Ñ'ð �K‰K˜ÐCÐDÕEð r   c                 ó.   — t        j                  | «       y r#   )r   Ú'_dsdb_write_prefixes_from_schema_to_ldbr)   s    r   Úwrite_prefixes_from_schemaz SamDB.write_prefixes_from_schema¾  s   € Ü×4Ñ4°TÕ:r   c                 ó,   — t        j                  | «      S r#   )r   Ú_dsdb_get_partitions_dnr)   s    r   r§  zSamDB.get_partitions_dnÁ  s   € Ü×+Ñ+¨DÓ1Ð1r   c                 ó.   — t        j                  | |«      S r#   )r   Ú_dsdb_get_nc_root)r&   r%   s     r   Úget_nc_rootzSamDB.get_nc_rootÄ  s   € Ü×%Ñ% d¨BÓ/Ð/r   c                 ó   — | j                   j                  t        |«      «      }d }|�|j                  |«      }|€Rt        j                  | ||«      }|€|S |€0i | j                   t        |«      <   | j                   t        |«         }|||<   |S r#   )Úhash_well_knownrÅ   rN   r   Ú_dsdb_get_wellknown_dn)r&   Únc_rootÚwkguidÚh_ncr%   s        r   r�   zSamDB.get_wellknown_dnÇ  s“   € Ø×#Ñ#×'Ñ'¬¨G«Ó5ˆØˆØÐØ—‘˜&Ó!ˆBØˆ:Ü×,Ñ,¨T°7¸FÓCˆBØˆzØ�	Øˆ|Ø57�×$Ñ$¤S¨£\Ñ2Ø×+Ñ+¬C°«LÑ9�ØˆD�‰LØˆ	r   c                 óD  — t        |t        «      st        |«      j                  d«      }t	        j
                  «       }t	        j                  | | j                  «       «      |_        t	        j                  |t        j                  d«      |d<   | j                  |«       y )NÚutf8Ú	minPwdAge©rR  ÚbytesrN   rT  ri   r  rÁ   rP   r%   rÖ   rØ   r  ©r&   rÛ   Úms      r   Úset_minPwdAgezSamDB.set_minPwdAgeÖ  óm   € Ü˜%¤Ô'Ü˜“J×%Ñ% fÓ-ˆEÜ�K‰K‹MˆÜ�v‰v�d˜DŸN™NÓ,Ó-ˆŒÜ×+Ñ+¨E´3×3GÑ3GÈÓUˆˆ+‰Ø�‰�A�r   c                 óº   — | j                  | j                  «       t        j                  dg¬«      }t	        |«      dk(  ry d|d   vry t        |d   d   d   «      S )Nr  ©rd   rf   r   ©rh   rP   ri   r–  rk   rm   r—  s     r   Úget_minPwdAgezSamDB.get_minPwdAgeÞ  óY   € Ø�k‰k˜$Ÿ.™.Ó*´#·.±.ÈÈˆkÓVˆÜˆs‹8�qŠ=ØØ  A¡Ñ&Øä�s˜1‘v˜kÑ*¨1Ñ-Ó.Ð.r   c                 óD  — t        |t        «      st        |«      j                  d«      }t	        j
                  «       }t	        j                  | | j                  «       «      |_        t	        j                  |t        j                  d«      |d<   | j                  |«       y )Nr  Ú	maxPwdAger  r  s      r   Úset_maxPwdAgezSamDB.set_maxPwdAgeç  r	  r   c                 óº   — | j                  | j                  «       t        j                  dg¬«      }t	        |«      dk(  ry d|d   vry t        |d   d   d   «      S )Nr  r  r   r  r—  s     r   Úget_maxPwdAgezSamDB.get_maxPwdAgeï  r  r   c                 óD  — t        |t        «      st        |«      j                  d«      }t	        j
                  «       }t	        j                  | | j                  «       «      |_        t	        j                  |t        j                  d«      |d<   | j                  |«       y )Nr  ÚminPwdLengthr  r  s      r   Úset_minPwdLengthzSamDB.set_minPwdLengthø  sn   € Ü˜%¤Ô'Ü˜“J×%Ñ% fÓ-ˆEÜ�K‰K‹MˆÜ�v‰v�d˜DŸN™NÓ,Ó-ˆŒÜ×.Ñ.¨u´c×6JÑ6JÈNÓ[ˆˆ.ÑØ�‰�A�r   c                 óº   — | j                  | j                  «       t        j                  dg¬«      }t	        |«      dk(  ry d|d   vry t        |d   d   d   «      S )Nr  r  r   r  r—  s     r   Úget_minPwdLengthzSamDB.get_minPwdLength   sZ   € Ø�k‰k˜$Ÿ.™.Ó*´#·.±.ÈÐHXˆkÓYˆÜˆs‹8�qŠ=ØØ 3 q¡6Ñ)Øä�s˜1‘v˜nÑ-¨aÑ0Ó1Ð1r   c                 óD  — t        |t        «      st        |«      j                  d«      }t	        j
                  «       }t	        j                  | | j                  «       «      |_        t	        j                  |t        j                  d«      |d<   | j                  |«       y )Nr  ÚpwdPropertiesr  r  s      r   Úset_pwdPropertieszSamDB.set_pwdProperties	  sn   € Ü˜%¤Ô'Ü˜“J×%Ñ% fÓ-ˆEÜ�K‰K‹MˆÜ�v‰v�d˜DŸN™NÓ,Ó-ˆŒÜ ×/Ñ/°´s×7KÑ7KÈ_Ó]ˆˆ/ÑØ�‰�A�r   c                 óº   — | j                  | j                  «       t        j                  dg¬«      }t	        |«      dk(  ry d|d   vry t        |d   d   d   «      S )Nr  r  r   r  r—  s     r   Úget_pwdPropertieszSamDB.get_pwdProperties  sZ   € Ø�k‰k˜$Ÿ.™.Ó*´#·.±.ÈÐHYˆkÓZˆÜˆs‹8�qŠ=ØØ C¨¡FÑ*Øä�s˜1‘v˜oÑ.¨qÑ1Ó2Ð2r   c                 óh  — t        j                  «       }t        j                  | d| j                  «       j	                  «       z  «      |_        |�)t        j                  |t         j                  d«      |d<   n(t        j                  g t         j                  d«      |d<   | j                  |«       y )Nú1CN=Directory Service,CN=Windows NT,CN=Services,%sÚdSHeuristics)
ri   r  rÁ   Úget_config_basednrÂ   r%   rÖ   rØ   r×   r  )r&   Údsheuristicsr  s      r   Úset_dsheuristicsz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                 óÚ   — | j                  d| j                  «       j                  «       z  t        j                  dg¬«      }t        |«      dk(  rd }|S d|d   v r|d   d   d   }|S d }|S )Nr  r   r  r   )rh   r!  rÂ   ri   r–  rk   )r&   rq   r"  s      r   Úget_dsheuristicsz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                 ól   — |ddœ}|r||d<   |r||d<   |rt        |«      |d<   | j                  |«       y)a  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
        ÚorganizationalUnitr.  r†   rö   rŒ   N)r   r�   )r&   Úou_dnr†   rö   r•   r  s         r   Ú	create_ouzSamDB.create_ou6  sI   € ð Ø0ñ2ˆñ Ø*ˆAˆmÑÙØˆAˆf‰IáÜ(0°«ˆAÐ$Ñ%Ø�‰��r   c                 óœ   •— | j                  «        	 t        t        | �  |«      }| j	                  «        |S #  | j                  «        ‚ xY w)zƒReturns the value of the sequence number according to the requested type
        :param seq_type: type of sequence number
         )r£   r;   r   râ  r¤   r¥   )r&   Úseq_typerî  rA   s      €r   râ  zSamDB.sequence_numberJ  sP   ø€ ð 	×ÑÔ ð	&Üœ˜tÑ4°XÓ>ˆCð
 ×#Ñ#Ô%Øˆ
øð	Ø×#Ñ#Ô%Øús	   “8 ¸Ac                 óp   — | j                  dt        j                  dg¬«      }t        |d   d   d   «      S )z get the NTDS DN from the rootDSEr«   ÚdsServiceNamer”  r   r•  r—  s     r   Úget_dsServiceNamezSamDB.get_dsServiceNameX  s6   € à�k‰k˜r¬¯©ÀÐ?PˆkÓQˆÜ�3�q‘6˜/Ñ*¨1Ñ-Ó.Ð.r   c                 óp   — | j                  dt        j                  dg¬«      }t        |d   d   d   «      S )z"get the server DN from the rootDSEr«   Ú
serverNamer”  r   r•  r—  s     r   Úget_serverNamezSamDB.get_serverName]  s5   € à�k‰k˜r¬¯©À¸~ˆkÓNˆÜ�3�q‘6˜,Ñ'¨Ñ*Ó+Ð+r   c                 ób   — |€t        j                  | |«      S t        j                  | ||¬«      S )zDDo a DNS lookup in the database, returns the NDR database structures)Údns_partition)r   Úlookup)r&   rª  r3  s      r   Ú
dns_lookupzSamDB.dns_lookupb  s3   € àÐ Ü—?‘? 4¨Ó2Ð2ä—?‘? 4¨Ø1>ô@ð @r   c                 ó.   — t        j                  | |«      S )z;Return the NDR database structures from a dnsRecord element)r   Úextract)r&   rÜ   s     r   Údns_extractzSamDB.dns_extractj  s   € ä×Ñ  bÓ)Ð)r   c                 ó0   — t        j                  | ||«      S )zfDo a DNS modification on the database, sets the NDR database
        structures on a DNS name
        )r   r  )r&   rª  Únew_recordss      r   Údns_replacezSamDB.dns_replacen  s   € ô ×Ñ  h°Ó<Ð<r   c                 ó0   — t        j                  | ||«      S )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_dnzSamDB.dns_replace_by_dnt  s   € ô ×%Ñ% d¨B°Ó<Ð<r   c                 óŽ   — t        «       st        d«      ‚|€t        j                  | ||«      S t        j                  | |||«      S )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_tombstonesz SamDB.garbage_collect_tombstones}  sa   € ô
 ÔÜð &ó 'ð 'ð Ð%Ü×8Ñ8¸¸rØ9EóGð Gô ×8Ñ8¸¸rØ9EØ9KóMð Mr   c                 ó,   — t        j                  | «      S )zcreate a RID set for this DSA)r   Ú_dsdb_create_own_rid_setr)   s    r   Úcreate_own_rid_setzSamDB.create_own_rid_setŽ  s   € ä×,Ñ,¨TÓ2Ð2r   c                 ó,   — t        j                  | «      S )z.return a new RID from the RID Pool on this DSA)r   Ú_dsdb_allocate_ridr)   s    r   Úallocate_ridzSamDB.allocate_rid’  s   € ä×&Ñ& tÓ,Ð,r   c                 ó,   — | j                  «       \  }}|S )aE  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&   ÚridÚ_s      r   Únext_free_ridzSamDB.next_free_rid–  s   € ð ×%Ñ%Ó'‰ˆˆQØˆ
r   c                 ó*  — t        j                  | | j                  «       «      }| j                  |t         j                  dg¬«      }	 |d   d   }t        j                  | |d   j                  d«      «      }| j                  |t         j                  dg¬«      }	 |d   d   }t        j                  | |d   j                  d«      «      }| j                  |t         j                  g d	¢¬«      }d
}d}	 t        |d   d   d   «      }	|	|k(  r't        j                  t         j                  d|z  «      ‚	 t        |d   d   d   «      }
	 t        |d   d   d   «      }|
|k(  s||k(  r|	}
|
|z  }n|dz  }|
|z  }|
dz	  }||kD  r7|	|
k(  r$t        j                  t         j                  d«      ‚|	}
|
|z  }|
dz	  }|}||k  s||kD  r*t        j                  t         j                  d|||fz  «      ‚||fS # t
        $ r) t        j                  t         j                  d|z  «      d‚w xY w# t
        $ r) t        j                  t         j                  d|z  «      d‚w xY w# t
        $ r |}	Y �Œcw xY w# t
        $ r |}
Y �Œ4w xY w# t
        $ r |}Y �Œ1w xY w)a‘  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 dnNrN  ÚrIDSetReferenceszVNo RID Set DN - Cannot find attribute rIDSetReferences of %s to calculate reference dn)ÚrIDAllocationPoolÚrIDPreviousAllocationPoolÚ
rIDNextRIDl   ÿÿ l   ÿÿÿÿ rR  zBad RID Set %srS  rT  rg   é    zRID pools out of RIDsz"Bad RID chosen %d from range %d-%d)ri   rÁ   r1  rh   r–  ÚKeyErrorÚLdbErrorÚERR_NO_SUCH_ATTRIBUTErS  rm   ÚERR_OPERATIONS_ERROR)r&   Úserver_name_dnrq   Ú
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   rK  zSamDB.free_rid_bounds¡  s  € ô Ÿ™  d×&9Ñ&9Ó&;Ó<ˆØ�k‰k˜~Ü #§¡Ø!2Ð 3ð ó 5ˆð	HØ˜Q™Ð 1Ñ2ˆJô Ÿ™˜t Z°¡]×%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Ò"ð ˜YÒ&Ü—l‘l¤3×#;Ñ#;Ø#:ó<ð <ð #ˆIØ$ zÑ1ˆLØ$¨™?ˆLØ#ˆHà�lÒ" h°Ò&=Ü—,‘,œs×7Ñ7ØCØ (¨,¸ÐEñ FóGð Gð ˜Ð%Ð%øôY ò 	HÜ—,‘,Ü×)Ñ)ð,à.<ñ=ó>ð DHð	Hð	Hûô ò 	GÜ—,‘,Ü×)Ñ)ð,à.;ñ<ó=ð CGð	Gð	Gûô( ò 	$Ø#‹Jð	$ûô ò 	#Ø"‹Ið	#ûô ò 	"Ø!‹Hð	"úsN   Á	G5 ÂH* Ã6I Ä7I1 ÅJ Ç52H'È*2IÉI.É-I.É1J É?J ÊJÊJc                 ó  — t        j                  | | j                  «       «      }t        |t         j                  «      rt	        |«      }t        j                  | |«      }|j                  |«      s|j                  |«       |S )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
        )ri   rÁ   rP   rR  rN   Úis_child_ofÚadd_base)r&   r%   rP   Úfull_dns       r   rÄ   zSamDB.normalize_dn_in_domainÿ  sc   € ô —F‘F˜4 §¡Ó!1Ó2ˆ	ä�bœ#Ÿ&™&Ô!Ü�R“ˆBä—&‘&˜˜rÓ"ˆØ×"Ñ" 9Ô-Ø×Ñ˜YÔ'Øˆr   )Nr   N)NTF)NNNNNNNN)TNN)NNNNr«   )FFNNNNNNNNNNNNNNNNNTNNNNNNNF)NNNNNNNNNNNNNNN)NNFNN)FN)F)T)NNNr#   )_r   r   r   Ú__doc__rÊ  rü  r1   ri   ÚFLG_DONT_CREATE_DBr'   rG   r@   rL   rP   rS   r\   r_   rY   r{   r}   rš   r¨   r½   rÔ   rÝ   rï   r,  r5  rI  rL  r  ra  re  rh  ÚpropertyÚ
domain_sidrm  rp  rl  ru  rz  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§  rú  r�   r  r  r  r  r  r  r  r  r#  r%  r)  râ  r.  r1  r5  r8  r;  r>  rC  rF  rI  rN  rK  rÄ   Ú__classcell__)rA   s   @r   r   r   4   s¶  ø„ Ùà€MØ€O÷ñ ð(   D°dÈØ!¨×)?Ñ)?Ø¨TØ"¨Dõ2õ,4ò#ò"ò.ò-òDòEð GKØ05ó+òZò*ð2 ;?ØDHØ+/ó2òh&ò*3ðl 8<Ø.2Ø04óZ&òxð. 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ò?ò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òòò/òò/òò2òò3òòóô(ò/ò
,ó
@ò*ò=ò=ð 7;óMò"3ò-ò	ò\&ö|r   r   c                   óT   — e Zd ZdZdd„Zd„ Zd„ Zd„ Zd„ Zd„ Z	d	„ Z
d
„ Zd„ Zd„ Zd„ Zy)Údsdb_Dnza class for binary DNNc                 ór  — |€T|j                  d«      rt        j                  }n2|j                  d«      rt        j                  }nt        j                  }|t        j                  t        j                  fv r…|j                  d«      }t        |«      dk  rt        d|z  «      ‚dt        |d   «      z   t        |d   «      z   }|d| | _	        | j                  d	t        |d   «      z   d
 | _
        ||d | _        n|| _        d| _	        d| _
        t        j                  || j                  «      | _        y)zcreate a dsdb_DnNzB:zS:ú:é   zInvalid DN %srg   r   é   r±   r«   )Ú
startswithr   ÚDSDB_SYNTAX_BINARY_DNÚDSDB_SYNTAX_STRING_DNÚDSDB_SYNTAX_OR_NAMEr¤  rk   ÚRuntimeErrorrm   ÚprefixÚbinaryÚdnstringri   rÁ   r%   )r&   r$   r|  Ú
syntax_oidÚcolonsÚ
prefix_lens         r   r'   z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Ø$ Z [Ð1ˆD�Mà$ˆDŒMØˆDŒKØˆDŒKÜ—&‘&˜ §¡Ó.ˆ�r   c                 óf   — | j                   t        | j                  j                  d¬«      «      z   S )Nrg   )Úmode)rz  rN   r%   rÃ   r)   s    r   Ú__str__zdsdb_Dn.__str__-  s(   € Ø�{‰{œS §¡×!5Ñ!5¸1Ð!5Ó!=Ó>Ñ>Ð>r   c                 óà   — | }|}|j                   j                  d«      }|j                   j                  d«      }t        ||«      }|dk7  r|S t        |j                  |j                  «      }|S )z6 compare dsdb_Dn values similar to parsed_dn_compare()rå  r   )r%   Úget_extended_componentr   r{  )r&   ÚotherÚdn1Údn2Úguid1Úguid2Úvs          r   Ú__cmp__zdsdb_Dn.__cmp__0  se   € àˆØˆØ—‘×-Ñ-¨fÓ5ˆØ—‘×-Ñ-¨fÓ5ˆä��uÓˆØ�Š6ØˆHÜ�—
‘
˜CŸJ™JÓ'ˆØˆr   c                 ó*   — | j                  |«      dk(  S ©Nr   ©r‹  ©r&   r…  s     r   Ú__eq__zdsdb_Dn.__eq__>  ó   € Ø�|‰|˜EÓ" aÑ'Ð'r   c                 ó*   — | j                  |«      dk7  S r�  rŽ  r�  s     r   Ú__ne__zdsdb_Dn.__ne__A  r‘  r   c                 ó*   — | j                  |«      dk  S r�  rŽ  r�  s     r   Ú__lt__zdsdb_Dn.__lt__D  ó   € Ø�|‰|˜EÓ" QÑ&Ð&r   c                 ó*   — | j                  |«      dk  S r�  rŽ  r�  s     r   Ú__le__zdsdb_Dn.__le__G  r‘  r   c                 ó*   — | j                  |«      dkD  S r�  rŽ  r�  s     r   Ú__gt__zdsdb_Dn.__gt__J  r–  r   c                 ó*   — | j                  |«      dk\  S r�  rŽ  r�  s     r   Ú__ge__zdsdb_Dn.__ge__M  r‘  r   c                 óN   — | j                   dk(  ryt        | j                  d«      S )z6return binary part of a dsdb_Dn as an integer, or Noner«   Né   )rz  rm   r{  r)   s    r   Úget_binary_integerzdsdb_Dn.get_binary_integerP  s"   € à�;‰;˜"ÒØÜ�4—;‘; Ó#Ð#r   c                 ó@   — t        j                  | j                  «      S )zreturn binary as a byte string)ÚbinasciiÚ	unhexlifyr{  r)   s    r   r
   zdsdb_Dn.get_bytesV  s   € ä×!Ñ! $§+¡+Ó.Ð.r   r#   )r   r   r   rj  r'   r‚  r‹  r�  r“  r•  r˜  rš  rœ  rŸ  r
   r   r   r   rp  rp    s<   „ Ùó/ò2?òò(ò(ò'ò(ò'ò(ò$ó/r   rp  )rj  rW   ri   r]  rU  rC   r9  r   r   Ú	samba.ndrr   r   Úsamba.dcerpcr   r   Úsamba.commonr	   r
   r   r   r   r¡  Ú__docformat__r   rl   r   r   ÚLdbr   Úobjectrp  r   r   r   ú<module>r©     sw   ðñ. /ã Û 
Û Û Û 	Û 	ß  ß *ß 'Ý (ß 'Ý !Ý  Û à"€òô	�ô 	ô	˜ô 	ô[ˆE�I‰Iô [ôz.G/ˆfõ G/r   