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

�N�gA�@sfdZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
mZmZzddl
Z
Wn	ey9Ynwe�e�ZdZdd�Zdd�Zd7d
d�Zdd
�Z							d8dd�Zd9dd�Zd:dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd:d d!�Zd"d#�Z d$d%�Z!ej"j#j$�%d&�d'd(��Z&d)d*�Z'd+d,�Z(d-d.�Z)d/d0�Z*d1d2�Z+d3d4�Z,d5d6�Z-dS);a
Manage users on Mac OS 10.7+

.. 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)�CommandExecutionError�SaltInvocationError�usercCs"t�d�dks
tddkrdStS)NZkernel�Darwin�osrelease_info)�
�)Fz&Only available on Mac OS 10.7+ systems)�
__grains__�get�__virtualname__�rr�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/mac_user.py�__virtual__"srcCstdddgdd�dS)z
    Flush dscl cache
    �cmd.runZdscacheutilz-flushcacheF)�python_shellN��__salt__rrrr
�_flush_dscl_cache)sr�createcCsdtddkrd\}}nd\}}|r||d|d<tdd|d|g||d	kr-d
dd
�Sddd
�S)z$
    Run a dscl -create command
    r)r�)�.�)Z	localhostz/Local/Defaultr�cmd.run_allZdscl�-�passwd�quiet�debugF)Zoutput_loglevelr)r	r)�cmd�ctype�sourceZnoderootrrr
�_dscl0s

��r cCs6dd�t��D�}tdd�D]
}||vr|SqdS)NcSsh|]}|j�qSr)�pw_uid��.0�xrrr
�	<setcomp>Csz#_first_avail_uid.<locals>.<setcomp>i�i)�pwd�getpwall�range)Zuids�idxrrr
�_first_avail_uidBs��r*Tc
Kst|�rtd|�d���tjj�|�rtd��|durt�}|dur$d}|dur-d|��}|dur3d}|dur9d}t|t	�sBtd	��t|t	�sKtd
��d|��}	t
|	d|g�t
|	d|g�t
|	d
|g�t
|	d|g�t
|	d|g�|r~td|||d�t�
d�|r�t||�dS)z�
    Add a user to the minion

    CLI Example:

    .. code-block:: bash

        salt '*' user.add name <uid> <gid> <groups> <home> <shell>
    �User '�' already exists�"Username cannot contain whitespaceN��/Users/z	/bin/bashr�uid must be an integer�gid must be an integer�UniqueID�PrimaryGroupID�	UserShell�NFSHomeDirectory�RealNamez
file.mkdir)r�group�T)�infor�salt�utils�stringutils�contains_whitespacerr*�
isinstance�intr r�time�sleep�chgroups)
�name�uid�gid�groups�home�shell�fullnameZ
createhome�kwargsZ	name_pathrrr
�addIs<





rKFcCsvtjj�|�rtd��t|�}|sdS|rt�d�t|d�t	d|��gdd�dd	k}|r9|r9t
d
|d�|S)z�
    Remove a user from the minion

    CLI Example:

    .. code-block:: bash

        salt '*' user.delete name remove=True force=True
    r-Tz.force option is unsupported on MacOS, ignoringrr/�delete�r�retcoderzfile.removerG)r:r;r<r=rr9�log�warningrBr r)rC�remove�forceZ	user_info�retrrr
rL�s


rLcCs@dtvr
|s
tdSg}t��D]	}|�t|��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&r'�append�_format_info)ZrefreshrS�datarrr
�getent�s
rXcC�xt|t�s	td��t|�}|std|�d���||dkrdStd|��d|d|gdd	�t�d
�t|��d�|kS)z{
    Change the uid for a named user

    CLI Example:

    .. code-block:: bash

        salt '*' user.chuid foo 4376
    r0r+�' does not existrDTr/r2�changerMr8�	r>r?rr9rr r@rAr
)rCrD�pre_inforrr
�chuid�s


