mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-23 04:25:43 +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;
|
my @grants;
|
||||||
if ( $grants =~ m/(?:INSERT|SELECT|UPDATE) \(/ ) {
|
if ( $grants =~ m/(?:INSERT|SELECT|UPDATE) \(/ ) {
|
||||||
PTDEBUG && _d('Splitting grants on keywords:', $grants);
|
PTDEBUG && _d('Splitting grants on keywords:', $grants);
|
||||||
@grants = map {
|
# TODO: the following .+? might break (e.g. on `annoying)column`).
|
||||||
my $grant = $_;
|
# Remember to update this whenever we switch to using
|
||||||
$grant =~ s/^\s+//;
|
# a common SQL regex module
|
||||||
$grant =~ s/,\s*$//;
|
@grants = $grants =~ m/
|
||||||
$grant;
|
(
|
||||||
} $grants =~ m/
|
(?:INSERT|SELECT|UPDATE)\s\(.+?\) # a column grants
|
||||||
\G # Start matching after the previous match
|
| [A-Z\s]+
|
||||||
\s? # Space after previous match's separating comma
|
|
||||||
(?: # Either match...
|
|
||||||
(?: (?:INSERT|SELECT|UPDATE)\s\(.+?\) ) # a column grant
|
|
||||||
| (?: [A-Z\s]+ ) # or a table grant
|
|
||||||
)
|
)
|
||||||
,? # Separted from the next grant, if any, by a comma
|
(?:,\s)? # Separted from the next grant, if any, by a comma
|
||||||
/xg;
|
/xg;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@@ -128,6 +128,17 @@ ok(
|
|||||||
"Column-level grants --separate --revoke (bug 866075)"
|
"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'\@'%'"`);
|
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