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: //lib/python3/dist-packages/apparmor/__pycache__/profile_storage.cpython-310.pyc
o

T��eh$�@sTddlmZmZddlmZddlmZddlmZddl	m
Z
ddlmZddl
mZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZe�Zdeideideideide
ideideideideideideid�ZGdd�d�Zdd�Z dd�Z!dd�Z"dd�Z#dd�Z$dd�Z%dd �Z&d!d"�Z'd#d$�Z(d%S)&�)�AppArmorBug�type_is_str)�
AbiRuleset)�CapabilityRuleset)�ChangeProfileRuleset)�DbusRuleset)�FileRuleset)�IncludeRuleset)�NetworkRuleset)�
PtraceRuleset)�
RlimitRuleset)�
SignalRuleset)�MessageQueueRuleset)�quote_if_needed)�init_translation�ruleset)�abi�inc_ie�
capability�change_profile�dbus�file�network�ptrace�rlimit�signal�mqueuec@sBeZdZdZdd�Zdd�Zdd�Zdd	�Zddd�Zd
d�Z	d
S)�ProfileStoragez�class to store the content (header, rules, comments) of a profilename

       Acts like a dict(), but has some additional checks.
    cCs�t�}|||d�|d<tD]}t|d�||<q
d|d<d|d<d|d<d|d<d|d	<d|d
<d|d<d|d
<d|d<d|d<d|d<t�|d<t�|d<t�|dd<t�|dd<t�|dd<t�|dd<t�|dd<t�|dd<||_dS)N)�profile�hat�calledby�infor��filename�logprof_suggest�name�
attachment�xattrs�flagsF�external�header_comment�initial_comment�profile_keywordr�allow�deny�mount�
pivot_root�unix)�dict�	ruletypes�list�data)�self�profilenamerr r5�rule�r9�:/usr/lib/python3/dist-packages/apparmor/profile_storage.py�__init__9s0


zProfileStorage.__init__cCs ||jvr
|j|Std|���Nzattempt to read unknown key %s)r5r)r6�keyr9r9r:�__getitem__[s

zProfileStorage.__getitem__cCs||jvrtd|��t|j|�tkr2t|�tkr!||j|<dStd|t|j|�t|�|f��|dvrVt|�s>|durE||j|<dStd|t|j|�t|�|f��t|j|�ryt|�rh||j|<dStd|t|j|�t|�|f��td||t|�f��)Nzattempt to set unknown key %sz6Attempt to change type of "%s" from %s to %s, value %s)r'r(r#z*Attempt to overwrite "%s" with %s, type %s)r5r�type�boolr)r6r=�valuer9r9r:�__setitem__as
"""zProfileStorage.__setitem__cCsdd�|�d��S)Nz'
<ProfileStorage>
%s
</ProfileStorage>
�
�)�join�get_rules_clean)r6r9r9r:�__repr__~szProfileStorage.__repr__NcCs$||jvr|j�||�Std|��r<)r5�getr)r6r=�fallbackr9r9r:rH�s
zProfileStorage.getcCsZtttd�}gd�}g}|D]}|�|�r ||||j|�7}q||j|�|�7}q|S)z�return all clean rules of a profile (with default formatting, and leading whitespace as specified in the depth parameter)

           Note that the profile header and the closing "}" are _not_ included.
        )r/r0r1)rrrrrrr/rrrr0r1rr)�write_mount�write_pivot_root�
write_unixrHr5�	get_clean)r6�depth�write_functions�write_orderr5�ruletyper9r9r:rF�s�
zProfileStorage.get_rules_clean)N)
�__name__�
__module__�__qualname__�__doc__r;r>rBrGrHrFr9r9r9r:r3s"
rcCs(|durd}|�dd���}tt|��S)zAsplit the flags given as string into a sorted, de-duplicated listNr"�,� )�replace�split�sorted�set)r(�
flags_listr9r9r:�split_flags�sr]cCs|t|�s|durt|�}t|�s|durt|�}|r,|D]}||vr'|�|�qt|�S|D]}||vr9|�|�q.t|�S)zFadd (if set_flag == True) or remove the given flags_to_change to flagsN)rr]�append�removerZ)r(�flags_to_change�set_flag�flag_to_changer9r9r:�add_or_remove_flag�s
��
�rccCs2g}t|�D]
}|sd}|�t|��qd�|�S)Nz""rW)rZr^rrE)�refr5rAr9r9r:�
var_transform�s
recC�Vd|}g}||�dd�s|S||dD]
}|�d||��f�q|�d�|S)N�  r/F�%s%sr"�rHr^�	serialize)�	prof_datarNr-�prer5�
mount_ruler9r9r:�write_mount_rules��
rncC� t||d�}|t||d�7}|S�Nr.r-)rn�rkrNr5r9r9r:rJ��rJcCrf)Nrgr0Frhr"ri)rkrNr-rlr5�pivot_root_ruler9r9r:�write_pivot_root_rules�rorucCrprq)rurrr9r9r:rK�rsrKcCrprq)�write_unix_rulesrrr9r9r:rL�rsrLcCrf)Nrgr1Frhr"ri)rkrNr-rlr5�	unix_ruler9r9r:rvrorvN))�apparmor.commonrr�apparmor.rule.abir�apparmor.rule.capabilityr�apparmor.rule.change_profiler�apparmor.rule.dbusr�apparmor.rule.filer�apparmor.rule.includer	�apparmor.rule.networkr
�apparmor.rule.ptracer�apparmor.rule.rlimitr�apparmor.rule.signalr
�apparmor.rule.mqueuer�
apparmor.ruler�apparmor.translationsr�_r3rr]rcrernrJrurKrLrvr9r9r9r:�<module>sJ�}