
    b                         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mZ  G 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)EVT_ID_SUCCESSFUL_LOGONEVT_LOGON_NETWORKc                   :     e Zd Z fdZ fdZd Zd Zd Z xZS )AuthLogTestsNetLogonc           	         t          t          |                                            t          j                                        | _        t                      | _        t          | j        | j                  | _
        t          j        d         | _        d| _        d| _        t           | _        | j
                                        | _        d| j        d| j        | _        d| j        z   dz                       d          }| j
                            | j        d	d
| j        z  t/          t0          t2          z            |d           d S )N)session_infolpDOMAINNetLogonGood
abcdefghijzcn=z
,cn=users,"z	utf-16-lecomputerz%s$)dnobjectclasssAMAccountNameuserAccountControl
unicodePwd)superr   setUpsambatestsenv_loadparmr   r   sessionr   ldbosenvirondomainnetbios_namemachinepassr   remoteAddress	domain_dnbase_dnr   encodeaddstrr	   r
   )selfutf16pw	__class__s     ?/usr/lib/python3/dist-packages/samba/tests/auth_log_netlogon.pyr   zAuthLogTestsNetLogon.setUp.   s.   "D))//111+**,,%''w   j**'7x))++*.*;*;*;T\\J))C/77DD'%#d&7703DDEE!# # 	$ 	$ 	$ 	$ 	$    c                     t          t          |                                            t          | j        | j                   d S )N)r   r   tearDownr   r#   r   )r/   r1   s    r2   r5   zAuthLogTestsNetLogon.tearDownF   s:    "D))22444TXtw'''''r3   c                    d }|rd|z  }nd}t                      }|                    |                                            |                    t                     |                    | j                   |                    | j        dz              t          j	        d|z  |                                 |          }| 
                    ||          } ||           d S )Nc                     | d         dk    o5| d         d         dk    o#| d         d         dk    o| d         d         dk    S )	NtypeAuthorizationserviceDescriptionDCE/RPCauthTypeschanneltransportProtectionSEAL )msgs    r2   isLastExpectedMessagezBAuthLogTestsNetLogon._test_netlogon.<locals>.isLastExpectedMessageL   s`    F. FO$%9:iGFO$Z0J>F O$%:;vE	Gr3   z[schannel,%s]z
[schannel]$z
ncalrpc:%s)r   guessget_loadparmset_secure_channel_typer   set_passwordr(   set_usernamer'   r   waitForMessages)r/   bindingcheckFunctionrB   machine_credsnetlogon_connmessagess          r2   _test_netlogonz#AuthLogTestsNetLogon._test_netlogonJ   s    	G 	G 	G  	#%/GG"G#D--//000--n===""4#3444""4#4s#:;;; ),*@*.*;*;*=*=*79 9 ''(=}MMhr3   c                    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   r9   r8   r;   r:   ncalrpcr<   NONEr>   	sessionId   AuthenticationNETLOGONServerAuthenticateauthDescriptionNT_STATUS_OKstatuszHMAC-SHA256passwordTypeeventId	logonType)assertEquallen
assertTrueis_guidr   r   )r/   rN   expected_messagesrA   s       r2   netlogon_checkz#AuthLogTestsNetLogon.netlogon_checke   s   *h--K	M 	M 	M
 qk#f+666o./CD	F 	F 	FC$8$DEEE_!56K!LMMMS%9+%FGGHHH qk)3v;777./0DE	G 	G 	G-./0AB	D 	D 	D./9	; 	; 	;./?	A 	A 	A0./	:	< 	< 	<*./<	> 	> 	> 	> 	>r3   c                 <    |                      d| j                   d S )Nr?   )rO   rd   )r/   s    r2   test_netlogonz"AuthLogTestsNetLogon.test_netlogon   s!    FD$788888r3   )	__name__
__module____qualname__r   r5   rO   rd   rf   __classcell__)r1   s   @r2   r   r   ,   s        $ $ $ $ $0( ( ( ( (     6> > >@9 9 9 9 9 9 9r3   r   )__doc__samba.testsr   r$   samba.samdbr   samba.tests.auth_log_basesamba.credentialsr   samba.dcerpcr   samba.dcerpc.dcerpcr   
samba.authr   r   
samba.dsdbr	   r
   samba.dcerpc.miscr   samba.dcerpc.windows_event_idsr   r   r    auth_log_baseAuthLogTestBaser   r@   r3   r2   <module>rx      s6  &      				               ) ) ) ) ) ) ! ! ! ! ! ! : : : : : : % % % % % % $ $ $ $ $ $ F F F F F F F F , , , , , ,       Z9 Z9 Z9 Z9 Z95;4D Z9 Z9 Z9 Z9 Z9r3   