HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/win_dism.cpython-310.pyc
o

�N�g�Q�@s�dZddlZddlZddlZddlZddlZddlmZe�	e
�ZdZz7ej
j��s,e�ej�ej�ej�d�d��rGej�ej�d�d�Znej�ej�d�d�Zej�ed�ZWneyje�d	�dZYnwd
d�Zd/dd
�Z	d0dd�Zd1dd�Zd/dd�Zd/dd�Zd/dd�Z						d2dd�Z d3dd�Z!d4dd�Z"d/dd �Z#d/d!d"�Z$	d5d#d$�Z%d1d%d&�Z&d/d'd(�Z'd1d)d*�Z(d/d+d,�Z)d/d-d.�Z*dS)6u�
Install features/packages for Windows using DISM, which is useful for minions
not running server versions of Windows. Some functions are only available on
Windows 10.

�N)�CommandExecutionErrorZdismZ
SystemRootZ	SysNativeZSystem32zdism.exezwin_dism: Non-Windows systemcCstjj��sdStS)z
    Only work on Windows
    )Fz!Only available on Windows systems)�salt�utils�platform�
is_windows�__virtualname__�rr�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/win_dism.py�__virtual__)sr
cCsXtd|r	d|��ndd|��g}td|�}|�d|�d�}t�||tj�}|��|S)N�/English�/Image:�/Onlinez/Get-�cmd.runz : (.*)\r\n.*State : z\r\n)�bin_dism�__salt__�re�findall�	MULTILINE�sort)�
type_regex�plural_type�
install_value�image�cmd�out�pattern�capabilitiesrrr	�_get_components3s�rFcCs�tjj�tdd�dkrtd�td���td|rd|��nddd	|��g}|r0|�d
|���|r7|�d�|s>|�d�t	d
|�S)a�
    Install a capability

    Args:
        capability (str): The capability to install
        source (Optional[str]): The optional source of the capability. Default
            is set by group policy and can be Windows Update.
        limit_access (Optional[bool]): Prevent DISM from contacting Windows
            Update for the source package
        image (Optional[str]): The path to the root directory of an offline
            Windows image. If `None` is passed, the running operating system is
            targeted. Default is None.
        restart (Optional[bool]): Reboot the machine if required by the install

    Raises:
        NotImplementedError: For all versions of Windows that are not Windows 10
        and later. Server editions of Windows use ServerManager instead.

    Returns:
        dict: A dictionary containing the results of the command

    CLI Example:

    .. code-block:: bash

        salt '*' dism.add_capability Tools.Graphics.DirectX~~~~0.0.1.0
    �	osversion�10���zD`install_capability` is not available on this version of Windows: {}�/Quietrr
z/Add-Capability�/CapabilityName:�/Source:�/LimitAccess�
/NoRestart�cmd.run_all�
rr�versions�version_cmp�
__grains__�NotImplementedError�formatr�appendr)�
capability�source�limit_accessr�restartrrrr	�add_capabilityAs$
��

r2cCsftjj�tdd�dkrtd�td���td|rd|��nddd	|��g}|s-|�d
�t	d|�S)a�
    Uninstall a capability

    Args:
        capability(str): The capability to be removed
        image (Optional[str]): The path to the root directory of an offline
            Windows image. If `None` is passed, the running operating system is
            targeted. Default is None.
        restart (Optional[bool]): Reboot the machine if required by the install

    Raises:
        NotImplementedError: For all versions of Windows that are not Windows 10
        and later. Server editions of Windows use ServerManager instead.

    Returns:
        dict: A dictionary containing the results of the command

    CLI Example:

    .. code-block:: bash

        salt '*' dism.remove_capability Tools.Graphics.DirectX~~~~0.0.1.0
    rrr zF`uninstall_capability` is not available on this version of Windows: {}r!rr
