HEX
Server: LiteSpeed
System: Linux s787.bom1.mysecurecloudhost.com 4.18.0-477.13.1.lve.el8.x86_64 #1 SMP Thu Jun 1 16:40:47 EDT 2023 x86_64
User: mobilech (5348)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/__pycache__/scripts.cpython-310.pyc
o

;jwZ�@sTdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
ZddlmZmZmZe�e�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z dd�Z!dd�Z"dd �Z#d!d"�Z$d#d$�Z%d%d&�Z&d'd(�Z'd)d*�Z(d+d,�Z)d-d.�Z*d/d0�Z+d1d2�Z,d3d4�Z-d7d5d6�Z.dS)8zI
This module contains the function calls to execute command line scripts
�N)�randint)�SaltClientError�SaltReqTimeoutError�SaltSystemExitc	Cs�z|jj}Wn
ttfyd}Ynw|tjkr6d}z|jjd}|d�|�7}Wn
ttfy5Ynwd}|dur@|r@d}|rJt	|t
jdd�|rizt�
�}t�|�Wn	ty`Ynwt
�tjjj�t
�tjjj�dS)NFz
Exiting gracefully on Ctrl-c�jidz�
This job's jid is: {0}
The minions may not have all finished running and any remaining minions will return upon completion. To look up the return data for this job later, run the following command:

salt-run jobs.lookup_jid {0}z"
Exiting with hard crash on Ctrl-cT��file�flush)�options�
hard_crash�AttributeError�KeyError�signal�SIGINTZlocal_clientZpub_data�format�print�sys�stderr�	traceback�
format_exc�log�error�exit�salt�defaults�	exitcodes�
EX_GENERIC�EX_OK)�client�signum�sigframeZ	hardcrashZexit_msgr�trace�r"�@/opt/saltstack/salt/lib/python3.10/site-packages/salt/scripts.py�_handle_signalss<�
���r$cCs^t�tj�tjtjfvrt�tjt�t|��t�tj�tjur-t�tjt�t|��dSdS�N)	r�	getsignalr�SIG_DFL�default_int_handler�	functools�partialr$�SIGTERM)rr"r"r#�_install_signal_handlers>s
�r,cCs8ddl}tdkrtjttjd<|jj��}|��dS)z 
    Start the salt master.
    rN�__main__)�salt.cli.daemons�__name__r�modules�cli�daemonsZMaster�start)rZmasterr"r"r#�salt_masterIs
r4c
srddl�t���jj_ddl�ddl�dd�}t�	����fdd�}z�z+�j
j��s8tj
|t��fd�}|���jj��}t�tjt�||��|��WnQtttfy�}zB�jdd	�tjd
dd�t�d�d
}|dur}t|d�r}|j�dd
�}t d|�}t�!d|�t"�#|�t$�%�j&j'j(�WYd}~nd}~wwW�jdd	�dSW�jdd	�dS�jdd	�w)z 
    Start a minion process
    rNcSs|j��dSr%)�minion�reload)�manager�sig�framer"r"r#�
handle_hupjsz"minion_process.<locals>.handle_hupc
s��jdd�rL���t�d�zt��dkr"�jj��s"t�	|d�Wn t
yC}zt�d|�t�
�jjj�WYd}~nd}~ww�jdd�sdSdS)z�
        Have the minion suicide if the parent process is gone

        NOTE: small race issue where the parent PID could be replace
        with another process with same PID!
        F��blocking�rz(Minion process encountered exception: %sN)�acquire�release�time�sleep�os�getuid�utils�platform�
is_windows�kill�OSErrorrr�_exitrrr)�
parent_pid�exc��lockrr"r#�suicide_when_without_parentos
����z3minion_process.<locals>.suicide_when_without_parent��target�argsTr;z4Fatal functionality error caught by minion handler:
��exc_infoz** Restarting minion **�<�config�random_reauth_delay�zwaiting random_reauth_delay %ss))Z
salt._loggingrB�getpidZ_loggingZin_mainprocessZ__pid__r.�salt.utils.platform�	threading�RLockrDrErF�Thread�getppidr3r1r2�Minionr�SIGHUPr)r*rrrr>r�warning�hasattrrU�getr�infor@rArrrr�SALT_KEEPALIVE)r:rN�threadr5rK�delayr"rLr#�minion_processYsF
��


����rgcCsddl}ddl}ddl}ddl}|jj��|jj��ddl	}ddl
}tdkr0tj
ttj
d<dtjvr;tj�d�|jj��rM|jj��}|��dSdtjvr^|jj��}|��dSdd�}|�|j�}|�|j�}d}	z1|jtd
d�}|��|�|jt�||j��|�|jt�||j��|�|jt�||j��Wnt y�|jj��}|��YdSw|s�ddl!}t"|j#j$d�d	}|�%�|�|j|�|�|j|�|j&|j'j(j)ks�t�*|j&�t+�,d
t-dd��t.�/�}	|	j0D]}
|	�1|
�q�t.�2�qq)zR
    Start the salt minion in a subprocess.
    Auto restart minion on error.
    rNr-��--disable-keepalivecSst�||�dS)zy
        Escalate the signal received to the multiprocessing process that
        is actually running the minion
        N)rBrG)�pidrr r"r"r#�escalate_signal_to_process�sz/salt_minion.<locals>.escalate_signal_to_processFTZMinionKeepAlive)rP�namer5�rW�
)3rZsalt.utils.debugrY�salt.utils.processrD�debugZenable_sigusr1_handler�process�notify_systemd�multiprocessingr.r/rr0�path�removerErFr1r2r^r3�argvr&rr+�Processrgr)r*rjr_�	Exception�salt.config�_supervisor_drop_privilegesrU�
minion_config�join�exitcoderrrdrr@rAr�logging�	getLogger�handlers�
removeHandler�basicConfig)rrrsr5rkZprev_sigint_handlerZprev_sigterm_handler�supervisor_privileges_droppedrq�rlogger�handlerr"r"r#�salt_minion�s|

�����

�r�c
s|ddl}ddl}t����fdd�}zlz)|jj��s(tj|t�	�fd�}|�
�d}d}|jjj
}|jj��}|�
�Wn:ttttfy`}ztjddd	�d}|jjj}WYd}~nd}~wtyv}zd}|j}WYd}~nd}~wwW�jdd
�n�jdd
�w|dur�t�d�d}|dur�t|d
�r�|j�dd�}td|�}	t� d|	�|�!|	�n|�!d�t"�#|�dS)z&
    Start a proxy minion process
    rNcs`�jdd�r.���t�d�zt�|d�Wnty%t�d�Ynw�jdd�sdSdS)z�
        Have the minion suicide if the parent process is gone

        NOTE: there is a small race issue where the parent PID could be replace
        with another process with the same PID!
        Fr;r=ri�N)r>r?r@rArBrGrHrI)rJ�rMr"r#rNs
��z9proxy_minion_process.<locals>.suicide_when_without_parentrOFzProxy Minion failed to start: TrRr;z** Restarting proxy minion **rTrUrVrWz*Sleeping random_reauth_delay of %s seconds)$r.rYrZr[rDrErFr\rBr]r3rrrr1r2�ProxyMinionrxrrrrrrd�
SystemExit�coder>r`rarUrbrrc�putrr)
�queuerrNreZrestart�proxyminion�statusrKrfZrandom_delayr"r�r#�proxy_minion_processsV
�
�����



