o
    ßý°j¨B ã                
   @   sh  d Z ddlmZmZ ddlmZ ddlmZ ddlmZ ddl	Z	ddl
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1 d	d
l2m3Z3m4Z4m5Z5 ddl6m7Z7 d	dl8m9Z9 d	dl:m;Z; ddl<m=Z=m>Z> ddl?m@Z@mAZA ddlBmCZCmDZD ddlEmFZFmGZG ddlHmIZImJZJ ddlKmLZLmMZM ddlNmOZOmPZP ddlQmRZRmSZS ddlTmUZUmVZV ddlWmXZXmYZY ddlZm[Z[ ddl\m]Z] ddl^m_Z_ ddl`maZa ddlbmcZc ddldmeZe ddlfmgZg ddlhmiZi dd ljmkZk dd!llmmZm dd"lnmoZo dd#lpmqZq dd$lrmsZs dd%ltmuZu dd&lvmwZw d	d'lxmyZy d	d(lzm{Z{ d	d)l|m}Z}m~Z~mZm€Z€m�Z�m‚Z‚mƒZƒm„Z„m…Z…m†Z†m‡Z‡mˆZˆm‰Z‰mŠZŠ dd*l‹mŒZŒm�Z�mŽZŽm�Z�m�Z� dd+l‘m’Z’m“Z“m”Z”m•Z•m–Z–m—Z—m˜Z˜ dd,l™mšZš dd-l›mœZœ e+e,e-e.gZ�ee"e#eeeee(e)eg
Zžd.d/„ ZŸd0d1„ Z G d2d3„ d3e¡ƒZ¢dS )4Ú
é    )ÚdeepcopyÚcopy)Úlinesep)ÚRLock)ÚreduceNé   )'Ú	ANONYMOUSÚSIMPLEÚSASLÚ
MODIFY_ADDÚMODIFY_DELETEÚMODIFY_REPLACEÚget_config_parameterÚDEREF_ALWAYSÚSUBTREEÚASYNCÚSYNCÚNO_ATTRIBUTESÚALL_ATTRIBUTESÚALL_OPERATIONAL_ATTRIBUTESÚMODIFY_INCREMENTÚLDIFÚASYNC_STREAMÚRESTARTABLEÚROUND_ROBINÚREUSABLEÚAUTO_BIND_DEFAULTÚAUTO_BIND_NONEÚAUTO_BIND_TLS_BEFORE_BINDÚ	SAFE_SYNCÚSAFE_RESTARTABLEÚAUTO_BIND_TLS_AFTER_BINDÚAUTO_BIND_NO_TLSÚSTRING_TYPESÚSEQUENCE_TYPESÚ	MOCK_SYNCÚ
MOCK_ASYNCÚNTLMÚEXTERNALÚ
DIGEST_MD5ÚGSSAPIÚPLAINÚDSAÚSCHEMAÚALLé   )ÚRESULT_SUCCESSÚRESULT_COMPARE_TRUEÚRESULT_COMPARE_FALSE)ÚExtendedOperationsRoot)Ú
ServerPool)ÚServer)Úabandon_operationÚabandon_request_to_dict)Úadd_operationÚadd_request_to_dict)Úbind_operationÚbind_request_to_dict)Úcompare_operationÚcompare_request_to_dict)Údelete_operationÚdelete_request_to_dict)Úextended_operationÚextended_request_to_dict)Úmodify_operationÚmodify_request_to_dict)Úmodify_dn_operationÚmodify_dn_request_to_dict)Úsearch_operationÚsearch_request_to_dict)Úoperation_to_ldifÚadd_ldif_header)Úsasl_digest_md5)Úsasl_external)Ú
sasl_plain)ÚSyncStrategy)ÚSafeSyncStrategy)ÚSafeRestartableStrategy)ÚMockAsyncStrategy)ÚAsyncStrategy)ÚReusableStrategy)ÚRestartableStrategy)ÚLdifProducerStrategy)ÚMockSyncStrategy)ÚAsyncStreamStrategy)Úunbind_operation)Úpaged_search_control)ÚConnectionUsage)ÚTls)ÚLDAPUnknownStrategyErrorÚLDAPBindErrorÚ$LDAPUnknownAuthenticationMethodErrorÚ"LDAPSASLMechanismNotSupportedErrorÚLDAPObjectClassErrorÚLDAPConnectionIsReadOnlyErrorÚLDAPChangeErrorÚLDAPExceptionErrorÚLDAPObjectErrorÚLDAPSocketReceiveErrorÚLDAPAttributeErrorÚLDAPInvalidValueErrorÚLDAPInvalidPortErrorÚLDAPStartTLSError)Úescape_bytesÚprepare_for_streamÚcheck_json_dictÚformat_jsonÚ
to_unicode)ÚlogÚlog_enabledÚERRORÚBASICÚPROTOCOLÚEXTENDEDÚ#get_library_log_hide_sensitive_data)Úsafe_dn)Úcheck_port_and_port_listc                 C   s|   | rt | ƒdkrt| d ƒd t| d ƒ S | r.t | ƒdkr.dt| d ƒ d t| d ƒ S zt| ƒW S  ty=   Y dS w )	Nr   r   ú:r0   é   ú[z]:ú?)ÚlenÚstrÚ	Exception)Úendpoint© r€   úˆ/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/ldap3/core/connection.pyÚ_format_socket_endpoint_   s    
ÿr‚   c                 C   sl   | r4z|   ¡ }W n ty   d}Y nw z|  ¡ }W n ty%   d}Y nw dt|ƒ d t|ƒ d S dS )N)NNNNz<local: z - remote: ú>z<no socket>)Úgetsocknamer~   Úgetpeernamer‚   )ÚsockÚlocalÚremoter€   r€   r�   Ú_format_socket_endpointsk   s   ÿÿr‰   c                   @   sä  e Zd ZdZddeddedddddddddddddddddddddddfdd„ZdGdd	„Zd
d„ Zdd„ Z	dd„ Z
dd„ Zedd„ ƒZejdd„ ƒZedd„ ƒZdd„ Zdd„ Z		dHdd„Z							dIdd„Z	dJdd „Zeedd!d!dddddddfd"d#„Z	dJd$d%„Z			dKd&d'„Z	dJd(d)„Z	dJd*d+„Z			dLd,d-„Z	dJd.d/„Z			dKd0d1„ZdMd2d3„Zd4d5„ Z d6d7„ Z!d8d9„ Z"					dNd:d;„Z#			<				dOd=d>„Z$		<	dPd?d@„Z%dJdAdB„Z&edCdD„ ƒZ'dEdF„ Z(dS )QÚ
Connectiona�  Main ldap connection class.

    Controls, if used, must be a list of tuples. Each tuple must have 3
    elements, the control OID, a boolean meaning if the control is
    critical, a value.

    If the boolean is set to True the server must honor the control or
    refuse the operation

    Mixing controls must be defined in controls specification (as per
    RFC 4511)

    :param server: the Server object to connect to
    :type server: Server, str
    :param user: the user name for simple authentication
    :type user: str
    :param password: the password for simple authentication
    :type password: str
    :param auto_bind: specify if the bind will be performed automatically when defining the Connection object
    :type auto_bind: int, can be one of AUTO_BIND_DEFAULT, AUTO_BIND_NONE, AUTO_BIND_NO_TLS, AUTO_BIND_TLS_BEFORE_BIND, AUTO_BIND_TLS_AFTER_BIND as specified in ldap3
    :param version: LDAP version, default to 3
    :type version: int
    :param authentication: type of authentication
    :type authentication: int, can be one of ANONYMOUS, SIMPLE or SASL, as specified in ldap3
    :param client_strategy: communication strategy used in the Connection
    :type client_strategy: can be one of SYNC, ASYNC, LDIF, RESTARTABLE, REUSABLE as specified in ldap3
    :param auto_referrals: specify if the connection object must automatically follow referrals
    :type auto_referrals: bool
    :param sasl_mechanism: mechanism for SASL authentication, can be one of 'EXTERNAL', 'DIGEST-MD5', 'GSSAPI', 'PLAIN'
    :type sasl_mechanism: str
    :param sasl_credentials: credentials for SASL mechanism
    :type sasl_credentials: tuple
    :param check_names: if True the library will check names of attributes and object classes against the schema. Also values found in entries will be formatted as indicated by the schema
    :type check_names: bool
    :param collect_usage: collect usage metrics in the usage attribute
    :type collect_usage: bool
    :param read_only: disable operations that modify data in the LDAP server
    :type read_only: bool
    :param lazy: open and bind the connection only when an actual operation is performed
    :type lazy: bool
    :param raise_exceptions: raise exceptions when operations are not successful, if False operations return False if not successful but not raise exceptions
    :type raise_exceptions: bool
    :param pool_name: pool name for pooled strategies
    :type pool_name: str
    :param pool_size: pool size for pooled strategies
    :type pool_size: int
    :param pool_lifetime: pool lifetime for pooled strategies
    :type pool_lifetime: int
    :param cred_store: credential store for gssapi
    :type cred_store: dict
    :param use_referral_cache: keep referral connections open and reuse them
    :type use_referral_cache: bool
    :param auto_escape: automatic escaping of filter values
    :type auto_escape: bool
    :param auto_encode: automatic encoding of attribute values
    :type auto_encode: bool
    :param source_address: the ip address or hostname to use as the source when opening the connection to the server
    :type source_address: str
    :param source_port: the source port to use when opening the connection to the server. Cannot be specified with source_port_list
    :type source_port: int
    :param source_port_list: a list of source ports to choose from when opening the connection to the server. Cannot be specified with source_port
    :type source_port_list: list
    Né   TFc           !      C   sÀ  t dƒ}tƒ | _| j��I |tvr%d| _ttƒr ttd| j| ƒ t| jƒ‚|| _	|| _
|| _|s7| j
r7t| _n&|s=t| _n |ttttfv rI|| _nd| _ttƒrXttd| j| ƒ t| jƒ‚|| _|rddnd| _d | _d | _d | _d| _d| _d| _d | _|du r„t| _n|du rŒt| _n|| _|
| _|| _|rštƒ nd | _ d | _!d| _"d| _#|| _$g | _%d| _&d| _'d| _(d | _)d| _*|| _+|rÂ|n|| _,|| _-|| _.|| _/|| _0d| _1|| _2|| _3|	rÞdnd| _4t5| ƒ| _6g | _7|| _8|| _9|| _:|| _;|| _<|| _=d | _>d | _?d| _@tA||ƒ} | �rttƒ�rtt| ƒ tB| ƒ‚|d u�r!|nd| _Cdg| _D|d u�r2|g| _Dn|d u�r>|d d … | _DtE|tFƒ�rHtG|ƒ}tE|tHƒ�rVtI|tJddd	�}tE|tIƒ�rm|| _K| jK L| ¡ | jK M| ¡| _Nnd | _K|| _N| j	tOk�rtP| ƒ| _Qn„| j	tRk�r‹tS| ƒ| _Qnx| j	tTk�r—tU| ƒ| _Qnl| j	tVk�r£tW| ƒ| _Qn`| j	tXk�r¯tY| ƒ| _QnT| j	tZk�r»t[| ƒ| _QnH| j	t\k�rÊt]| ƒ| _Qd| _+n9| j	t^k�rÖt_| ƒ| _Qn-| j	t`k�râta| ƒ| _Qn!| j	tbk�rîtc| ƒ| _Qnd
| _ttƒ�rþttd| j| ƒ t| jƒ‚| jQjd| _d| jQje| _e| jQjf| _f| jQjg| _g| jQjh| _h| jQji�s%|  j¡  ttkƒ�rEtlƒ �r7ttkd|  m¡ ƒ nttkd| ƒ W d   ƒ d S W d   ƒ d S W d   ƒ d S 1 �sYw   Y  d S )NÚDEFAULT_THREADED_POOL_NAMEz"unknown client connection strategyú%s for <%s>úunknown authentication methodTFr   Ú )ÚactiveÚexhaustzunknown strategyzinstantiated Connection: <%s>zinstantiated Connection: <%r>)nr   r   Úconnection_lockÚCLIENT_STRATEGIESÚ
last_errorrp   rq   ro   r\   Ústrategy_typeÚuserÚpasswordr
   Úauthenticationr	   r   r(   r^   ÚversionÚauto_referralsÚrequestÚresponseÚresultÚboundÚ	listeningÚclosedr   Ú	auto_bindr#   Úsasl_mechanismÚsasl_credentialsrZ   Ú_usageÚsocketÚtls_startedÚsasl_in_progressÚ	read_onlyÚ_context_stateÚ_deferred_openÚ_deferred_bindÚ_deferred_start_tlsÚ_bind_controlsÚ_executing_deferredÚlazyÚ	pool_nameÚ	pool_sizeÚ
cred_storeÚpool_lifetimeÚpool_keepaliveÚstarting_tlsÚcheck_namesÚraise_exceptionsÚ
auto_ranger4   ÚextendÚ_entriesÚfast_decoderÚreceive_timeoutÚempty_attributesÚuse_referral_cacheÚauto_escapeÚauto_encodeÚ_digest_md5_kicÚ_digest_md5_kisÚ_digest_md5_sec_numrw   rh   Úsource_addressÚsource_port_listÚ
isinstancer$   r6   r%   r5   r   Úserver_poolÚ
initializeÚget_current_serverÚserverr   rN   Ústrategyr    rO   r!   rP   r   rR   r   rU   r   rT   r   rS   r&   rV   r'   rQ   r   rW   ÚsendÚopenÚget_responseÚpost_send_single_responseÚpost_send_searchÚno_real_dsaÚ_do_auto_bindrr   ru   Ú!repr_with_sensitive_data_stripped)!ÚselfrÊ   r–   r—   r¡   r™   r˜   Úclient_strategyrš   r¸   r¢   r£   r¶   Úcollect_usager¨   r¯   r·   r°   r±   r³   r²   r»   r¼   Úreturn_empty_attributesr¾   r¿   rÀ   r´   rÄ   Úsource_portrÅ   Úconf_default_pool_nameÚport_errr€   r€   r�   Ú__init__º   s   




















 �è  �ì  �$êzConnection.__init__c                 C   sF   | j jr!| j}d | _| j}d | _|t| jƒ|rt|ƒnd t|ƒfS |S ©N)rË   Úthread_saferœ   r›   r   r�   r   )rÔ   Ústatusrœ   Útemp_responseÚtemp_requestr€   r€   r�   Ú_prepare_return_valueu  s   "z Connection._prepare_return_valuec                 C   sd  | j r¬| j ttfvr®ttƒrttd| ƒ | jr| jdd� | j tkr)| j	dd� na| j t
krZ| jdd�r;| j	dd� nOd| jrDd| j nd }ttƒrRttd|| ƒ |  ¡  t|ƒ‚| j tkrŠ| j	dd� | jdd�sŠd	| jrtd| j nd }ttƒr‚ttd|| ƒ |  ¡  t|ƒ‚| js°d
| jr–d| j nd }ttƒr¤ttd|| ƒ |  ¡  t|ƒ‚d S d S d S )Nz"performing automatic bind for <%s>F©Úread_server_infoTz/automatic start_tls befored bind not successfulú - r�   r�   z-automatic start_tls after bind not successfulzautomatic bind not successful)r¡   r   r   rp   rr   ro   r    rÍ   r#   Úbindr   Ú	start_tlsr”   rq   Úunbindri   r"   rž   r]   )rÔ   Úerrorr€   r€   r�   rÒ   ~  s>   


ãzConnection._do_auto_bindc                 C   s°   | j rt| j ƒnddt| jƒ | jrdnd| jsdn| jrdnd| jr%dn| jr*d	nd
t| j	ƒ| j
s4dn| jr9dnd| jr?dndt| dƒrJ| jjjnd| jrPdndg
}d |¡S )NÚNonezuser: r¯   znot lazyÚunboundzdeferred bindrž   r    zdeferred openrÍ   ztls not startedzdeferred start_tlsztls startedrŸ   znot listeningrË   zNo strategyzinternal decoderzpyasn1 decoderrä   )rÊ   r}   r–   r¯   rž   r«   r    rª   r‰   r¥   r¦   r¬   rŸ   ÚhasattrrË   Ú	__class__Ú__name__r»   Újoin)rÔ   Úsr€   r€   r�   Ú__str__ž  s   ö
zConnection.__str__c                 C   sn  t dƒ}| jrd | ¡}nd | ¡}|| jd u rdnd | ¡7 }|| jd u r(dnd | ¡7 }|| jd u r6dnd | ¡7 }|| jd u rDdnd | ¡7 }|| jd u rRdnd	 | ¡7 }|| jd u r`dnd
 | ¡7 }|| j	d u rndnd | ¡7 }|| j
