Skip to content

Commit

Permalink
issue-671: get ASNI_QUOTES from session sql_mode instead of GLOBAL sq…
Browse files Browse the repository at this point in the history
…l_mode
  • Loading branch information
SoledaD208 committed Oct 10, 2024
1 parent 28bf709 commit 9c128ae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 3 additions & 9 deletions plugins/module_utils/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class InvalidPrivsError(Exception):


def get_mode(cursor):
cursor.execute('SELECT @@GLOBAL.sql_mode')
cursor.execute('SELECT @@sql_mode')
result = cursor.fetchone()
mode_str = result[0]
if 'ANSI' in mode_str:
Expand Down Expand Up @@ -214,8 +214,6 @@ def user_add(cursor, user, host, host_all, password, encrypted,
# Mysql and MariaDB differ in naming pam plugin and Syntax to set it
if plugin == 'pam': # Used by MariaDB which requires the USING keyword, not BY
query_with_args = "CREATE USER %s@%s IDENTIFIED WITH %s USING %s", (user, host, plugin, plugin_auth_string)
elif plugin == 'ed25519': # Used by MariaDB which requires the USING keyword, not BY
query_with_args = "CREATE USER %s@%s IDENTIFIED WITH %s USING PASSWORD(%s)", (user, host, plugin, plugin_auth_string)
elif salt:
if plugin in ['caching_sha2_password', 'sha256_password']:
generated_hash_string = mysql_sha256_password_hash_hex(password=plugin_auth_string, salt=salt)
Expand Down Expand Up @@ -395,15 +393,12 @@ def user_mod(cursor, user, host, host_all, password, encrypted,
update = True

if update:
query_with_args = None
if plugin_hash_string:
query_with_args = "ALTER USER %s@%s IDENTIFIED WITH %s AS %s", (user, host, plugin, plugin_hash_string)
elif plugin_auth_string:
# Mysql and MariaDB differ in naming pam plugin and syntax to set it
if plugin == 'pam':
if plugin in ('pam', 'ed25519'):
query_with_args = "ALTER USER %s@%s IDENTIFIED WITH %s USING %s", (user, host, plugin, plugin_auth_string)
elif plugin == 'ed25519':
query_with_args = "ALTER USER %s@%s IDENTIFIED WITH %s USING PASSWORD(%s)", (user, host, plugin, plugin_auth_string)
elif salt:
if plugin in ['caching_sha2_password', 'sha256_password']:
generated_hash_string = mysql_sha256_password_hash_hex(password=plugin_auth_string, salt=salt)
Expand All @@ -415,8 +410,7 @@ def user_mod(cursor, user, host, host_all, password, encrypted,
else:
query_with_args = "ALTER USER %s@%s IDENTIFIED WITH %s", (user, host, plugin)

if not module.check_mode:
cursor.execute(*query_with_args)
cursor.execute(*query_with_args)
password_changed = True
changed = True

Expand Down
4 changes: 4 additions & 0 deletions tests/integration/targets/test_mysql_user/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@
- import_tasks: issue-64560.yaml
tags:
- issue-64560

- import_tasks: issue-671.yaml
tags:
- issue-671

# Test that mysql_user still works with force_context enabled (database set to "mysql")
# (https://github.com/ansible-collections/community.mysql/issues/265)
Expand Down

0 comments on commit 9c128ae

Please sign in to comment.