404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@3.144.82.228: ~ $
3

�f�r�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZddl
mZyddlZWnek
r�YnXdZdZdZd	ZGd
d�de�ZGdd
�d
e�ZGdd�de�ZdS)�N)�datetime)�Lock)�	find_spec)�sos_get_command_output�file�linkZnode�dirc@s�eZdZdZedd��Zejd�ZdZ	dZ
e�Zdd�Z
d	d
�Zdd�Zd
d�Zdd�Zdd�Zd+dd�Zd,dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�ZdS)-�Archivez!Abstract base class for archives.cCs|jS)z6Returns the archive class's name as a string.
        )�__name__)�cls�r�/usr/lib/python3.6/archive.py�archive_type+szArchive.archive_typeZsosZunsetFcCsd|j�|fS)Nz[archive:%s] %s)r)�self�msgrrr
�_format_msg8szArchive._format_msgcCs
||_dS)N)�_debug)r�debugrrr
�	set_debug;szArchive.set_debugcCs|jj|j|��dS)N)�log�errorr)rrrrr
�	log_error>szArchive.log_errorcCs|jj|j|��dS)N)rZwarningr)rrrrr
�log_warnAszArchive.log_warncCs|jj|j|��dS)N)r�infor)rrrrr
�log_infoDszArchive.log_infocCs |js
dS|jj|j|��dS)N)rrrr)rrrrr
�	log_debugGszArchive.log_debugNcCst�dS)N)�NotImplementedError)r�src�dest�forcerrr
�add_fileOszArchive.add_file�wcCst�dS)N)r)r�contentr�moderrr
�
add_stringRszArchive.add_stringcCst�dS)N)r)rr"rrrr
�
add_binaryUszArchive.add_binarycCst�dS)N)r)r�source�	link_namerrr
�add_linkXszArchive.add_linkcCst�dS)N)r)r�pathrrr
�add_dir[szArchive.add_dircCst�dS)N)r)rr)r#�devicerrr
�add_node^szArchive.add_nodecCst�dS)z�Return a temporary directory that clients of the archive may
        use to write content to. The content of the path is guaranteed
        to be included in the generated archive.N)r)rrrr
�get_tmp_diraszArchive.get_tmp_dircCst�dS)z�Return the maximum file name length this archive can support.
        This is the lesser of the name length limit of the archive
        format and any temporary file system based cache.N)r)rrrr
�name_maxgszArchive.name_maxcCsdS)aTReturn a string representing the path to the temporary
        archive. For archive classes that implement in-line handling
        this will be the archive file itself. Archives that use a
        directory based cache prior to packaging should return the
        path to the temporary directory where the report content is
        locatedNr)rrrr
�get_archive_pathmszArchive.get_archive_pathcCsdS)z:Clean up any temporary resources used by an Archive class.Nr)rrrr
�cleanupvszArchive.cleanupcCs|j�dS)aFinalize an archive object via method. This may involve creating
        An archive that is subsequently compressed or simply closing an
        archive that supports in-line handling. If method is automatic then
        the following methods are tried in order: xz, gzipN)�close)r�methodrrr
