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: //usr/lib/python3.6/site-packages/ipalib/install/__pycache__/kinit.cpython-36.opt-1.pyc
3

�
�ix�@s�ddlmZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZddl
mZeje�ZdZdZd	Zd
edd�deZd
eZeje�Zeje�Zdd�Zddd�Zddd�Zddd�Zddd�ZdS)�)�absolute_importN)�paths)�run)�PATTERN_GROUPUSER_NAME)�validate_hostnamel�:�-l:�-z@?([a-zA-Z0-9.-]*)$�(��)z!([a-zA-Z0-9.-]+)/([a-zA-Z0-9.-]+)cCs�t|t�std��d|kr,d|kr,td��nrtj|�}|dkr�tj|�}|dkrZtd��nD|d}yt|�Wn.tk
r�}ztt|���WYdd}~XnXdS)NzInvalid principal: not a string�/� zInvalid principal: bad spacingzInvalid principal: cannot parse�)�
isinstance�str�RuntimeError�user_pattern�match�service_patternr�
ValueError)�	principalrZhostname�e�r�/usr/lib/python3.6/kinit.py�validate_principal#s




rcCsRt|�tth}tjd||�tjd|��x td|d�D�]}tjjd�}|dk	rb|tjd<ntjj	dd�z�y<t
j|t
jj
�}||d�}	t
j||	dd�}
tjd	||�|
St
jjk
�r}zL|j|kr҂tjd
|||�||kr�tjd|��tjd�tjd
�WYdd}~XnXWd|dk	�r8|tjd<ntjj	dd�XdSWdS)z�
    Given a ccache_path, keytab file and a principal kinit as that user.

    The optional parameter 'attempts' specifies how many times the credential
    initialization should be attempted in case of non-responsive KDC.
    z)Initializing principal %s using keytab %szusing ccache %sr�KRB5_CONFIGN)ZccacheZ
client_keytabZinitiate)�name�storeZusagezAttempt %d/%d: successzAttempt %d/%d: failed: %sz'Maximum number of attempts (%d) reachedz#Waiting 5 seconds before next retry�)r�KRB5KDC_ERR_SVC_UNAVAILABLE�KRB5_KDC_UNREACH�logger�debug�range�os�environ�get�pop�gssapi�NameZNameTypeZkerberos_principalZCredentials�
exceptionsZGSSErrorZmin_code�timeZsleep)rZkeytab�ccache_name�configZattemptsZerrors_to_retryZattemptZ
old_configrrZcredrrrr�kinit_keytab;s@

 
r,FcCs�t|�tjd|�tjd|g}|dk	rBtjd|�|jd|g�|rT|jd|g�|rltjd�|jd�|r�tjd	�|jd
�|jd|g�dd
i}	|dk	r�||	d<t|||	ddd�}
|
jr�t	|
j
��dS)z�
    perform interactive kinit as principal using password. If using FAST for
    web-based authentication, use armor_ccache_path to specify http service
    ccache.
    z(Initializing principal %s using passwordz-cNz&Using armor ccache %s for FAST webauthz-Tz-lz%Requesting principal canonicalizationz-CzUsing enterprise principalz-Ez--�LC_ALL�CrFT)�stdin�env�
raiseonerr�
capture_error)rrr r�KINIT�extend�appendr�
returncoderZerror_output)rZpasswordr*r+Zarmor_ccache_nameZcanonicalizeZ
enterpriseZlifetime�argsr0�resultrrr�kinit_passwordhs.




r9cCs^tjd�ddi}tjdd|g}|dk	rJx |D]}|jddj|�g�q.Wt||d	d	d
�dS)a}
    perform anonymous pkinit to obtain anonymous ticket to be used as armor
    for FAST.

    :param ccache_name: location of the armor ccache
    :param pkinit_anchor: if not None, the location of PKINIT anchor file to
        use. Otherwise the value from Kerberos client library configuration is
        used

    :raises: CalledProcessError if the anonymous PKINIT fails
    zInitializing anonymous ccacher-r.z-nz-cNz-XzX509_anchors=FILE:{}T)r0r1r2)rr rr3r4�formatr)r*�pkinit_anchorsr0r7�
pkinit_anchorrrr�kinit_armor�s

r=cCs�t|�tjd||�ddi}|dk	r.||d<tjd|g}|dk	rdx |D]}|jdd|��g�qHW|jdd	|��g�|jd
|g�t||dddd
�dS)aqPerform kinit with X.509 identity (PKINIT)

    :param principal: principal name
    :param user_identity: X509_user_identity paramemter
    :param ccache_name: location of ccache
    :param config: path to krb5.conf (default: default location)
    :param pkinit_anchor: if not None, the PKINIT anchors to use. Otherwise
        the value from Kerberos client library configuration is used. Entries
        must be prefixed with FILE: or DIR:

    user identity example:
       FILE:filename[,keyfilename]
       PKCS12:filename
       PKCS11:...
       DIR:directoryname

    :raises: CalledProcessError if PKINIT fails
    z)Initializing principal %s using PKINIT %sr-r.Nrz-cz-Xz
X509_anchors=zX509_user_identity=z--�
T)r0r/r1r2)rrr rr3r4r)rZ
user_identityr*r+r;r0r7r<rrr�kinit_pkinit�s

r?���)Nr)NNFFN)N)NN)Z
__future__rZloggingr"�rer)r&Zipaplatform.pathsrZipapython.ipautilrZipalib.constantsrZipalib.utilrZ	getLogger�__name__rrrZ
PATTERN_REALMZPATTERN_PRINCIPALZPATTERN_SERVICE�compilerrrr,r9r=r?rrrr�<module>s2



-
&