403 Forbidden


Disable Functions:
Path : /usr/libexec/kcare/python/kcarectl/
File Upload :
Command :
Current File : //usr/libexec/kcare/python/kcarectl/libcare.pyo

�
o��fc@sddlZddlZddlZddlZddlZddlmZddlmZddlmZddlm	Z	ddlm
Z
ddlmZdd	lmZdd
lm
Z
ddlmZddlmZdd
lmZddlmZddlmZmZmZer=ddlmZmZmZndZd>ZdZdZdZdZ idd6dd6dd6dd6dd6Z!idddgd6ddgd6dd gd!6Z"d"�Z#d#�Z$d$e%fd%��YZ&d&�Z'dd'�Z)d(�Z*d)�Z+d*�Z,e-dd+�Z.d,�Z/d-�Z0e$d.��Z1e$d/��Z2d0�Z3d1�Z4d2�Z5d3�Z6d4�Z7d5�Z8e$e'd6���Z9ej:e$e'ej;dd7����Z<e$d8��Z=d9�Z>d:�Z?dd;�Z@d<�ZAd=�ZBdS(?i����Ni(t	constants(tconfig(tconfig_handlers(t	log_utils(t
process_utils(tutils(tauth(terrors(tselinux(tfetch(tupdate_utils(tserver_info(tjson_loads_nstrturlquotet	HTTPError(tDicttListtTuples!/usr/libexec/kcare/libcare-clients/run/libcare/libcare.socks/var/run/libcare.socki<s /var/cache/kcare/libcare_patchess /var/cache/kcare/libcare_cvelists&/etc/sysconfig/kcare/libcare.logrotatetdbtmysqldtmariadbdtpostgrestqemusqemu-kvmsqemu-system-x86_64tlibctlibssltlibscGstjjtjd||�S(Nt	userspace(tostpathtjoinRtPATCH_CACHE(tlibnametparts((s-/usr/libexec/kcare/python/kcarectl/libcare.pytget_userspace_cache_path/scs�fd�}|S(NcsYz�||�SWdytd�Wn/tk
rS}tjdj|�dt�nXXdS(Nt
clearcaches$Libcare cache clearing failed: '{0}'t	print_msg(tlibcare_clientt	ExceptionRtlogerrortformattFalse(targstkwargsterr(tclbl(s-/usr/libexec/kcare/python/kcarectl/libcare.pytwrapper4s((R,R-((R,s-/usr/libexec/kcare/python/kcarectl/libcare.pytclear_libcare_cache3s
tUserspacePatchLevelcBs)eZdd�Zdd�Zd�ZRS(cCst||�j||�S(N(tsupert__new__(tclsRtbuildidtleveltbaseurl((s-/usr/libexec/kcare/python/kcarectl/libcare.pyR1BscCs(||_||_||_||_dS(N(R4RR3R5(tselfRR3R4R5((s-/usr/libexec/kcare/python/kcarectl/libcare.pyt__init__Es			cGst|j|jt|�|�S(N(R!RR3tstr(R6R ((s-/usr/libexec/kcare/python/kcarectl/libcare.pyt
cache_pathKsN(t__name__t
__module__tNoneR1R7R9(((s-/usr/libexec/kcare/python/kcarectl/libcare.pyR/Ascsd����fd�}|S(NcSsd
\}}z�|dkr't�}ni}g}xft|�D]X}|jdd�||jd�<x0|jdg�D]}|j|jd��qxWq@Wdjg|j�D]}dj|�^q��}dj|�}Wdtjt	|d	t
�tjt|d	t
�XdS(s(KPT-1543 Save info about applyed patchestslatest-versiontpackagetpatchestcves
t Nt
ensure_dir(R=R=(R<t
_libcare_infot_get_patches_infotgettappendRtitemsRtatomic_writetLIBCARE_PATCHEStTruetLIBCARE_CVE_LIST(tinfotversionstcvestpackagest	cves_listtrectpatch((s-/usr/libexec/kcare/python/kcarectl/libcare.pytsave_current_statePs1cs/d}z�||�}|SWd�|�XdS(N(R<(R)R*RL(R,RS(s-/usr/libexec/kcare/python/kcarectl/libcare.pyR-bs
((R,R-((R,RSs-/usr/libexec/kcare/python/kcarectl/libcare.pytrefresh_applied_patches_listOs	c
Cs�tjpd}t|�}tjtj|d�|||d�}|dtjtj	d|��7}tj|d�}y"t
jtj
�|dt�}Wn3tjk
r�tjt||�dt��nXtj|j�ttj|j���}t|||d	|jd
��}t|d	�}	t|||	d�}
tjj|
�sltjj |
�dkr�tj|d
�}y,t
j!||
dtj"dt
j#|��Wq�t$k
r�}|j%dkr�tj&d��n�q�Xnt|||	�}dd|
d|dg}
t'j(|
dtdt�\}}}|r]tj)dj*|||���nt||d�}tjj+|�r�tjj,|�r�tj|�ntj-|	|d�tj.|d|�dS(Ntmaintus	latest.v1s?info=tupdateRt
check_licenset
ignore_errorsR4R5spatch.tar.gzit	patch_urltcheck_signaturethash_checkeri�i�sKC+ licence is requiredttartxfs-Cs--no-same-ownertcatch_stdouttcatch_stderrs(Patches unpacking error: '{0}' '{1}' {2}tlatests.tmp(i�i�(/RtPREFIXR
Rtget_patch_server_urltLIBNAME_MAPRERtencode_server_lib_infotserver_lib_infoR	twrap_with_cache_keyRturlopen_authR(RtNotFoundtshutiltrmtreeR!RJRtset_config_from_patchservertheadersRtnstrtreadR/R8RRtexiststgetsizet	fetch_urlt
USE_SIGNATUREtget_hash_checkerRtcodetNoLibcareLicenseExceptionRtrun_commandt
KcareErrorR'tislinktisdirtsymlinktrename(Rtbuild_idtpatch_leveltprefixturlt	cache_dsttresponsetmetaR4tplevelt
patch_pathtextdsttcmdRutstdouttstderrt	link_name((s-/usr/libexec/kcare/python/kcarectl/libcare.pytfetch_userspace_patchmsB'#""+,
$!%cCsj|t_|st�ntjd|r/dnd�|rFt�ntjjd|r^dnd�dS(NtLIBCARE_DISABLEDtFALSEtYESslibcare service is tenabledtdisabled(	RR�tlibcare_server_stopRt
update_configtlibcare_server_startRtkcarelogRL(R�((s-/usr/libexec/kcare/python/kcarectl/libcare.pytset_libcare_status�s


cCsEytjdd�ddg}Wntk
r3dSXtj|�dS(Ntservices
/usr/sbin/s/sbin/tlibcaretstop(s
/usr/sbin/s/sbin/(Rtfind_cmdR%Rw(R�((s-/usr/libexec/kcare/python/kcarectl/libcare.pyR��s

cCs�tjstjjtj�rStjtjddg�tjtjddg�nAytjdd	�ddg}Wnt	k
r�dSXtj|�dS(
Nsreset-failedR�trestartslibcare.socketR�s
/usr/sbin/s/sbin/tstart(s
/usr/sbin/s/sbin/(
RtSKIP_SYSTEMCTL_CHECKRRRpt	SYSTEMCTLRRwR�R%(R�((s-/usr/libexec/kcare/python/kcarectl/libcare.pyR��s
csadjd�t|pg�D��}ddg}�sM|dd|g7}nyt|�}Wn+tk
r�}tjdj|���nXg}xN|jd�D]=}|r�y|jt	j
|��Wq�tk
r�q�Xq�q�Wg|D]3}i|jd	�d	6|jd
�d
6|d6^q�}x8|D]0}t
�fd�|dj�D��|d<q)W|S(
Nt|css|]}dj|�VqdS(s({0})N(R'(t.0tproc((s-/usr/libexec/kcare/python/kcarectl/libcare.pys	<genexpr>�sRLs-js-ls-rs/Gathering userspace libraries info error: '{0}'s
tcommtpidRc3s4|]*\}}d|ks"�r||fVqdS(tpatchlvlN((R�tktv(tpatched(s-/usr/libexec/kcare/python/kcarectl/libcare.pys	<genexpr>�s(RtsortedR$R%RRxR'tsplitRFtjsontloadst
ValueErrortpoptdictRG(R�tlimittregexpR�tlinesR+tresulttline((R�s-/usr/libexec/kcare/python/kcarectl/libcare.pyRC�s&%
@
.c	Cs�t�}xJ|D]B}x9|dj�D]'\}}|j|d|df�q'WqWg}x�tD]{}xr|D]j\}}t||t|�d�}	tjj|	�rpt	|	d��}
|j
tj|
��WdQXqpqpWqcW|S(NRR3R�s	info.jsontr(
tsetRGtaddt
USERSPACE_MAPR!R8RRtisfiletopenRFR�tload(RLR?RQt_tdataR�R�R}R�tpatch_info_filenametfd((s-/usr/libexec/kcare/python/kcarectl/libcare.pyRD�s	
#
'cCs
tt��S(N(RDRC(((s-/usr/libexec/kcare/python/kcarectl/libcare.pytlibcare_patch_info_basic�scCs3t�}|stjd�ntji|d6�S(NsNo patched processes.R�(R�RR&R�tdumps(R�((s-/usr/libexec/kcare/python/kcarectl/libcare.pytlibcare_patch_info�s	cCs3t�}|stjd�ntji|d6�S(NsNo patched processes.R�(RCRR&R�R�(R�((s-/usr/libexec/kcare/python/kcarectl/libcare.pytlibcare_info�s	cCs=i}x0t�D]%}|jdd�||jd�<qW|S(Nslatest-versionR=R>(R�RE(R�RQ((s-/usr/libexec/kcare/python/kcarectl/libcare.pyt_libcare_version�s#cCs7x0t�j�D]\}}|j|�r|SqWdS(NR=(R�RGt
startswith(RR>tversion((s-/usr/libexec/kcare/python/kcarectl/libcare.pytlibcare_versionscCsdjd�|D��dS(NR=css"|]}tj|�dVqdS(tN(Rtbstr(R�tp((s-/usr/libexec/kcare/python/kcarectl/libcare.pys	<genexpr>
sR�(R(tparams((s-/usr/libexec/kcare/python/kcarectl/libcare.pytlibcare_client_format	scCs:x$tD]}tjj|�r|SqWtjd��dS(NsLibcare socket is not found.(tLIBCARE_SOCKETRRRpRRx(tlibcare_socket((s-/usr/libexec/kcare/python/kcarectl/libcare.pytget_available_libcare_socket
s
cGs
tjrtjd��ntjtjtjd�}|jd�d}z�|jt	��|jt
�t|�}tj
djd|��|j|�x-tr�|jd�}|s�Pn||7}q�W|jdd	�}tj
d
jd|��|SWd|j�XdS(NsLibcare is disabled.ii
R=sLibcare socket send: {cmd}R�isutf-8treplaces!Libcare socket recieved: {result}R�(RR�RRxtsockettAF_UNIXtSOCK_STREAMt
settimeouttconnectR�tLIBCARE_SOCKET_TIMEOUTR�RtlogdebugR'tsendallRJtrecvtdecodetclose(R�tsocktresR�R�R�((s-/usr/libexec/kcare/python/kcarectl/libcare.pyR$s(	


	cCs�x�|D]�}ytdt|��Wn+tk
rQ}tjdj|���nXytd�Wqtk
r�}tjdj|���qXqWdS(Ntstorages(Userspace storage switching error: '{0}'RWs%Userspace patch applying error: '{0}'(R$R!R%RRxR'(R�R�R+((s-/usr/libexec/kcare/python/kcarectl/libcare.pytlibcare_patch_apply,s
cCs@ytd�Wn+tk
r;}tjdj|���nXdS(Ntunloads&Userspace patch unloading error: '{0}'(R$R%RRxR'(R+((s-/usr/libexec/kcare/python/kcarectl/libcare.pytlibcare_unload9scCs�tj�t�|tjkr.tjr.dS|dkrOtt	j
��}ng}x'|D]}|jt	j|g��q\W|s�t
jdj|��dStd|�\}}}}|r�tjd��n|s�t
jd�dStjtjjtjd��t�yt|�Wn8tjk
rW}t
jt|��tjd��nXt�}	t|	�}
ttd�|	D���s�dSt
jdjd	|��t
jd
jd|
��t d�|
j!�D��}t d
�|j!�D��}||}
t"d�|
j!�D��}t
jdjdt#|
�d|��x9|
j$�D]+\}}t
jdj|t#|���qOW|	S(s0Patch userspace processes to the latest version.sNo such userspace patches: {0}R�s:There was an errors while patches downloading (unpacking).sNo patches were found.Rs+There was an errors while patches applying.css|]}|dVqdS(RN((R�titem((s-/usr/libexec/kcare/python/kcarectl/libcare.pys	<genexpr>tssPatched before: {before}tbeforesPatched after: {after}taftercss"|]}|D]}|Vq
qdS(N((R�RGR�((s-/usr/libexec/kcare/python/kcarectl/libcare.pys	<genexpr>{scss"|]}|D]}|Vq
qdS(N((R�RGR�((s-/usr/libexec/kcare/python/kcarectl/libcare.pys	<genexpr>|scss|]}t|�VqdS(N(tlen(R�R�((s-/usr/libexec/kcare/python/kcarectl/libcare.pys	<genexpr>ss�The patches have been successfully applied to {count} newly discovered processes. The overall amount of applied patches is {overall}.tcounttoveralls*Object `{0}` is patched for {1} processes.N(%Rtlog_all_parent_processestrotate_libcare_logsRtUPDATE_MODE_AUTORtLIB_AUTO_UPDATER<tlistR�tkeystextendRERtloginfoR'tcheck_userspace_updatesRRxRtrestore_selinux_contextRRRRR�R&R8RCt_get_userspace_procstanyR�R�tvaluestsumR�RG(tmodeR�tprocess_filtertuserspace_patchtfailedtsomething_foundR�R�R�t
data_afterR�tuniq_procs_aftertuniq_procs_beforetdiffR�R�R�((s-/usr/libexec/kcare/python/kcarectl/libcare.pytdo_userspace_updateBsR


	
	#cCs_yt�\}}}}Wntjk
r0dSX|r;dS|rEdStjdd�r[dSdS(Niitfilenames.libcarestatusii(R�RRxR
tstatus_gap_passed(R�R�tlibs_not_patched((s-/usr/libexec/kcare/python/kcarectl/libcare.pytget_userspace_update_status�scCs�i}xy|D]q}xh|dj�D]V\}}|jd�r$||krXg||<n||j|d|df�q$q$Wq
W|S(NRR�R�R�(RGRERF(RLR�R�RRQ((s-/usr/libexec/kcare/python/kcarectl/libcare.pyR��s

*cCset�}xU|D]M}xD|dj�D]2\}}|j||d|jdd�f�q'WqW|S(NRR3R�i(R�RGR�RE(RLR�R�RRQ((s-/usr/libexec/kcare/python/kcarectl/libcare.pyt_get_userspace_libs�s
	
.cCs?|s5g}gtj�D]}|j|�^qntdtd|�}t|�}t}}t}x�t|�D]�}|\}}	}
y/t||	|
�t}|
dkr�t}nWqst	j
t	jfk
r�qst	jk
r��qst	j
k
r}t}tjt|��qsXqsWtjdd�||||fS(NR�R�iR�s.libcarestatus(R�R�R�RCR(R�RJRR�RRiRvtAlreadyTrialedExceptionRxRR&R8R
ttouch_status_gap_file(R�Rtdata_beforeR�R�R�RRQRR}R�R�((s-/usr/libexec/kcare/python/kcarectl/libcare.pyR��s.)

cCs�d}d}tjddt�}|r�y(tj|tgdt�\}}}Wn%tk
rv}d}t|�}nX|r�tj	dj
|�dt�q�ntjd	dt�d
}tj
j|�s�dStjd}y�tj|�}tjd
�}g|D]*}	|j|	�rtj
j||	�^q}
g|
D]}tj
j|�|f^q:}|jdt�d}
xY|D]Q\}}|
tj
j|�7}
|
|kr{tj|�tjjd|�q{q{WWn$tk
r�tjddt�nXdS(NiR=t	logrotatet	raise_excR`is5failed to run logrotate for libcare logs, stderr: {0}R#slogrotate utility wasn't founds/var/log/libcare/iis^\d+\.log.*treverses%Removed %s because of logs size limits)Failed to cleanup libcare server logfilesi(RR�R(RwtLIBCARE_LOGROTATE_CONFIGRJR%R8RR&R'tlogwarnRRRzRt!LIBCARE_PIDLOGS_MAX_TOTAL_SIZE_MBtlistdirtretcompiletmatchRtgetctimetsortRqtremoveR�RLtlogexc(trcR�tlogrotate_pathR�tetlibcare_log_directorytmax_total_sizet	log_filest	pidlog_retfntpidlog_filestfptpidlog_files_with_ctt
total_sizetfilepath((s-/usr/libexec/kcare/python/kcarectl/libcare.pyR��s<("
7+

cCsbytjdd	�ddg}Wntk
r3tSXtj|dtdt�\}}}|dkS(
sKAssume that whenever the service is not running, we did not patch anything.R�s
/usr/sbin/s/sbin/R�tstatusR_R`i(s
/usr/sbin/s/sbin/(RR�R%R(RwRJ(R�RuR�((s-/usr/libexec/kcare/python/kcarectl/libcare.pytlibcare_server_started�s
$(s/run/libcare/libcare.socks/var/run/libcare.sock(CRRRjR�R�R=RRRRRRRRRR	R
Rtpy23RR
RR(ttypingRRRtLIBCARE_CLIENTR�R�RIRKR
RdR�R!R.tintR/RTR<R�R�R�R�RJRCRDR�R�R�R�R�R�R�R$R�R�tskip_if_no_selinux_moduletUPDATE_MODE_MANUALR�RR�RR�R�R#(((s-/usr/libexec/kcare/python/kcarectl/libcare.pyt<module>s|)
			,	
										
G			*

404 Not Found
[ LogOut ]