File: //opt/cloudlinux/venv/lib/python3.11/site-packages/lve_utils/__pycache__/cagefs.cpython-311.pyc
�
��
j
� �B � d Z ddlZddlZddlZddlZdZdZddd�Zd� ZdS ) z�Helpers for CageFS interaction from lvectl / lvdctl.
Kept in python_lve to avoid a hard dependency on securelve: lve-utils
is installed on systems without CageFS, so anything we call here must
degrade to a no-op when CageFS is absent.
� Nz/usr/sbin/cagefsctlz/etc/cagefs/proxy.commandsz(/usr/share/lve-utils/lvd-registry-helperz&/usr/share/lve-utils/lvd-limits-helper)�LVD_REGISTRY_HELPER�LVD_LIMITS_HELPERc �n � t j � t � � sdS t t
dd�� � 5 } | � � � }ddd� � n# 1 swxY w Y n# t $ r d}Y nw xY w|}t � � � D ]Q\ }}||v r�
t j � |� � s�*|r|�
d� � s|dz
}||� d|� d�z
}�R||k rdS t j dt
� � t j �
t
� � }t j |d �
� � t j |d�� � \ }} t j |d
d�� � 5 } | � |� � ddd� � n# 1 swxY w Y t j |t
� � nB# t( $ r5 t j � |� � rt j |� � � w xY wt- j t dgt, j t, j d�� � dS )a5 Register LVD helper proxyexec entries in /etc/cagefs/proxy.commands.
No-op when CageFS is not installed (cagefsctl binary absent) or when
the entries are already present. When entries are added, runs
``cagefsctl --update-wrappers`` so the in-CageFS proxyexec wrappers
appear immediately.
N�rzutf-8)�encoding� �
�=zRegistering LVD helpers in %sT)�exist_okz.proxy.commands.)�dir�prefix�wz--update-wrappersF)�stdout�stderr�check)�os�path�exists�CAGEFSCTL_TOOL�open�PROXY_COMMANDS_PATH�read�FileNotFoundError�LVD_PROXY_ENTRIES�items�endswith�logging�info�dirname�makedirs�tempfile�mkstemp�fdopen�write�replace�
BaseException�unlink�
subprocess�run�DEVNULL)�f�content�new_content�key�binary� proxy_dir�fd�tmp_paths �G/opt/cloudlinux/venv/lib64/python3.11/site-packages/lve_utils/cagefs.py�ensure_lvd_proxy_commandsr4 ! s� � � �7�>�>�.�)�)� ����
�%�s�W�
=�
=�
=� ���f�f�h�h�G� � � � � � � � � � � ���� � � � ���� � � ��������� �K�(�.�.�0�0� +� +���V��+�����w�~�~�f�%�%� ��� �{�3�3�D�9�9� ��4��K��#�*�*��*�*�*�*����g������L�0�2E�F�F�F����� 3�4�4�I��K� �D�)�)�)�)��#� �:L�M�M�M�L�B���
�Y�r�3��
1�
1�
1� !�Q�
�G�G�K� � � � !� !� !� !� !� !� !� !� !� !� !���� !� !� !� !�
�
�8�0�1�1�1�1��� � � �
�7�>�>�(�#�#� ��I�h����
�����
�N� �,�-��!��!�� � � � � � sd �A, �A �A, � A$�$A, �'A$�(A, �,A;�:A;�!G �8F�G �F�G �!F�"G � ?G?) �__doc__r r r( r! r r r r4 � � r3 �<module>r8 st ��� � ���� � � � � � � � � ���� '��2� � F�A�� � �1� 1� 1� 1� 1r7