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/utils/__pycache__/win_update.cpython-310.pyc
o

�N�g,��@s�dZddlZddlZddlZddlZddlZddlmZzddl	Z	ddl
ZdZWne
y3dZYnwe�e�Zdddd	�Zd
Zdd�ZGd
d�d�ZGdd�d�Zdd�ZdS)z/
Classes for working with Windows Update Agent
�N)�CommandExecutionErrorTFzNever Requires RebootzAlways Requires RebootzCan Require Reboot)r��Z
win_updatecCstjj��sdStsdStS)N)Fz%win_update: Only available on Windows)Fzwin_update: Missing pywin32)�salt�utils�platformZ
is_windows�HAS_PYWIN32�__virtualname__�r
r
�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/win_update.py�__virtual__ s
rc@s:eZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�Updatesa]
    Wrapper around the 'Microsoft.Update.UpdateColl' instance
    Adds the list and summary functions. For use by the WindowUpdateAgent class.

    Code Example:

    .. code-block:: python

        # Create an instance
        updates = Updates()

        # Bind to the collection object
        found = updates.updates

        # This exposes Collections properties and methods
        # https://msdn.microsoft.com/en-us/library/windows/desktop/aa386107(v=vs.85).aspx
        found.Count
        found.Add

        # To use custom functions, use the original instance
        # Return the number of updates inside the collection
        updates.count()

        # Return a list of updates in the collection and details in a dictionary
        updates.list()

        # Return a summary of the contents of the updates collection
        updates.summary()
    ZSoftwareZDriver)rrcCs@tjj���tj�d�|_Wd�dS1swYdS)zd
        Initialize the updates collection. Can be accessed via
        ``Updates.updates``
        �Microsoft.Update.UpdateCollN)rr�winapi�Com�win32com�client�Dispatch�updates��selfr
r
r�__init__Is"�zUpdates.__init__cCs|jjS)aN
        Return how many records are in the Microsoft Update Collection

        Returns:
            int: The number of updates in the collection

        Code Example:

        .. code-block:: python

            import salt.utils.win_update
            updates = salt.utils.win_update.Updates()
            updates.count()
        )r�Countrr
r
r�countQsz
Updates.countcCs|��dkrdSt�d�i}|jD]s}zt|jj�}Wnty,t�d�d}Ynwz|jj}WntyCt�d�d}Ynw|j	j
t|j�|j
|j|jt|j�t|j�t|j�t|j�t|j�t|j�|t|dd�|jD�d	d�|jD�|jd
�||j	j
<q|S)a�
        Create a dictionary with the details for the updates in the collection.

        Returns:
            dict: Details about each update

        .. code-block:: cfg

            Dict of Updates:
            {'<GUID>': {
                'Title': <title>,
                'KB': <KB>,
                'GUID': <the globally unique identifier for the update>,
                'Description': <description>,
                'Downloaded': <has the update been downloaded>,
                'Installed': <has the update been installed>,
                'Mandatory': <is the update mandatory>,
                'UserInput': <is user input required>,
                'EULAAccepted': <has the EULA been accepted>,
                'Severity': <update severity>,
                'NeedsReboot': <is the update installed and awaiting reboot>,
                'RebootBehavior': <will the update require a reboot>,
                'Categories': [
                    '<category 1>',
                    '<category 2>',
                    ... ]
            }}

        Code Example:

        .. code-block:: python

            import salt.utils.win_update
            updates = salt.utils.win_update.Updates()
            updates.list()
        r�Nothing to returnz*Building a detailed report of the results.�=Windows Update: Error reading InstallationBehavior COM ObjectFrcS�g|]}d|�qS�ZKBr
��.0�itemr
r
r�
<listcomp>��z Updates.list.<locals>.<listcomp>cSsg|]}|j�qSr
)�Namerr
r
rr!�s)Zguid�Title�Type�Description�
Downloaded�	InstalledZ	MandatoryZEULAAccepted�NeedsReboot�SeverityZ	UserInput�RebootBehaviorZKBs�
Categories�
SupportUrl)r�log�debugr�bool�InstallationBehaviorZCanRequestUserInput�AttributeErrorr+�Identity�UpdateID�strr$�update_typesr%r&�IsDownloaded�IsInstalled�IsMandatory�EulaAccepted�RebootRequired�MsrcSeverity�REBOOT_BEHAVIOR�KBArticleIDsr,r-)r�results�updateZ
user_input�requires_rebootr
r
r�listbsL&