d u r|dnd | ¡7 }|| jd u rŠdnd | ¡7 }|| jd u r˜dnd | ¡7 }|| jd u r¦dnd| jr¬dnd 7 }|| jd u r¸dnd | ¡7 }|| jd u rÆdnd | ¡7 }|| jd u rÔdnd | ¡7 }|| jd u så| j|krçdnd | ¡7 }|| jd u rõdnd | ¡7 }|| jd u �rdnd | ¡7 }|| jd u �rdnd | ¡7 }|| jd u �r"dndt| jƒ 7 }|| jd u �r3dn	d| j�r:dnd 7 }|| jd u �rGdn	d| j�rNdnd 7 }|| jd u �r[dnd | ¡7 }|| jd u �rjdn	d| j�rqdnd 7 }|| jd u �r~dn	d| j�r…dnd 7 }|| jd u �r’dn	d| j�r™dnd 7 }|| jd u �r¦dn	d | j�r­dnd 7 }|d!7 }|S )"NrŒ   ú#Connection(server={0.server_pool!r}úConnection(server={0.server!r}r�   ú, user={0.user!r}z, password={0.password!r}ú, auto_bind={0.auto_bind!r}ú, version={0.version!r}ú%, authentication={0.authentication!r}ú%, client_strategy={0.strategy_type!r}ú%, auto_referrals={0.auto_referrals!r}ú%, sasl_mechanism={0.sasl_mechanism!r}ú), sasl_credentials={0.sasl_credentials!r}ú, check_names={0.check_names!r}z, collect_usage=ÚTrueÚFalseú, read_only={0.read_only!r}ú, lazy={0.lazy!r}ú), raise_exceptions={0.raise_exceptions!r}ú, pool_name={0.pool_name!r}ú, pool_size={0.pool_size!r}ú#, pool_lifetime={0.pool_lifetime!r}ú%, pool_keepalive={0.pool_keepalive!r}ú, cred_store=z, fast_decoder=ú, auto_range=ú', receive_timeout={0.receive_timeout!r}z, return_empty_attributes=ú, auto_encode=ú, auto_escape=ú, use_referral_cache=ú))r   rÇ   Úformatr–   r—   r¡   r™   r˜   r•   rš   r¢   r£   r¶   Úusager¨   r¯   r·   r°   r±   r³   r´   r²   Úreprr»   r¸   r¼   r½   rÀ   r¿   r¾   ©rÔ   rÙ   Úrr€   r€   r�   Ú__repr__­  s@   
$&"((((((zConnection.__repr__c              	   C   sÀ  t dƒ}| jrd | ¡}nd | ¡}|| jd u rdnd | ¡7 }|| jd u r(dn	d dt| jƒ ¡7 }|| jd u r;dnd | ¡7 }|| jd u rIdnd	 | ¡7 }|| jd u rWdnd
 | ¡7 }|| j	d u rednd | ¡7 }|| j
