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

�N�gZ/�@sbdZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
mZddlm
Z
zddlZdZWneyAdZYnwzddlZdZWneyUdZYnwzddlZdZWneyidZYnwe�e�Zdd�Ze
d	�d!d
d	��Zdd�Zd
d�Zdd�Zd!dd�Zd!dd�Zdd�Zd"dd�Z d#dd�Z!d"dd�Z"d!dd�Z#d!dd �Z$dS)$zY
Functions for querying and modifying a user account and the groups to which it
belongs.
�N)�CommandExecutionError)�jinja_filterTFcCsHtrt�t���j}ntrtjj	j
rtjj	��}ntd��tjj
�|�S)z
    Get the current user
    z9Required external library (pwd or win32api) not installed)�HAS_PWD�pwd�getpwuid�os�geteuid�pw_name�HAS_WIN_FUNCTIONS�salt�utilsZ
win_functionsZ	HAS_WIN32Zget_current_userr�stringutils�
to_unicode)�ret�r�C/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/user.py�get_user+s�r�get_uidcC�TtsdS|durzt��WStyYdSwzt�|�jWSty)YdSw)z�
    Get the uid for a given user name. If no user given, the current euid will
    be returned. If the user does not exist, None will be returned. On systems
    which do not support pwd or os.geteuid, None will be returned.
    N)rrr�AttributeErrorr�getpwnam�pw_uid�KeyError��userrrrr:s
��cCs�Gdd�dtj�}|�}d|_d}d}t��}tjj�t�|�d||ddddddt�|��dkr4td��z$tj	�
�}tjj�||t�|��dkrLtd	��|jdkWtjj�
|�Stjj�
|�w)
z�
    Using the win32 api, determine if the user with token 'user_token' has
    administrator rights.

    See MSDN entry here:
        http://msdn.microsoft.com/en-us/library/aa376389(VS.85).aspx
    c@s@eZdZdejfdejfdejfdejfdejfdejfgZdS)z:_win_user_token_is_admin.<locals>.SID_IDENTIFIER_AUTHORITYZbyte0Zbyte1Zbyte2Zbyte3Zbyte4�byte5N)�__name__�
__module__�__qualname__�ctypes�c_byte�_fields_rrrr�SID_IDENTIFIER_AUTHORITYXs�r"�� i �rzAllocateAndInitializeSid failedzCheckTokenMembership failed)r�	Structurer�c_void_pZwindllZadvapi32ZAllocateAndInitializeSid�byref�	ExceptionZwintypesZBOOLZCheckTokenMembership�valueZFreeSid)Z
user_tokenr"Znt_authorityZSECURITY_BUILTIN_DOMAIN_RIDZDOMAIN_ALIAS_RID_ADMINSZadministrators_groupZis_adminrrr�_win_user_token_is_adminOs@	
�
�
��
 r+cCstd�S)zs
    ctypes.windll.shell32.IsUserAnAdmin() is intentionally avoided due to this
    function being deprecated.
    r)r+rrrr�_win_current_user_is_admin�sr,cCs^t�}tjj��rt�rd|��S|Sd}|dkr-|D]}|tjvr,dtj|��Sq|S)zh
    Get a user name for publishing. If you find the user is "root" attempt to be
    more specific
    Zsudo_)Z	SUDO_USER�root)rrr�platformZ
is_windowsr,r�environ)rZenv_varsZevarrrr�get_specific_user�s
�
�r0c

Cs�t�|�}g}t�}|r+zt�|�j}Wnty*}z
td|�d|����d}~ww|j}t	|dd�}t
jdkrBdd�|��D�}|D]}||}	|	|vrX|�
|	�sX|�|	�qDt��|kr~zt�|�Wnty}}ztd	�t��||���d}~wwtt���t|�kr�zt�|�Wnty�}ztd
�||���d}~wwt��|jkr�z	t�|j�WdSty�}ztd�t��|j|���d}~wwdS)zm
    Change the current process to belong to the specified user (and the groups
    to which it belongs)
    zFailed to fetch the GID for z	. Error: NT��include_default�darwincSs i|]\}}|�d�s||�qS)�_)�
startswith)�.0�k�vrrr�
<dictcomp>�s zchugid.<locals>.<dictcomp>z-Failed to change from gid {} to {}. Error: {}z2Failed to set supplemental groups to {}. Error: {}z-Failed to change from uid {} to {}. Error: {})rr�set�grp�getgrnam�gr_gidrr�pw_gid�get_group_dict�sysr.�items�add�appendr�getgid�setgid�OSError�format�sorted�	getgroups�	setgroups�getuidr�setuid)
�runas�groupZuinfoZ	supgroupsZsupgroups_seenZ
target_pw_gid�errZ
group_listZ
group_name�gidrrr�chugid�sn
���

�
�������������rQc	Cs�d}d}t��}t�t�t���j�j}|r||krd}|}n|}|r,|}||kr+d}n|r?||kr?t�t�|�j�j}d}n|}|sE|rJt||�|durUt	�
|�dSdS)zi
    Helper method for for subprocess.Popen to initialise uid/gid and umask
    for the new process.
    FTN)�getpassZgetuserr;�getgrgidrrr>�gr_namerQr�umask)	rMrUrNZ	set_runasZset_grp�current_userZcurrent_grpZ
runas_userZ	runas_grprrr�chugid_and_umask�s,�
�rWcCs trtrt�t�|�j�jSdS)zo
    Returns the specified user's default group. If the user doesn't exist, a
    KeyError will be raised.
    N)�HAS_GRPrr;rSrrr>rTrrrr�get_default_group	s��rYcs�tdustdur
gSd}t�}t�d��zVtt��t�	��j
��}t�}tdd�|D��}d}||��dkrD|d8}||��dks8�fd	d
�|D���fdd
�|D�}�fdd
�|D�}	d
d
�|D�}
|	|
}Wn	tytYnw|dur�t�d���fdd
�t
��D�}zt��}||vr�|�|�Wn	ty�Ynw|dur�|�|�|dur�zt
�t�	��j
�j}|�|�Wn	ty�Ynwt�d�t|��t|�S)z\
    Returns a list of all of the system group names of which the user
    is a member.
    FNzTrying os.getgrouplist for '%s'css�|]}|jVqdS�N)r=�r6Zlgrprrr�	<genexpr>!s�z!get_group_list.<locals>.<genexpr>���i��csg|]}|�kr|�qSrrr[��	local_maxrr�
<listcomp>'�z"get_group_list.<locals>.<listcomp>csg|]}|�kr|�qSrr)r6Zrgrpr_rrra(rbcsg|]
}|j�vr|j�qSr)r=rT)r6�_group)�user_group_list_localrrra)s

�cSsg|]}t�|�j�qSr)r;rSrT)r6Zgroup_idrrrra.s�z"Trying generic group list for '%s'csg|]
}�|jvr|j�qSr)�gr_memrT)r6�grrrra:szGroup list for user '%s': %s)rXrr:�logZtracerHr�getgrouplistrrr>�	_getgrallr)r;�getgrallrYrCr�updaterSrT�remove)rr2�group_namesZugroupsZuser_group_listZlocal_grallZ
local_gidsZmax_idxZuser_group_list_remoteZlocal_group_namesZremote_group_namesZ
default_groupr)r`rrdr�get_group_listsb�
���
��
�rncCsHtdustdur
iSi}t||d�}|D]
}|�|t�|�ji�q|S)z�
    Returns a dict of all of the system groups as keys, and group ids
    as values, of which the user is a member.
    E.g.: {'staff': 501, 'sudo': 27}
    Fr1)rXrrnrkr;r<r=)rr2Z
group_dictrmrNrrrr?Usr?cCs4tdustdur
gStt||d����}tt|��S)zZ
    Returns a list of all of the system group IDs of which the user
    is a member.
    Fr1)rXr�listr?�valuesrHr:)rr2Zgid_listrrr�get_gid_listdsrqcCr)z�
    Get the gid for a given group name. If no group given, the current egid
    will be returned. If the group does not exist, None will be returned. On
    systems which do not support grp or os.getegid it will return None.
    N)rXr�getegidrr;r<r=r)rNrrr�get_gidos
��rscCs�g}|sdn|}tj�|d�}tjj�|��C}|D]7}tjj�|�}|�	��
d�}t|d�|d<|drDdd�|d�
d�D�|d<ng|d<|�t
�|��qWd	�|S1s\wY|S)
zL
    Alternative implemetantion for getgrall, that uses only /etc/group
    �/z	etc/group�:r%�cSsg|]}|���qSr)�strip)r6Zmemrrrra�sz_getgrall.<locals>.<listcomp>�,N)r�path�joinrr�filesZfopenr
rrw�split�intrCr;�struct_group)r-rZ	etc_groupZfp_�line�compsrrrri�s"�
��rirZ)T)NT)%�__doc__rrR�loggingrr@Zsalt.utils.pathrZsalt.utils.platformZsalt.utils.stringutilsZsalt.exceptionsrZsalt.utils.decorators.jinjarrr�ImportErrorr;rXZsalt.utils.win_functionsr
�	getLoggerrrgrrr+r,r0rQrWrYrnr?rqrsrirrrr�<module>sX���
:

D"


B