HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/ipalib/__pycache__/rpc.cpython-36.opt-1.pyc
3

�d[e��@szdZddlmZddlmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlmZddlmZddlZddlmZddlZddlmZdd	lmZdd
lmZmZmZm Z m!Z!ddl"m#Z#m$Z$ddl%m&Z&m'Z'dd
l(m)Z*ddl+m,Z,ddl+m-Z-ddl.m/Z/ddl0m1Z1m2Z2ddl3m4Z4ddl5m6Z6ddl7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?ddl@mAZAddlBmCZCddlDmEZEddl"mFZFy4ddlGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQWnFeRk
�rddlSmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQYnXejT�r6ddlUmVZVnddlWmXZVejT�rNeYZZej[e\�Z]dZ^dZ_dd�Z`d d!�Zad"d#�Zbd$d%�ZcdLd'd(�ZddMd*d+�ZeGd,d-�d-ef�ZgdNd.d/�Zhejiejfd0d1�Zkd2d3�ZldOd4d5�ZmdPd6d7�ZnGd8d9�d9�ZoGd:d;�d;eN�ZpGd<d=�d=ep�ZqGd>d?�d?eq�ZrGd@dA�dAer�ZsGdBdC�dCes�ZtGdDdE�dEe�ZuGdFdG�dGeu�ZvGdHdI�dI�ZwGdJdK�dKeu�ZxdS)Qa`
RPC client and shared RPC client/server functionality.

This module adds some additional functionality on top of the ``xmlrpc.client``
module in the Python standard library (``xmlrpclib`` in Python 2).
For documentation on the ``xmlrpclib`` module, see:

    http://docs.python.org/2/library/xmlrpclib.html

Also see the `ipaserver.rpcserver` module.
�)�absolute_import)�DecimalN)�SSLError)�x509)�DNSException)�Connectible)�LDAP_GENERALIZED_TIME_FORMAT)�errors_by_code�UnknownError�NetworkError�XMLRPCMarshallError�	JSONError)�errors�capabilities)�context�
Connection)�Encoding)�ipautil)�session_storage)�Cookie)�DNSName�	query_srv)�_)�create_https_connection)�KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN�KRB5KRB_AP_ERR_TKT_EXPIRED�
KRB5_FCC_PERM�KRB5_FCC_NOFILE�KRB5_CC_FORMAT�KRB5_REALM_CANT_RESOLVE�KRB5_CC_NOTFOUND�
get_principal)�DN)�	Principal)�VERSION_WITHOUT_CAPABILITIES)�api)
�Binary�Fault�DateTime�dumps�loads�ServerProxy�	Transport�
ProtocolError�MININT�MAXINT)�RemoteDisconnected)�
BadStatusLineZipa_sessionzX-IPA-Session-CookiecCsFytj|t|�Wn.tk
r@}ztt|���WYdd}~XnXdS)z�
    Given a principal create or update the session data for that
    principal in the persistent secure storage.

    Raises ValueError if unable to perform the action for any reason.
    N)rZ
store_data�CCACHE_COOKIE_KEY�	Exception�
ValueError�str)�	principal�data�e�r9�/usr/lib/python3.6/rpc.py�%update_persistent_client_session_datadsr;cCs@ytj|t�Stk
r:}ztt|���WYdd}~XnXdS)z�
    Given a principal return the stored session data for that
    principal from the persistent secure storage.

    Raises ValueError if unable to perform the action for any reason.
    N)r�get_datar2r3r4r5)r6r8r9r9r:�#read_persistent_client_session_dataqsr=cCsDytj|t�Wn.tk
r>}ztt|���WYdd}~XnXdS)z�
    Given a principal remove the session data for that
    principal from the persistent secure storage.

    Raises ValueError if unable to perform the action for any reason.
    N)rZremove_datar2r3r4r5)r6r8r9r9r:�%delete_persistent_client_session_data~sr>cs^t|�ttfkr&t�fdd�|D��St|t�rJt�fdd�|j�D��St|�tkr^t|�St|�tkrrt	|�St|t