r^cCrY)z�
    Change the default group of the user

    CLI Example:

    .. code-block:: bash

        salt '*' user.chgid foo 4376
    r1r+rZrETr/r3r[rMr8r\)rCrEr]rrr
�chgid�s

�
r_cCsft|�}|std|�d���||dkrdStd|��d|d|gdd�t�d	�t|��d�|kS)
z�
    Change the default shell of the user

    CLI Example:

    .. code-block:: bash

        salt '*' user.chshell foo /bin/zsh
    r+rZrHTr/r4r[rMr8�r9rr r@rAr
)rCrHr]rrr
�chshell�s
�
racKs�tjjjdi|��}|�dd�}|rtjj�|�|r t�d�t|�}|s.td|�d���||dkr6dSt	d|��d	|d|gd
d�t
�d�t|��d�|kS)z�
    Change the home directory of the user

    CLI Example:

    .. code-block:: bash

        salt '*' user.chhome foo /Users/foo
    �persistFz6Ignoring unsupported 'persist' argument to user.chhomer+rZrGTr/r5r[rMr8Nr)
r:r;�argsZclean_kwargs�popZinvalid_kwargsrOr9rr r@rAr
)rCrGrJrbr]rrr
�chhomes"

�
recCs�tjj�|�}t|�}|std|�d���tjj�|d�|d<||dkr(dStd|��d|gdd�t�d	�tjj�t|��	d��}||kS)
z�
    Change the user's Full Name

    CLI Example:

    .. code-block:: bash

        salt '*' user.chfullname foo 'Foo Bar'
    r+rZrITr/r6rrMr8)
r:r;rW�decoder9rr r@rAr
)rCrIr]�currentrrr
�
chfullname%s
�
	rhc	Cst|�}|std|�d���t|t�r|�d�}dd�|D�}|r+td�d�|����tt	|��}dd	�|D�}t
d
|d�}|rG|�|�||krMdS||D]}td
|��d|gdd�qQ|su||D]}td
|��d|gdd�qft
�d�tt	|��|kS)aW
    Change the groups to which the user belongs. Note that the user's primary
    group does not have to be one of the groups passed, membership in the
    user's primary group is automatically assumed.

    groups
        Groups to which the user should belong, can be passed either as a
        python list or a comma-separated string

    append
        Instead of removing user from groups not included in the ``groups``
        parameter, just add user to any groups for which they are not members

    CLI Example:

    .. code-block:: bash

        salt '*' user.chgroups foo wheel,root
    r+rZ�,cSsg|]}tjj�|�r|�qSr)r:r;r<r=r"rrr
�
<listcomp>aszchgroups.<locals>.<listcomp>zInvalid group name(s): {}z, cSs h|]}tt|��rt|��qSr)�bool�strr"rrr
r%gs zchgroups.<locals>.<setcomp>zfile.gid_to_grouprETz/Groups/ZGroupMembershiprUrMrLr8)r9rr>rl�splitr�format�join�set�list_groupsrrKr r@rA)	rCrFrUZuinfoZ
bad_groupsZugrpsZdesired�
primary_groupr7rrr
rBEs0

�

rBcs@ztt�fdd�t��D���}Wt|�StyiYSw)zn
    Return user information

    CLI Example:

    .. code-block:: bash

        salt '*' user.info root
    c3s�|]
}|j�kr|VqdS)N)�pw_namer"�rCrr
�	<genexpr>�s�zinfo.<locals>.<genexpr>)�next�iterr&r'�
StopIterationrV)rCrWrrtr
r9xs
 ��r9cCs&|jt|j�|j|j|j|j|jd�S)z1
    Return user information in a pretty way
    )rErFrGrCrHrDrI)�pw_gidrqrs�pw_dir�pw_shellr!�pw_gecos)rWrrr
rV�s�rV�idcCstdddd|g�S)z�
    Return the primary group of the named user

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' user.primary_group saltadmin
    rr}z-gz-nrrtrrr
