AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /proc/thread-self/root/usr/lib/python3/dist-packages/uaclient/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /proc/thread-self/root/usr/lib/python3/dist-packages/uaclient/__pycache__/security.cpython-310.pyc
o

F��c���@s�ddlZddlZddlZddlZddlZddlZddlmZddlmZddl	m
Z
mZmZm
Z
mZmZmZddlmZmZmZmZmZmZddlmZmZmZddlmZddlmZm Z dd	l!m"Z"dd
l#m$Z$m%Z%ddl&m'Z'dZ(d
Z)dZ*dZ+dZ,dZ-dZ.dZ/e
dde0fdee1fdee1fde0fg�Z2ej3Gdd�dej4��Z5Gdd�dej6�Z7Gdd�d�Z8Gdd �d �Z9Gd!d"�d"�Z:d#ee1ee1e1fffd$d%�Z;d&ee:d'ee1e0fd#ee1ee1ee1e1ffffd(d)�Z<d*d+�Z=	,dod-ed.e1d/e0d#e5fd0d1�Z>d2d3�Z?d4d5�Z@d6e:d7ee1ee1e1ffd#ee1e8ffd8d9�ZAd:e9d7ee1ee1e1ffd#ee1e8ffd;d<�ZBd.e1d=ee1e8ffd>d?�ZCd@e8dAee1ee1e1ffd#e8fdBdC�ZDdDdE�ZEdFeee1e8fdGeFdHeFd#e1fdIdJ�ZGdKe1d-efdLdM�ZHdKe1d-ed#e0fdNdO�ZId-edPee1eee1e8ffdQee1ee1fdGeFdHeFd/e0d#e2fdRdS�ZJdee1d#e1fdTdU�ZKd-ed.e1d=ee1e8fd7ee1ee1e1ffdVee1ee1ee1e1fffd/e0d#e5fdWdX�ZLdpdYdZ�ZMd-ed[e1d#e0fd\d]�ZNd-ed#e0fd^d_�ZOd-ed`e1d#e0fdadb�ZPd-ed/e0d#e0fdcdd�ZQdKe1d-ed/e0d#e0fdedf�ZRd-ed#e0fdgdh�ZSdiee1e
fd-ed/e0d#e0fdjdk�ZTd-edlee1dKe1d/e0d#e0f
dmdn�ZUdS)q�N)�defaultdict)�datetime)�Any�Dict�List�
NamedTuple�Optional�Set�Tuple)�apt�
exceptions�messages�
serviceclient�system�util)�CLOUD_TYPE_TO_TITLE�
PRO_CLOUDS�get_cloud_type)�UAConfig)�BASE_UA_URL�PRINT_WRAP_WIDTH)�entitlement_factory)�ApplicabilityStatus�UserFacingStatus)�colorize_commandsz=((CVE|cve)-\d{4}-\d{4,7}$|(USN|usn|LSN|lsn)-\d{1,5}-\d{1,2}$)z	cves.jsonzcves/{cve}.jsonznotices.jsonznotices/{notice}.jsonzUbuntu standard updateszUbuntu Pro: ESM InfrazUbuntu Pro: ESM Apps�ReleasedPackagesInstallResult�
fix_status�unfixed_pkgs�installed_pkgs�all_already_installedc@seZdZdZdZdZdZdS)�	FixStatuszD
    An enum to represent the system status after fix operation
    r��N)�__name__�
__module__�__qualname__�__doc__�SYSTEM_NON_VULNERABLE�SYSTEM_STILL_VULNERABLE�SYSTEM_VULNERABLE_UNTIL_REBOOT�r*r*�3/usr/lib/python3/dist-packages/uaclient/security.pyr 3s
r cs6eZdZdZdZejZdee	e
fdee	e
ffdd�Zej
ejgd�d�		d#�fd
d�	�Z																d$dee	d
ee	dee	deedeedee	dee	deee	dedfdd�Zde	ddfdd�Z										d%dee	dee	deedeedee	dedfdd�Zd e	ddfd!d"�Z�ZS)&�UASecurityClient��security_url�query_params�returncCs.|jj�di��di�}|r|�|�|S|S)zD
        Update query params with data from feature config.
        �features�extra_security_params)�cfg�get�update)�selfr/r2r*r*r+�_get_query_paramsDs�
z"UASecurityClient._get_query_params)r!��)�retry_sleepsNcs"|�|�}t�j|||||dd�S)NF)�path�data�headers�methodr/�potentially_sensitive)r7�super�request_url)r6r;r<r=r>r/��	__class__r*r+rATs
�zUASecurityClient.request_url�query�priority�package�limit�offset�	component�version�status�CVEc		s:||||||||d�}	�jt|	d�\}
}�fdd�|
D�S)znQuery to match multiple-CVEs.

        @return: List of CVE instances based on the the JSON response.
        )�qrErFrGrHrIrJrK�r/csg|]}t�|d��qS)��client�response)rL)�.0�cve_md�r6r*r+�
<listcomp>~sz-UASecurityClient.get_cves.<locals>.<listcomp>)rA�API_V1_CVES)r6rDrErFrGrHrIrJrKr/�
cves_response�_headersr*rTr+�get_cvesbs�

�zUASecurityClient.get_cves�cve_idcC�"|�tj|d��\}}t||d�S)zkQuery to match single-CVE.

        @return: CVE instance for JSON response from the Security API.
        )�cverO)rA�API_V1_CVE_TMPL�formatrL)r6rZ�cve_responserXr*r*r+�get_cve��
�zUASecurityClient.get_cve�details�release�order�USNc	sJ�||||d�}�jt|d�\}}t��fdd�|�dg�D�dd�d�S)	zuQuery to match multiple-USNs.

        @return: Sorted list of USN instances based on the the JSON response.
        )rbrcrGrHrdrNcs0g|]}�dus�|�dg�vrt�|d��qS)N�cves_idsrO)r4re)rR�usn_md�rbr6r*r+rU�s��
�z0UASecurityClient.get_notices.<locals>.<listcomp>�noticescS�|jS�N��id��xr*r*r+�<lambda>��z.UASecurityClient.get_notices.<locals>.<lambda>��key)rA�API_V1_NOTICES�sortedr4)	r6rbrcrGrHrdr/�
usns_responserXr*rhr+�get_notices�s
�
�
��zUASecurityClient.get_notices�	notice_idcCr[)zbQuery to match single-USN.

        @return: USN instance representing the JSON response.
        )�noticerO)rA�API_V1_NOTICE_TMPLr^re)r6rx�notice_responserXr*r*r+�
get_notice�razUASecurityClient.get_notice)NNNN)NNNNNNNN)NNNNN)r#r$r%�url_timeout�cfg_url_base_attrr�SecurityAPIError�
api_error_clsr�strrr7r�retry�socket�timeoutrAr�intrrYr`rwr|�
__classcell__r*r*rBr+r,>sv
�

����������
	�

�������
�r,c@s�eZdZdZdeeeffdd�Zedd��Z	edd��Z
ed	d
��Zedd��Zed
d��Z
edd��Zedefdd��Zedd��ZdS)�CVEPackageStatuszAClass representing specific CVE PackageStatus on an Ubuntu seriesr_cCs
||_dSrk�rQ)r6r_r*r*r+�__init__�s
zCVEPackageStatus.__init__cC�
|jdS�N�descriptionr�rTr*r*r+r���
zCVEPackageStatus.descriptioncCrjrk)r�rTr*r*r+�
fixed_version�szCVEPackageStatus.fixed_versioncCr�)N�pocketr�rTr*r*r+r��r�zCVEPackageStatus.pocketcCr�)N�release_codenamer�rTr*r*r+r��r�z!CVEPackageStatus.release_codenamecCr�)NrKr�rTr*r*r+rK�r�zCVEPackageStatus.statuscCsz|jdkrdS|jdkrdS|jdkrdS|jdvrdS|jd	kr#d
S|jdkr*dS|jd
kr7tjj|jd�Sd�|j�S)N�neededzSorry, no fix is available yet.zneeds-triagez7Ubuntu security engineers are investigating this issue.�pendingz)A fix is coming soon. Try again tomorrow.)�ignored�deferredzSorry, no fix is available.�DNEz.Source package does not exist on this release.�not-affectedz/Source package is not affected on this release.�released)�
fix_streamzUNKNOWN: {})rKr
�SECURITY_FIX_RELEASE_STREAMr^�
pocket_sourcerTr*r*r+�status_message�s"






�zCVEPackageStatus.status_messager0cCst|jtk�S)z?Return True if the package requires an active Pro subscription.)�boolr��UBUNTU_STANDARD_UPDATES_POCKETrTr*r*r+�requires_ua��zCVEPackageStatus.requires_uacCsP|jdkr	t}|S|jdkrt}|S|jdvrt}|Sd|jvr$t}|St}|S)z>Human-readable string representing where the fix is published.�	esm-infra�esm-apps)�updates�security�esm)r��UA_INFRA_POCKET�UA_APPS_POCKETr�r�)r6�
fix_sourcer*r*r+r��s

�	
�
��zCVEPackageStatus.pocket_sourceN)r#r$r%r&rr�rr��propertyr�r�r�r�rKr�r�r�r�r*r*r*r+r��s&





r�c@s�eZdZdZdedeeeffdd�Zde	fdd�Z
ed	d
��Zdd�Z
edeefd
d��Zededfdd��Zedd��Zedeeeffdd��ZdS)rLz7Class representing CVE response from the SecurityClientrPrQcC�||_||_dSrk�rQrP�r6rPrQr*r*r+r���
zCVE.__init__r0cC�t|t�sdS|j|jkS�NF)�
isinstancerLrQ�r6�otherr*r*r+�__eq__�
z
CVE.__eq__cC�|j�dd���S)Nrm�UNKNOWN_CVE_ID�rQr4�upperrTr*r*r+rm�zCVE.idcCs>|j}|jD]}|j}dj|j|d�d�|j�g}d�|�S)z2Return a string representing the URL for this cve.�{issue}: {title}��issue�title�https://ubuntu.com/security/{}�
)r�rir�r^rm�join)r6r�ry�linesr*r*r+�get_url_header
s

�
zCVE.get_url_headercC�|j�dg�S)N�notices_ids�rQr4rTr*r*r+r�szCVE.notices_idsrec�<t�d�st�fdd��j�dg�D�dd�dd��_�jS)	z�Return a list of USN instances from API response 'notices'.

        Cache the value to avoid extra work on multiple calls.
        �_noticesc�g|]}t�j|��qSr*)rerP)rRryrTr*r+rU#�
��zCVE.notices.<locals>.<listcomp>ricSrjrkrl��nr*r*r+rp'rqzCVE.notices.<locals>.<lambda>T�rs�reverse)�hasattrrurQr4r�rTr*rTr+ri�

��zCVE.noticescC�|j�d�Sr�r�rTr*r*r+r�,�zCVE.descriptioncCsdt|d�r|jSi|_t��d}|jdD]}|dD]}|d|kr-t|�|j|d<qq|jS)z�Dict of package status dicts for the current Ubuntu series.

        Top-level keys are source packages names and each value is a
        CVEPackageStatus object
        �_packages_status�series�packages�statusesr��name)r�r�r�get_platform_inforQr�)r6r�rF�
pkg_statusr*r*r+�packages_status0s
���zCVE.packages_statusN)r#r$r%r&r,rr�rr�r�r�r�rmr�rr�rir�r�r�r*r*r*r+rL�s


rLc	@s�eZdZdZdedeeeffdd�Zde	fdd�Z
edefd	d
��Zede
efdd��Zede
efd
d��Zedd��Zedd��Zdd�Zedeeeeeeeffffdd��ZdS)rez7Class representing USN response from the SecurityClientrPrQcCr�rkr�r�r*r*r+r�Gr�zUSN.__init__r0cCr�r�)r�rerQr�r*r*r+r�Kr�z
USN.__eq__cCr�)Nrm�UNKNOWN_USN_IDr�rTr*r*r+rmPr�zUSN.idcCr�)z$List of CVE IDs related to this USN.rfr�rTr*r*r+rfTr�zUSN.cves_idscr�)	z�List of CVE instances based on API response 'cves' key.

        Cache the values to avoid extra work for multiple call-sites.
        �_cvescr�r*)rLrP)rRr\rTr*r+rUar�zUSN.cves.<locals>.<listcomp>�cvescSrjrkrlr�r*r*r+rperqzUSN.cves.<locals>.<lambda>Tr�)r�rurQr4r�rTr*rTr+r�Yr�zUSN.cvescCr�)Nr�r�rTr*r*r+r�jr�z	USN.titlecCr�)N�
referencesr�rTr*r*r+r�nr�zUSN.referencescCsrdj|j|jd�g}|jr!|�d�|jD]
}|�d�|��qn|jr4|�d�|jD]}|�|�q,d�|�S)z5Return a string representing the URL for this notice.r�r�zFound CVEs:r�zFound Launchpad bugs:r�)r^rmr�rf�appendr�r�)r6r�r\�	referencer*r*r+r�rs

�


zUSN.get_url_headercCsJt|d�r|jSt��d}i|_|j�di��|g�D]�}|�d�rW|d|jvrMd|j|dvrCtjdj|j	|dd�|j	d	��||j|dd<qd|i|j|d<q|�d
�sltjdj|j	|dd�|j	d	��d
|d
vr�tjdj|j	|d|d
d�|j	d	��|d
�
d
�d}||jvr�i|j|<||j||d<q|jS)aWBinary package information available for this release.


        Reformat the USN.release_packages response to key it based on source
        package name and related binary package names.

        :return: Dict keyed by source package name. The second-level key will
            be binary package names generated from that source package and the
            values will be the dict response from USN.release_packages for
            that binary package. The binary metadata contains the following
            keys: name, version.
            Optional additional keys: pocket and component.
        �_release_packagesr��release_packages�	is_sourcer��sourcez6{usn} metadata defines duplicate source packages {pkg})�usn�pkg��issue_id�source_linkzL{issue} metadata does not define release_packages source_link for {bin_pkg}.)r��bin_pkg�/zX{issue} metadata has unexpected release_packages source_link value for {bin_pkg}: {link})r�r��link���)r�r�rr�rQr4r�SecurityAPIMetadataErrorr^rm�split)r6r�r��source_pkg_namer*r*r+r��sN

��

����	

zUSN.release_packagesN)r#r$r%r&r,rr�rr�r�r�r�rmrrfrLr�r�r�r�r�r*r*r*r+reDs"

,rer0c	Cs|d}t�dd|ddg�\}}i}|��D]%}|�d�\}}}}|s%|}d|vr*q||vr5||||<q||i||<q|S)z�Return a dict of all source packages installed on the system.

    The dict keys will be source package name: "krb5". The value will be a dict
    with keys binary_pkg and version.
    z${db:Status-Status}z
dpkg-queryz#-f=${Package},${Source},${Version},r�z-W�,�	installed)r�subp�
splitlinesr�)	�status_field�out�_err�installed_packages�pkg_line�pkg_namer��pkg_versionrKr*r*r+�#query_installed_source_pkg_versions�s$
��r��usns�beta_pocketscs�i}|D]Q}|j��D]I\}}�fdd�|��D�}||vr%|r%|||<q||vrT||}|��D]"\}}	||vr>|	||<q1||d}
|	d}t�||
d�sS|	||<q1qq|S)aWalk related USNs, merging the released binary package versions.

    For each USN, iterate over release_packages to collect released binary
        package names and required fix version. If multiple related USNs
        require different version fixes to the same binary package, track the
        maximum version required across all USNs.

    :param usns: List of USN response instances from which to calculate merge.
    :param beta_pockets: Dict keyed on service name: esm-infra, esm-apps
        the values of which will be true of USN response instances
        from which to calculate merge.

    :return: Dict keyed by source package name. Under each source package will
        be a dict with binary package name as keys and binary package metadata
        as the value.
    c	s.i|]\}}d��|�dd�d�ur||�qS)Fr��None�r4)rR�bin_pkg_name�
bin_pkg_md�r�r*r+�
<dictcomp>�s���z>merge_usn_released_binary_package_versions.<locals>.<dictcomp>rJ�le)r��itemsr�compare_versions)r�r��usn_pkg_versionsr��src_pkg�binary_pkg_versions�public_bin_pkg_versions�usn_src_pkgr��
binary_pkg_md�prev_version�current_versionr*rr+�*merge_usn_released_binary_package_versions�s,
�

���rcCsX|js|gSi}|jD]}|jD]}||vr|j|d�||<qqtt|��dd�d��S)z�For a give usn, get the related USNs for it.

    For each CVE associated with the given USN, we capture
    other USNs that are related to the CVE. We consider those
    USNs related to the original USN.
    �rxcSrjrkrlrnr*r*r+rp$rqz"get_related_usns.<locals>.<lambda>rr)r�r�r|�listru�values)r�rP�related_usnsr\�related_usn_idr*r*r+�get_related_usnss


���rFr3r��dry_runc
s6|rttj�����t|d�}t�}tt|�tt|�d�}d�vr�d}zt	�
gd��\}}Wn
tjy9Ynw|r{z2t
�|�ddd}|rm|�dg�}	t�fd	d
�|	D��rmttjj�|�dd�d
��tjWSWntttfyzYnwz|j�d�}
|j�d�}Wn#tjy�}zt|�}
d|
��vr�tjj�d�}
t�|
��d}~wwt|
|d�}t|
� ��t!||�}nRz
|j"�d�}t#||�}Wn#tjy�}zt|�}
d|
��vr�tjj�d�}
t�|
��d}~wwt$||d�}t!||�}t|� ��|j%d�stj&d����d��t'|�||||d�S)N)r3)r�r�rL)zcanonical-livepatchrKz	--verbosez
--format=json�Statusr�	Livepatch�Fixesc3s(�|]}|d���ko|dVqdS)�Name�PatchedN)�lower)rR�fixr�r*r+�	<genexpr>Ms
��
�z(fix_security_issue_id.<locals>.<genexpr>�VersionzN/A)r�rJ)rZ)rbz	not foundr�)r\r�r�r�r�r�z.{} metadata defines no fixed package versions.)r3r��affected_pkg_statusr��usn_released_pkgsr)(�printr
�SECURITY_DRY_RUN_WARNINGr�r,r��_is_pocket_used_by_beta_servicer�r�rr�r�ProcessExecutionError�json�loadsr4�any�CVE_FIXED_BY_LIVEPATCHr^r r'�
ValueError�KeyError�
IndexErrorr`rwrr�r�SECURITY_FIX_NOT_FOUND_ISSUE�UserFacingError�'get_cve_affected_source_packages_statusr�rr|r� get_usn_affected_packages_statusrQr��prompt_for_affected_packages)r3r�rrPr�r��
status_stdout�_�parsed_patch�fixesr\r��e�msgr r!r�r*r�r+�fix_security_issue_id's�

�����
�����
�����
�������r8cCs^i}|D](}t||���D]\}}||vr|||<q
||j}t�||jd�s+|||<q
q|S)Nr)r/rr�rr)r�r��
affected_pkgsr\r�r��current_verr*r*r+�get_affected_packages_from_cves�s"�
�

���r;cCs�i}|j��D]7\}}||vrqtt�}d|d<dd�|��D�}|s1d}tj|�|j�|jd��|��|d<t	|d�||<q|S)	Nr�rKcSs"h|]
\}}|�d�r|d�qS)r�r�)rRr3�pkg_bin_infor*r*r+�	<setcomp>�s��z1get_affected_packages_from_usn.<locals>.<setcomp>zC{} metadata defines no pocket information for any release packages.r�r�)r_)
r�rrr�rr�r^rm�popr�)r�r�r9r��pkg_infor_�all_pocketsr7r*r*r+�get_affected_packages_from_usn�s$���rAr�r�cCs|jr	t|j|�St||�S)z�Walk CVEs related to a USN and return a dict of all affected packages.

    :return: Dict keyed on source package name, with active CVEPackageStatus
        for the current Ubuntu release.
    )r�r;rArr*r*r+r0�s
r0r\cCs8i}|j��D]\}}|jdkrq||vr|||<q|S)z�Get a dict of any CVEPackageStatuses affecting this Ubuntu release.

    :return: Dict of active CVEPackageStatus keyed by source package names.
    r�)r�rrK)r\r��affected_pkg_versions�
source_pkg�package_statusr*r*r+r/�s
�r/r cCs�t|�}|dkrttjjddd�d�ttjj|d��dS|dkr&d	}nd}tjj||d�d
d�t|����}tt	j
|tdd
��dS)a	Print header strings describing affected packages related to a CVE/USN.

    :param issue_id: String of USN or CVE issue id.
    :param affected_pkg_status: Dict keyed on source package name, with active
        CVEPackageStatus for the current Ubuntu release.
    r�Nozs are)�count�
plural_str�.�r�Nr!z isz: �, �    ��width�subsequent_indent)�lenr"r
�SECURITY_AFFECTED_PKGSr^�SECURITY_ISSUE_UNAFFECTEDr�ru�keys�textwrap�fillr)r�r rFrGr7r*r*r+�print_affected_packages_header�s.	�������rUr��usn_src_released_pkgscCsht�|�}|r2|�d�r2d|jd<|dd|jd<|��D]\}}|�d�}|r1||jd<|Sq|S)a�Parse release status based on both pkg_status and USN.release_packages.

    Since some source packages in universe are not represented in
    CVEPackageStatus, rely on presence of such source packages in
    usn_src_released_pkgs to represent package as a "released" status.

    :param pkg_status: the CVEPackageStatus for this source package.
    :param usn_src_released_pkgs: The USN.release_packages representing only
       this source package. Normally, release_packages would have data on
       multiple source packages.

    :return: Tuple of:
        human-readable status message, boolean whether released,
        boolean whether the fix requires access to UA
    r�r�rKrJr�r�)�copy�deepcopyr4rQr)r�rV�usn_pkg_statusr��usn_released_pkgr�r*r*r+�#override_usn_release_package_statuss 