�r�|tks�|tkr�t	|�St|t
�r�t|�St|tj�r�tj�d�r�t|�S|jt�St|t�r�tj�d�r�dt	|�iSt	|�St|t��rt	|�St|tj��r4tj|jtj��jd�St|tj��rZtj|jtj��jd�S|S)a�
    Wrap all ``str`` in ``xmlrpc.client.Binary``.

    Because ``xmlrpc.client.dumps()`` will itself convert all ``unicode`` instances
    into UTF-8 encoded ``str`` instances, we don't do it here.

    So in total, when encoding data for an XML-RPC packet, the following
    transformations occur:

        * All ``str`` instances are treated as binary data and are wrapped in
          an ``xmlrpc.client.Binary()`` instance.

        * Only ``unicode`` instances are treated as character data. They get
          converted to UTF-8 encoded ``str`` instances (although as mentioned,
          not by this function).

    Also see `xml_unwrap()`.

    :param value: The simple scalar or simple compound value to wrap.
    c3s|]}t|��VqdS)N)�xml_wrap)�.0�v)�versionr9r:�	<genexpr>�szxml_wrap.<locals>.<genexpr>c3s |]\}}|t|��fVqdS)N)r?)r@�krA)rBr9r:rC�s�datetime_values�dns_name_values�__dns_name__�ascii) �type�list�tuple�
isinstance�dict�items�bytesr&r�unicode�intr.r/r"r5�datetimer�client_has_capabilityr(�strftimerrr#�crypto_x509�Certificate�base64�	b64encode�public_bytes�
x509_Encoding�DER�decode�CertificateSigningRequest)�valuerBr9)rBr:r?�s<



r?�UTF-8cs�t|ttttf�r|S|dkr"|St|t�r6|j��St|ttf�rZt�fdd�|D��St|t	�r�d|krxt
|d�St	�fdd�|j�D��Sn,t|t�r�|j
St|t�r�tjjt|�d�St|��dS)aI
    Unwrap all ``xmlrpc.Binary``, decode all ``str`` into ``unicode``.

    When decoding data from an XML-RPC packet, the following transformations
    occur:

        * The binary payloads of all ``xmlrpc.client.Binary`` instances are
          returned as ``str`` instances.

        * All ``str`` instances are treated as UTF-8 encoded Unicode strings.
          They are decoded and the resulting ``unicode`` instance is returned.

    Also see `xml_wrap()`.

    :param value: The value to unwrap.
    :param encoding: The Unicode encoding to use (defaults to ``'UTF-8'``).
    Nc3s|]}t|��VqdS)N)�
xml_unwrap)r@rA)�encodingr9r:rC�szxml_unwrap.<locals>.<genexpr>rGc3s |]\}}|t|��fVqdS)N)r`)r@rDrA)rar9r:rC�sz%Y%m%dT%H:%M:%S)rLrPrQ�float�boolrOr\rJrKrMrrNr&r7r(rR�strptimer5�	TypeError)r^rar9)rar:r`�s$




