HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/channel/__pycache__/client.cpython-310.pyc
o

�N�gGT�@sdZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
ZddlZddlZddl
ZddlZddlZddlZddlmZe�e�ZdZdZGdd�d�ZGdd	�d	�ZGd
d�d�ZGdd
�d
�ZGdd�d�ZGdd�d�ZGdd�d�ZdS)z�
Encapsulate the different transports available to Salt.

This includes client side transport, for the ReqServer and the Publisher
�N)�SyncWrapper�<�c@�eZdZdZedd��ZdS)�
ReqChannelz�
    Factory class to create a sychronous communication channels to the master's
    ReqServer. ReqChannels use transports to connect to the ReqServer.
    cK�ttj|f|dd�S�N�io_loop)Z
loop_kwarg)r�AsyncReqChannel�factory��opts�kwargs�r�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/channel/client.pyr%��zReqChannel.factoryN��__name__�
__module__�__qualname__�__doc__�staticmethodrrrrrrsrc@r)�PushChannelzM
    Factory class to create Sync channel for push side of push/pull IPC
    cKrr)r�AsyncPushChannelrrrrrr4rzPushChannel.factoryNrrrrrr/�rc@r)�PullChannelzM
    Factory class to create Sync channel for pull side of push/pull IPC
    cKrr)r�AsyncPullChannelrrrrrrCrzPullChannel.factoryNrrrrrr>rrc@s�eZdZdZgd�ZdgZedd��Zee	fdd�Z
edd	��Zed
d��Z
dd
�Zejjjjdd��Zejjjj			d$dd��Zdd�Zejjjjd%dd��Zejjjjdd��Zejjjjdd��Zejjjjd&dd��Zdd�Zd d!�Zd"d#�ZdS)'r
z�
    Factory class to create a asynchronous communication channels to the
    master's ReqServer. ReqChannels connect to the master's ReqServerChannel.
    )�!crypted_transfer_decode_dictentry�_crypted_transfer�_uncrypted_transfer�send�connect�closec
Ks�d}d|vr|d}nd|�di��di�vr|ddd}d|vr-d|vr-|d|d<|�d�}|dur>tjjjj��}|�dt�}|�dt�}|�d	d
�}|dkr]tj	j
||d�}nd}tjj||d�}	|||	|||d
�S)N�zeromq�	transport�pillar�master�
master_urir	Zrequest_channel_timeoutZrequest_channel_tries�crypt�aes�clear�r	)�tries�timeout)
�get�salt�ext�tornado�ioloop�IOLoop�current�REQUEST_CHANNEL_TIMEOUT�REQUEST_CHANNEL_TRIESr(�	AsyncAuthr$Zrequest_client)
�clsr
r�ttyper	r-r,r(�authr$rrrr^s$

zAsyncReqChannel.factorycKsRt|�|_||_||_d|_|jrtj�|jd|jj�|_d|_	||_
||_dS)N�pki_dirF)�dictr
r$r:�master_pubkey_path�os�path�join�mpub�_closingr-r,)�selfr
r$r:r-r,rrrr�__init__|s
	