d u rsdnd | ¡7 }|| jd u r�dnd | ¡7 }| jtkr®|| jd u r”dnd | jd | jd dt| jd ƒ | jd ¡7 }n|| jd u r¶dnd | ¡7 }|| jd u rÄdnd | ¡7 }|| jd u rÒdn| jr×dnd7 }|| jd u râdnd | ¡7 }|| jd u rðdnd | ¡7 }|| jd u rþdnd | ¡7 }|| jd u �s| j|k�rdnd | ¡7 }|| jd u �r"dnd | ¡7 }|| jd u �r1dnd | ¡7 }|| jd u �r@dnd | ¡7 }|| jd u �rOdndt| jƒ 7 }|| jd u �r`dn| j�rfd nd7 }|| jd u �rrdn	d!| j�ryd"nd 7 }|| jd u �r†dnd# | ¡7 }|| jd u �r•dn| j�r›d$nd7 }|| jd u �r§dn	d%| j�r®d"nd 7 }|| jd u �r»dn	d&| j�rÂd"nd 7 }|| jd u �rÏdn	d'| j�rÖd"nd 7 }|d(7 }|S ))NrŒ   rñ   rò   r�   ró   z, password='{0}'z*<stripped %d characters of sensitive data>rô   rõ   rö   r÷   rø   rù   z/, sasl_credentials=({0!r}, {1!r}, '{2}', {3!r})r   r0   Ú*r   r‹   rú   rû   z, collect_usage=Truerý   rþ   rÿ   r   r  r  r  r  r  z, fast_decoder=Truer  rü   r  z, return_empty_attributes=Truer  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Ó   Ñ  sD   
&
D *"$($(((z,Connection.repr_with_sensitive_data_strippedc                 C   s   | j jr	| j  ¡ S dS )z»Used by the LDIFProducer strategy to accumulate the ldif-change operations with a single LDIF header
        :return: reference to the response stream if defined in the strategy.
        N)rË   Ú
can_streamÚ
get_stream©rÔ   r€   r€   r�   Ústreamø  s   zConnection.streamc                 C   sP   | j � | jjr| j |¡ W d   ƒ d S W d   ƒ d S 1 s!w   Y  d S rÜ   )r’   rË   r  Ú
set_stream)rÔ   Úvaluer€   r€   r�   r  ÿ  s   þ"ÿc                 C   sX   | j sdS | jjr)| j  ¡  | jjjD ]}|  j |jj7  _ q|  j | jjj7  _ | j S )zKUsage statistics for the connection.
        :return: Usage object
        N)	r¤   rË   ÚpooledÚresetÚpoolÚworkersÚ
