HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //proc/676643/root/lib/python3/dist-packages/apparmor/__pycache__/common.cpython-310.pyc
o

%`bb,�@sXddlmZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
daGdd�de�ZGdd�de�Zd5d
d�Zdd
�Ze	jfdd�Zdd�Zd6dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd7d d!�Zd"d#�Zd7d$d%�Zd&d'�Z d(d)�Z!d*d+�Z"d,d-�Z#e	j$dd.kr�e%Z&d/d0�Z'd1d2�Z(Gd3d4�d4e)�Z*dS)8�)�print_functionNFc@s eZdZdZdd�Zdd�ZdS)�AppArmorExceptionz)This class represents AppArmor exceptionscCs
||_dS�N)�value)�selfr�r�1/usr/lib/python3/dist-packages/apparmor/common.py�__init__!�
zAppArmorException.__init__cCs
t|j�Sr)�reprr�rrrr�__str__$r
zAppArmorException.__str__N)�__name__�
__module__�__qualname__�__doc__r	r
rrrrrsrc@seZdZdZdS)�AppArmorBugzDThis class represents AppArmor exceptions "that should never happen"N)rrrrrrrrr'sr�TcCs@ztd|tjd�Wn	tyYnw|rt�|�dSdS)zPrint error message and exitz	ERROR: %s��fileN)�print�sys�stderr�IOError�exit)�out�	exit_code�do_exitrrr�error.s��rcCs.ztd|tjd�WdStyYdSw)zPrint warning messagezWARN: %srN)rrrr�rrrr�warn8s
�r cCs,ztd||d�WdStyYdSw)z
Print messagez%srN)rr)r�outputrrr�msg?s
�r"cCs6trztd|tjd�WdStyYdSwdS)zPrint debug messagez	DEBUG: %srN)�	DEBUGGINGrrrrrrrr�debugFs��r$�cCsd|d}t|t�r4d}|��D]}t|d|�t|||d|�d}q|r2t|d�d
Sd
St|t�s>t|t�rft|�dkrLt|d�d
St|d	�|D]	}t||d�qTt|d
�d
St|tj	�rs|�|�d
S|r�t|d||f�d
St|d|�d
S)z$ Recursively prints nested elements.� �Tz[%s]rFz[--- empty ---]r�[�]z%s = %sz- %sN)
�
isinstance�dict�keysr�recursive_print�list�tuple�len�rules�	_Raw_Rule)�src�dpth�key�tabs�empty�litemrrrr-Os,
�r-c
Cs�t|�ztj|tjtjd�}Wnty(}zdt|�gWYd}~Sd}~wwtjddkr;|�	�d�
dd�}n|�	�d}|j|gS)z!Try to execute the given command.)�stdoutr�Nr��ascii�ignore)r$�
subprocess�Popen�PIPE�STDOUT�OSError�strr�version_info�communicate�decode�
returncode)�command�sp�exrrrr�cmdps

���
rKc
Cs�ztj|tjd�}tj||jd�}Wnty*}zdt|�gWYd}~Sd}~wwtjddkr=|��d�	dd�}n|��d}|j
|gS)	z#Try to pipe command1 into command2.)r9)�stdinr:Nrr;r<r=)r>r?r@r9rBrCrrDrErFrG)�command1�command2�sp1�sp2rJrrrr�cmd_pipe�s��
rQcCsnd|}|�d�std|�dSd|vrtd|�dSz	tj�|�WdSty6td|�YdSw)	z
Valid pathzInvalid path: %s�/z
%s (relative)F�"z%s (contains quote)z%s (could not normalize)T)�
startswithr$�os�path�normpath�	Exception)rV�mrrr�
valid_path�s
��rZcCs:t|�sdSg}t�|d�D]}|�|�q|��|S)z$Find contents of the given directoryNz/*)rZ�glob�append�sort)rV�files�frrr�get_directory_contents�sr`cCs>tj�|�}|r|ddks|dkrdSd}|�|�rdSdS)aReturns True if filename matches something to be skipped (rpm or dpkg backup files, hidden files etc.)
        The list of skippable files needs to be synced with apparmor initscript and libapparmor _aa_is_blacklisted()
        path: filename (with or without directory)r�.�READMET)z	.dpkg-newz	.dpkg-oldz
