a
    )&i                     @   s   d dl Z 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lmZ e jd d	 d
ejd< dZdZG dd deZedkrdZdZd dlZe  dS )    N)SCOPE_SUBTREE)NTSTATUSErrorgensec)AuthContext)security)
ndr_unpack) NT_STATUS_NO_IMPERSONATION_TOKEN)KDCBaseTestz
bin/python1ZPYTHONUNBUFFEREDFc                   @   s2   e Zd ZdZdd Zdd Zdd Zdd
dZdS )CcacheTestszbTest for authentication using Kerberos credentials stored in a
       credentials cache file.
    c                 C   s   |    d S )N_run_ccache_testself r   >/usr/lib/python3/dist-packages/samba/tests/krb5/test_ccache.pytest_ccache.   s    zCcacheTests.test_ccachec                 C   s   | j dd d S )NT)renamer   r   r   r   r   test_ccache_rename1   s    zCcacheTests.test_ccache_renamec                 C   s   | j dddd d S )NFT)include_pacexpect_anonallow_errorr   r   r   r   r   test_ccache_no_pac4   s    zCcacheTests.test_ccache_no_pacFTc               
   C   sH  d}d}|   }| j| jjdd}| }	| j||| jjd||f d\}
}| j||
|d\}}| t	j
|j |jtd|	 d	gd
}| dt| ttj|d d	 d }|r|  }t| }t|tjd|d< || |  }|dd i }||d< ||d< tj|}|| | tj! |"d t#||g d}tj$||}||
 |"d d}d}d}|r|s|st%d |&|\}}|svt%d |&|\}}qvz|' }W nL t(y } z2|s| )  |j*\}}| t+| W Y d }~d S d }~0 0 |j,}|j-}| .t|d | ||d  d S )NZ	ccachemacZhostF)account_typeZ	use_cachez%s/%s)r   Zspn)Zpacz(sAMAccountName=%s)Z	objectSid)ZscopeZ
expressionattrs   r   ZsAMAccountNamezserver rolez"active directory domain controllerlp_ctxZtarget_hostnameZGSSAPI)r   ldbmethods    zrunning client gensec_updatezrunning server gensec_update)/Z	get_samdbZget_cached_credsZAccountTypeZUSERZget_usernameZcreate_accountZCOMPUTERZcreate_ccache_with_userZ
addCleanuposremovenamesearchr   ZassertEquallenr   r   Zdom_sidZget_new_usernamer   ZMessageZget_dnZMessageElementZFLAG_MOD_REPLACEZmodifyZget_lpsetr   ZSecurityZstart_clientZset_credentialsZwant_featureZFEATURE_SEALZstart_mech_by_sasl_namer   Zstart_serverprintupdateZsession_infor   Zfailargsr   Zsecurity_tokenZsidsZassertGreater) r   r   r   r   r   Z	mach_nameZserviceZsamdbZuser_credentialsZ	user_nameZmach_credentials_ZcredsZ	cachefileZldb_resZsidnew_namemsgZlpZsettingsZgensec_clientZauth_contextZgensec_serverZclient_finishedZserver_finishedZserver_to_clientZclient_to_serverZsessioneenumtokenZ
token_sidsr   r   r   r   8   s    







zCcacheTests._run_ccache_testN)FTFF)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r   )   s     r   __main__)sysr    r   r   Zsambar   r   Z
samba.authr   Zsamba.dcerpcr   Z	samba.ndrr   Zsamba.ntstatusr   Zsamba.tests.krb5.kdc_base_testr	   pathinsertenvironZglobal_asn1_printZglobal_hexdumpr   r/   Zunittestmainr   r   r   r   <module>   s(   
 