r�c	Cs�ddl}ddl}ddl}dtjvrtj�d�|jj��r)|j	j
��}|��dSdtj
vr:|j	j
��}|��dSd}	z|��}WntyW|j	j
��}|��YdSw|jt|fdd�}|��|stddl}t|jjd	�d}z2|��z|jdd
�}Wnty�|jdkr�YWdSd}Ynw|dkr�t�|j�t�|�Wn
ty�YdSwt��}|jD]}|� |�q�t�!�q=)z
    Start a proxy minion.
    rNrhriFTr�)rPrQrl�proxy)�blockrT)"rsr.rYrrtrurDrErFr1r2r�r3rv�Queuerxrwr�ryrzrUZproxy_configr|rbr}rr@rA�KeyboardInterruptr~rr�r�r�)	rsrr�r�r�rqZ
restart_delayr�r�r"r"r#�
salt_proxyVsd

��
��
�r�cCs`ddl}|jj��ddl}t��}z
|jj�	�}|�
�WdSty/t�|d�YdSw)z 
    Start the salt syndic.
    rN�)
rorDrqrrr.rBrXr1r2ZSyndicr3r�rG)rrjZsyndicr"r"r#�salt_syndic�s�r�c
Csfddl}z|jj��}t|�|��WdSty2}ztj�	d|�d��WYd}~dSd}~ww)z7
    Manage the authentication keys with salt-key.
    rNzError: �
)
Zsalt.cli.keyr1�keyZSaltKeyr,�runrxrr�write)rr�errr"r"r#�salt_key�s"��r�cCs(ddl}|jj��}t|�|��dS)�V
    Publish commands to the salt system from the command line on the
    master.
    rN)Zsalt.cli.cpr1ZcpZ	SaltCPClir,r��rrr"r"r#�salt_cp�sr�cC�>ddl}dtjvrtj�d�|jj��}t|�|��dS)zi
    Directly call a salt command in the modules, does not require a running
    salt minion to run.
    rNrh)	Z
salt.cli.callrrtrur1�callZSaltCallr,r�r�r"r"r#�	salt_call��
r�cCs>ddl}dtjvrtj�d�|jj��}t|�|��dS)z-
    Execute a salt convenience routine.
    rNrh)Zsalt.cli.runrrtrur1r�ZSaltRunr,r�r"r"r#�salt_run�s
r�cCs�ddl}dtjvrtj�d�z|jj��}t|�|��WdSt	y`}z4t
t|�tjdd�z|j
jr@t��}t�|�WnttfyLYnwt�|jjj�WYd}~dSd}~ww)z%
    Execute the salt-ssh system
    rNrhTr)Zsalt.cli.sshrrtrur1ZsshZSaltSSHr,r�rr�strrr