����	
�zUpdates.listcCs<|��dkrdSddddiid�}|jD]�}|dd7<tjj�|j�s6tjj�|j�s6|dd7<tjj�|j�rNtjj�|j�sN|dd7<tjj�|j�r^|dd7<|jD]}|j	|d	vrv|d	|j	d7<qad|d	|j	<qa|j
r�|j
|d
vr�|d
|j
d7<qd|d
|j
<q|S)ah
        Create a dictionary with a summary of the updates in the collection.

        Returns:
            dict: Summary of the contents of the collection

        .. code-block:: cfg

            Summary of Updates:
            {'Total': <total number of updates returned>,
             'Available': <updates that are not downloaded or installed>,
             'Downloaded': <updates that are downloaded but not installed>,
             'Installed': <updates installed (usually 0 unless installed=True)>,
             'Categories': {
                <category 1>: <total for that category>,
                <category 2>: <total for category 2>,
                ... }
            }

        Code Example:

        .. code-block:: python

            import salt.utils.win_update
            updates = salt.utils.win_update.Updates()
            updates.summary()
        rr)�Total�	Availabler'r(r,r*rCrrDr'r(r,r*)rrrr�data�is_truer7r8r,r#r<)rr?r@�categoryr
r
r�summary�sF�
	����
�zUpdates.summaryN)	�__name__�
__module__�__qualname__�__doc__r6rrrBrHr
r
r
rr
(s
Yr
c
@s�eZdZdZidd�dd�dd�dd	�d
d�dd
�dd�dd�dd�dd�dd�dd�dd�dd�dd�d d!�d"d#�d$d%d&d'd(d)d*d+d,��ZdDd.d/�Zd0d1�ZdDd2d3�Zd4d5�Z	-	-	6	6	-	-	7	7dEd8d9�Z	d:d;�Z
d<d=�Zd>d?�Zd@dA�Z
dBdC�Zd7S)F�WindowsUpdateAgentz9
    Class for working with the Windows update agent
    i,@$�z'WinHTTP Send/Receive failed: 0x8024402Ci4$�zDownload failed: 0x80240034i2$�z#Invalid search criteria: 0x80240032i/$�zCancelled by policy: 0x8024002Fi-$�zMissing source: 0x8024002Di,$�zMissing source: 0x8024002C�($�z!Uninstall not allowed: 0x80240028i%$�zPrevented by policy: 0x80240025i$$�zNo Updates: 0x80240024i$�z"Service being shutdown: 0x8024001Ei$�z#Self Update in Progress: 0x8024001Bi$�z&Exclusive Install Conflict: 0x80240019i$�zInstall not allowed: 0x80240016i$�zDuplicate item: 0x80240013i$�zOperation cancelled: 0x8024000Bi	$�z!Operation in progress: 0x80240009iD$�zAccess Denied: 0x8024044z$Unsupported search scope: 0x80240045zAccess is denied: 0x80070005zSetup in progress: 0x8024004Az!Install still pending: 0x00242015zAlready downloaded: 0x00240008zAlready uninstalled: 0x00240007zAlready installed: 0x00240006zReboot required: 0x00240005)iE$�i�l����JHl�����_�l������l������l������l������TcCsXtjj���tj�d�|_tj�d�|_Wd�n1swY|j	|d�dS)aT
        Initialize the session and load all updates into the ``_updates``
        collection. This collection is used by the other class functions instead
        of querying Windows update (expensive).

        Args:

            online (bool):
                Tells the Windows Update Agent go online to update its local
                update database. ``True`` will go online. ``False`` will use the
                local update database as is. Default is ``True``

                .. versionadded:: 3001

        Need to look at the possibility of loading this into ``__context__``
        zMicrosoft.Update.SessionrN��online)
rrrrrrr�_session�_updates�refresh)rrPr
r
rr1s
�zWindowsUpdateAgent.__init__cCs&t�}|j}|jD]}|�|�q	|S)aV
        Get the contents of ``_updates`` (all updates) and puts them in an
        Updates class to expose the list and summary functions.

        Returns:

            Updates:
                An instance of the Updates class with all updates for the
                system.

        Code Example:

        .. code-block:: python

            import salt.utils.win_update
            wua = salt.utils.win_update.WindowsUpdateAgent()
            updates = wua.updates()

            # To get a list
            updates.list()

            # To get a summary
            updates.summary()
        )r
rrR�Add)rr�foundr@r
r
rrMs

zWindowsUpdateAgent.updatescCs�d}|j��}||_d|j_z|�|�}|jjdkr&t�d|�d|��WSWn7t	j
y^}z*|j\}}}}	z	|j|d}
Wnt
yNd|��}
Ynwt�d|
|�t|
��d	}~ww|j|_d	S)
a�
        Refresh the contents of the ``_updates`` collection. This gets all
        updates in the Windows Update system and loads them into the collection.
        This is the part that is slow.

        Args:

            online (bool):
                Tells the Windows Update Agent go online to update its local
                update database. ``True`` will go online. ``False`` will use the
                local update database as is. Default is ``True``

                .. versionadded:: 3001

        Code Example:

        .. code-block:: python

            import salt.utils.win_update
            wua = salt.utils.win_update.WindowsUpdateAgent()
            wua.refresh()
        z Type='Software' or Type='Driver'zSalt: Load UpdatesrzNo Updates found for:
		%szNo Updates found: ��Unknown Failure: zSearch Failed: %s
		%sN)rQZCreateUpdateSearcherZOnline�ClientApplicationIDZSearchr
rr.r/�
pywintypes�	com_error�args�
fail_codes�KeyError�errorrrR)rrP�
search_stringZsearcherr?r^�hr�msg�exc�arg�failure_coder
r
rrSns,

����zWindowsUpdateAgent.refreshcCs2t�}|jD]}tjj�|j�r|j�|�q|S)a�
        Gets a list of all updates available on the system that have the
        ``IsInstalled`` attribute set to ``True``.

        Returns:

            Updates: An instance of Updates with the results.

        Code Example:

        .. code-block:: python

            import salt.utils.win_update
            wua = salt.utils.win_update.WindowsUpdateAgent(online=False)
            installed_updates = wua.installed()
        )	r
rRrrrErFr8rrT)rrr@r
r
r�	installed�s
�zWindowsUpdateAgent.installedFNc		Cs(t�}	|	j}
|jD]�}z&tjj�|j�r|rWq	tjj�|j�r$|r$Wq	tjj�|j	�r0|r0Wq	Wn	t
y:Yq	wztjj�|jj�}Wnt
yVt
�d�d}Ynw|r\|r\q	|sd|jdkrdq	|sl|jdkrlq	|dur�d}
|jD]	}|j|vr~d}
qu|
s�q	|dur�|j|vr�q	|
�|�q	|	S)a�
        Gets a list of all updates available on the system that match the passed
        criteria.

        Args:

            skip_hidden (bool):
                Skip hidden updates. Default is ``True``

            skip_installed (bool):
                Skip installed updates. Default is ``True``

            skip_mandatory (bool):
                Skip mandatory updates. Default is ``False``

            skip_reboot (bool):
                Skip updates that can or do require reboot. Default is ``False``

            software (bool):
                Include software updates. Default is ``True``

            drivers (bool):
                Include driver updates. Default is ``True``

            categories (list):
                Include updates that have these categories. Default is none
                (all categories). Categories include the following:

                * Critical Updates
                * Definition Updates
                * Drivers (make sure you set drivers=True)
                * Feature Packs
                * Security Updates
                * Update Rollups
                * Updates
                * Update Rollups
                * Windows 7
                * Windows 8.1
                * Windows 8.1 drivers
                * Windows 8.1 and later drivers
                * Windows Defender

            severities (list):
                Include updates that have these severities. Default is none
                (all severities). Severities include the following:

                * Critical
                * Important

        .. note::

            All updates are either software or driver updates. If both
            ``software`` and ``drivers`` is ``False``, nothing will be returned.

        Returns:

            Updates: An instance of Updates with the results of the search.

        Code Example:

        .. code-block:: python

            import salt.utils.win_update
            wua = salt.utils.win_update.WindowsUpdateAgent()

            # Gets all updates and shows a summary
            updates = wua.available()
            updates.summary()

            # Get a list of Critical updates
            updates = wua.available(categories=['Critical Updates'])
            updates.list()
        rTrrNF)r
