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/auth/__pycache__/pam.cpython-310.pyc
o

�N�g��@s�dZddlZddlZddlZddlZddlZddlmZmZm	Z	m
Z
mZmZm
Z
mZmZmZmZmZddlmZdZzddlZWneyKdZYnwe�e�Zzeed��ZejZee_eege_ ej!Z"ege"_#e	e�e"_Wne$y�ej%ddd	�dZ&YnwdZ&d
Z'dZ(dZ)d
Z*Gdd�de
�Z+Gdd�de
�Z,Gdd�de
�Z-ee
e
e	e	e,��e	e	e-��e�Z.Gdd�de
�Z/z:eed��Z0e0j1Z2e
e2_eee	e/�e	e+�ge2_ e0j3Z4e
e4_e+e
ge4_ e0j5Z6e
e6_e+e
ge6_ e0j7Z8e
e8_e+e
ge8_ Wne$�y
ej%ddd	�dZ9YnwdZ9dd�Z:d(dd�Z;dd�Z<dd �Z=d!d"�Z>ed#k�rGe;ej?d$ej?d%ej?d&ej?d'��r@e�@d�e�@d
�dSdS))a`
Authenticate against PAM

Provides an authenticate function that will allow the caller to authenticate
a user against the Pluggable Authentication Modules (PAM) on the system.

Implemented using ctypes, so no compilation is necessary.

There is one extra configuration option for pam.  The `pam_service` that is
authenticated against.  This defaults to `login`

.. code-block:: yaml

    auth.pam.service: login

.. note:: Solaris-like (SmartOS, OmniOS, ...) systems may need ``auth.pam.service`` set to ``other``.

.. note:: PAM authentication will not work for the ``root`` user.

    The Python interface to PAM does not support authenticating as ``root``.

.. note:: This module executes itself in a subprocess in order to user the system python
    and pam libraries. We do this to avoid openssl version conflicts when
    running under a salt onedir build.
�N)�CDLL�	CFUNCTYPE�POINTER�	Structure�c_char�c_char_p�c_int�c_uint�c_void_p�cast�pointer�sizeof)�find_libraryTF�cz Failed to load libc using ctypes)�exc_info����c@s"eZdZdZdefgZdd�ZdS)�	PamHandlez(
    Wrapper class for pam_handle_t
    �handlecCst�|�d|_dS)Nr)r�__init__r��self�r�A/opt/saltstack/salt/lib/python3.10/site-packages/salt/auth/pam.pyr[s

zPamHandle.__init__N)�__name__�
__module__�__qualname__�__doc__r
�_fields_rrrrrrTs
rc@�(eZdZdZdefdefgZdd�ZdS)�
PamMessagez1
    Wrapper class for pam_message structure
    �	msg_style�msgcC�d|j�d|j�d�S)Nz<PamMessage � '�'>)r#r$rrrr�__repr__j�zPamMessage.__repr__N)rrrrrrr r(rrrrr"`��r"c@r!)�PamResponsez2
    Wrapper class for pam_response structure
    �resp�resp_retcodecCr%)Nz
<PamResponse r&r')r-r,rrrrr(xr)zPamResponse.__repr__N)rrrrrrr r(rrrrr+nr*r+c@s eZdZdZdefdefgZdS)�PamConvz.
    Wrapper class for pam_conv structure
    �convZappdata_ptrN)rrrr�	CONV_FUNCr
r rrrrr.�sr.ZpamzFailed to load pam using ctypescCstotS)z$
    Only load on Linux systems
    )�HAS_LIBC�HAS_PAMrrrr�__virtual__�sr3�utf-8cs�t|t�r
|�|�}t�t�r��|��t|t�r|�|�}t�fdd��}t�}t|d�}t||t|�t|��}|dkrDt||�dSt	|d�}|dkrRt
|d�}t|d�|dkS)��
    Returns True if the given username and password authenticate for the
    given service.  Returns False otherwise

    ``username``: the username to authenticate

    ``password``: the password in plain text
    csht|tt��}t|tt��|d<t|�D]}||jjtkr1t	��}t|t
�|j|_d|j|_qdS)z�
        Simple conversation function that responds to any
        prompt where the echo is off with the supplied password
        r)
�CALLOCr
r+rr�range�contentsr#�PAM_PROMPT_ECHO_OFF�STRDUPrr,r-)Z
n_messages�messagesZ
p_responseZapp_data�addr�iZpw_copy��passwordrr�my_conv�s�z_authenticate.<locals>.my_convrF)�
isinstance�str�encoder0rr.�	PAM_STARTr�PAM_END�PAM_AUTHENTICATE�
PAM_ACCT_MGMT)�usernamer?Zservice�encodingr@rr/�retvalrr>r�
_authenticate�s&
	









rKcCs�tj��}||d<||d<t�dd�|d<t|d<t�t�dd����}t�t	���}|�
�s7t�d	|�d
St
jt|�t|�g|dd
d�}|jd
krMdSt�d||j|j�d
S)r5�SALT_PAM_USERNAME�SALT_PAM_PASSWORDzauth.pam.serviceZlogin�SALT_PAM_SERVICE�SALT_PAM_ENCODINGzauth.pam.pythonz/usr/bin/python3z7Error 'auth.pam.python' config value does not exist: %sFT)�env�capture_output�checkrzPam auth failed for %s: %s %s)�os�environ�copyZ__opts__�getZ__salt_system_encoding__�pathlib�Path�resolve�__file__�exists�log�error�
subprocess�runrB�
returncode�stdout�stderr)rHr?rPZpyexeZpyfile�retrrr�authenticate�s(
	�
rdcKs
t||�S)z
    Authenticate via pam
    )rd)rHr?�kwargsrrr�auth�s
rfcOstjj�|�S)zY
    Retrieve groups for a given user for this auth provider

    Uses system groups
    )�salt�utils�userZget_group_list)rH�argsrerrr�groups�srk�__main__rLrMrNrO)r4)Ar�loggingrSrWr^�sys�ctypesrrrrrrrr	r
rrr
Zctypes.utilrZHAS_USERZsalt.utils.userrg�ImportError�	getLoggerrr\ZLIBCZcallocr6�restype�argtypesZstrdupr:Z	argstypes�	ExceptionZtracer1r9ZPAM_PROMPT_ECHO_ONZ
PAM_ERROR_MSGZ
PAM_TEXT_INFOrr"r+r0r.ZLIBPAMZ	pam_startrDZpam_authenticaterFZ
pam_acct_mgmtrGZpam_endrEr2r3rKrdrfrkrT�exitrrrr�<module>s�8�

��

�
1
	�
