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/relenv/__pycache__/relocate.cpython-310.pyc
o

�N�g.�@s�dZddlZddlZddlZddlZddlZe�e�Zgd�Z	dZ
dZdZdd�Z
d	d
�Zdd�Zd
d�Zdd�Zdd�Zdd�Zdd�Zd#dd�Zd$dd�Z	d%dd�Zed krmddlZeed!�sfed"��eej�dSdS)&zO
A script to ensure the proper rpaths are in place for the relenv environment.
�N)zlinux-vdso.so.1z	libc.so.6�
librt.so.1z	libm.so.6z
libmd.so.0zlibpthread.so.0z
libdl.so.2zlibmemusage.sozlibnsl.so.1zlibnss_compat.so.2zlibnss_db.so.2zlibnss_dns.so.2zlibnss_files.so.2zlibnss_hesiod.so.2zlibpcprofile.so.2zlibresolv.so.2rzlibthread_db.so.1zlibutil.so.1zlibutil.so.2z
libgcc_s.so.2z
libgcc_s.so.1�LC_ID_DYLIB�
LC_LOAD_DYLIB�LC_RPATHcCsBt|d��}|�d�}Wd�|dvS1swY|dvS)z�
    Determines whether the given file is a macho file.

    :param path: The path to the file to check
    :type path: str

    :return: Whether the file is a macho file
    :rtype: bool
    �rb�N)s���open�read��path�fp�magic�r�C/opt/saltstack/salt/lib/python3.10/site-packages/relenv/relocate.py�is_macho2s

��rcCsBt|d��}|�d�}Wd�|dkS1swY|dkS)z�
    Determines whether the given file is an ELF file.

    :param path: The path to the file to check
    :type path: str

    :return: Whether the file is an ELF file
    :rtype: bool
    rrNsELFrrrrr�is_elfBs

��rcCs�d}d}d}i}dd�|�d�D�D]U}|sq|��ddkrId}|r6||vr+g||<||�|�d}d}|��dttd	fvrI|��d}d
}|rg|��ddkrY|��d}|��dd
krg|��d}q|ry||vrrg||<||�|�|S)z�
    Parse the output of ``otool -l <path>``.

    :param stdout: The output of the ``otool -l <path>`` command
    :type stdout: str

    :return: The parsed relevant output with command keys and path values
    :rtype: dict
    FNcS�g|]}|���qSr��strip)�.0�xrrr�
<listcomp>_�z!parse_otool_l.<locals>.<listcomp>�
r�cmd���rT�name�r)�split�appendrr)�stdoutZin_cmdrr�data�linerrr�
parse_otool_lQs:
�r$cCsJ|��D]}|�d�dkrq|�dd�d���d��d��d�SgS)z�
    Parse the output of ``readelf -d <path>``.

    :param stdout: The output of the ``readelf -d <path>`` command
    :type stdout: str

    :return: The RPATH values
    :rtype: list
    �PATHr�:r�[�])�
splitlines�findrr)r!r#rrr�parse_readelf_d~s

*r+cCs>tjdd|gtjtjd�}|j��}|�d�dkrdSt|�S)z�
    Run ``otool -l <path>`` and return its parsed output.

    :param path: The path to the file
    :type path: str

    :return: The parsed relevant RPATH content, or None if it isn't an object file
    :rtype: dict or None
    Zotoolz-l��stderrr!zis not an object filerN)�
subprocess�run�PIPEr!�decoder*r$)r�procr!rrr�parse_macho�s
�
r3cCs(tjdd|gtjtjd�}t|j���S)z�
    Run ``readelf -d <path>`` and return its parsed output.

    :param path: The path to the file
    :type path: str

    :return: The RPATH's found.
    :rtype: list
    Zreadelfz-d)r!r-)r.r/r0r+r!r1)rr2rrr�parse_rpath�s
�r4cCst|�}t�d||�t|vr�|tD]q}|�d�r!t�d|�qtj�|�r�t�	|��
�tj�|�}tj�|�sW|rDt�d||�qt
�||�t
�||�t�d||�t�d||�t�	d�tj�|t�	|��
�j�}dd	|||g}t�|�t�d
|||�q|S)a�
    Ensure the given macho file has the correct rpath and is in th correct location.

    :param path: The path to a macho file
    :type path: str
    :param root_dir: The directory the file needs to reside under
    :type root_dir: str
    :param rpath_only: If true, only ensure the correct rpaths are present and don't copy the file
    :type rpath_only: bool

    :return: The information from ``parse_macho`` on the macho file.
    zProcessing file %s %r�@zSkipping dynamic load: %s�(In `rpath_only mode` but %s is not in %szCopied %s to %szUse %s to %sz@loader_pathZinstall_name_toolz-changezChanged %s to %s in %s)r3�log�infor�
startswith�osr�exists�pathlib�Path�resolve�basename�warning�shutil�copy�copymode�relpath�parentr.r/)r�root_dir�
rpath_only�objr�y�zrrrr�handle_macho�s2

�
�rKcCs tj�|��tj�|�tj�S)a5
    Determines whether a file is contained within a directory.

    :param filepath: The path to the file to check
    :type filepath: str
    :param directory: The directory to check within
    :type directory: str

    :return: Whether the file is contained within the given directory
    :rtype: bool
    )r:r�realpathr9�sep)�filepath�	directoryrrr�	is_in_dir�s rPTcCsvt|�}|r
dd�|D�}||vr6d�|g|�}t�d||�tjddd||gtjtjd�}|jr4d	S|Sd�|�S)
a�
    Patch the rpath of a given ELF file.

    :param path: The path to an ELF file
    :type path: str
    :param new_rpath: The new rpath to add
    :type new_rpath: str
    :param only_relative: Whether or not to remove non-relative rpaths, defaults to True
    :type only_relative: bool, optional

    :return: The new rpath, or False if patching failed
    :rtype: str or bool
    cSsg|]	}|�d�r|�qS)�$ORIGIN)r9)rZrpathrrrr�szpatch_rpath.<locals>.<listcomp>r&zSet RPATH=%s %sZpatchelfz
--force-rpathz--set-rpathr,F)r4�joinr7r8r.r/r0�
returncode)rZ	new_rpathZ
only_relativeZ	old_rpathZ
patched_rpathr2rrr�patch_rpath�s�
rTcCs�|dur|}tjd|gtjtjd�}d}|j����D]�}|�d�dkr+t�d|�qdd	�|�	dd
�D�\}}|dkrDt�
d||�q|�d
d
�d��}	t
j�|	�}
|tvr_t�d|�qt|	|�rmd}t�d|	�qt
j�||
�}t
j�|�r�t�d|�q|r�t�
d|	|�qt�d|	|�t�|	|�t�|	|�d}q|r�t
j�|t
j�|��}|dkr�d}
n	tt�d�|�}
t�d||
�t||
�dSt�d|�dS)a�
    Handle the parsing and pathcing of an ELF file.

    :param path: The path of the ELF file
    :type path: str
    :param libs: The libs directory
    :type libs: str
    :param rpath_only: If true, only ensure the correct rpaths are present and don't copy the file
    :type rpath_only: bool
    :param root: The directory to ensure the file is under, defaults to None
    :type root: str, optional
    NZlddr,Fz=>rzSkip ldd output line: %scSrrr)r�_rrrr#rzhandle_elf.<locals>.<listcomp>rz	not foundz(Unable to find library %s linked from %s� rzSkipping glibc lib %sTz&File already within root directory: %szRelocated library exists: %sr6z
Copy %s to %s�.rQzAdjust rpath of %s to %szDo not adjust rpath of %s)r.r/r0r!r1r)r*r7�debugrr@�rsplitrr:rr?�LIBCLIBSrPr8rRr;rArBrCrD�dirname�strr<r=rT)rZlibsrG�rootr2Zneeds_rpathr#Zlib_nameZ
location_infoZ
linked_libZlib_basenameZrelocated_pathZrelpartrDrrr�
handle_elf
sL

r^�DEBUG�<stdout>cCs,|dkr
|dd�}ni}tjd
t�|���dd�|��tt�|����}|dur/t�|d�}tt�|����}|}i}d}|r�d	}t�	|�D]H\}}	}
|
D]@}tj
�||�}||vr\qNt�
d
|�t|�r}t�d|�t|||�}
|
dur||
||<d}qNt|�r�t�d|�t||||�qNqG|s@dSdS)a
    The entrypoint into the relocate script.

    :param root: The root directory to operate traverse for files to be patched
    :type root: str
    :param libs_dir: The directory to place the libraries in, defaults to None
    :type libs_dir: str, optional
    :param rpath_only: If true, only ensure the correct rpaths are present and don't copy the file, defaults to True
    :type rpath_only: bool, optional
    :param log_level: The level to log at, defaults to "INFO"
    :type log_level: str, optional
    r`�w)�filename�filemodez%(asctime)s %(message)s)�level�formatN�libTFzChecking %szFound Mach-O %szFound ELF %sr)�logging�basicConfig�getLevelName�upperr\r<r=r>r:�walkrrRr7rXrr8rKrr^)r]Zlibs_dirrGZ	log_levelZ
log_file_name�kwargsrFZ	processed�found�dirs�files�filerrUrrr�mainOsN�������rq�__main__�RELENVzNot in a relenv environment)T)N)NTr_r`)�__doc__rgr:r<rAr.�	getLogger�__name__r7rZrrrrrr$r+r3r4rKrPrTr^rq�sys�hasattr�RuntimeErrorrsrrrr�<module>s:
-(

#C
�5
