/
usr
/
libexec
/
kcare
/
python
/
kcarectl
/
__pycache__
/
New Directory
Upload File
HOME
a @�j�# � @ s� d dl Z d dlZd dlZd dlZd dlZd dlZddlmZmZm Z m Z mZmZ dZdZde d ZdZd Zed ZdZdd � Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� ZdS )� N� )�errors�fetch�fs_utils� log_utils�platform_utils�utilszlibcare-plugin.versionzlibcare-plugin.soz/var/lib/libcare/z.sig.stagingzlibcare-pluginz%/var/cache/kcare/release.content.jsonz .json-sig�@ c C s� t jtj�t�d�\}}zt�|| � W t�|� nt�|� 0 t�|tj �}d� t�� |�}z$t�|� t �|t� W t�|� nt�|� 0 dS )z�Check the signature of content itself, out of reach of any writer. Mirrors load_plugin() in kpatch_server_main.c: copy the bytes aside, unlink the copy, and hand the verifier a path that only this process can reach. )�dirz/proc/{0}/fd/{1}N)�tempfile�mkstemp�os�path�dirname�PLUGIN_VERIFY_MANIFEST�write�close�open�O_RDONLY�format�getpid�unlinkr �check_gpg_signature�PLUGIN_VERIFY_MANIFEST_SIG)�content�fdr Zro_fd�link� r �4/usr/libexec/kcare/python/kcarectl/libcare_plugin.py�_verify_manifest_bytes! s r c C s� t t�� � } | st�d��zfttd��}|�� }W d � n1 sD0 Y t|� t � t�|��d }|d� | t� d }W n> tttttfy� } zt�d� |���W Y d}~n d}~0 0 t|�tkr�t�d� t���|S ) zEReturn the SHA256 the signed manifest publishes for this plugin slot.z6Cannot determine the libcare plugin id for this distro�rbN�filesz{0}/{1}�sha256z*Libcare plugin manifest lookup failed: {0}z7Malformed sha256 for {0} in the libcare plugin manifest)�_libcare_plugin_id_for_distror �get_os_releaser � KcareErrorr r �readr �json�loadsr �nstrr �LIBCARE_PLUGIN_BINARY_FILE�IOError�OSError� ValueError�KeyError� TypeError�len�SHA256_HEX_LEN)Z plugin_id�fr r! �digest�errr r r �plugin_hash6 s &&r5 c C sz t j�t�}td }zHt j�|�s,t �|� t�| |� t� |t� W t j� |�rvt �|� nt j� |�rtt �|� 0 dS )z'Copy source_path into the staging slot.�.tmpN)r r r �LIBCARE_PLUGIN_STAGING_PATH�isdir�makedirs�shutil�copy2r �sync_rename�existsr )�source_pathZstaging_dirZtmp_pathr r r �stage_pluginK s �r? c C s� t j�t�}t j�|�s"t �|� td }td }t�| |� t |d��}|� |� W d � n1 sh0 Y t�|� t�|� t j� t�r�t j� t�r�t �ttd � t �ttd � t �|t� t �|t� tj|dd� dS )z�Put the manifest and its signature where plugin_hash() looks for them. Both files are in place on disk before either is moved to its final name, and the pair being replaced is set aside for :func:`revert_manifest`. r6 �wbN�.prevF)� raise_exc)r r r r r8 r9 r r: r; r r r � fsync_path�isfile�rename)Z manifest_path� signatureZ target_dirZtmp_manifestZtmp_sigr2 r r r �install_manifestZ s ( rG c C sz t tfD ]l} z0tj�| d �r0t�| d | � n t�| � W q tyr } zt� d� | |�� W Y d}~qd}~0 0 qdS )z?Undo install_manifest, so the manifest never outlives the swap.rA z*Plugin manifest revert failed for {0}: {1}N)r r r r rD rE r r, r �logwarnr )r r4 r r r �revert_manifestu s rI c C s� | pd� � } t|pd�}| r |s$dS | dkr2|}n6ztt|�dd�d ��}W n ttfyf Y dS 0 d�| |�}t�|� d��� � S ) aO Build patches03 build_id slot `<distro-id>-<version>-libcare-plugin` from /etc/os-release fields. Mirrors the publisher side in `scripts/makedeploy/libcare_distributives_mapping.py`. Version is full VERSION_ID for ubuntu, major-only int elsewhere. Returns ``None`` when distro_id or version is empty / unparseable. � N�ubuntu�.r r z{0}-{1}-libcare-plugin�ascii)�lower�str�int�splitr/ r- r �hashlib�sha1�encode� hexdigest)� distro_id�version�ver�rawr r r r# � s r# c s$ �z�t | d����}|�d�}t|�dk sH|dd� dksH|dd� dkrZW d � W dS t�d |d d� �\}t�d|d d� �\� t�d|dd� �\}t�d|dd� �\}� dks�|dks�||kr�W d � W dS |�|� |�� | ��t��� | k �rW d � W dS � �fdd�}||�\}}} |�|� |�| �} t|�D ]�}||�\}} }|| k�rp�qP| �d|�}|dk �r��qP| ||� dk�r��qP|�| � |�|�}|�d�� dd�� � W d � W S W d � n1 �s�0 Y W n tttj f�y Y dS 0 dS )am Read the .libcare_plugin_version section from an ELF64 file. Mirrors the C-side read_plugin_version in kpatch_server_main.c so the client can decide whether a locally-staged plugin is newer than the running one without having to load it. :param path: Absolute path to the ELF file. :return: Version string, or empty string on any failure. r r N� s ELF� � rJ �<Q�( �0 z<H�: �<