%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/utils/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/utils/verify.pyc

�
���^c@@s3dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZyddlZWne
k
r�ddlZnXddlmZddlmZddlmZmZmZddlZddlZddlZddlZddlZddlZeje�Z ej!j"j#�rQdndZ$d	d
dgZ%d�Z&d
�Z'd�Z(d�Z)d�Z*d�Z+e,de,e$d�Z-d�Z.d�Z/de,d�Z0d�Z1d�Z2d�Z3d�Z4e,d�Z5d�Z6d�Z7d�Z8e,de,d �Z9dS(!u3
A few checks to make sure the environment is sane
i(tabsolute_importtprint_functiontunicode_literalsN(tis_console_configured(t
LOG_LEVELS(tSaltClientErrortSaltSystemExittCommandExecutionErroruc:\saltu/utcp://uudp://ufile://cC@s�yddl}Wntk
r$tSX|j}tjd|�}|s�dj|�}t�rntj	|�nt
jjdj|��tS|j
�\}}}|j�r�t|�}n|j�r�t|�}n|r�|j�r�t|�}n|dkrw|dkrwd|kr^|r^d	}t�rAtj	|�nt
jjd
j|��tS|r�|dkr�tSn(|dks�|dkr�|dkr�tStjd�d
t
jdkr�d}t�r�tj|�q�t
jjdj|��ntS(u6
    ZeroMQ python bindings >= 2.1.9 are required
    iNu^(\d+)\.(\d+)(?:\.(\d+))?u1Using untested zmq python bindings version: '{0}'uWARNING {0}
iiudevu6Using dev zmq module, please report unexpected resultsu
WARNING: {0}
i	u,ZeroMQ python bindings >= 2.1.9 are requiredusalt-masteru�The Salt Master is unstable using a ZeroMQ version lower than 2.1.11 and requires this fix: http://lists.zeromq.org/pipermail/zeromq-dev/2011-June/012094.htmlu
CRITICAL {0}
(tzmqt	ExceptiontTruet__version__tretmatchtformatRtlogtwarningtsyststderrtwritetgroupstisdigittinttcriticaltargvtFalse(RtverR
tmsgtmajortminortpoint((s5/usr/lib/python2.7/site-packages/salt/utils/verify.pytzmq_version*sJ
			$
	cC@sitj}yDtj|pddtjtj�}|s:|S|d}|dSWntjk
rd|SXdS(u�
    Lookup a hostname and determine its address family. The first address returned
    will be AF_INET6 if the system is IPv6-enabled, and AF_INET otherwise.
    iN(tsockettAF_INETtgetaddrinfotNonet	AF_UNSPECtSOCK_STREAMtgaierror(thostnametfallbackt	hostnamesth((s5/usr/lib/python2.7/site-packages/salt/utils/verify.pyt
lookup_familygs	
cC@st|�}x	||fD]�}tj|tj�}z�y6|jtjtjd�|j|t|�f�Wn�tk
r}dj	||�}|j
r�dj	|t|��}ndj	|�}|d7}t�r�t
j|�ntjjdj	|��tSXWd|j�XqWtS(uJ
    Attempt to bind to the sockets to verify that they are available
    iuUnable to bind socket {0}:{1}u{0}, error: {1}u!{0}, this might not be a problem.u'; Is there another salt-master running?u
WARNING: {0}
N(R+R R%t
setsockoptt
SOL_SOCKETtSO_REUSEADDRtbindRR	RtargststrRRRRRRRtcloseR
(t	interfacetpub_porttret_porttaddr_familytporttsocktexcR((s5/usr/lib/python2.7/site-packages/salt/utils/verify.pyt
verify_socketzs&	
		cC@sag}xT|D]L}t}x'tD]}|j|�r t}Pq q W|r
|j|�q
q
W|S(N(R
tDEFAULT_SCHEMESt
startswithRtappend(tfilest	to_verifytfilenametverify_filetscheme((s5/usr/lib/python2.7/site-packages/salt/utils/verify.pytverify_logs_filter�s

cC@stt|�|�S(u�
    Verify the log files exist and are owned by the named user.  Filenames that
    begin with tcp:// and udp:// will be filtered out. Filenames that begin
    with file:// are handled correctly
    (tverify_filesRC(R>tuser((s5/usr/lib/python2.7/site-packages/salt/utils/verify.pytverify_log_files�sc
C@s0tjjj�rtSddl}y|j|�}|d}WnFtk
r�dj|�}t	j
j|�t	jtj
jj�nXx�|D]�}tjj|�}y�|r�ytj|�Wq�tk
r�}|jtjkr��q�q�Xntjj|�s&tjjj|d��WdQXnWn�tk
r�}tjj|�rodj||�}td|��n|jtjkr��ndj|�}td|��n4tk
r�}d	j||�}td|��nXtj|�}	||	jkr�ytj||d
�Wq(tk
r$q(Xq�q�WtS(uK
    Verify that the named files exist and are owned by the named user
    iNiuPFailed to prepare the Salt environment for user {0}. The user is not available.
uwu)Failed to create path {0}, is {1} a file?RuDNo permissions to access "{0}", are you running as the correct user?u!Failed to create path "{0}" - {1}i����( tsalttutilstplatformt
is_windowsR
tpwdtgetpwnamtKeyErrorRRRRtexittdefaultst	exitcodest	EX_NOUSERtostpathtdirnametmakedirstOSErrorterrnotEEXISTtisfileR>tfopentIOErrorRtEACCEStstattst_uidtchown(
R>RERKtpwnamtuidterrtfn_RTRtstats((s5/usr/lib/python2.7/site-packages/salt/utils/verify.pyRD�sR
	



uc
C@s�tjjj�r+t||d|d|�Sddl}yB|j|�}|d}|d}	tjjj|dt	�}
WnFt
k
r�dj|�}tj
j|�tjtjjj�nXx�|D]�}|s�q�ntjj|�s�yUtjjjd	��tj|�WdQXtj�dkrAtj|||	�nWq�tk
r�}d
}
tj
j|
j||��tj|j�q�Xntj|�}tj�dkr�tj|�}|j|ks�|j|	kr	|r�|j|
kr�q	tj|||	�nx�gtj |�D]}d|kr|^qD]�}tjj!||�}djtjj"�|krtq8nx[tjjj#|�D]D\}}}x�|D]�}|j$d
�r�q�ntjj!||�}ytj|�}Wnt%tfk
r�nX|j|ks|j|	kr�|r3|j|
kr3qItj|||	�q�q�Wx~|D]v}tjj!||�}tj|�}|j|ks�|j|	krT|r�|j|
kr�q�tj|||	�qTqTWq�Wq8Wn||kr�tj&|j'�}|dkr�|dkr�tj(|tj)�r7tj*|d�q�d}
|
j|�}
t+�ret,j-|
�q�tj
jdj|
��q�q�q�W|t	kr�t.�ndS(uh
    Verify that the named directories are in place and that the environment
    can shake the salt
    t
permissivet
skip_extraiNiitinclude_defaultuPFailed to prepare the Salt environment for user {0}. The user is not available.
iu,Failed to create directory path "{0}" - {1}
ujobsu{0}jobsu.i�i�u0Unable to securely set the permissions of "{0}".uCRITICAL: {0}
(/RGRHRIRJtwin_verify_envRKRLREtget_gid_listRRMRRRRRNRORPRQRRRStisdirR>t	set_umaskRUtgetuidR_RVRWR]R^tst_gidtlistdirtjointseptos_walkR<R[tS_IMODEtst_modetaccesstW_OKtchmodRRRR(tdirsRERetpki_dirRftroot_dirRKR`RatgidRRbtdir_RtmodetfmodetatsubdirtfsubdirtrootR>tnameRStsmode((s5/usr/lib/python2.7/site-packages/salt/utils/verify.pyt
verify_env�s�


	
5%

%
	#cC@s�tjjj�rtS|tjjj�kr2tSddl}yQ|j|�}y�t	t
d�rxt
j||j�n"t
j
tjjj|dt��t
j|j�t
j|j�dt
jkr�|jt
jd<ndt
jkr�|jt
jd<nx0dD](}|t
jkr|jt
j|<qqWWnYtk
r�d	}|j|�}t�rptj|�ntjjd
j|��tSXWnStk
r�dj|�}t�r�tj|�ntjjd
j|��tSXtS(
u0
    Check user and assign process uid/gid.
    iNu
initgroupsRguHOMEuSHELLuUSERuLOGNAMEu:Salt configured to run as user "{0}" but unable to switch.uCRITICAL: {0}
uUser not found: "{0}"(uUSERuLOGNAME( RGRHRIRJR
REtget_userRKRLthasattrRRt
initgroupstpw_gidt	setgroupsRiRtsetgidtsetuidtpw_uidtenvirontpw_dirtpw_shelltpw_nameRVRRRRRRRRM(RERKtpwusertenvvarR((s5/usr/lib/python2.7/site-packages/salt/utils/verify.pyt
check_userNsD"

		
	cC@s�|g}tjj|�\}}|dkrQ|g}tjj|�\}}nx<||dkr�|jd|�tjj|�\}}qTW|S(u�
    Returns a full list of directories leading up to, and including, a path.

    So list_path_traversal('/path/to/salt') would return:
        ['/', '/path', '/path/to', '/path/to/salt']
    in that order.

    This routine has been tested on Windows systems as well.
    list_path_traversal('c:\path\to\salt') on Windows would return:
        ['c:\', 'c:\path', 'c:\path\to', 'c:\path\to\salt']
    ui(RRRStsplittinsert(RStouttheadttail((s5/usr/lib/python2.7/site-packages/salt/utils/verify.pytlist_path_traversals		urootcC@s�x�t|�D]�}tj|tj�s
dj|�}tjj|�sV|d7}nGtjj	j
�}||kr�|dj|�7}n|dj|�7}|r�dSt|��q
q
WdS(u
    Walk from the root up to a directory and verify that the current
    user has access to read each directory. This is used for  making
    sure a user can read all parent directories of the minion's  key
    before trying to go and generate a new key and raising an IOError
    uCould not access {0}.u Path does not exist.u Try running as user {0}.u" Please give {0} read permissions.N(R�RRRttR_OKRRStexistsRGRHRER�R(RSREtskip_perm_errorsttpathRtcurrent_user((s5/usr/lib/python2.7/site-packages/salt/utils/verify.pytcheck_path_traversal�s
cC@s�|jdd�}tjjd�r7tj�}}ntjtj�\}}t	j
j|jd�d�}tt	j
|��}tjd|�tj}|d|kr�dSd	j||�}||kr�|d
7}tj}nT|d|kr�tj}n8|d|krtj}n|d|kr7tj}n||kr]|d
j||�7}n|d7}tjd|d|�dS(uI
    Check the number of max allowed open files and adjust if needed
    umax_open_filesi��uwinupki_diruminionsu6This salt-master instance has accepted %s minion keys.iNujThe number of accepted minion keys({0}) should be lower than 1/4 of the max open files soft setting({1}). u$salt-master will crash pretty soon! iiupAccording to the system's hard limit, there's still a margin of {0} to raise the salt's max_open_files setting. u#Please consider raising this value.tlevelR(tgetRRIR<t	win32filet_getmaxstdiotresourcet	getrlimitt
RLIMIT_NOFILERRRSRotlenRnRtdebugtloggingtINFORtCRITICALtWARNING(toptstmof_ctmof_stmof_htaccepted_keys_dirtaccepted_countR�R((s5/usr/lib/python2.7/site-packages/salt/utils/verify.pytcheck_max_open_files�s8	
	
cC@s�d}x�|jtjj�dD]�}|dkr�tjjtjjj||g��r�tjtjjj||g��}q�tjjtjjj||g��}q tjjtjjj||g��}q W|S(Nui(R�RRRSRptislinkRotreadlinktabspath(RStbasetpart((s5/usr/lib/python2.7/site-packages/salt/utils/verify.pyt_realpath_darwin�s ''*+cC@s�d}x�|jtjj�D]�}|dkr�y:tjtjjj||g��}tjj|�}Wq�tk
r�tjjtjjj||g��}q�Xq|}qW|S(Nu(R�RRRSRpR�RoR�RV(RSR�R�((s5/usr/lib/python2.7/site-packages/salt/utils/verify.pyt_realpath_windowss$
.
cC@s^tjjj�rt|�Stjjj�rNtjjjrGt	|�S|Snt
jj|�S(u�
    Cross platform realpath method. On Windows when python 3, this method
    uses the os.readlink method to resolve any filesystem links. On Windows
    when python 2, this method is a no-op. All other platforms and version use
    os.realpath
    (
RGRHRIt	is_darwinR�RJtexttsixtPY3R�RRRStrealpath(RS((s5/usr/lib/python2.7/site-packages/salt/utils/verify.pyt	_realpaths

cC@s�t|�}tjj|�s"dStjj|�sLtjj||�}ntjj|�}t|�}|r�|j|�r�|Sn(tjj|�tjj|�kr�|SdS(u�
    Accepts the root the path needs to be under and verifies that the path is
    under said root. Pass in subdir=True if the path can result in a
    subdirectory of the root instead of having to reside directly in the root
    u(R�RRRStisabsRotnormpathR<RT(R�RSRt	real_roott	real_path((s5/usr/lib/python2.7/site-packages/salt/utils/verify.pyt
clean_paths$c@soyJt�fd�ddtd�fD��r2tStt|d���SWnttttfk
rjtSXdS(u+
    Returns if the passed id is valid
    c3@s|]}|�kVqdS(N((t.0tx(tid_(s5/usr/lib/python2.7/site-packages/salt/utils/verify.pys	<genexpr>:su/u\uupki_dirN(	tanyR1RtboolR�tAttributeErrorRMt	TypeErrortUnicodeDecodeError(R�R�((R�s5/usr/lib/python2.7/site-packages/salt/utils/verify.pytvalid_id5s+cC@s.d	}x!|D]}|j|�r
tSq
WtS(
u�
    Check a string to see if it has any potentially unsafe routines which
    could be executed via python, this routine is used to improve the
    safety of modules suct as virtualenv
    uimportu;u
subprocessuevaluopenufileuexecuinput(uimportu;u
subprocessuevaluopenufileuexecuinput(tcountRR
(tcodetbadstbad((s5/usr/lib/python2.7/site-packages/salt/utils/verify.pytsafe_py_codeAs
cC@sMtjt|jd��j�tj�}|tjkrItjd�ndS(uF
    If an insecre logging configuration is found, show a warning
    u	log_leveluFInsecure logging configuration detected! Sensitive data may be logged.N(	RR�R1tlowerR�tNOTSETR�RR(R�R�((s5/usr/lib/python2.7/site-packages/salt/utils/verify.pyt
verify_logVs*c
C@s�ddl}ddl}ddl}tjjdd�}dj|dg�}|jjj	d|d|�s�t
d	j|���ntjj|�s�tj
|�n|jjj�}|jjj|�ry|jjj|d
�WnRt
k
r;dj|�}	t�rtj|	�q<tjjdj|	��nX|syh|jjj�}
|
jd
d
dd�|
jdd
dd�|
jdd
dd�|
j|t�Wqt
k
r�dj|�}	t�r�tj|	�q�tjjdj|	��qXqnxp|D]h}|sqntjj|�s�ytj
|�Wq�tk
r�}d}	tjj|	j||��tj|j�q�Xn||kry~|jjj|d
�|jjj�}
|
jd
d
dd�|
jdd
dd�|
jdd
dd�|
j|t�Wqtt
k
rpd}	|	j|�}	t�rTtj|	�qqtjjdj|	��qtXqqW|t kr�t!�ndS(uh
    Verify that the named directories are in place and that the environment
    can shake the salt
    iNu
SystemRootu
C:\Windowsu\uTEMPRSt
allow_pathu3`file_roots` set to a possibly unsafe location: {0}uS-1-5-32-544u*Unable to securely set the owner of "{0}".uCRITICAL: {0}
ugrantufull_controluthis_folder_subfolders_filesuS-1-5-18uS-1-3-4u0Unable to securely set the permissions of "{0}".u,Failed to create directory path "{0}" - {1}
("tsalt.utils.win_functionstsalt.utils.win_dacltsalt.utils.pathRRR�R�RoRHRSt	safe_pathRRRjRUt
win_functionstget_current_usertis_admintwin_daclt	set_ownerRRRRRRtdacltadd_acetsaveR
RVRNRWRR(
RSRwReRxRfRGtsystem_rootR�R�RR�R{Rb((s5/usr/lib/python2.7/site-packages/salt/utils/verify.pyRh`s�
	
	
		#

	$(:t__doc__t
__future__RRRRRRRR]RWR R�R�tImportErrorR�tsalt.logRtsalt.log.setupRtsalt.exceptionsRRRtsalt.defaults.exitcodesRGtsalt.utils.filesR�tsalt.utils.platformtsalt.utils.usertsalt.ext.sixt	getLoggert__name__RRHRIRJtROOT_DIRR;RR+R:RCRFRDRR�R�R�R�R�R�R�R�R�R�R�R�Rh(((s5/usr/lib/python2.7/site-packages/salt/utils/verify.pyt<module>s`
	=			
			6h	1		<	
					


Zerion Mini Shell 1.0