ok

Mini Shell

Direktori : /opt/alt/python37/lib/python3.7/site-packages/clcommon/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/clcommon/__pycache__/clcagefs.cpython-37.pyc

B

E!wd#'�@s�ddlmZddlmZddlmZddlZddlZddlZddlZdZdZ	Gdd�de
�ZGd	d
�d
e
�ZGdd�d�Z
d
d�Zd$dd�Zd%dd�Zd&dd�Zdd�Zdd�Zdd�Zd'dd�Zd d!�Zd"d#�ZdS)(�)�print_function)�absolute_import)�divisionNz/etc/cagefs/cagefs.mpz/usr/sbin/cagefsctlc@seZdZdd�Zdd�ZdS)�CagefsMpConflictcCsd|t|f|_dS)NzUConflict in adding '%s' to %s because of pre-existing alternative specification: '%s')�CAGEFS_MP_FILENAME�_msg)�self�new_itemZ
existing_item�r
�B/opt/alt/python37/lib/python3.7/site-packages/clcommon/clcagefs.py�__init__szCagefsMpConflict.__init__cCs|jS)N)r)rr
r
r�__str__szCagefsMpConflict.__str__N)�__name__�
__module__�__qualname__rr
r
r
r
rrsrc@seZdZdZdd�ZdS)�CagefsNotSupportedErrorzCagefs Not Supported ExceptioncCst�||�dS)N)�	Exceptionr)r�messager
r
rr!sz CagefsNotSupportedError.__init__N)rrr�__doc__rr
r
r
rrsrc@s�eZdZdZdZdZdd�Zdd�Zdd	�Ze	d
d��Z
dd
�Zdd�Zdd�Z
e	dd��Ze	dd��Ze	dd��Zdd�Zdd�ZdS)�CagefsMpItemz@!%*��!cCs6|dd�dkrd|_n|��dkr,d|_n||_dS)z�Constructor

        :param arg: Is either path to add to cagefs.mp or a raw line is read from cagefs.mp
        :param prefix: The same as adding prefix '!' to arg before passing it to ctorN��#r)�
_path_spec�strip)r�argr
r
rr+s
zCagefsMpItem.__init__cCs(|��dkr$|dk	r$d|j|f|_|S)z%Specify mode as in fluent constructor�@Nz%s,%03o)�prefixr)r�moder
r
rr8szCagefsMpItem.modecCs|jS)N)r)rr
r
rr
@szCagefsMpItem.__str__cCs$|dkrdS|ddkr |dS|S)Nr�/���r
)�pathr
r
r�
_add_slashCs
zCagefsMpItem._add_slashcCsDt�|�}|��s|��rdSt�|���}t�|���}|�|�S)NF)r�_adopt�is_dummyr#r"�
startswith)rZanother�adoptedZ	this_pathZtest_preexist_in_pathr
r
r�pre_exist_inKs
zCagefsMpItem.pre_exist_incCs\t�|�}|��s|��rdS|��|��kr2dStjtjgi}g}|��|�|��|�kS)NFT)rr$r%r�_PREFIX_MOUNT_RW�_PREFIX_MOUNT_RO�get)rZexistingr'Zprefix_compatibility_mapZnull_optionsr
r
r�is_compatible_by_prefix_withWs
z)CagefsMpItem.is_compatible_by_prefix_withcCs
|jdkS)N)r)rr
r
rr%gszCagefsMpItem.is_dummycCst|t�r|St|�SdS)N)�
isinstancer)�xr
r
rr$js
zCagefsMpItem._adoptcCs|�d�dS)zjCut off mode from path spec like @/var/run/screen,777

        Only one comma per path spec is allowed ;-)�,r)�split)�	path_specr