connectionr  Úterminated_usage)rÔ   Úworkerr€   r€   r�   r    s   
zConnection.usagec                 C   s€   | j �3 | j | j| jf¡ | jtkr-| jtkrt| _| jr"|  	¡  | js-|  
¡ s-tdƒ‚| W  d   ƒ S 1 s9w   Y  d S )Nzunable to bind)r’   r©   Úappendrž   r    r¡   r   r   r#   rÍ   rå   r]   r  r€   r€   r�   Ú	__enter__  s   

$õzConnection.__enter__c              	   C   s¬   | j �I | j ¡ \}}|s| js| jr#z|  ¡  W n	 ty"   Y nw |s,| jr,|  ¡  |d urDt	t
ƒr;tt
d|| ƒ 	 W d   ƒ dS W d   ƒ d S 1 sOw   Y  d S )Nr�   F)r’   r©   Úpoprž   r  rç   rc   r    rÍ   rp   rq   ro   )rÔ   Úexc_typeÚexc_valÚexc_tbÚcontext_boundÚcontext_closedr€   r€   r�   Ú__exit__!  s"   ÿ
ò"õzConnection.__exit__c                 C   s\  t tƒr
ttd| ƒ d| _| j�� | jr7| js7| jjr"| j 	|¡ d| _
|| _d| _t tƒr5ttd| ƒ �nÎd| _
d| _| jrF| jdd� | jtkr…t tƒrUttd| ƒ | jjs~t| j| j| jd| jd	�}t tƒrsttd
t|ƒ| ƒ |  |  d||¡¡}nà| j 	|¡}nÙ| jtkrÅt tƒr”ttd| ƒ | jjs¾t| j| j| j| j| jd	�}t tƒr³ttdt|ƒ| ƒ |  |  d||¡¡}n | j 	|¡}n™| jtkrþ| jtv rêt tƒrÙttd| ƒ | jjsã|  |¡}n{| j 	|¡}ntd| _t tƒrùttd| j| ƒ t | jƒ‚| jt!k�rI| j�r4| j�r4t"| j #d¡ƒdk�r4t tƒ�r"ttd| ƒ | jj�s-|  $|¡}n1| j 	|¡}n*d| _t tƒ�rDttd| j| ƒ t%| jƒ‚d| _t tƒ�rYttd| j| ƒ t%| jƒ‚| jj&�s„| jj�s„| jtt!fv�r„|  '|¡\}}t tƒ�rƒttd|| ƒ n:| jj&�r™| j(}t tƒ�r˜ttd|| ƒ n%| jj�s¦| jtt!fv �r©|}nd| _t tƒ�r¹ttd| j| ƒ t%| jƒ‚|du �rÇd| _n3|du �rÐd| _n*|du �rÙd| _n!|d t)k�râdnd| _| j�sú|�rú|d �rú| j�sú|d | _|�r| j�r|  *¡  g | _+t tƒ�rttd| jƒ |  ,| j| j(¡W  d  ƒ S 1 �s'w   Y  dS )a%  Bind to ldap Server with the authentication method and the user defined in the connection

        :param read_server_info: reads info from server
        :param controls: LDAP controls to send along with the bind operation
        :type controls: list of tuple
        :return: bool

        zstart BIND operation via <%s>NTzdeferring bind for <%s>Frâ   z"performing anonymous BIND for <%s>r�   )rÀ   z)anonymous BIND request <%s> sent via <%s>ÚbindRequestzperforming simple BIND for <%s>z&simple BIND request <%s> sent via <%s>zperforming SASL BIND for <%s>z&requested SASL mechanism not supportedr�   ú\r   zperforming NTLM BIND for <%s>z)NTLM needs domain\username and a passwordrŽ   z-async BIND response id <%s> received via <%s>z$BIND response <%s> received via <%s>r�   Údescriptionz done BIND operation, result <%s>)-rp   rr   ro   r”   r’   r¯   r®   rË   r  Úvalidate_bindr«   r­   rž   r    rÍ   r˜   r	   rs   r;   r™   r–   rÀ   r<   rÏ   rÌ   r
   r—   r   r¢   ÚSASL_AVAILABLE_MECHANISMSÚdo_sasl_bindrq   r_   r(   r|   ÚsplitÚdo_ntlm_bindr^   ÚsyncrÎ   r�   r1   Úrefresh_server_inforº   rá   )rÔ   rã   Úcontrolsr›   rœ   Ú_r�   r€   r€   r�   rå   2  sº   
€




&





$
€

€




 

&›zConnection.bindc              	   C   s<  t tƒr
ttd| ƒ d | _| j�„ |r|| _|d ur|| _|s$|r$t| _|tt	t
tfv r0|| _n|d urHd| _t tƒrCttd| j| ƒ t| jƒ‚|rM|| _|rR|| _| jjs€z|  ||¡W W  d   ƒ S  ty   d| _t tƒrzttd| j| ƒ t| jƒ‚w | jj ¡  |  d| j¡W  d   ƒ S 1 s—w   Y  d S )Nz!start (RE)BIND operation via <%s>rŽ   r�   z[Unable to rebind as a different user, furthermore the server abruptly closed the connectionT)rp   rr   ro   r”   r’   r–   r—   r
   r˜   r	   r   r(   rq   r^   r¢   r£   rË   r  rå   re   r]   r  Úrebind_poolrá   r�   )rÔ   r–   r—   r˜   r¢   r£   rã   r3  r€   r€   r�   Úrebind§  sD   

æ
ü$ÞzConnection.rebindc                 C   sà   t tƒr
ttd| ƒ | jr| j ¡  d| _| j�N | jr4| j	s4| j
s%| jr4| j ¡  d| _d| _
d| _n| jsPtƒ }t tƒrDttd| ƒ |  d||¡ | j ¡  t tƒrZttddƒ |  d¡W  d  ƒ S 1 siw   Y  dS )z¦Unbind the connected user. Unbind implies closing session as per RFC4511 (4.3)

        :param controls: LDAP controls to send along with the bind operation

        zstart UNBIND operation via <%s>NFzUNBIND request sent via <%s>ÚunbindRequestz"done UNBIND operation, result <%s>T)rp   rr   ro   r¾   rË   Úunbind_referral_cacher”   r’   r¯   r®   r«   rª   Úcloser¬   r    rX   rs   rÌ   rá   )rÔ   r3  r›   r€   r€   r�   rç   Ø  s*   


$ðzConnection.unbindr   c                 C   s"  dd„ t dƒD ƒ}ttƒrttd| ƒ | jr'|r't|ƒ}ttƒr'ttd|| ƒ | j��[ |  ¡  |s6t	g}n|t
kr=t
g}t|tƒrE|g}|	rRt|tƒrR| t¡ n|	r^t|tƒr^|tf7 }t|tƒr…ttƒrqttd|t|ƒ| ƒ |
du rxg }
nt|
ƒ}
|
 t|||ƒ¡ | jrÉ| jjrÉ| jrÉ|D ]7}d|v rŸ| d¡d	 }n|}| jjrÈ| ¡ |vrÈ|| jjjvrÈd