r`FcCs*t|�tkrt||�}nt||||dd�S)a�
    Encode an XML-RPC data packet, transparently wraping ``params``.

    This function will wrap ``params`` using `xml_wrap()` and will
    then encode the XML-RPC data packet using ``xmlrpc.client.dumps()`` (from the
    Python standard library).

    For documentation on the ``xmlrpc.client.dumps()`` function, see:

        http://docs.python.org/library/xmlrpc.client.html#convenience-functions

    Also see `xml_loads()`.

    :param params: A ``tuple`` or an ``xmlrpc.client.Fault`` instance.
    :param methodname: The name of the method to call if this is a request.
    :param methodresponse: Set this to ``True`` if this is a response.
    :param encoding: The Unicode encoding to use (defaults to ``'UTF-8'``).
    T)�
methodname�methodresponsera�
allow_none)rIrKr?r))�paramsrBrfrgrar9r9r:�	xml_dumps�srjcs~eZdZdZdZe�Zef�fdd�	Zdd�Zefd	d
�Z	dd�Z
d
d�Zdd�Zefdd�Z
eejfdd�Zdd�Z�ZS)�_JSONPrimera�Fast JSON primer and pre-converter

    Prepare a data structure for JSON serialization. In an ideal world, priming
    could be handled by the default hook of json.dumps(). Unfortunately the
    hook treats Python 2 str as text while IPA considers str as bytes.

    The primer uses a couple of tricks to archive maximum performance:

    * O(1) type look instead of O(n) chain of costly isinstance() calls
    * __missing__ and __mro__ with caching to handle subclasses
    * inline code with minor code duplication (func lookup in enc_list/dict)
    * avoid surplus function calls (e.g. func is _identity, obj.__class__
      instead if type(obj))
    * function default arguments to turn global into local lookups
    * avoid re-creation of bound method objects (e.g. result.append)
    * on-demand lookup of client capabilities with cached values

    Depending on the client version number, the primer converts:

    * bytes -> {'__base64__': b64encode}
    * datetime -> {'__datetime__': LDAP_GENERALIZED_TIME}
    * DNSName -> {'__dns_name__': unicode}

    The _ipa_obj_hook() functions unserializes the marked JSON objects to
    bytes, datetime and DNSName.

    :see: _ipa_obj_hook
    rB�
_cap_datetime�_cap_dnsnamec!s�tt|�j�||_d|_d|_|jt|t|t	|t
d�|t|ttt
tttt|jtj|jt|jt|jt|jt|jtj|jtj|ji�dS)N)�superrk�__init__rBrlrm�updaterPrcrQrIrbrr"r5r#r�_enc_dnsnamerR�
_enc_datetimerO�
_enc_bytesrJ�	_enc_listrKrM�	_enc_dictrUrV�_enc_certificater])�selfrB�	_identity)�	__class__r9r:ro8s*z_JSONPrimer.__init__cCsdx*|jD] }||kr||||<||SqWx*|D]"}t||�r2||||<||Sq2Wt|��dS)N)�__mro__�
issubclassre)rw�typ�cr9r9r:�__missing__Ps

z_JSONPrimer.__missing__cCs||j}||kr|S||�S)N)ry)rw�objrx�funcr9r9r:�convert]s
z_JSONPrimer.convertcCsB|j}|dkr"tj|jd�}||_|r4d|jt�iS|jt�SdS)NrE�__datetime__)rlrrSrBrTr)rw�val�capr9r9r:rrbsz_JSONPrimer._enc_datetimecCs>|j}|dkr"tj|jd�}||_|r2dt|�iSt|�SdS)NrFrG)rmrrSrBrP)rwr�r�r9r9r:rqmsz_JSONPrimer._enc_dnsnamecCs"tj|�}tjs|jd�}d|iS)NrH�
__base64__)rWrX�six�PY2r\)rwr�Zencodedr9r9r:rsxs

z_JSONPrimer._enc_bytescCs>g}|j}x.|D]&}||j}|||kr,|n||��qW|S)N)�appendry)rwr�rx�resultr�rAr�r9r9r:rt~s

z_JSONPrimer._enc_listcCs@i}x6||�D]*\}}||j}||kr,|n||�||<qW|S)N)ry)rwr�rx�
_iteritemsr�rDrAr�r9r9r:ru�s

z_JSONPrimer._enc_dictcCs|j|jtj��S)N)rsrYrZr[)rwr�r9r9r:rv�sz_JSONPrimer._enc_certificate)rBrlrm)�__name__�
__module__�__qualname__�__doc__�	__slots__�objectrxror~r�rrrqrsrtr��	iteritemsrurv�
__classcell__r9r9)ryr:rks
rkcCs0t|�j|�}|r"tj|ddd�Stj|�SdS)aVSerialize a Python object structure to JSON

    :param object val: Python object structure
    :param str version: client version
    :param bool pretty_print: indent and sort JSON (warning: slow!)
    :return: text
    :note: pretty printing triggers a slow path in Python's JSON module. Only
           use pretty_print in debug mode.
    �T)�indent�	sort_keysN)rkr��jsonr))r�rB�pretty_printr�r9r9r:�json_encode_binary�s
r�cCsxd|krtj|d�Sd|kr0tjj|dt�Sd|krDt|d�Sx*||�D]\}}|j|krNt|�||<qNW|SdS)z,JSON object hook

    :see: _JSONPrimer
    r�r�rGN)rW�	b64decoderRrdrrryrK)Zdctr�Z_listrDrAr9r9r:�
_ipa_obj_hook�s
r�cCs"t|t�r|jd�}tj|td�S)z�Convert serialized JSON string back to Python data structure

    :param val: JSON string
    :type val: str, bytes
    :return: Python data structure
    :see: _ipa_obj_hook, _JSONPrimer
    zutf-8)Zobject_hook)rLrOr\r�r*r�)r�r9r9r:�json_decode_binary�s

r�cCs$t|jt�r t|j|jj|��S|S)N)rL�faultStringrOr'�	faultCoder\)r8rar9r9r:�decode_fault�sr�cCsHyt|�\}}t|�|fStk
rB}zt|��WYdd}~XnXdS)a�
    Decode the XML-RPC packet in ``data``, transparently unwrapping its params.

    This function will decode the XML-RPC packet in ``data`` using
    ``xmlrpc.client.loads()`` (from the Python standard library).  If ``data``
    contains a fault, ``xmlrpc.client.loads()`` will itself raise an
    ``xmlrpc.client.Fault`` exception.

    Assuming an exception is not raised, this function will then unwrap the
    params in ``data`` using `xml_unwrap()`.  Finally, a
    ``(params, methodname)`` tuple is returned containing the unwrapped params
    and the name of the method being called.  If the packet contains no method
    name, ``methodname`` will be ``None``.

    For documentation on the ``xmlrpc.client.loads()`` function, see:

        http://docs.python.org/2/library/xmlrpclib.html#convenience-functions

    Also see `xml_dumps()`.

    :param data: The XML-RPC packet to decode.
    N)r*r`r'r�)r7rari�methodr8r9r9r:�	xml_loads�s
