HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/pw_user.cpython-310.pyc
o

�N�g�1�@sFdZddlZddlZddlZddlZddlZddlmZzddl	Z	dZ
Wney/dZ
Ynwe�e
�ZdZdd�Zd	d
�Zdd�Zd
d�Z												d4dd�Zd5dd�Zd6dd�Zdd�Zdd�Zdd�Zd6dd�Zd6dd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd7d(d)�Z d*d+�Z!d,d-�Z"d.d/�Z#d0d1�Z$d2d3�Z%dS)8a
Manage users with the pw command

.. important::
    If you feel that Salt should be using this module to manage users on a
    minion, and it is using a different module (or gives an error similar to
    *'user.info' is not available*), see :ref:`here
    <module-provider-override>`.
�N)�CommandExecutionErrorTF�usercCstr
tddvr
tSdS)zC
    Set the user module if the kernel is FreeBSD or DragonFly
    Zkernel)ZFreeBSDZ	DragonFly)FzsThe pw_user execution module cannot be loaded: the pwd python module is not available or the system is not FreeBSD.)�HAS_PWDZ
__grains__�__virtualname__�rr�H/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/pw_user.py�__virtual__:srcCs�zt�|�j�dd�}Wntytd|�d���w|s iSt|�dkr1|�d�t|�dks&tj	j
�|d�tj	j
�|d�tj	j
�|d	�tj	j
�|d�d
�S)zD
    Retrieve GECOS field info and return it in dictionary form
    �,��User '�' does not exist��r����fullname�
roomnumber�	workphone�	homephone)�pwd�getpwnam�pw_gecos�split�KeyErrorr�len�append�salt�utils�data�decode)�name�gecos_fieldrrr�
_get_gecosGs�
��r#c	Cs0d�|�dd�|�dd�|�dd�|�dd��S)z�
    Accepts a dictionary entry containing GECOS field names and their values,
    and returns a full GECOS comment string, to be used with pw usermod.
    z{},{},{},{}rrrrr)�format�get)Z
gecos_dictrrr�_build_gecos]s



�r&cCs�t|t�s	t|�}t|�}|sdS|||krdSt�|�}|||<dd|dt|�g}td|dd�t|�}t|��|�|kS)z:
    Common code to change a user's GECOS information
    FT�pw�usermod�-c�cmd.run�Zpython_shell)	�
isinstance�strr#�copy�deepcopyr&�__salt__�infor%)r!�key�value�pre_infoZ
gecos_data�cmd�	post_inforrr�
_update_gecosjs

r7rc
Ks@tjjjdi|
��}
tjj�|
�dd��rt�d�|
r!t�d�t	|t
�r+|�d�}ddg}|r8|�d|g�|rA|�d	|g�|rM|�d
d�
|�g�|durX|�d|g�|d
ura|�d�|rj|�d|g�|rs|�d|g�tjj�|�s|�d�t|||	|
d��}|�d|g�|�d|g�td|dd�dkS)z�
    Add a user to the minion

    CLI Example:

    .. code-block:: bash

        salt '*' user.add name <uid> <gid> <groups> <home> <shell>
    �systemFz5pw_user module does not support the 'system' argumentz!Invalid kwargs passed to user.addr	r'Zuseradd�-u�-g�-GN�-dT�-m�-L�-sz-orr)�-n�cmd.retcoder+rr)rr�argsZclean_kwargsr�is_true�pop�log�warningr,r-r�extend�joinrr&r0)r!�uid�gid�groups�home�shell�uniquerrrrZ
createhome�
loginclass�kwargsr5r"rrr�add}sD





��rQcCsPtjj�|�rt�d�ddg}|r|�d�|�d|g�td|dd�d	kS)
z�
    Remove a user from the minion

    CLI Example:

    .. code-block:: bash

        salt '*' user.delete name remove=True force=True
    zGpw userdel does not support force-deleting user while user is logged inr'Zuserdelz-rr@rAFr+r)	rrrrCrE�errorrrGr0)r!�remove�forcer5rrr�delete�s
�
rUcCsBdtvr
|s
tdSg}t��D]
}|�t|j��q|td<|S)z}
    Return the list of all info for all users

    CLI Example:

    .. code-block:: bash

        salt '*' user.getent
    zuser.getent)�__context__r�getpwallrr1�pw_name)Zrefresh�retrrrr�getent�s
rZcC�^t|�}|std|�d���||dkrdSddd|d|g}td	|d
d�t|��d�|kS)z{
    Change the uid for a named user

    CLI Example:

    .. code-block:: bash

        salt '*' user.chuid foo 4376
    rrrITr'r(r9r@r*Fr+�r1rr0r%)r!rIr4r5rrr�chuid��
r]cCr[)z�
    Change the default group of the user

    CLI Example:

    .. code-block:: bash

        salt '*' user.chgid foo 4376
    rrrJTr'r(r:r@r*Fr+r\)r!rJr4r5rrr�chgid�r^r_cCr[)z�
    Change the default shell of the user

    CLI Example:

    .. code-block:: bash

        salt '*' user.chshell foo /bin/zsh
    rrrMTr'r(r?r@r*Fr+r\)r!rMr4r5rrr�chshell