| | _ttƒrÃttd| j| ƒ t| jƒ‚q‘t|||||||||du rÙ| jn|| j| jrã| jjnd| jj | jd�}ttƒrùttdt!|ƒ| ƒ |  "|  #d||
¡¡}g | _$t|tƒ�r|}ttƒ�rttd|| ƒ nR| j%d dk�r,t&|ƒd	k�r,dnd}|�sD| j%d t'fv�rD| j�sD| j%d | _ttƒ�rm|D ]!}|d dk�r]ttd|| ƒ �qK|d dk�rkttd|| ƒ �qKttƒ�rxttd|ƒ | j(|dd�W  d  ƒ S 1 �sŠw   Y  dS )a)  
        Perform an ldap search:

        - If attributes is empty noRFC2696 with the specified size
        - If paged is 0 and cookie is present the search is abandoned on
          server attribute is returned
        - If attributes is ALL_ATTRIBUTES all attributes are returned
        - If paged_size is an int greater than 0 a simple paged search
          is tried as described in
        - Cookie is an opaque string received in the last paged search
          and must be used on the next paged search response
        - If lazy == True open and bind will be deferred until another
          LDAP operation is performed
        - If mssing_attributes == True then an attribute not returned by the server is set to None
        - If auto_escape is set it overrides the Connection auto_escape
        c                 S   ó   g | ]}|  ¡ ‘qS r€   ©Úlower©Ú.0Úvr€   r€   r�   Ú
<listcomp>  ó    z%Connection.search.<locals>.<listcomp>ÚATTRIBUTES_EXCLUDED_FROM_CHECKzstart SEARCH operation via <%s>z;search base sanitized to <%s> for SEARCH operation via <%s>z>performing paged search for %d items with cookie <%s> for <%s>Nú;r   úinvalid attribute type r�   ©Ú	validatorr¶   z!SEARCH request <%s> sent via <%s>ÚsearchRequestz/async SEARCH response id <%s> received via <%s>ÚtypeÚsearchResDoneTFr�   r+  ÚsearchResEntryz,SEARCH response entry <%s> received via <%s>ÚsearchResRefz0SEARCH response reference <%s> received via <%s>z"done SEARCH operation, result <%s>©rœ   ))r   rp   rr   ro   r¶   rv   rt   r’   Ú_fire_deferredr   r   rÆ   r$   Úlistr   r   ÚtupleÚintrs   rj   rY   rÊ   Úschemar/  r<  Úattribute_typesr”   rq   rf   rG   r¿   rÀ   Úcustom_validatorrH   rÐ   rÌ   rº   r�   r|   r1   rá   )rÔ   Úsearch_baseÚsearch_filterÚsearch_scopeÚdereference_aliasesÚ
attributesÚ
size_limitÚ
time_limitÚ
types_onlyÚget_operational_attributesr3  Ú
paged_sizeÚpaged_criticalityÚpaged_cookier¿   Ú#conf_attributes_excluded_from_checkÚattribute_nameÚattribute_name_to_checkr›   rœ   Úreturn_valueÚentryr€   r€   r�   Úsearchø  s”   




"

€ô
€& 
€
&µzConnection.searchc           
   
   C   sJ  dd„ t dƒD ƒ}ttƒrttd| ƒ d| _| jr(t|ƒ}ttƒr(ttd|| ƒ | jrh| jj	rh| jrhd|v r>| 
d¡d }n|}| jj	jrh| ¡ |vrh|| jj	jvrhd	| | _ttƒrcttd
| j| ƒ t| jƒ‚t|tƒr�d| _ttƒr|ttd
| j| ƒ t| jƒ‚| j�– |  ¡  t|||| j| jr–| jj	nd| jrž| jjnd| jd�}ttƒr±ttdt|ƒ| ƒ |  |  d||¡¡}g | _t|tƒrÑ|}	ttƒrÐttd|	| ƒ n2| jd dkrá| jd tkrádnd}	|	s÷| jd ttfvr÷| js÷| jd | _ttƒ�rttd|| ƒ ttƒ�rttd|	ƒ |   |	¡W  d  ƒ S 1 �sw   Y  dS )z-
        Perform a compare operation
        c                 S   r:  r€   r;  r=  r€   r€   r�   r@  u  rA  z&Connection.compare.<locals>.<listcomp>rB  z start COMPARE operation via <%s>Nz3dn sanitized to <%s> for COMPARE operation via <%s>rC  r   rD  r�   zvalue cannot be a sequencerE  z"COMPARE request <%s> sent via <%s>ÚcompareRequestz0async COMPARE response id <%s> received via <%s>rH  ÚcompareResponser�   TFr+  z'COMPARE response <%s> received via <%s>z#done COMPARE operation, result <%s>)!r   rp   rr   ro   r”   r¶   rv   rt   rÊ   rQ  r/  rR  r<  rq   rf   rÆ   r%   rg   r’   rM  r=   rÀ   rS  rs   r>   rÏ   rÌ   rº   rP  r�   r2   r3   rá   )