zAsyncReqChannel.__init__cC�|jrdSdS�Nr)r*�r:�rCrrrr(�szAsyncReqChannel.cryptcCs|jjS�N)r$r9rHrrrr9�szAsyncReqChannel.ttypecCs8|j|dd�}|jdkr|jd|d<|jd|d<|S)N���enc�load�versionr)�encryption_algorithmZenc_algo�signing_algorithm�sig_algo)r(r
)rCrM�retrrr�
_package_load�s�
zAsyncReqChannel._package_loadc
csr�d}	z|jj||d�V}Wn!ty0}zt�d|�||kr"�|d7}WYd}~qd}~wwtjjj�	|��)N�T�r-�Failed to send msg %r)
r$r �	Exception�log�tracer/r0r1�gen�Return)rCrMr,r-�_tryrR�excrrr�_send_with_retry�s$����z AsyncReqChannel._send_with_retryNccsN�|dur|j}|dur|j}t��j}||d<|jjs"|j��V|�|�	|jj
�|��||�V}|j��}d|vrQ|j��V|�|�	|jj
�|��||�V}|�
|d|jd�}tj�|j|�}	|	�||�}
|�|
d|
d�s{tj�d��tj�|
d�}|d|dkr�tj�d��|d|kr�tj�d��tjjj�|d	��)
N�nonce�keyrO�data�sigz,Pillar payload signature failed to validate.zKey verification failed.z!Pillar nonce verification failed.r%)r-r,�uuid�uuid4�hexr:�
authenticated�authenticater^rS�	crypticle�dumpsZget_keysZdecryptr
r/r(Z	Crypticle�loads�verify_signature�AuthenticationError�payloadr0r1rZr[)rCrMZdictkeyr-r,r_rRr`r)ZpcryptZ
signed_msgrarrrr�sF�
�
��z1AsyncReqChannel.crypted_transfer_decode_dictentrycCstj�|j��|||jd�S)NrP)r/r(Z	PublicKeyr=Zverifyr
)rCrarbrrrrk�s�z AsyncReqChannel.verify_signatureFc#s��t��j��rt�t�r��d<tjjjj	�����fdd��}�j
js+�j
��Vz|�V}Wntj
jyF�j
��V|�V}Ynwtjjj�|��)a�
        Send a load across the wire, with encryption

        In case of authentication errors, try to renegotiate authentication
        and retry the method.

        Indeed, we can fail too early in case of a master restart during a
        minion state execution call

        :param dict load: A load to send across the wire
        :param int timeout: The number of seconds on a response before failing
        r_c3sh��jj���jj�����d�V}|r�jjj|��d�}�r%�jdkr,tjj	�
|�}tjjj
�|��)NrU)r_Ztcp)r$r rSr:rhrirjr9r/�frameZdecode_embedded_strsr0r1rZr[)ra�rMr_�rawrCr-rr�_do_transfers��z7AsyncReqChannel._crypted_transfer.<locals>._do_transfer)rcrdre�
isinstancer<r/r0r1rZ�	coroutiner:rfrgr(rlr[)rCrMr-rprqrRrrorr�s�

�z!AsyncReqChannel._crypted_transferccs*�|jj|�|�|d�V}tjjj�|��)z�
        Send a load across the wire in cleartext

        :param dict load: A load to send across the wire
        :param int timeout: The number of seconds on a response before failing
        rU)r$r rSr/r0r1rZr[)rCrMr-rRrrrrs��z#AsyncReqChannel._uncrypted_transferccs�|j��VdSrI)r$r!rHrrrr!.s�zAsyncReqChannel.connectc
cs��|dur|j}|dur|j}d}	z%|jdkr't�d|�|j||d�V}nt�d|�|j|||d�V}Wn!tyX}zt�d	|�||krJ�|d7}WYd}~qd}~wwtj	j
j�|��)
a,
        Send a request, return a future which will complete when we send the message

        :param dict load: A load to send across the wire
        :param int tries: The number of times to make before failure
        :param int timeout: The number of seconds on a response before failing
        NrTTr*zReqChannel send clear load=%rrUzReqChannel send crypt load=%r)r-rprV)
r-r,r(rXrYrrrWr/r0r1rZr[)rCrMr,r-rpr\rRr]rrrr 2s.�	
��zAsyncReqChannel.sendcCs.|jrdSt�d|jj�d|_|j��dS)z�
        Since the message_client creates sockets and assigns them to the IOLoop we have to
        specifically destroy them, since we aren't the only ones with references to the FDs
        NzClosing %s instanceT)rBrX�debug�	__class__rr$r"rHrrrr"Rs
zAsyncReqChannel.closecC�|SrIrrHrrr�	__enter__]�zAsyncReqChannel.__enter__cG�|��dSrI�r"�rC�argsrrr�__exit__`�zAsyncReqChannel.__exit__)NNN)F)NNF)rrrr�
async_methods�
close_methods�classmethodrr5r6rD�propertyr(r9rSr/r0r1rZrsr^rrkrrr!r r"rwr}rrrrr
MsD�
"
�




�3

.



r
c@s�eZdZdZddgZdgZedd��Zd"dd	�Ze	d
d��Z
ejj
jjdd
��Zdd�Zd"dd�Zdd�Zejj
jjdd��Zejj
jjdd��Zdd�Zdd�Zejj
jjdd��Zdd�Zd d!�ZdS)#�AsyncPubChannelzQ
    Factory class to create subscription channels to the master's Publisher
    r!�_decode_payloadr"cKs�d}d|vr|d}nd|�di��di�vr|ddd}d|vr-d|vr-|d|d<|dkr;d|d<t�d	|�|�d
