%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/modules/inspectlib/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pyo

�
���^c@@s ddlmZmZddlZddlZddlmZmZmZddl	Z	ddl
mZddlm
Z
ddlmZddlmZmZmZmZmZddlZddlZddlZddlZddlZddlmZyddlZWnek
r#eZnXe	j e!�Z"d	e
fd
��YZ#d�Z$d�Z%e!d
kre&ej'�dkr�e(ddej)�ej*d�nej'd\Z+Z,Z-e$e+�r�ej*d�nyFej.�dkrej/j0j1�ej*d�nej/j0j1�Wn e2k
r9Z3ej*d�nXej4�ej5d�y�ej.�Z6e6dkr�ej/j0j1�ej/j7j8ej9j:e+e
j;�d��Z<e<j=dj>e6��WdQXej*d�nWn e2k
r�Z3ej*d�nXej/j0j1�e%e,e+e-�ndS(i(tabsolute_importtprint_functionN(tPopentPIPEtSTDOUT(tInspectorSnapshotException(t	EnvLoader(tkiwiproc(t
AllowedDirt
IgnoredDirtPackagetPayloadFiletPackageCfgFile(tCommandExecutionErrort	Inspectorc
B@sOeZdZdddgZdddddgZd	d
ddgZd
dddddddddg
Zd/d/d/d�Zd�Z	d�Z
d/d/d�Zd�Zd�Z
d�Zd�Zd�Zd �Zd!�Zd"�Zd#�Zd$�Zd%�Zd&�Zd'�Zd(�Zd)�Zd*d+�Zed
d,d-�Zd,d
d.�ZRS(0s/etc/salt/miniont
configurationtpayloadtalltproctsysfstdevtmpfsttmpfssfuse.gvfs-fuse-daemontautofstcifstnfstnfs4s/tmps/var/tmps/lost+founds/var/runs/var/lib/rpms/.snapshotss/.zfss/etc/sshs/roots/homecC@s#tj|d|d|d|�dS(Ntcachedirtpiddirtpidfilename(Rt__init__(tselfRRR((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pyR8scC@s|jjdt�|S(s6
        Open new snapshot.

        :return:
        tnew(tdbtopentTrue(R((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pytcreate_snapshot;scC@s|jj�|S(sF
        Open an existing, latest snapshot.

        :return:
        (R R!(R((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pytreuse_snapshotDs
cG@sDt|gt|�dtdtdtd|p4tj�jd|�S(s2
        Call an external system command.
        tstdouttstdintstderrtenvtinput(RtlistRRtostenvirontcommunicate(RtcommandR)R(tparams((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pyt_syscallMs(cC@s[|jj�jd�dkr(|j�S|jj�jd�dkrP|j�St�SdS(sS
        Package scanner switcher between the platforms.

        :return:
        t	os_familytDebiantSusetredhatN(R3R4(tgrains_coretos_datatgett_Inspector__get_cfg_pkgs_dpkgt_Inspector__get_cfg_pkgs_rpmtdict(R((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pyt
_get_cfg_pkgsTs


c	C@s t�}xtjjj|jddddd�d�jtj	�D]�}|j
�}|sbqDnt�||<x�tjjj|jddddd|�d�jtj	�D]M}|j
�}|s�q�n|j
�jdd�\}}||j|�q�W||sD|j
|�qDqDW|S(	sY
        Get packages with configuration files on Dpkg systems.
        :return:
        s
dpkg-querys-Wfs${binary:Package}\nis${Conffiles}\nt iN(R:tsalttutilststringutilstto_strR0tNonetsplitR+tlineseptstripR*tappendtpop(Rtdatatpkg_nametpkg_cfg_itemtpkg_cfg_filetpkg_cfg_sum((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pyt__get_cfg_pkgs_dpkgas"	#
$ 
cC@s�|jddddddd�\}}t�}d}g}tjjj|�}xv|jtj	�D]b}|j
�}|s�qdn|jd�s�|r�|r�|||<n|}g}qd|j|�qdW|r�|r�|||<n|S(sG
        Get packages with configuration files on RPM systems.
        trpms-qas
--configfiless
--queryformats%{name}-%{version}-%{release}\nt/N(
R0RAR:R=R>R?R@RBR+RCRDt
startswithRE(RtoutterrRGRHtpkg_configstline((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pyt__get_cfg_pkgs_rpm~s&	
	
c	
C@s�t�}x�|j�D]�\}}t�}t�}|jj�jd�dkr�tjjj	|j
dddd|�d�jt
j�}nj|jj�jd�dkr�tjjj	|j
dddd	d
ddd
d|�
d�jt
j�}nx�|D]�}|j�}|s|jd�dks|jd�djd�dkrVqn|jd�d}||kr|j|�qqW|r|||<qqW|S(s�
        Filter out unchanged packages on the Debian or RPM systems.

        :param data: Structure {package-name -> [ file .. file1 ]}
        :return: Same structure as data, except only files that were changed.
        R1R2tdpkgs--verifyiR3R4RMs-Vs--nodepss
--nodigests
--nosignatures	--nomtimes
--nolinktos c R<t5i����N(sSusesredhat(R:titemsR*R5R6R7R=R>R?R@R0RARBR+RCRDtfindRE(	RRGtf_dataRHt	pkg_filestcfgstcfg_dataRStcfg_file((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pyt_get_changed_cfg_pkgs�s*			$	
>c	C@s�d}d}x�|j�D]�\}}t�}||_||_|jj|�xL|D]D}t�}||_||_||_|jj|�|d7}qWW|d7}qWdS(sZ
        Save configuration packages. (NG)

        :param data:
        :return:
        iiN(	RWR
tidtnameR tstoreRtpkgidtpath(	RRGtpkg_idt
pkg_cfg_idRHRRtpkgt
pkg_configtcfg((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pyt_save_cfg_packages�s			
				c
C@s�d}x�d|fd|fd|ffD]�\}}x�|D]�}tj|�}t�}	||	_||	_||	_|j|	_|j|	_	|j
|	_|j|	_
|j|	_|j|	_|j|	_|d7}|jj|	�q;Wq(WdS(s�
        Save payload (unmanaged files)

        :param files:
        :param directories:
        :param links:
        :return:
        itftdtliN(R+tstatRR_Rctp_typetst_modetmodetst_uidtuidtst_gidtgidtst_sizetp_sizetst_atimetatimetst_mtimetmtimetst_ctimetctimeR Ra(
RtfilestdirectoriestlinkstidxRntp_listtp_objtstatsR((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pyt
_save_payload�s"
.
				
cC@sf|jj�jd�dkr(|j�S|jj�jd�dkrP|j�St�t�t�fS(s>
        Build a in-memory data of all managed files.
        R1R2R3R4(sSusesredhat(R5R6R7t"_Inspector__get_managed_files_dpkgt!_Inspector__get_managed_files_rpmR*(R((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pyt_get_managed_files�s


cC@sgt�}t�}t�}x*tjjj|jdd
d
dd�d�jtj	�D]�}|j
�}|stqVnx�tjjj|jdd
d
d|�d�jtj	�D]�}|j
�}|s�|dkr�q�ntjj|�r�|j
|�q�tjj|�r|j
|�q�tjj|�r�|j
|�q�q�WqVWt|�t|�t|�fS(sZ
        Get a list of all system files, belonging to the Debian package manager.
        s
dpkg-querys-Wfs${binary:Package}\niRUs-LRNs./t.N(RNs./R�(tsetR=R>R?R@R0RARBR+RCRDRctisdirtaddtislinktisfiletsorted(RtdirsRR}RHtresource((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pyt__get_managed_files_dpkg�s&			#AcC@s't�}t�}t�}x�tjjj|jdd
d
d�d�jtj	�D]�}|j
�}|sqqSn|jdd�jd�}|dddkr�|j|d�qS|dddkr�|j|d�qS|ddd	krS|j|d�qSqSWt
|�t
|�t
|�fS(sZ
        Get a list of all system files, belonging to the RedHat package manager.
        RMs-qlavis	R<Rki����Rlt-N(R�R=R>R?R@R0RARBR+RCRDtreplaceR�R�(RR�RR}RS((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pyt__get_managed_files_rpms			>cG@s�t�}t�}t�}tj|tj�r{xHtj|�D]4}tjj||�}t}x/|D]'}|jt	|��rht
}qhqhqhW|s@tjj|�s@tj|tj�r�q@ntj
jj|�r�|j|�q@tjj|�rR|j|�|j||�\}	}
}|j|	�|j|
�|j|�q@tjj|�r@|j|�q@q@Wnt|�t|�t|�fS(sW
        Walk implementation. Version in python 2.x and 3.x works differently.
        (R*R+taccesstR_OKtlistdirRctjoinR"ROtstrtFalsetexistsR=R>R�RER�t_get_all_filestextendR�R�(RRctexcludeR}R�Rtobjtvalidtex_objtf_objtd_objtl_obj((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pyR�*s0			

0


c	C@s||\}}}|\}}}ttt|�j|���ttt|�j|���ttt|�j|���fS(sK
        Get the intersection between all files and managed files.
        (R�R*R�t
difference(	Rtmanagedt
system_alltm_filestm_dirstm_linksts_filests_dirsts_links((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pyt_get_unmanaged_filesIs
c
C@s�t�}xB|jjt�D].}tjj|j�r|j|j�qqWt�}|s�xE|jjt�D].}tjj|j�rp|j|j�qpqpWnt�}t�}t�}x�g|p�tj	d�D]}|r�|^q�D]�}	|	ddkrdj
|	�}	n|	|ks�tjj|	�r;q�n|j|	|�\}
}}|j
|
�|j
|�|j
|�q�W|j|j�|||f�S(s"
        Scan the system.
        RNis/{0}(R*R R7RR+RcR�RER	R�tformatR�R�R�R�R�(
Rtallowedtallowed_dirtignoredtignored_dirt	all_filestall_dirst	all_linkstptht
entry_pathte_fileste_dirste_links((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pyt
_scan_payloadTs,					5

cK@s�|jjdt�t�}|t|j�O}tjjj�}x�|j	�D]{\}}||j
kr�x|D]}|j|d�qpWqNnx5|D]-}|d|jkr�|j|d�q�q�WqNWt
�}x`tt
|��D]L}t}	x'|D]}
|j|
�r�t}	Pq�q�W|	r�|j|�q�q�Wx0|D](}t�}||_|jj|�q@Wg|jdd�jd�D]}
|
r�|
^q�}x0|D](}t�}||_|jj|�q�W|S(sJ
        Prepare full system scan by setting up the database etc.
        Rtmount_pointttypetfiltertt,(R R!R"R�tIGNORE_PATHSR=R>tfsutilst_get_mountsRWt
IGNORE_MOUNTSR�tIGNORE_FS_TYPESR*R�ROR�RER	RcRaR7RBR(Rtkwargst
ignored_fstmountstdeviceRGtmpttignored_alltentryR�te_entryR�tdir_objtelmR�R�((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pyt_prepare_full_scanss>	

	

		4
		cC@s?ddlm}ddlm}||j�|_||_dS(s3
        Initialize some Salt environment.
        i(t
minion_config(tcoreN(tsalt.configR�tsalt.grainsR�tDEFAULT_MINION_CONFIG_PATHt__opts__R5(RR�tg_core((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pyt	_init_env�scC@s=|j�|j|j|j���|j|j��dS(s0
        Take a snapshot of the system.
        N(R�RiR^R;R�R�(RRp((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pytsnapshot�s
icK@s�||jkr'tdj|���nt|j�rEtd��n|j|�tjdj|t	tj
j|j�tj
j|j�|��dS(s0
        Take a snapshot of the system.
        sUnknown mode: '{0}'sInspection already in progress.s.nice -{0} python {1} {2} {3} {4} & > /dev/nullN(
tMODERR�tis_alivetpidfileR
R�R+tsystemt__file__Rctdirnametdbfile(RRptpriorityR�((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pytrequest_snapshot�s
tqcow2cC@s1tt_tjdtd|�j|�jd�S(sk
        Export description for Kiwi.

        :param local:
        :param path:
        :return:
        tgrainsR�t	something(t__salt__RtKiwiExportert
__grains__tloadtexport(RtdescriptiontlocalRcR�((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pyR��s	cC@s>tdkr.d}tj|�t|��ntd��dS(sj
        Build an image using Kiwi.

        :param format:
        :param path:
        :return:
        sXUnable to build the image due to the missing dependencies: Kiwi module is not available.sBuild is not yet implementedN(tkiwiRAtlogterrorR
(RR�Rctmsg((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pytbuild�s

N(t__name__t
__module__R�R�R�R�R�RARR#R$R0R;R8R9R^RiR�R�R�R�R�R�R�R�R�R�R�R�R�R�(((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pyR.s:					
												+				cC@s�yHtjjj|��)}tjt|j�j��d�WdQXt	SWnKt
k
r�}tj|tj�r�tj
j|�r�tj|�ntSXdS(s&
    Check if PID is still alive.
    iN(R=R>R}tfopenR+tkilltinttreadRDR"t	ExceptionR�tW_OKRcR�tunlinkR�(R�tfp_tex((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pyR��s('cC@s t||�j�j|�dS(s 
    Main analyzer routine.
    N(RR$R�(R�R�Rp((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pytmain�st__main__is,This module is not intended to use directly!tfileitws{0}
(?t
__future__RRR+tsyst
subprocessRRRtloggingt"salt.modules.inspectlib.exceptionsRtsalt.modules.inspectlibRRt salt.modules.inspectlib.entitiesRR	R
RRtsalt.utils.cryptR=tsalt.utils.filestsalt.utils.fsutilstsalt.utils.pathtsalt.utils.stringutilstsalt.exceptionsR
R�tImportErrorRAt	getLoggerR�R�RR�R�tlentargvtprintR'texitR�R�RptforkR>tcryptt
reinit_cryptotOSErrorR�tsetsidtumasktpidR}R�RcR�tPID_FILER�twriteR�(((sE/usr/lib/python2.7/site-packages/salt/modules/inspectlib/collector.pyt<module>sd(

��		

-

Zerion Mini Shell 1.0