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/states/__pycache__/user.cpython-310.pyc
o

�N�g��@sdZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
e�e�Z
ddd�Z																							
								ddd�Z																																			dd
d�Zddd�ZdS)a�
Management of user accounts.
============================

The user module is used to create and manage user settings, users can be set
as either absent or present

.. code-block:: yaml

    fred:
      user.present:
        - fullname: Fred Jones
        - shell: /bin/zsh
        - home: /home/fred
        - uid: 4000
        - gid: 4000
        - groups:
          - wheel
          - storage
          - games

    testuser:
      user.absent
�N)�CommandExecutionErrorFc	Cs�t|�}t|�}||ks|s|�|�rdSdd�|�|�D�}|r'|�|�}n|�|�}t|�}|D]}|��D]\}}||krAq8||d|dkrP|�|�q8q2t|�S)z4
    Determine if the groups need to be changed
    FcSsi|]	}|td|��qS�z
group.info��__salt__)�.0�name�r�D/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/user.py�
<dictcomp>1sz"_group_changes.<locals>.<dictcomp>�gid)	�set�issubset�union�symmetric_difference�
difference�list�items�remove�bool)	ZcurZwantedrZall_grps�diffZremainZdiff_grp�grp�inforrr	�_group_changes's$

��rT��?B�c.Cs�dtvr
td|�}td|�} | sdSi}!tt|pg|pg��}"dd�| dD�}#i}$t|#�D]\}%}&|#�|&�dkrO|&|$vrDg|$|&<|$|&�| d|%�q1|rX|durb|sbtt|"| d��}"|rn| d	|krn||!d	<|dur�| d
|td|�fvr�||!d
<td|dur�|n| d
�}'td| d
�}(|'| dvs�|'|"vr�|'tjj�	|$�
��vr�td|'�})|$|)D]}*|*| dvr�| d�|*�|*|"vr�|"�|*�q�n|'| dvr�| d�|'�|'|"vr�|"�|'�|(|'k�r|(| dv�r|(tjj�	|$�
��v�rtd|(�})|$|)D]
}*| d�|*��q	n| d�|(�|| dv�rQ||"v�rQ|tjj�	|$�
��v�rJtd|�})|$|)D]
}*| d�|*��q>n| d�|�t| d|"|��rd|"�s`|�rd|"|!d<|�rr| d
|k�rr||!d
<|�r�|�rz|n| d
}+|+du�r�t
j�|+��s�|+|!d<|�r�| d|k�r�||!d<dtv�rVdtv�rV|�r�|
�s�td�},|d|,k�s�|d|,k�r�|	�r�|d|k�r�||!d<|
�r�|ddk�r�d|!d<|du�r�|d|k�r�||!d<|du�r�|d|k�r�||!d<|du�r|d|k�r||!d<|du�r|d|k�r||!d<|du�r+|d|k�r+||!d<|�r9|d|k�r9||!d<|�rD|d�d ��rQ|du�rU|d�d ��rU||!d!<n7dtv�r�tjj���r�|�r|d"k�rtjj�|d�tjj�|�k�r||!d<|du�r�| d#�r�||!d!<tjj�|�}tjj�| d$�| d$<|du�r�| d$|k�r�||!d$<|�r�| d%|k�r�||!d&<|�r�| d'|k�r�||!d(<|�r�| d)|k�r�||!d*<|�r�| d+|k�r�||!d,<d-tv�r|
du�rtjj�|
�}
tjj�| d.�| d.<| d.|
k�r|
|!d.<d/tv�r5|du�r5tjj�|�}tjj�| d0�| d0<| d0|k�r5||!d0<d1tv�r\|du�r\tjj�|�}tjj�| d2�| d2<| d2|k�r\||!d2<d3tv�r�|du�r�tjj�|�}tjj�| d4�| d4<| d4|k�r�||!d4<td5d6v�r�|�r�td7|�|k�r�||!d8<g}-|�s�d	|!v�r�|-�d9�| d	|��|�s�d
|!v�r�|-�d:�| d
|��|-�r�td;|-d<��|!S)=aU
    Return a dict of the changes required for a user if the user is present,
    otherwise return False.

    Updated in 2015.8.0 to include support for windows homedrive, profile,
    logonscript, and description fields.

    Updated in 2014.7.0 to include support for shadow attributes, all
    attributes supported as integers only.
    �shadow.info�	user.infoFcSsg|]}td|��qS)�file.group_to_gidr)r�gnamerrr	�
<listcomp>ys�z_changes.<locals>.<listcomp>�groups�N�uidrrzfile.gid_to_group�home�homeDoesNotExist�shellzshadow.default_hash�passwdrT�empty_password�lstchg�date�min�mindays�max�maxdays�inact�	inactdays�warn�warndays�expire�!�
password_lock���Zaccount_locked�fullname�	homedrive�
win_homedrive�profile�win_profile�logonscript�win_logonscript�description�win_descriptionzuser.chroomnumber�
roomnumberzuser.chworkphone�	workphonezuser.chhomephone�	homephonezuser.chother�other�kernel�ZOpenBSDZFreeBSD�user.get_loginclass�
loginclassz�Changing uid ({} -> {}) not permitted, set allow_uid_change to True to force this change. Note that this will not change file ownership.z�Changing gid ({} -> {}) not permitted, set allow_gid_change to True to force this change. Note that this will not change file ownership.z-Encountered error checking for needed changes)r)r�sortedr�	enumerate�count�append�salt�utils�data�flatten�valuesrr�os�path�isdir�
startswith�platform�
is_windows�	dateutils�strftime�decode�
__grains__�formatr).rr#rr!�optional_groups�
remove_groupsr$�
createhome�password�enforce_passwordr(r&r7r@rArBrCrGr*r,r.r0r2r3r9r;r=r?�allow_uid_change�allow_gid_changer5�lshad�lusrZchangeZ
wanted_groupsZlusr_groups_gidsZdupe_groups�idxZ_gidZdefault_grpZold_default_grpZdupe_gidrZnewhomeZdefault_hash�errorsrrr	�_changesDs2,�� 
��
��
���
����rgc$>sD
|	rU|
rUt�d�ddddd�}$z0td|�d�d	d
�\}%}&}'}(|&dkr*t�d�t�d
|$�|&��td|	|'|$�|&�d�}	WntyTt�d�td|	�}	Ynw|durbtj	j
�t|��}|durotj	j
�t|��}|dur|tj	j
�t|��}|dur�tj	j
�t|��}|dur�tj	j
�t|��}t
ddkr�d}|idd|�d�d�})|||fD]}*t|*t�r�d|*vr�d|*��|)d<d|)d<|)Sq�|r�dd�|D�}+|+r�d�d�|+��|)d<d|)d<|)S|�rd d�|D���fd!d�|D�D]	},t�d"|,|�q�nd�|�r|�rt|��|�D]
}-t�d#|-|��q|�r+td$|�d%k�r+|}.n|}.z't|||.|�||||	|||
|||||||||||||||||!|"fd&|#i�}/Wnt�yr}0zd|)d<|0j|)d<|)WYd}0~0Sd}0~0ww|/�rtd'�r�d|)d<d(|)d<|/��D]%\}1}2|1dk�r�d)}2n
|1d*k�r�|�s�d+}1|)d|1�d,|2�d-�7<�q�|)Sdtv�r�td|�}3t
dd.v�r�td/|�}4td0|�}5d|/v�r�|/d=|�s�td1||	�nt�d2�|/�d3d�du�r�td4|�d&|/v�r/|/�d&�}6|6�stj	j���rtd5|�n |6�std6|�n|6�r*tj	j���s*td7|�nt�d8�d9|/v�r>|/d9=td:||�d;d<�}7d}8d=|/v�rZ|/�d=�}2d>|/v�rZ|7||2�d}8d>|/v�r�|/�d>�}2|8�sl|7||2�tj�|2��s�td?|2|5d@|5dAdB�dC|/v�r�|/dC=tdD||�dE|/v�r�|/dE=tdF||�dG|/v�r�|/dG=tdH||�dI|/v�r�|/dI=tdJ||�dK|/v�r�|/dK=tdL||�dM|/v�r�tdN||/�dM�dO�dP|/v�r�tdN||/�dP�dQ�dR|/v�r�tdN||/�dR�dS�dT|/v�rtdN||/�dT�dU�dVd�t|/�D�D]}1tdW|1��||/�|1���qdX|/v�r6tdY||/�dX�|�|/�rH|)�dZg��d[�d\�|/���td0|�}9i}:dtv�rb|3d|	k�rbtd|�}:t
dd.v�rotd/|�};|9D]}1|9|1|5|1k�r�|9|1|)d]|1<�qqdtv�r�|:D]!}1|3|1|:|1k�r�|1dk�r�d)|)d]|1<�q�|:|1|)d]|1<�q�t
dd.v�r�|;|4k�r�|;|)d]d^<|)d]�r�d_|��|)d<t||||�||||	|||
||||||||||||||||fdd|#d`��}/|/�rda|/��|)d<d|)d<|)S|/du�r�td'�rd|)d<d|�db�|)d<|)S|�r&��r&|� ��n	��r/�dd�}tj	j���slidc|�d@|�dA|�dX|�d=|�dd|
�de|�df|�dg|�dh|�di|�dj|�dk|�dl|�dm| �d^|�dn|�}<n||	|||||||do�	}<tdpd�i|<��}=|=du�r�dq|�dr�|)d<td0|�|)d]<|�s�d%|)d]d=<dtv�rtj	j���stj	j�!��s|	�r�|�s�td1||	�td|�}:|:d|	k�r�ds�|d)�|)d<d|)d<d)|)d]dt<|�r	|	�s	td4|�td|�}:|:dd%k�rd|�du�|)d<d|)d<d%|)d]dt<|du�r4td:||�td|�}:|:dv|k�r.dw�||�|)d<d|)d<||)d]d9<|�r]tdD||�td|�}:|:dx|k�rWdy�||�|)d<d|)d<||)d]dC<|�r�tdF||�td|�}:|:dz|k�r�d{�||�|)d<d|)d<||)d]dE<|�r�tdH||�td|�}:|:d||k�r�d}�||�|)d<d|)d<||)d]dG<|�r�tdJ||�td|�}:|:d~|k�r�d�||�|)d<d|)d<||)d]dI<|�rtdL||�td|�}:|:dK|k�r�d��||�|)d<d|)d<||)d]dK<|)Stj	j���ra|	�r*|�s*td�||	��s$ds�|d)�|)d<d|)d<d)|)d]d<|�r_tdL||�td|�}:tj	j"�#|:dK�tj	j"�#|�k�rWd��||�|)d<d|)d<|:dK|)d]d�<|)Stj	j�!��r�|	�r�|�s�td1||	��s�ds�|d)�|)d<d|)d<d)|)d]d<|)St|=t��r�|=|)d<nd�|��|)d<d|)d<|)S)�a$
    Ensure that the named user is present with the specified properties

    name
        The name of the user to manage

    uid
        The user id to assign. If not specified, and the user does not exist,
        then the next available uid will be assigned.

    gid
        The id of the default group to assign to the user. Either a group name
        or gid can be used. If not specified, and the user does not exist, then
        the next available gid will be assigned.

    allow_uid_change : False
        Set to ``True`` to allow the state to update the uid.

        .. versionadded:: 2018.3.1

    allow_gid_change : False
        Set to ``True`` to allow the state to update the gid.

        .. versionadded:: 2018.3.1

    usergroup
        If True, a group with the same name as the user will be created. If
        False, a group with the same name as the user will not be created. The
        default is distribution-specific. See the USERGROUPS_ENAB section of
        the login.defs(5) man page.

        .. note::
            Only supported on GNU/Linux distributions

        .. versionadded:: 3001

    groups
        A list of groups to assign the user to, pass a list object. If a group
        specified here does not exist on the minion, the state will fail.
        If set to the empty list, the user will be removed from all groups
        except the default group. If unset, salt will assume current groups
        are still wanted, and will make no changes to them.

    optional_groups
        A list of groups to assign the user to, pass a list object. If a group
        specified here does not exist on the minion, the state will silently
        ignore it.

    NOTE: If the same group is specified in both "groups" and
    "optional_groups", then it will be assumed to be required and not optional.

    remove_groups
        Remove groups that the user is a member of that weren't specified in
        the state, Default is ``True``.

    home
        The custom login directory of user. Uses default value of underlying
        system if not set. Notice that this directory does not have to exist.
        This also the location of the home directory to create if createhome is
        set to True.

    createhome : True
        If set to ``False``, the home directory will not be created if it
        doesn't already exist.

        .. warning::
            Not supported on Windows or Mac OS.

            Additionally, parent directories will *not* be created. The parent
            directory for ``home`` must already exist.

    nologinit : False
        If set to ``True``, it will not add the user to lastlog and faillog
        databases.

        .. note::
            Not supported on Windows.

    password
        A password hash to set for the user. This field is only supported on
        Linux, FreeBSD, NetBSD, OpenBSD, and Solaris. If the ``empty_password``
        argument is set to ``True`` then ``password`` is ignored.
        For Windows this is the plain text password.
        For Linux, the hash can be generated with ``mkpasswd -m sha-256``.

    .. versionchanged:: 0.16.0
       BSD support added.

    hash_password
        Set to True to hash the clear text password. Default is ``False``.


    enforce_password
        Set to False to keep the password from being changed if it has already
        been set and the password hash differs from what is specified in the
        "password" field. This option will be ignored if "password" is not
        specified, Default is ``True``.

    empty_password
        Set to True to enable password-less login for user, Default is ``False``.

    password_lock
        Set to ``False`` to unlock a user's password (or Windows account). On
        non-Windows systems ONLY, this parameter can be set to ``True`` to lock
        a user's password. Default is ``None``, which does not take action on
        the password (or Windows account).

        .. versionadded:: 3006.0

    shell
        The login shell, defaults to the system default shell

    unique
        Require a unique UID, Default is ``True``.

    system
        Choose UID in the range of FIRST_SYSTEM_UID and LAST_SYSTEM_UID, Default is
        ``False``.

    loginclass
        The login class, defaults to empty
        (BSD only)

    User comment field (GECOS) support (currently Linux, BSD, and MacOS
    only):

    The below values should be specified as strings to avoid ambiguities when
    the values are loaded. (Especially the phone and room number fields which
    are likely to contain numeric data)

    fullname
        The user's full name

    roomnumber
        The user's room number (not supported in MacOS)

    workphone
        The user's work phone number (not supported in MacOS)

    homephone
        The user's home phone number (not supported in MacOS)

    other
        The user's other attribute (not supported in MacOS)
        If GECOS field contains more than 4 commas, this field will have the rest of 'em

    .. versionchanged:: 2014.7.0
       Shadow attribute support added.

    Shadow attributes support (currently Linux only):

    The below values should be specified as integers.

    date
        Date of last change of password, represented in days since epoch
        (January 1, 1970).

    mindays
        The minimum number of days between password changes.

    maxdays
        The maximum number of days between password changes.

    inactdays
        The number of days after a password expires before an account is
        locked.

    warndays
        Number of days prior to maxdays to warn users.

    expire
        Date that account expires, represented in days since epoch (January 1,
        1970).

    The below parameters apply to windows only:

    win_homedrive (Windows Only)
        The drive letter to use for the home directory. If not specified the
        home directory will be a unc path. Otherwise the home directory will be
        mapped to the specified drive. Must be a letter followed by a colon.
        Because of the colon, the value must be surrounded by single quotes. ie:
        ``- win_homedrive: 'U:'``

        .. versionchanged:: 2015.8.0

    win_profile (Windows Only)
        The custom profile directory of the user. Uses default value of
        underlying system if not set.

        .. versionchanged:: 2015.8.0

    win_logonscript (Windows Only)
        The full path to the logon script to run when the user logs in.

        .. versionchanged:: 2015.8.0

    win_description (Windows Only)
        A brief description of the purpose of the users account.

        .. versionchanged:: 2015.8.0
    zHashing a clear text password�md5Zblowfish�sha256�sha512)�1Z2a�5�6rr'�$�rkz7Using MD5 for hashing passwords is considered insecure!z;Re-using existing shadow salt for hashing password using %szshadow.gen_password)Z