rrrrrrr
rrrr)rrr�r!r"r"r#�salt_ssh�s(

����r�c
Cs�z
ddl}ddl}Wn(ty2}zddl}t�d|�td�t�|j	j
j�WYd}~nd}~wwdtjvr>tj�
d�|jj��}t|�|��dS)z*
    The main function for salt-cloud
    rNzError importing salt cloud: %sz*salt-cloud is not available in this systemrh)Z
salt.cloudZsalt.cloud.cli�ImportError�salt.defaults.exitcodesrrrrrrr�EX_UNAVAILABLErtruZcloudr1Z	SaltCloudr,r�)r�err"r"r#�
salt_cloud�s��
r�cCs4ddl}|jj��ddl}|jj��}|��dS)z(
    The main function for salt-api
    rN)	rorDrqrrZsalt.cli.apir1ZapiZSaltAPIr3)rZsapir"r"r#�salt_apis
r�cCr�)r�rNrh)	Z
salt.cli.saltrrtrur1rZSaltCMDr,r�r�r"r"r#�	salt_mainr�r�cCs ddl}|jj��}|��dS)z]
    The main function for spm, the Salt Package Manager

    .. versionadded:: 2015.8.0
    rN)Zsalt.cli.spmr1�spmZSPMr�)rr�r"r"r#�salt_spm+sr�cCs$ddl}|jjj|||||d�dS)zb
    Quickstart for developing on the saltstack installation

    .. versionadded:: 2016.11.0
    rN)�	extensionrl�description�salt_dir�merge)Zsalt.utils.extendrD�extendr�)r�rlr�r�r�rr"r"r#�salt_extend7s
�r�cCs�g}ttjt�D]}|�d�r|�|dd��q	ttj�dkr8d}|D]	}|d|��7}q%t|�t�	d�tjd}||vrIdtjd<t
}nd	|��tjd<tj�d�ttjtd
|���}|�dS)z=
    Change the args and redirect to another salt script
    rr=Nrmz4Must pass in a salt command, available commands are:r�rWrzsalt-Zsalt_)
�dirrr0r/�
startswith�append�lenrvrrr��pop�getattr)ZavailZfun�msg�cmdZs_funr"r"r#�
salt_unityHs&
�



r�cCsF|dd�}d}|D]}d|vrd}q
d|vr!|s!|�d|���|S)NFz--targetT�installz	--target=)r�)rQrP�new_argsZtarget_in_args�argr"r"r#�	_pip_argsbs�r�cCs:|��}d|vr|�tj�|d��|d<|S||d<|S)N�
PYTHONPATH)�copyrB�pathsep)�env�extrasZnew_envr"r"r#�_pip_environmentms�r�cCs4t�t��tjWd�S1swYdSr%)�
contextlib�suppressrr�RELENVr"r"r"r#�_get_onedir_env_pathvs �r�cCs�ddl}tjdd�}d}t|�D]?\}}|rd}q|dvr.|dt|�kr.||dS|�d�r=|�dd�dS|�d�rPt|�d	krP|d	d�Sqtj�	d
�}|r[|S|j
jS)a�
    Return the salt config directory to use when the keepalive supervisor
    reads minion or proxy options.

    Respects ``-c``/``--config-dir`` on the command line first, then the
    ``SALT_CONFIG_DIR`` env var, then falls back to the compiled-in
    default. Keeping this lookup simple and ``argparse``-free avoids
    pulling in the full option parser (which the child process already
    runs) and keeps the parent's privilege drop cheap.
    rNrWF)�-cz--config-dirz
--config-dir=�=r�rm�SALT_CONFIG_DIR)Z
salt.syspathsrrv�	enumerater�r��splitrB�environrbZsyspathsZ
CONFIG_DIR)rrvZ	skip_next�idxr�Zenv_dirr"r"r#�_supervisor_config_dir}s$
�r�c	Cs�ddl}ddl}t�}tj�||�}z||�}Wnty+tjd||dd�YdSw|�	d�}|s5dS||j
j��kr?dS|j
j
�|�dS)a~
    Drop privileges in the salt-minion / salt-proxy keepalive supervisor.

    The supervisor forks a child process that runs the actual minion;
    only the child needs root to perform ``verify_env`` chowns and to
    create the pidfile, and the child drops to the configured user via
    ``salt.cli.daemons.Minion._real_start``. The parent only needs to
    forward signals to the child and restart it on
    ``SALT_KEEPALIVE``-flavoured exits -- neither requires privileges.

    Leaving the parent as root meant an unprivileged minion process tree
    still had a privileged root process at its head, defeating the
    purpose of configuring ``user: <something other than root>``. See
    issue #68115.

    ``config_loader`` is ``salt.config.minion_config`` or
    ``salt.config.proxy_config``; ``config_name`` is the corresponding
    config file basename (``minion`` or ``proxy``).
    rNzDSupervisor could not load %s config from %s; skipping privilege dropTrR�user)�salt.utils.user�salt.utils.verifyr�rBrtr|rxrrprbrDr��get_user�verify�
check_user)Z
config_loaderZconfig_namer�
config_dir�config_file�optsr�r"r"r#rz�s*��
rzc
Cshddl}ddl}ddl}t�}|dur$tdtjdd�t�|jj	j
�n
t|djtj
��}|r8tj�|d�}n'tj�d�rLtj�d�}tj�|d�}ntj�d	�rYtj�d	�}n|jjd
}|j�|�}|�d�}|jj��}|r�|dkr�||kr�|jj�|�ttj��|�}	ttjd
d�|�}
tjddgttjd
d�|�}t j!|dd|	d�}t�|j"�dS)z'
    Proxy to current python's pip
    rNzi'salt-pip' is only meant to be used from a Salt onedir. You probably want to use the system 'pip` binary.Trzextras-{}.{}r5r�ZSALT_MINION_CONFIGZ	conf_filer��rootrWz-mZpipF)�shell�checkr�)#ryr�r�r�rrrrrrrr�r�version_inforBrtr|r�rbrUZDEFAULT_MINION_OPTSr{rDr�r�r�r�r�r�r�rv�
executable�
subprocessr��
returncode)
r�rZrelenv_pathr�r�Zsalt_config_dirr�r��current_userr�rQZcommand�retr"r"r#�salt_pip�sF�
��r�r%)/�__doc__r�r)r~rBrr�rrZr@r�randomrr�rZsalt.exceptionsrrrrr/rr$r,r4rgr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rzr�r"r"r"r#�<module>sP
'EnJD
	+