U
    ÓZj­  ã                   @   sÚ   d Z ddlZddlZddlZddlZddlmZ ddlm	Z	 zddl
ZW n ek
rd   ddlZY nX ddlmZ dZdZd	Zd
d„ Zdd„ Ze ¡ d dkr¦ejZnejZG dd„ dejƒZdd„ ZG dd„ deƒZdS )zP
Functions for communicating with Pageant, the basic windows ssh agent program.
é    N)Ú	zero_byte)Úbé   )Ú_winapil   ºPœ  i    éJ   c                   C   s   t jj dd¡S )Ns   Pageant)ÚctypesÚwindllÚuser32ZFindWindowA© r
   r
   úW/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/paramiko/win_pageant.pyÚ_get_pageant_window_object.   s    r   c                   C   s
   t tƒ ƒS )zÂ
    Check to see if there is a "Pageant" agent we can talk to.

    This checks both if we have the required libraries (win32all or ctypes)
    and if there is a Pageant currently running.
    )Úboolr   r
   r
   r
   r   Úcan_talk_to_agent2   s    r   Ú64bitc                   @   s,   e Zd ZdZdefdejjfdejfgZ	dS )ÚCOPYDATASTRUCTzy
    ctypes implementation of
    http://msdn.microsoft.com/en-us/library/windows/desktop/ms649010%28v=vs.85%29.aspx
    Znum_dataÚ	data_sizeZdata_locN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	ULONG_PTRr   ZwintypesZDWORDZc_void_pZ_fields_r
   r
   r
   r   r   B   s
   
ýr   c              
   C   sæ   t ƒ }|sdS dt ¡  }t |tt ¡ ¡}|�¬ | | ¡ t dt	|ƒt
 ¡}| ¡ \}}tt||ƒ}tjj |tt |¡t |¡¡}|dkrÎ| d¡ | d¡}	t d|	¡d }
|	| |
¡ W  5 Q R £ S W 5 Q R £ dS Q R X dS )za
    Communication with the Pageant process is done through a shared
    memory-mapped file.
    NzPageantRequest%08xr   r   é   z>I)r   ÚthreadÚ	get_identr   Z	MemoryMapÚ_AGENT_MAX_MSGLENZ get_security_attributes_for_userÚwriteÚarrayr   r   Úbuffer_infor   Ú_AGENT_COPYDATA_IDr   r   r	   ZSendMessageAÚwin32con_WM_COPYDATAZsizeofZbyrefÚseekÚreadÚstructÚunpack)ÚmsgZhwndZmap_nameZpymapZchar_bufferZchar_buffer_addressZchar_buffer_sizeZcdsÚresponseZdatalenZretlenr
   r
   r   Ú_query_pageantO   s<      ÿ
  ÿ   ÿ

r&   c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚPageantConnectiona  
    Mock "connection" to an agent which roughly approximates the behavior of
    a unix local-domain socket (as used by Agent).  Requests are sent to the
    pageant daemon via special Windows magick, and responses are buffered back
    for subsequent reads.
    c                 C   s
   d | _ d S ©N©Ú	_response©Úselfr
   r
   r   Ú__init__}   s    zPageantConnection.__init__c                 C   s   t |ƒ| _d S r(   )r&   r*   )r,   Údatar
   r
   r   Úsend€   s    zPageantConnection.sendc                 C   s@   | j d krdS | j d |… }| j |d … | _ | j dkr<d | _ |S )NÚ r)   )r,   ÚnÚretr
   r
   r   Úrecvƒ   s    

zPageantConnection.recvc                 C   s   d S r(   r
   r+   r
   r
   r   ÚcloseŒ   s    zPageantConnection.closeN)r   r   r   r   r-   r/   r3   r4   r
   r
   r
   r   r'   u   s
   	r'   )r   r   Zctypes.wintypesr   Úplatformr"   Zparamiko.commonr   Zparamiko.py3compatr   Ú_threadr   ÚImportErrorr0   r   r   r   r   r   r   ÚarchitectureZc_uint64r   Zc_uint32Z	Structurer   r&   Úobjectr'   r
   r
   r
   r   Ú<module>   s,   
&