mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-23 12:47:56 +00:00
Simplified split_grants() and added a test for mixed table & column grants on the same table
This commit is contained in:
@@ -1887,19 +1887,15 @@ sub split_grants {
|
||||
my @grants;
|
||||
if ( $grants =~ m/(?:INSERT|SELECT|UPDATE) \(/ ) {
|
||||
PTDEBUG && _d('Splitting grants on keywords:', $grants);
|
||||
@grants = map {
|
||||
my $grant = $_;
|
||||
$grant =~ s/^\s+//;
|
||||
$grant =~ s/,\s*$//;
|
||||
$grant;
|
||||
} $grants =~ m/
|
||||
\G # Start matching after the previous match
|
||||
\s? # Space after previous match's separating comma
|
||||
(?: # Either match...
|
||||
(?: (?:INSERT|SELECT|UPDATE)\s\(.+?\) ) # a column grant
|
||||
| (?: [A-Z\s]+ ) # or a table grant
|
||||
# TODO: the following .+? might break (e.g. on `annoying)column`).
|
||||
# Remember to update this whenever we switch to using
|
||||
# a common SQL regex module
|
||||
@grants = $grants =~ m/
|
||||
(
|
||||
(?:INSERT|SELECT|UPDATE)\s\(.+?\) # a column grants
|
||||
| [A-Z\s]+
|
||||
)
|
||||
,? # Separted from the next grant, if any, by a comma
|
||||
(?:,\s)? # Separted from the next grant, if any, by a comma
|
||||
/xg;
|
||||
}
|
||||
else {
|
||||
|
@@ -128,6 +128,17 @@ ok(
|
||||
"Column-level grants --separate --revoke (bug 866075)"
|
||||
);
|
||||
|
||||
diag(`/tmp/12345/use -u root -e "GRANT SELECT ON sakila.city TO 'sally'\@'%'"`);
|
||||
|
||||
ok(
|
||||
no_diff(
|
||||
sub { pt_show_grants::main('-F', $cnf, qw(--only sally --no-header)) },
|
||||
"t/pt-show-grants/samples/column-grants-combined.txt",
|
||||
stderr => 1,
|
||||
),
|
||||
"Column-level grants combined with table-level grants on the same table (bug 866075)"
|
||||
);
|
||||
|
||||
diag(`/tmp/12345/use -u root -e "DROP USER 'sally'\@'%'"`);
|
||||
|
||||
# #############################################################################
|
||||
|
4
t/pt-show-grants/samples/column-grants-combined.txt
Normal file
4
t/pt-show-grants/samples/column-grants-combined.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
-- Grants for 'sally'@'%'
|
||||
GRANT INSERT (city), SELECT, SELECT (city_id) ON `sakila`.`city` TO 'sally'@'%';
|
||||
GRANT SELECT (SANumber, DateCreated, PaymentStat, PckPrice) ON `test`.`t` TO 'sally'@'%';
|
||||
GRANT USAGE ON *.* TO 'sally'@'%';
|
Reference in New Issue
Block a user