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__/cryptdev.cpython-310.pyc
o

�N�g8(�@s�dZddlZddlZddlZddlZddlZddlZddlm	Z	e�
e�ZdZ
dd�ZGdd�d�Zd	d
�Zddd
�Zddd�Z					ddd�Zdd�Zdd�ZdS)z^
Salt module to manage Unix cryptsetup jobs and the crypttab file

.. versionadded:: 2018.3.0
�N)�CommandExecutionErrorZcryptdevcCstjj��rdSdS)z)
    Only load on POSIX-like systems
    )Fz=The cryptdev module cannot be loaded: not a POSIX-like systemT)�salt�utils�platformZ
is_windows�rr�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/cryptdev.py�__virtual__src@s�eZdZdZGdd�de�ZdZdZeefdd��Z	edd	��Z
ed
d��Zdd
�Zdd�Z
dd�Zdd�Zedd��Zdd�ZdS)�_crypttab_entryz�
    Utility class for manipulating crypttab entries. Primarily we're parsing,
    formatting, and comparing lines. Parsing emits dicts expected from
    crypttab() or raises a ValueError.
    c@seZdZdZdS)z_crypttab_entry.ParseErrorz;Error raised when a line isn't parsible as a crypttab entryN)�__name__�
__module__�__qualname__�__doc__rrrr�
ParseError+sr��name�device�password�optionsz4{name: <12} {device: <44} {password: <22} {options}
cCspt|�dkr
td|����|�d�r|�d��|��}t|�dkr&|dg7}t|�dkr1|�d��tt||��S)N�zInvalid key array: �#zComment!��zInvalid Entry!)�len�
ValueError�
startswithr�split�dict�zip)�cls�line�keys�compsrrr�dict_from_line1s



z_crypttab_entry.dict_from_linecOs|di|j|i|����S�Nr)r")r�args�kwargsrrr�	from_lineBsz_crypttab_entry.from_linecCs|jjdi|��Sr#)�crypttab_format�format)r�entryrrr�dict_to_lineFsz_crypttab_entry.dict_to_linecCs|�|j�S)z&String value, only works for full repr)r*�criteria��selfrrr�__str__Jsz_crypttab_entry.__str__cCs
t|j�S)zAlways works)�reprr+r,rrr�__repr__Ns
z_crypttab_entry.__repr__cs"�fdd�|D�}�jdi|��S)z(Returns an instance with just those keyscsi|]}|�j|�qSr)r+)�.0�keyr,rr�
<dictcomp>Tsz(_crypttab_entry.pick.<locals>.<dictcomp>Nr)�	__class__)r-r Zsubsetrr,r�pickRsz_crypttab_entry.pickcKsdd�|��D�|_dS)z1Store non-empty, non-null values to use as filtercSs(i|]\}}|dur|tjj�|��qS�N)rr�stringutils�
to_unicode)r1r2�valuerrrr3Ys
�z,_crypttab_entry.__init__.<locals>.<dictcomp>N)�itemsr+)r-r+rrr�__init__Ws�z_crypttab_entry.__init__cCstj�tj�|��S)z%Resolve equivalent paths equivalently)�os�path�normcase�normpath)r=rrr�	norm_path_sz_crypttab_entry.norm_pathcCs4|�|�}|j��D]
\}}|||krdSq
dS)z<Compare potentially partial criteria against a complete lineFT)r"r+r:)r-rr)r2r9rrr�matchds
�z_crypttab_entry.matchN)r
rrr
rr�
crypttab_keysr'�classmethodr"r&r*r.r0r5r;�staticmethodr@rArrrrr	$s$


r	cCsfi}tdd�}t�d�}t�|�|�d�D]}|�|�}|r+|��}|||d<qt�d�q|S)z5
    List existing device-mapper device details.
    zcmd.run_stdoutzdmsetup ls --target cryptz5(?P<devname>\S+)\s+\((?P<major>\d+), (?P<minor>\d+)\)�
Zdevnamez-dmsetup output does not match expected format)	�__salt__�re�compile�log�debugrrA�	groupdict�warning)�retZdevicesZ	out_regexrrAZdev_inforrr�activems


rN�
/etc/crypttabc
Cs�i}tj�|�s
|Stjj�|��M}|D]A}tjj�|��	d�}z+t
�|�}|d�d�|d<|d|vrC|dd7<|d|vs5|||�
d�<Wqt
jyUYqwWd�|S1sawY|S)z{
    List the contents of the crypttab

    CLI Example:

    .. code-block:: bash

        salt '*' cryptdev.crypttab
    rEr�,r�_N)r<r=�isfilerr�files�fopenr7r8�rstripr	r"r�popr)�configrM�ifilerr)rrr�crypttab�s*

