HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/chroot.cpython-310.pyc
o

�N�g�.�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
ZddlZddlZddiZ
e�e�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zddd�Zdd�Zddd�Zdd�ZdS)z�
Module for chroot
:maintainer:    Alberto Planas <aplanas@suse.com>
:maturity:      new
:depends:       None
:platform:      Linux
�N�apply_ZapplycCstdd�dur
dSdS)z%
    Chroot command is required.
    z
path.which�chrootNT)Fz)Module chroot requires the command chroot)�	__utils__�rr�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/chroot.py�__virtual__srcCsDtj�|d�}tj�|d�}tj�|d�}tdd�||||fD��S)z�
    Return True if the chroot environment is present.

    root
        Path to the chroot environment

    CLI Example:

    .. code-block:: bash

        salt myminion chroot.exist /chroot

    �dev�proc�syscss�|]	}tj�|�VqdS�N)�os�path�isdir)�.0�irrr�	<genexpr>7s�zexist.<locals>.<genexpr>)rr
�join�all)�rootrr	r
rrr�exist&src
Cs�t|�sKtj�|d�}tj�|d�}tj�|d�}ztj|dd�tj|dd�tj|dd�Wd
StyJ}z
t�d|�WYd}~d	Sd}~wwd
S)aX
    Create a basic chroot environment.

    Note that this environment is not functional. The caller needs to
    install the minimal required binaries, including Python if
    chroot.call is called.

    root
        Path to the chroot environment

    CLI Example:

    .. code-block:: bash

        salt myminion chroot.create /chroot

    rr	r
i�)�modeimz2Error when trying to create chroot directories: %sNFT)rrr
r�makedirs�OSError�log�error)rrr	r
�errr�create:s���rc	Cs�d}z=tjj�d��'}tjj�d��}|��}|��}Wd�n1s%wYWd�n1s4wY||k}W|StyIY|Sw)z�
    Return True if the process is inside a chroot jail

    .. versionadded:: 3004

    CLI Example:

    .. code-block:: bash

        salt myminion chroot.in_chroot

    Fz/proc/1/mountinfoz/proc/self/mountinfoN)�salt�utils�filesZfopen�readr)�resultZroot_fdZself_fdZroot_mountinfoZself_mountinforrr�	in_chrootZs&
��
��
��r"c
Os�|stj�d��t|�stj�d��tj|d�}tdtdtddd�tdd	d�d
�}tddd
|d|g�}|rEtd|�d|d�St	j
�t	j
jt	j
�
||��}z�tjjjd-i|��}dtjd��t	j
�|d�dddt	j
�|d�dt	j
�|d�ddddd|gt|�d d!�|��D�}	td"|d#d!�|	D��}
z+td$|
d%�}|�d&|�}t|t�r�d'|vr�|d'td'<|�d(|�WWtd|�Sty�d|
d'|
d%|
d)d*�d+�YWtd|�Swtd|�w).a�
    Executes a Salt function inside a chroot environment.

    The chroot does not need to have Salt installed, but Python is
    required.

    root
        Path to the chroot environment

    function
        Salt execution module function

    CLI Example:

    .. code-block:: bash

        salt myminion chroot.call /chroot test.ping
        salt myminion chroot.call /chroot ssh.set_auth_key user key=mykey

    zMissing function parameterzChroot environment not found��dirz
thin.gen_thinZcachedirz
config.optionZthin_extra_mods�Zthin_so_mods)Z
extra_modsZso_modszcmd.run�tarZxzfz-C�files.rm_rfF)r!�comment�pythonrz	salt-callz
--metadataz--localz
--log-filerz
--cachedir�cachez--out�jsonz-l�quietz--cSsg|]\}}|�d|���qS)�=r)r�k�vrrr�
<listcomp>�szcall.<locals>.<listcomp>zcmd.run_chrootcSsg|]}t|��qSr)�str)r�xrrrr0�szjson.find_json�stdout�local�retcode�return�stderr)r3r7)r!r5r(Nr)r�
exceptionsZCommandExecutionErrorr�tempfile�mkdtempr�__opts__�__salt__rr
r�sep�relpathr�argsZclean_kwargsr
�version_info�list�items�get�
isinstance�dict�__context__�
ValueError)
r�functionr?�kwargsZthin_dest_pathZ	thin_pathr3Zchroot_pathZsafe_kwargsZ	salt_argv�ret�datar4rrr�callzsj�
�����
��rLcKs&|rt||fi|��St|fi|��S)aW
    Apply an state inside a chroot.

    This function will call `chroot.highstate` or `chroot.sls` based
    on the arguments passed to this function. It exists as a more
    intuitive way of applying states.

    root
        Path to the chroot environment

    For a formal description of the possible parameters accepted in
    this function, check `state.apply_` documentation.

    CLI Example:

    .. code-block:: bash

        salt myminion chroot.apply /chroot
        salt myminion chroot.apply /chroot stuff
        salt myminion chroot.apply /chroot stuff pillar='{"foo": "bar"}'

    )�sls�	highstate)r�modsrIrrrr�scCs�tjjjj�|�tj�t��}tjjj�	|||t
