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: //lib/python3/dist-packages/samba/tests/samba_tool/__pycache__/gpo.cpython-310.pyc
o

�/aw4�@sddlZddlZddlZddlZddlZddlmZddlZddlm	Z	m
Z
ddlmZddl
mZmZddlmZddlmZmZddlmZdd	lmZdd
lmZddlmmZddlmZddl m!Z!ej"�#ej"�$ej"�%e&�d
��Z'ddd�Z(Gdd�de�Z)dS)�N)�SambaToolCmdTest)�
get_gpo_dn�get_gpo_info)�LoadParm)�
stage_file�unstage_file)�preg)�ndr_pack�
ndr_unpack)�
get_string)�ConfigParser)�StringIO)�NamedTemporaryFile)�sleepz../../../../..TFcCsHtj�|�r4|r$t|���}|��t|���}|��||kr"|SdSt|���t|���kr2|SdS|g}|g}|r�|��}	|��}
t�|	�}t�|
�}|��|��||kr\|S|D]A}
tj�	|	|
�}tj�	|
|
�}tj�
|�r|�|�|�|�q^|�d�r�|s�|�d�r�|r�t|d���t|d���kr�|Sq^|s<dS)z�Use this function to determine if the GPO backup differs from another.

    xml=True checks whether any xml files are equal
    binary=True checks whether any .SAMBABACKUP files are equal
    Nz.xmlz.SAMBABACKUP�rb)
�os�path�isfile�open�	readlines�sort�read�pop�listdir�join�isdir�append�endswith)�path1�path2�binary�xml�	sortlines�file1�file2�l_dirs�r_dirs�l_dir�r_dir�dirlist�
dirlist_other�e�l_name�r_name�r.�</usr/lib/python3/dist-packages/samba/tests/samba_tool/gpo.py�has_difference(sN�


����r0cs4eZdZdZdZdZdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Z d:d;�Z!d<d=�Z"d>d?�Z#d@dA�Z$dBdC�Z%�fdDdE�Z&�fdFdG�Z'�Z(S)H�GpoCmdTestCasez%Tests for samba-tool time subcommands�testgpoz&{1E1DC8EA-390C-4800-B327-98B56A0AEA5D}cCs4|�ddddtjd�\}}}|�|||d�dS)z?Run gpo list against the server and make sure it looks accurate�gpo�listall�-H�	ldap://%s�SERVERz%Ensuring gpo listall ran successfullyN��	runsubcmdr�environ�assertCmdSuccess��self�result�out�errr.r.r/�
test_gpo_listbs zGpoCmdTestCase.test_gpo_listc	Cs2|�dddddtjd�\}}}|�|d�dS)	zfRun against a non-existent GPO, and make sure it fails (this hard-coded UUID is very unlikely to existr3�fetchz$c25cac17-a02a-4151-835d-fae17446ee43r5r6r7zcheck for result codeN)r9rr:�
assertCmdFailr<r.r.r/�test_fetchfailgs"zGpoCmdTestCase.test_fetchfailc	CsT|�dd|jddtjdd|j�\}}}|�|||d�t�tj�	|jd��d	S)
z/Run against a real GPO, and make sure it passesr3rBr5r6r7�--tmpdir�!Ensuring gpo fetched successfully�policyN)
r9�gpo_guidrr:�tempdirr;�shutil�rmtreerrr<r.r.r/�
test_fetchls*zGpoCmdTestCase.test_fetchc	Cs8|�dd|jddtjd�\}}}|�|||d�dS)�(Show a real GPO, and make sure it passesr3�showr5r6r7rFN�r9rHrr:r;r<r.r.r/�	test_showrs$zGpoCmdTestCase.test_showcCsN|�dd|jddtjddtjdtjdf�\}}}|�|||d	�d
S)rMr3rNr5r6r7�-U%s%%%s�USERNAME�PASSWORDrFNrOr<r.r.r/�test_show_as_adminws:z!GpoCmdTestCase.test_show_as_adminc
CsJ|�ddddtjddtjdtjdf�\}}}|�|||d	�d
S)z9Check all the GPOs on the remote server have correct ACLsr3�aclcheckr5r6r7rQrRrSz!Ensuring gpo checked successfullyNr8r<r.r.r/�
test_aclcheck|s6zGpoCmdTestCase.test_aclcheckcCs&|�ddtjddtjdtjdf�|_d|j��}|j�|dd	��|�d
d|ddtjddtjd
tjdf�\}}}|�|||d�t�	�}t�
|j|�|_t�dtj
d�|d<|j�|�|�d
d|ddtjddtjd
tjdf�\}}}|�|||d�|j�|�dS)Nr5r6�	DC_SERVERrQ�DC_USERNAME�DC_PASSWORDzOU=gpo_test_link,%s�organizationalUnit)�dn�objectClassr3�getlinkr7rRrSz&Ensuring gpo link fetched successfully� �gPLink)�getSamDBrr:�samdb�get_default_basedn�addr9r;�ldb�Message�Dnr[�MessageElement�FLAG_MOD_REPLACE�modify�delete)r=�container_dnr>r?r@�mr.r.r/�test_getlink_empty�s:
���

�
�

�
�z!GpoCmdTestCase.test_getlink_emptycCs�tj�|jd|j�}tj�|jd�}t�|�tj�|jd�}t�|�d}z�|�ddd|dd	tjd
d|d|j	d
tjdtjdfd�\}}}d|�
d�d�
d�d}|�dd|dd	tjd
d|�\}}}|�|||d�|�t
tj�|d|�|ddd��W|r�|�dd|dd	tjd
d
tjdtjdf�\}}}|�|||d�t�|�t�|�dS|r�|�dd|dd	tjd
d
tjdtjdf�\}}}|�|||d�t�|�t�|�w)z<Restore from a static backup and compare the binary contentsrG�temp�newNr3�restore�BACKUP_RESTORE1r5r6r7rE�
--entitiesrQrRrS�--restore-metadata�{%s}�{��}r�backuprFTF�r r!�del�!Ensuring gpo deleted successfully�rrr�backup_path�backup_gpo_guidrI�mkdirr9r:�entity_file�splitr;�assertIsNoner0rJrK)r=�static_path�	temp_path�new_pathrHr>r?r@r.r.r/�"test_backup_restore_compare_binary�s��


���
�

�
��
�
���
�
�
���
�
z1GpoCmdTestCase.test_backup_restore_compare_binaryc
Cs.tj�|jd|j�}tj�|jd�}t�|�tj�|jd�}t�|�d}d}d}�z|�ddd|dd	tjd
d|d|j	d
tjdtjdfd�\}}}	d|�
d�d�
d�d}|}|�dd|dd	tjd
d|d�\}}}	|�|||	d�|�dddtj�|d|�dd	tjd
d|d
tjdtjdfd�
\}}}	d|�
d�d�
d�d}|}|�|||	d�|�dd|dd	tjd
d|�\}}}	|�t
tj�|d|�tj�|d|�ddd��W|�r|�dd|dd	tjd
d
tjdtjdf�\}}}	|�|||	d�|�r2|�dd|dd	tjd
d
tjdtjdf�\}}}	|�|||	d�t�|�t�|�dS|�re|�dd|dd	tjd
d
tjdtjdf�\}}}	|�|||	d�|�r�|�dd|dd	tjd
d
tjdtjdf�\}}}	|�|||	d�t�|�t�|�w) z�Restore from a static backup (and use no entity file, resulting in
        copy-restore fallback), and compare the binary contentsrGrnroNr3rprqr5r6r7rErrrQrRrSrsrtrurvrwrrx�--generalizerF�BACKUP_RESTORE2�"Ensuring gpo restored successfullyTFryrzr{r|�
r=r�r�r�rH�	gpo_guid1�	gpo_guid2r>r?r@r.r.r/�.test_backup_restore_no_entities_compare_binary�s��


���
�

�
�
���
�	
�
��
�
�
���
�
���
�
�
���
�
���
�
z=GpoCmdTestCase.test_backup_restore_no_entities_compare_binaryc
Cs2tj�|jd|j�}tj�|jd�}t�|�tj�|jd�}t�|�d}d}d}�z|�ddd|dd	tjd
d|d|j	d
tjdtjdfd�\}}}	d|�
d�d�
d�d}|}|�dd|dd	tjd
d|�\}}}	|�|||	d�|�dddtj�|d|�dd	tjd
d|d|j	d
tjdtjdfd�\}}}	d|�
d�d�
d�d}|}|�|||	d�|�dd|dd	tjd
d|�\}}}	|�t
tj�|d|�tj�|d|�ddd��W|�r
|�dd|dd	tjd
d
tjdtjdf�\}}}	|�|||	d�|�r4|�dd|dd	tjd
d
tjdtjdf�\}}}	|�|||	d�t�|�t�|�dS|�rg|�dd|dd	tjd
d
tjdtjdf�\}}}	|�|||	d�|�r�|�dd|dd	tjd
d
tjdtjdf�\}}}	|�|||	d�t�|�t�|�w)z6Restore from a static backup and backup to compare XMLrGrnroNr3rprqr5r6r7rErrrQrRrSrsrtrurvrwrrxrFr�r�Tryrzr{r|r�r.r.r/�&test_backup_restore_backup_compare_XML,s��


���
�

�
�
���
�

�
��
�
�
���
�
���
�
�
���
�
���
�
z5GpoCmdTestCase.test_backup_restore_backup_compare_XMLcCsJtj�|jd|j�}tj�|jd�}t�|�tj�|jd�}t�|�tj�|d�}t|d��
}|�d�Wd�n1s@wYtj�|d�}d}z�|�	dd	d
|ddtj
d
d|d|dtj
dtj
dfd�\}}	}
|�||	|
d�d|	�d�d�d�d}|�	dd|ddtj
d
d|dd|�
\}}	}
|�||	|
d�|�
t||dd��|�
ttj�|d|�|ddd ��W|r�|�	dd!|ddtj
d
dtj
dtj
df�\}}	}
|�||	|
d"�t�|�t�|�dS|�r|�	dd!|ddtj
d
dtj
dtj
df�\}}	}
|�||	|
d"�t�|�t�|�w)#zfRestore from a static backup with different entities, generalize it
        again, and compare the XMLrGrnro�entities�wbsD<!ENTITY SAMBA__NETWORK_PATH__82419dafed126a07d6b96c66fc943735__ "\\samdom.example.com">
<!ENTITY SAMBA__NETWORK_PATH__0484cd41ded45a0728333a9c5e5ef619__ "\\samdom">
<!ENTITY SAMBA____SDDL_ACL____4ce8277be3f630300cbcf80a80e21cf4__ "D:PAR(A;CI;KA;;;BA)(A;CIIO;KA;;;CO)(A;CI;KA;;;SY)(A;CI;KR;;;S-1-16-0)">
<!ENTITY SAMBA____USER_ID_____d0970f5a1e19cb803f916c203d5c39c4__ "*S-1-5-113">
<!ENTITY SAMBA____USER_ID_____7b7bc2512ee1fedcd76bdc68926d4f7b__ "Administrator">
<!ENTITY SAMBA____USER_ID_____a3069f5a7a6530293ad8df6abd32af3d__ "Foobaz">
<!ENTITY SAMBA____USER_ID_____fdf60b2473b319c8c341de5f62479a7d__ "*S-1-5-32-545">
<!ENTITY SAMBA____USER_ID_____adb831a7fdd83dd1e2a309ce7591dff8__ "Guest">
<!ENTITY SAMBA____USER_ID_____9fa835214b4fc8b6102c991f7d97c2f8__ "*S-1-5-32-547">
<!ENTITY SAMBA____USER_ID_____bf8caafa94a19a6262bad2e8b6d4bce6__ "*S-1-5-32-546">
<!ENTITY SAMBA____USER_ID_____a45da96d0bf6575970f2d27af22be28a__ "System">
<!ENTITY SAMBA____USER_ID_____171d33a63ebd67f856552940ed491ad3__ "s-1-5-32-545">
<!ENTITY SAMBA____USER_ID_____7140932fff16ce85cc64d3caab588d0d__ "s-1-1-0">
Nr3rprqr5r6r7rErrrQrRrSrsr�rtrurvrwrrxr�rFT)r"Fryrzr{)rrrr}r~rIrr�writer9r:r;r�r�r0rJrK)r=r�r�r��alt_entity_file�f�gen_entity_filerHr>r?r@r.r.r/�test_backup_restore_generalizes��

�
���
�

�
���
�
���
�
�
���
�
z-GpoCmdTestCase.test_backup_restore_generalizec
Cs�|�ddtjddtjdtjdf�|_tj�|jd�}t�|�dd	d
�}t|j|j	�}|D]}||}t
��}||_t
�
|t
j|�||<|j�|�q2z�|�dd|j	ddtjd
d|�\}}}	|�|||	d�d|�d�d�d�d}
tj�|d|
�}|�ddd|ddtjd
d|jdtjdtjdfd�
\}}}	|�|||	d�d|�d�d�d�d}t|j|�}|�t|�d�|D]}|�||dv�|�||t|d|d��q�W|�r|�dd|ddtjd
dtjdtjdf�\}}}	|�|||	d�t�tj�|jd��t�tj�|jd��dS|�rM|�dd|ddtjd
dtjdtjdf�\}}}	|�|||	d�t�tj�|jd��t�tj�|jd��w)Nr5r6rWrQrXrYrnz�[{35378EAC-683F-11D2-A89A-00C04FBBCFA2}{53D6AB1B-2488-11D1-A28C-00C04FB94F17}][{827D319E-6EAC-11D2-A4EA-00C04F79F83A}{803E14A0-B4FB-11D0-A0D0-00A0C90F574B}][{B1BE8D72-6EAC-11D2-A4EA-00C04F79F83A}{53D6AB1B-2488-11D1-A28C-00C04FB94F17}]z�[{3060E8D0-7020-11D2-842D-00C04FA372D4}{3060E8CE-7020-11D2-842D-00C04FA372D4}][{35378EAC-683F-11D2-A89A-00C04FBBCFA2}{0F6B957E-509E-11D1-A7CC-0000F87571E3}])�gPCMachineExtensionNames�gPCUserExtensionNamesr3rxr7rErFrtrurvrwrrGrp�RESTORE_EXTrRrSrsr�rzr{)r`rr:rarrrIrrrHrdrer[rgrhrir9r;r�r�assertEqual�len�
assertTrue�strrJrK)
r=r��
extensions�gpo_dn�ext�datarlr>r?r@�guidrH�msgr.r.r/�%test_backup_with_extension_attributes�s�
��
��
�
���
�	"�
���
��
���
�z4GpoCmdTestCase.test_backup_with_extension_attributescCs�t�}|�tjd�|�dd�}tj�|tjd��dd�}|�ddd	d
tjddtj�t	d
�dtjdtjdf�\}}}|�
|||d�|�tj�|�d�|�tj�tj�|d��d�t
�|�dS)N�SERVERCONFFILEr�sysvol�REALM�Policies�PolicyDefinitionsr3�admxloadr5r6r7z
--admx-dir=%szlibgpo/admxrQrRrSz Filling PolicyDefinitions failedz!PolicyDefinitions was not createdz
samba.admx)r�loadrr:�getrr�lowerr9�source_pathr;r��existsrJrK)r=�lp�
local_path�	admx_pathr>r?r@r.r.r/�test_admx_loads>������
�
	���zGpoCmdTestCase.test_admx_loadc	
snt�}|�tjd�|�dd�}tj�||�d���d|jd�}d�|�	dd	|j�d
ddtjd
dtjdtjdf�\}}}|�
|||d�|�tj�|�d�t
tjt|d����}t�fdd�|jD��}|�|d�|�	dd	|j�ddtjd
dtjdtjdf�\}}}|�
|||d�t
tjt|d����}t�fdd�|jD��}|�|d�dS)Nr�rr��realmr��Machine/Registry.polzapply group policiesr3)�manage�smb_conf�set�yesr5r6r7rQrRrSz"Failed to set apply group policieszThe Registry.pol does not existrc�$g|]}t|j��ko|jdk�qS�rv�r�	valuenamer���.0r+�rGr.r/�
<listcomp>@��z4GpoCmdTestCase.test_smb_conf_set.<locals>.<listcomp>zThe sudoers entry was not addedz$Failed to unset apply group policiescr�r�r�r�r�r.r/r�Pr�z!The sudoers entry was not removed)rr�rr:r�rrr�rH�runsublevelcmdr;r�r�r
r�filerr�any�entries)	r=r�r��reg_polr>r?r@�reg_data�retr.r�r/�test_smb_conf_set*sb����
�
������
�
�
�z GpoCmdTestCase.test_smb_conf_setc
Cs�t�}|�tjd�|�dd�}tj�||�d���d|jd�}t	�
�}t	��}d|_d|_
d	|_d
|_d
|_|g|_t|t|��}|�|d|�|�dd
|jddtjddtjdtjdf�\}}}	|�d|j
|d�t|�dS)Nr�rr�r�r�r�s Software\Policies\Samba\smb_confsapply group policies�rv�Could not create the target %sr3)r�r��listr5r6r7rQrRrSz	%s = True�The test entry was not found!)rr�rr:r�rrr�rHrr��entry�keynamer��typer��num_entriesr�rr	r�r��assertInr)
r=r�r�r��stager+r�r>r?r@r.r.r/�test_smb_conf_listTs:����
�z!GpoCmdTestCase.test_smb_conf_listc
Cs0t�}|�tjd�|�dd�}tj�||�d���d|jd�}|�	dd|jd	d
ddtjd
dtjdtjdf�\}}}|�
|||d�|�tj�|�d|�t
|d���}|�d|d�|�	dd|jd	ddtjd
dtjdtjdf�\}}}|�
|||d�t
|d���}|�d|d�dS)Nr�rr�r�r�z0Machine/Microsoft/Windows NT/SecEdit/GptTmpl.infr3�r��securityr��MaxTicketAge�10r5r6r7rQrRrS�Failed to set MaxTicketAgez%s was not created�r�MaxTicketAge = 10r��Failed to unset MaxTicketAge�The test entry was still found!)rr�rr:r�rrr�rHr�r;r�r�rrr��assertNotIn)r=r�r��inf_polr>r?r@�inf_pol_contentsr.r.r/�test_security_setss^����
�
������
�
��z GpoCmdTestCase.test_security_setc
Cs�|�dd|jddddtjddtjd	tjd
f�\}}}|�|||d�|�dd|jddtjddtjd	tjd
f�\}}}|�d
|d�|�dd|jdddtjddtjd	tjd
f�\}}}|�|||d�dS)Nr3r�r�r�r5r6r7rQrRrSr�)r�r�r�r�r�r�)r�rHrr:r;r�r<r.r.r/�test_security_list�sT���
�
����
����
�
�z!GpoCmdTestCase.test_security_listc
Cst�}|�tjd�|�dd�}tj�||�d���d|jdd�}|�	dd	|jd
ddd
tjddtjdtjdf�\}}}|�
|||d�|�	dd	|jd
dd
tjddtjdtjdf�\}}}|�
|||d�tdd�}|�|�|�
|�d��dS)Nr�rr�r�r�zMachine/Microsoft/Windows NTzSecEdit/GptTmpl.infr3r�r�r�r5r6r7rQrRrSr�r�)�
interpolationzKerberos Policy)rr�rr:r�rrr�rHr�r;rr�assertFalse�has_section)r=r�r��gpt_infr>r?r@�inf_datar.r.r/�test_security_nonempty_sections�sP����
�
����
�
�

z.GpoCmdTestCase.test_security_nonempty_sectionscCs6|�dd|jddddddtjdd	tjd
tjdf�
\}}}|�|||d�d
}|�dd|jddtjdd	tjd
tjdf�\}}}|�||d�|�dd|j|ddtjdd	tjd
tjdf�\}}}|�|||d�|�dd|jddtjdd	tjd
tjdf�\}}}|�||d�dS)Nr3)r��sudoersrc�ALL�fakeu�fakegr5r6r7rQrRrSzSudoers add failedz$fakeu,fakeg% ALL=(ALL) NOPASSWD: ALL�r�r�r�r��r�r��remove�Sudoers remove failedr��r�rHrr:r;r�r�)r=r>r?r@�sudoerr.r.r/�test_sudoers_add�sd���
�	���
����
����
�zGpoCmdTestCase.test_sudoers_addcCsdt�}|�tjd�|�dd�}tj�||�d���d|jdd�}t	�
d�}t	�|d	�}t	�|d
�}d|_t	�|d�}d
|_t	�|d�}d|_t	�|d�}	d|	_t	�|d�}
t	�|
d�}d|_t	�|
d�}t	�|d�}
d|
_t	�|d�}d|_t	�|d�}t	�|d�}d|_d|j
d<t	�|
d�}t	�|d�}
d|
_t	�|d�}d|_t	�|
d�}t	�|d�}
d|
_t	�|d�}d|_t	�|d�}t	�|d�}d|_d|j
d<t	�|d�}t	�|d�}d|_d|j
d<t|t	�|d ��}|�|d!|�d"}d#}d$}|�d%d&|jd'd(tjd)d*tjd+tjd,f�\}}}|�|||d-�|�||d.�|�||d.�|�||d.�|�d%d/|j|d'd(tjd)d*tjd+tjd,f�\}}}|�|||d0�|�d%d/|j|d'd(tjd)d*tjd+tjd,f�\}}}|�|||d0�|�d%d&|jd'd(tjd)d*tjd+tjd,f�\}}}|�||d1�|�||d1�t|�dS)2Nr�rr�r�r�zMachine/VGP/VTLA/Sudoz!SudoersConfiguration/manifest.xml�	vgppolicy�
policysetting�version�1�namezSudo Policy�descriptionz!Sudoers File Configuration Policy�
apply_mode�merger��load_plugin�true�
sudoers_entry�commandr��user�listelement�	principalr�r��fakeu2�fakeg2�group�utf-8r�zfakeu ALL=(ALL) NOPASSWD: ALLz&fakeu2,fakeg2% ALL=(ALL) NOPASSWD: ALLzALL ALL=(ALL) NOPASSWD: ALLr3r�r5r6r7rQrRrSzSudoers list failedr�r�r�r�)rr�rr:r�rrr�rH�etree�Element�
SubElement�text�attribr�tostringr�r�r;r�r�r)r=r�r��vgp_xmlr�r��pvr�r�r�r�r�r�r�rrrrr�r��sudoer2�sudoer_no_principalr>r?r@r.r.r/�test_sudoers_lists��



���
�����
����
�	���
��z GpoCmdTestCase.test_sudoers_listcCs|t�}|�tjd�|�dd�}tj�||�d���d|jdd�}t	�
d�}t	�|d	�}t	�|d
�}d|_t	�|d�}d
|_t	�|d�}d|_t	�|d�}	d|	_t	�|d�}
t	�|
d�}t	�|d�}tj�|j
d�|_t	�|d�}
tj�|j
d�|
_t|t	�|d��}|�|d|�d|j|
jf}|�dd|jddtjdd tjd!tjd"f�\}}}|�||d#�t|�dS)$Nr�rr�r�r��Machine/VGP/VTLA/UnixzSymlink/manifest.xmlr�r�r�r�r�zSymlink Policyr�zSpecifies symbolic link datar�r�r��file_properties�source�test.source�target�test.targetrr��ln -s %s %sr3�r��symlinkr�r5r6r7rQrRrSr�)rr�rr:r�rrr�rHrrr	r
rIrrr�r�r�r)r=r�r�r
r�r�rr�r�r�r�rrrr�rr>r?r@r.r.r/�test_symlink_listqsN�
���
�z GpoCmdTestCase.test_symlink_listc
Cs\tj�|jd�}tj�|jd�}d||f}|�dd|j||ddtjdd	tjd
tjdf�\}}}|�|||d�|�dd
|jddtjdd	tjd
tjdf�\}}}|�||d�|�dd|j||ddtjdd	tjd
tjdf�\}}}|�|||d�|�dd
|jddtjdd	tjd
tjdf�\}}}|�	||d�dS)Nrrrr3)r�rrcr5r6r7rQrRrSzSymlink add failedrr�)r�rr�zSymlink remove failedzThe test entry was not removed!)
rrrrIr�rHr:r;r�r�)r=�source_text�target_textrr>r?r@r.r.r/�test_symlink_add�sj���
�	���
����
�	���
�zGpoCmdTestCase.test_symlink_addcCsXt�}|�tjd�|�dd�}tj�||�d���d|jdd�}tj�||�d���d|jdd	�}t	�
d
�}t	�|d�}t	�|d�}d
|_t	�|d�}d|_t	�|d�}	d|	_t	�|d�}
t	�|
d�}t	�|d�}||_t	�|d�}
tj�|j
d�|
_t	�|d�}t�t���j|_t	�|d�}t�t���j|_t	�|d�}|�dd�t	�|d�t	�|d�t	�|d�t	�|d�}|�dd�t	�|d�t	�|d�t	�|d�}|�dd�t	�|d�t	�|d�t|t	�|d��}|�|d |�|�d!d"|jd#d$tjd%d&tjd'tjd(f�\}}}|�|
j|d)�|�d*|d+�t|�dS),Nr�rr�r�r�rzFiles/manifest.xml�Machine/VGP�VTLA/Unix/Files/test.sourcer�r�r�r�r��Filesr�z+Represents file data to set/copy on clientsr�rrrrrr�permissionsr�rr��execute�otherrr�r3�r��filesr�r5r6r7rQrRrSr��
-rwxr-xr-x�)The test entry permissions were not found)rr�rr:r�rrr�rHrrr	r
rI�pwd�getpwuid�getuid�pw_name�grp�getgrgid�getgid�gr_namer�rrr�r�r�r)r=r�r�r
�source_filer�r�rr�r�r�rrrrrr"r�r>r?r@r.r.r/�test_files_list�sx��
���
��zGpoCmdTestCase.test_files_listc
Cs t�}|�tjd�|�dd�}tj�||�d���d|jdd�}tj�|j	d�}d	}t
|d
��
}|�|�Wd�n1sAwYtj�|j	d�}t�
t���j}t�t���j}	|�dd
|j||||	dddtjddtjdtjdf�\}
}}|�|
||d�|�|t
|d���d�|�dd|jddtjddtjdtjdf�\}
}}|�||d�|�d|d�t�|�|�dd|j|ddtjddtjdtjdf�\}
}}|�|
||d�|�dd|jddtjddtjdtjdf�\}
}}|�||d�dS)Nr�rr�r�r�rr rz#!/bin/sh
echo hello world�wrr3)r�r&rc�755r5r6r7rQrRrSzFile add failedr�z,Failed to find the source file on the sysvolr%r�r'r()r�r&r�zFile remove failedr�)rr�rr:r�rrr�rHrIrr�r)r*r+r,r-r.r/r0r�r;r�r�unlinkr�)
r=r�r��
sysvol_sourcer1�source_datar3�target_filerrr>r?r@r.r.r/�test_files_adds������
�����
��
���
�	���
�zGpoCmdTestCase.test_files_addcCs�t�}|�tjd�|�dd�}tj�||�d���d|jdd�}t	�
d�}t	�|d	�}t	�|d
�}d|_t	�|d�}d
|_t	�|d�}d|_t	�|d�}	d|	_t	�|d�}
t	�|
d�}t	�|d�t	�|d�}t	�|d�t	�|d�}
t	�|
d�}d|_t	�|
d�}d|_t
|t	�|d��}|�|d|�d}|�dd |jd!d"tjd#d$tjd%tjd&f�\}}}|�||d'�t|�dS)(Nr�rr�r�r�zMachine/VGP/VTLA/SshCfgzSshD/manifest.xmlr�r�r�r�r�zConfiguration Filer�z+Represents Unix configuration file settingsr�r�r��
configfile�filename�
configsection�sectionname�keyvaluepair�key�KerberosAuthentication�value�Yesrr��KerberosAuthentication Yesr3�r��opensshr�r5r6r7rQrRrSr��rr�rr:r�rrr�rHrrr	r
rrr�r�r�r)r=r�r�r
r�r�rr�r�r�r�r:r<�optr?rAr�rEr>r?r@r.r.r/�test_vgp_openssh_listFsV�
���
�z$GpoCmdTestCase.test_vgp_openssh_listc
Cs2|�dd|jddddtjddtjd	tjd
f�\}}}|�|||d�d}|�dd
|jddtjddtjd	tjd
f�\}}}|�||d�|�dd|jdddtjddtjd	tjd
f�\}}}|�|||d�|�dd
|jddtjddtjd	tjd
f�\}}}|�||d�dS)Nr3)r�rEr�r@rBr5r6r7rQrRrSzOpenSSH set failedrCrDr�zOpenSSH unset failedr�r�)r=r>r?r@rEr.r.r/�test_vgp_openssh_setssh���
�
���
����
�	���
�z#GpoCmdTestCase.test_vgp_openssh_setcCs�t�}d}t��@}tj�|j�}|�d�|��|�dd|j	|jdddtj
ddtj
d	tj
d
f�\}}}|�|||d�Wd�n1sKwYd�d|�
d
���d|j	dd|g�}d|}|�dd|j	ddtj
ddtj
d	tj
d
f�\}}}|�||d�|�
dd�}	tj�|	|�
d
���d|j	dd|�}
|�tj�|
�d�|�dd|j	|jddtj
ddtj
d	tj
d
f�\}}}|�|||d�|�dd|j	ddtj
ddtj
d	tj
d
f�\}}}|�||d�dS)Ns#!/bin/sh
echo $@ hello worldr3)r��scripts�startuprcz'-n'r5r6r7rQrRrSzScript add failed�\r�r��MACHINE\VGP\VTLA\Unix�Scripts\Startupz@reboot root %s -n�r�rJrKr�r�rr�rzScripts/Startupz.The test script was not uploaded to the sysvol)r�rJrKr�zScript remove failedr�)rrrr�basenamer�r��flushr�rHr:r;rr�r�r�r�r�r�)r=r��fnamer�r>r?r@�script_pathr�r��local_script_pathr.r.r/�test_startup_script_add�s�
���
�	�����
������
�	���
�z&GpoCmdTestCase.test_startup_script_addcCsvt�}|�tjd�|�dd�}tj�||�d���d|jdd�}t	�
d�}t	�|d	�}t	�|d
�}d|_t	�|d�}d
|_t	�|d�}d|_t	�|d�}	t	�|	d�}
t	�|
d�}d|_t	�|
d�}d|_t
|t	�|d��}
|�|
d|�d�d|�d���d|jdd|jg�}d||jf}|�dd|jddtjd d!tjd"tjd#f�\}}}|�||d$�t|�dS)%Nr�rr�r�r�rzScripts/Startup/manifest.xmlr�r�r�r�r�zUnix Scriptsr�z6Represents Unix scripts to run on Group Policy clientsr�r�scriptztest.sh�
parametersz-err�rLrMrNz@reboot root %s %sr3rOr5r6r7rQrRrSr�rF)r=r�r�r
r�r�rr�r�r�rrVrWr�rSr�r>r?r@r.r.r/�test_startup_script_list�sR�
����
�z'GpoCmdTestCase.test_startup_script_listcC�6d}d|}|�dd|j|ddtjddtjd	tjd
f�\}}}|�|||d�|�dd|jddtjddtjd	tjd
f�\}}}|�||d
�|�dd|jddtjddtjd	tjd
f�\}}}|�|||d�|�dd|jddtjddtjd	tjd
f�\}}}|�||d�dS)NzThis is the message of the day�"%s
"r3)r��motdr�r5r6r7rQrRrSzMOTD set failed�r�r[r�r�zMOTD unset failedr�r��r=r
r�r>r?r@r.r.r/�test_vgp_motd_set�f���
�	���
����
����
�z GpoCmdTestCase.test_vgp_motd_setcC�Jt�}|�tjd�|�dd�}tj�||�d���d|jdd�}t	�
d�}t	�|d	�}t	�|d
�}d|_t	�|d�}d
|_t	�|d�}d|_t	�|d�}	d|	_t	�|d�}
t	�|
d�}d|_t	�|
d�}d|_t
|t	�|d��}
|�|
d|�|�dd|jddtjddtjdtjd f�\}}}|�|j|d!�t|�dS)"Nr�rr�r�r�rzMOTD/manifest.xmlr�r�r�r�r��	Text Filer��Represents a Generic Text Filer��replacer�r;r[r
zThis is a message of the dayrr�r3r\r5r6r7rQrRrSr�rF�r=r�r�r
r�r�rr�r�r�r�r;r
r�r>r?r@r.r.r/�
test_vgp_motd1�J�
���
�zGpoCmdTestCase.test_vgp_motdcCr`)"Nr�rr�r�r�rzIssue/manifest.xmlr�r�r�r�r�rar�rbr�rcr�r;�issuer
�Welcome to Samba!rr�r3�r�rgr�r5r6r7rQrRrSr�rFrdr.r.r/�test_vgp_issue_listXrfz"GpoCmdTestCase.test_vgp_issue_listcCrY)NrhrZr3)r�rgr�r5r6r7rQrRrSzIssue set failedrir�zIssue unset failedr�r�r]r.r.r/�test_vgp_issue_setr_z!GpoCmdTestCase.test_vgp_issue_setcs�tt|���|�dd|jddtjddtjdtjdfd	|j�\}}}|�|||d
�t	�
tj�|jd��zd|�
d
�d�
d�d|_Wnty[|�d|�Ynwtj�t��dddd�|_tj�|jd�|_dS)z#set up a temporary GPO to work withr3�creater5r6r7rQrRrSrEz!Ensuring gpo created successfullyrGrtrurvrwrz!Failed to find GUID in output: %s�source4�selftest�
provisionszgeneralized-gpo-backupr�N)�superr1�setUpr9�gpo_namerr:rIr;rJrKrrr�rH�
IndexError�fail�samba�source_tree_topdirr}r�r<��	__class__r.r/rq�s$
�"��zGpoCmdTestCase.setUpcs\|�dd|jddtjddtjdtjdf�\}}}|�|||d	�tt|���d
S)z%remove the temporary GPO to work withr3rzr5r6r7rQrRrSr{N)r9rHrr:r;rpr1�tearDownr<rwr.r/ry�s:zGpoCmdTestCase.tearDown))�__name__�
__module__�__qualname__�__doc__rrr~rArDrLrPrTrVrmr�r�r�r�r�r�r�r�r�r�r�r�rrrr2r9rHrIrUrXr^rerjrkrqry�
__classcell__r.r.rwr/r1ZsL!3WSOE*& #+j(.>A--<),'',r1)TTF)*rr)r-rdru�samba.tests.samba_tool.baserrJ�samba.netcmd.gporr�samba.paramr�samba.tests.gporr�samba.dcerpcr�	samba.ndrr	r
�samba.commonr�configparserr�ior
�xml.etree.ElementTreer�ElementTree�tempfiler�timerr�abspathr�dirname�__file__r�r0r1r.r.r.r/�<module>s&
2