rÔ   ÚdnÚ	attributer  r3  r`  rb  r›   rœ   rc  r€   r€   r�   Úcomparem  sV   $



6
€$

&êzConnection.comparec              	   C   sˆ  dd„ t dƒD ƒ}dd„ t dƒD ƒ}ttƒrttd| ƒ d| _t|ƒ}| jr5t|ƒ}ttƒr5ttd|| ƒ | j	��€ |  
¡  g }|du rGg }	nt|tƒrPt|ƒn|g}	d	}
|ry|D ]}| ¡ d
krw|}
t||
 tƒrpt||
 ƒn||
 g} nqYntƒ }|
s€d}
dd„ |D ƒ}tdd„ |	| g ƒ||
< ||
 s«d| _ttƒr¦ttd| j| ƒ t| jƒ‚| j�r| jj�r| j�r||
 D ]'}| ¡ |vrã|| jjjvrãdt|ƒ | _ttƒrÞttd| j| ƒ t| jƒ‚q¼|D ]6}d|v rô| d¡d }n|}| ¡ |v�r|| jjjv�rd| | _ttƒ�rttd| j| ƒ t| jƒ‚qæt||| j| j�r*| jjnd| j�r3| jjnd| jd�}ttƒ�rGttdt|ƒ| ƒ |  |   d||¡¡}g | _!t|t"t#f ƒ�rl|}ttƒ�rkttd|| ƒ n6ttƒ�rxttd|| ƒ | j$d dk�rŠ| j$d t%k�rŠdnd}|�s¢| j$d t%fv�r¢| j�s¢| j$d | _ttƒ�r­ttd |ƒ |  &|¡W  d  ƒ S 1 �s½w   Y  dS )!zë
        Add dn to the DIT, object_class is None, a class name or a list
        of class names.

        Attributes is a dictionary in the form 'attr': 'val' or 'attr':
        ['val1', 'val2', ...] for multivalued attributes
        c                 S   r:  r€   r;  r=  r€   r€   r�   r@  µ  rA  z"Connection.add.<locals>.<listcomp>rB  c                 S   r:  r€   r;  r=  r€   r€   r�   r@  ¶  rA  ÚCLASSES_EXCLUDED_FROM_CHECKzstart ADD operation via <%s>Nz/dn sanitized to <%s> for ADD operation via <%s>r�   ÚobjectclassÚobjectClassc                 S   s   g | ]}t |ƒ‘qS r€   )rn   )r>  Úobject_classr€   r€   r�   r@  Õ  rA  c                 S   s   || vr	| |g S | S rÜ   r€   )ÚxÚyr€   r€   r�   Ú<lambda>Ö  s    z Connection.add.<locals>.<lambda>z"objectClass attribute is mandatoryr�   zinvalid object class rC  r   rD  rE  zADD request <%s> sent via <%s>Ú
addRequestz,async ADD response id <%s> received via <%s>z#ADD response <%s> received via <%s>rH  ÚaddResponser�   TFr+  zdone ADD operation, result <%s>)'r   rp   rr   ro   r”   r   r¶   rv   rt   r’   rM  rÆ   r%   rN  r<  Údictr   rq   r`   rÊ   rQ  Úobject_classesr}   r/  rR  rf   r9   rÀ   rS  rs   r:   rÏ   rÌ   rº   r$   rP  r�   r1   rá   )rÔ   rh  rn  rX  r3  r`  Ú conf_classes_excluded_from_checkÚ_attributesÚattr_object_classÚparm_object_classÚobject_class_attr_nameÚattrÚobject_class_namera  rb  r›   rœ   rc  r€   r€   r�   Úadd©  s�   
$ý€

€


€8

€
( 
&ºzConnection.addc                 C   s„  t tƒr
ttd| ƒ d| _| jrt|ƒ}t tƒrttd|| ƒ | j�– |  ¡  | j	r>d| _t t
ƒr9tt
d| j| ƒ t| jƒ‚t|ƒ}t tƒrOttdt|ƒ| ƒ |  |  d||¡¡}g | _t|ttf ƒrr|}t tƒrqttd|| ƒ n0t tƒr}ttd	|| ƒ | jd
 dkr�| jd tkr�dnd}|s¢| jd tfvr¢| js¢| jd | _t tƒr¬ttd|ƒ |  |¡W  d  ƒ S 1 s»w   Y  dS )zE
        Delete the entry identified by the DN from the DIB.
        zstart DELETE operation via <%s>Nz2dn sanitized to <%s> for DELETE operation via <%s>úconnection is read-onlyr�   z!DELETE request <%s> sent via <%s>Ú
delRequestz/async DELETE response id <%s> received via <%s>z&DELETE response <%s> received via <%s>rH  ÚdelResponser�   TFr+  z"done DELETE operation, result <%s>)rp   rr   ro   r”   r¶   rv   rt   r’   rM  r¨   rq   ra   r?   rs   r@   rÏ   rÌ   rº   rÆ   r$   rP  r�   r1   rá   )rÔ   rh  r3  r›   rœ   rc  r€   r€   r�   Údelete  sB   
€$$äzConnection.deletec                 C   s¢  dd„ t dƒD ƒ}ttƒrttd| ƒ d| _| jr(t|ƒ}ttƒr(ttd|| ƒ | j��š |  	¡  | j
rHd| _ttƒrCttd| j| ƒ t| jƒ‚t|tƒsad	| _ttƒr\ttd| j| ƒ t| jƒ‚|swd
| _ttƒrrttd| j| ƒ t| jƒ‚tƒ }|D ]­}| jr¾| jjr¾| jr¾d|v r”| d¡d }n|}| jjjr¾| ¡ |vr¾|| jjjvr¾d| | _ttƒr¹ttd| j| ƒ t| jƒ‚|| }t|tƒrõ|d ttttddddfv rõt|ƒdkrïd| _ttƒrêttd| j| ƒ t| jƒ‚|g||< q||D ]-}	t|	ƒdk�s|	d ttttddddfv�r$d| _ttƒ�rttd| j| ƒ t| jƒ‚q÷|||< q|t||| j| j�r7| jjnd| j�r@| jjnd| jd�}
ttƒ�rTttdt |
ƒ| ƒ |  !|  "d|
|¡¡}g | _#t|t$t%f ƒ�ry|}ttƒ�rxttd|| ƒ n6ttƒ�r…ttd|| ƒ | j&d dk�r—| j&d t'k�r—dnd}|�s¯| j&d t'fv�r¯| j�s¯| j&d | _ttƒ�rºttd|ƒ |  (|¡W  d  ƒ S 1 �sÊw   Y  dS )a7  
        Modify attributes of entry

        - changes is a dictionary in the form {'attribute1': change), 'attribute2': [change, change, ...], ...}
        - change is (operation, [value1, value2, ...])
        - operation is 0 (MODIFY_ADD), 1 (MODIFY_DELETE), 2 (MODIFY_REPLACE), 3 (MODIFY_INCREMENT)
        c                 S   r:  r€   r;  r=  r€   r€   r�   r@  ?  rA  z%Connection.modify.<locals>.<listcomp>rB  zstart MODIFY operation via <%s>Nz2dn sanitized to <%s> for MODIFY operation via <%s>r~  r�   zchanges must be a dictionaryzno changes in modify requestrC  r   rD  r0   r   r‹   zmalformed changezinvalid change listrE  z!MODIFY request <%s> sent via <%s>ÚmodifyRequestz/async MODIFY response id <%s> received via <%s>z&MODIFY response <%s> received via <%s>rH  ÚmodifyResponser�   TFr+  z"done MODIFY operation, result <%s>))r   rp   rr   ro   r”   r¶   rv   rt   r’   rM  r¨   rq   ra   rÆ   rt  rb   rÊ   rQ  r/  rR  r<  rf   r%   r   r   r   r   r|   rC   rÀ   rS  rs   rD   rÏ   rÌ   rº   r$   rP  r�   r1   rá   )rÔ   rh  Úchangesr3  r`  Ú
changelistra  rb  ÚchangeÚchange_operationr›   rœ   rc  r€   r€   r�   Úmodify4  sŽ   




$

&
,

ü
8

€
( 
&ºzConnection.modifyc           	      C   s¨  t tƒr
ttd| ƒ d| _| jr.t|ƒ}t tƒrttd|| ƒ t|ƒ}t tƒr.ttd|| ƒ | j�™ |  ¡  | j	rMd| _t t
ƒrHtt
d| j| ƒ t| jƒ‚t||||ƒ}t tƒrattdt|ƒ| ƒ |  |  d||¡¡}g | _t|ttf ƒr„|}t tƒrƒttd	|| ƒ n0t tƒr�ttd
|| ƒ | jd dkrŸ| jd tkrŸdnd}|s´| jd tfvr´| js´| jd | _t tƒr¾ttd|ƒ |  |¡W  d  ƒ S 1 sÍw   Y  dS )z\
        Modify DN of the entry or performs a move of the entry in the
        DIT.
        z"start MODIFY DN operation via <%s>Nz5dn sanitized to <%s> for MODIFY DN operation via <%s>z>relative dn sanitized to <%s> for MODIFY DN operation via <%s>r~  r�   z$MODIFY DN request <%s> sent via <%s>ÚmodDNRequestz2async MODIFY DN response id <%s> received via <%s>z)MODIFY DN response <%s> received via <%s>rH  ÚmodDNResponser�   TFr+  z%done MODIFY DN operation, result <%s>)rp   rr   ro   r”   r¶   rv   rt   r’   rM  r¨   rq   ra   rE   rs   rF   rÏ   rÌ   rº   rÆ   r$   rP  r�   r1   rá   )	rÔ   rh  Úrelative_dnÚdelete_old_dnÚnew_superiorr3  r›   rœ   rc  r€   r€   r�   Ú	modify_dn‘  sH   

