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/apport/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/apport/__pycache__/fileutils.cpython-310.pyc
o

�v�f�K�@s&dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddl
mZddlmZzddlmZmZmZmZeeefWneybddlmZmZmZmZYnwddlmZddlmZej�dd	�Zd
ZdZ dZ!d
Z"Gdd�dej#j$e%�Z&dd�Z'dd�Z(dd�Z)dd�Z*dd�Z+dd�Z,dd�Z-dd�Z.d d!�Z/d"d#�Z0d$d%�Z1d&d'�Z2d(d)�Z3d*d+�Z4d,d-�Z5d.d/�Z6dOd0d1�Z7d2d3�Z8dPd5d6�Z9de9_:d7d8�Z;d9d:�Z<d;d<�Z=d=d>�Z>d?e?d@e@eAeAffdAdB�ZBdOdCdD�ZCdQdEdF�ZDdGdH�ZEdIdJ�ZFdKdL�ZGdMdN�ZHdS)Rz0Functions to manage apport problem report files.�N)�closing)�
itemgetter)�ConfigParser�
NoOptionError�NoSectionError�MissingSectionHeaderError)�
ProblemReport)�impl�APPORT_REPORT_DIRz
/var/crashz/var/lib/apport/coredump�z~/.config/apport/settingsz/run/snapd.socketc@seZdZdd�Zdd�ZdS)�UHTTPConnectioncCstjj�|d�||_dS)N�	localhost)�http�client�HTTPConnection�__init__�path)�selfr�r�2/usr/lib/python3/dist-packages/apport/fileutils.pyr,s
zUHTTPConnection.__init__cCs&t�tjtj�}|�|j�||_dS�N)�socket�AF_UNIX�SOCK_STREAM�connectr�sock)rrrrrr0s
zUHTTPConnection.connectN)�__name__�
__module__�__qualname__rrrrrrr*srcCs<t�dtj�s	dSz
t�gd��dkWStyYdSw)z)Check whether crash reporting is enabled.z/usr/bin/whoopsieT)z/bin/systemctlz-qz
is-enabledz
whoopsie.pathrF)�os�access�X_OK�
subprocess�call�OSErrorrrrr�allowed_to_report6s�r%cCs\|sdS|�d�sdSd|vrdSdD]	}||vrdSq|�d�}t|�dkr*dS|dS)z'Extract the socket from a DBus address.Nzunix:path=/run/user/z../)�%�,�;�=��)�
startswith�split�len)�	dbus_addr�search�partsrrr�get_dbus_socketBs
�
r2c	Cs�|durdSd}t�|�D]4}|�d�rA|�d�s|�d�sq
|r$dSt|d��}d|��vr2|}Wd�n1s<wYq
|S)z�Return a package's .desktop file.

    If given package is installed and has a single .desktop file, return the
    path to it, otherwise return None.
    Nz.desktopz/etc/xdg/autostartz/usr/share/applications/�rbsNoDisplay=true)�	packaging�	get_files�endswithr,�open�read)�package�desktopfile�line�frrr�find_package_desktopfile]s 
���r=cCsDgd�}d}|D]}|�|�rd}nq|o!|�d�o!|�d�S)a2Check whether the given file is likely to belong to a package.

    This is semi-decidable: A return value of False is definitive, a True value
    is only a guess which needs to be checked with find_file_package().
    However, this function is very fast and does not access the package
    database.
    )	z/bin/z/bootz/etc/z/initrdz/libz/sbin/z/optz/usr/z/varFTz/usr/local/z	/var/lib/)r,)�file�
pkg_whitelist�whitelist_match�irrr�likely_packagedys
��rBcCsLtj�|�\}}tj�|�}tj�|�rtj�||�}t|�s!dSt�|�S)z[Return the package that ships the given file.

    Return None if no package ships it.
    N)	rrr-�realpath�isdir�joinrBr4�get_file_package)r>�dir�name�resolved_dirrrr�find_file_package�s
rJcCs�z@ttt���/}d|��}|�d|�|��}|jdkr-t�|���dWd�WSWd�WdS1s9wYWdSt	yJYdSw)zbReturn the data of the given snap.

    Return None if the snap is not found to be installed.
    z
/v2/snaps/�GET���resultN)
rr�SNAPD_SOCKET�request�getresponse�status�json�loadsr8�	Exception)�snap�c�url�responserrr�	find_snap�s

�&��rYcCs t�|�}|j|jkp|jdkS)zACheck whether the report file has already been processed earlier.r)r�stat�st_atime�st_mtime�st_size)�report�strrr�seen_report�s
r`cCs�d|�dd�d}d|�dd�d}tj�|�r5tj�|�r5t�|�}t�|�}|j|jkr5t�|�t|d��	Wd�dS1sFwYdS)Nz	%s.upload�.r+rz%s.uploaded�a)�rsplitrr�existsrZr\�unlinkr7)r^�upload�uploaded�	report_st�	upload_strrr�mark_report_upload�s


"�rjcCszd|vr
|d�dd�}ntd��t��}d|t|�|f}tj�t|�}t|d��	Wd�dS1s6wYdS)N�ExecutablePath�/�_z1report does not have the ExecutablePath attributez%s.%s.%s.hangingrb)	�replace�
ValueErrorr�geteuid�strrrE�
report_dirr7)r^�pid�subject�uid�baserrrr�mark_hanging_process�s"�rwcCs�t�|�}zt�||j|jdf�WdStycd}|dkrUt|�}|�d�|��zt�|�}Wnty@YYdSw|j|jkrHn
t	�
d�|d8}|dks!|dkr`t|�YdSYdSw)zMark given report file as seen.r+�rNg�������?)rrZ�utimer\r$r7r8�closer[�time�sleep�
delete_report)r^r_�timeoutr<rrr�mark_report_seen�s.

