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

�N�g2�@s�dZddlZe�e�ZzddlZddlZddlZddlm	Z	Wn1e
yPzddlZe��ddlZddlZddlZddl
m	Z	Wne
yMdZYnwYnwdd�Zdd�Zdd	�ZdS)
a
Provide authentication using MySQL.

When using MySQL as an authentication backend, you will need to create or
use an existing table that has a username and a password column.

To get started, create a simple table that holds just a username and
a password. The password field will hold a SHA256 checksum.

.. code-block:: sql

    CREATE TABLE `users` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `username` varchar(25) DEFAULT NULL,
      `password` varchar(70) DEFAULT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;

To create a user within MySQL, execute the following statement.

.. code-block:: sql

    INSERT INTO users VALUES (NULL, 'diana', SHA2('secret', 256))

.. code-block:: yaml

    mysql_auth:
      hostname: localhost
      database: SaltStack
      username: root
      password: letmein
      auth_sql: 'SELECT username FROM users WHERE username = "{0}" AND password = SHA2("{1}", 256)'

The `auth_sql` contains the SQL that will validate a user to ensure they are
correctly authenticated. This is where you can specify other SQL queries to
authenticate users.

Enable MySQL authentication.

.. code-block:: yaml

    external_auth:
      mysql:
        damian:
          - test.*

:depends:   - MySQL-python Python module
�N)�OperationalErrorcCstt�tdur
dfSdfS)z:
    Confirm that a python mysql client is installed.
    Nz!No python mysql client installed.�)�bool�MySQLdb�rr�C/opt/saltstack/salt/lib/python3.10/site-packages/salt/auth/mysql.py�__virtual__Jsrc
Cs�i}z+tdd|d<tdd|d<tdd|d<tdd|d<tdd|d<W|StyF}z
t�d|�WYd}~dSd}~ww)	z'
    Grab MySQL Connection Details
    Z
mysql_auth�hostname�username�password�database�auth_sqlz%s does not existN)Z__opts__�KeyError�log�error)Z	conn_info�errr�__get_connection_infoQs���rc
Cs�t�}|dur	dSzt�|d|d|d|d�}Wnty3}zt�|�WYd}~dSd}~ww|��}|�|d�||��|j	dkrJd	SdS)
z/
    Authenticate using a MySQL user table
    NFr	r
rrr
�T)
rr�connectrrrZcursorZexecute�formatZrowcount)r
r�_info�connrZcurrrr�authes"�
��
r)�__doc__�logging�	getLogger�__name__rrZMySQLdb.convertersZMySQLdb.cursorsZMySQLdb.connectionsr�ImportErrorZpymysqlZinstall_as_MySQLdbZMySQLdb.errrrrrrrr�<module>s01
���