o
    j	                     @   s   d dl Z d dlZd dlmZ d dlmZmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ ddd	Zd
d Zedkr@e  dS dS )    N)logger)KerberosClientFactorykerberos_url_help_epilog)KerberosSecretType)KerberosSPN)KerberosCredential)Kirbic                    s^  t | }| }t|}|jtjkr2t	d |
 I d H  t	d ||I d H \}}}	nQt	d |jj D ]E}
z*td|
   tj|
 dd}||}||I d H \}}}	td W  n ty } zt	d|  W Y d }~q=d }~ww |d ur|j| td	|  t||}
tt|
 |d ur|
| td
 d S )NzGetting TGTzGetting DMSAzGetting TGS via TGT from CCACHEzTrying to get SPN with %shex)encodingzSucsess!z-This ticket is not usable it seems Reason: %szTicket stored in ccache file %szDone!)r   from_url
get_clientr   from_upnsecret_typer   CCACHEr   debugget_TGTdmsa
credentialccacheget_all_tgt_kirbisinfoget_usernamer   
from_kirbito_hexget_client_newcred	Exceptionto_fileprintr   from_ticketdatastrlogging)kerberos_url
targetuser	kirbifile
ccachefilecuclienttarget_usertgsencTGSRepPartkeykirbi
ccred_teste r.   /root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/minikerberos/examples/getDmsa.pydMSA   s>   







r0   c                  C   s   dd l } | jd| jtd}|jddd |jddd |jd	d
ddd |jddd |jddd | }|jdkrBtt	j
 n|jdkrNtt	j ntd tt|j|j|j|j d S )Nr   z0Gets an S4U2self ticket impersonating given user)descriptionformatter_classepilogz--kirbizPkirbi file to store the TGS ticket in, otherwise kirbi will be printed to stdout)helpz--ccachez&ccache file to store the TGT ticket inz-vz	--verbosecount)actiondefaultr!   z3Machine account credentials in kerberos URL format.r"       )argparseArgumentParserRawDescriptionHelpFormatterr   add_argument
parse_argsverboser   setLevelr    WARNINGINFOasynciorunr0   r!   r"   r+   r   )r:   parserargsr.   r.   r/   main/   s   


 rG   __main__)NN)r    rC   minikerberosr   minikerberos.common.factoryr   r   minikerberos.common.constantsr   minikerberos.common.spnr   minikerberos.common.credsr   minikerberos.common.kirbir   r0   rG   __name__r.   r.   r.   r/   <module>   s    
$
