File: //lib/python3.6/site-packages/sos/cleaner/archives/__pycache__/__init__.cpython-36.pyc
3
��'j__ � @ sr d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlmZ d dl m
Z
mZmZ dd� Z
G dd� d�ZdS )� N)�ProcessPoolExecutor)�file_is_binary�sos_get_command_output�file_is_certificatec
C s� t j| ���}tjj|d�}tt ddd� �|_xp|j� D ]d}tjj||j�}tjj |�}tjj |�}tjj
||g�}||kr�td|� d|� ���|j||� q6W tjj||jj
d�d j
d �d
�S Q R X d S )NZcleanerZfully_trusted_filterc S s | S )N� )�member�pathr r �/usr/lib/python3.6/__init__.py�<lambda># s z!extract_archive.<locals>.<lambda>z"Attempted path traversal in tarflez != �/� z.tarr ���)�tarfile�open�osr �join�getattrZextraction_filterZ
getmembers�name�abspath�commonprefix� Exception�extract�split) �archive_path�tmpdir�archiver r Zmember_pathZ
abs_directoryZ
abs_target�prefixr r r �extract_archive s r c @ sx e Zd ZdZdZdZdZdZdZdZ i Z
dd� Zdd� Zd d
� Z
dd� Zd
d� ZdRdd�Zdd� Zedd� �Zedd� �Zedd� �Zdd� Zdd� Zdd� Zd d!� ZdSd"d#�ZdTd$d%�ZdUd&d'�ZdVd(d)�Zd*d+� Zed,d-� �Z d.d/� Z!d0d1� Z"d2d3� Z#d4d5� Z$dWd6d7�Z%d8d9� Z&d:d;� Z'd<d=� Z(d>d?� Z)d@dA� Z*dBdC� Z+dDdE� Z,dFdG� Z-dHdI� Z.dJdK� Z/dLdM� Z0dNdO� Z1dPdQ� Z2dS )X�SoSObfuscationArchivea A representation of an extracted archive or an sos archive build
directory which is used by SoSCleaner.
Each archive that needs to be obfuscated is loaded into an instance of this
class. All report-level operations should be contained within this class.
r ZundeterminedFc C s� || _ | j | _|| _| j jd�d jd�d | _| j| _tjd�| _tjd�| _ | j
� | _d| _| j
� d| _|| _|| _f | _| jd | j � d
| j� �� d S )Nr r z.tarr �sos�sos_uiF� zLoaded z as type r
)r �final_archive_pathr r �archive_name�ui_name�logging� getLogger�soslog�ui_log�_load_skip_list� skip_list�is_extracted�
_load_self�archive_root�keep_binary_files�treat_certificates�parsers�log_info�description)�selfr r r. r/ r r r �__init__C s
zSoSObfuscationArchive.__init__c C sV xP| j D ]F}y|j|�}W q tk
rL } z| jd|� �� W Y d d }~X qX qW |S )NzError obfuscating string data: )r0 Zparse_string_for_keysr r1 )r3 Zstring_data�parser�errr r r �obfuscate_stringW s &z&SoSObfuscationArchive.obfuscate_stringc C s� | j |jd�d �}|j|jd�d |�}||kr�|j|�d }tjj||�}tjj|�shtj||� n&| j tj|��}tj |� tj
||� d S )Nr r r r
r
)r7 r �replacer r r �islink�rename�readlink�remove�symlink)r3 Z
short_name�filenameZ_ob_short_nameZ_ob_filename�arc_pathZ_ob_pathZ
_target_obr r r �obfuscate_filenamea s
z(SoSObfuscationArchive.obfuscate_filenamec C s
|| _ d S )N)r0 )r3 r0 r r r �set_parsersx s z!SoSObfuscationArchive.set_parsersc C s4 t jd�| _t jd�| _x| jD ]}|j� q W d S )Nr r )r% r&