�}|durLtjjjj��}tj	j
||d�}tj�||�}|||||�S)Nr#r$r%r&r'ZdetectTZdetect_modez$Transport is set to detect; using %sr	r+)
r.rX�infor/r0r1r2r3r4r(r7r$Zpublish_client)r8r
rr9r	r:r$rrrrqs 

zAsyncPubChannel.factoryNcCsh||_||_||_|j�d�|_||_d|_d|_tj	j
jd|jdd�|_
tj
�|jd|jj�|_dS)NssaltF�minion)r
�listenr;)r
r	r:Z	gen_token�tokenr$rB�_reconnectedr/�utils�eventZ	get_eventr>r?r@rAr=)rCr
r$r:r	rrrrD�szAsyncPubChannel.__init__cCrErFrGrHrrrr(�szAsyncPubChannel.cryptc
cs��z0|jjs|j��Vt|j�dd��dkr|j�d�}n|jjd}|j�||j	|j
�VWdSty9�tyZ}zdt
|�vrOtj�d|����WYd}~dSd}~ww)zX
        Return a future which completes when connected to the remote publisher
        �publish_porti�z	-|RETRY|-zUnable to sign_in to master: N)r:rfrg�intr
r.Zcredsr$r!�connect_callback�disconnect_callback�KeyboardInterruptrW�strr/�
exceptions�SaltClientError)rCr�r]rrrr!�s(�
�����zAsyncPubChannel.connectcCs,|j��|jdur|j��d|_dSdS)z#
        Close the channel
        N)r$r"r�ZdestroyrHrrrr"�s




�zAsyncPubChannel.closecs:�dur
�j�d�Stjjjj��fdd��}�j�|�S)zH
        When jobs are received pass them (decoded) to callback
        Nc3s@��j�|�V}��|�V}t�d|�|dur�|�dSdS)NzPubChannel received: %r)r$Z_decode_messagesr�rXrt)�messagesrm�decoded��callbackrCrr�
wrap_callback�s��z.AsyncPubChannel.on_recv.<locals>.wrap_callback)r$�on_recvr/r0r1rZrs)rCr�r�rr�rr��s

zAsyncPubChannel.on_recvcCs|j|dd�S)NrJrK)r()rCrMrrrrS�s�zAsyncPubChannel._package_loadc
#s��jd|d��tjjjj��fdd��}|s�jjs`d}|�jdks,�jddkr`z�j��VWn+tj	j
yQ}zt�|�|d7}WYd}~nd}~ww|�jdks,�jddks,z|�V}tjjj�
|��tjjy��j��V|�V}tjjj�
|��w)	z�
        Send the minion id to the master so that the master may better
        track the connection state of the minion.
        In case of authentication errors, try to renegotiate authentication
        and retry the method.
        �id)r��tokc3sF����jj����}tjjj|dd�}�j�|�Vtj	j