z/Remove-Capabilityr"r%r&r')r.rr1rrrr	�remove_capabilityws
��
r3cCsptjj�tdd�dkrtd�td���td|rd|��nddg}td	|�}d
}t	�
||t	j�}|��|S)a)
    List all capabilities on the system

    Args:
        image (Optional[str]): The path to the root directory of an offline
            Windows image. If `None` is passed, the running operating system is
            targeted. Default is None.

    Raises:
        NotImplementedError: For all versions of Windows that are not Windows 10
        and later. Server editions of Windows use ServerManager instead.

    Returns:
        list: A list of capabilities

    CLI Example:

    .. code-block:: bash

        salt '*' dism.get_capabilities
    rrr �H`installed_capabilities` is not available on this version of Windows: {}rrr
z/Get-CapabilitiesrzCapability Identity : (.*)\r\n)
rrr(r)r*r+r,rrrrrr)rrrrrrrr	�get_capabilities�s
��r5cC�6tjj�tdd�dkrtd�td���tddd�S)aC
    List the capabilities installed on the system

    Args:
        image (Optional[str]): The path to the root directory of an offline
            Windows image. If `None` is passed, the running operating system is
            targeted. Default is None.

    Raises:
        NotImplementedError: For all versions of Windows that are not Windows 10
        and later. Server editions of Windows use ServerManager instead.

    Returns:
        list: A list of installed capabilities

    CLI Example:

    .. code-block:: bash

        salt '*' dism.installed_capabilities
    rrr r4�Capability Identity�Capabilities�	Installed�rrr(r)r*r+r,r�rrrr	�installed_capabilities��
�r<cCr6)aC
    List the capabilities available on the system

    Args:
        image (Optional[str]): The path to the root directory of an offline
            Windows image. If `None` is passed, the running operating system is
            targeted. Default is None.

    Raises:
        NotImplementedError: For all versions of Windows that are not Windows 10
        and later. Server editions of Windows use ServerManager instead.

    Returns:
        list: A list of available capabilities

    CLI Example:

    .. code-block:: bash

        salt '*' dism.installed_capabilities
    rrr r4r7r8zNot Presentr:r;rrr	�available_capabilities�r=r>cCs�td|r	d|��nddd|��g}|r|�d|���|r%|�d|���|r,|�d�|r3|�d	�|s:|�d
�td|�S)a|
    Install a feature using DISM

    Args:
        feature (str): The feature to install
        package (Optional[str]): The parent package for the feature. You do not
            have to specify the package if it is the Windows Foundation Package.
            Otherwise, use package to specify the parent package of the feature
        source (Optional[str]): The optional source of the capability. Default
            is set by group policy and can be Windows Update
        limit_access (Optional[bool]): Prevent DISM from contacting Windows
            Update for the source package
        enable_parent (Optional[bool]): True will enable all parent features of
            the specified feature
        image (Optional[str]): The path to the root directory of an offline
            Windows image. If `None` is passed, the running operating system is
            targeted. Default is None.
        restart (Optional[bool]): Reboot the machine if required by the install

    Returns:
        dict: A dictionary containing the results of the command

    CLI Example:

    .. code-block:: bash

        salt '*' dism.add_feature NetFx3
    r!rr
z/Enable-Feature�
/FeatureName:�
/PackageName:r#r$z/Allr%r&�rr-r)�feature�packager/r0Z
enable_parentrr1rrrr	�add_feature
s"&�


rDcCsJtd|r	d|��nddd|��g}|r|�d�|s|�d�td|�S)	a�
    Disables the feature.

    Args:
        feature (str): The feature to uninstall
        remove_payload (Optional[bool]): Remove the feature's payload. Must
            supply source when enabling in the future.
        image (Optional[str]): The path to the root directory of an offline
            Windows image. If `None` is passed, the running operating system is
            targeted. Default is None.
        restart (Optional[bool]): Reboot the machine if required by the install

    Returns:
        dict: A dictionary containing the results of the command

    CLI Example:

    .. code-block:: bash

        salt '*' dism.remove_feature NetFx3
    r!rr
z/Disable-Featurer?z/Remover%r&rA)rBZremove_payloadrr1rrrr	�remove_featureDs�

rEcCsttd|r	d|��nddg}|r$d|vr|�d|���n|�d|���td|�}d	}t�||tj�}|��|S)
aU
    List features on the system or in a package

    Args:
        package (Optional[str]): The full path to the package. Can be either a
            .cab file or a folder. Should point to the original source of the
            package, not to where the file is installed. You cannot use this
            command to get package information for .msu files

            This can also be the name of a package as listed in
            ``dism.installed_packages``
        image (Optional[str]): The path to the root directory of an offline
            Windows image. If `None` is passed, the running operating system is
            targeted. Default is None.

    Returns:
        list: A list of features

    CLI Example:

        .. code-block:: bash

            # Return all features on the system
            salt '*' dism.get_features

            # Return all features in package.cab
            salt '*' dism.get_features C:\packages\package.cab

            # Return all features in the calc package
            salt '*' dism.get_features Microsoft.Windows.Calc.Demo~6595b6144ccf1df~x86~en~1.0.0.0
    rrr
z
/Get-Features�~r@�
/PackagePath:rzFeature Name : (.*)\r\n)rr-rrrrr)rCrrrrZfeaturesrrr	�get_featuresjs!�rHcC�tddd�S)a�
    List the features installed on the system

    Args:
        image (Optional[str]): The path to the root directory of an offline
            Windows image. If `None` is passed, the running operating system is
            targeted. Default is None.

    Returns:
        list: A list of installed features

    CLI Example:

    .. code-block:: bash

        salt '*' dism.installed_features
    �Feature Name�FeaturesZEnabled�rr;rrr	�installed_features��rMcCrI)a�
    List the features available on the system

    Args:
        image (Optional[str]): The path to the root directory of an offline
            Windows image. If `None` is passed, the running operating system is
            targeted. Default is None.

    Returns:
        list: A list of available features

    CLI Example:

    .. code-block:: bash

        salt '*' dism.available_features
    rJrKZDisabledrLr;rrr	�available_features�rNrOcCsXtd|r	d|��nddd|��g}|r|�d�|r|�d�|s&|�d�td	|�S)
a
    Install a package using DISM

    Args:
        package (str):
            The package to install. Can be a .cab file, a .msu file, or a folder

            .. note::
                An `.msu` package is supported only when the target image is
                offline, either mounted or applied.

        ignore_check (Optional[bool]):
            Skip installation of the package if the applicability checks fail

        prevent_pending (Optional[bool]):
            Skip the installation of the package if there are pending online
            actions

        image (Optional[str]):
            The path to the root directory of an offline Windows image. If
            ``None`` is passed, the running operating system is targeted.
            Default is None.

        restart (Optional[bool]):
            Reboot the machine if required by the install

    Returns:
        dict: A dictionary containing the results of the command

    CLI Example:

    .. code-block:: bash

        salt '*' dism.add_package C:\Packages\package.cab
    r!rr
z/Add-PackagerGz/IgnoreCheckz/PreventPendingr%r&rA)rCZignore_checkZprevent_pendingrr1rrrr	�add_package�s'�


rPcCs^td|r	d|��nddg}|s|�d�d|vr!|�d|���n|�d|���td	|�S)
a�
    Uninstall a package

    Args:
        package (str): The full path to the package. Can be either a .cab file
            or a folder. Should point to the original source of the package, not
            to where the file is installed. This can also be the name of a
            package as listed in ``dism.installed_packages``
        image (Optional[str]): The path to the root directory of an offline
            Windows image. If `None` is passed, the running operating system is
            targeted. Default is None.
        restart (Optional[bool]): Reboot the machine if required by the
            uninstall

    Returns:
        dict: A dictionary containing the results of the command

    CLI Example:

    .. code-block:: bash

        # Remove the Calc Package
        salt '*' dism.remove_package Microsoft.Windows.Calc.Demo~6595b6144ccf1df~x86~en~1.0.0.0

        # Remove the package.cab (does not remove C:\packages\package.cab)
        salt '*' dism.remove_package C:\packages\package.cab
    r!rr
