Perform privilege grants/revokes only when required
Use `has_table_privileges` and `has_database_privileges` to test whether a user already has a privilege before granting it, or whether a user doesn't have a privilege before revoking it.
This commit is contained in:
parent
4348475ed3
commit
167e7c2b81
1 changed files with 4 additions and 0 deletions
|
@ -431,6 +431,8 @@ def revoke_privileges(cursor, user, privs):
|
|||
check_funcs = dict(table=has_table_privileges, database=has_database_privileges)
|
||||
|
||||
changed = False
|
||||
revoke_funcs = dict(table=revoke_table_privilege, database=revoke_database_privilege)
|
||||
check_funcs = dict(table=has_table_privilege, database=has_database_privilege)
|
||||
for type_ in privs:
|
||||
for name, privileges in privs[type_].iteritems():
|
||||
# Check that any of the privileges requested to be removed are
|
||||
|
@ -444,6 +446,8 @@ def revoke_privileges(cursor, user, privs):
|
|||
def grant_privileges(cursor, user, privs):
|
||||
if privs is None:
|
||||
return False
|
||||
grant_funcs = dict(table=grant_table_privilege, database=grant_database_privilege)
|
||||
check_funcs = dict(table=has_table_privilege, database=has_database_privilege)
|
||||
|
||||
grant_funcs = dict(table=grant_table_privileges, database=grant_database_privileges)
|
||||
check_funcs = dict(table=has_table_privileges, database=has_database_privileges)
|
||||
|
|
Loading…
Reference in a new issue