r�c@s$eZdZdd�Zdd�Zdd�ZdS)�DummyParsercCs
g|_dS)N)r7)rwr9r9r:ro�szDummyParser.__init__cCs|jj|�dS)N)r7r�)rwr7r9r9r:�feed�szDummyParser.feedcCsdj|j�S)N�)�joinr7)rwr9r9r:�close�szDummyParser.closeN)r�r�r�ror�r�r9r9r9r:r��sr�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�MultiProtocolTransportz,Transport that handles both XML-RPC and JSONcOstj|�|jdd�|_dS)N�protocol)r,ro�getr�)rw�args�kwargsr9r9r:ro�s
zMultiProtocolTransport.__init__cCs&|jdkrt�}||fStj|�SdS)Nr�)r�r�r,�	getparser)rw�parserr9r9r:r��s
z MultiProtocolTransport.getparsercCsF|jdkr|jdd�n|jdd�|jdtt|���|j|�dS)Nr�zContent-Typezapplication/jsonztext/xmlzContent-Length)r��	putheaderr5�lenZ
endheaders)rw�
connection�request_bodyr9r9r:�send_contents

z#MultiProtocolTransport.send_contentN)r�r�r�r�ror�r�r9r9r9r:r��sr�c@seZdZdZdd�ZdS)�LanguageAwareTransportz(Transport sending Accept-Language headerc
Cs�tj||�\}}}y$tjtjd�jddd�dj�}Wntjk
rPd}YnXt|t	�s`g}|j
d|jdd	�f�|j
d
dt|�f�|||fS)N��.�)�maxsplitrZen_uszAccept-Languager�-ZRefererzhttps://%s/ipa/xml)
r��
get_host_info�locale�	setlocale�LC_MESSAGES�split�lower�ErrorrLrJr��replacer5)rw�hostZ
extra_headersrZlangr9r9r:r�s


z$LanguageAwareTransport.get_host_infoN)r�r�r�r�r�r9r9r9r:r�sr�c@seZdZdZdd�ZdS)�SSLTransportz2Handles an HTTPS transaction to an XML-RPC server.cCs�|j|�\}|_}|jr<||jdkr<tjd|�|jdSt|dttdd�tj	j
tj	jd�}|j�tjd|�||f|_|jdS)NrzHTTP connection keep-alive (%s)r�i��ca_certfile)�tls_version_min�tls_version_maxzNew HTTP connection (%s))
r��_extra_headers�_connection�logger�debugr�getattrrr%�envr�r�Zconnect)rwr�Z_x509�connr9r9r:�make_connection+s


zSSLTransport.make_connectionN)r�r�r�r�r�r9r9r9r:r�)sr�c@s�eZdZdZejjejjgZdd�Z	ddd�Z
dd�Zd	d
�Zddd
�Z
dd�Zdd�Zd dd�Zejrpdd�Zejd�Zdd�Zdd�Zdd�ZdS)!�
KerbTransportzK
    Handles Kerberos Negotiation authentication to an XML-RPC server.
    cOs8tj|f|�|�d|_|jdd�|_|jdd�|_dS)N�service�HTTP�ccache)r�ro�_sec_context�popr�r�)rwr�r�r9r9r:roFszKerbTransport.__init__NcCs�|j}|tkrtj|d��n||tkr.tj��nj|tkr@tj��nX|tkrRtj	��nF|t
krdtj��n4|tkrvtj
��n"|tkr�tj��ntjt|�d��dS)N)r�)�message)Zmin_coderrZServiceErrorrZ
NoCCacheErrorrZ
TicketExpiredrZBadCCachePermsrZBadCCacheFormatrZCannotResolveKDCr �CCacheError�
KerberosErrorrP)rwr8r��minorr9r9r:�_handle_exceptionLs 





zKerbTransport._handle_exceptioncCs
|jdS)Nr)r�)rwr9r9r:�	_get_host_szKerbTransport._get_hostcCs2x,|jD]"\}}||kr|jj||f�PqWdS)N)r��remove)rw�name�hrAr9r9r:�_remove_extra_headerbsz"KerbTransport._remove_extra_headerTc	Cs�t|jt�sg|_|jd�|rDttdd�}|rD|jjd|f�dS|j�}|jd|j	d�d}yPd}|j
r�tjdd|j
id	�}tj
|tjj�}tj|||jd
�|_|jj�}Wn4tjjk
r�}z|j||d�WYdd}~XnX|j|�dS)z�
        Two things can happen here. If we have a session we will add
        a cookie for that. If not we will set an Authorization header.
        r�session_cookieN�@�:rZinitiater�)ZusageZstore)�credsr��flags)r�)rLr�rJr�r�rr�r�r�r�r��gssapiZCredentials�NameZNameTypeZhostbased_serviceZSecurityContextr�r��step�
exceptions�GSSErrorr��_set_auth_header)	rw�
use_cookier�r�r�r�r��responser8r9r9r:�
get_auth_infohs,
 zKerbTransport.get_auth_infocCs2|jd�|r.|jjddtj|�jd�f�dS)NZ
Authorizationznegotiate %srH)r�r�r�rWrXr\)rw�tokenr9r9r:r��s
zKerbTransport._set_auth_headerc
Cs�|jr�|jdd�}d}xb|jd�D]T}|j�jd�\}}}|j�dkr"ytj|jd��}PWq"t	t
fk
rtYq"Xq"W|s�tjdd��|jj
|d	�}|jjr�d|_d
S|j|�dS|jdkr�|jdd
�dSd
S)Nzwww-authenticater��,� Z	negotiaterHz,No valid Negotiate header in server response)r�)r�TFi�)r�)r�Z	getheaderr��strip�	partitionr�rWr��encodere�UnicodeErrorrr�r�Zcompleter��statusr�)rwr��headerr�ZfieldrDZ_dummyrAr9r9r:�_auth_complete�s0


zKerbTransport._auth_completercCspy�|j|�}|r|jd�|j�x�tjrh|j|||�|j||�|j|�|j||�|j	dd�}n|j
|||||�|j	�}|jdkr�|j�|jdkr�|j
|�s�q$t|||j|j|j��||_|j
|�s�q$|j|�SWn�tjjk
�r}z|j|�WYdd}~XnZtk
�r<|j�tjd|��Yn0tk
�rj|j�tjd|dd��YnXdS)	Nr�T)�	buffering��i�z&HTTP server has closed connection (%s)zHTTP connection destroyed (%s))�exc_info)r��set_debuglevelr�r�r�Zsend_requestZ	send_hostZsend_user_agentr�Zgetresponse�_KerbTransport__send_requestr��readr�r-�reason�msg�verbose�parse_responser�r�r�r�r0r�r�r��
BaseException)rwr��handlerr�r�r�r�r8r9r9r:�single_request�sL



	



zKerbTransport.single_requestcCs�|jdd�}|r|jd�|jrNtrN|jd|dd�|jdd�|jd�n|jd|�|jd|jf�|j||�|j	||�|S)	Nr�ZPOSTT)Zskip_accept_encoding�Accept-Encoding�gzipz
User-Agent)rr)
r�r�Zaccept_gzip_encodingrZ
putrequestr�r�Z
user_agentZsend_headersr�)rwr�r�rr�r�Zheadersr9r9r:Z__send_request�s

zKerbTransport.__send_requestz.*?(&expiry=\d+).*?cCs.|j�}x |jj|�D]}|j|d�}qW|S)Nr�)�http_cookie�	expiry_re�findallr�)rwr�rZexpr9r9r:�_slice_session_cookiesz#KerbTransport._slice_session_cookiecCs�|dkrdSttdd�}ttdd�}tjdt|�|�t|t�sF|g}d}y4x.|D]&}tj|t	|t
j
j�d�}|dk	rRPqRWWn.tk
r�}ztj
d||�dSd}~XnX|dkr�dS|j|�}tjd||�yt||�Wntk
r�YnXdS)a�
        Given the contents of a Set-Cookie header scan the header and
        extract each cookie contained within until the session cookie
        is located. Examine the session cookie if the domain and path
        are specified, if not update the cookie with those values from
        the request URL. Then write the session cookie into the key
        store for the principal. If the cookie header is None or the
        session cookie is not present in the header no action is
        taken.

        Context Dependencies:

        The per thread context is expected to contain:
            principal
                The current pricipal the HTTP request was issued for.
            request_url
                The URL of the HTTP request.

        Nr6�request_urlzreceived Set-Cookie (%s)'%s')�	timestampz&unable to parse cookie header '%s': %sz$storing cookie '%s' for principal %s)r�rr�r�rIrLrJr�get_named_cookie_from_string�COOKIE_NAMErR�utcnowr3�errorrr;)rwZ
cookie_headerr6rr�Zcookier8�
cookie_stringr9r9r:�store_session_cookies:



z"KerbTransport.store_session_cookiecCs6tjr|jjd�}n|jjd�}|j|�tj||�S)Nz
Set-Cookie)r�r�r�Z
getheadersZget_allrr�r�)rwr�r�r9r9r:r�Ks

zKerbTransport.parse_response)N)T)r)r�r�r�r�r��RequirementFlag�mutual_authentication�out_of_sequence_detectionr�ror�r�r�r�r�r�rr��PY3r��re�compilerrrr�r9r9r9r:r�?s"


"	
?
<r�c@s&eZdZdZejjejjejjgZ	dS)�DelegatedKerbTransportzb
    Handles Kerberos Negotiation authentication and TGT delegation to an
    XML-RPC server.
    N)
r�r�r�r�r�rZdelegate_to_peerrrr�r9r9r9r:rTsrc@sZeZdZdZdZeZdZdZdd�Z	dd�Z
dd�Zdd	d
�Zdd�Z
d
d�Zdd�ZdS)�	RPCClientzq
    Forwarding backend plugin for XML-RPC client.

    Also see the `ipaserver.rpcserver.xmlserver` plugin.
    Nc

Cs�tjj|�\}}}}}}g}d|jj}	yt|	�}
Wntk
rLg}
YnXx4|
D],}t|j�j	d�}|j
dtj|�|f�qTW||kr�|j
|�|jd|�|S)zP
        Create a list of urls consisting of the available IPA servers.
        z_ldap._tcp.%s.r�zhttps://%s%sr)�urllib�parse�urlparser�Zdomainrrr5�target�rstripr�rZ
format_netlocr��insert)
rw�rpc_uriZ_schemeZ_netloc�pathZ_paramsZ_queryZ	_fragmentZserversr�ZanswersZanswer�serverr9r9r:�get_url_listks


zRPCClient.get_url_listcCs�y"t|�}|dkrdS|jd�}Wn,tk
rN}ztjd|�dSd}~XnXytj|ttjj	�d�}Wn,tk
r�}ztjd|�dSd}~XnX|S)a
        Retrieves the session cookie for the given principal from the
        persistent secure storage. Returns None if not found or unable
        to retrieve the session cookie for any reason, otherwise
        returns a Cookie object containing the session cookie.
        Nzutf-8z%Error reading client session data: %s)r	z7Error retrieving cookie from the persistent storage: %s)
r=r\r3r�r�rr
rrRr)rwr6rr8r�r9r9r:�*get_session_cookie_from_persistent_storage�s$
z4RPCClient.get_session_cookie_from_persistent_storagec
CsT|}ttdd�}|j|�}|dkr2tjd|�|Stjd||�y|j|�Wn�tjk
r�}z4tjd||�yt|�Wnt	k
r�YnX|Sd}~XnZtj
k
r�}ztjd|�|Sd}~Xn.t	k
�r�}ztjd|�|Sd}~XnXtjd|j��t
td	|j��tjj|�\}}}}	}
}|j}tjj||||	|
|f�}|S)
aE
        Attempt to load a session cookie for the current principal
        from the persistent secure storage. If the cookie is
        successfully loaded adjust the input url's to point to the
        session path and insert the session cookie into the per thread
        context for later insertion into the HTTP request. If the
        cookie is not successfully loaded then the original url is
        returned and the per thread context is not modified.

        Context Dependencies:

        The per thread context is expected to contain:
            principal
                The current pricipal the HTTP request was issued for.

        The per thread context will be updated with:
            session_cookie
                A cookie string to be inserted into the Cookie header
                of the HTPP request.

        r6NzFfailed to find session_cookie in persistent storage for principal '%s'zKfound session_cookie in persistent storage for principal '%s', cookie: '%s'z,deleting session data for principal '%s': %sz,not sending session cookie, URL mismatch: %sz-not sending session cookie, unknown error: %sz(setting session_cookie into context '%s'r�)r�rr"r�r�Zhttp_return_okrZExpiredr>r3ZURLMismatchr
r�setattrrrr�session_pathZ
urlunparse)
rw�urlZoriginal_urlr6r�r8�scheme�netlocrriZqueryZfragmentZsession_urlr9r9r:�apply_session_cookie�s@

zRPCClient.apply_session_cookiec(Cs�|dkr|jjj}|dkr$|jjj}|dkr6|jjj}|dkrH|jjj}|t_|j|j}y`t	|d�}t
tdd�}||kr�yttd�Wntk
r�YnXt
td|�|s�|j|�}Wntjtfk
r�YnX|j|�}	dd|d�}
�x�|	D�]�}�x�tdd�D�]�}|jd	��r,|�r&t}
nt}
nt}
|
|jd
|d�|
d<tjd
|�t
td|�|j|f|
�}t|	�dk�r||Sy�t
|d�}y|gi�Wnbtk
�r�}zDt|�}|jt k�r�t |j}||j!d��nt"|j|j!|d��WYdd}~XnX|Stj#k
�r�Yn�t$k
�r�}zjt%td��rr|j&dk�rrttd�yt'|�Wnt(k
�rlYnX�w|�s|�ntj)d||�PWYdd}~Xn>t(k
�r�}z |�s��ntj)d||�PWYdd}~XnX�qWq�Wt*t+d�dj,|	�d��dS)N)Zccache_namer6r�TzUTF-8)rhrar�r�zhttps://r�)r�r�r��	transportz	trying %srr�Zping)r�)�coder
r i�zConnection to %s failed with %szany of the configured serversz, )�urir
)-r%r�r��fallback�delegateZtls_ca_certrr��env_rpc_uri_keyr!r��delattr�AttributeErrorr#r(rr�r4r!�range�
startswithrr�r�r�r�r��server_proxy_classr�r'r�r�r	r�r
r�r-�hasattr�errcoder>r3�inforrr�)rwr�r�r-r.r�rr6Zstored_principalZurlsZproxy_kwr%Z_try_numZtransport_class�serverproxy�commandr8r
r9r9r:�create_connection�s�










zRPCClient.create_connectioncCs*tt|jd�}|dk	r&|jj}|j�dS)N)r�r�idr��_ServerProxy__transportr�)rwr�r9r9r:�destroy_connectionXszRPCClient.destroy_connectioncCs||�S)z"Call the command with given paramsr9)rwr9rir9r9r:�
_call_command^szRPCClient._call_commandc!Os.ttdd�}t|j|�}||g}d}�x�td|�D�]�}tjd|d||j|�y|j||�Stk
r�}	zTt	|	�}	tjd|	j
||	j�|	j
tkr�t|	j
}
|
|	jd��t
|	j
|	j|d	��WYdd}	~	Xq2tk
�r�}	z�ttd
d�}|o�|	jdk�r�ttd
�yttdd�}t|�Wn0tk
�rL}
ztjd
|
�WYdd}
~
XnX|jtjjd�|jj|jj|jj�}tt|jt||j��w2t||	j d��WYdd}	~	Xq2t!t"j#fk
�r�}	zt|t$|	�d��WYdd}	~	Xq2t%t&fk
�r}	zt't$|	�d��WYdd}	~	Xq2Xq2Wt|t(d�d��dS)a�
        Forward call to command named ``name`` over XML-RPC.

        This method will encode and forward an XML-RPC request, and will then
        decode and return the corresponding XML-RPC response.

        :param command: The name of the command being forwarded.
        :param args: Positional arguments to pass to remote command.
        :param kw: Keyword arguments to pass to remote command.
        rNr)rz+[try %d]: Forwarding '%s' to %s server '%s'r�z"Caught fault %d from server %s: %s)r�)r+r