�finalizezszArchive.finalize)NF)r!)r
�
__module__�__qualname__�__doc__�classmethodr�loggingZ	getLoggerr�_namerr�
_path_lockrrrrrrr r$r%r(r*r,r-r.r/r0r3rrrr
r	(s.


	r	c@s�eZdZdZdZdZdZd5dd�Zdd�Zdd	�Z	d6dd�Z
d7dd�Zdd�Zd8dd�Z
d9dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd:d%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�ZdS);�FileCacheArchivezd Abstract superclass for archive types that use a temporary cache
    directory in the file system. �Nc
Cs�||_tjj|j|g�|kr,tjj||�|_||_||_||_||_|pJd|_	||_
tjj||�|_|j
�tj|jd�WdQRX|jd|jf�dS)N�/i�z*initialised empty FileCacheArchive at '%s')r9�osr)�commonprefix�relpath�_tmp_dirZ_policyZ_threads�enc_opts�sysroot�manifest�join�
_archive_rootr:�makedirsr)r�name�tmpdir�policy�threadsrBrCrDrrr
�__init__�s
zFileCacheArchive.__init__cCs(tjj|�r|jtj�}tjj|j|�S)N)r>r)�isabs�lstrip�seprErF)rrHrrr
�	dest_path�szFileCacheArchive.dest_pathcCsB|js|j|j�r|S|dtjkr2|dd�}tjj|j|�S)Nr�)rC�
startswithr>rOr)rE)rr)rrr
�join_sysroot�s
zFileCacheArchive.join_sysroot�cs�|jd|�|j�|}�fdd�}|jd�s4|}n&tjj|j|��rJ|ntjj|�d}|}g}x2|dkr�|dkr�tjj|�\}}	|j|	�|}qdW|j	��}
d}�x|D�]�}tjj
|
|�}
||
�s�q�tjj
||�}tjj|
�s�|jd|
�tjj|��r�tjj|��r�tj
|�}
tjj|�d}tjj
||
�}|j||d�}tjj|�}tjj|
��rntjj|
|�}
|jd	|
|
f�tj|
|
�q�|jd
|
�tj|
|�|}q�W|S)a�Create leading path components

            The standard python `os.makedirs` is insufficient for our
            needs: it will only create directories, and ignores the fact
            that some path components may be symbolic links.

            :param src: The source path in the host file system for which
                        leading components should be created, or the path
                        to an sos_* virtual directory inside the archive.

                        Host paths must be absolute (initial '/'), and
                        sos_* directory paths must be a path relative to
                        the root of the archive.

            :param mode: An optional mode to be used when creating path
                         components.
            :returns: A rewritten destination path in the case that one
                      or more symbolic links in intermediate components
                      of the path have altered the path destination.
        zMaking leading paths for %scs|jtjj�d��S)z>Test whether path ``path`` is inside the archive.
            r<)rRr>r)rE)r))�rootrr
�
in_archive�sz8FileCacheArchive._make_leading_paths.<locals>.in_archiver=rr<zMaking path %s)r#zMaking symlink '%s' -> '%s'zMaking directory %s)rrFrRr>r)�isdirrS�split�append�reverserE�exists�islink�readlink�_make_leading_paths�normpathrMr@�symlink�mkdir)rrr#rrV�src_dirr)Z
path_comps�head�tailZabs_pathZsrc_path�comp�targetZ
target_dirZ
target_srcr)rUr
r^�sN


z$FileCacheArchive._make_leading_pathsFc
Csb|p|j|�}|tkr|}ntjj|�d}|s4|Stjj|�r\tjj|�r\td|��n2tjj|�s�|tkrt|ntjj|�d}|j|�dd�}|r�|Stjj|��r^tj	|�}d}	|t
kr�tj|j
�r�t|	|df��|tko�tj|j
��rt|	|df��|tk�r0||j
��r0t|	|df��|tk�rZtj|j
��rZt|	|d	f��d
S|S)a4Check a new destination path in the archive.

            Since it is possible for multiple plugins to collect the same
            paths, and since plugins can now run concurrently, it is possible
            for two threads to race in archive methods: historically the
            archive class only needed to test for the actual presence of a
            path, since it was impossible for another `Archive` client to
            enter the class while another method invocation was being
            dispatched.

            Deal with this by implementing a locking scheme for operations
            that modify the path structure of the archive, and by testing
            explicitly for conflicts with any existing content at the
            specified destination path.

            It is not an error to attempt to create a path that already
            exists in the archive so long as the type of the object to be
            added matches the type of object already found at the path.

            It is an error to attempt to re-create an existing path with
            a different path type (for example, creating a symbolic link
            at a path already occupied by a regular file).

            :param src: the source path to be copied to the archive
            :param path_type: the type of object to be copied
            :param dest: an optional destination path
            :param force: force file creation even if the path exists
            :returns: An absolute destination path if the path should be
                      copied now or `None` otherwise
        rz'path '%s' exists and is not a directorycSs(ttj|�tj|�tj|�tj|�g�S)N)�any�stat�S_ISBLK�S_ISCHR�S_ISFIFO�S_ISSOCK)r#rrr
�
is_special4s
z/FileCacheArchive.check_path.<locals>.is_specialz path '%s' exists and is not a %szregular filez
symbolic linkzspecial fileZ	directoryN)rP�P_DIRr>r)rXr[rW�
ValueErrorr^�lstat�P_FILErh�S_ISREG�st_mode�P_LINK�S_ISLNK�P_NODE�S_ISDIR)
rr�	path_typerr�dest_dirrbrm�stZve_msgrrr
�
check_paths8


