Spamworldpro Mini Shell
Spamworldpro


Server : Apache/2.4.52 (Ubuntu)
System : Linux webserver 6.8.0-49-generic #49~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Nov 6 17:42:15 UTC 2 x86_64
User : www-data ( 33)
PHP Version : 8.1.2-1ubuntu2.21
Disable Function : NONE
Directory :  /lib/python3/dist-packages/sos/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/sos/__pycache__/archive.cpython-310.pyc
o

i��d�l�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZddl
mZzddlZWn	eyGYnwdZdZdZd	ZGd
d�de�ZGdd
�d
e�ZGdd�de�ZdS)�N)�datetime)�Lock)�	find_spec)�sos_get_command_output�file�link�node�dirc@s�eZdZdZedd��Ze�d�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.cC�|jS)z6Returns the archive class's name as a string.
        )�__name__)�cls�r�-/usr/lib/python3/dist-packages/sos/archive.py�archive_type(szArchive.archive_type�sos�unsetFcCsd|��|fS)Nz[archive:%s] %s)r��self�msgrrr�_format_msg5�zArchive._format_msgcCs
||_dS�N)�_debug)r�debugrrr�	set_debug8s
zArchive.set_debugcC�|j�|�|��dSr)�log�errorrrrrr�	log_error;�zArchive.log_errorcCrr)r�warningrrrrr�log_warn>r zArchive.log_warncCrr)r�inforrrrr�log_infoAr zArchive.log_infocCs |jsdS|j�|�|��dSr)rrrrrrrr�	log_debugDszArchive.log_debugNcC�t�r��NotImplementedError)r�src�dest�forcerrr�add_fileL�zArchive.add_file�wcCr&rr')r�contentr*�moderrr�
add_stringOr-zArchive.add_stringcCr&rr')rr/r*rrr�
add_binaryRr-zArchive.add_binarycCr&rr')r�source�	link_namerrr�add_linkUr-zArchive.add_linkcCr&rr'�r�pathrrr�add_dirXr-zArchive.add_dircCr&rr')rr7r0�devicerrr�add_node[r-zArchive.add_nodecCr&)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.r'�rrrr�get_tmp_dir^�zArchive.get_tmp_dircCr&)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.r'r;rrr�name_maxdr=zArchive.name_maxcC�dS)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
        locatedNrr;rrr�get_archive_pathjszArchive.get_archive_pathcCr?)z:Clean up any temporary resources used by an Archive class.Nrr;rrr�cleanupsszArchive.cleanupcCs|��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�methodrrr�finalizewszArchive.finalize�NF�r.)r�
__module__�__qualname__�__doc__�classmethodr�logging�	getLoggerr�_namerr�
_path_lockrrrr"r$r%r,r1r2r5r8r:r<r>r@rArDrrrrr
%s2



	r
c@s�eZdZdZdZdZdZ	d3dd�Zdd�Zdd	�Z	d4dd�Z
d5dd�Zdd�Zd5dd�Z
d6dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd4d%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�ZdS)7�FileCacheArchivezd Abstract superclass for archive types that use a temporary cache
    directory in the file system. �NcCs�||_tj�|j|g�|krtj�||�|_||_||_||_||_|p%d|_	||_
