AlkantarClanX12

Your IP : 18.219.47.239


Current Path : /proc/self/root/usr/lib/python3.6/site-packages/isc/__pycache__/
Upload File :
Current File : //proc/self/root/usr/lib/python3.6/site-packages/isc/__pycache__/rndc.cpython-36.pyc

3

���f+�@sXddlmZddlZddlZddlZddlZddlZddlZddlZGdd�de	�Z
dS)�)�OrderedDictNc@sleZdZdZddddddd�Zd	d
�Zdd�Zddd�Zdd�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�rndczRNDC protocol client library������)�md5Zsha1Zsha224Zsha256Zsha384Zsha512cCsb||_|j�}|jd�r$|dd�}||_tt|�|_tj|�|_	t
jdd�|_d|_
|j�dS)z�Creates a persistent connection to RNDC and logs in
        host - (ip, port) tuple
        algo - HMAC algorithm: one of md5, sha1, sha224, sha256, sha384, sha512
               (with optional prefix 'hmac-')
        secret - HMAC secret, base64 encodedzhmac-�Nr��i)�host�lower�
startswith�algo�getattr�hashlib�hlalgo�base64�	b64decode�secret�randomZrandint�ser�nonce�_rndc__connect_login)�selfrrr�r�/usr/lib/python3.6/rndc.py�__init__$s
z
rndc.__init__cCst|j|d�d�S)z�Call a RNDC command, all parsing is done on the server side
        cmd - a complete string with a command (eg 'reload zone example.com')
        )�type�_data)�dict�_rndc__command)r�cmdrrr�call5sz	rndc.callFcCst�}�x|j�D]�\}}|r(|dkr(q|tjdt|��|jd�7}t|�tkrt|tjddt|��|jd�7}qt|�tkr�|tjddt|��|7}qt|�tkr�|tjddt|��|7}qt|�t	kr�|j
|�}|tjddt|��|7}qtdt|���qW|S)N�_auth�B�asciiz>BIr�z#Cannot serialize element of type %s)�	bytearray�items�struct�pack�len�encoder �str�bytesr�_rndc__serialize_dict�NotImplementedError)r�data�ignore_auth�rv�k�vZsdrrrZ__serialize_dict;s""
zrndc.__serialize_dictc	Os,|jd7_ttj��}t||�}t�}t�|d<t�|d<t|j�|dd<t|�|dd<t|d�|dd<|jdk	r�|j|dd<||d	<|j|d
d�}tj|j	||j
�j�}tj
|�}|jdkr�tjd
|�|dd<n"ttjd|j|j|��|dd<|j|�}tjdt|�dd�|}|S)Nrr&�_ctrlZ_serZ_tim�<Z_exp�_noncer!T)r5r
Z22s�hmd5ZB88s�hshaz>II�)r�int�timerr0rr2�hmac�newrr�digestrZ	b64encoderr,r-r*�_rndc__algosr.)	r�args�kwargsZnowr4�d�msg�hash�bhashrrrZ__prep_messageOs,






zrndc.__prep_messagecCs�|jdk	r |dd|jkr dS|jdkr8|dd}n|dddd�}t|�tkrb|jd	�}|d
dt|�d7}tj|�}|j|dd
�}t	j
|j||j�j
�}||kS)Nr9r;Fr
r&r<r=rr(�=r>T)r5)rrr r1�decoder.rrr2rArBrrrC)rrHrJZremote_hashZmy_msgZmy_hashrrrZ__verify_msgjs


zrndc.__verify_msgc	Os�|j||�}|jj|�}|t|�kr,td��|jjd�}t|�dkrLtd��tjd|�\}}|dkrptd|��|d8}|jj|tj	�}t|�|kr�td��t
|�tkr�t|�}|j
|�}|j|�s�td	��|S)
NzCannot send the message�zCan't read response headerz>IIrzWrong message version %dr>zCan't read response datazAuthentication failure)�_rndc__prep_message�socket�sendr.�IOErrorZrecvr,�unpackr3ZMSG_WAITALLr r0r*�_rndc__parse_message�_rndc__verify_msg)	rrErFrHZsent�headerZlength�versionr4rrrZ	__commandys(

zrndc.__commandcCs2tj|j�|_d|_|jdd�}|dd|_dS)NZnull)r r9r;)rOZcreate_connectionrrr#)rrHrrrZ__connect_login�szrndc.__connect_logincCs�d}||}|d7}||||�jd�}||7}||}|d7}tjd|||d��d}|d7}||||�}||7}||d�}|dkr�|||fS|dkr�t�}	x(t|�dkr�|j|�\}
}}||	|
<q�W||	|fStd|��dS)Nrrr(z>Ir>r)zUnknown element type %d)rLr,rRrr.�_rndc__parse_elementr3)r�input�posZlabellen�labelr Zdatalenr4�restrGZilabel�valuerrrZ__parse_element�s*

zrndc.__parse_elementcCs8t�}d}x(t|�dkr2|j|�\}}}|||<qW|S)Nr)rr.rW)rrXr6ZhdatarZr\rrrZ__parse_message�szrndc.__parse_messageN)F)�__name__�
__module__�__qualname__�__doc__rDrr%r2rNrTr#rrWrSrrrrrs 
r)�collectionsrr@r,rrArrrO�objectrrrrr�<module>s