r r�i�r6z1Error trying to remove persisent session data: %sZ
KRB5CCNAME)r,r
)r
z.Exceeded number of tries to forward a request.))r�rr�r2r�r�r�r>r'r�r�r�r	r
r-r6r0r>r3r:�os�environr�r�r�r-r.r#r;rZ
disconnectr�errmsgr�socketr
r5�
OverflowErrorrerr)rwr�r��kwr r9riZ	max_triesZtry_numr8r
r�r6Ze2r8r9r9r:�forwarddsX




 $zRPCClient.forward)NNNNN)r�r�r�r�r$r+r4r�r/r!r"r(r:r=r>rEr9r9r9r:r^s D
mrc@s$eZdZdZeZdZdZdd�ZdS)�	xmlclientz/ipa/session/xmlZxmlZ
xmlrpc_uricCs*|djdt�}t||�}||�}t|�S)Nr�rB)r�r$r?r`)rwr9rirBr�r9r9r:r>�s
zxmlclient._call_commandN)	r�r�r�r$r+r4r�r/r>r9r9r9r:rF�s
rFc@s$eZdZdd�Zdd�Zdd�ZdS)�JSONServerProxycCsDtjj|�}|jdkrtd��|j|_|j|_||_	||_
||_dS)N�http�httpszunsupported XML-RPC protocol)rHrI)rrZurlsplitr&�IOErrorr'�_JSONServerProxy__hostr�_JSONServerProxy__handler�_JSONServerProxy__transport�_JSONServerProxy__verboser<)rwr,r*rar�rhZ	split_urir9r9r:ro�s
zJSONServerProxy.__init__cCsJ|jdk}t|�|dd�}|djdt�}t|||d�}|rHtjd|�|jj|j	|j
|jd�|jd	kd
�}|r�tjdtj
tj|�dd
d��yt|�}Wn0tk
r�}ztt|�d��WYdd}~XnX|jd�}|�rByt|d}	Wn2tk
�rt|jd�|jd�|j	d��Yn$X|jdi�}
|d|
d<|	f|
��|dS)N�r)r�rir;r�rB)r�zRequest: %szutf-8�)r�zResponse: %sTr�)r�r�)r
r
r+r�)r+r
r r7r�)rNrPr�r$r�r�r7rMZrequestrKrLr�r�r)r*r�r4r
r5r	�KeyErrorr
)rwr�r�Z
print_jsonZpayloadrBr�r8r
Zerror_classrDr9r9r:Z	__request�sF
 

zJSONServerProxy.__requestcs��fdd�}|S)Ncs�j�|�S)N)�_JSONServerProxy__request)r�)r�rwr9r:�_call�sz*JSONServerProxy.__getattr__.<locals>._callr9)rwr�rSr9)r�rwr:�__getattr__�szJSONServerProxy.__getattr__N)r�r�r�rorRrTr9r9r9r:rG�s0rGc@seZdZdZeZdZdZdS)�
jsonclientz/ipa/session/jsonr�Zjsonrpc_uriN)r�r�r�r$rGr4r�r/r9r9r9r:rUsrU)r_)NFr_)F)r_)r_)yr�Z
__future__rZdecimalrrRZloggingr?r�rWr�rrBrrZsslrZcryptographyrrUr�Z
dns.exceptionrr�Zipalib.backendrZipalib.constantsrZ
ipalib.errorsr	r
rrr
ZipalibrrZipalib.requestrrZipalib.x509rrZZ	ipapythonrrZipapython.cookierZipapython.dnsutilrrZipalib.textrZipalib.utilrZipalib.krb_utilsrrrrrrr r!Zipapython.dnr"Zipapython.kerberosr#Zipalib.capabilitiesr$r%Z	xmlrpclibr&r'r(r)r*r+r,r-r.r/�ImportErrorZ
xmlrpc.clientrZhttp.clientr0Zhttplibr1r5rPZ	getLoggerr�r�rr2r;r=r>r?r`rjrMrkr�r�rJr�r�r�r�r�r�r�r�r�rrrFrGrUr9r9r9r:�<module>s�(46



A
+
z



O
H