rrRrrrErFZIsHiddenr8r9r2r1r+r.r/r%r,r#r<rT)rZskip_hiddenZskip_installedZskip_mandatoryZskip_rebootZsoftwareZdrivers�
categoriesZ
severitiesrrUr@rA�matchrGr
r
r�	available�sVU
�����

�
zWindowsUpdateAgent.availablecCs�t�}|j}t|t�r|g}t|t�rt|�g}|jD]>}|D]9}||jjkr-|�|�q|dd�|j	D�vr=|�|�q|dd�|j	D�vrM|�|�q||j
vrX|�|�qqq|S)a;
        Search for either a single update or a specific list of updates. GUIDs
        are searched first, then KB numbers, and finally Titles.

        Args:

            search_string (str, list):
                The search string to use to find the update. This can be the
                GUID or KB of the update (preferred). It can also be the full
                Title of the update or any part of the Title. A partial Title
                search is less specific and can return multiple results.

        Returns:
            Updates: An instance of Updates with the results of the search

        Code Example:

        .. code-block:: python

            import salt.utils.win_update
            wua = salt.utils.win_update.WindowsUpdateAgent()

            # search for a single update and show its details
            updates = wua.search('KB3194343')
            updates.list()

            # search for a list of updates and show their details
            updates = wua.search(['KB3195432', '12345678-abcd-1234-abcd-1234567890ab'])
            updates.list()
        cSrrr
rr
r
rr!zr"z-WindowsUpdateAgent.search.<locals>.<listcomp>cSsg|]}|�qSr
r
rr
r
rr!s)r
r�
isinstancer5�intrRr3r4rTr>r$)rr_rrUr@�findr
r
r�searchHs.








��zWindowsUpdateAgent.searchcCsn|��dkr
ddd�}|S|j��}d|j_tjj����tj	�
d�}dii}|jD]M}|jj
}i|d|<|j|d|d<t|j�|d|d	<tjj�|j�s^t�d
|j�|��tjj�|j�sxt�d|�t�d|j�|�|�q+|jdkr�d
dd�}|Wd�S||_zt�d�|��}Wn6tjy�}z)|j\}	}
}}z	|j|d}
Wnty�d|��}
Ynwt� d|
�t!|
��d}~wwddddddd�}t�d�t�||j"�||j"|d<|j"dvr�t�d�d
|d<n	t�d�d|d<t#|j�D]}|�$|�jj
}||�%|�j"|d|d<�qWd�|S1�s0wY|S) a�
        Download the updates passed in the updates collection. Load the updates
        collection using ``search`` or ``available``

        Args:

            updates (Updates):
                An instance of the Updates class containing a the updates to be
                downloaded.

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

        Code Example:

        .. code-block:: python

            import salt.utils.win_update
            wua = salt.utils.win_update.WindowsUpdateAgent()

            # Download KB3195454
            updates = wua.search('KB3195454')
            results = wua.download(updates)
        rFzNothing to download��Successr
zSalt: Download Updaterr
r$ZAlreadyDownloadedzAccepting EULA: %szTo Be Downloaded: %s�
	Title: %sTNzDownloading UpdatesrVrWzDownload Failed: %szDownload Not StartedzDownload In ProgresszDownload SucceededzDownload Succeeded With ErrorszDownload FailedzDownload Aborted�rrr��rVzDownload Complete�Message�rrqzDownloaded Successfullyrn�Result)&rrQZCreateUpdateDownloaderrXrrrrrrrrr3r4r$r0r7rErFr:r.r/Z
