mirror of
https://github.com/webmin/webmin.git
synced 2025-07-23 00:30:33 +00:00
Re-factor grant parsing, and fix bug that prevent grants from being displayed when DBI returns an array
This commit is contained in:
@ -15,9 +15,8 @@ else {
|
||||
foreach $g (@{$s->{'data'}}) {
|
||||
if ($g->[0] eq $in{'table'} &&
|
||||
$g->[2] eq $in{'ns'}) {
|
||||
$g->[1] =~ s/^\{//; $g->[1] =~ s/\}$//;
|
||||
@grant = map { /^"(.*)=(.*)"$/ || /^(.*)=(.*)$/; [ $1, $2 ] }
|
||||
split(/,/, $g->[1]);
|
||||
@grant = &extract_grants($g->[1]);
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,7 +58,7 @@ foreach $g (@grant, [ undef, undef ]) {
|
||||
[ 'public', $text{'grant_public'} ],
|
||||
(map { [ "group $_", &text('grant_group', $_) ] }
|
||||
@groups),
|
||||
(@users) ]));
|
||||
(@users) ], 1, 0, 1));
|
||||
|
||||
# Permissions
|
||||
($acl = $g->[1]) =~ s/\/.*//g;
|
||||
|
@ -75,20 +75,19 @@ elsif (@tables) {
|
||||
"'>".&html_escape($tname)."</a>");
|
||||
push(@cols, $text{"grant_$type"});
|
||||
push(@cols, &html_escape($d));
|
||||
$g->[1] =~ s/^\{//; $g->[1] =~ s/\}$//;
|
||||
@gr = grep { /=\S/ } map { /^"(.*)"$/ ? $1 : $_ } split(/,/, $g->[1]);
|
||||
my @gr = &extract_grants($g->[1]);
|
||||
local $gstr;
|
||||
foreach $gr (@gr) {
|
||||
$gstr .= " | " if ($gr ne $gr[0]);
|
||||
if ($gr =~ /^=(\S+)/) {
|
||||
if ($gr->[0] eq "") {
|
||||
$gstr .= $text{'grant_public'};
|
||||
}
|
||||
elsif ($gr =~ /^group\s+(\S+)=(\S+)/) {
|
||||
elsif ($gr->[0] =~ /^group\s+(\S+)/) {
|
||||
$gstr .= &text('grant_group',
|
||||
"<tt>".&html_escape($1)."</tt>");
|
||||
}
|
||||
elsif ($gr =~ /^(\S+)=(\S+)$/) {
|
||||
$gstr .= "<tt>".&html_escape($1)."</tt>";
|
||||
else {
|
||||
$gstr .= "<tt>".&html_escape($gr->[0])."</tt>";
|
||||
}
|
||||
}
|
||||
push(@cols, $gstr);
|
||||
|
@ -1231,5 +1231,23 @@ else {
|
||||
return $cmd;
|
||||
}
|
||||
|
||||
# extract_grants(field)
|
||||
# Given a field from pg_class that contains grants either as a comma-separated
|
||||
# list or an array, return a list of tuples in user,grant format
|
||||
sub extract_grants
|
||||
{
|
||||
my ($f) = @_;
|
||||
my @rv;
|
||||
if (ref($f)) {
|
||||
@rv = map { [ split(/=/, $_, 2) ] } @$f;
|
||||
}
|
||||
else {
|
||||
$f =~ s/^\{//;
|
||||
$f =~ s/\}$//;
|
||||
@rv = map { [ split(/=/, $_, 2) ] } map { s/\\"/"/g; s/"//g; $_ } grep { /=\S/ } split(/,/, $f);
|
||||
}
|
||||
return @rv;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
@ -18,9 +18,8 @@ else {
|
||||
foreach $g (@{$s->{'data'}}) {
|
||||
if ($g->[0] eq $in{'table'} &&
|
||||
$g->[2] eq $in{'ns'}) {
|
||||
$g->[1] =~ s/^\{//; $g->[1] =~ s/\}$//;
|
||||
@grant = map { /^"(.*)=(.*)"$/ || /^(.*)=(.*)$/; [ $1, $2 ] }
|
||||
split(/,/, $g->[1]);
|
||||
@grant = &extract_grants($g->[1]);
|
||||
last;
|
||||
}
|
||||
}
|
||||
$qt = $ss ? "e_table($in{'ns'}.".".$in{'table'})
|
||||
|
Reference in New Issue
Block a user