Fix database table quoting in privileges_unpack() (#3858)

In Ansible 2.x this module gives `changed = True` for all privileges
that are specified including a table with

    priv: "database.table:GRANT"

Mysql returns escaped names in the format

    `database`.`tables`:GRANT

However in PR #1358, which was intended to support dotted database names
(a crazy idea to begin with), the quotes for the table name were left
out, leading to `curr_priv != new_priv`.

This means that the idempotency comparison between new_priv and
curr_priv is always 'changed'.

This PR re-introduces quoting to the table part of the priv.
pull/18777/head
Tobias Wolf 8 years ago committed by Matt Clay
parent ed246a328f
commit cda78382b6

@ -422,9 +422,12 @@ def privileges_unpack(priv, mode):
for item in priv.strip().split('/'):
pieces = item.strip().split(':')
dbpriv = pieces[0].rsplit(".", 1)
# Do not escape if privilege is for database '*' (all databases)
if dbpriv[0].strip('`') != '*':
pieces[0] = '%s%s%s.%s' % (quote, dbpriv[0].strip('`'), quote, dbpriv[1])
# Do not escape if privilege is for database or table, i.e.
# neither quote *. nor .*
for i, side in enumerate(dbpriv):
if side.strip('`') != '*':
dbpriv[i] = '%s%s%s' % (quote, side.strip('`'), quote)
pieces[0] = '.'.join(dbpriv)
if '(' in pieces[1]:
output[pieces[0]] = re.split(r',\s*(?=[^)]*(?:\(|$))', pieces[1].upper())

Loading…
Cancel
Save