€$$ÞzConnection.modify_dnc                 C   s  t tƒr
ttd| ƒ d| _| j�n |  ¡  d}| jjs|dkrh| jjr3|| jjv r3| jj| d dvs7|dkr[t|ƒ}t t	ƒrHtt	dt
|ƒ| ƒ |  d||¡ d| _d| _g | _d	}nt tƒrhttd
t|ƒ| ƒ t tƒrrttd|ƒ |  |¡W  d  ƒ S 1 s�w   Y  dS )z?
        Abandon the operation indicated by message_id
        z start ABANDON operation via <%s>NFr   rH  )ÚabandonRequestr)  r7  z#ABANDON request: <%s> sent via <%s>r�  Tz\cannot abandon a Bind, an Unbind or an Abandon operation or message ID %s not found via <%s>z#done ABANDON operation, result <%s>)rp   rr   ro   r”   r’   rM  rË   Ú_outstandingr7   rs   r8   rÌ   r�   rœ   rº   rq   r}   rá   )rÔ   Ú
message_idr3  rc  r›   r€   r€   r�   ÚabandonÊ  s,   0$êzConnection.abandonc                 C   s6  t tƒr
ttd| ƒ d| _| j�� |  ¡  t|||d�}t tƒr)ttdt|ƒ| ƒ |  	|  
d||¡¡}g | _t|tƒrI|}t tƒrHttd|| ƒ n0t tƒrTttd|| ƒ | jd d	krd| jd
 tkrddnd}|sy| jd
 tfvry| jsy| jd | _t tƒrƒttd|ƒ | j|dd�W  d  ƒ S 1 s”w   Y  dS )z0
        Performs an extended operation
        z!start EXTENDED operation via <%s>N)Ú	no_encodez#EXTENDED request <%s> sent via <%s>ÚextendedReqz1async EXTENDED response id <%s> received via <%s>z(EXTENDED response <%s> received via <%s>rH  ÚextendedRespr�   TFr+  z$done EXTENDED operation, result <%s>rL  )rp   rr   ro   r”   r’   rM  rA   rs   rB   rÏ   rÌ   rº   rÆ   rP  r�   r1   rá   )rÔ   Úrequest_nameÚrequest_valuer3  r“  r›   rœ   rc  r€   r€   r�   Úextendedë  s0   
€$$ëzConnection.extendedc                 C   sò   t tƒr
ttd| ƒ | j�b d}d | _| jjstƒ | j_| jr5| j	s5d| _
d| _d}t tƒr4ttd| ƒ n$d| _
| jr?|  ¡  | jj | ¡rS| jjrS|rP|  ¡  d}n| jjsYd}t tƒrcttd|ƒ |  |¡W  d   ƒ S 1 srw   Y  d S )Nz"start START TLS operation via <%s>FTzdeferring START TLS for <%s>z%done START TLS operation, result <%s>)rp   rr   ro   r’   r�   rÊ   Útlsr[   r¯   r®   r¬   r¦   r    rÍ   ræ   rË   r1  r2  rá   )rÔ   rã   rc  r€   r€   r�   ræ     s6   
€$åzConnection.start_tlsc              	   C   sâ   t tƒr
ttd| ƒ d | _| j�W d }| jsTd| _z6| jtkr%t| |ƒ}n&| jt	kr0t
| |ƒ}n| jtkrAddlm} || |ƒ}n
| jdkrKt| |ƒ}W d| _nd| _w t tƒr^ttd|ƒ |W  d   ƒ S 1 sjw   Y  d S )Nz"start SASL BIND operation via <%s>Tr   )Úsasl_gssapir,   Fz%done SASL BIND operation, result <%s>)rp   rr   ro   r”   r’   r§   r¢   r)   rL   r*   rK   r+   Úprotocol.sasl.kerberosrš  rM   )rÔ   r3  r�   rš  r€   r€   r�   r.  .  s.   




€$ëzConnection.do_sasl_bindc              	   C   s0  t tƒr
ttd| ƒ d | _| j�ý | j�sd| _zÕddlm} | j 	dd¡\}}|||| j
d�}t| jd|ƒ}t tƒrAttd	| ƒ |  |  d
||¡¡}| jjsW|  |¡\}}	n|d }	d|	v rç|	d  d¡ 	d¡}
d|
v ræt| jd|ƒ}t tƒr~ttd| ƒ |  |  d
||¡¡}| jjs”|  |¡\}}	nt tƒr¡ttd|d | ƒ |d }	|	d tkræt| jd||	d ƒ}t tƒr¿ttd| ƒ |  |  d
||¡¡}| jjsÕ|  |¡\}}	nt tƒrâttd|d | ƒ |d }	nd }	W d| _nd| _w t tƒrüttd|	ƒ |	W  d   ƒ S W d   ƒ d S 1 �sw   Y  d S )Nz"start NTLM BIND operation via <%s>Tr   )Ú
NtlmClientr*  r0   )Ú	user_nameÚdomainr—   ÚSICILY_PACKAGE_DISCOVERYz3NTLM SICILY PACKAGE DISCOVERY request sent via <%s>r)  r   Úserver_credsÚasciirC  r(   ÚSICILY_NEGOTIATE_NTLMz+NTLM SICILY NEGOTIATE request sent via <%s>z5NTLM SICILY NEGOTIATE response <%s> received via <%s>r�   ÚSICILY_RESPONSE_NTLMz/NTLM SICILY RESPONSE NTLM request sent via <%s>z)NTLM BIND response <%s> received via <%s>Fz%done SASL NTLM operation, result <%s>)rp   rr   ro   r”   r’   r§   Ú
utils.ntlmrœ  r–   r/  r—   r;   r™   rs   rÏ   rÌ   rË   r1  rÎ   Údecoder1   )rÔ   r3  rœ  Údomain_namer�  Úntlm_clientr›   rœ   r4  r�   Úsicily_packagesr€   r€   r�   r0  J  sj   ÿ
ÿ€€Ê$ÿzConnection.do_ntlm_bindc                 C   s²   | j jsG| j�6 | js5ttƒrttd| ƒ | j}| j}| j	}| j
 | ¡ || _|| _|| _	W d   ƒ d S W d   ƒ d S 1 s@w   Y  d S ttƒrQttd| ƒ | j j ¡  d S )Nzrefreshing server info for <%s>z)refreshing server info from pool for <%s>)rË   r  r’   r    rp   rr   ro   rœ   r�   rº   rÊ   Úget_info_from_serverr  )rÔ   Úprevious_responseÚprevious_resultÚprevious_entriesr€   r€   r�   r2  ‡  s$   ö"ÿzConnection.refresh_server_infoc           	      C   sâ   | j �d |d u r| j}t|tƒr^td|||d�}t|ƒ}|pt}| |¡}|rJ| ¡ dkr?tdgƒd }| 	t
|| | ƒ¡ | 	t
|| | ƒ¡ ttƒrUttd|| ƒ |W  d   ƒ S 	 W d   ƒ d S 1 sjw   Y  d S )NÚsearchResponse)Ú
sort_orderr   ú-z"building LDIF output <%s> for <%s>)r’   rœ   rÆ   r%   rI   rJ   r   rî   ÚtellÚwriterk   rp   rr   ro   )	rÔ   Úsearch_resultÚ
all_base64Úline_separatorr®  r  Ú
ldif_linesÚldif_outputÚheaderr€   r€   r�   Úresponse_to_ldifœ  s&   

