ok

Mini Shell

Direktori : /opt/imunify360/venv/lib/python3.11/site-packages/im360/plugins/__pycache__/
Upload File :
Current File : //opt/imunify360/venv/lib/python3.11/site-packages/im360/plugins/__pycache__/cagefs.cpython-311.pyc

�

�cg�����dZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZddlm
Z
mZddlmZmZddlmZd	Zd
Zeje��ZGd�de
��ZdS)
a
Goal: Invoke

    /usr/sbin/cagefsctl --update-etc
    /usr/sbin/cagefsctl --force-update-etc

    asynchronously. As far production scale `cagefsctl --force-update-etc`
    tends last for too long, e.g. -

    # time cagefsctl --force-update-etc
    Updating users ...
    Updating user user523 ...
    Updating user user804 ...
    ...
    Updating user user269 ...
    Updating user user116 ...
    Updating user user121 ...
    Updating user user117 ...

    real    2m44.454s
    user    0m26.233s
    sys     0m19.972s
�N)�Optional)�
inactivity)�MessageType)�MessageSink�expect)�
load_state�
save_state)�timefunz/usr/sbin/cagefsctlz--wait-lockc��eZdZd�Zd�Zeej��d���Zd�Z	e
ej���de
efd���Zed���Zd	S)
�CageFSc��K�||_tj��|_t	d���dd��|_|j�|�����|_	dS)Nr�last_force_update_tsr)
�_loop�asyncio�Queue�_queuer�get�_last_force_update_ts�create_task�	_consumer�_consumer_task)�self�loops  �I/opt/imunify360/venv/lib/python3.11/site-packages/im360/plugins/cagefs.py�create_sinkzCageFS.create_sink,si������
��m�o�o���%/��%9�%9�%=�%=�"�A�&
�&
��"�#�j�4�4�T�^�^�5E�5E�F�F�����c��K�|j���|j�d{V��|j���r2t�d|j�����t
dd|ji��dS)Nz%d item(s) were not consumedrr)r�cancelr�qsize�logger�warningr	r)rs r�shutdownzCageFS.shutdown4s�������"�"�$�$�$��!�!�!�!�!�!�!�!��;�����	P��N�N�9�4�;�;L�;L�;N�;N�O�O�O���-�t�/I�J�	
�	
�	
�	
�	
rc��K�|d}t|dd��}|�|�|j��r|j�|��dSdS)N�conf�username)�getattr�modified_sincerr�
put_nowait)r�message�configr%s    r�put_to_queuezCageFS.put_to_queue?si���������6�:�t�4�4����6�#8�#8��&�$
�$
��
�K�"�"�8�,�,�,�,�,� �rc��NK�		|j����d{V��}tj�t
��s�F|h}		|�|j������-#tj	$rYnwxYwtj�d��5|D]}|�
|���d{V���	ddd��n#1swxYwYn<#tj$rYdSt$rt �d��Y��wxYw��#)z
        :raise never:
        TN�cagefszSomething went wrong)rr�os�path�exists�_CAGEFSCTL_TOOL�add�
get_nowaitr�
QueueEmptyr�track�task�
_commitconfig�CancelledError�	Exceptionr �	exception)r�commitconfig_username�uniqr%s    rrzCageFS._consumerMs�����	�
�.2�k�o�o�.?�.?�(?�(?�(?�(?�(?�(?�%��w�~�~�o�6�6���.�.���;������!7�!7�!9�!9�:�:�:�;���)�����D����� �%�*�*�8�4�4�;�;�$(�;�;��"�0�0��:�:�:�:�:�:�:�:�:�:�;�;�;�;�;�;�;�;�;�;�;�;����;�;�;�;����)�
�
�
�����
�
�
�� � �!7�8�8�8���	
����/	s`�AC)�	C)�
.A;�;B
�
C)�B
�
"C)�/!C�C)�C!�!C)�$C!�%C)�)D"�;#D"�!D")�logr%c��JK�|rttd|g}nttdg}	tj|tjtjtjdd���d{V��}|�|tj	|j
��}|�|tj|j��}tj
||���d{V��|����d{V��\}}|����d{V��}|�t �d��dS|r t �d||||��dSt �d||��|�t'j��|_dSdS#tj$rt �d	|���wxYw)
zJ
        :raise asyncio.CancelledError:
        :raise Exception:
        z--update-etcz--force-update-etcF)�stdin�stdout�stderr�start_new_sessionNz+logic error: process has not terminated yetz,%r failed with rc [%s], stdout=%s, stderr=%sz%r succeeded with rc [%s]z"%r is terminated by CancelledError)r1�
_WAIT_LOCKr�create_subprocess_exec�
subprocess�DEVNULL�PIPE�
_passthru_log�logging�DEBUGr@�WARNrA�gather�communicate�waitr �error�info�timerr8r!)	rr%�cmd�proc�future1�future2�out�err�rcs	         rr7zCageFS._commitconfigns������	F�"�J���I�C�C�"�J�0D�E�C�"	=� �7�� �(�!��!��#(����������D��(�(��g�m�T�[�I�I�G��(�(��g�l�D�K�H�H�G��.��'�2�2�2�2�2�2�2�2�2�!�-�-�/�/�/�/�/�/�/�/�H�C���y�y�{�{�"�"�"�"�"�"�B�
�z����J�K�K�K�K�K��
=����B�������������7��b�A�A�A��#�15����D�.�.�.�$�#��!�%�	�	�	��N�N�?��E�E�E��	���s�CE6�6,F"c��K�	|����d{V��}|sdSt�|d||���<)NTz%r: %r)�readliner r=)rR�loglevel�streamreader�lines    rrHzCageFS._passthru_log�sX����	6�%�.�.�0�0�0�0�0�0�0�0�D��
����J�J�x��3��5�5�5�		6rN)�__name__�
__module__�__qualname__rr"rr�ConfigUpdater+rr
r rPr�strr7�staticmethodrH�rrrr+s�������G�G�G�	
�	
�	
��V�K�$�%�%�-�-�&�%�-����B
�W������,=�H�S�M�,=�,=�,=���,=�\�6�6��\�6�6�6rr)�__doc__rrIr.rErQ�typingr�defence360agent.apir�"defence360agent.contracts.messagesr�!defence360agent.contracts.pluginsrr�'defence360agent.subsys.persistent_staterr	�defence360agent.utilsr
r1rC�	getLoggerr^r rrdrr�<module>rms����.��������	�	�	�	���������������*�*�*�*�*�*�:�:�:�:�:�:�A�A�A�A�A�A�A�A�J�J�J�J�J�J�J�J�)�)�)�)�)�)�'��
�
�	��	�8�	$�	$��x6�x6�x6�x6�x6�[�x6�x6�x6�x6�x6r

Zerion Mini Shell 1.0