HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/samba/tests/dcerpc/__pycache__/sam.cpython-310.pyc
o

�/a�y�@s�dZddlmZmZmZddlmZddlmZddlm	Z	m
Z
ddlmZddl
mZddlmZdd	lmZmZmZmZdd
lmZddlmZddlZd
d�Zdd�Zdd�ZGdd�de�ZdS)zTests for samba.dcerpc.sam.�)�samr�security�lsa)�DomainGeneralInformation)�RpcInterfaceTestCase)�env_loadparm�delete_force)�Credentials)�system_session)�SamDB)�ATYPE_NORMAL_ACCOUNT�ATYPE_WORKSTATION_TRUST�GTYPE_SECURITY_UNIVERSAL_GROUP�GTYPE_SECURITY_GLOBAL_GROUP)�generate_random_password)�
ndr_unpackNcCsdd�|jd|�D�S)NcSsg|]}|j|jf�qS�)�idx�name)�.0�entryrr�8/usr/lib/python3/dist-packages/samba/tests/dcerpc/sam.py�
<listcomp>*sztoArray.<locals>.<listcomp>)�entries)�handle�array�num_entriesrrr�toArray)srcCs$ttj|dd�}|��\}}|S�N�	objectSIDr�rr�dom_sid�split)�msg�sid�_�ridrrrr&0�r&cCs|ddS)N��6r)rrrr�
calc_max_size;sr*cs�eZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Z�ZS)-�	SamrTestscs4tt|���t�d|���|_|��|��dS)Nzncalrpc:)�superr+�setUpr�get_loadparm�conn�
open_samdb�open_domain_handle��self��	__class__rrr-AszSamrTests.setUpcCsLt�|_tjd|_t�|_|j�|j�t�|_	t
|j	|j|jd�|_dS)N�DOMAIN)�session_info�credentials�lp)rr9�os�environ�domainr	�creds�guessr
�sessionr�samdbr2rrrr0Js�zSamrTests.open_samdbcCsH|j�dtj�|_|j�|jt�|j��|_	|j�
|jtj|j	�|_dS�N)r/�Connect2r�SEC_FLAG_MAXIMUM_ALLOWEDr�LookupDomainr�Stringr<�
domain_sid�
OpenDomain�
domain_handler2rrrr1Us��
�zSamrTests.open_domain_handlecs,dd��t�|j������fdd�|D�S)NcSs$ttj|dd�}|��\}}|Srr )r#r$�xr%rrrr$cr'z$SamrTests.filter_domain.<locals>.sidcsg|]
}�|��kr|�qSrr)rrI�r!r$rrrisz+SamrTests.filter_domain.<locals>.<listcomp>)rr!r@�get_domain_sid)r3�
unfilteredrrJr�
filter_domainbszSamrTests.filter_domaincCs |j�dddt���\}}}dS)Nrr()r/�Connect5r�ConnectInfo1)r3�level�inforrrr�
test_connect5ks�zSamrTests.test_connect5cCs"|j�dtj�}|�|du�dSrA)r/rBrrC�
assertTrue�r3rrrr�
test_connect2oszSamrTests.test_connect2cCs4|j�dtj�}t|j�|dd��|j�|�dS)Nr���)r/rBrrCr�EnumDomains�CloserTrrr�test_EnumDomainssszSamrTests.test_EnumDomainscCsNg}|D] }d|}d||j��f}t|j|�|j�|�|�|�q|S)Nz
SAMR_GRP%dzcn=%s,cn=Users,%s)r@�	domain_dnr�newgroup�append�r3�ids�dns�ir�dnrrr�
create_groups}szSamrTests.create_groupsc	Csfg}|D],}d|}d||j��f}t|j|�|jj|ddd|d|d|d�|�|�q|S)NzSAMR_USER%dzcn=%s,CN=USERS,%sFzDescription for zgiven%dnamez	surname%d)�password�setpassword�description�	givenname�surname)r@rZr�newuserr\r]rrr�create_users�s�zSamrTests.create_userscCsVg}|D]$}d|}d||j��f}t|j|�|jj|d|d�|�|�q|S)Nz
SAMR_CMP%dzcn=%s,cn=COMPUTERS,%szDescription of )re)r@rZr�newcomputerr\r]rrr�create_computers�szSamrTests.create_computerscCs|D]}t|j|�qdSrA)rr@)r3r_rarrr�
delete_dns�s�zSamrTests.delete_dnscCs`|jj||d�}|�t|�dk�|j�|j|ddd�\}}}	|�t|�|�|�t|�|�|||	j�|j�|j|d|d�\}
}}|�||
�|�||�|||j�|�|dk�|j�|j||ddd�\}
}}|�||
�|�d|�|t	|�dd�|j�|�|dk�|j�|j|ddd�\}
}}|�||
�|�d|�|t	|�dd�|j�|�|dk�|j�|j|ddd�\}
}}|�||
�|�d|�|t	|�dd�|j�|gd	��}|j�|j|ddd�\}}}|�||�|�t|�d|�|t	|�dd�|j�|jj||d�}|j�|j|ddd�\}}}|�t|�t|�|�|�t|�t|�|�|||j�|�
|�|j�|j|ddd�\}}}|�t|�t|�|�|t|�k�ro|||j�n|t|�dk�r�|t	|�dd�|j�n|�d
�|��|j�|j||dd�\}}}|�||�|�d|�|j�
|j�dS)N��
expression�attrsrirV�����r(�i�i�i�i�zIncorrect number of entries {0})r@�searchrS�lenr/�QueryDisplayInforH�assertEqualr�listrl�fail�formatrXr)r3rP�
check_results�select�
attributes�add_elements�expected�ts�rs�actual�ts1�rs1�actual1�ts2�rs2�actual2r_�ts3�rs3�actual3�new�ts4�rs4�actual4�ts5�rs5�actual5�ts6�rs6�actual6rrr�_test_QueryDisplayInfo�s�
�
�
�
�
�
�
�

�
�z SamrTests._test_QueryDisplayInfoc�N�fdd�}��gd��}d�t�}gd�}��d|||�j���|�dS)Ncs�t||�D]P\}}��t|tj����t|d�t|j��|jj	dkr-��
d|v�n
��t|d�t|j��|jj	dkrH��
d|v�q��t|d�t|j��qdS)N�sAMAccountNamer�displayNamere)�ziprS�
isinstancer�DispEntryGeneralrw�str�account_name�	full_name�length�assertFalsere�rr��e�ar2rrr{4s���z>SamrTests.test_QueryDisplayInfo_level_1.<locals>.check_results�r(rprr��)(&(objectclass=user)(sAMAccountType={0}))�r�r�rer(�rirzrr�rl�r3r{r_r|r}rr2r�test_QueryDisplayInfo_level_13s��z'SamrTests.test_QueryDisplayInfo_level_1csN�fdd�}��gd��}d�t�}ddg}��d|||�j���|�dS)Nc�zt||�D]5\}}��t|tj����t|d�t|j��|jj	dkr-��
d|v�q��t|d�t|j��qdS�Nr�rre)r�rSr�r�
DispEntryFullrwr�r�rer�r�r�r2rrr{\����z>SamrTests.test_QueryDisplayInfo_level_2.<locals>.check_resultsr�r�r�rerp)rkrzr
r�rlr�rr2r�test_QueryDisplayInfo_level_2[s��z'SamrTests.test_QueryDisplayInfo_level_2c�P�fdd�}��gd��}dttf}ddg}��d|||�j���|�dS)Ncr�r�)r�rSr�r�DispEntryFullGrouprwr�r�rer�r�r�r2rrr{�r�z>SamrTests.test_QueryDisplayInfo_level_3.<locals>.check_resultsr��5(&(|(groupType=%d)(groupType=%d))(objectClass=group))r�rerr�rbrrr�rlr�rr2r�test_QueryDisplayInfo_level_3s��z'SamrTests.test_QueryDisplayInfo_level_3cr�)Nc�Zt||�D]%\}}��t|tj����t|jtj����t	|d�t	|jj
��qdS�Nr��r�rSr�r�DispEntryAsciir�r�AsciiStringLargerwr��stringr�r2rrr{�����z>SamrTests.test_QueryDisplayInfo_level_4.<locals>.check_resultsr�r�r�r�r�r�rr2r�test_QueryDisplayInfo_level_4�s��z'SamrTests.test_QueryDisplayInfo_level_4cr�)Ncr�r�r�r�r2rrr{�r�z>SamrTests.test_QueryDisplayInfo_level_5.<locals>.check_resultsr�r�r�re�r�r�rr2r�test_QueryDisplayInfo_level_5�s��z'SamrTests.test_QueryDisplayInfo_level_5cs��fdd�}��gd��}dttf}ddg}�jj||d�}��|�}��t|�dk�tt	|�t
d	�}tt|�d
�}�j�
�jd|�\}	}
}��t|�|�|||
j�td�}�j�
�jd|�\}	}
}��d|�||dd�|
j�td�}t|�}�j��j��j�
�j||�\}	}
}��d|���d|	�td�}g}
�j�
�jd|�\}	}
}|	rΈ�d|�|
�|
jd��j�
�j|	|�\}	}
}|	s�|r�|
�|
jd�g}
td�}�j�
�jd|�\}	}
}��gd
��}|	�r��d|�|
�|
jd��j�
�j|	|�\}	}
}|	s�|�r|
�|
jd���t|�t|
��|||
�tt|�t|�d
�}�j�
�jd|�\}	}
}��t|�t|�|��jj||d�}��|�}��t|�t|�k�tt	|�t
d	�}|||
j�g}
td�}�j�
�jd|�\}	}
}��|�|	�r�|�r���d|�|
�|
jd��j�
�j|	|�\}	}
}|	�r�|�s�|�r�|
�|
jd���t|�t|
��|||
���|�dS)Nc�Ft||�D]\}}��t|tj����t|d�t|jj��qdSr��	r�rSr�r�SamEntryrwr�rr�r�r2rrr{����z6SamrTests.test_EnumDomainGroups.<locals>.check_resultsr�r�r�rrmr���key�
rr(rs)rbrrr@rtrMrSru�sortedrxr&r*r/�EnumDomainGroupsrHrwrrXrr\rl�r3r{r_r|r}rL�filteredr�max_size�
resume_handler�r�rhr��	extra_dns�unfiltered01�
filtered01�
expected01rr2r�test_EnumDomainGroups�s��

�
�
�
�
��
�
��

�

�

��
zSamrTests.test_EnumDomainGroupscs2�fdd�}��gd��}d}gd�}�jj||d�}��|�}��t|�dk�tt|�td�}t	t|�d	�}�j
��jd
d
|�\}	}
}��
t|�|�|||
j�t	d�}�j
��jd
d
|�\}	}
}��
d|�||dd�|
j�t|�}t	d�}�j
��j��j
��j|d
|�\}	}
}��
d
|���
d
|	�g}
t	d�}�j
��jd
d
|�\}	}
}|	rψ�
d|�|
�|
jd
��j
��j|	d
|�\}	}
}|	s�|r�|
�|
jd
���
t|�t|
��|||
�g}
t	d�}�j
��jd
d
|�\}	}
}��gd��}|	�r#��
d|�|
�|
jd
��j
��j|	d
|�\}	}
}|	�s|�r.|
�|
jd
���
t|�t|
��|||
�t	t|�t|�d	�}�j
��jd
d
|�\}	}
}��
t|�t|�|��jj||d�}��|�}��t|�t|�k�tt|�td�}��
t|�|�|||
j���||�dS)
Ncr�r�r�r�r2rrr{br�z5SamrTests.test_EnumDomainUsers.<locals>.check_resultsr�z(objectClass=user))r�r�userAccountConrolrmr�r�r�rr(rs)rir@rtrMrSrur�rxr&r*r/�EnumDomainUsersrHrwrrXrr\rlr�rr2r�test_EnumDomainUsersas�


�

�

�

�

��


�

��


�
zSamrTests.test_EnumDomainUserscCs~|j�|jt�}td�}|j�|jdd|�\}}}|}|r6|�d|�|j�|j|d|�\}}}||7}|s|�||j�dS�Nr(r)r/�QueryDomainInforHrr*r�rw�	num_users�r3rQr�r�r�r�countrrr�$test_DomGeneralInformation_num_users�s �

�

��z.SamrTests.test_DomGeneralInformation_num_userscC�z|j�|jt�}td�}|j�|jd|�\}}}|}|r4|�d|�|j�|j||�\}}}||7}|s|�||j�dSr�)r/r�rHrr*r�rw�
num_groupsr�rrr�%test_DomGeneralInformation_num_groups�� �
�
��z/SamrTests.test_DomGeneralInformation_num_groupscCr�r�)r/r�rHrr*�EnumDomainAliasesrw�num_aliasesr�rrr�&test_DomGeneralInformation_num_aliases�r�z0SamrTests.test_DomGeneralInformation_num_aliases)�__name__�
__module__�__qualname__r-r0r1rMrRrUrYrbrirkrlr�r�r�r�r�r�r�r�r�r�r��
__classcell__rrr4rr+?s0	
	
z($%zr+)�__doc__�samba.dcerpcrrr�samba.dcerpc.samrr�samba.testsrrr�samba.credentialsr	�
samba.authr
�samba.samdbr�
samba.dsdbrr
rr�sambar�	samba.ndrrr:rr&r*r+rrrr�<module>s