ð$îzConnection.response_to_ldifry   c              
      sV  | j �ž |d u r| j}t|tƒr™tƒ }g |d< |D ]P‰ ˆ d dkritƒ }	ˆ d |	d< |rF|s>t‡ fdd„ˆ d D ƒƒ|	d< ntˆ d ƒ|	d< |rb|sZt‡ fdd„ˆ d	 D ƒƒ|	d	< ntˆ d	 ƒ|	d
< |d  |	¡ qttu rrt|ƒ t	j
|d||dtdd�}
ttƒr‰ttd|
| ƒ |r�| |
¡ |
W  d   ƒ S W d   ƒ d S 1 s¤w   Y  d S )NÚentriesrH  rJ  rh  c                 3   s,   � | ]}ˆ d  | r|ˆ d  | fV  qdS )rX  Nr€   ©r>  ÚkeyrL  r€   r�   Ú	<genexpr>Ï  ó   €* z.Connection.response_to_json.<locals>.<genexpr>rX  c                 3   s,   � | ]}ˆ d  | r|ˆ d | fV  qdS )zraw:attributesÚraw_attributesNr€   rº  rL  r€   r�   r¼  Õ  r½  r¾  ÚrawT)ú,z: )Úensure_asciiÚ	sort_keysÚindentÚcheck_circularÚdefaultÚ
separatorsz"building JSON output <%s> for <%s>)r’   rœ   rÆ   r%   rt  r   r}   Úbytesrl   ÚjsonÚdumpsrm   rp   rr   ro   r±  )rÔ   r¿  r²  rÃ  Úsortr  Úchecked_attributesÚinclude_emptyÚ	json_dictrd  Újson_outputr€   rL  r�   Úresponse_to_json¶  s>   	
  €
Û"üzConnection.response_to_jsonc                 C   sˆ   | j �7 | jr2t|tƒrt|dƒ}ttƒrttd| ƒ | | j	|||d�¡ | 
¡  W d   ƒ d S W d   ƒ d S 1 s=w   Y  d S )Nzw+z!writing response to file for <%s>)r¿  rÃ  rÊ  )r’   rœ   rÆ   r$   rÍ   rp   rr   ro   Ú
writelinesrÏ  r9  )rÔ   Útargetr¿  rÃ  rÊ  r€   r€   r�   Úresponse_to_fileæ  s   


÷"ÿzConnection.response_to_filec                 C   s„  | j �µ | jr | js¨d| _ttƒrttd| j| j| j| ƒ z~z`| jr(| j	dd� | jrP| j
dd�sPd| jr:d| j nd }ttƒrHttd|| ƒ |  ¡  t|ƒ‚| jr[| jd| jd	� |d u rk| jjsk| jjttfv sy| jjsw| jjttfv sy|r}|  ¡  W n ty– } zttƒr‘ttd|| ƒ ‚ d }~ww W d| _nd| _w W d   ƒ d S W d   ƒ d S W d   ƒ d S 1 s»w   Y  d S )
NTz?executing deferred (open: %s, start_tls: %s, bind: %s) for <%s>Frâ   z!deferred start_tls not successfulrä   r�   r�   )rã   r3  )r’   r¯   r®   rp   rr   ro   rª   r¬   r«   rÍ   ræ   r”   rq   rç   ri   rå   r­   rÊ   ÚinfoÚget_infor-   r/   rQ  r.   r2  rc   )rÔ   Ú	read_inforè   Úer€   r€   r�   rM  ö  sD   <€€ý€èÿÿ"çzConnection._fire_deferredc                 C   s$   | j r| js|  | j | j¡| _| jS rÜ   )rœ   rº   Ú_get_entriesr›   r  r€   r€   r�   r¹    s   zConnection.entriesc                 C   s¨  | j �Ç ddlm}m} g }|D ]}|d dkr)t|d  ¡ ƒ}||vr)| |¡ q|jdd„ d� g }|D ]}	|D ]}
|
|	krB nq:| |	¡ q6g }|D ]/}	|| jj	d	�}|t
|	ƒ7 }| |	|| jjrq|| ||d
 |d |	d�n|| |dd|	d�f¡ qMg }|D ]@}|d dkrÁt|d  ¡ ƒ}|D ]}||d kr©|d  |¡}| |¡  nq“dt|ƒ | _ttƒr¼tt| j| ƒ t| jƒ‚q�W d   ƒ |S 1 sÍw   Y  |S )Nr   )Ú	ObjectDefÚReaderrH  rJ  rX  c                 S   s
   t | ƒ S rÜ   )r|   )ro  r€   r€   r�   rq  %  s   
 z)Connection._get_entries.<locals>.<lambda>)r»  )rQ  ÚbaseÚfilter)rX  r�   r   zattribute set not found for )r’   r�   rØ  rÙ  ÚsetÚkeysr   rÊ  rÊ   rQ  rN  rË   r1  Ú_create_entryr}   r”   rp   rq   ro   rd   )rÔ   Úsearch_responseÚsearch_requestrØ  rÙ  Ú	attr_setsrœ   Úresp_attr_setÚunique_attr_setsÚattr_setÚ
unique_setÚobject_defsÚ
object_defr¹  rd  r€   r€   r�   r×    s\   
€ÿ
€2þ
ý
€ô
ä*Ö*zConnection._get_entries)F)TN)NNNNNTNrÜ   )NNN)TNN)T)NFNNN)FNry   TNTT)Fry   T))rí   Ú
__module__Ú__qualname__Ú__doc__r   r   rÛ   rá   rÒ   rð   r  rÓ   Úpropertyr  Úsetterr  r!  r(  rå   r6  rç   r   r   re  rj  r}  r�  rˆ  rŽ  r’  r˜  ræ   r.  r0  r2  r¸  rÏ  rÒ  rM  r¹  r×  r€   r€   r€   r�   rŠ   z   sì    A
â 
<	 $'



þv
ù2
ÿ#
òy
ü>
üa
þ/
ý`
û;
þ#
ü
"!=
û
ù2
ü

rŠ   )£rê  r   r   Úosr   Ú	threadingr   Ú	functoolsr   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/   Úresultsr1   r2   r3   r¹   r4   Úpoolingr5   rÊ   r6   Úoperation.abandonr7   r8   Úoperation.addr9   r:   Úoperation.bindr;   r<   Úoperation.comparer=   r>   Úoperation.deleter?   r@   Úoperation.extendedrA   rB   Úoperation.modifyrC   rD   Úoperation.modifyDnrE   rF   Úoperation.searchrG   rH   Úprotocol.rfc2849rI   rJ   Úprotocol.sasl.digestMd5rK   Úprotocol.sasl.externalrL   Úprotocol.sasl.plainrM   Ústrategy.syncrN   Ústrategy.safeSyncrO   Ústrategy.safeRestartablerP   Ústrategy.mockAsyncrQ   Ústrategy.asynchronousrR   Ústrategy.reusablerS   Ústrategy.restartablerT   Ústrategy.ldifProducerrU   Ústrategy.mockSyncrV   Ústrategy.asyncStreamrW   Úoperation.unbindrX   Úprotocol.rfc2696rY   r  rZ   r™  r[   Ú
exceptionsr\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   Ú
utils.convrj   rk   rl   rm   rn   Ú	utils.logro   rp   rq   rr   rs   rt   ru   Úutils.dnrv   Úutils.port_validatorsrw   r-  r“   r‚   r‰   ÚobjectrŠ   r€   r€   r€   r�   Ú<module>   s|    ¤@$ý÷