�
�

�r[cCsdi}t|���D]'\}}|�|i�}t||�}|j�dd�}||vr&g||<||�||f�q|S)Nr�r�)rurr4r[rK�replacer�)r r!�
status_groupsrr��usn_released_srcrY�status_groupr*r*r+�group_by_usn_package_status&s�r`�pkg_status_list�	pkg_index�num_pkgscCs�|sdSg}g}|D]\}}|d7}|�d�||��|�|�q
tjd�dd�|�dd�t|���tdd	�}d
�||j�S)z;Format the packages and status to an user friendly message.�r!z{}/{}z{} {}:�(rJ�)rKrLz{}
{})r�r^rSrTr�rurr�)rarbrc�	msg_index�src_pkgsrr��
msg_headerr*r*r+�_format_packages_message4s ��rjr�cCs:d}|tkr	d}n|tkrd}t||d�}|r||�SdS)Nzno-service-neededr�r�)r3r�)r�r�r)r�r3�service_to_check�ent_clsr*r*r+�_get_service_for_pocketNsrmcCs4t||�}|r|��\}}|tjkrdS|jSdS)zBCheck if the pocket where the fix is at belongs to a beta service.F)rm�user_facing_statusr�ACTIVE�
valid_service)r�r3�ent�
ent_statusr3r*r*r+r$Ys

r$�src_pocket_pkgs�binary_pocket_pkgscCs�d}d}t�}t�}	|rWtttfD]E}
||
}||
}|rDt|||d�}
|
r4t|
�|s2ttj�qd}|t|�7}|t	|||
|d�M}|sQ|�
dd�|D��q|	�
|�qt|||	|d�S)a%Handle the packages that could be fixed and have a released status.

    :returns: Tuple of
        boolean whether all packages were successfully upgraded,
        list of strings containing the packages that were not upgraded,
        boolean whether all packages were already installed
    T�rarbrcF)r3�upgrade_pkgsr�rcS�g|]\}}|�qSr*r*�rRrr3r*r*r+rU��z2_handle_released_package_fixes.<locals>.<listcomp>)rrrr)�setr�r�r�rjr"r
�SECURITY_UPDATE_INSTALLEDrO�upgrade_packages_and_attachr5r)r3rsrtrbrcrr�upgrade_statusrrr��
pkg_src_group�binary_pkgsr7r*r*r+�_handle_released_package_fixesisN��
��r�c
CsFt|�}tjd�||dkrdnd|dkrdndd�t|���tdd	�S)
z�Format the list of unfixed packages into an message.

    :returns: A string containing the message output for the unfixed
              packages.
    z"{} package{} {} still affected: {}r!�srd�are�isrJrKrL)rOrSrTr^r�rur)r�num_pkgs_unfixedr*r*r+�_format_unfixed_packages_msg�s��r�r!cCsJt|�}t||�|dkrtjStjj|d�}tt�}tt�}	d}
t	||�}g}t
|���D]�\}
}|
dkrVtjj|d�}t
t||
|d��|
t|�7}
|dd�|D�7}q.|D]V\}}||j�||f�||��D]A\}}|�|i�}||vr�|dd�|D�7}dj||d	�}|t|�7}t�||��||}|d
}t�||d�s�|	|j�|�qlqXq.t|||	|
||d�}||j7}|r�t
t|��|j�r|jr�t
t�|��|r�tjStjStj|j d
��rtj!jdd�}t
|�|j"�#d|�t
t�tjj|d���tj$St
t�|��|�rtjStjSt
t�tjj|d���tjS)aProcess security CVE dict returning a CVEStatus object.

    Since CVEs point to a USN if active, get_notice may be called to fill in
    CVE title details.

    :returns: An FixStatus enum value corresponding to the system state
              after processing the affected packages
    rrIr�rucSrwr*r*rxr*r*r+rU�ryz0prompt_for_affected_packages.<locals>.<listcomp>cSrwr*r*rxr*r*r+rU�s�z5{issue} metadata defines no fixed version for {pkg}.
)r�r�rJr)r3rsrtrbrcr)rz
fix operation)�	operationrd)%rOrUr r'r
�SECURITY_ISSUE_RESOLVEDr^rrr`rur�SECURITY_ISSUE_NOT_RESOLVEDr"rjr�r�r4r�rr�rrr�rrrr�handle_unicode_charactersr(r�
should_rebootr�ENABLE_REBOOT_REQUIRED_TMPL�notice_file�addr))r3r�r r�r!rrF�fix_messagersrtrb�pkg_status_groupsr�status_value�pkg_status_grouprr��
binary_pkgrJr^r7�	fixed_pkgr��released_pkgs_install_result�
reboot_msgr*r*r+r1�s�
����
�����
�����
	������������r1cCs4t�\}}|tvrttjjt�|�|d��dSdS)z:Alert the user when running Pro on cloud with PRO support.)r��cloudN)rrr"r