j�d��)N)�headerT)
rSr:rhrir/r$rnZ	frame_msgr r0r1rZr[)�msg�package�rMrCrrrq�s
�z-AsyncPubChannel.send_id.<locals>._do_transferrZtcp_authentication_retriesrTN)r
r/r0r1rZrsr:rfrgr�r�rXrtr[r(rl)rCr�Z
force_authrq�countr]rRrr�r�send_id�s4�

����zAsyncPubChannel.send_idc
cs��|jrdSz�|�|j|j�Vd|_|j�d|jdid�|jr�|j�d�dkrCd�	|jdt
���}tj
j�|jddgd�}nd	�	|jdt
���}tj
j�|jddgd
�}|jddd|j||d�}t�|j��2}z
|j|d
d�VWntjjy�t�d�Ynty�tjddd�YnwWd�n1s�wYWdSWdSd|_WdSty�}ztjd|dd�WYd}~dSd}~ww)NTr&Z__master_connectedZ__roleZsyndiczSyndic {} started at {}r��startzMinion {} started at {}r�Z
_minion_event)r��cmdZpretagr�ra�tagrrUzEfire_master failed: master could not be contacted. Request timed out.zfire_master failed)�exc_infoz2Caught exception in PubChannel connect callback %r)rBr�r�r��	connectedr��
fire_eventr
r.�format�time�asctimer/r�Ztagifyr
rr r�ZSaltReqTimeoutErrorrXr�rW�error)rC�resultrar�rMZchannelr]rrrr��sV�������(����z AsyncPubChannel.connect_callbackcCs,|jrdSd|_|j�d|jdid�dS)NFr&Z__master_disconnected)rBr�r�r�r
rHrrrr�.sz#AsyncPubChannel.disconnect_callbackcCs\|j�d�r*|�dd�stj�d��tjj|j|d|�d�|dd�s,tj�d��dSdS)	NZsign_pub_messagesrbFz<Message signing is enabled but the payload has no signature.rMrQ)�	algorithmz%Message signature failed to validate.)r
r.r/r(rlrkr=)rCrmrrr�_verify_master_signature4s ����z(AsyncPubChannel._verify_master_signatureccs��t�d|�d}|ddkrY|�|�z
|jj�|d�|d<Wn
tjjy.d}Ynw|rYz|j�	�V|jj�|d�|d<WntjjyXt�
d|jd�Ynwtjj
j�|��)	NzDecoding payload: %sFrLr)rMTzEPayload decryption failed even after re-authenticating with master %sZ	master_ip)rXrYr�r:rhrjr/r(rlrgr�r
r0r1rZr[)rCrmZreauthrrrr�Fs*�
���zAsyncPubChannel._decode_payloadcCrvrIrrHrrrrw\rxzAsyncPubChannel.__enter__cGryrIrzr{rrrr}_r~zAsyncPubChannel.__exit__rI)rrrrrr�r�rrDr�r(r/r0r1rZrsr!r"r�rSr�r�r�r�r�rwr}rrrrr�ds6��





	


%
/

r�c@r)rz3
    Factory class to create IPC Push channels
    cK�ddl}|jjj|fi|��S)z\
        If we have additional IPC transports other than UxD and TCP, add them here
        rN)�salt.transport.ipcr$�ipcZIPCMessageClient�r
rr/rrrrhszAsyncPushChannel.factoryNrrrrrrcrrc@r)rz3
    Factory class to create IPC pull channels
    cKr�)z\
        If we have additional IPC transports other than UXD and TCP, add them here
        rN)r�r$r�ZIPCMessageServerr�rrrryszAsyncPullChannel.factoryNrrrrrrtrr)r�loggingr>r�rcZ
salt.cryptr/Zsalt.exceptionsZsalt.ext.tornado.genZsalt.ext.tornado.ioloopZsalt.payloadZsalt.transport.frameZsalt.utils.eventZsalt.utils.filesZsalt.utils.minionsZsalt.utils.stringutilsZsalt.utils.verifyZsalt.utils.asynchronousr�	getLoggerrrXr5r6rrrr
r�rrrrrr�<module>s>