AlkantarClanX12

Your IP : 3.133.123.162


Current Path : /opt/cloudlinux/venv/lib64/python3.11/site-packages/clcommon/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/clcommon/__pycache__/clpwd.cpython-311.pyc

�

�tg���|�ddlZddlZddlZddlmZddlmZGd�d��Zdd�Zed	���Z	d
�Z
d
d�ZdS)�N)�contextmanager�)�FormattedExceptionc�z�eZdZdZGd�de��Zdd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zd�Zd�Zdd�ZdS)�ClPwdz/etc/login.defsc���eZdZ�fd�Z�xZS)�ClPwd.NoSuchUserExceptionc�d��ttj|��jdd|id�g|�Ri|��dS)NzNo such user (%(user)s)�user��message�context)�superr�NoSuchUserException�__init__)�selfr�args�kwargs�	__class__s    ���/builddir/build/BUILDROOT/alt-python27-cllib-3.4.16-1.el8.cloudlinux.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/clcommon/clpwd.pyrz"ClPwd.NoSuchUserException.__init__sc���;�E�%�+�T�2�2�;�4�"�D�>�=�=�
 ��
 �
 �
 ��
 �
 �
 �
 �
 �)�__name__�
__module__�__qualname__r�
__classcell__)rs@rrr	s8�������	 �	 �	 �	 �	 �	 �	 �	 �	 rrNc��i|_i|_i|_i|_|�|�d��|_dS||_dS)N��)�
_user_key_map�_uid_key_map�_user_full_map�
_uid_full_map�get_sys_min_uid�_min_uid)r�min_uids  rrzClPwd.__init__sK�������� �������?� �0�0��5�5�D�M�M�M�#�D�M�M�Mrc�8�|���|jS�N)�_load_passwd_databaser�rs r�
get_user_dictzClPwd.get_user_dict'����"�"�$�$�$��!�!rc�8�|���|jSr&)r'rr(s r�get_uid_dictzClPwd.get_uid_dict+s���"�"�$�$�$�� � rc�8�|���|jSr&)r'r r(s r�get_user_full_dictzClPwd.get_user_full_dict/s���"�"�$�$�$��"�"rc�8�|���|jSr&)r'r!r(s r�get_uid_full_dictzClPwd.get_uid_full_dict3r*rc��	|���|S#t$r }t�|��|�d}~wwxYw)z*
        Return pw_entry for user
        N)r.�KeyErrorrr�rr�es   r�get_pw_by_namezClPwd.get_pw_by_name7sS��	9��*�*�,�,�T�2�2���	9�	9�	9��+�+�D�1�1�q�8�����	9������
A�A�Ac��	|���|S#t$r }t�|��|�d}~wwxYw)z7
        Return list of passwd entries for uid
        N�r0r2rr)r�uidr4s   r�
get_pw_by_uidzClPwd.get_pw_by_uid@sS��	8��)�)�+�+�C�0�0���	8�	8�	8��+�+�C�0�0�a�7�����	8���r6c��	|���|jS#t$r }t�|��|�d}~wwxYw)z&
        Returns uid for user
        N)r.�pw_uidr2rrr3s   r�get_uidz
ClPwd.get_uidIsV��	9��*�*�,�,�T�2�9�9���	9�	9�	9��+�+�D�1�1�q�8�����	9�����!�
A�A�Ac��	|���|jS#t$r }t�|��|�d}~wwxYw)z`
        Returns homedir for a user
        @param user: string
        @return: string
        N)r.�pw_dirr2rrr3s   r�get_homedirzClPwd.get_homedirRsV��	9��*�*�,�,�T�2�9�9���	9�	9�	9��+�+�D�1�1�q�8�����	9���r>c��|js�tj��D]�}||j|j<|j|jvrg|j|j<|j|j�|��|j|jkrQ||j|j<|j|j	vrg|j	|j<|j	|j�|����dSdS)zZ
        Loads the passwd database and fills user_to_uid and user_to_homedir maps
        N)
r!�pwd�getpwallr �pw_namer<�appendr#rr)r�entrys  rr'zClPwd._load_passwd_database]s����!�
	B�����	
B�	
B��5:��#�E�M�2��<�t�'9�9�9�79�D�&�u�|�4��"�5�<�0�7�7��>�>�>��<�4�=�0�0�8=�D�&�u�}�5��|�4�+<�<�<�:<��)�%�,�7��%�e�l�3�:�:�5�A�A�A��
	B�
	B�	
B�	
Brc��	|���|}n-#t$r }t�|��|�d}~wwxYwd�|D��S)zs
        Return names of users with uid specified
        @param uid: int
        @return: list of strings
        Nc��g|]	}|j��
S�)rE)�.0rGs  r�
<listcomp>z#ClPwd.get_names.<locals>.<listcomp>xs��3�3�3�%��
�3�3�3rr8)rr9�entriesr4s    r�	get_nameszClPwd.get_namesmsj��	8��,�,�.�.�s�3�G�G���	8�	8�	8��+�+�C�0�0�a�7�����	8����4�3�7�3�3�3�3s��
A�A�Arc��tj�|j��r�t	|jdd���5}|���}ddd��n#1swxYwY|D]d}|�d��rM	t|�d��d�	����cS#t$rY�`wxYw�e|S)z�
        Return system defined MIN_UID from /etc/login.def or def_min_uid
        @param def_min_uid: int
        @return: MIN_UID: int
        �rzutf-8)�encodingN�UID_MINr)�os�path�exists�LOGIN_DEF_FILE�open�	readlines�
startswith�int�split�strip�
ValueError)r�def_min_uid�f�lines�lines     rr"zClPwd.get_sys_min_uidzs���7�>�>�$�-�.�.�	��d�)�3��A�A�A�
&�Q����
�
��
&�
&�
&�
&�
&�
&�
&�
&�
&�
&�
&����
&�
&�
&�
&��
�
���?�?�9�-�-���"�4�:�:�i�#8�#8��#;�#A�#A�#C�#C�D�D�D�D�D��%������������s#�A�A!�$A!�9B>�>
C�
Cr&)r)rrrrVrrrr)r,r.r0r5r:r=rAr'rNr"rJrrrrs������&�N� � � � � �0� � � �$�$�$�$�"�"�"�!�!�!�#�#�#�"�"�"�9�9�9�8�8�8�9�9�9�	9�	9�	9�B�B�B� 4�4�4������rrTc�0��tj��}|dkr��r�tj���}�fd�t	j��D��}|j}||vr|�|��tj|��|r3tj	|j��tj
|j��n2tj|j��tj
|j��|r)�tjd<|jtjd<dSdSdSdS)z�
    Drop current root privileges to user
    :param effective_or_real: if True - drop euid, else - drop ruid
    :param user: name of unix user
    :param set_env: bool -> if true set $HOME and $USER env variables
    :return: None
    rc�0��g|]}�|jv�|j��SrJ)�gr_mem�gr_gid)rK�grouprs  �rrLz(drop_user_privileges.<locals>.<listcomp>�s'���X�X�X��4�5�<�CW�CW�u�|�CW�CW�CWr�USER�HOMEN)rS�geteuidrC�getpwnam�grp�getgrall�pw_gidrF�	setgroups�setegid�seteuidr<�setgid�setuid�environr@)r�effective_or_real�set_env�current_euid�user_pwd�user_groups�main_user_groups`      r�drop_user_privilegesrz�s����:�<�<�L��q���T���<��%�%��X�X�X�X�����X�X�X��"�/���+�-�-�����/�/�/�
��[�!�!�!��	'��J�x��'�'�'��J�x��'�'�'�'��I�h�o�&�&�&��I�h�o�&�&�&��	1�!%�B�J�v��!)��B�J�v����%����	1�	1rc#�K�tj��tj��tj��}}}	t	|dd���n-#t
$r }t�|��|�d}~wwxYw	dV�tj|��tj	|��tj
|��dS#tj|��tj	|��tj
|��wxYw)zk
    Temporary drop privileges to some user
    :type user: str
    :raises: ClPwd.NoSuchUserException
    TF)rtruN)rS�getuid�getgid�	getgroupsrzr2rrrprorn)r�old_uid�old_gid�
old_groupsr4s     r�drop_privilegesr��s�����$&�9�;�;��	���R�\�^�^�j�W�G�5��T�T�5�I�I�I�I�I���5�5�5��'�'��-�-�1�4�����5����!�
����
�
�7����
�
�7����
��Z� � � � � ��	�
�7����
�
�7����
��Z� � � � ���s#�A�
A:�A5�5A:�>C�>C>c��|�td���ddlm}ddlm}||��}	|d\}}n##t
$r}|dd|id	���|�d}~wwxYw|S)
zw
    Resolve document root by username
    :param user: str -> name of unix user
    :return: str -> document root
    Nz-Cannot resolve docroot without specified userr)�userdomains)�NoDomainrz!No domain for user %(user)s foundrr)r�cpapir��cpapi.cpapiexceptionsr��
IndexError)rr�r��domains_list�_�resultr4s       r�_resolve_doc_root_by_userr��s����|� �!P�Q�Q�Q�#�"�"�"�"�"�/�/�/�/�/�/��;�t�$�$�L�� ��O�	��6�6�������h�:���~�
�
����	���������
�Ms�6�
A�A�Ac�&�ddlm}ddlm}|}d}t	j��}|�'||��\}}|�|}n||kr|d���|}nB|�t
|���}n/|dkr)tj|��j	}t
|���}||fS)a
    Resolve username and doc_root by domain,
    or resolve document root by username,
    or resolve document root and username by effective uid
    :param user: str -> name of unix user
    :param domain: str -> domain of panel user
    :return: tuple -> user, doc_root
    r)�docroot)�
IncorrectDataNzUser and domain are in conflict)rr)
r�r�r�r�rSrir�rC�getpwuidrE)	r�domainr�r��result_user�result_doc_rootrv�doc_root�domain_users	         r�resolve_username_and_doc_rootr��s���������4�4�4�4�4�4��K��O��:�<�<�L�
�� '�������+��<�%�K�K�
�[�
 �
 ��-� A�B�B�B�"���	
�	�3��>�>�>���	��	�	��l�<�0�0�8��3��E�E�E����'�'r)NTT)NN)rSrCrk�
contextlibr�clexceptionrrrzr�r�r�rJrr�<module>r�s���
�	�	�	�
�
�
�
�
�
�
�
�%�%�%�%�%�%�+�+�+�+�+�+�y�y�y�y�y�y�y�y�x1�1�1�1�<�!�!���!�&���4(�(�(�(�(�(r