File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/win_lgpo_reg.cpython-310.pyc
Back
o ;j| � @ s� d Z ddlZddlZddlZddlZddlZddlZddlm Z e� e�ZdZ dZdddd d ddd dd� Zdd� Zdd� Zd)dd�Zd)dd�Zd)dd�Zd)dd�Zdd� Z d*d d!�Z " d+d#d$�Z d,d%d&�Zd'd(� ZdS )-a� LGPO - Registry.pol =================== .. versionadded:: 3006.0 A module for working with registry based policies in Windows Local Group Policy (LGPO). This module contains functions for working with the ``Registry.pol`` file. The ``Registry.pol`` file is the source of truth for registry settings and LGPO. Group Policy is refreshed every 90 seconds by default. During that refresh the contents of the ``Registry.pol`` file are applied to the Registry. If the setting is changed outside of Group Policy to something other than what is contained in the ``Registry.pol`` file, it will be changed back during the next refresh. In the Group Policy Editor (``gpedit.msc``) these policies can be set to three states: - Not Configured - Enabled - Disabled A policy that is "Not Configured" does not have an entry in the ``Registry.pol`` file. A Group Policy refresh will not make any changes to key/value pairs in the registry that are not specified in the ``Registry.pol`` file. An "Enabled" policy will have an entry in the ``Registry.pol`` files that contains its key path, value name, value type, value size, and value data. When Group Policy is refreshed, existing values will be overwritten with those contained in the ``Registry.pol`` file. A "Disabled" policy will have an entry in the ``Registry.pol`` file with the key path and the value name, but the value name will be prepended with ``**del.``. When Group Policy is refreshed the key/value will be deleted from the registry. If the key contains no values, it will also be deleted. Working with LGPO Reg --------------------- The easiest way to figure out the values needed for this module is to set the policy using the Group Policy Editor (``gpedit.msc``) and then run the ``lgpo_reg.read_reg_pol`` function. This function will display a dictionary of all registry-based policies in the ``Registry.pol`` file. From its return you can get the ``key``, ``v_name``, ``v_type``, and ``v_data`` required to "enable" that policy. Use those values to set/disable/delete policies using this module. The same values can also be used to create states for setting these policies. .. note:: Not all policies in the Group Policy Editor (``gpedit.msc``) that write to the registry make that change in the ``Registry.pol`` file. Those policies could still be enforced via the ``Registry.pol`` file... theoretically. But you will have to find the values needed to set them with this module using a different method. � N)�SaltInvocationErrorZlgpo_regz&{00000000-0000-0000-0000-000000000000}ZREG_NONE�REG_SZ� REG_EXPAND_SZ� REG_BINARY� REG_DWORDZREG_DWORD_BIG_ENDIANZREG_LINK�REG_MULTI_SZ� REG_QWORD) r � � � � � � � � c C s t jj�� sdS tS )z Only works on Windows )Fz*LGPO_REG Module: Only available on Windows)�salt�utils�platformZ is_windows�__virtualname__� r r �M/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/win_lgpo_reg.py�__virtual__U s r c C s� d}d}| D ]5}|� � |� � kr;|}| | D ]$}|� � �d�r0|� � |� � �dd�d kr/|}q|� � |� � kr:|}qq||fS )a Helper function to find the value in the registry.pol file. Sometimes the value is prepended by an action that needs to happen with that value, such as `**del.` to delete it from the registry. Returns: tuple: A tuple containing: found_key, found_name � �**del.�.r )�lower� startswith�split)�pol_data�key�v_name� found_key� found_name�p_keyZp_namer r r �_find_value_ s ��r$ �Machinec C s\ | � � dv r d} n | � � dv rd} ntd��tjjj| }tjjj|d d�}tjj�|�S )am Read the contents of the Registry.pol file. Display the contents as a human-readable dictionary. Args: policy_class (:obj:`str`, optional): The registry class to retrieve. Can be one of the following: - Computer - Machine - User Default is ``Machine``. Raises: SaltInvocationError: Invalid policy class Returns: dict: A dictionary representing the contents of the Registry.pol file CLI Example: .. code-block:: bash # Read the machine Registry.pol salt '*' lgpo_reg.read_reg_pol �Zcomputer�machiner% ��user�User�%An invalid policy class was specified�policy_path)Zreg_pol_path)r r r r �win_lgpo_reg� CLASS_INFOZread_reg_pol_fileZreg_pol_to_dict)�policy_classZpol_infoZ pol_file_datar r r �read_reg_polw s �r0 c C sh |� � dv r d}n |� � dv rd}ntd��tjjj| }tjj�| �}tjj�||d |d |d �S ) a Write data to the Registry.pol file. The data is a dictionary that is then converted to the appropriate bytes format expected by Registry.pol Args: data (dict): A dictionary containing Registry.pol data policy_class (:obj:`str`, optional): The registry class to write to. Can be one of the following: - Computer - Machine - User Default is ``Machine``. Raises: SaltInvocationError: Invalid policy class CommandExecutionError: On failure Returns: bool: True if successful CLI Example: .. code-block:: bash # Write to Machine Registry.pol salt '*' lgpo_reg.write_reg_pol "{'SOFTWARE\MyKey': {'MyValue': 'data': 1, 'type': 'REG_DWORD'}}" r&