a
    )&iK                     @   s   d dl Z d dlZd dl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 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)security)
ndr_unpack) NT_STATUS_NO_IMPERSONATION_TOKEN)libsmb_samba_internal)param)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 )SmbTestszfTest for SMB authentication using Kerberos credentials stored in a
       credentials cache file.
    c                 C   s   |    d S )N_run_smb_testself r   ;/usr/lib/python3/dist-packages/samba/tests/krb5/test_smb.pytest_smb/   s    zSmbTests.test_smbc                 C   s   | j dd d S )NT)renamer   r   r   r   r   test_smb_rename2   s    zSmbTests.test_smb_renamec                 C   s   | j ddd d S )NFT)include_pacexpect_errorr   r   r   r   r   test_smb_no_pac5   s    zSmbTests.test_smb_no_pacFTc              
   C   s  |   }| }d}d}| j| jjd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< || t	jdd}| t	jjd| d|j t	jd< t }||   j! |d}| |j"d| |"dd |d}| |j"d| |"dd zt#j$||||d}W nL t%y } z2|s| &  |j'\}}| t(| W Y d }~d S d }~0 0 | )| |* \}}}}}| ||d
  d S )NZcifstmpF)Zaccount_typeZ	use_cache)Zpacz(sAMAccountName=%s)Z	objectSid)ZscopeZ
expressionattrs   r   ZsAMAccountNameZ
KRB5CCNAME zFILE:zclient min protocolZNT1zclient max protocol)Zlpcreds)+Z	get_samdbZhost_dns_nameZget_cached_credsZAccountTypeZUSERZget_usernameZget_dc_credsZcreate_ccache_with_userZ
addCleanuposremovenamesearchr   ZassertEquallenr   r   Zdom_sidZget_new_usernameldbZMessageZget_dnZMessageElementZFLAG_MOD_REPLACEZmodifyenvironget__setitem__s3paramZget_contextloadZget_lpZ
configfilesetlibsmbZConnr   Zfailargsr   ZassertFalseZposix_whoami)r   r   r   r   ZsamdbZ	mach_nameZserviceZshareZuser_credentialsZ	user_nameZmach_credentialsr   Z	cachefileZldb_resZsidnew_namemsgZkrb5_ccnameZs3_lpZmin_protocolZmax_protocolZconneenum_ZuidgidZgidsZsidsZguestr   r   r   r   9   sl    





zSmbTests._run_smb_testN)FTF)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r   *   s     r   __main__)sysr   r"   r   Zsambar   Zsamba.dcerpcr   Z	samba.ndrr   Zsamba.ntstatusr   Zsamba.samba3r   r)   r   r&   Zsamba.tests.krb5.kdc_base_testr	   pathinsertr#   Zglobal_asn1_printZglobal_hexdumpr   r1   Zunittestmainr   r   r   r   <module>   s(   
k