r^r`cCsjt|�}|std|�d���||dkrdSdd|d|g}|r$|�d�td	|d
d�t|��d�|kS)a�
    Set a new home directory for an existing user

    name
        Username to modify

    home
        New home directory to set

    persist : False
        Set to ``True`` to prevent configuration files in the new home
        directory from being overwritten by the files from the skeleton
        directory.

    CLI Example:

    .. code-block:: bash

        salt '*' user.chhome foo /home/users/foo True
    rrrLTr'r(r<r=r*Fr+)r1rrr0r%)r!rLZpersistr4r5rrr�chhome!s
racCsft|t�r
|�d�}tt|��}|t|�krdS|r||7}dddd�|�d|g}td|dd	�d
kS)a�
    Change the groups to which a user belongs

    name
        Username to modify

    groups
        List of groups to set for the user. Can be passed as a comma-separated
        list or a Python list.

    append : False
        Set to ``True`` to append these groups to the user's existing list of
        groups. Otherwise, the specified groups will replace any existing
        groups for the user.

    CLI Example:

    .. code-block:: bash

        salt '*' user.chgroups foo wheel,root True
    r	Tr'r(r;r@rAFr+r)r,r-r�set�list_groupsrHr0)r!rKrZugrpsr5rrr�chgroupsBs

rdcC�t|d|�S)z�
    Change the user's Full Name

    CLI Example:

    .. code-block:: bash

        salt '*' user.chfullname foo "Foo Bar"
    r�r7)r!rrrr�
chfullnamec�
rgcCre)z
    Change the user's Room Number

    CLI Example:

    .. code-block:: bash

        salt '*' user.chroomnumber foo 123
    rrf)r!rrrr�chroomnumberprhricCre)z�
    Change the user's Work Phone

    CLI Example:

    .. code-block:: bash

        salt '*' user.chworkphone foo "7735550123"
    rrf)r!rrrr�chworkphone}rhrjcCre)z�
    Change the user's Home Phone

    CLI Example:

    .. code-block:: bash

        salt '*' user.chhomephone foo "7735551234"
    rrf)r!rrrr�chhomephone�rhrkcCs@|t|�krdSddd|�d|�g}td|dd�t|�|kS)	z�
    Change the default login class of the user

    .. versionadded:: 2016.3.5

    CLI Example:

    .. code-block:: bash

        salt '*' user.chloginclass foo staff
    Tr'r(r>r@r*Fr+)�get_loginclassr0)r!rO�rootr5rrr�chloginclass�s
rncCs�i}z\t�|�}|j|d<t|�|d<|j|d<|j|d<|j|d<|j|d<|j|d<|j	�
dd	�}t|�d
krD|�d�t|�d
ks9|d|d
<|d|d<|d|d<|d	|d<W|St
yiiYSw)zn
    Return user information

    CLI Example:

    .. code-block:: bash

        salt '*' user.info root
    rJrKrLr!�passwdrMrIr	r
r
rrrrrrrr)rr�pw_gidrc�pw_dirrX�	pw_passwd�pw_shell�pw_uidrrrrr)r!rYrr"rrrr1�s,








���r1cCs6tdddd|g�}|�d�}t|�dkr|dSdS)	z�
    Get the login class of the user

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' user.get_loginclass foo

    zcmd.run_stdoutr'Zusershowr@�:�
r
r)r0rr)r!�userinforrrrl�s
rlcCstjj�|�S)z�
    Return a list of groups the named user belongs to

    CLI Example:

    .. code-block:: bash

        salt '*' user.list_groups foo
    )rrrZget_group_list)r!rrrrc�s
rccCstdd�t��D��S)zr
    Return a list of all users

    CLI Example:

    .. code-block:: bash

        salt '*' user.list_users
    css�|]}|jVqdS�N)rX)�.0rrrr�	<genexpr>�s�zlist_users.<locals>.<genexpr>)�sortedrrWrrrr�
list_users�s
r|cCs|t|�}|std|�d���t|�}|rtd|�d���ddd|d|g}td|�t|�}|d	|d	kr<|d	|kSd
S)z�
    Change the username for a named user

    CLI Example:

    .. code-block:: bash

        salt '*' user.rename name new_name
    rrz' already existsr'r(z-lr@r*r!F)r1rr0)r!�new_nameZcurrent_infoZnew_infor5r6rrr�rename�s
r~)NNNNNTrrrrTN)FF)Frx)&�__doc__r.�loggingZsalt.utils.argsrZsalt.utils.dataZsalt.utils.userZsalt.exceptionsrrr�ImportError�	getLogger�__name__rErrr#r&r7rQrUrZr]r_r`rardrgrirjrkrnr1rlrcr|r~rrrr�<module>sb#�



�
?


!!



"