.dpkg-distz	.dpkg-bakz.dpkg-removez.pacsavez.pacnewz.rpmnewz.rpmsavez.origz.rej�~F)rUrV�basename�endswith)rVrd�skippable_suffixrrr�is_skippable_file�s
rg�UTF-8cCstd||�S)zOpen specified file read-only�r��open_file_anymode)rV�encodingrrr�open_file_read��rmcCstd|d�S)z+Open specified file in write/overwrite mode�wrhrj)rVrrr�open_file_write�rnrpcCs,d}tjddkrd}tj||||d�}|S)zBCrash-resistant wrapper to open a specified file in specified mode�surrogateescaperr;�replace)�errors)rrD�codecs�open)�moderVrl�
errorhandling�origrrrrk�s
rkcCsZtj��}t�|�}zt�tj���tj�d�}Wt�|tj	|�|St�|tj	|�w)zReturns the pressed keyr)
rrL�fileno�termios�	tcgetattr�tty�setraw�read�	tcsetattr�	TCSADRAIN)�fd�old_settings�chrrr�readkey�s

�r�cCs
t�t�S)z+A neat alternative to perl's hash reference)�collections�defaultdict�hasherrrrrr��s
r�cCs�t�d�}|��}|�dd��dd�}t�dd|�}|�|�rE|�|���}|d}|d	}|d
�dd�}|d|d|}|�|�s|�d
d�}d}|�d|�}|�dd�}|�|d�}|ddkrid|}|ddkrs|d}|S)Nz^(.*){([^}]*)}(.*)$�(z\(�)z\)z(?<!\\)(\.|\+|\$)z\\\1r�r�,�|�?z[^/]�,__KJHDKVZH_AAPROF_INTERNAL_GLOB_SVCUZDGZID__z**�*z(((?<=/)[^/]+)|((?<!/)[^/]*))z(((?<=/)[^]+)|((?<!/)[^]*))�^����$)�re�compile�striprr�sub�search�groups)�regexp�regex_paren�new_reg�match�prev�after�p1�
multi_globrrr�convert_regexp�s*


�r�cCs"t�|tj�stj�d�dSdS)NzVCannot write to profile directory.
Please run as a user with appropriate permissions.
FT)rU�access�W_OKrr9�write)�prof_dirrrr�	user_permsr�r�cCst|�ttfvr
dSdS)zT returns True if the given variable is a str (or unicode string when using python 2)TF)�typerC�unicode)�varrrr�type_is_strsr�cCs6d|vr|�d�dd�\}}||fS|}|}||fS)Nz//r�)�split)�full_profile�profile�hatrrr�
split_names�r�c@sDeZdZdZefdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�DebugLoggerz�Unified debug facility. Logs to file or stderr.

    Does not log anything by default. Will only log if environment variable
    LOGPROF_DEBUG is set to a number between 1 and 3 or if method activateStderr
    is run.
    c	CsJd|_tj|_t�dd�r�d|_t�d�|_zt|j�|_Wnty*d|_Ynw|jt	dd�vr>t
j�dt�d��|jdkrEdS|jdkrOtj
|_n|jdkrYtj|_n	|jd	krbtj|_ztj|j|jd
d�Wn,ty�ddl}|jdd
ddd�}t
j�d|j|jf�tj|j|jd
d�Ynwt�|�|_dSdS)NF�
LOGPROF_DEBUGz/var/log/apparmor/logprof.logrr'z>Environment Variable: LOGPROF_DEBUG contains invalid value: %srr�r;z%%(asctime)s - %(name)s - %(message)s
)�filename�level�formatro�apparmorz.log)�prefix�suffix�deletez#
Could not open: %s
Logging to: %s
)�	debugging�logging�DEBUG�debug_levelrU�getenv�logfile�intrX�rangerr9r��ERROR�INFO�basicConfigr�tempfile�NamedTemporaryFile�name�	getLogger�logger)r�module_namer��templogrrrr	+sH
��






�
��	�zDebugLogger.__init__cCs*d|_tj|jdtjd�t�t�|_dS)NTz%(levelname)s: %(message)s)r�r��stream)	r�r�r�r�rrr�rr�rrrr�activateStderrPs�zDebugLogger.activateStderrcC�|jr|j�|�dSdSr)r�r�r�r�messagerrrrY��zDebugLogger.errorcCr�r)r�r��infor�rrrr�]r�zDebugLogger.infocCr�r)r�r�r$r�rrrr$ar�zDebugLogger.debugcCst��dSr)r��shutdownrrrrr�eszDebugLogger.shutdownN)
rrrrr	r�rr�r$r�rrrrr�$s%	r�)rT)rr%)rh)+�
__future__rrtr�r[r�rUr�r>rrzr|�apparmor.rulesr1r#rXrrrr r9r"r$r-rKrQrZr`rgrmrprkr�r�r�r�rDrCr�r�r��objectr�rrrr�<module>sJ


	!