zFileCacheArchive.check_pathcCs�ydtj|�}|jd�s |jd�rDtj||�tj||j|jfd�ntj||�tj	||j
|j�Wn4tk
r�}z|j
d||f�WYdd}~XnXdS)Nz/sys/z/proc/)�nsz&caught '%s' setting attributes of '%s')r>rhrR�shutilZcopymode�utime�st_atime_ns�st_mtime_nsZcopystat�chown�st_uid�st_gid�	Exceptionr)rrrrh�errr
�_copy_attributesPs
z!FileCacheArchive._copy_attributescCs|j��|s|}|j|t|d�}|s(dSt|dd�s�ytj||�WnJtk
r�}z.|jd�s~|jd�rln|jd||f�WYdd}~XnX|j	||�d|}n<|j
d�t|d��}x|D]}|j|�q�WWdQRXd	}|j
d
||jf�WdQRXdS)N)r�readz/sys/z/proc/zFile %s not collected: '%s'z'%s'rr!z	open filez!added %s to FileCacheArchive '%s')r:r{rq�getattrr}�copy�OSErrorrRrr��seek�open�writerrF)rrrrr��	file_name�f�linerrr
r ^s,$


zFileCacheArchive.add_filer!cCs�|j��|}|j|tdd�}tj||dd��R}t|t�rD|jdd�}|j|�t	j
j|�rf|j||�|j
d||jf�WdQRXWdQRXdS)NT)rzutf-8)�encoding�utf8�ignorez-added string at '%s' to FileCacheArchive '%s')r:r{rq�codecsr��
isinstance�bytes�decoder�r>r)r[r�rrF)rr"rr#rr�rrr
r$�s

zFileCacheArchive.add_stringcCsd|j�T|j|t�}|sdStj|ddd��}|j|�WdQRX|jd||jf�WdQRXdS)N�wb)r�z,added binary content at '%s' to archive '%s')r:r{rqr�r�r�rrF)rr"rr�rrr
r%�szFileCacheArchive.add_binaryc	Cs�|jd||f�|j�H|j|t�}|s.dStjj|�s\tj||�|jd|||jf�WdQRX|jd|||f�tjj	|�}tjj
tjj||��}|j|�}dd�}tjj
|��s�tjj|��r>|}tjj	|�}tjj|tj|��}tjj||�}|||��r|jd||f�dS|jd||f�|j||�nbtjj|��rf|jd|�|j|�n:tjj|��r�|jd	|�|j|�n|jd
||f�dS)Nzadding symlink at '%s' -> '%s'z-added symlink at '%s' to '%s' in archive '%s'z.Link follow up: source=%s link_name=%s dest=%scSs�tjj|�}tjj|�s.tjjtjj||��}tjj|�}||krFdSytj|�Wn2tk
r�}z|jdkrtdS�WYdd}~XnXdS)z�Return ``True`` if the symbolic link ``link_name`` is part
                of a file system loop, or ``False`` otherwise.
            T�(NF)	r>r)�dirnamerM�realpathrErhr��errno)r'r&Zlink_dirr�rrr
�is_loop�s
z*FileCacheArchive.add_link.<locals>.is_loopz#Link '%s' - '%s' loops: skipping...z'Adding link %s -> %s for link follow upz Adding dir %s for link follow upz!Adding file %s for link follow upz)No link follow up: source=%s link_name=%s)rr:r{rtr>r)�lexistsr`rFr�r�rErPr[r\r]r@r(rWr*�isfiler )	rr&r'rZ
source_dirZhost_path_nameZdest_path_namer�ryrrr
r(�sH
zFileCacheArchive.add_linkc
Cs"|j�|j|t�WdQRXdS)zmCreate a directory in the archive.

            :param path: the path in the host file system to add
        N)r:r{rn)rr)rrr
r*�szFileCacheArchive.add_dircCs�|j|t�}|sdStjj|�s�ytj|||�WnLtk
r~}z0|jtjkrjd}|j	d||f�dS|�WYdd}~XnX|j
||�dS)NzOperation not permittedzadd_node: %s - mknod '%s')r{rvr>r)r[�mknodr�r�ZEPERMrr�)rr)r#r+rr�rrrr
r,�szFileCacheArchive.add_nodecCs*dtjkr"tjd}tj|j|�SdSdS)N�PC_NAME_MAX�)r>�pathconf_names�pathconfrF)rZpc_name_maxrrr
r.s

