a
    [ÔJa1  ã                   @   sp   d Z ddlmZ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 ddlZG d	d
„ d
eƒZdS )zTests for samba.dcerpc.sam.é    )ÚsamrÚsecurityÚlsa)ÚCredentials)ÚTestCase)Údom_sid)ÚNTSTATUSError)ÚNT_STATUS_ACCESS_DENIEDNc                   @   sD   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dS )ÚLsaTestsc                 C   s   |   ¡ | _tj d¡| _d S )NZSERVER)Zget_loadparmÚlpÚsambaZtestsZenv_get_var_valueÚserver)Úself© r   ú8/usr/lib/python3/dist-packages/samba/tests/dcerpc/lsa.pyÚsetUp!   s    
zLsaTests.setUpc                 C   s:  t ƒ }| | j¡ | ¡  t d| j | j|¡}t ¡ }t ¡ }t	dƒ}||_
|g|_d|_t ¡ }tj}d}tj}	tj}
| |||||	|
¡\}}}|  |d¡ |  |jd¡ |  |jd jjd¡ | |||||	|
¡\}}}|  |d¡ |  |jd¡ |  |jd jjd¡ | |||||	|
¡ | |||||	|
¡ d S ©Núncacn_ip_tcp:%s[schannel,seal]úS-1-5-7é   r   zANONYMOUS LOGON©r   Úguessr   Úset_machine_accountr   Úlsarpcr   ÚSidArrayÚSidPtrr   ÚsidÚsidsÚnum_sidsÚTransNameArray2ÚLSA_LOOKUP_NAMES_ALLÚ'LSA_LOOKUP_OPTION_SEARCH_ISOLATED_NAMESÚLSA_CLIENT_REVISION_2ÚLookupSids3ÚassertEqualÚcountÚnamesÚnameÚstring)r   Úmachine_credsÚcr   r   Úxr&   Úlevelr%   Úlookup_optionsÚclient_revisionÚdomainsZdomains2Znames2Zcount2r   r   r   Útest_lsa_LookupSids3_multiple%   sB    ýÿÿz&LsaTests.test_lsa_LookupSids3_multiplec                 C   s(  t ƒ }| | j¡ | ¡  t d| j | j|¡}t ¡ }t ¡ }t	dƒ}||_
|g|_d|_t ¡ }tj}d}tj}	tj}
| |||||	|
¡\}}}|  |d¡ |  |jd¡ |  |jd jjd¡ t d| j | j|¡}| |||||	|
¡\}}}|  |d¡ |  |jd¡ |  |jd jjd¡ d S r   r   )r   r)   r*   r   r   r+   r&   r,   r%   r-   r.   r/   r   r   r   Ú#test_lsa_LookupSids3_multiple_connsN   s`    ýû
ÿýû
ÿz,LsaTests.test_lsa_LookupSids3_multiple_connsc                 C   s   t ƒ }| | j¡ | ¡  t d| j | j|¡}| ddd¡\}}t d| j | j|¡}t ¡ }|g}tj	}d}	tj
}
tj}| ||||	|
|¡\}}}	| ||||	|
|¡\}}}	|  |	d¡ |  |jd¡ t ¡ }t ¡ }|jd j|_t ¡ }|g|_d|_tj	}d}	d}
tj}| ||||	|
|¡\}}}	|  |	d¡ |  |jd¡ |  |jd jj|j¡ t ¡ }|g}tj	}d}	tj
}
tj}| ||||	|
|¡\}}}	dS )ú™
        Test by going back and forward between real DB lookups
        name->sid->name to ensure the sam.ldb handle is fine once
        shared
        úncacn_np:%s[seal]Nr   r   r   )r   r   r   r   r   r   r   ÚGetUserNameÚTransSidArray3r    r!   r"   ÚLookupNames4r$   r%   r   r   r   r   r   r   r#   r&   r'   r(   )r   r)   Úc_normalÚusernameÚdomainr*   r   r&   r,   r%   r-   r.   r/   r   Zlookup_sidsr   r   r   Ú*test_lsa_LookupNames4_LookupSids3_multiple„   sŽ    ýýû
	û
û
ÿûz3LsaTests.test_lsa_LookupNames4_LookupSids3_multiplec                 C   sî   t ƒ }| | j¡ | ¡  t d| j | j|¡}| ddd¡\}}t d| j | j|¡}t ¡ }|g}tj	}d}	tj
}
tj}| ||||	|
|¡\}}}	t d| j | j|¡}t ¡ }|g}tj	}d}	tj
}
tj}| ||||	|
|¡\}}}	dS )r2   r3   Nr   r   )r   r   r   r   r   r   r   r4   r5   r    r!   r"   r6   )r   r)   r7   r8   r9   r*   r   r&   r,   r%   r-   r.   r/   r   r   r   Ú$test_lsa_LookupNames4_multiple_connsÚ   sZ    ýýû
ýûz-LsaTests.test_lsa_LookupNames4_multiple_connsc              	   C   sÀ   t ƒ }| | j¡ | ¡  t d| j | j|¡}| d d d ¡\}}t ¡ }|g}tj	}d}tj
}	tj}
|  t¡$}| |||||	|
¡ W d   ƒ n1 sš0    Y  |jjd tkr¼tdƒ‚d S )Nr3   r   z:LookupNames4 without schannel must fail with ACCESS_DENIED)r   r   r   r   r   r   r   r4   r5   r    r!   r"   ÚassertRaisesr   r6   Ú	exceptionÚargsr	   ÚAssertionError)r   r)   r7   r8   r9   r   r&   r,   r%   r-   r.   Úer   r   r   Ú&test_lsa_LookupNames4_without_schannel  s2    ýû"z/LsaTests.test_lsa_LookupNames4_without_schannelc              	   C   sÔ   t ƒ }| | j¡ | ¡  t d| j | j|¡}t ¡ }t ¡ }t	dƒ}||_
|g|_d|_t ¡ }tj}d}tj}	tj}
|  t¡$}| |||||	|
¡ W d   ƒ n1 s®0    Y  |jjd tkrÐtdƒ‚d S )Nzncacn_ip_tcp:%s[seal]r   r   r   z9LookupSids3 without schannel must fail with ACCESS_DENIED)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r<   r   r#   r=   r>   r	   r?   )r   r)   r*   r   r   r+   r&   r,   r%   r-   r.   r@   r   r   r   Ú%test_lsa_LookupSids3_without_schannel.  s:    ýû"z.LsaTests.test_lsa_LookupSids3_without_schannelN)
Ú__name__Ú
__module__Ú__qualname__r   r0   r1   r:   r;   rA   rB   r   r   r   r   r
      s   )6V6r
   )Ú__doc__Zsamba.dcerpcr   r   r   Zsamba.credentialsr   Zsamba.testsr   Zsamba.dcerpc.securityr   r   r   Zsamba.ntstatusr	   r
   r   r   r   r   Ú<module>   s   