
    Fcu                        d dl Z d dlZe j                            d d           dej        d<   d dlZd dlmZ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ZdZ G d de          Zedk    rdZdZd dlZ ej                     dS dS )    Nz
bin/python1PYTHONUNBUFFERED)LdbErrorERR_OPERATIONS_ERROR
SCOPE_BASESCOPE_SUBTREE)security)
ndr_unpack)SamDB)credentials)KDCBaseTestFc                   6    e Zd ZdZd Zd Zd Z	 	 d
dZd Zd	S )	LdapTestszgTest for LDAP authentication using Kerberos credentials stored in a
       credentials cache file.
    c                 .    |                                   d S )N_run_ldap_testselfs    </usr/lib/python3/dist-packages/samba/tests/krb5/test_ldap.py	test_ldapzLdapTests.test_ldap-   s        c                 2    |                      d           d S )NT)renamer   r   s    r   test_ldap_renamezLdapTests.test_ldap_rename0   s    4(((((r   c                 6    |                      ddd           d S )NFT)include_pacexpect_anonallow_errorr   r   s    r   test_ldap_no_paczLdapTests.test_ldap_no_pac3   s5    (,$ 	 	@ 	@ 	@ 	@ 	@r   FTc                 &   |                                  }|                                }d}|                     | j        j        d          }|                                }	|                                 }
|                     ||
|||          \  }}|                     t          j
        |j                   |                    t          d|	z  dg          }|                     dt          |                     t!          t"          j        |d	         d         d	                   }|rr|                                 }t)          j        |                                          }t)          j        |t(          j        d
          |d
<   |                    |           	 t5          d|z  ||                                           }ni# t8          $ r\}|s|                                  |j        \  }}|                     t>          |           |                      d|           Y d }~d S d }~ww xY w|                    dtB          dg          }|                     dt          |                     |d	         d         }t!          t"          j        |d	                   }|r|                     t"          j"        tG          |                     t!          t"          j        |d                   }|                     t"          j$        tG          |                     t          |          dk    rOt!          t"          j        |d                   }|                     t"          j%        tG          |                     d S d S |                     ||           d S )NldapF)account_type	use_cache)pacz(sAMAccountName=%s)	objectSid)scope
expressionattrs   r   sAMAccountName	ldap://%surlr   lp NT_STATUS_NO_IMPERSONATION_TOKEN tokenGroupsr&   r(         )&	get_samdbhost_dns_nameget_cached_credsAccountTypeUSERget_usernameget_dc_credscreate_ccache_with_user
addCleanuposremovenamesearchr   assertEquallenr
   r	   dom_sidget_new_usernameldbMessageget_dnMessageElementFLAG_MOD_REPLACEmodifyr   get_lpr   failargsr   assertInr   SID_NT_ANONYMOUSstrSID_NT_NETWORKSID_NT_THIS_ORGANISATION)r   r   r   r   r   samdb	mach_nameserviceuser_credentials	user_namemach_credentialscreds	cachefileldb_ressidnew_namemsgldb_as_usereenumestrtoken_groups	token_sids                          r   r   zLdapTests._run_ldap_test7   s      ''))	  00). 1   %1133	,,.. "99:J:J:A:C>I	 : K K	 		9>222 ,,]*?)*K&1]  4 4 	CLL))))71:k+B1+EFF 		 ,,..H+.557788C$'$6x7:7K7G%I %IC ! LL	K)$;,1#';;==2 2 2KK  	 	 	 		JD$14888MM<dCCCFFFFF	 $$R+5,9? % < < 	CLL)))qz-0x/aAA	 	-X6IGGG"8#3\!_EEIX4c)nnEEE<  A%%&x'7aII	  !B!$Y1 1 1 1 1 &% S),,,,,s   'G 
H)AH$$H)c                    |                                  }|                                }t          j                    }|                                 t          d|z  ||                                           }|                    dt          dg          }| 	                    dt          |                     t          t          j        |d         d         d                   }| 	                    t          j        t          |                     | 	                    t          |d         d                   d           d S )Nr+   r,   r0   r1   r2   r)   r   )r5   r6   r   Credentialsset_anonymousr   rL   rA   r   rB   rC   r
   r	   rD   rP   rQ   )r   rT   rU   
anon_credsr`   r\   re   s          r   test_ldap_anonymouszLdapTests.test_ldap_anonymous   s     ''))	 ,..
  """ i 7(2#{{}}. . . $$R+5,9? % < < 	CLL))) x/M1J11MNN	2C	NNCCCWQZ677;;;;;r   N)FTFF)	__name__
__module____qualname____doc__r   r   r   r   rj    r   r   r   r   (   s~           ) ) )@ @ @ 8<6;U- U- U- U-n< < < < <r   r   __main__)sysr>   pathinsertenvironrF   r   r   r   r   samba.dcerpcr	   	samba.ndrr
   samba.samdbr   sambar   samba.tests.krb5.kdc_base_testr   global_asn1_printglobal_hexdumpr   rk   unittestmainro   r   r   <module>r~      s;  ( 


 				 <      !$
  



 I I I I I I I I I I I I ! ! ! ! ! !                         6 6 6 6 6 6 y< y< y< y< y< y< y< y<x zNOOOHMOOOOO	 r   