HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/verify.cpython-310.pyc
o

�N�g�e�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z
ddlZ
ddlZ
ddl
Z
ddlZ
ddlmZddlmZmZmZz
ddlZddlZ
Wn
ey]ddlZYnwe�e�Ze
jj��rkdndZgd�Z dd	�Z!d
d�Z"dd
�Z#dd�Z$dd�Z%dd�Z&dd�Z'dddefdd�Z(dd�Z)dd�Z*d6dd �Z+d!d"�Z,d#d$�Z-d%d&�Z.d'd(�Z/d7d*d+�Z0d,d-�Z1d.d/�Z2d0d1�Z3d2d3�Z4d8d4d5�Z5dS)9z3
A few checks to make sure the environment is sane
�N)�
LOG_LEVELS)�CommandExecutionError�SaltClientError�SaltSystemExitzc:\salt�/)ztcp://zudp://zfile://cCszddl}Wn
tyYdSw|j}t�d|�}|s$t�d|�dS|��\}}}|��r3t	|�}|��r;t	|�}|rE|��rEt	|�}|dkrc|dkrcd|vrZ|sZt�d	�dS|rb|d
krbdSn|dkso|dkrq|dkrqdSt�
d�dtjdvr�t�
d
�dS)z6
    ZeroMQ python bindings >= 2.1.9 are required
    rNTz^(\d+)\.(\d+)(?:\.(\d+))?z0Using untested zmq python bindings version: '%s'���devz6Using dev zmq module, please report unexpected results�	z,ZeroMQ python bindings >= 2.1.9 are requiredzsalt-masterz�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.htmlF)
�zmq�	Exception�__version__�re�match�log�warning�groups�isdigit�int�critical�sys�argv)r�verr�major�minorZpoint�r�E/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/verify.py�zmq_version&s@�
�
�rcCsTtj}zt�|p	ddtjtj�}|s|WS|d}|dWStjy)|YSw)z�
    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.
    Nr)�socket�AF_INET�getaddrinfo�	AF_UNSPEC�SOCK_STREAM�gaierror)�hostname�fallbackZ	hostnames�hrrr�
lookup_familyYs�
�r'cCs�t|�}||fD]e}t�|tj�}zWz|�tjtjd�|�|t|�f�Wn<tyb}z0d|�d|��}|j	rC|�dt
|���}n|�d�}|d7}t�|�WYd}~W|�
�dSd}~wwW|�
�q|�
�wd	S)
zJ
    Attempt to bind to the sockets to verify that they are available
    rzUnable to bind socket �:z	, error: z, this might not be a problem.z'; Is there another salt-master running?NFT)r'rr"�
setsockopt�
SOL_SOCKET�SO_REUSEADDR�bindrr�args�strrr�close)Z	interfaceZpub_portZret_portZaddr_family�port�sock�exc�msgrrr�
verify_socketls(

���r4cCs@g}|D]}d}tD]}|�|�rd}nq
|r|�|�q|S)z!
    Filter files to verify.
    TF)�DEFAULT_SCHEMES�
startswith�append)�filesZ	to_verify�filenameZverify_file�schemerrr�verify_logs_filter�s
�
�r;cCstt|�|�S)z�
    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
    )�verify_filesr;)r8�userrrr�verify_log_files�sr>cCs`tjj��rdSddl}z|�|�WSty/td�|�t	j
dd�t	�tjj
j�YdSw)z.
    Get the user from passwords database
    TrNzNFailed to prepare the Salt environment for user {}. The user is not available.)�file�flush)�salt�utils�platform�
is_windows�pwd�getpwnam�KeyError�print�formatr�stderr�exit�defaultsZ	exitcodes�	EX_NOUSER)r=rErrr�
_get_pwnam�s��rNc	Cs�tjj��rdSt|�}|d}|D]�}tj�|�}zC|r>zt�|�Wnt	y=}z
|j
t
jkr3�WYd}~nd}~wwtj�|�s\tjj
�|d��Wd�n1sWwYWnIt	y�}z%tj�|�ryd|�d|�d�}t|d��|j
t
jkr��d	�|�}t|d��d}~wt	y�}z
d
|�d|��}t|d��d}~wwt�|�}||jkr�z	t�||d�Wqt	y�YqwqdS)
zK
    Verify that the named files exist and are owned by the named user
    TrN�wzFailed to create path z, is z a file?)r3zCNo permissions to access "{}", are you running as the correct user?zFailed to create path "z" - ���)rArBrCrDrN�os�path�dirname�makedirs�OSError�errnoZEEXIST�isfiler8ZfopenrZEACCESrI�stat�st_uid�chown)	r8r=�pwnam�uidZfn_rS�errr3Zstatsrrrr<�s\�����
�
�
��

��r<F�cCs�tjj��rt||||d�St|�}|d}|d}tjjj|dd�}	|D�]}
|
s+q%tj	�
|
�s�z+tjj�d��
t�
|
�Wd�n1sIwYt��dkr[t�|
||�Wn$ty�}zd	}tj�|�|
|��t�|j�WYd}~nd}~wwt�|
�}
t��dk�rt�|
�}|j|ks�|j|kr�|r�|j|	vr�nt�|
||�d
d�t�|
�D�D]c}tj	�|
|�}tj	j�d�|vr�q�tjj	�|�D]H\}}}t�||�D]<}|� d
�r�q�tj	�||�}z#t�|�}|j|ks�|j|k�r|�r|j|	v�rnt�|||�Wq�t�yYq�wq�q�|
|k�rCt�!|
j"�}|dk�rC|dk�rCt�#|
tj$��r=t�%|
d�q%t&�'d|
�q%|du�rNt(�dSdS)�h
    Verify that the named directories are in place and that the environment
    can shake the salt
    )�
permissive�
skip_extrar�F��include_default�Nr�,Failed to create directory path "{0}" - {1}
cSsg|]}d|vr|�qS)�jobsr)�.0�arrr�
<listcomp>szverify_env.<locals>.<listcomp>rg�.i�i�z/Unable to securely set the permissions of "%s".))rArBrCrD�win_verify_envrNr=�get_gid_listrQrR�isdirr8Z	set_umaskrT�getuidrZrUrrJ�writerIrKrVrXrY�st_gid�listdir�join�sepZos_walk�	itertools�chainr6�S_IMODE�st_mode�access�W_OK�chmodrrr)�dirsr=r`�pki_dirra�root_dirr[r\�gidr�dir_r]r3�modeZfmode�subdirZfsubdir�rootr8�namerRZsmoderrr�
verify_env�s��
����



����
��

�r�cCs�tjj��rdS|tjj��krdSt|�}zNttd�r$t�	||j
�nt�tjjj|dd��t�
|j
�t�|j�dtjvrG|jtjd<dtjvrR|jtjd<dD]
}|tjvra|jtj|<qTWdStytt�d|�YdSw)	z0
    Check user and assign process uid/gid.
    T�
initgroupsFrc�HOMEZSHELL)ZUSERZLOGNAMEz9Salt configured to run as user "%s" but unable to switch.)rArBrCrDr=�get_userrN�hasattrrQr��pw_gid�	setgroupsrm�setgid�setuid�pw_uid�environ�pw_dir�pw_shell�pw_namerUrr)r=ZpwuserZenvvarrrr�
check_user<s2



����r�cCsl|g}tj�|�\}}|dkr|g}tj�|�\}}||dkr4|�d|�tj�|�\}}||dks |S)a�
    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']
    r^r)rQrR�split�insert)rR�out�head�tailrrr�list_path_traversalbs�r�r�cCs�t|�D]>}t�|tj�sBd|�d�}tj�|�s|d7}ntjj�	�}||kr1|d|�d�7}n|d|�d�7}|r>dSt
|��qdS)a
    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
    zCould not access rkz Path does not exist.z Try running as user z
 Please give z read permissions.N)r�rQry�R_OKrR�existsrArBr=r�r)rRr=Zskip_perm_errorsZtpathr3�current_userrrr�check_path_traversal{s
��r�cCs|�dd�}tj�d�rt��}}nt�tj�\}}t	j
�|�d�d�}tt	�
|��}t�d|�tj}|d|kr=dSd	�||�}||krO|d
7}tj}n|d|krYtj}n|d|krctj}n	|d|krltj}||kry|d
�||�7}|d7}tj||d�dS)zI
    Check the number of max allowed open files and adjust if needed
    Zmax_open_filesi���winr}Zminionsz6This salt-master instance has accepted %s minion keys.�NzhThe number of accepted minion keys({}) should be lower than 1/4 of the max open files soft setting({}). z$salt-master will crash pretty soon! rrbzoAccording to the system's hard limit, there's still a margin of {} to raise the salt's max_open_files setting. z#Please consider raising this value.)�levelr3)�getrrCr6�	win32fileZ_getmaxstdio�resourceZ	getrlimitZ
RLIMIT_NOFILErQrRrs�lenrrr�debug�logging�INFOrI�CRITICAL�WARNING)�optsZmof_cZmof_sZmof_hZaccepted_keys_dirZaccepted_countr�r3rrr�check_max_open_files�s>��
�r�cCs�d}|�tjj�dd�D];}|dkr;tj�tjj�||g��r-t�tjj�||g��}q
tj�tjj�||g��}q
tj�tjj�||g��}q
|S)Nr^r)r�rQrRrt�islinkrs�readlink�abspath�rR�base�partrrr�_realpath_darwin�sr�c
Cs�d}|�tjj�D]5}|dkr<ztjj�tjj�||g��}tj�|�}Wq	t	y;tj�tjj�||g��}Yq	w|}q	|�
d�rJ|dd�}|S)Nr^z\\?\r�)r�rQrRrtrArBr�rsr�rUr6r�rrr�_realpath_windows�s�
r�cCs4tjj��r
t|�Stjj��rt|�Stj�	|�S)z�
    Cross platform realpath method. On Windows when python 3, this method
    uses the os.readlink method to resolve any filesystem links.
    All other platforms and version use ``os.path.realpath``.
    )
