File: //usr/lib/python3.9/site-packages/ipalib/__pycache__/krb_utils.cpython-39.pyc
a
}�f_ � @ s� d dl Z d dlZd dlZd dlmZ dZdZdZdZdZ dZ
d Zd
ZdZ
dZd
Zee ZdZdZe�d�Zdd� Zdd� Zdd� Zdd� Zdd� Zd!dd�Zd"dd�Zd#dd �ZdS )$� N)�errorsl �:�- l �:�- l :�- l :�- l :�- l �:�- l �:�- l �:�- l �:�- l :�- i i, z%m/%d/%y %H:%M:%Sz^((\w+):)?(.+)c C sP t �| �}|r@|�d�}|�d�}|du r0d}n|�� }||fS td| ��dS )a�
Given a Kerberos ccache name parse it into it's scheme and
location components. Currently valid values for the scheme
are:
* FILE
* MEMORY
The scheme is always returned as upper case. If the scheme
does not exist it defaults to FILE.
:parameters:
ccache_name
The name of the Kerberos ccache.
:returns:
A two-tuple of (scheme, ccache)
� � N�FILEzInvalid ccache name = "%s")�ccache_name_re�search�group�upper�
ValueError)�ccache_name�match�scheme�location� r �4/usr/lib/python3.9/site-packages/ipalib/krb_utils.py�krb5_parse_ccache6 s
r c C s d| � � |f S )Nz%s:%s)r )r
�namer r r �krb5_unparse_ccacheU s r c C s d| ||f S )a�
Given a Kerberos service principal name, the host where the
service is running and a Kerberos realm return the Kerberos V5
service principal name.
:parameters:
service
Service principal name.
host
The DNS name of the host where the service is located.
realm
The Kerberos realm the service exists in.
:returns:
Kerberos V5 service principal name.
z%s/%s@%sr )Zservice�host�realmr r r �"krb5_format_service_principal_nameY s r c C s t d| | �S )z�
Given a Kerberos realm return the Kerberos V5 TGT name.
:parameters:
realm
The Kerberos realm the TGT exists in.
:returns:
Kerberos V5 TGT name.
Zkrbtgt)r )r r r r �krb5_format_tgt_principal_namel s
r c C s t �tt �| ��S )z�
Given a UNIX timestamp format it into a string in the same
manner the MIT Kerberos library does. Kerberos timestamps are
always in local time.
:parameters:
timestamp
Unix timestamp
:returns:
formated string
)�time�strftime�
krb5_time_fmt� localtime)Z timestampr r r �krb5_format_timex s r c C s d}|rd|i}t jd| |d�S )a�
Obtains GSSAPI credentials with given principal name from ccache. When no
principal name specified, it retrieves the default one for given
credentials cache.
:parameters:
name
gssapi.Name object specifying principal or None for the default
ccache_name
string specifying Kerberos credentials cache name or None for the
default
:returns:
gssapi.Credentials object
NZccacheZinitiate)�usager �store)�gssapiZCredentials)r r r r r r �get_credentials� s r c
C sT zt | d�}t|j�W S tjjyN } ztjt|�d��W Y d}~n
d}~0 0 dS )aY
Gets default principal name from given credentials cache.
:parameters:
ccache_name
string specifying Kerberos credentials cache name or None for the
default
:returns:
Default principal name as string
:raises:
errors.CCacheError if the principal cannot be retrieved from given
ccache
)r )�messageN)r �strr r �
exceptions�GSSErrorr ZCCacheError)r �creds�er r r �
get_principal� s
r'