z/Remove-Packager%rFr@rGr&rA)rCrr1rrrr	�remove_packages�
rQcCsPt|d�}|���d�r|��nd|��}|D]}d|�d�|vr%|SqdS)a

    Get the actual package name on the system based on the KB name

    .. versionadded:: 3006.0

    Args:
        kb (str): The name of the KB to remove. Can also be just the KB number
        image (Optional[str]): The path to the root directory of an offline
            Windows image. If `None` is passed, the running operating system is
            targeted. Default is None.

    Returns:
        str: The name of the package found on the system
        None: If the package is not installed on the system

    CLI Example:

    .. code-block:: bash

        # Get the package name for KB1231231
        salt '*' dism.get_kb_package_name KB1231231

        # Get the package name for KB1231231 using just the number
        salt '*' dism.get_kb_package_name 1231231
    r;�kbZKB�_rFN)�installed_packages�lower�
startswith�upper)rRrZpackages�searchrCrrr	�get_kb_package_name0s
 �rYcCs@t||d�}|dur|�d�}t|��t�d|�t|||d�S)a�
    Remove a package by passing a KB number. This searches the installed
    packages to get the full package name of the KB. It then calls the
    ``dism.remove_package`` function to remove the package.

    .. versionadded:: 3006.0

    Args:
        kb (str): The name of the KB to remove. Can also be just the KB number
        image (Optional[str]): The path to the root directory of an offline
            Windows image. If `None` is passed, the running operating system is
            targeted. Default is None.
        restart (Optional[bool]): Reboot the machine if required by the
            uninstall

    Returns:
        dict: A dictionary containing the results of the command

    CLI Example:

    .. code-block:: bash

        # Remove the KB5007575 just passing the number
        salt '*' dism.remove_kb 5007575

        # Remove the KB5007575 just passing the full name
        salt '*' dism.remove_kb KB5007575
    )rRrNz not installedz	Found: %s)rCrr1)rYr�log�debugrQ)rRrr1�pkg_name�msgrrr	�	remove_kbRs
r^cCstddd|d�S)a�
    List the packages installed on the system

    Args:
        image (Optional[str]): The path to the root directory of an offline
            Windows image. If `None` is passed, the running operating system is
            targeted. Default is None.

    Returns:
        list: A list of installed packages

    CLI Example:

    .. code-block:: bash

        salt '*' dism.installed_packages
    zPackage IdentityZPackagesr9)rrrrrLr;rrr	rTws�rTcCs�td|r	d|��nddg}d|vr|�d|���n|�d|���td|�}|d	d
krVt�}t|d���D]}d|vrS|�d�}t|�d
krKq9|d||d
<q9|S|}|S)a�
    Display information about a package

    Args:
        package (str): The full path to the package. Can be either a .cab file
            or a folder. Should point to the original source of the package, not
            to where the file is installed. You cannot use this command to get
            package information for .msu files
        image (Optional[str]): The path to the root directory of an offline
            Windows image. If `None` is passed, the running operating system is
            targeted. Default is None.

    Returns:
        dict: A dictionary containing the results of the command

    CLI Example:

    .. code-block:: bash

        salt '*' dism. package_info C:\packages\package.cab
    rrr
z/Get-PackageInforFr@rGr&�retcoder�stdoutz : ��)rr-r�dict�str�
splitlines�split�len)rCrrr�ret�line�inforrr	�package_info�s*�
��rk)N)NFNF)NF)NNFFNF)FNF)NN)FFNF)+�__doc__�logging�osrZsalt.utils.platformrZsalt.utils.versionsZsalt.exceptionsr�	getLogger�__name__rZrrrr�OSError�path�exists�join�environ�getZbin_pathrZtracer
rr2r3r5r<r>rDrErHrMrOrPrQrYr^rTrkrrrr	�<module>s\

�


�
6
,
+
 
�
:
&
6

�
8
.
"
%