��|�}Wd�n1s(wYtjj
�||�}d}tj|d�}	tj�|	d�}	|	�|dd�}
ztjj�||	�t|d|
|||d�}Wtd|	�|Std|	�w)	zB
    Create the salt_state tarball, and execute in the chroot
    Nr#zsalt_state.tgzr%�z	state.pkg)�testZpkg_sum�	hash_typer')r�client�ssh�wrapper�stateZ_cleanup_slsmod_low_data�
fileclient�get_file_clientr;Zprep_trans_tar�
__pillar__�valuerZ	hashutilsZget_hashr9r:rr
r�replacer�copyfilerLr)r�chunks�	file_refsrQrRrSZ	trans_tarZ
trans_tar_sumrJZsalt_state_pathZsalt_state_path_in_chrootrrr�_create_and_execute_salt_state�s8
���	�r_�basec
Ks�t�t���}|�|�di��tjjj	t
fi|��}tjjj�
||ttj�t
��}t|t�r4|�d�}|�o|�||i�\}	}
|r\t|t�rL|�d�}d|	vrX|	d�|�n||	d<|j�|	�\}	}|
|7}
|
|j�|	�7}
|
r{|
Wd�S|j�|	�\}	}|
|7}
|
r�|
Wd�S|j�|	�}	|j�|	�}
Wd�n1s�wYtjjj�|
tjjjj�|�dd�|�dd���}|d}t||
|||�S)a3
    Execute the states in one or more SLS files inside the chroot.

    root
        Path to the chroot environment

    saltenv
        Specify a salt fileserver environment to be used when applying
        states

    mods
        List of states to execute

    test
        Run states in test-only (dry-run) mode

    exclude
        Exclude specific states from execution. Accepts a list of sls
        names, a comma-separated string of sls names, or a list of
        dictionaries containing ``sls`` or ``id`` keys. Glob-patterns
        may be used to match multiple states.

    For a formal description of the possible parameters accepted in
    this function, check `state.sls` documentation.

    CLI Example:

    .. code-block:: bash

        salt '*' chroot.sls /chroot stuff pillar='{"foo": "bar"}'
    �pillar�,Z__exclude__N�extra_filerefsr%rR)�copy�deepcopyrYrZ�updaterCrrrV�get_sls_optsr;rSrT�SSHHighStater<rWrXrDr1�splitZrender_highstate�extendZreconcile_extendZverify_highZrequisite_inZ
apply_excludeZcompile_high_data�lowstate_file_refsrU�_merge_extra_filerefsr_)rrOZsaltenvrQZexcluderIra�opts�st_Z	high_data�errorsZ
ext_errorsZ
req_in_errorsr]r^rRrrrrMsL"
�



���
��rMc
Kst�t���}|�|�di��tjjj	t
fi|��}tjjj�
||ttj�t
���P}|��}tjjj�|tjjjj�|�dd�|�dd���}|D]}t|t�s`dtd<|Wd�SqJ|�dd�}|d	}	t|||||	�Wd�S1s}wYdS)
a�
    Retrieve the state data from the salt master for this minion and
    execute it inside the chroot.

    root
        Path to the chroot environment

    For a formal description of the possible parameters accepted in
    this function, check `state.highstate` documentation.

    CLI Example:

    .. code-block:: bash

        salt myminion chroot.highstate /chroot
        salt myminion chroot.highstate /chroot pillar='{"foo": "bar"}'

    rarcr%rPr5NrQFrR)rdrerYrZrfrCrrrVrgr;rSrTrhr<rWrXZcompile_low_chunksrkrUrlrDrErF�popr_)
rrIrarmrnr]r^�chunkrQrRrrrrNjs0
�
��
�$�rNr)r`NN)�__doc__rd�loggingrr
r9rZsalt.client.ssh.stateZsalt.client.ssh.wrapper.stateZsalt.defaults.exitcodesZsalt.exceptionsZsalt.utils.argsZsalt.utils.filesZ__func_alias__�	getLogger�__name__rrrrr"rLrr_rMrNrrrr�<module>s0

  
Y
'T