a
    Wa                     @   s   d Z ddlZddlZddlm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mZ dd
lmZ ddlmZ ddlmZmZ G dd dejjjZdS )a0  
    Tests that exercise the auth logging for a successful netlogon attempt

    NOTE: As the netlogon authentication is performed once per session,
          there is only one test in this routine.  If another test is added
          only the test executed first will generate the netlogon auth message
    N)SamDB)Credentials)netlogon)AS_SYSTEM_MAGIC_PATH_TOKEN)system_session)delete_force)UF_WORKSTATION_TRUST_ACCOUNTUF_PASSWD_NOTREQD)SEC_CHAN_WKSTA)	text_type)EVT_ID_SUCCESSFUL_LOGONEVT_LOGON_NETWORKc                       s@   e Zd Z fddZ fddZdd Zdd Zd	d
 Z  ZS )AuthLogTestsNetLogonc                    s   t t|   tj | _t | _t	| j| jd| _
tjd | _d| _d| _t| _| j
 | _d| j| jf | _td| j d d}| j
| jdd	| j tttB |d
 d S )N)Zsession_infolpZDOMAINZNetLogonGoodZ
abcdefghijzcn=%s,cn=users,%s"z	utf-16-leZcomputerz%s$)dnZobjectclassZsAMAccountNameZuserAccountControlZ
unicodePwd)superr   setUpsambatestsZenv_loadparmr   r   Zsessionr   ldbosenvironZdomainnetbios_namemachinepassr   ZremoteAddressZ	domain_dnZbase_dnr   r   encodeaddstrr   r	   )selfZutf16pw	__class__ ?/usr/lib/python3/dist-packages/samba/tests/auth_log_netlogon.pyr   /   s*    
zAuthLogTestsNetLogon.setUpc                    s    t t|   t| j| j d S )N)r   r   tearDownr   r   r   r   r   r!   r"   r#   G   s    zAuthLogTestsNetLogon.tearDownc                 C   s   dd }|rd| }nd}t  }||   |t || j || jd  t		d| |  |}| 
||}|| d S )Nc                 S   s<   | d dko:| d d dko:| d d dko:| d d dkS )	NtypeAuthorizationserviceDescriptionDCE/RPCauthTypeZschanneltransportProtectionSEALr!   )msgr!   r!   r"   isLastExpectedMessageM   s    zBAuthLogTestsNetLogon._test_netlogon.<locals>.isLastExpectedMessagez[schannel,%s]z
[schannel]$z
ncalrpc:%s)r   ZguessZget_loadparmZset_secure_channel_typer
   Zset_passwordr   Zset_usernamer   r   ZwaitForMessages)r   ZbindingZcheckFunctionr-   Zmachine_credsZnetlogon_connmessagesr!   r!   r"   _test_netlogonK   s    


z#AuthLogTestsNetLogon._test_netlogonc                 C   s  d}|  |t|d |d }|  d|d  |  d|d d  |  d|d d	  |  d
|d d  | | |d d  |d }|  d|d  |  d|d d  |  d|d d  |  d|d d  |  d|d d  |  t|d d  |  t|d d  d S )N   z/Did not receive the expected number of messagesr   r&   r%   r(   r'   Zncalrpcr)   ZNONEr*   Z	sessionId   ZAuthenticationZNETLOGONZServerAuthenticateZauthDescriptionZNT_STATUS_OKZstatuszHMAC-SHA256ZpasswordTypeZeventIdZ	logonType)ZassertEquallenZ
assertTrueZis_guidr   r   )r   r/   Zexpected_messagesr,   r!   r!   r"   netlogon_checkf   sB    






z#AuthLogTestsNetLogon.netlogon_checkc                 C   s   |  d| j d S )Nr+   )r0   r4   r$   r!   r!   r"   test_netlogon   s    z"AuthLogTestsNetLogon.test_netlogon)	__name__
__module____qualname__r   r#   r0   r4   r5   __classcell__r!   r!   r   r"   r   -   s
    r   )__doc__Zsamba.testsr   r   Zsamba.samdbr   Zsamba.tests.auth_log_baseZsamba.credentialsr   Zsamba.dcerpcr   Zsamba.dcerpc.dcerpcr   Z
samba.authr   r   Z
samba.dsdbr   r	   Zsamba.dcerpc.miscr
   Zsamba.compatr   Zsamba.dcerpc.windows_event_idsr   r   r   Zauth_log_baseZAuthLogTestBaser   r!   r!   r!   r"   <module>   s   