%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/modules/cryptdev.pyo

�
���^c@@s
dZddlmZmZmZddlZddlZddlZddlZ	ddl
Z	ddlZ	ddlm
Z
ddlmZeje�ZdZd�Zdefd	��YZd
�Zdd�Zdd
�Zdddedd�Zd�Zd�ZdS(u^
Salt module to manage Unix cryptsetup jobs and the crypttab file

.. versionadded:: 2018.3.0
i(tabsolute_importtprint_functiontunicode_literalsN(tCommandExecutionError(tsixucryptdevcC@s tjjj�rtdfStS(u)
    Only load on POSIX-like systems
    u=The cryptdev module cannot be loaded: not a POSIX-like system(tsalttutilstplatformt
is_windowstFalsetTrue(((s9/usr/lib/python2.7/site-packages/salt/modules/cryptdev.pyt__virtual__s
t_crypttab_entrycB@s�eZdZdefd��YZdZdZeed��Zed	��Z	ed
��Z
d�Zd�Zd
�Z
d�Zed��Zd�ZRS(u�
    Utility class for manipulating crypttab entries. Primarily we're parsing,
    formatting, and comparing lines. Parsing emits dicts expected from
    crypttab() or raises a ValueError.
    t
ParseErrorcB@seZdZRS(u;Error raised when a line isn't parsible as a crypttab entry(t__name__t
__module__t__doc__(((s9/usr/lib/python2.7/site-packages/salt/modules/cryptdev.pyR
/sunameudeviceupassworduoptionsu4{name: <12} {device: <44} {password: <22} {options}
cC@s�t|�dkr*tdj|���n|jd�rK|jd��n|j�}t|�dkry|dg7}nt|�dkr�|jd��nttjj	||��S(NiuInvalid key array: {0}u#uComment!iuuInvalid Entry!(
tlent
ValueErrortformatt
startswithR
tsplittdictRtmovestzip(tclstlinetkeystcomps((s9/usr/lib/python2.7/site-packages/salt/modules/cryptdev.pytdict_from_line5scO@s||j||��S(N(R(Rtargstkwargs((s9/usr/lib/python2.7/site-packages/salt/modules/cryptdev.pyt	from_lineFscC@s|jj|�S(N(tcrypttab_formatR(Rtentry((s9/usr/lib/python2.7/site-packages/salt/modules/cryptdev.pytdict_to_lineJscC@s|j|j�S(u&String value, only works for full repr(R#tcriteria(tself((s9/usr/lib/python2.7/site-packages/salt/modules/cryptdev.pyt__str__NscC@s
t|j�S(uAlways works(treprR$(R%((s9/usr/lib/python2.7/site-packages/salt/modules/cryptdev.pyt__repr__RscC@s9tg|D]}||j|f^q
�}|j|�S(u(Returns an instance with just those keys(RR$t	__class__(R%Rtkeytsubset((s9/usr/lib/python2.7/site-packages/salt/modules/cryptdev.pytpickVs,cK@s d�tj|�D�|_dS(u1Store non-empty, non-null values to use as filtercS@s:i|]0\}}|dk	rtjjj|�|�qS(N(tNoneRRtstringutilst
to_unicode(t.0R*tvalue((s9/usr/lib/python2.7/site-packages/salt/modules/cryptdev.pys
<dictcomp>]s		N(Rt	iteritemsR$(R%R$((s9/usr/lib/python2.7/site-packages/salt/modules/cryptdev.pyt__init__[scC@stjjtjj|��S(u%Resolve equivalent paths equivalently(tostpathtnormcasetnormpath(R5((s9/usr/lib/python2.7/site-packages/salt/modules/cryptdev.pyt	norm_pathascC@sJ|j|�}x4tj|j�D] \}}|||kr"tSq"WtS(u<Compare potentially partial criteria against a complete line(RRR2R$R	R
(R%RR"R*R1((s9/usr/lib/python2.7/site-packages/salt/modules/cryptdev.pytmatchfs
(unameudeviceupassworduoptions(RRRRR
t
crypttab_keysR!tclassmethodRR R#R&R(R,R3tstaticmethodR8R9(((s9/usr/lib/python2.7/site-packages/salt/modules/cryptdev.pyR(s				cC@s�i}tdd�}tjd�}tj|�xV|jd�D]E}|j|�}|rz|j�}|||d<qBtjd�qBW|S(u5
    List existing device-mapper device details.
    ucmd.run_stdoutudmsetup ls --target cryptu5(?P<devname>\w+)\W+\((?P<major>\d+), (?P<minor>\d+)\)u
udevnameu-dmsetup output does not match expected format(	t__salt__tretcompiletlogtdebugRR9t	groupdicttwarning(trettdevicest	out_regexRR9tdev_info((s9/usr/lib/python2.7/site-packages/salt/modules/cryptdev.pytactiveos
u
/etc/crypttabc
C@s�i}tjj|�s|Stjjj|���}x�|D]�}tjjj|�j	d�}ydt
j|�}|djd�|d<x$|d|kr�|dcd7<q�W|||j
d�<Wq;t
jk
r�q;Xq;WWdQX|S(u{
    List the contents of the crypttab

    CLI Example:

    .. code-block:: bash

        salt '*' cryptdev.crypttab
    u
uoptionsu,unameu_N(R4R5tisfileRRtfilestfopenR.R/trstripRRRtpopR
(tconfigRDtifileRR"((s9/usr/lib/python2.7/site-packages/salt/modules/cryptdev.pytcrypttab�s

c

C@szt}td|�}g}y�tjjj|d��z}xp|D]h}tjjj|�}y)|j|�rvt	}n
|j
|�Wq@tjk
r�|j
|�q@Xq@WWdQXWn7tt
fk
r�}d}t|j||���nX|rly<tjjj|d��}	|	jd�|D��WdQXWqltt
fk
rh}d}t|j||���qlXn|rvdSd	S(
u2
    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
    tnameurNuCould not read from {0}: {1}uw+cs@s$|]}tjjj|�VqdS(N(RRR.tto_str(R0R((s9/usr/lib/python2.7/site-packages/salt/modules/cryptdev.pys	<genexpr>�suCould not write to {0}: {1}uchangeuabsent(R	RRRRJRKR.R/R9R
tappendR
tIOErrortOSErrorRRt
writelines(
RQRNtmodifiedR$tlinesRORtexctmsgtofile((s9/usr/lib/python2.7/site-packages/salt/modules/cryptdev.pytrm_crypttab�s0
	!unoneuunamec
C@s:|dkrd}nHt|tj�r*n3t|t�rKdj|�}nd}t|��i|d6|d6|dk	r�|ndd6|d6}g}	d}
t|t�r�n0t|tj�s�d	}t|��n	|g}t|�}y|j|�}WnJt	k
rJd
�}
tj
j|
|�}dj|�}t|��nXt
jj|�sutdj|���ny�tjjj|d
���}x�|D]�}tjjj|�}yd|j|�rd}
|j|�r�|	j|�qd}
|	jtj|��n
|	j|�Wq�tjk
r<|	j|�q�Xq�WWdQXWn7ttfk
r�}d}t|j||���nX|
dkr�|	jtj|��d}
n|
dkr6|s6y<tjjj|d��}|jd�|	D��WdQXWq3ttfk
r/d}t|j|���q3Xq6n|
S(u
    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
    uu,u+options must be a string or list of stringsunameudeviceunoneupassworduoptionsu,match_on must be a string or list of stringscS@s
|tjkS(N(RR:(R*((s9/usr/lib/python2.7/site-packages/salt/modules/cryptdev.pyt<lambda>su$Unrecognized keys in match_on: "{0}"uBad config file "{0}"urupresentuchangeNuCouldn't read from {0}: {1}unewuw+cs@s$|]}tjjj|�VqdS(N(RRR.RR(R0R((s9/usr/lib/python2.7/site-packages/salt/modules/cryptdev.pys	<genexpr>7suFile not writable {0}(R-t
isinstanceRtstring_typestlisttjoinRRR,tKeyErrorRtfilterRR4R5RIRRRJRKR.R/R9RSt	text_typeR
RTRURV(RQtdevicetpasswordtoptionsRNttesttmatch_onRZt
entry_argsRXRDR"R$tfilterFntinvalid_keysRORRYR[((s9/usr/lib/python2.7/site-packages/salt/modules/cryptdev.pytset_crypttab�sx	
	
	
	!cC@s\|dks$|dks$|dkr3td��ntddj|||��}|dkS(u$
    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
    unoneu-u<For immediate crypt device mapping, keyfile must not be noneucmd.retcodeu&cryptsetup open --key-file {0} {1} {2}iN(R-RR=R(RQRetkeyfiletcode((s9/usr/lib/python2.7/site-packages/salt/modules/cryptdev.pytopen?s
$
cC@s#tddj|��}|dkS(u�
    Close a crypt device using ``cryptsetup``.

    CLI Example:

    .. code-block:: bash

        salt '*' cryptdev.close foo
    ucmd.retcodeucryptsetup close {0}i(R=R(RQRo((s9/usr/lib/python2.7/site-packages/salt/modules/cryptdev.pytcloseSs
(Rt
__future__RRRtloggingR4R>tsalt.utils.filesRtsalt.utils.platformtsalt.utils.stringutilstsalt.exceptionsRtsalt.extRt	getLoggerRR@t__virtualname__RtobjectRRHRPR\R	RmRpRq(((s9/usr/lib/python2.7/site-packages/salt/modules/cryptdev.pyt<module>s.	
G	 2e	

Zerion Mini Shell 1.0