zFileCacheArchive.name_maxcCs|jS)N)rF)rrrr
r-szFileCacheArchive.get_tmp_dircCs|jS)N)rF)rrrr
r/
sz!FileCacheArchive.get_archive_pathcCs2tjtjj|j|�|d�|jd||jf�dS)zsCreate path, including leading components.

            Used by sos.sosreport to set up sos_* directories.
        )r#z2created directory at '%s' in FileCacheArchive '%s'N)r>rGr)rErFr)rr)r#rrr
rG
szFileCacheArchive.makedirscCs|j|�}tj|dddd�S)N�rzutf-8r�)r��errors)rPr�r�)rr)rrr
�	open_files
zFileCacheArchive.open_filecCstjj|j�rtj|j�dS)N)r>r)rWrFr}Zrmtree)rrrr
r0szFileCacheArchive.cleanupcCsftj�}|jj}||}|jjd|�|jjd|�|jjd|�|j|jjdd�tjj	dd��dS)	z�Adds component-agnostic data to the manifest so that individual
        SoSComponents do not need to redundantly add these manually
        Zend_time�run_timeZcompression�)�indent�sos_reportsz
manifest.jsonN)
rZnowrDZ
start_timeZ	add_fieldr$Zget_jsonr>r)rE)rr2�end�startr�rrr
�add_final_manifest_datasz(FileCacheArchive.add_final_manifest_datacCsN|j|j�|_tjj|j|j�}tj|j|�||_tjj|j|j��|_	dS)zeRename the archive to an obfuscated version using an initialized
        SoSCleaner instance
        N)
Zobfuscate_stringr9r>r)rErA�renamerFrH�
_archive_name)rZcleanerZ	_new_rootrrr
�rename_archive_root+s
z$FileCacheArchive.rename_archive_rootc
Cs�tjtjB}t|d�r(|j}|j|B}n|}|}d}|j|��}|j�}WdQRXt|t	�sh|j
dd�}tj||||d�\}	}
|
r�|j|	|�nd}
|
S)a�Apply a regexp substitution to a file in the archive.

        :param path: Path in the archive where the file can be found
        :type path: ``str``

        :param regexp:  A regex to match the contents of the file
        :type regexp: ``str`` or compiled ``re`` object

        :param subst: The substitution string to be used to replace matches
                      within the file
        :type subst: ``str``

        :returns: Number of replacements made
        :rtype: ``int``
        �patternr<Nr�r�)�flagsr)
�re�
IGNORECASE�	MULTILINE�hasattrr�r�r�r�r��strr��subnr$)rr)ZregexpZsubstZcommon_flagsr�r�r"�readable�resultZreplacementsrrr
�do_file_sub5s"


zFileCacheArchive.do_file_subcCs�|jd|j|f�y|j|�}Wn2tk
rT}z|jd|�|j�Sd}~XnX|j�|jd|jtj	|j�j
f�|jdr�y
|j|�Stk
r�}zd}|jd||f�|Sd}~Xq�Xn|SdS)Nz)finalizing archive '%s' using method '%s'z-An error occurred compressing the archive: %szbuilt archive at '%s' (size=%d)Zencryptz)An error occurred encrypting the archive:z%s %s)
rrF�_build_archiver�rrHr0r�r>rh�st_sizerB�_encrypt)rr2�res�errr�Zexp_msgrrr
r3Zs&


zFileCacheArchive.finalizecCs�|jdd�}|d7}d|}d}|jdrD|d|jd7}||7}|jdr�d	|jdjd
d�}d|i}|d
7}d|}||7}t|d|d�}|ddkr�|S|ddkr�|jdr�d}q�d}nd|d}t|��dS)a�Encrypts the compressed archive using GPG.

        If encryption fails for any reason, it should be logged by sos but not
        cause execution to stop. The assumption is that the unencrypted archive
        would still be of use to the user, and/or that the end user has another
        means of securing the archive.

        Returns the name of the encrypted archive, or raises an exception to
        signal that encryption failed and the unencrypted archive name should
        be used.
        z
sosreport-zsecured-sosreport-z.gpgzgpg --batch -o %s N�keyz--trust-model always -e -r %s Zpasswordz%sz'"r<Zsos_gpgz-c --passphrase-fd 0 z!/bin/bash -c "echo $sos_gpg | %s"r)Ztimeout�envZstatus�zSpecified key not in keyringzCould not read passphrasezgpg exited with code %s)�replacerBrr�)r�archiveZarc_nameZenc_cmdr�Zpasswdr�rrrr
r�rs,