rr�s
rrcCsdd�tjj�|�D�}|S)a{
    Return a list of groups the named user belongs to.

    name

        The name of the user for which to list groups. Starting in Salt 2016.11.0,
        all groups for the user, including groups beginning with an underscore
        will be listed.

        .. versionchanged:: 2016.11.0

    CLI Example:

    .. code-block:: bash

        salt '*' user.list_groups foo
    cSsg|]}|�qSrr)r#r7rrr
rj�szlist_groups.<locals>.<listcomp>)r:r;rZget_group_list)rCrFrrr
rq�srqcCstdgd�d}|��S)zr
    Return a list of all users

    CLI Example:

    .. code-block:: bash

        salt '*' user.list_users
    z/users�list�stdout)r rm)Zusersrrr
�
list_users�s
r�cCsnt|�}|std|�d���t|�}|rtd|�d���td|��d||gdd�t�d�t|��d�|kS)	z�
    Change the username for a named user

    CLI Example:

    .. code-block:: bash

        salt '*' user.rename name new_name
    r+rZr,r/Z
RecordNamer[rMr8r`)rC�new_nameZcurrent_infoZnew_inforrr
�rename�s

r�cCs,gd�}td|dd�}|drdS|dS)a
    .. versionadded:: 2016.3.0

    Gets the current setting for Auto Login

    :return: If enabled, returns the user name, otherwise returns False
    :rtype: str, bool

    CLI Example:

    .. code-block:: bash

        salt '*' user.get_auto_login
    )�defaults�read�0/Library/Preferences/com.apple.loginwindow.plist�
autoLoginUserrT)Zignore_retcoderNFrr)rrSrrr
�get_auto_login�sr�cCs�gd�}t|�d}ttt|��dg}t|�|}|dkr'|dg||}tdt|�t|��D]#}d}t|t|t|�t|���D]}||||A||<|d7}qCq1t|�S)a�
    Internal function for obfuscating the password used for AutoLogin
    This is later written as the contents of the ``/etc/kcpassword`` file

    .. versionadded:: 2017.7.3

    Adapted from:
    https://github.com/timsutton/osx-vm-templates/blob/master/scripts/support/set_kcpassword.py

    Args:

        password(str):
            The password to obfuscate

    Returns:
        str: The obfuscated password
    )�}��R�#����������r8r)�lenr~�map�ordr(�min�bytes)�password�keyZkey_len�	remainderZchunk_indexZ	key_indexZpassword_indexrrr
�_kcpassword�s�
�r�c	Cs�dddd|g}td|�t�}t|d�}tjj�d��%tjj�dd	��
}|�|�Wd
�n1s5wYWd
�n1sDwYt	|t
�rP|S|��|��kS)a�
    .. versionadded:: 2016.3.0

    Configures the machine to auto login with the specified user

    Args:

        name (str): The user account use for auto login

        password (str): The password to user for auto login

            .. versionadded:: 2017.7.3

    Returns:
        bool: ``True`` if successful, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt '*' user.enable_auto_login stevej
    r��writer�r�r)r��?z/etc/kcpassword�wbN)rr�r�r:r;�filesZ	set_umaskZfopenr�r>rk�lower)rCr�rrgZ
o_password�fdrrr
�enable_auto_login1s �
���r�cCs2d}td|�gd�}td|�t�sdSdS)z�
    .. versionadded:: 2016.3.0

    Disables auto login on the machine

    Returns:
        bool: ``True`` if successful, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt '*' user.disable_auto_login
    zrm -f /etc/kcpasswordr)r�rLr�r�TF)rr�)rrrr
�disable_auto_login\s
r�)r)NNNNNNT)FF)F).�__doc__�loggingr@Zsalt.utils.argsr:Zsalt.utils.dataZsalt.utils.decorators.pathZsalt.utils.filesZsalt.utils.stringutilsZsalt.utils.userZsalt.exceptionsrrr&�ImportError�	getLogger�__name__rOrrrr r*rKrLrXr^r_rarerhrBr9rVr;Z
decorators�path�whichrrrqr�r�r�r�r�r�rrrr
�<module>s`
�

	
�
<
  
 3
2+