���
��rYc

CsNd}t|d�}g}zDtjj�|d��2}|D]'}tjj�|�}z|�|�r'd}n|�|�Wqtj	y<|�|�YqwWd�n1sGwYWnt
yc}z
d}t|�||���d}~ww|r�z$tjj�|d��}	|	�
dd	�|D��Wd�n1s�wYWnt
y�}z
d
}t|�||���d}~ww|r�dSdS)
a2
    Remove the named mapping from the crypttab. If the described entry does not
    exist, nothing is changed, but the command succeeds by returning
    ``'absent'``. If a line is removed, it returns ``'change'``.

    CLI Example:

    .. code-block:: bash

        salt '*' cryptdev.rm_crypttab foo
    F)r�rTNzCould not read from {0}: {1}�w+cs��|]
}tjj�|�VqdSr6�rrr7Zto_str�r1rrrr�	<genexpr>�s�zrm_crypttab.<locals>.<genexpr>zCould not write to {0}: {1}�changeZabsent)r	rrrSrTr7r8rA�appendr�OSErrorrr(�
writelines)
rrWZmodifiedr+�linesrXr�exc�msg�ofilerrr�rm_crypttab�sF


�����������rh�nonerFrc
Cst|durd}nt|t�r
nt|t�rd�|�}nd}t|��|||dur&|nd|d�}g}	d}
t|t�r5nt|t�s@d}t|��|g}tdi|��}z|�|�}Wntykdd	�}
t|
|�}d
|�d�}t|��wt	j
�|�sztd|�d���zXtj
j�|d
��F}|D];}tj
j�|�}z#|�|�r�d}
|�|�r�|	�|�nd}
|	�t|��n|	�|�Wq�tjy�|	�|�Yq�wWd�n1s�wYWnty�}z
d}t|�||���d}~ww|
dur�|	�t|��d}
|
dk�r8|�s8z(tj
j�|d��}|�dd�|	D��Wd�W|
S1�swYW|
St�y7d}t|�|���w|
S)a
    Verify that this device is represented in the crypttab, change the device to
    match the name passed, or add the name if it is not present.

    CLI Example:

    .. code-block:: bash

        salt '*' cryptdev.set_crypttab foo /dev/sdz1 mypassword swap,size=256
    NrrPz+options must be a string or list of stringsrirz,match_on must be a string or list of stringscSs
|tjvSr6)r	rB)r2rrr�filterFns
zset_crypttab.<locals>.filterFnz Unrecognized keys in match_on: "�"zBad config file "rZZpresentr`zCouldn't read from {0}: {1}�newr[csr\r6r]r^rrrr_9s�
�zset_crypttab.<locals>.<genexpr>zFile not writable {0}r)�
isinstance�str�list�joinrr	r5�KeyError�filterr<r=rRrrrSrTr7r8rArarrbr(rc)rrrrrW�testZmatch_onrfZ
entry_argsrdrMr)r+rjZinvalid_keysrXrrergrrr�set_crypttab�s�

�


�


�������


��	�	��rtcCsF|dus|dks|dkrtd��tdd|�d|�d|���}|dkS)	a$
    Open a crypt device using ``cryptsetup``. The ``keyfile`` must not be
    ``None`` or ``'none'``, because ``cryptsetup`` will otherwise ask for the
    password interactively.

    CLI Example:

    .. code-block:: bash

        salt '*' cryptdev.open foo /dev/sdz1 /path/to/keyfile
    Nri�-z<For immediate crypt device mapping, keyfile must not be none�cmd.retcodezcryptsetup open --key-file � r)rrF)rr�keyfile�coderrr�openCs��rzcCstdd|���}|dkS)z�
    Close a crypt device using ``cryptsetup``.

    CLI Example:

    .. code-block:: bash

        salt '*' cryptdev.close foo
    rvzcryptsetup close r)rF)rryrrr�closeZs
r{)rO)rirrOFr)r
�loggingr<rGZsalt.utils.filesrZsalt.utils.platformZsalt.utils.stringutilsZsalt.exceptionsr�	getLoggerr
rIZ__virtualname__rr	rNrYrhrtrzr{rrrr�<module>s.

I

 2
�r