AcceptEularTrr
ZDownloadrYrZr[r\r]r^r�
ResultCode�range�Item�GetUpdateResult)rr�retZ
downloaderZ
download_listr@�uid�resultr^r`rarbrcrd�result_code�ir
r
r�download�s�



�

�
���
�
	




��
�M�MzWindowsUpdateAgent.downloadcCs�|��dkr
ddd�}|S|j��}d|j_tjj����'tj	�
d�}dii}|jD]:}|jj
}i|d|<|j|d|d<t|j�|d|d	<tjj�|j�set�d
|�t�d|j�|�|�q+|jdkryddd�}|Wd
�S||_zt�d�|��}Wn6tjy�}z)|j\}	}
}}z	|j|d}
Wnty�d|��}
Ynwt�d|
�t|
��d
}~wwddddddd�}t�d�t�||j �||j |d<|j dvr�d|d<|j!|d<t�d|j!�n	t�d�d|d<t"|j�D]<}|�#|�jj
}||�$|�j |d|d <z	|�#|�j%j&}Wnt'�y0t�d!�d"}Ynwt(||d|d#<q�Wd
�|S1�sHwY|S)$a#
        Install the updates passed in the updates collection. Load the updates
        collection using the ``search`` or ``available`` functions. If the
        updates need to be downloaded, use the ``download`` function.

        Args:

            updates (Updates):
                An instance of the Updates class containing a the updates to be
                installed.

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

        Code Example:

        .. code-block:: python

            import salt.utils.win_update
            wua = salt.utils.win_update.WindowsUpdateAgent()

            # install KB3195454
            updates = wua.search('KB3195454')
            results = wua.download(updates)
            results = wua.install(updates)
        rFzNothing to installrmzSalt: Install Updaterr
r$ZAlreadyInstalledzTo Be Installed: %sroTNzInstalling UpdatesrVrWzInstall Failed: %szInstallation Not StartedzInstallation In ProgresszInstallation Succeededz"Installation Succeeded With ErrorszInstallation FailedzInstallation AbortedrpzInstall Completersrtrnr)�NeedsReboot: %szInstall Failedrurrr+))rrQ�CreateUpdateInstallerrXrrrrrrrrr3r4r$r0r8rErFr.r/rTrr
ZInstallrYrZr[r\r]r^rrvr;rwrxryr1r+r2r=)rrrz�	installerZinstall_listr@r{r|r^r`rarbrcrdr}r~�reboot_behaviorr
r
r�install�s�



�

�
���
�
	



������
�V�VzWindowsUpdateAgent.installcCs�|��dkr
ddd�}|S|j��}d|j_tjj����"tj	�
d�}dii}|jD];}|jj
}i|d|<|j|d|d<t|j�|d|d	<tjj�|j�rft�d
|�t�d|j�|�|�q+|jdkrzddd�}|Wd�S||_zt�d
�|��}W�n-tj�y�}�z|j\}	}
}}z	|j|d}
Wnty�d|��}
Ynw|ddk�r�t�d�zB|D]=}|jD]7}gd�}|�|�d� �}|D]%}d||�!�vr�|�"d�d}||d<dddd|��ddg}|�|�q�q�q�Wn(t#�y)}zt�d�t�dd�$|��t�d |�t#d!|����d}~wwt�d"�d#|d$<d%|d&<t%�|d'<t�d(|d'�|j&dd)�|j'D]K}|jj
}|D]A}|jj
|k�r�|j�skd*|d|d+<nd,|d|d+<z|j(j)}Wnt*�y�t�d-�d.}Ynwt+||d|d/<�qU�qM|WYd}~Wd�St�,d0|
�t#|
��d}~wwd1d2d*d3d,d4d5�}t�d6�t�||j-�||j-|d&<|j-d7v�r�d#|d$<|j.|d'<t�d(|j.�n	t�d8�d|d$<t/|j�D]=}|�0|�jj
}||�1|�j-|d|d+<z	|�0|�j(j)}Wnt*�y*t�d-�d.}Ynwt+||d|d/<�q�Wd�|S1�sCwY|S)9ah
        Uninstall the updates passed in the updates collection. Load the updates
        collection using the ``search`` or ``available`` functions.

        .. note::

            Starting with Windows 10 the Windows Update Agent is unable to
            uninstall updates. An ``Uninstall Not Allowed`` error is returned.
            If this error is encountered this function will instead attempt to
            use ``dism.exe`` to perform the un-installation. ``dism.exe`` may
            fail to to find the KB number for the package. In that case, removal
            will fail.

        Args:

            updates (Updates):
                An instance of the Updates class containing a the updates to be
                uninstalled.

        Returns:
            dict: A dictionary containing the results of the un-installation

        Code Example:

        .. code-block:: python

            import salt.utils.win_update
            wua = salt.utils.win_update.WindowsUpdateAgent()

            # uninstall KB3195454
            updates = wua.search('KB3195454')
            results = wua.uninstall(updates)
        rFzNothing to uninstallrmzSalt: Uninstall Updaterr
