
    >OOfl6                         d Z ddlZddlmZmZmZ ddlmZmZm	Z	m
Z
mZmZ ddlmZmZmZmZ ddlmZ ddlmZmZmZmZmZmZ dd	lmZmZ dd
lmZ  e       Z  G d de      Z!y)
    N   )SEQUENCE_TYPESget_config_parameter
DIGEST_MD5)LDAPSocketReceiveErrorcommunication_exception_factoryLDAPExceptionErrorLDAPExtensionErrorLDAPOperationResult$LDAPSignatureVerificationFailedError)BaseStrategySESSION_TERMINATED_BY_SERVERRESPONSE_COMPLETETRANSACTION_ERROR)LDAPMessage)loglog_enabledERRORNETWORKEXTENDEDformat_ldap_message)decoderdecode_message_fast)md5_hmacc                   H    e Zd ZdZd ZddZd Zd Zd Zd Z	d Z
d	 Zd
 Zy)SyncStrategyaZ  
    This strategy is synchronous. You send the request and get the response
    Requests return a boolean value to indicate the result of the requested Operation
    Connection.response will contain the whole LDAP response for the messageId requested in a dict form
    Connection.request will contain the result LDAP message in a dict form
    c                     t        j                  | |       d| _        d| _        d| _        d| _        t        d      | _        y )NTFSOCKET_SIZE)r   __init__syncno_real_dsapooled
can_streamr   socket_size)selfldap_connections     T/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/ldap3/strategy/sync.pyr    zSyncStrategy.__init__0   s<    dO4	 />    c                 &   t        j                  | ||       |r3| j                  j                  s	 | j                  j	                          y y y # t
        $ r9 d | j                  j                  _        d | j                  j                  _        Y y w xY wN)	r   open
connection_deferred_openrefresh_server_infor   server	_dsa_info_schema_info)r&   reset_usageread_server_infos      r(   r,   zSyncStrategy.open8   sw    $-=>DOO$B$B;335 %C ' ;37&&06:&&3;s   A ?BBc                     | j                   j                  s)| j                   j                  sd| j                   _        y y y )NT)r-   	listeningclosedr&   s    r(   _start_listenzSyncStrategy._start_listenA   s0    ((1G1G(,DOO% 2H(r)   c           
         g }d}d}d}d}d}d}d}d}	|r.|r	 | j                   j                  j                  | j                        }| j                   j"                  t$        k(  r2| j                   j&                  r| j                   j(                  s||z   }|dk(  s|rt*        j-                  |dd d	      }	|dd }d}|t/        |      z  }||z  }||	k\  r||	d
z
  |	dz
   }||	dz
  |	 }||	d }|d|	d
z
   }| j                   j&                  }t0        j3                  t5        |||z         dd       }||k7  rVt7        dt        t*        j-                  |d	            z   dz   |j9                         z   dz   |j9                         z   dz         d}||z  }d}n||z  }t/        |      dkD  rt;        j<                  |      }|dk(  rd}t/        |      |k  rd}net        t>              r(t        t>        dt/        |d|       | j                          |jA                  |d|        ||d }d}t/        |      dk(  rd}nd}|r.t        t>              r%t        t>        dt/        |      | j                          |S # t        t        j
                  t        f$ r}
dt        |
      z   | j                   _        	 | j                          n# t        j
                  t        f$ r Y nw xY wt        t              r0t        t        d| j                   j                  | j                           t        t         t!        |
      t        |
                  | j                   j                        d}
~
ww xY w)zV
        Receives data over the socket
        Checks if the socket is closed
        Tr)   r   zerror receiving data: <%s> for <%s>N   big         zCSignature verification failed for the recieved LDAP message number z. Expected signature z	 but got .zreceived %d bytes via <%s>Fz"received %d ldap messages via <%s>)!r-   socketrecvr%   OSErrorerrorAttributeErrorstr
last_errorcloser
   r   r   r   r	   r   typesasl_mechanismr   _digest_md5_kissasl_in_progressint
from_byteslenbytesfromhexr   r   hexr   compute_ldap_message_sizer   append)r&   messages	receivingunprocesseddataget_more_datasasl_total_bytes_recievedsasl_received_datasasl_next_packetsasl_buffer_lengthesasl_signaturesasl_sec_numkiscalculated_signaturelengths                   r(   rX   zSyncStrategy.receivingE   s    
 	$%!   ??1166t7G7GHD ??11Z?DOODcDclpl{l{  mM  mM+d2D)S04D-0^^D1Iu-M*#ABx'*$-T:-&$.&04FF *<<NQS<STfijTj)k'9:Lq:PQc'd+=>P>Q+R(-?@XASVXAX-Y*"oo==/4}}Xc<ZlKl=mnopr=s/t,)-AA"F  HM  PS  TW  Tb  Tb  co  qv  Tw  Px  Hx  {R  HR  Ui  Um  Um  Uo  Ho  r}  H}  @N  @R  @R  @T  HT  WZ  HZ  #[  [451#'99-0*4'K4y1}%??LR<$(M{#f,$(M"7+G%A3{SZTZG[C\^b^m^mnOOK$89"-fg"6K$)M;'1,$)	!	 B w=s8}doo^  ~> 	1ICPQF1RDOO.

"LL*<= "5)E?DOO4N4NPTP_P_`b9:PRYRVWXRYZ]^_Z`Rabcgcrcrc}c}~~	s<   /I: :M,M'6KM'K# M'"K##BM''M,c                 ~   | j                  |      \  }}|| j                  _        |d   dk(  r~|D ]y  }|d   dk7  sd| j                  _        t	        t
              r0t        t
        d| j                  j                  | j                         t        | j                  j                         |j                  |       |S )zp
        Executed after an Operation Request (except Search)
        Returns the result message or None
        rK   intermediateResponsez multiple messages received errorr<   )	get_responser-   resultrI   r   r   r   r   rV   )r&   
