fixes #1120 - privileges using columns

This commit is contained in:
Bryan Fleming 2015-05-06 16:44:40 -05:00 committed by Matt Clay
parent 20aa4c0cea
commit 6f8d60a5ed

View file

@ -158,6 +158,7 @@ password=n<_665{vS43y
import getpass import getpass
import tempfile import tempfile
import re
try: try:
import MySQLdb import MySQLdb
except ImportError: except ImportError:
@ -313,13 +314,19 @@ def privileges_unpack(priv):
not specified in the string, as MySQL will always provide this by default. not specified in the string, as MySQL will always provide this by default.
""" """
output = {} output = {}
privs = []
for item in priv.strip().split('/'): for item in priv.strip().split('/'):
pieces = item.strip().split(':') pieces = item.strip().split(':')
dbpriv = pieces[0].rsplit(".", 1) dbpriv = pieces[0].rsplit(".", 1)
pieces[0] = "`%s`.%s" % (dbpriv[0].strip('`'), dbpriv[1]) pieces[0] = "`%s`.%s" % (dbpriv[0].strip('`'), dbpriv[1])
if '(' in pieces[1]:
output[pieces[0]] = [s.strip() for s in pieces[1].upper().split(',')] output[pieces[0]] = re.split(r',\s*(?=[^)]*(?:\(|$))', pieces[1].upper())
new_privs = frozenset(output[pieces[0]]) for i in output[pieces[0]]:
privs.append(re.sub(r'\(.*\)','',i))
else:
output[pieces[0]] = pieces[1].upper().split(',')
privs = output[pieces[0]]
new_privs = frozenset(privs)
if not new_privs.issubset(VALID_PRIVS): if not new_privs.issubset(VALID_PRIVS):
raise InvalidPrivsError('Invalid privileges specified: %s' % new_privs.difference(VALID_PRIVS)) raise InvalidPrivsError('Invalid privileges specified: %s' % new_privs.difference(VALID_PRIVS))