a
    )&i                     @   s   d dl Z d dlZd dlZd dlmZmZ d dlmZ d dlm	Z	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)NTSTATUSErrorcredentials)lsa)NT_STATUS_ACCESS_DENIED NT_STATUS_NO_IMPERSONATION_TOKEN)KDCBaseTestz
bin/python1ZPYTHONUNBUFFEREDFc                   @   s:   e Zd ZdZdd Zdd Zdd Zdd
dZdd ZdS )RpcTestszfTest for RPC authentication using Kerberos credentials stored in a
       credentials cache file.
    c                 C   s   |    d S )N_run_rpc_testself r   ;/usr/lib/python3/dist-packages/samba/tests/krb5/test_rpc.pytest_rpc.   s    zRpcTests.test_rpcc                 C   s   | j dd d S )NT)renamer
   r   r   r   r   test_rpc_rename1   s    zRpcTests.test_rpc_renamec                 C   s   | j dddd d S )NFT)include_pacexpect_anonallow_errorr
   r   r   r   r   test_rpc_no_pac4   s    zRpcTests.test_rpc_no_pacFTc              
   C   s<  |   }| j}d}| j| jjdd}| }	|  }
| j||
|||d\}}| t	j
|j |r|  }t| }t|tjd|d< || d| }zt||  |}W nN ty  } z4|s|   |j\}}| |tth W Y d }~d S d }~0 0 |d d d \}}|r*| |	|j n| |	|j d S )NZcifsF)Zaccount_typeZ	use_cache)ZpacZsAMAccountNamencacn_np:%s[\pipe\lsarpc]) Z	get_samdbhostZget_cached_credsZAccountTypeZUSERZget_usernameZget_server_credsZcreate_ccache_with_userZ
addCleanuposremovenameZget_new_usernameldbZMessageZget_dnZMessageElementZFLAG_MOD_REPLACEZmodifyr   lsarpcget_lpr   ZfailargsZassertInr   r   GetUserNameZassertNotEqualstringassertEqual)r   r   r   r   r   Zsamdb	mach_nameZserviceZuser_credentialsZ	user_nameZmach_credentialsZcredsZ	cachefilenew_namemsgbinding_strconneenum_account_namer   r   r   r   8   sN    


zRpcTests._run_rpc_testc                 C   sX   | j }t }|  d| }t||  |}|d d d \}}| d|j	
  d S )Nr   zANONYMOUS LOGON)r   r   ZCredentialsZset_anonymousr   r   r   r    r"   r!   upper)r   r#   Z
anon_credsr&   r'   r+   r*   r   r   r   test_rpc_anonymousx   s    zRpcTests.test_rpc_anonymousN)FTFF)	__name__
__module____qualname____doc__r   r   r   r   r-   r   r   r   r   r	   )   s     
@r	   __main__)sysr   r   Zsambar   r   Zsamba.dcerpcr   Zsamba.ntstatusr   r   Zsamba.tests.krb5.kdc_base_testr   pathinsertenvironZglobal_asn1_printZglobal_hexdumpr	   r.   Zunittestmainr   r   r   r   <module>   s    
]