zFileCacheArchive._encrypt)N)rT)NF)NF)r!)rT)r
r4r5r6rArFr�rLrPrSr^r{r�r r$r%r(r*r,r.r-r/rGr�r0r�r�r�r3r�rrrr
r;�s6

\
K
$
G	
	

%r;cs`eZdZdZdZdZd�fdd�	Zddd�Zdd	�Zd
d�Z	dd
�Z
�fdd�Zdd�Z�Z
S)�TarFileArchivez: archive class using python TarFile to create tar archivesNFcs:tt|�j|||||||�d|_tjj||j��|_dS)N�tar)	�superr�rL�_suffixr>r)rErHr�)rrHrIrJrKrBrCrD)�	__class__rr
rL�s

zTarFileArchive.__init__cCsP|j|_d|j|jd<d|j|jd<|r4||_n|j|_|j|_|j	|_
dS)Nz%.9fZatimeZctime)�st_mtime�mtime�st_atime�pax_headers�st_ctimer#rsr�Zuidr��gid)rZtar_info�fstatr#rrr
�set_tarinfo_from_stat�sz$TarFileArchive.set_tarinfo_from_statcs�|jttjj|j�d�d���s*|j�dddg}t�fdd�|D��rNdSytj��}Wntk
rp|SX|j	r�|j
��}|r�||jd<|j||�|S)	NrQz
/version.txt$z/sos_logs(/.*)?z/sos_reports(/.*)?c3s|]}tj|��VqdS)N)r��match)�.0�skip)�	orig_pathrr
�	<genexpr>�sz9TarFileArchive.copy_permissions_filter.<locals>.<genexpr>zRHT.security.selinux���)
rH�lenr>r)rXrFrgrhr��_with_selinux_context�get_selinux_contextr�r�)rZtarinfoZskipsr��contextr)r�r
�copy_permissions_filter�s  


z&TarFileArchive.copy_permissions_filtercCs,ytj|�\}}|Stk
r&dSXdS)N)�selinuxZ
getfileconr�)rr)Zrc�crrr
r��s
z"TarFileArchive.get_selinux_contextcCsd|j|jfS)Nz%s.%s)rFr�)rrrr
rH�szTarFileArchive.namecstt|�j�S)N)r�r�r.)r)r�rr
r.�szTarFileArchive.name_maxcCs�|dkrtd�dk	rdnd}|jd�}|jd||_|dkrHddi}nd	d
i}tj|jfdd|i|��}xLdD]D}tjjtjj|j	|��s�qr|j
tjj|j	|�|j�d|��d�qrW|j
|j	|j|jd�|j
�|jd|7_|j�S)N�autoZlzmaZxzZgzipZipz.%sZ
compresslevel�Zpreset�r#zw:%s�version.txtr��sos_logsr=)�arcname)r��filter)r�r�r�)r�stripr��tarfiler�r>r)r[rErF�addr9r�r1r�rH)rr2Z
_comp_mode�kwargsr�Z_contentrrr
r��s(



zTarFileArchive._build_archive)N)N)r
r4r5r6r2r�rLr�r�r�rHr.r��
__classcell__rr)r�r
r��s

r�)r>r�r}r8r�r�rhr�rZ	threadingr�importlib.utilrZ
sos.utilitiesrr��ImportErrorrqrtrvrn�objectr	r;r�rrrr
�<module>s4[

Filemanager

Name Type Size Permission Actions
__init__.cpython-36.opt-1.pyc File 5.04 KB 0644
__init__.cpython-36.pyc File 5.04 KB 0644
archive.cpython-36.opt-1.pyc File 22.42 KB 0644
archive.cpython-36.pyc File 22.42 KB 0644
component.cpython-36.opt-1.pyc File 14.84 KB 0644
component.cpython-36.pyc File 14.84 KB 0644
missing.cpython-36.opt-1.pyc File 2.68 KB 0644
missing.cpython-36.pyc File 2.68 KB 0644
options.cpython-36.opt-1.pyc File 11.79 KB 0644
options.cpython-36.pyc File 11.79 KB 0644
utilities.cpython-36.opt-1.pyc File 18.3 KB 0644
utilities.cpython-36.pyc File 18.3 KB 0644