�
���rc	Csfg}t�tj�td��D]$}ztj�|�dkr&t�|tjtjB�r&|�	|�Wqt
y0Yqw|S)zCReturn a list with all report files accessible to the calling user.�*.crashr)�globrrrErr�getsizer �R_OK�W_OK�appendr$��reports�rrrr�get_all_reports�s$
��r�c	Cs<g}t�D]}zt|�s|�|�WqtyYqw|S)z�Get new reports for calling user.

    Return a list with all report files which have not yet been processed
    and are accessible to the calling user.
    )r�r`r�r$r�rrr�get_new_reports�s

��r�c	Cs�g}t�tj�td��D]<}z1t�|�}|jdkr>|jdkr>zt�	|j�}|j
�d�r.WWqWn	ty8Ynw|�
|�WqtyHYqw|S)z�Get all system reports.

    Return a list with all report files which belong to a system user (i. e.
    uid < 500 according to LSB).
    r�r���guest)r�rrrErrrZr]�st_uid�pwd�getpwuid�pw_namer,�KeyErrorr�r$)r�r�r_�pwrrr�get_all_system_reportss&
��
��r�cCsdd�t�D�S)z�Get new system reports.

    Return a list with all report files which have not yet been processed
    and belong to a system user (i. e. uid < 500 according to LSB).
    cSsg|]}t|�s|�qSr)r`)�.0r�rrr�
<listcomp>0sz*get_new_system_reports.<locals>.<listcomp>)r�rrrr�get_new_system_reports*sr�cCs^zt�|�WdSty.t|d��}|�d�Wd�YdS1s&wYYdSw)z�Delete the given report file.

    If unlinking the file fails due to a permission error (if report_dir is not
    writable to normal users), the file will be truncated to 0 bytes instead.
    �wrN)rrer$r7�truncate)r^r<rrrr}3s&��r}c	Cszt�}|j|dddgd�z#t|d�}t�t�|d��}t�t���}||dkr.WdS|WSttfy<YdSw)z�Return the number of recent crashes for the given report file.

    Return the number of recent crashes (currently, crashes which happened more
    than 24 hours ago are discarded).
    F�CrashCounter�Date)�
key_filteri�Qr)	r�load�intr{�mktime�strptime�	localtimeror�)r^�pr�count�report_time�cur_timerrr�get_recent_crashes@s�r�cCs�d|vr
|d�dd�}nd|vr|d�dd�d}ntd��|s&t��}tj�td	|t|�f�}t	j
d
kr=t|d�St�t�|tj
tjBtjBd�d
�S)a6Construct a canonical pathname for a report and open it for writing

    If uid is not given, it defaults to the effective uid of the current process.
    The report file must not exist already, to prevent losing previous reports
    or symlink attacks.

    Return an open file object for binary writing.
    rkrlrm�PackageNr+rz7report has neither ExecutablePath nor Package attributez%s.%s.crash�3�xbi��wb)rnr-rorrprrErrrq�sys�versionr7�fdopen�O_WRONLY�O_CREAT�O_EXCL)r^rurtrrrr�make_report_fileTs	

$r�cCs�tj�|�sJ�tjdd|gtjtjdid�}|��d��}|jdkr&gSg}|�	�D]}|�
d�r>|�|�dd�d�q,|S)	z�Check file integrity against md5 sum file.

    sumfile must be md5sum(1) format (relative to /).

    Return a list of files that don't match.
    z/usr/bin/md5sumz-crl)�stdout�stderr�cwd�envr�FAILED�:r+)
rrrdr"�Popen�PIPE�communicate�decode�
returncode�
splitlinesr6r�rc)�sumfile�m�out�
mismatchesr;rrr�check_files_md5ns�

�r�Fc
	CsR|st�t���d}t�d|�}d}d}d}tjswtdd�t_zBz"t�	|tj
tjB�}t�|�}	t
�|	j�rBt�|d�}|�d�}WnttfyNYnwW|durY|��n|durbt�|�n|durl|��w|durvt�|�wwztj�|�Wn	ty�Ynwz|r�tj�||�WStj�||�WSttfy�|YSw)z�Return a setting from user configuration.

    This is read from ~/.config/apport/settings or path. If bool is True, the
    value is interpreted as a boolean.

    Privileges may need to be dropped before calling this.
    r�~�N)�
interpolationr�r�)r�r�rrp�_config_filern�
get_config�configrr7�
O_NOFOLLOW�O_RDONLY�fstatrZ�S_ISREG�st_moder�r8�IOErrorr$rz�read_stringr�
getboolean�getrr)
�section�setting�defaultr�bool�homedir�contents�fdr<r_rrrr��sR	

���

��
���r�cCs&||�d�dd�}t|��d�S)z7Extracts the starttime from the contents of a stat file�)r*N�)�rfindr�r-)r��strippedrrr�
get_starttime�sr�cCstd}d}|��D]-}|�d�r t|���dkr t|��d�}q|�d�r5t|���dkr5t|��d�}q||fS)z;Extracts the uid and gid from the contents of a status fileNzUid:r+zGid:)r�r,r.r-r�)r��real_uid�real_gidr;rrr�get_uid_and_gid�s�r�cCsV|D]&}|��}t|�dkrqt|d�}|t|d�}||kr(||kr(dSqdS)zSearch for an ID in a map fd�r+r*TF)r-r.r�)�mapfdrur;�fields�
host_start�host_endrrr�
search_map�s�r�cCs:td��}|����}Wd�|S1swY|S)zGets the kernel boot idz/proc/sys/kernel/random/boot_idN)r7r8�strip)r<�boot_idrrr�get_boot_id�s

��r��proc_pid_fd�returncstdtdtf�fdd�}tddd|d��}|���d	�}Wd
�n1s%wY|s.iStdd�|�d
�D��S)z�Get the process environ from a proc directory file descriptor.

    Raises an OSError in case the environ file could not been read.
    �flagsr�cstj||�d�S)N��dir_fd)rr7)rr��r�rr�opener�sz#get_process_environ.<locals>.opener�environzutf-8rn)�encoding�errorsr�z NcSs g|]}d|vr|�dd��qS)r)r+)r-)r��entryrrrr�s z'get_process_environ.<locals>.<listcomp>�)r�r7r8�rstrip�dictr-)r�r��
environ_fdr�rr�r�get_process_environ�s���r�cCs2|durdSztjd|d�WStyYdSw)z;Gets the process path from a proc directory file descriptorN�unknown�exer�)r�readlinkr$r�rrr�get_process_paths�r�c	Cs�|dur	d}d}n"|dur+td|��}|��}Wd�n1s"wYt|�}|dur3t|�}|�dd��dd�}|durEt��}d||t�t|�t|�f}tj	�
t|�}||fS)zGet the path to a core fileNr�z
/proc/%s/statrlrmrazcore.%s.%s.%s.%s.%s)r7r8r�r�rnr�getuidr�rqrrE�core_dir)	rsr�ru�	timestampr��	stat_file�
stat_contents�	core_name�	core_pathrrr�
get_core_paths$
�
�rc
Cs�t|�}g}g}tj�t�rtjtd�}|D]*}z|�d�d|kr4tj�tj�t|��}|�	||g�Wqt
tfy@Yqw|S)z�Searches the core file directory for files that belong to a
       specified uid. Returns a list of lists containing the filename and
       the file modification time.)rrar*)rqrrrdr��listdirr-�getmtimerEr��
IndexError�FileNotFoundError)ru�
core_files�	uid_filesr<r{rrr�find_core_files_by_uid,s��rcCstt|�}t|td�d�}t|�tdkr6tt|�td�D]}t�tj�	t
|dd��|�|d�qdSdS)zcRemoves old files from the core directory if there are more than
       the maximum allowed per uidr+)�keyrN)r�sortedrr.�max_corefiles_per_uid�ranger�removerrEr�)rur
�sorted_files�xrrr�clean_core_directoryAs�rc	Cs�i}tjd|gtjtjdd�}|jD]1}z
|�dd�\}}Wn	ty'Yqw|��}d|vr1q|��d��}|�d�r?q|||<q|j�	�|�
�|jdkrTiS|S)	z�Get libraries with which the specified binary is linked.

    Return a library name -> path mapping, for example 'libc.so.6' ->
    '/lib/x86_64-linux-gnu/libc.so.6'.
    �lddT)r�r��universal_newlinesz=>r+z
linux-vdsor�()r"r�r��STDOUTr�r-ror�r,rz�waitr�)r�libsrr;rH�restrrr�shared_librariesOs.�
�



rcCs6t|�}||vr
dS|D]}|�|d�rdSqdS)z�Check if the binary at path links with the library named lib.

    path should be a fully qualified path (e.g. report['ExecutablePath']),
    lib may be of the form 'lib<name>' or 'lib<name>.so.<version>'
    Tz.so.F)rr,)r�libr�
linked_librrr�links_with_shared_libraryqs�rr)NNF)NNNNN)I�__doc__rr�r"�os.pathr{r�r�rZrRr�http.clientr�
contextlibr�operatorr�configparserrrrr�ImportError�problem_reportr�apport.packaging_implr	r4r�r�rrr�rr�rNrr�objectrr%r2r=rBrJrYr`rjrwrr�r�r�r�r}r�r�r�r�r�r�r�r�r�r�r�rqr�r�rrrrrrrrr�<module>sdP�

	

1

"

Spamworldpro Mini