r
r�
_cut_off_modeqszCagefsMpItem._cut_off_modecCs|�tj�S)N)�lstripr�PREFIX_LIST)r1r
r
r�_cut_off_prefixyszCagefsMpItem._cut_off_prefixcCst�t�|j��S)N)rr5r2r)rr
r
rr"}szCagefsMpItem.pathcCs |j|��kr|jdSdSdS)Nrr)rr")rr
r
rr�s
zCagefsMpItem.prefixN)rrrr4r)r*rrr
�staticmethodr#r(r,r%r$r2r5r"rr
r
r
rr%s
rcCstj�t�S)N)�osr"�exists�CAGEFSCTL_TOOLr
r
r
r�is_cagefs_present�sr:��cCsT|dkrd}|dkrd}tj�|�s.t�|�|dk	rBt�||�t�|||�dS)Nr!)r7r"�isdir�mkdir�chmod�chown)r"r�owner_id�group_idr
r
r�_mk_mount_dir_setup_perm�s
rBFcCsZt�s
dS|dkrtddg}n
td|g}|rBtj|tjtjd�ntj|tjtjd�dS)Nz--wait-lockz
--remount-allz	--remount)�stdout�stderr)r:r9�
subprocess�Popen�DEVNULL�run)�user�remount_in_backgroundZcommandr
r
r�_remount_cagefs�s
rKrcst||||�t�sdStj�t�s<tjtdgtj	tj	d�t
�ttd�}z�t||��
|��dd�|D�}	�fdd�|	D�}
|
s�|�d	d
�|dk	r�|��}td||d�t�|d�|��|r�t|d
�n��|
d�s�t�|
d��Wd|��XdS)a�
    Add mount point to /etc/cagefs/cagefs.mp

    :param path: Directory path to be added in cagefs.mp and mounted
                 from within setup_mount_dir_cagefs().
                 If this directory does not exist, then it is created.

    :param added_by: package or component, mount dir relates to, or whatever will
                     stay in cagefs.mp with "# added by..." comment

    :param mode: If is not None: Regardless of whether directory exists or not prior this call,
                 it's permissions will be set to mode.

    :param owner_id: Regardless of whether directory exists or not prior this call,
                     it's owner id will be set to.
                     If None, the owner won't be changed.

    :param group_id: Regardless of whether directory exists or not prior this call,
                     it's group id will be set to.
                     If None, the group won't be changed.

    :param prefix: Mount point prefix. Default is mount as RW.
                   Pass '!' to add read-only mount point.
                   Refer CageFS section at http://docs.cloudlinux.com/ for more options.

    :param remount_cagefs: If True, cagefs skeleton will be automatically
                           remounted to apply changes.

    :param remount_in_background: If True, cagefs remount will be done in separate
                    background process, without waiting for completion

    :returns: None

    Propagates native EnvironmentError if no CageFS installed or something else goes wrong.

    Raises CagefsMpConflict if path is already specified in cagefs.mp, but in a way which is opposite
    to mount_as_readonly param.
    Nz--create-mp)rCrDzr+css|]}|��VqdS)N)�rstrip)�.0Z	file_liner
r
r�	<genexpr>�sz)setup_mount_dir_cagefs.<locals>.<genexpr>csg|]}��|�r|�qSr
)r()rMr.)r	r
r�
<listcomp>�sz*setup_mount_dir_cagefs.<locals>.<listcomp>r�z# next line is added by )�file)rJr!)rBr:r7r"r8rrErHr9rG�add_new_line_to_cagefs_mp�openrr�seekr�print�closerKr,r)r"Zadded_byrr@rAr�remount_cagefsrJZ	cagefs_mpZtrim_nl_iterZpre_exist_optionr
)r	r�setup_mount_dir_cagefs�s.)
rXc	Csttd��
}|��SQRXdS)N�r)rSr�	readlines)�fr
r
r�_get_cagefs_mp_lines�sr\c	Cs ttd��}|�|�SQRXdS)N�w)rSr�
writelines)�linesr[r
r
r�_write_cagefs_mp_linessr`cCsBt�}|r>|ddkr>|dddkr>|dd7<t|�dS)zR
    Add new line to the end of /etc/cagefs/cagefs.mp file if it is not there
    rrr!�
N)r\r`)r_r
r
rrRs rRcsNt�}t�djtjt�|�d����fdd�|D�}t|�|rJt|d�dS)af
    Remove mount points matching given path from cagefs.mp file
    :param str path: Path that should be removed from file.
    :param bool remount_cagefs: Remount cagefs skeleton or not
    :param remount_in_background: If True, cagefs remount will be done in separate
           background process, without waiting for completion
    :return: Nothing
    z^[{prefix}]?{path}(,\d+)?$)rr"c3s|]}��|�s|VqdS)N)�match)rM�line)rYr
rrN sz*remove_mount_dir_cagefs.<locals>.<genexpr>)rJN)	r\�re�compile�formatrr4�escaper`rK)r"rWrJr_Zlines_with_excluded_pathr
)rYr�remove_mount_dir_cagefss	rhcCstj�d�S)zEIf this folder /var/.cagefs exists, it means process is inside cagefsz/var/.cagefs)r7r"r<r
r
r
r�	in_cagefs'sricCspy&d}|tjkrtj�|�ddl}Wntk
r:dSXy|�|�sLdSWntk
rjtd��YnXdS)z,
    Check that cagefs enabled for user
    z/usr/share/cagefs/rNFz;ERROR: CageFS version is unsupported. Please update CageFS.T)�sysr"�append�	cagefsctl�ImportErrorZis_user_enabled�AttributeErrorr)rIZcagefs_lib_dirrlr
r
r�_is_cagefs_enabled,s

ro)r;NN)NF)Nr;NNrFF)FF)Z
__future__rrrr7rdrErjrr9rrrrr:rBrKrXr\r`rRrhriror
r
r
r�<module>	s,
b


R


Zerion Mini Shell 1.0