message_id	responsesri   responses        r(   post_send_single_responsez&SyncStrategy.post_send_single_response   s    
 !--j9	6!'&>33% MF#'==1SDOO."5)E?DOO4N4NPTP_P_`01K1KLLM 	 r)   c                 v   | j                  |      \  }}|| j                  _        t        |t              r|dd | j                  _        |S d| j                  _        t        t              r0t        t        d| j                  j                  | j                         t        | j                  j                        )z
        Executed after a search request
        Returns the result message and store in connection.response the objects found
        Nzerror receiving responser<   )rh   r-   ri   
isinstancer   rl   rI   r   r   r   r   )r&   rj   rk   ri   s       r(   post_send_searchzSyncStrategy.post_send_search   s    
 !--j9	6!'i0'0|DOO$%?"u(B(BDOOT$T__%?%?@@r)   c           
         g }d}|s| j                         }|r|D ]  }t        |      dkD  s| j                  j                  r.| j                  j                  j                  t        |             | j                  j                  rt        |      }| j                  |      }n/t        j                  |t              \  }}	| j                  |      }t        t              r&t        t        d| j                  t!        |d             t#        |d         |k(  r|j%                  |       |d   dvsd	}t#        |d         dk(  r|d
   dk(  rt&        c S |d
   dk(  rt(        c S d| j                  _        t        t,              r0t        t,        d| j                  j*                  | j                         t/        | j                  j*                        t#        |d         |k7  rw|d   dk(  rod| j                  _        t        t,              r0t        t,        d| j                  j*                  | j                         t1        | j                  j*                        d| j                  _        t        t,              r0t        t,        d| j                  j*                  | j                         t/        | j                  j*                         nt&        S |s|j%                  t2               |S )zH
        Performs the capture of LDAP response for SyncStrategy
        Fr   )asn1Specz!ldap message received via <%s>:%sz<<	messageIDrK   )searchResEntrysearchResRefrg   TresponseNamez1.3.6.1.4.1.1466.20036z2.16.840.1.113719.1.27.103.4z,unknown unsolicited notification from serverr<   extendedRespz8multiple extended responses to a single extended requestzinvalid messageId received)rX   rQ   r-   usage_usageupdate_received_messagefast_decoderr   decode_response_fastr   decodeLDAP_MESSAGE_TEMPLATEdecode_responser   r   r   r   rO   rV   r   r   rI   r   r   r   r   )
r&   rj   timeoutldap_responsesresponse_completerk   rl   	ldap_respdict_response_s
             r(   _get_responsezSyncStrategy._get_response   st    !#(I ) $UH8}q(??00 OO22JJ3x=Y??77(;H(EI,0,E,Ei,PM+2>>(Mb+cLIq,0,@,@,KM&x0*Mt`st}  @D  aE  Fy56*D*11-@,V4<vv48 1 ;!78A=,^<@XX'C C!.~!>B`!`'8 8=k :#.u#5$'@Z@Z\`\k\k$l&<T__=W=W&X X ;!78JF=Y_K`drKr9sDOO6*51 #E?DOO<V<VX\XgXg h"4T__5O5O"PP :VDOO6*51 #E?DOO<V<VX\XgXg h"89S9S"TTI$UX 43_ $` 	/0r)   c                     t         r+   NotImplementedError)r&   values     r(   
set_streamzSyncStrategy.set_stream       !!r)   c                     t         r+   r   r8   s    r(   
get_streamzSyncStrategy.get_stream   r   r)   N)TT)__name__
__module____qualname____doc__r    r,   r9   rX   rm   rp   r   r   r    r)   r(   r   r   (   s8    ?;-Tl$A 8t""r)   r   )"r   rC    r   r   r   core.exceptionsr   r	   r
   r   r   r   strategy.baser   r   r   r   protocol.rfc4511r   	utils.logr   r   r   r   r   r   
utils.asn1r   r   protocol.sasl.digestMd5r   r~   r   r   r)   r(   <module>r      sL   2  ? ? y  y l l * W W 5 .# S"< S"r)   