*vhdZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z mZddlmZmZddlmZd Zd ZejeZGd 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) MessageSinkexpect) load_state save_state)timefunz/usr/sbin/cagefsctlz --wait-lockceZdZdZdZeejdZdZ e e j de efdZedZd S) CageFScK||_tj|_t ddd|_|j||_ dS)Nr last_force_update_tsr) _loopasyncioQueue_queuerget_last_force_update_ts create_task _consumer_consumer_task)selfloops S/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/plugins/cagefs.py create_sinkzCageFS.create_sink,si moo %/%9%9%=%= "A& & "#j44T^^5E5EFFcK|j|jd{V|jr2td|jt dd|jidS)Nz%d item(s) were not consumedr r)rcancelrqsizeloggerwarningr r)rs rshutdownzCageFS.shutdown4s ""$$$!!!!!!!! ;     P NN94;;L;L;N;N O O O -t/IJ     rcK|d}t|dd}|||jr|j|dSdS)Nconfusername)getattrmodified_sincerr put_nowait)rmessageconfigr%s r put_to_queuezCageFS.put_to_queue?si6:t44  6#8#8  &$ $  K " "8 , , , , , rcNK |jd{V}tjt sF|h} ||j-#tj $rYnwxYwtj d5|D]}| |d{V dddn #1swxYwYn<#tj$rYdSt$rt dYwxYw#)z :raise never: TNcagefszSomething went wrong)rrospathexists_CAGEFSCTL_TOOLadd get_nowaitr QueueEmptyrtracktask _commitconfigCancelledError Exceptionr exception)rcommitconfig_usernameuniqr%s rrzCageFS._consumerMs  .2koo.?.?(?(?(?(?(?(?%w~~o66..;!7!7!9!9:::;)D %**844;;$(;;"00::::::::::;;;;;;;;;;;;;;;;)        !7888  / s`AC) C) .A;;B  C) B  "C)/!C C)C!!C)$C!%C))D";#D"!D")logr%cJK|rttd|g}nttdg} tj|tjtjtjddd{V}||tj |j }||tj |j }tj ||d{V|d{V\}}|d{V}|t ddS|r t d||||dSt d|||t'j|_dSdS#tj$rt d |wxYw) zJ :raise asyncio.CancelledError: :raise Exception: z --update-etcz--force-update-etcF)stdinstdoutstderrstart_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_LOCKrcreate_subprocess_exec subprocessDEVNULLPIPE _passthru_logloggingDEBUGr@WARNrAgather communicatewaitr errorinfotimerr8r!) rr%cmdprocfuture1future2outerrrcs rr7zCageFS._commitconfigns  F"JICC"J0DEC" = 7 (!!#(D((gmT[IIG((glDKHHG.'22 2 2 2 2 2 2 2!--////////HCyy{{""""""B z JKKKKK = B  7bAAA#15D...$#!%    NN? E E E  s CE66,F"cK |d{V}|sdSt|d||<)NTz%r: %r)readliner r=)rRloglevel streamreaderlines rrHzCageFS._passthru_logsX 6%..00000000D  JJx3 5 5 5  6rN)__name__ __module__ __qualname__rr"rr ConfigUpdater+rr r rPrstrr7 staticmethodrHrrr r +sGGG     VK $%% - -&% -B W,=HSM,=,=,=,=\66\666rr )__doc__rrIr.rErQtypingrdefence360agent.apir"defence360agent.contracts.messagesr!defence360agent.contracts.pluginsrr'defence360agent.subsys.persistent_staterr defence360agent.utilsr r1rC getLoggerr^r r rdrrrms.  ******::::::AAAAAAAAJJJJJJJJ))))))'   8 $ $x6x6x6x6x6[x6x6x6x6x6r