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__/config.cpython-310.pyc
o

%`b�2�@s�ddlmZddlZddlZddlZddlZddlZddlZejdkr1ddl	Z
Gdd�de
j	�Znddl
Z
ddlm
Z
mZGdd�de�Zd	d
�ZdS)�)�with_statementN��rc@seZdZdd�ZdS)�configparser_py2cCs*|�|�}t�}|D]\}}|||<q
|S)N)�items�dict)�self�section�section_val�section_options�option�value�r�1/usr/lib/python3/dist-packages/apparmor/config.py�__getitem__s


zconfigparser_py2.__getitem__N)�__name__�
__module__�__qualname__rrrrrrsr)�AppArmorException�open_file_readc@sVeZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�ZdS)�Config�
/etc/apparmorcCs.||_|dks|dkr||_d|_dStd��)N�shell�inizUnknown configuration file type)�CONF_DIR�	conf_type�
input_filer)rr�conf_dirrrr�__init__-s

zConfig.__init__cCs.|jdkrdt�i}|S|jdkrt��}|S)Nr�r)rr�configparser�ConfigParser)r�configrrr�
new_config6s


�zConfig.new_configcCs�tj�|j|�}||_|jdkr|�|�}|S|jdkrVtjdkr&t	�
�}nt�}t|_
tjdkr8|�|�|Sz|�|�W|St	jyUt|�}|�|j�Y|Sw|S)zGReads the file and returns a config[section][attribute]=property objectrrr)�os�path�joinrrr�
read_shell�sys�version_infor r!r�str�optionxform�read�ParsingError�
py2_parser�name)r�filename�filepathr"�tmp_filepathrrr�read_config=s,


�



���zConfig.read_configcCs�tj�|j|�}tjtjB}z@tjddd|jd�}tj�	|j
�r)t�|j
|j
�nt�|j
|�|jdkr=|�|||�n|jdkrI|�|||�|��Wn
ty[td|��wt�|j
|�dS)	z-Writes the given config to the specified file�w�aa_tempF)�prefix�delete�dirrrzUnable to write to %sN)r$r%r&r�stat�S_IRUSR�S_IWUSR�tempfile�NamedTemporaryFile�existsr�shutil�copymoder/�chmodr�write_shell�write_configparser�close�IOErrorr�rename)rr0r"r1�permission_600�config_filerrr�write_configUs 

�zConfig.write_configcC�0d}|r|��D]
}tj�|�r|}|Sq|S)z2Returns name of first matching file None otherwiseN)�splitr$r%�isfile)r�	file_listr0�frrr�find_first_filem��zConfig.find_first_filecCrJ)z7Returns name of first matching directory None otherwiseN)rKr$r%�isdir)r�dir_list�dirname�direcrrr�find_first_dirwrPzConfig.find_first_dircCs�dt�i}t|��2}|D]&}t�|d�}|r2d|dvr&|d�d�\}}n|d}d}||d|<qWd�|S1s>wY|S)zDReads the shell type conf files and returns config[''][option]=valuerT�=rN)rr�shlexrK)rr1r"�	conf_file�line�resultrr
rrrr'�s 

��
�
�
zConfig.read_shellcCs�dd�|d��D�}tj�|j�r�t|j���}|D]�}t�|d�}|r�d|dvr�|d�d�\}}	d|vrD|	�dd�d}
d|
}
nd}
||vr�|	|d|krw|d|}|d	urqd
|vrfd
|d
}|d||
d}n||
d}|�|�|�	|�q|d}d	}	||vr�|d|d	ur�|d|}	|d|	d}|�|�|�	|�q|�|�qWd	�n1s�wY|r�|D] }|d|}	|	d	ur�|d}n|d|	d}|�|�q�d	Sd	S)z-Writes the config object in shell file formatcSsg|]}|�qSrr)�.0�keyrrr�
<listcomp>�sz&Config.write_shell.<locals>.<listcomp>rTrVr�#�N�"�
)
�keysr$r%r>rrrWrK�write�remove)rr1�f_outr"�options�f_inrYrZrr
�comment�	value_newrrrrB�sX


�

���.
�zConfig.write_shellc
CsP|��}d}d}g}tj�|j�r�t|j���}|D]�}	|	���d�rc|r>|D]}
d|
d|||
d}|�|�q&g}||vrG|�	|�|	�
�dd�}||vr`d}|�|�}|�|	�qd	}q|r�t�
|	d�}|ss|�|	�q|	�
d
d�\}
}z|�
dd�\}}
d|
}
Wnty�d}
Ynw|
�
�|vr�|||
�
�|�
�kr�|�||||
�
��}|
d
||
}	|�|	�|�	|
�
��qWd�n1s�wY|r�|D]}
d|
d|||
d}	|�|	�q�g}||vr�|�	|�|D]'}|�d
|�|�|�}|D]}
d|
d|||
d}	|�|	��qq�dS)z6Writes/updates the given file with given config objectTN�[�  z = rar_���FrVr^rz
[%s]
)�sectionsr$r%r>rr�lstrip�
startswithrcrd�striprfrWrK�
ValueError�replace)rr1rer"rmrcr	rfrgrYr�line_newr
rhrrrrC�sp

�
���,

��zConfig.write_configparserN)r)rrrrr#r3rIrOrUr'rBrCrrrrr,s
	

?rcCs�t�d�}t|jd�}tj�|�rJt|��-}|D]"}|dd�dkr)|dd�}n|ddkr5|dd�}|�|�qWd�n1sEwY|�	�|S)	z6Returns the de-dented ini file from the new format ini�rwr4N�rkr�	r_)
r<r=�openr/r$r%r>rrc�flush)r0�tmprergrYrrrr.s

��	r.)�
__future__rr$rWr?r9r(r<r)r!r r�apparmor.commonrr�objectrr.rrrr�<module>s


l