tj�||�|_|j
�t�|jd�Wd�n1sGwY|�d|jf�dS)N�/�z*initialised empty FileCacheArchive at '%s')rM�osr7�commonprefix�relpath�_tmp_dir�_policy�_threads�enc_opts�sysroot�manifest�join�
_archive_rootrN�makedirsr$�r�name�tmpdir�policy�threadsrYrZr[rrr�__init__�s 
�
�zFileCacheArchive.__init__cCs(tj�|�r|�tj�}tj�|j|�Sr)rSr7�isabs�lstrip�sepr\r])rr`rrr�	dest_path�szFileCacheArchive.dest_pathcCs@|jr	|�|j�r|S|dtjkr|dd�}tj�|j|�S)Nr�)rZ�
startswithrSrgr7r\r6rrr�join_sysroot�s
zFileCacheArchive.join_sysrootrRcs�|�d|�|j�|}�fdd�}|�d�s|}ntj�|�|��r%|ntj�|�d}|}g}|dkrP|dkrPtj�|�\}}	|�|	�|}|dkrP|dks9|�	��}
d}|D]{}tj�
|
|�}
||
�shqZtj�
||�}tj�|
�s�|�d|
�tj�|�r�tj�|�r�t�
|�}
tj�|�d}tj�
||
�}|j||d�}tj�|�}tj�|
�r�tj�|
|�}
|�d	|
|
f�t�|
|
�qZ|�d
|
�t�|
|�|}qZ|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|�tj��d��S)z>Test whether path ``path`` is inside the archive.
            rP)rjrSr7r\)r7��rootrr�
in_archive�sz8FileCacheArchive._make_leading_paths.<locals>.in_archiverQrrPzMaking path %s�r0zMaking symlink '%s' -> '%s'zMaking directory %s)r%r]rjrSr7�isdirrk�split�append�reverser\�exists�islink�readlink�_make_leading_paths�normpathrerU�symlink�mkdir)rr)r0r*rn�src_dirr7�
path_comps�head�tail�abs_path�src_path�comp�target�
target_dir�
target_srcrrlrrw�sV
�
�
��z$FileCacheArchive._make_leading_pathsFc
CsJ|p|�|�}|tkr|}ntj�|�d}|s|Stj�|�r,tj�|�s,td|��tj�|�sE|tkr8|ntj�|�d}|�|�dd�}|rM|Stj�|�r�t�	|�}d}	|t
krlt�|j
�slt|	|df��|tkr~t�|j
�s~t|	|df��|tkr�||j
�s�t|	|df��|tkr�t�|j
�s�t|	|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(tt�|�t�|�t�|�t�|�g�Sr)�any�stat�S_ISBLK�S_ISCHR�S_ISFIFO�S_ISSOCKrorrr�
is_special1s�z/FileCacheArchive.check_path.<locals>.is_specialz path '%s' exists and is not a %szregular filez
symbolic linkzspecial file�	directoryN)rh�P_DIRrSr7rqrtrp�
ValueErrorrw�lstat�P_FILEr��S_ISREG�st_mode�P_LINK�S_ISLNK�P_NODE�S_ISDIR)
rr)�	path_typer*r+�dest_dirr{r��st�ve_msgrrr�
check_paths:�

zFileCacheArchive.check_pathc
Cs�z3t�|�}|�d�s|�d�r"t�||�tj||j|jfd�nt�||�t�	||j
|j�WdStyO}z|�
d||f�WYd}~dSd}~ww)N�/sys/�/proc/)�nsz&caught '%s' setting attributes of '%s')rSr�rj�shutil�copymode�utime�st_atime_ns�st_mtime_ns�copystat�chown�st_uid�st_gid�	Exceptionr%)rr)r*r��errr�_copy_attributesMs
���z!FileCacheArchive._copy_attributescCs:|j��|s|}|j|t|d�}|s	Wd�dSt|dd�s[zt�||�Wn&tyO}z|�d�s;|�d�r<n	|�d||f�WYd}~nd}~ww|�	||�d|}n&|�
d�t|d��}|D]}|�|�qhWd�n1szwYd	}|�
d
||jf�Wd�dS1s�wYdS)N�r+�readr�r�zFile %s not collected: '%s'z'%s'rr.z	open filez!added %s to FileCacheArchive '%s')rNr�r��getattrr��copy�OSErrorrjr$r��seek�open�writer%r])rr)r*r+r��	file_name�f�linerrrr,[s:�
��

���"�zFileCacheArchive.add_filer.cCs�|j�A|}|j|tdd�}tj||dd�}t|t�r!|�dd�}|�|�t	j
�|�r2|�||�|�
d||jf�Wd�dS1sGwYdS)NTr��utf-8��encoding�utf8�ignorez-added string at '%s' to FileCacheArchive '%s')rNr�r��codecsr��
isinstance�bytes�decoder�rSr7rtr�r%r])rr/r*r0r)r�rrrr1s

�"�zFileCacheArchive.add_stringcCs||j�1|�|t�}|s	Wd�dStj|ddd�}|�|�|�d||jf�Wd�dS1s7wYdS)N�wbr�z,added binary content at '%s' to archive '%s')rNr�r�r�r�r�r%r])rr/r*r�rrrr2�s�
�"�zFileCacheArchive.add_binaryc	Cs�|�d||f�|j�0|�|t�}|s	Wd�dStj�|�s5t�||�|�d|||jf�Wd�n1s?wY|�d|||f�tj�	|�}tj�
tj�||��}|�|�}dd�}tj�
|�s�tj�|�r�|}tj�	|�}tj�|t�|��}tj�||�}|||�r�|�d||f�dS|�d||f�|�||�dStj�|�r�|�d|�|�|�dStj�|�r�|�d	|�|�|�dS|�d
||f�dSdS)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=%sc
Ss�tj�|�}tj�|�stj�tj�||��}tj�|�}||kr#dSzt�|�WdStyD}z
|jdkr?WYd}~dS�d}~ww)z�Return ``True`` if the symbolic link ``link_name`` is part
                of a file system loop, or ``False`` otherwise.
            T�(NF)	rSr7�dirnamere�realpathr\r�r��errno)r4r3�link_dirr�rrr�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)r%rNr�r�rSr7�lexistsryr]r�r�r\rhrtrurvrUr5rpr8�isfiler,)	rr3r4r*�
source_dir�host_path_name�dest_path_namer�r�rrrr5�sZ�
���
�

��
��zFileCacheArchive.add_linkcCs8|j�|�|t�Wd�dS1swYdS)zmCreate a directory in the archive.

            :param path: the path in the host file system to add
        N)rNr�r�r6rrrr8�s"�zFileCacheArchive.add_dirc
Cs�|�|t�}|s
dStj�|�sHz	t�|||�Wn&ty?}z|jtjkr9d}|�	d||f�WYd}~dS|�d}~ww|�
||�dSdS)NzOperation not permittedzadd_node: %s - mknod '%s')r�r�rSr7rt�mknodr�r��EPERMr$r�)rr7r0r9r*r�rrrrr:�s ���zFileCacheArchive.add_nodecCs&dtjvrtjd}t�|j|�SdS)N�PC_NAME_MAX�)rS�pathconf_names�pathconfr])r�pc_name_maxrrrr>�s

zFileCacheArchive.name_maxcCrr�r]r;rrrr<�zFileCacheArchive.get_tmp_dircCrrr�r;rrrr@r�z!FileCacheArchive.get_archive_pathcCs2tjtj�|j|�|d�|�d||jf�dS)zsCreate path, including leading components.

            Used by sos.sosreport to set up sos_* directories.
        roz2created directory at '%s' in FileCacheArchive '%s'N)rSr^r7r\r]r%)rr7r0rrrr^
s
�zFileCacheArchive.makedirscCs|�|�}tj|dddd�S)N�rr�r�)r��errors)rhr�r�r6rrr�	open_files
zFileCacheArchive.open_filecCs"tj�|j�rt�|j�dSdSr)rSr7rpr]r��rmtreer;rrrrAs�zFileCacheArchive.cleanupcCsft��}|jj}||}|j�d|�|j�d|�|j�d|�|�|jjdd�tj�	dd��dS)	z�Adds component-agnostic data to the manifest so that individual
        SoSComponents do not need to redundantly add these manually
        �end_time�run_time�compression�)�indent�sos_reportsz
manifest.jsonN)
r�nowr[�
start_time�	add_fieldr1�get_jsonrSr7r\)rrC�end�startr�rrr�add_final_manifest_datas�z(FileCacheArchive.add_final_manifest_datacCsN|�|j�|_tj�|j|j�}t�|j|�||_tj�|j|���|_	dS)zeRename the archive to an obfuscated version using an initialized
        SoSCleaner instance
        N)
�obfuscate_stringrMrSr7r\rV�renamer]r`�
_archive_name)r�cleaner�	_new_rootrrr�rename_archive_root(s
z$FileCacheArchive.rename_archive_rootc
Cs�|�d|j|f�z|�|�}Wnty.}z|�d|�|��WYd}~Sd}~ww|��|�d|jt�	|j�j
f�|jdrmz|�|�WStyl}zd}|�d||f�|WYd}~Sd}~ww|S)Nz)finalizing archive '%s' using method '%s'z-An error occurred compressing the archive: %szbuilt archive at '%s' (size=%d)�encryptz)An error occurred encrypting the archive:z%s %s)
r$r]�_build_archiver�rr`rAr�rSr��st_sizerY�_encrypt)rrC�res�errr��exp_msgrrrrD2s4����
�
��zFileCacheArchive.finalizecCs�|�dd�}|d7}d|}d}|jdr"|d|jd7}||7}|jdrBd	|jd�d
d�}d|i}|d
7}d|}||7}t|d|d�}|ddkrQ|S|ddkrh|jdrbd}t|��d}t|��d|d}t|��)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 �passwordz%sz'"rP�sos_gpgz-c --passphrase-fd 0 z!/bin/bash -c "echo $sos_gpg | %s"r)�timeout�env�status�zSpecified key not in keyringzCould not read passphrasezgpg exited with code %s)�replacerYrr�)r�archive�arc_name�enc_cmdr��passwdr�rrrrr�Js0


��zFileCacheArchive._encryptr)rRrErF)rrGrHrIrVr]r�rdrhrkrwr�r�r,r1r2r5r8r:r>r<r@r^r�rAr�r�rDr�rrrrrO�s8
�

\K

$G	
	

rOcsbeZdZdZdZdZ	d�fdd�	Zddd�Zdd	�Zd
d�Z	dd
�Z
�fdd�Zdd�Z�Z
S)�TarFileArchivez: archive class using python TarFile to create tar archivesNFc	s:tt|��|||||||�d|_tj�||���|_dS)N�tar)	�superr�rd�_suffixrSr7r\r`r�r_��	__class__rrrd|s�
�zTarFileArchive.__init__cCsP|j|_d|j|jd<d|j|jd<|r||_n|j|_|j|_|j	|_
dS)Nz%.9f�atime�ctime)�st_mtime�mtime�st_atime�pax_headers�st_ctimer0r�r��uidr��gid)r�tar_info�fstatr0rrr�set_tarinfo_from_stat�sz$TarFileArchive.set_tarinfo_from_statcs�|jttj�|j�d�d���s|j�gd�}t�fdd�|D��r&dSzt���}Wnty8|YSw|j	rH|�
��}|rH||jd<|�||�|S)N���)z
/version.txt$z/sos_logs(/.*)?z/sos_reports(/.*)?c3s�|]	}t�|��VqdSr)�re�match)�.0�skip��	orig_pathrr�	<genexpr>�s�z9TarFileArchive.copy_permissions_filter.<locals>.<genexpr>zRHT.security.selinux)
r`�lenrSr7rqr]r�r�r��_with_selinux_context�get_selinux_contextr	r)r�tarinfo�skipsr�contextrrr�copy_permissions_filter�s" �

z&TarFileArchive.copy_permissions_filtercCs*z
t�|�\}}|WStyYdSwr)�selinux�
getfileconr�)rr7�rc�crrrr�s�z"TarFileArchive.get_selinux_contextcCsd|j|jfS)Nz%s.%s)r]rr;rrrr`�rzTarFileArchive.namecstt|���Sr)rr�r>r;rrrr>�szTarFileArchive.name_maxcCs�|dkrtd�durdnd}|�d�}|jd||_|dkr$ddi}nd	d
i}tj|jfdd|i|��}d
D]"}tj�tj�|j	|��sGq8|j
tj�|j	|�|j�d|��d�q8|j
|j	|j|jd�|�
�|jd|7_|��S)N�auto�lzma�xz�gzip�ipz.%s�
compresslevel��preset�r0zw:%s)zversion.txtr��sos_logsrQ)�arcname)r-�filter)r�stripr��tarfiler�rSr7rtr\r]�addrMrrBrr`)rrC�
_comp_mode�kwargsr��_contentrrrr��s.

���zTarFileArchive._build_archiver)rrGrHrIrCrrdrrrr`r>r��
__classcell__rrrrr�vs�
	
r�)rSr0r�rKr�r�r�rr�	threadingr�importlib.utilr�
sos.utilitiesrr�ImportErrorr�r�r�r��objectr
rOr�rrrr�<module>s6�[y

Spamworldpro Mini