�SECURITY_USE_PRO_TMPLr^rr4)�
cloud_typer3r*r*r+�*_inform_ubuntu_pro_existence_if_applicableEs

���r��tokenc
Cs�ddl}ddlm}ttdd|gg��z|�|j|dddd�|�}|dkWStjy?}zt|j	�WYd}~d	Sd}~ww)
ztAttach to an Ubuntu Pro subscription with a given token.

    :return: True if attach performed without errors.
    rN��cli�pro�attachTr�)r��auto_enabler^�
attach_configF)
�argparse�uaclientr�r"r�
action_attach�	Namespacerr.r7)r3r�r�r��ret_code�errr*r*r+�_run_ua_attachPs ��

��r�cCspt�ttj�tjdgd�d�}|dkrdS|dkr$ttj�td�|dvr6ttj�td	�}t	||�Sd
S)zZPrompt for attach to a subscription or token.

    :return: True if attach performed.
    zBChoose: [S]ubscribe at ubuntu.com [A]ttach existing token [C]ancel)r��a�c��
valid_choicesr�Fr�z*Hit [Enter] when subscription is complete.)r�r��> T)
r�r"r
�*SECURITY_UPDATE_NOT_INSTALLED_SUBSCRIPTIONr�prompt_choices�PROMPT_UA_SUBSCRIPTION_URL�input�PROMPT_ENTER_TOKENr�)r3�choicer�r*r*r+�_prompt_for_attachgs 
�


r��servicecCs�ddl}ddlm}ttjj|d��tjd�|�ddgd�}|dkr@tt	d	d
|gg��t
d|�|j|gddd
dd�|�k�SdS)zMPrompt for enable a pro service.

    :return: True if enable performed.
    rNr��r�zChoose: [E]nable {} [C]ancelr6r�r�r��enableTFr�)r��
assume_yes�betar^�access_only)
r�r�r�r"r
�SECURITY_SERVICE_DISABLEDr^rr�rr��
action_enabler�)r3r�r�r�r�r*r*r+�_prompt_for_enable�s0�����r�cCs|r	ttj�dSt|�S)z<Verify if machine is attached to an Ubuntu Pro subscription.T)r"r
� SECURITY_DRY_RUN_UA_NOT_ATTACHEDr�)r3rr*r*r+�_check_attached�s
r�cCs�t||�}|rK|��\}}|tjkrdS|��\}}|tjkrA|r-ttj	j
|jd��dSt||j�r5dSttj
j
|jd��dSttjj
|jd��dS)zQ
    Verify if the Ubuntu Pro subscription has the required service enabled.
    Tr�F)rmrnrro�applicability_statusr�
APPLICABLEr"r
�'SECURITY_DRY_RUN_UA_SERVICE_NOT_ENABLEDr^r�r��SECURITY_UA_SERVICE_NOT_ENABLED� SECURITY_UA_SERVICE_NOT_ENTITLED)r�r3rrqrrr3r�r*r*r+�(_check_subscription_for_required_service�s8


�������r�cCs�ddl}ddlm}t�ttj�tjd�	t
�ddgd�}|dkrDttj�td�}tt
d	d
gg��|�|jddd
�|�t||�SdS)zdPrompt for attach a new subscription token to the user.

    :return: True if attach performed.
    rNr�z2Choose: [R]enew your subscription (at {}) [C]ancel�rr�r�r�r��detachTr�)r�r^F)r�r�r�r�r"r
�%SECURITY_UPDATE_NOT_INSTALLED_EXPIREDrr�r^r�PROMPT_EXPIRED_ENTER_TOKENr�r�
action_detachr�r�)r3r�r�r�r�r*r*r+�_prompt_for_new_token�s&
��
�
r��status_cachecCsV|�dd�}|s
dS|�d�}|dus|t�|j�kr)|r$ttj�dSt|�SdS)zuCheck if the Ubuntu Pro subscription is expired.

    :returns: True if subscription is expired and not renewed.
    �attachedF�expiresN)r4r�now�tzinfor"r
�(SECURITY_DRY_RUN_UA_EXPIRED_SUBSCRIPTIONr�)r�r3rr��contract_expiry_datetimer*r*r+�_check_subscription_is_expired�s

��

r�rvcCs�|sdSt��dkr|sttj�dS|tkr=|�d�pi}|�dd�s,t||�s+dSn	t	|||d�r5dSt
|||�s=dSttgd�gd�t|�g��|sdt
��t
jgd	�|tjjd
did�dS)
aUpgrade available packages to fix a CVE.

    Upgrade all packages in upgrades_packages and, if necessary,
    prompt regarding system attach prior to upgrading Ubuntu Pro packages.

    :return: True if package upgrade completed or unneeded, False otherwise.
    TrFzstatus-cacher�)r�r3r)rr5z&&)r�install�--only-upgrade�-y)zapt-getr�r�r��DEBIAN_FRONTEND�noninteractive)�cmd�	error_msg�env)�os�getuidr"r
�SECURITY_APT_NON_ROOTr��
read_cacher4r�r�r�rrur�run_apt_update_command�run_apt_command�APT_INSTALL_FAILEDr7)r3rvr�rr�r*r*r+r|sF


�������

�r|)F)r0N)VrW�enumr&r�r�rS�collectionsrr�typingrrrrrr	r
r�rrr
rrr�uaclient.clouds.identityrrr�uaclient.configr�uaclient.defaultsrr�uaclient.entitlementsr�(uaclient.entitlements.entitlement_statusrr�uaclient.statusr�CVE_OR_USN_REGEXrVr]rtrzr�r�r�r�r�r�unique�Enumr �UAServiceClientr,r�rLrer�rrr8r;rAr0r/rUr[r`r�rjrmr$r�r�r1r�r�r�r�r�r�r�r�r|r*r*r*r+�<module>sJ$ �

��
wEJ|�
�
�1����
�k��

���

��

�"��
�#���
�������
�D��
����
�
"���
�*
���
������

Anon7 - 2022
AnonSec Team