crypt_salt�	algorithmzINo existing shadow salt found, defaulting to a randomly generated new oneNrD�WindowsFT�User z is present and up to date�r�changes�result�comment�,zUnsupported char ',' in rvrucSsg|]
}td|�s|�qSrr�r�xrrr	r P�zpresent.<locals>.<listcomp>z*The following group(s) are not present: {}cSsg|]
}td|�r|�qSrrrxrrr	r Yrzcsg|]}|�vr|�qSrrrx�Zpresent_optgroupsrr	r Zsz0Optional group "%s" for user "%s" is not presentzCGroup "%s" specified in both groups and optional_groups for user %srrr5�testz5The following user attributes are set to be changed:
zXXX-REDACTED-XXX�groupz
ensure groupsz: �
rErFrzshadow.set_passwordz0No password will be set when empty_password=Truer(zshadow.del_passwordzshadow.unlock_accountzshadow.unlock_passwordzshadow.lock_passwordz,Account locking is not available on Windows.r*zshadow.set_datecSs4tddvrtd||�dStd||dd�dS)NrD)�Darwinrqzuser.chhomeF)Zpersist)rZr)r�valrrr	�_change_homedir�sz present.<locals>._change_homedirr$r%z
file.mkdirr#ri�r,zshadow.set_mindaysr.zshadow.set_maxdaysr0zshadow.set_inactdaysr2zshadow.set_warndaysr3zshadow.set_expirer9zuser.update)rr8r;)rr:r=)rr<r?)rr>cSs&g|]}|dkrd|��tvr|�qS)r!�user.chrrxrrr	r s r�r!z
user.chgroups�warningszUnhandled changes: {}z, rtrGz
Updated user )rarbr5z#These values could not be changed: z set to be addedrr&�unique�systemr7r@rArBrCr^�	nologinit�	usergroup)	rr_r7r>r!r$r8r:r<zuser.addz	New user z createdz0User {} created but failed to set password to {}r_z% created but failed to empty passwordr)z8User {} created but failed to set last change date to {}r+z4User {} created but failed to set minimum days to {}r-z4User {} created but failed to set maximum days to {}r/z5User {} created but failed to set inactive days to {}r1z1User {} created but failed to set warn days to {}z3User {} created but failed to set expire days to {}zuser.setpasswordZexpiration_datezFailed to create new user r)$�log�debugr�split�warning�get�
ValueErrorrrLrMrNrY�strrZ�
isinstancer[�joinr�intersectionrgr�strerror�__opts__r�poprUrVrQrRrSrrK�extendZ	is_darwinrWrX)>rr#rr�r!r\r]r$r^r_Z
hash_passwordr`r(r&r�r�r7r@rArBrCrGr*r,r.r0r2r3r9r;r=r?r�rarbr5Z
algorithms�_ZalgoZshadow_saltZshadow_hash�retZgecos_fieldZmissing_groupsZmissing_optgroupZisectedZchanges_gidrt�exc�keyr�rcZlcpreZpreZpasslockr�Z_homedir_changedZpostZspostZlcpost�paramsrurr{r	�presentsxr
�
�
�
�
���
�	��

���	�	�
�!
��

 






















�

�	
�
��

�
��&

��������	�
���
������


�
���
�
�������)���������	�
r�cCs�|iddd�}td|�}|rotdr!d|d<d|�d	�|d
<|Sttjj�|��}td|||�|d<dd
�|D�}|drbi|d<||D]}d|d|�d�<qGd|d|<d|��|d
<|Sd|d<d|��|d
<|Sd|�d�|d
<|S)a�
    Ensure that the named user is absent

    name
        The name of the user to remove

    purge
        Set purge to True to delete all of the user's files as well as the user,
        Default is ``False``.

    force
        If the user is logged in, the absent state will fail. Set the force
        option to True to remove the user even if they are logged in. Not
        supported in FreeBSD and Solaris, Default is ``False``.
    Trrsrr|Nrurrz set for removalrvzuser.deletecSsh|]
}td|�r|�qSrr)r�grrr	�	<setcomp>+rzzabsent.<locals>.<setcomp>rtZremovedz groupz
Removed user FzFailed to remove user z is not present)rr�rrLrM�userZget_group_list)r�purge�forcer�rdZbeforegroupsZaftergroupsr�rrr	�absents,�r�)F)NNNNTNTNTFNrrrrrNNrrrrNNNNNFFN)#NNNNNTNTNFTFNTFNNNNNNNNNNNNNNNNFFFN)FF)�__doc__�loggingrQZsalt.utils.datarLZsalt.utils.dateutilsZsalt.utils.platformZsalt.utils.userZsalt.utils.versionsZsalt.exceptionsr�	getLogger�__name__r�rrgr�r�rrrr	�<module>s�


�^
�v