r$ZAlreadyUninstalledzTo Be Uninstalled: %sroNzUninstalling UpdatesrVrWrNz/Uninstall Failed with WUA, attempting with DISM)�dism�/Onlinez
/Get-Packages�kbz : rZDismPackager�r�z/Remove-Packagez
/PackageName:z/Quietz
/NoRestartzUninstall using DISM failedzCommand: %s� �	Error: %szUninstall using DISM failed: zUninstall Completed using DISMTrnzUninstalled using DISMrsr)r�rOzUninstallation SucceededruzUninstallation Failedrrr+zUninstall Failed: %szUninstallation Not StartedzUninstallation In Progressz$Uninstallation Succeeded With ErrorszUninstallation AbortedrpzUninstall CompletertzUninstall Failed)2rrQr�rXrrrrrrrrr3r4r$r0r8rErFr.r/rTrr
Z	UninstallrYrZr[r\r]r>�_run�
splitlines�lower�splitr�join�needs_rebootrSrRr1r+r2r=r^rvr;rwrxry)rrrzr�Zuninstall_listr@r{r|r^r`rarbrcrdr r��cmdZpkg_listZpkgrAr}r~r�r
r
r�	uninstallus((



�

�
�

�
	����
���
	


��
�����������f�
	


�������
�0��0zWindowsUpdateAgent.uninstallc
Cs�t|t�rtjj�|�}zt�|�tj	|tj
tj
d�}|��WSty?}zt�dd�
|��t�d|�t|��d}~ww)z�
        Internal function for running commands. Used by the uninstall function.

        Args:
            cmd (str, list):
                The command to run

        Returns:
            str: The stdout of the command
        )�stdout�stderrzCommand Failed: %sr�r�N)rir5rrr[Zshlex_splitr.r/�
subprocess�Popen�PIPE�communicate�OSErrorr�r)rr��prbr
r
rr�Ts


��zWindowsUpdateAgent._run)T)TTFFTTNN)rIrJrKrLr\rrrSrerhrlrr�r�r�r
r
r
rrM
s���������	�
���
������

!2
�Bqz`rMcCs�tjj���@ztj�d�}Wn'tjy6}z|j	\}}}}t
�d|�WYd}~Wd�dSd}~wwtjj�
|j�Wd�S1sIwYdS)a
    Determines if the system needs to be rebooted.

    Returns:

        bool: ``True`` if the system requires a reboot, ``False`` if not

    CLI Examples:

    .. code-block:: bash

        import salt.utils.win_update

        salt.utils.win_update.needs_reboot()

    zMicrosoft.Update.SystemInfoz&Failed to create SystemInfo object: %sNF)rrrrrrrrYrZr[r.r/rErFr;)Zobj_sysrb�_rar
r
rr�ns
��$�r�)rL�loggingr�Zsalt.utils.argsrZsalt.utils.dataZsalt.utils.winapiZsalt.exceptionsrrYZwin32com.clientrr�ImportError�	getLoggerrIr.r=r	rr
rMr�r
r
r
r�<module>s>�
�fg