rArBrCZ	is_darwinr�rDr�rQrR�realpath)rRrrr�	_realpath�s
r�TcCs�tj�|�stj�t��|�}tj�|�}tj�|�s"tj�||�}tj�|�}|r2t|�}t|�}|rBtj�||g�|kr@|SdStj�|�|krL|SdS)a+
    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.
    Pass realpath=False if filesystem links should not be resolved.
    r^)	rQrR�isabsrs�getcwd�normpathr��
commonpathrS)r�rRr�r�rrr�
clean_paths �r�csNzt�fdd�dD��rWdStt|d���WSttttfy&YdSw)z+
    Returns if the passed id is valid
    c3s�|]}|�vVqdS)Nr)rh�x��id_rr�	<genexpr>"s�zvalid_id.<locals>.<genexpr>)r�\�Fr})�any�boolr��AttributeErrorrG�	TypeError�UnicodeDecodeError)r�r�rr�r�valid_ids�r�cCs"d}|D]
}|�|�rdSqdS)z�
    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
    )�import�;�
subprocess�eval�openr?�exec�inputFT)�count)�codeZbadsZbadrrr�safe_py_code)s
�r�cCs4g}t��D]\}}|t�dd�kr|�|�q|S)z(
    Return the insecure logs types
    �info�)r�itemsr�r7)Zinsecurer��valuerrr�insecure_log6s
�r�cCs8t�t|�d����tj�}|tjkrt�d�dSdS)zF
    If an insecre logging configuration is found, show a warning
    Z	log_levelzFInsecure logging configuration detected! Sensitive data may be logged.N)	rr�r.�lowerr��NOTSETr�rr)r�r�rrr�
verify_logAs
��r�cCsJddl}ddl}ddl}tj�dd�}d�|dg�}|jjj	||d�s*t
d|����tj�|�s5t�|�|jj
��}|jj
�|�r�d	}	|jjjd
dd�sV|jjjd
dd�z|jjj|	d
dd�Wnt
yqt�d|	�Ynwz,|jjjdd�}
|
jd
dddd�|
jddddd�|
jddddd�|
j|	dd�Wnt
y�t�d|	�Ynw|jj
�|��rz|jjj|d
d�Wnt
y�t�d|�Ynw|�sz*|jj��}
|
jd
dddd�|
jddddd�|
jddddd�|
j|dd�Wnt
�yt�d|�Ynw|D]�}|�s�qtj�|��sLzt�|�Wn%t�yK}zd}
tj�|
�||��t�|j �WYd}~nd}~ww||k�r�z4|jjj|d
d�|jj��}
|
jd
dddd�|
jddddd�|
jddddd�|
j|dd�W�qt
�y�t�d|�Y�qw�q|d u�r�t!�dSdS)!r_rNZ
SystemRootz
C:\Windowsr�ZTEMP)rR�
allow_pathz0`file_roots` set to a possibly unsafe location: zHKLM\SOFTWARE\Salt Project\saltZHKLMzSOFTWARE\Salt Project\salt)Zhive�keyzS-1-5-32-544�registry)�obj_name�	principal�obj_typez)Unable to securely set the owner of '%s'.)r�ZgrantZfull_controlZthis_key_subkeys)r�Zaccess_modeZpermissionsZ
applies_tozS-1-5-18zS-1-3-4T)r�Z	protectedz/Unable to securely set the permissions of '%s'.)r�r�z)Unable to securely set the owner of "%s".Zthis_folder_subfolders_filesz.Unable to securely set the permissions of '%s'rfF)"�salt.utils.pathZsalt.utils.win_daclZsalt.utils.win_functionsrQr�r�rsrBrRZ	safe_pathrrnrTZ
win_functionsZget_current_userZis_adminZwin_regZ
key_existsZ	set_valueZwin_daclZ	set_ownerrr�daclZadd_aceZsaverUrrJrprIrKrVr)rRr|r`r}rarAZsystem_rootr�r�Zreg_pathr�r�r]r3rrrrlMs��
��
�������������
�����
&
�rl)r�F)FT)Fr^F)6�__doc__rVrur�rQrrrXrZsalt.defaults.exitcodesrAZsalt.utils.filesr�Zsalt.utils.platformZsalt.utils.userZ
salt._loggingrZsalt.exceptionsrrrr�Zsalt.utils.win_reg�ImportErrorr��	getLogger�__name__rrBrCrDZROOT_DIRr5rr'r4r;r>rNr<r�r�r�r�r�r�r�r�r�r�r�r�r�rlrrrr�<module>s^�
3	1
�Y&
<